コード例 #1
0
ファイル: battle.cpp プロジェクト: renemilk/springlobby
void Battle::StartHostedBattle()
{
	if ( UserExists( GetMe().GetNick() ) )
	{
		if ( IsFounderMe() )
		{
			if ( sett().GetBattleLastAutoControlState() )
			{
				FixTeamIDs( (IBattle::BalanceType)sett().GetFixIDMethod(), sett().GetFixIDClans(), sett().GetFixIDStrongClans(), sett().GetFixIDGrouping() );
				Autobalance( (IBattle::BalanceType)sett().GetBalanceMethod(), sett().GetBalanceClans(), sett().GetBalanceStrongClans(), sett().GetBalanceGrouping() );
				FixColours();
			}
			if ( IsProxy() )
			{
				if ( UserExists( GetProxy()) && !GetUser(GetProxy()).Status().in_game )
				{
					// DON'T set m_generating_script here, it will trick the script generating code to think we're the host
					wxString hostscript = spring().WriteScriptTxt( *this );
					try
					{
						wxString path = TowxString(SlPaths::GetDataDir()) + _T("relayhost_script.txt");
						if ( !wxFile::Access( path, wxFile::write ) ) {
								wxLogError( _T("Access denied to script.txt.") );
						}

						wxFile f( path, wxFile::write );
						f.Write( hostscript );
						f.Close();

					} catch (...) {}
					m_serv.SendScriptToProxy( hostscript );
				}
			}
			if( GetAutoLockOnStart() )
			{
				SetIsLocked( true );
				SendHostInfo( IBattle::HI_Locked );
			}
			sett().SetLastHostMap(TowxString(GetServer().GetCurrentBattle()->GetHostMapName()));
			sett().SaveSettings();
			if ( !IsProxy() ) GetServer().StartHostedBattle();
			else if ( UserExists( GetProxy() ) && GetUser(GetProxy()).Status().in_game ) // relayhost is already ingame, let's try to join it
			{
				StartSpring();
			}
		}
	}
}
コード例 #2
0
ファイル: ibattle.cpp プロジェクト: cleanrock/springlobby
bool IBattle::IsFounder( const User& user ) const
{
	if ( UserExists(m_opts.founder) ) {
		try {
			return &GetFounder() == &user;
		} catch(...) {
			return false;
		}
	} else
		return false;
}
コード例 #3
0
ファイル: battle.cpp プロジェクト: tvo/springlobby
void Battle::StartSpring()
{
	if ( UserExists( GetMe().GetNick() ) && !GetMe().Status().in_game )
	{
		GetMe().BattleStatus().ready = false;
		SendMyBattleStatus();
		GetMe().Status().in_game = spring().Run( *this );
		GetMe().SendMyUserStatus();
	}
	ui().OnBattleStarted( *this );
}
コード例 #4
0
ファイル: battle.cpp プロジェクト: renemilk/springlobby
void Battle::StartSpring()
{
	if ( UserExists( GetMe().GetNick() ) && !GetMe().Status().in_game )
	{
		GetMe().BattleStatus().ready = false;
		SendMyBattleStatus();
		// set m_generating_script, this will make the script.txt writer realize we're just clients even if using a relayhost
		m_generating_script = true;
		GetMe().Status().in_game = spring().Run( *this );
		m_generating_script = false;
		GetMe().SendMyUserStatus();
	}
	ui().OnBattleStarted( *this );
}
コード例 #5
0
ファイル: battle.cpp プロジェクト: tvo/springlobby
void Battle::StartHostedBattle()
{
	if ( UserExists( GetMe().GetNick() ) )
	{
		if ( IsFounderMe() )
		{
			if ( sett().GetBattleLastAutoControlState() )
			{
				FixTeamIDs( (IBattle::BalanceType)sett().GetFixIDMethod(), sett().GetFixIDClans(), sett().GetFixIDStrongClans(), sett().GetFixIDGrouping() );
				Autobalance( (IBattle::BalanceType)sett().GetBalanceMethod(), sett().GetBalanceClans(), sett().GetBalanceStrongClans(), sett().GetBalanceGrouping() );
				FixColours();
			}
			if ( IsProxy() )
			{
				wxString hostscript = spring().WriteScriptTxt( *this );
				try
				{
					wxString path = sett().GetCurrentUsedDataDir() + wxFileName::GetPathSeparator() + _T("relayhost_script.txt");
					if ( !wxFile::Access( path, wxFile::write ) ) {
							wxLogError( _T("Access denied to script.txt.") );
					}

					wxFile f( path, wxFile::write );
					f.Write( hostscript );
					f.Close();

				} catch (...) {}
				m_serv.SendScriptToProxy( hostscript );
			}
			if( IsFounderMe() && GetAutoLockOnStart() )
			{
				SetIsLocked( true );
				SendHostInfo( IBattle::HI_Locked );
			}
			sett().SetLastHostMap( GetServer().GetCurrentBattle()->GetHostMapName() );
			sett().SaveSettings();
			if ( !IsProxy() ) GetServer().StartHostedBattle();
		}
	}
}
コード例 #6
0
ファイル: userdbsync.c プロジェクト: MalaGaM/nxscripts
static DWORD UserSyncFull(DB_CONTEXT *db)
{
    BOOL        removed;
    CHAR        *query;
    CHAR        userName[_MAX_NAME + 1];
    DWORD       error;
    DWORD       i;
    USERFILE    userFile;
    INT         result;
    NAME_ENTRY  *entry;
    NAME_LIST   list;
    MYSQL_BIND  bind[17];
    MYSQL_RES   *metadata;
    MYSQL_STMT  *stmt;

    ASSERT(db != NULL);
    TRACE("db=%p", db);

    //
    // Build list of user IDs
    //

    error = NameListCreateUsers(&list);
    if (error != ERROR_SUCCESS) {
        LOG_ERROR("Unable to create user ID list (error %lu).", error);
        return error;
    }

    //
    // Prepare and execute statement
    //

    stmt = db->stmt[7];

    query = "SELECT name,description,flags,home,limits,password,vfsfile,credits,"
            "       ratio,alldn,allup,daydn,dayup,monthdn,monthup,wkdn,wkup"
            "  FROM io_user";

    result = mysql_stmt_prepare(stmt, query, strlen(query));
    if (result != 0) {
        LOG_WARN("Unable to prepare statement: %s", mysql_stmt_error(stmt));
        return DbMapErrorFromStmt(stmt);
    }

    metadata = mysql_stmt_result_metadata(stmt);
    if (metadata == NULL) {
        LOG_WARN("Unable to retrieve result metadata: %s", mysql_stmt_error(stmt));
        return DbMapErrorFromStmt(stmt);
    }

    result = mysql_stmt_execute(stmt);
    if (result != 0) {
        LOG_ERROR("Unable to execute statement: %s", mysql_stmt_error(stmt));
        return DbMapErrorFromStmt(stmt);
    }

    //
    // Bind and fetch results
    //

    DB_CHECK_RESULTS(bind, metadata);
    ZeroMemory(&bind, sizeof(bind));

    bind[0].buffer_type   = MYSQL_TYPE_STRING;
    bind[0].buffer        = userName;
    bind[0].buffer_length = sizeof(userName);

    bind[1].buffer_type   = MYSQL_TYPE_STRING;
    bind[1].buffer        = userFile.Tagline;
    bind[1].buffer_length = sizeof(userFile.Tagline);

    bind[2].buffer_type   = MYSQL_TYPE_STRING;
    bind[2].buffer        = userFile.Flags;
    bind[2].buffer_length = sizeof(userFile.Flags);

    bind[3].buffer_type   = MYSQL_TYPE_STRING;
    bind[3].buffer        = userFile.Home;
    bind[3].buffer_length = sizeof(userFile.Home);

    bind[4].buffer_type   = MYSQL_TYPE_BLOB;
    bind[4].buffer        = &userFile.Limits;
    bind[4].buffer_length = sizeof(userFile.Limits);

    bind[5].buffer_type   = MYSQL_TYPE_BLOB;
    bind[5].buffer        = &userFile.Password;
    bind[5].buffer_length = sizeof(userFile.Password);

    bind[6].buffer_type   = MYSQL_TYPE_STRING;
    bind[6].buffer        = userFile.MountFile;
    bind[6].buffer_length = sizeof(userFile.MountFile);

    bind[7].buffer_type   = MYSQL_TYPE_BLOB;
    bind[7].buffer        = &userFile.Ratio;
    bind[7].buffer_length = sizeof(userFile.Ratio);

    bind[8].buffer_type   = MYSQL_TYPE_BLOB;
    bind[8].buffer        = &userFile.Credits;
    bind[8].buffer_length = sizeof(userFile.Credits);

    bind[9].buffer_type   = MYSQL_TYPE_BLOB;
    bind[9].buffer        = &userFile.DayUp;
    bind[9].buffer_length = sizeof(userFile.DayUp);

    bind[10].buffer_type   = MYSQL_TYPE_BLOB;
    bind[10].buffer        = &userFile.DayDn;
    bind[10].buffer_length = sizeof(userFile.DayDn);

    bind[11].buffer_type   = MYSQL_TYPE_BLOB;
    bind[11].buffer        = &userFile.WkUp;
    bind[11].buffer_length = sizeof(userFile.WkUp);

    bind[12].buffer_type   = MYSQL_TYPE_BLOB;
    bind[12].buffer        = &userFile.WkDn;
    bind[12].buffer_length = sizeof(userFile.WkDn);

    bind[13].buffer_type   = MYSQL_TYPE_BLOB;
    bind[13].buffer        = &userFile.MonthUp;
    bind[13].buffer_length = sizeof(userFile.MonthUp);

    bind[14].buffer_type   = MYSQL_TYPE_BLOB;
    bind[14].buffer        = &userFile.MonthDn;
    bind[14].buffer_length = sizeof(userFile.MonthDn);

    bind[15].buffer_type   = MYSQL_TYPE_BLOB;
    bind[15].buffer        = &userFile.AllUp;
    bind[15].buffer_length = sizeof(userFile.AllUp);

    bind[16].buffer_type   = MYSQL_TYPE_BLOB;
    bind[16].buffer        = &userFile.AllDn;
    bind[16].buffer_length = sizeof(userFile.AllDn);

    result = mysql_stmt_bind_result(stmt, bind);
    if (result != 0) {
        LOG_WARN("Unable to bind results: %s", mysql_stmt_error(stmt));
        return DbMapErrorFromStmt(stmt);
    }

    result = mysql_stmt_store_result(stmt);
    if (result != 0) {
        LOG_WARN("Unable to buffer results: %s", mysql_stmt_error(stmt));
        return DbMapErrorFromStmt(stmt);
    }

    //
    // Process result set
    //

    for (;;) {
        ZeroMemory(&userFile, sizeof(USERFILE));
        if (mysql_stmt_fetch(stmt) != 0) {
            break;
        }

        // Remove user from the list beforehand in case DbUserReadExtra() fails
        removed = NameListRemove(&list, userName);

        // Read the user's admin-groups, groups, and hosts
        error = DbUserReadExtra(db, userName, &userFile);
        if (error != ERROR_SUCCESS) {
            LOG_WARN("Unable to read user \"%s\" (error %lu).", userName, error);
            continue;
        }

        //
        // If ioFTPD fails to open a user at start-up, the user will still
        // have an entry in the UserIdTable file but ioFTPD considers them
        // gone. The call to UserExists() is done to check for this.
        //
        if (!removed || !UserExists(userName)) {
            TRACE("UserSyncFull: Create(%s)", userName);

            // User does not exist locally, create it.
            error = UserEventCreate(userName, &userFile);
            if (error != ERROR_SUCCESS) {
                LOG_WARN("Unable to create user \"%s\" (error %lu).", userName, error);
            }
        } else {
            TRACE("UserSyncFull: Update(%s)", userName);

            // User already exists locally, update it.
            error = UserEventUpdate(userName, &userFile);
            if (error != ERROR_SUCCESS) {
                LOG_WARN("Unable to update user \"%s\" (error %lu).", userName, error);
            }
        }
    }

    mysql_free_result(metadata);

    //
    // Delete remaining users
    //

    for (i = 0; i < list.count; i++) {
        entry = list.array[i];
        TRACE("UserSyncFull: Delete(%s,%d)", entry->name, entry->id);

        // User does not exist on database, delete it.
        error = UserEventDeleteEx(entry->name, entry->id);
        if (error != ERROR_SUCCESS) {
            LOG_WARN("Unable to delete user \"%s\" (error %lu).", entry->name, error);
        }
    }

    NameListDestroy(&list);

    return ERROR_SUCCESS;
}
コード例 #7
0
ファイル: battle.cpp プロジェクト: tvo/springlobby
bool Battle::ExecuteSayCommand( const wxString& cmd )
{
    wxString cmd_name=cmd.BeforeFirst(' ').Lower();
    if ( cmd_name == _T("/me") )
    {
        m_serv.DoActionBattle( m_opts.battleid, cmd.AfterFirst(' ') );
        return true;
    }
		if ( cmd_name == _T("/replacehostip") )
		{
				wxString ip = cmd.AfterFirst(' ');
				if ( ip.IsEmpty() ) return false;
				m_opts.ip = ip;
				return true;
		}
    //< quick hotfix for bans
    if (IsFounderMe())
    {
        if ( cmd_name == _T("/ban") )
        {
            wxString nick=cmd.AfterFirst(' ');
            m_banned_users.insert(nick);
            try
						{
							User& user = GetUser( nick );
							m_serv.BattleKickPlayer( m_opts.battleid, user );
						}
						catch( assert_exception ) {}
			UiEvents::GetUiEventSender( UiEvents::OnBattleActionEvent ).SendEvent(
					UiEvents::OnBattleActionData( wxString(_T(" ")) , nick+_T(" banned") )
				);

			//m_serv.DoActionBattle( m_opts.battleid, cmd.AfterFirst(' ') );
            return true;
        }
        if ( cmd_name == _T("/unban") )
        {
            wxString nick=cmd.AfterFirst(' ');
            m_banned_users.erase(nick);
			UiEvents::GetUiEventSender( UiEvents::OnBattleActionEvent ).SendEvent(
					UiEvents::OnBattleActionData( wxString(_T(" ")) , nick+_T(" unbanned") )
				);
            //m_serv.DoActionBattle( m_opts.battleid, cmd.AfterFirst(' ') );
            return true;
        }
        if ( cmd_name == _T("/banlist") )
        {
			UiEvents::GetUiEventSender( UiEvents::OnBattleActionEvent ).SendEvent(
					UiEvents::OnBattleActionData( wxString(_T(" ")) , _T("banlist:") )
				);

            for (std::set<wxString>::iterator i=m_banned_users.begin();i!=m_banned_users.end();++i)
            {
				UiEvents::GetUiEventSender( UiEvents::OnBattleActionEvent ).SendEvent(
						UiEvents::OnBattleActionData( wxString(_T(" ")) , *i )
					);
            }
            for (std::set<wxString>::iterator i=m_banned_ips.begin();i!=m_banned_ips.end();++i)
            {
				UiEvents::GetUiEventSender( UiEvents::OnBattleActionEvent ).SendEvent(
						UiEvents::OnBattleActionData( wxString(_T(" ")) , *i )
					);

            }
            return true;
        }
        if ( cmd_name == _T("/unban") )
        {
            wxString nick=cmd.AfterFirst(' ');
            m_banned_users.erase(nick);
            m_banned_ips.erase(nick);
			UiEvents::GetUiEventSender( UiEvents::OnBattleActionEvent ).SendEvent(
					UiEvents::OnBattleActionData( wxString(_T(" ")) , nick+_T(" unbanned") )
				);

            //m_serv.DoActionBattle( m_opts.battleid, cmd.AfterFirst(' ') );
            return true;
        }
        if ( cmd_name == _T("/ipban") )
        {
            wxString nick=cmd.AfterFirst(' ');
            m_banned_users.insert(nick);
			UiEvents::GetUiEventSender( UiEvents::OnBattleActionEvent ).SendEvent(
					UiEvents::OnBattleActionData( wxString(_T(" ")) , nick+_T(" banned") )
				);

            if (UserExists(nick))
            {
                User &user=GetUser(nick);
                if (!user.BattleStatus().ip.empty())
                {
                    m_banned_ips.insert(user.BattleStatus().ip);
					UiEvents::GetUiEventSender( UiEvents::OnBattleActionEvent ).SendEvent(
							UiEvents::OnBattleActionData( wxString(_T(" ")) , user.BattleStatus().ip+_T(" banned") )
						);
                }
                m_serv.BattleKickPlayer( m_opts.battleid, user );
            }
            //m_banned_ips.erase(nick);

            //m_serv.DoActionBattle( m_opts.battleid, cmd.AfterFirst(' ') );
            return true;
        }
    }
    //>
    return false;
}