void game_sv_TeamDeathmatch::AutoBalanceTeams() { if (!Get_AutoTeamBalance()) return; //calc team count s16 MinTeam, MaxTeam; u32 NumToMove; u32 cnt = get_players_count(), l_teams[2] = {0,0}; for(u32 it=0; it<cnt; it++) { xrClientData *l_pC = (xrClientData*) m_server->client_Get (it); game_PlayerState* ps = l_pC->ps; if (!l_pC->net_Ready) continue; if (ps->IsSkip()) continue; if(ps->team>=1) ++(l_teams[ps->team-1]); }; if (l_teams[0] == l_teams[1]) return; if (l_teams[0] > l_teams[1]) { MinTeam = 1; MaxTeam = 0; } else { MinTeam = 0; MaxTeam = 1; }; NumToMove = (l_teams[MaxTeam] - l_teams[MinTeam]) / 2; if (!NumToMove) return; /////////////////////////////////////////////////////////////////////// while (NumToMove) { ///////// get lowest score player from MaxTeam u32 LowestPlayer = 0; s16 LowestScore = 32767; for(u32 it=0; it<cnt; it++) { xrClientData *l_pC = (xrClientData*) m_server->client_Get (it); game_PlayerState* ps = l_pC->ps; if (!l_pC->net_Ready) continue; if (ps->IsSkip()) continue; if (ps->team-1 != MaxTeam) continue; if (ps->frags() < LowestScore) { LowestScore = ps->frags(); LowestPlayer = it; }; }; ///////// move player to opposite team xrClientData *l_pC = (xrClientData*) m_server->client_Get (LowestPlayer); game_PlayerState* ps = l_pC->ps; ps->team = u8((MinTeam+1) & 0x00ff); NumToMove--; } };
void __cdecl callback_serverkey(int keyid, void* outbuf, void *userdata) { if (!userdata) return; xrGameSpyServer* pServer = (xrGameSpyServer*) userdata; if (!pServer) return; CGameSpy_QR2* pQR2 = pServer->QR2(); if (!pQR2) return; game_sv_mp* gmMP = smart_cast<game_sv_mp*>(pServer->game); game_sv_Deathmatch* gmDM = smart_cast<game_sv_Deathmatch*>(pServer->game); game_sv_TeamDeathmatch* gmTDM = smart_cast<game_sv_TeamDeathmatch*>(pServer->game); game_sv_ArtefactHunt* gmAhunt = smart_cast<game_sv_ArtefactHunt*>(pServer->game); string4096 game_version; switch (keyid) { case HOSTNAME_KEY: pQR2->BufferAdd(outbuf, pServer->HostName.c_str()); break; case MAPNAME_KEY: pQR2->BufferAdd(outbuf, pServer->MapName.c_str()); break; case GAMEVER_KEY: pQR2->BufferAdd(outbuf, pQR2->GetGameVersion(game_version)); break; case NUMPLAYERS_KEY: pQR2->BufferAdd_Int(outbuf, pServer->GetPlayersCount()); break; case MAXPLAYERS_KEY: pQR2->BufferAdd_Int(outbuf, pServer->m_iMaxPlayers); break; case GAMETYPE_KEY: ADD_KEY_VAL(pServer->game, pQR2, BufferAdd, outbuf, type_name()); break; // pQR2->BufferAdd(outbuf, pServer->game->type_name()); break; case GAMEMODE_KEY: pQR2->BufferAdd(outbuf, "openplaying"); break; case PASSWORD_KEY: if ( 0 == *(pServer->Password) ) { pQR2->BufferAdd_Int( outbuf, 0 ); } else { pQR2->BufferAdd_Int( outbuf, 1 ); } break; case G_USER_PASSWORD_KEY: if ( pServer->HasProtected() ) { pQR2->BufferAdd_Int( outbuf, 1 ); } else { pQR2->BufferAdd_Int( outbuf, 0 ); } break; case G_BATTLEYE_KEY: #ifdef BATTLEYE if ( g_pGameLevel && Level().battleye_system.server ) { pQR2->BufferAdd_Int( outbuf, 1 ); } else { pQR2->BufferAdd_Int( outbuf, 0 ); } #endif // BATTLEYE break; case HOSTPORT_KEY: pQR2->BufferAdd_Int(outbuf, pServer->GetPort()); break; case DEDICATED_KEY: pQR2->BufferAdd_Int(outbuf, pServer->IsDedicated()); break; case GAMETYPE_NAME_KEY: ADD_KEY_VAL(pServer->game, pQR2, BufferAdd_Int, outbuf, Type()); break; //pQR2->BufferAdd_Int(outbuf, pServer->game->Type()); break; case NUMTEAMS_KEY: ADD_KEY_VAL(gmMP, pQR2, BufferAdd_Int, outbuf, GetNumTeams()); break; //pQR2->BufferAdd_Int(outbuf, gmMP->GetNumTeams()); break; case G_MAX_PING_KEY: pQR2->BufferAdd_Int(outbuf, g_sv_dwMaxClientPing); break; //------- game ---------// case G_MAP_ROTATION_KEY: ADD_KEY_VAL(gmDM, pQR2, BufferAdd_Int, outbuf, HasMapRotation()); break; //if (gmDM) pQR2->BufferAdd_Int(outbuf, gmDM->HasMapRotation()); else pQR2->BufferAdd(outbuf, ""); break; case G_VOTING_ENABLED_KEY: ADD_KEY_VAL(gmDM, pQR2, BufferAdd_Int, outbuf, IsVotingEnabled()); break; //if (gmDM) pQR2->BufferAdd_Int(outbuf, gmDM->IsVotingEnabled()); else pQR2->BufferAdd(outbuf, ""); break; case G_SPECTATOR_MODES_KEY: ADD_KEY_VAL(gmDM, pQR2, BufferAdd_Int, outbuf, GetSpectatorModes()); break; //if (gmDM) pQR2->BufferAdd_Int(outbuf, gmDM->GetSpectatorModes()); else pQR2->BufferAdd(outbuf, ""); break; //------- deathmatch -------// case G_FRAG_LIMIT_KEY: ADD_KEY_VAL(gmDM, pQR2, BufferAdd_Int, outbuf, GetFragLimit()); break; //if (gmDM)pQR2->BufferAdd_Int(outbuf, gmDM->GetFragLimit()); else pQR2->BufferAdd(outbuf, ""); break; case G_TIME_LIMIT_KEY: ADD_KEY_VAL(gmDM, pQR2, BufferAdd_Int, outbuf, GetTimeLimit()); break; //if (gmDM)pQR2->BufferAdd_Int(outbuf, gmDM->GetTimeLimit()); else pQR2->BufferAdd(outbuf, ""); break; case G_DAMAGE_BLOCK_TIME_KEY: ADD_KEY_VAL(gmDM, pQR2, BufferAdd_Int, outbuf, GetDMBLimit()); break; //if (gmDM)pQR2->BufferAdd_Int(outbuf, gmDM->GetDMBLimit()); else pQR2->BufferAdd(outbuf, ""); break; case G_DAMAGE_BLOCK_INDICATOR_KEY: ADD_KEY_VAL(gmDM, pQR2, BufferAdd_Int, outbuf, IsDamageBlockIndEnabled()); break; //if (gmDM)pQR2->BufferAdd_Int(outbuf, gmDM->IsDamageBlockIndEnabled()); else pQR2->BufferAdd(outbuf, ""); break; case G_ANOMALIES_ENABLED_KEY: ADD_KEY_VAL(gmDM, pQR2, BufferAdd_Int, outbuf, IsAnomaliesEnabled()); break; //if (gmDM)pQR2->BufferAdd_Int(outbuf, gmDM->IsAnomaliesEnabled()); else pQR2->BufferAdd(outbuf, ""); break; case G_ANOMALIES_TIME_KEY: ADD_KEY_VAL(gmDM, pQR2, BufferAdd_Int, outbuf, GetAnomaliesTime()); break; //if (gmDM)pQR2->BufferAdd_Int(outbuf, gmDM->GetAnomaliesTime()); else pQR2->BufferAdd(outbuf, ""); break; case G_WARM_UP_TIME_KEY: ADD_KEY_VAL(gmDM, pQR2, BufferAdd_Int, outbuf, GetWarmUpTime()); break; //if (gmDM)pQR2->BufferAdd_Int(outbuf, gmDM->GetWarmUpTime()); else pQR2->BufferAdd(outbuf, ""); break; case G_FORCE_RESPAWN_KEY: ADD_KEY_VAL(gmDM, pQR2, BufferAdd_Int, outbuf, GetForceRespawn()); break; //if (gmDM)pQR2->BufferAdd_Int(outbuf, gmDM->GetForceRespawn()); else pQR2->BufferAdd(outbuf, ""); break; //---- game_sv_teamdeathmatch ---- case G_AUTO_TEAM_BALANCE_KEY: ADD_KEY_VAL(gmTDM, pQR2, BufferAdd_Int, outbuf, Get_AutoTeamBalance()); break; //if (gmTDM)pQR2->BufferAdd_Int(outbuf, gmTDM->Get_AutoTeamBalance ()); break; case G_AUTO_TEAM_SWAP_KEY: ADD_KEY_VAL(gmTDM, pQR2, BufferAdd_Int, outbuf, Get_AutoTeamSwap()); break; //if (gmTDM)pQR2->BufferAdd_Int(outbuf, gmTDM->Get_AutoTeamSwap ()); break; case G_FRIENDLY_INDICATORS_KEY: ADD_KEY_VAL(gmTDM, pQR2, BufferAdd_Int, outbuf, Get_FriendlyIndicators()); break; //if (gmTDM)pQR2->BufferAdd_Int(outbuf, gmTDM->Get_FriendlyIndicators ()); break; case G_FRIENDLY_NAMES_KEY: ADD_KEY_VAL(gmTDM, pQR2, BufferAdd_Int, outbuf, Get_FriendlyNames()); break; //if (gmTDM)pQR2->BufferAdd_Int(outbuf, gmTDM->Get_FriendlyNames ()); break; case G_FRIENDLY_FIRE_KEY: ADD_KEY_VAL_INT(gmTDM, pQR2, BufferAdd_Int, outbuf, GetFriendlyFire()*100.0f); break; //if (gmTDM)pQR2->BufferAdd_Int(outbuf, int(gmTDM->GetFriendlyFire()*100.0f)); break; //---- game_sv_artefacthunt ---- case G_ARTEFACTS_COUNT_KEY: ADD_KEY_VAL(gmAhunt, pQR2, BufferAdd_Int, outbuf, Get_ArtefactsCount()); break; //if (gmAhunt) pQR2->BufferAdd_Int(outbuf, gmAhunt->Get_ArtefactsCount ()); break; case G_ARTEFACT_STAY_TIME_KEY: ADD_KEY_VAL(gmAhunt, pQR2, BufferAdd_Int, outbuf, Get_ArtefactsStayTime()); break; //if (gmAhunt) pQR2->BufferAdd_Int(outbuf, gmAhunt->Get_ArtefactsStayTime ()); break; case G_ARTEFACT_RESPAWN_TIME_KEY: ADD_KEY_VAL(gmAhunt, pQR2, BufferAdd_Int, outbuf, Get_ArtefactsRespawnDelta()); break; //if (gmAhunt) pQR2->BufferAdd_Int(outbuf, gmAhunt->Get_ArtefactsRespawnDelta ()); break; case G_REINFORCEMENT_KEY: ADD_KEY_VAL(gmAhunt, pQR2, BufferAdd_Int, outbuf, Get_ReinforcementTime()); break; //if (gmAhunt) pQR2->BufferAdd_Int(outbuf, gmAhunt->Get_ReinforcementTime ()); break; case G_SHIELDED_BASES_KEY: ADD_KEY_VAL(gmAhunt, pQR2, BufferAdd_Int, outbuf, Get_ShieldedBases()); break; //if (gmAhunt) pQR2->BufferAdd_Int(outbuf, gmAhunt->Get_ShieldedBases ()); break; case G_RETURN_PLAYERS_KEY: ADD_KEY_VAL(gmAhunt, pQR2, BufferAdd_Int, outbuf, Get_ReturnPlayers()); break; //if (gmAhunt) pQR2->BufferAdd_Int(outbuf, gmAhunt->Get_ReturnPlayers ()); break; case G_BEARER_CANT_SPRINT_KEY: ADD_KEY_VAL(gmAhunt, pQR2, BufferAdd_Int, outbuf, Get_BearerCantSprint()); break; //if (gmAhunt) pQR2->BufferAdd_Int(outbuf, gmAhunt->Get_BearerCantSprint ()); break; default: { // R_ASSERT2(0, "Unknown GameSpy Server key "); pQR2->BufferAdd(outbuf, ""); }break; } //GSI_UNUSED(userdata); };