diff options
| author | oy <Tom_Adams@web.de> | 2011-04-13 20:37:12 +0200 |
|---|---|---|
| committer | oy <Tom_Adams@web.de> | 2011-04-13 20:37:12 +0200 |
| commit | 06115dd49dca2f8eb5f14606437e8fd20037cc4d (patch) | |
| tree | 5ec4bca6158319b3f5285d7689c5f94ae8da8c93 /src/game/server/gamecontext.cpp | |
| parent | 63e059b8fff6498e42b765a1dca000e53005ea77 (diff) | |
| download | zcatch-06115dd49dca2f8eb5f14606437e8fd20037cc4d.tar.gz zcatch-06115dd49dca2f8eb5f14606437e8fd20037cc4d.zip | |
added "Whitespace and line Endings cleanup" by GreYFoX
Diffstat (limited to 'src/game/server/gamecontext.cpp')
| -rw-r--r-- | src/game/server/gamecontext.cpp | 146 |
1 files changed, 73 insertions, 73 deletions
diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index a0c1c64a..82adcbef 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -24,10 +24,10 @@ void CGameContext::Construct(int Resetting) { m_Resetting = 0; m_pServer = 0; - + for(int i = 0; i < MAX_CLIENTS; i++) m_apPlayers[i] = 0; - + m_pController = 0; m_VoteCloseTime = 0; m_pVoteOptionFirst = 0; @@ -241,7 +241,7 @@ void CGameContext::SendChat(int ChatterClientID, int Team, const char *pText) Msg.m_Team = 1; Msg.m_ClientID = ChatterClientID; Msg.m_pMessage = pText; - + // pack one for the recording only Server()->SendPackMsg(&Msg, MSGFLAG_VITAL|MSGFLAG_NOSEND, -1); @@ -277,7 +277,7 @@ void CGameContext::SendBroadcast(const char *pText, int ClientID) Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID); } -// +// void CGameContext::StartVote(const char *pDesc, const char *pCommand, const char *pReason) { // check if a vote is already running @@ -294,7 +294,7 @@ void CGameContext::StartVote(const char *pDesc, const char *pCommand, const char m_apPlayers[i]->m_VotePos = 0; } } - + // start vote m_VoteCloseTime = time_get() + time_freq()*25; str_copy(m_aVoteDescription, pDesc, sizeof(m_aVoteDescription)); @@ -338,7 +338,7 @@ void CGameContext::SendVoteStatus(int ClientID, int Total, int Yes, int No) Msg.m_Pass = Total - (Yes+No); Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID); - + } void CGameContext::AbortVoteKickOnDisconnect(int ClientID) @@ -353,7 +353,7 @@ void CGameContext::CheckPureTuning() // might not be created yet during start up if(!m_pController) return; - + if( str_comp(m_pController->m_pGameType, "DM")==0 || str_comp(m_pController->m_pGameType, "TDM")==0 || str_comp(m_pController->m_pGameType, "CTF")==0) @@ -364,13 +364,13 @@ void CGameContext::CheckPureTuning() Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "resetting tuning due to pure server"); m_Tuning = p; } - } + } } void CGameContext::SendTuningParams(int ClientID) { CheckPureTuning(); - + CMsgPacker Msg(NETMSGTYPE_SV_TUNEPARAMS); int *pParams = (int *)&m_Tuning; for(unsigned i = 0; i < sizeof(m_Tuning)/sizeof(int); i++) @@ -389,7 +389,7 @@ void CGameContext::OnTick() //if(world.paused) // make sure that the game object always updates m_pController->Tick(); - + for(int i = 0; i < MAX_CLIENTS; i++) { if(m_apPlayers[i]) @@ -398,7 +398,7 @@ void CGameContext::OnTick() m_apPlayers[i]->PostTick(); } } - + // update voting if(m_VoteCloseTime) { @@ -423,10 +423,10 @@ void CGameContext::OnTick() { if(!m_apPlayers[i] || m_apPlayers[i]->GetTeam() == TEAM_SPECTATORS || aVoteChecked[i]) // don't count in votes by spectators continue; - + int ActVote = m_apPlayers[i]->m_Vote; int ActVotePos = m_apPlayers[i]->m_VotePos; - + // check for more players with the same ip (only use the vote of the one who voted first) for(int j = i+1; j < MAX_CLIENTS; ++j) { @@ -453,13 +453,13 @@ void CGameContext::OnTick() else if(No >= (Total+1)/2) m_VoteEnforce = VOTE_ENFORCE_NO; } - + if(m_VoteEnforce == VOTE_ENFORCE_YES) { Console()->ExecuteLine(m_aVoteCommand); EndVote(); SendChat(-1, CGameContext::CHAT_ALL, "Vote passed"); - + if(m_apPlayers[m_VoteCreator]) m_apPlayers[m_VoteCreator]->m_LastVoteCall = 0; } @@ -475,7 +475,7 @@ void CGameContext::OnTick() } } } - + #ifdef CONF_DEBUG if(g_Config.m_DbgDummies) @@ -487,7 +487,7 @@ void CGameContext::OnTick() m_apPlayers[MAX_CLIENTS-i-1]->OnPredictedInput(&Input); } } -#endif +#endif } // Server hooks @@ -509,7 +509,7 @@ void CGameContext::OnClientEnter(int ClientID) m_apPlayers[ClientID]->Respawn(); char aBuf[512]; str_format(aBuf, sizeof(aBuf), "'%s' entered and joined the %s", Server()->ClientName(ClientID), m_pController->GetTeamName(m_apPlayers[ClientID]->GetTeam())); - SendChat(-1, CGameContext::CHAT_ALL, aBuf); + SendChat(-1, CGameContext::CHAT_ALL, aBuf); str_format(aBuf, sizeof(aBuf), "team_join player='%d:%s' team=%d", ClientID, Server()->ClientName(ClientID), m_apPlayers[ClientID]->GetTeam()); Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); @@ -525,7 +525,7 @@ void CGameContext::OnClientConnected(int ClientID) m_apPlayers[ClientID] = new(ClientID) CPlayer(this, ClientID, StartTeam); //players[client_id].init(client_id); //players[client_id].client_id = client_id; - + (void)m_pController->CheckTeamBalance(); #ifdef CONF_DEBUG @@ -552,7 +552,7 @@ void CGameContext::OnClientDrop(int ClientID, const char *pReason) m_apPlayers[ClientID]->OnDisconnect(pReason); delete m_apPlayers[ClientID]; m_apPlayers[ClientID] = 0; - + (void)m_pController->CheckTeamBalance(); m_VoteUpdate = true; @@ -568,7 +568,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) { void *pRawMsg = m_NetObjHandler.SecureUnpackMsg(MsgID, pUnpacker); CPlayer *pPlayer = m_apPlayers[ClientID]; - + if(!pRawMsg) { char aBuf[256]; @@ -576,7 +576,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "server", aBuf); return; } - + if(MsgID == NETMSGTYPE_CL_SAY) { CNetMsg_Cl_Say *pMsg = (CNetMsg_Cl_Say *)pRawMsg; @@ -585,10 +585,10 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) Team = pPlayer->GetTeam(); else Team = CGameContext::CHAT_ALL; - + if(g_Config.m_SvSpamprotection && pPlayer->m_LastChat && pPlayer->m_LastChat+Server()->TickSpeed() > Server()->Tick()) return; - + pPlayer->m_LastChat = Server()->Tick(); // check for invalid chars @@ -599,7 +599,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) *pMessage = ' '; pMessage++; } - + SendChat(ClientID, Team, pMsg->m_pMessage); } else if(MsgID == NETMSGTYPE_CL_CALLVOTE) @@ -620,7 +620,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) SendChatTarget(ClientID, "Wait for current vote to end before calling a new one."); return; } - + int Timeleft = pPlayer->m_LastVoteCall + Server()->TickSpeed()*60 - Now; if(pPlayer->m_LastVoteCall && Timeleft > 0) { @@ -629,7 +629,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) SendChatTarget(ClientID, aChatmsg); return; } - + char aChatmsg[512] = {0}; char aDesc[VOTE_DESC_LENGTH] = {0}; char aCmd[VOTE_CMD_LENGTH] = {0}; @@ -652,7 +652,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) pOption = pOption->m_pNext; } - + if(!pOption) { str_format(aChatmsg, sizeof(aChatmsg), "'%s' isn't an option on this server", pMsg->m_Value); @@ -682,7 +682,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) return; } } - + int KickID = str_toint(pMsg->m_Value); if(KickID < 0 || KickID >= MAX_CLIENTS || !m_apPlayers[KickID]) { @@ -702,7 +702,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) SendChatTarget(KickID, aBufKick); return; } - + str_format(aChatmsg, sizeof(aChatmsg), "'%s' called for vote to kick '%s' (%s)", Server()->ClientName(ClientID), Server()->ClientName(KickID), pReason); str_format(aDesc, sizeof(aDesc), "Kick '%s'", Server()->ClientName(KickID)); if (!g_Config.m_SvVoteKickBantime) @@ -722,7 +722,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) SendChatTarget(ClientID, "Server does not allow voting to move players to spectators"); return; } - + int SpectateID = str_toint(pMsg->m_Value); if(SpectateID < 0 || SpectateID >= MAX_CLIENTS || !m_apPlayers[SpectateID] || m_apPlayers[SpectateID]->GetTeam() == TEAM_SPECTATORS) { @@ -734,12 +734,12 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) SendChatTarget(ClientID, "You cant move yourself"); return; } - + str_format(aChatmsg, sizeof(aChatmsg), "'%s' called for vote to move '%s' to spectators (%s)", Server()->ClientName(ClientID), Server()->ClientName(SpectateID), pReason); str_format(aDesc, sizeof(aDesc), "move '%s' to spectators", Server()->ClientName(SpectateID)); str_format(aCmd, sizeof(aCmd), "set_team %d -1", SpectateID); } - + if(aCmd[0]) { SendChat(-1, CGameContext::CHAT_ALL, aChatmsg); @@ -769,7 +769,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) else if (MsgID == NETMSGTYPE_CL_SETTEAM && !m_World.m_Paused) { CNetMsg_Cl_SetTeam *pMsg = (CNetMsg_Cl_SetTeam *)pRawMsg; - + if(pPlayer->GetTeam() == pMsg->m_Team || (g_Config.m_SvSpamprotection && pPlayer->m_LastSetTeam && pPlayer->m_LastSetTeam+Server()->TickSpeed()*3 > Server()->Tick())) return; @@ -797,7 +797,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) else if (MsgID == NETMSGTYPE_CL_SETSPECTATORMODE && !m_World.m_Paused) { CNetMsg_Cl_SetSpectatorMode *pMsg = (CNetMsg_Cl_SetSpectatorMode *)pRawMsg; - + if(pPlayer->GetTeam() != TEAM_SPECTATORS || pPlayer->m_SpectatorID == pMsg->m_SpectatorID || ClientID == pMsg->m_SpectatorID || (g_Config.m_SvSpamprotection && pPlayer->m_LastSetSpectatorMode && pPlayer->m_LastSetSpectatorMode+Server()->TickSpeed()*3 > Server()->Tick())) return; @@ -809,13 +809,13 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) pPlayer->m_SpectatorID = pMsg->m_SpectatorID; } else if (MsgID == NETMSGTYPE_CL_STARTINFO) - { + { if(pPlayer->m_IsReady) return; - CNetMsg_Cl_StartInfo *pMsg = (CNetMsg_Cl_StartInfo *)pRawMsg; + CNetMsg_Cl_StartInfo *pMsg = (CNetMsg_Cl_StartInfo *)pRawMsg; pPlayer->m_LastChangeInfo = Server()->Tick(); - + // set start infos Server()->SetClientName(ClientID, pMsg->m_pName); Server()->SetClientClan(ClientID, pMsg->m_pClan); @@ -829,7 +829,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) // send vote options CNetMsg_Sv_VoteClearOptions ClearMsg; Server()->SendPackMsg(&ClearMsg, MSGFLAG_VITAL, ClientID); - + CNetMsg_Sv_VoteOptionListAdd OptionMsg; int NumOptions = 0; OptionMsg.m_pDescription0 = ""; @@ -897,7 +897,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) Server()->SendPackMsg(&OptionMsg, MSGFLAG_VITAL, ClientID); NumOptions = 0; } - + // send tuning parameters to client SendTuningParams(ClientID); @@ -907,16 +907,16 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) Server()->SendPackMsg(&m, MSGFLAG_VITAL|MSGFLAG_FLUSH, ClientID); } else if (MsgID == NETMSGTYPE_CL_CHANGEINFO) - { + { if(g_Config.m_SvSpamprotection && pPlayer->m_LastChangeInfo && pPlayer->m_LastChangeInfo+Server()->TickSpeed()*5 > Server()->Tick()) return; - + CNetMsg_Cl_ChangeInfo *pMsg = (CNetMsg_Cl_ChangeInfo *)pRawMsg; pPlayer->m_LastChangeInfo = Server()->Tick(); - + // set infos char aOldName[MAX_NAME_LENGTH]; - str_copy(aOldName, Server()->ClientName(ClientID), sizeof(aOldName)); + str_copy(aOldName, Server()->ClientName(ClientID), sizeof(aOldName)); Server()->SetClientName(ClientID, pMsg->m_pName); if(str_comp(aOldName, Server()->ClientName(ClientID)) != 0) { @@ -935,19 +935,19 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) else if (MsgID == NETMSGTYPE_CL_EMOTICON && !m_World.m_Paused) { CNetMsg_Cl_Emoticon *pMsg = (CNetMsg_Cl_Emoticon *)pRawMsg; - + if(g_Config.m_SvSpamprotection && pPlayer->m_LastEmote && pPlayer->m_LastEmote+Server()->TickSpeed()*3 > Server()->Tick()) return; - + pPlayer->m_LastEmote = Server()->Tick(); - + SendEmoticon(ClientID, pMsg->m_Emoticon); } else if (MsgID == NETMSGTYPE_CL_KILL && !m_World.m_Paused) { if(pPlayer->m_LastKill && pPlayer->m_LastKill+Server()->TickSpeed()*3 > Server()->Tick()) return; - + pPlayer->m_LastKill = Server()->Tick(); pPlayer->KillCharacter(WEAPON_SELF); } @@ -1024,14 +1024,14 @@ void CGameContext::ConSetTeam(IConsole::IResult *pResult, void *pUserData) CGameContext *pSelf = (CGameContext *)pUserData; int ClientID = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); int Team = clamp(pResult->GetInteger(1), -1, 1); - + char aBuf[256]; str_format(aBuf, sizeof(aBuf), "moved client %d to team %d", ClientID, Team); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); - + if(!pSelf->m_apPlayers[ClientID]) return; - + pSelf->m_apPlayers[ClientID]->SetTeam(Team); (void)pSelf->m_pController->CheckTeamBalance(); } @@ -1040,15 +1040,15 @@ void CGameContext::ConSetTeamAll(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; int Team = clamp(pResult->GetInteger(0), -1, 1); - + char aBuf[256]; str_format(aBuf, sizeof(aBuf), "moved all clients to team %d", Team); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); - + for(int i = 0; i < MAX_CLIENTS; ++i) if(pSelf->m_apPlayers[i]) pSelf->m_apPlayers[i]->SetTeam(Team); - + (void)pSelf->m_pController->CheckTeamBalance(); } @@ -1063,7 +1063,7 @@ void CGameContext::ConAddVote(IConsole::IResult *pResult, void *pUserData) pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "maximum number of vote options reached"); return; } - + // check for valid option if(!pSelf->Console()->LineIsValid(pCommand) || str_length(pCommand) >= VOTE_CMD_LENGTH) { @@ -1081,7 +1081,7 @@ void CGameContext::ConAddVote(IConsole::IResult *pResult, void *pUserData) pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); return; } - + // check for duplicate entry CVoteOptionServer *pOption = pSelf->m_pVoteOptionFirst; while(pOption) @@ -1095,11 +1095,11 @@ void CGameContext::ConAddVote(IConsole::IResult *pResult, void *pUserData) } pOption = pOption->m_pNext; } - + // add the option ++pSelf->m_NumVoteOptions; int Len = str_length(pCommand); - + pOption = (CVoteOptionServer *)pSelf->m_pVoteOptionHeap->Allocate(sizeof(CVoteOptionServer) + Len); pOption->m_pNext = 0; pOption->m_pPrev = pSelf->m_pVoteOptionLast; @@ -1108,7 +1108,7 @@ void CGameContext::ConAddVote(IConsole::IResult *pResult, void *pUserData) pSelf->m_pVoteOptionLast = pOption; if(!pSelf->m_pVoteOptionFirst) pSelf->m_pVoteOptionFirst = pOption; - + str_copy(pOption->m_aDescription, pDescription, sizeof(pOption->m_aDescription)); mem_copy(pOption->m_aCommand, pCommand, Len+1); char aBuf[256]; @@ -1125,7 +1125,7 @@ void CGameContext::ConRemoveVote(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; const char *pDescription = pResult->GetString(0); - + // check for valid option CVoteOptionServer *pOption = pSelf->m_pVoteOptionFirst; while(pOption) @@ -1146,7 +1146,7 @@ void CGameContext::ConRemoveVote(IConsole::IResult *pResult, void *pUserData) CNetMsg_Sv_VoteOptionRemove OptionMsg; OptionMsg.m_pDescription = pOption->m_aDescription; pSelf->Server()->SendPackMsg(&OptionMsg, MSGFLAG_VITAL, -1); - + // TODO: improve this // remove the option --pSelf->m_NumVoteOptions; @@ -1173,7 +1173,7 @@ void CGameContext::ConRemoveVote(IConsole::IResult *pResult, void *pUserData) pVoteOptionLast = pDst; if(!pVoteOptionFirst) pVoteOptionFirst = pDst; - + str_copy(pDst->m_aDescription, pSrc->m_aDescription, sizeof(pDst->m_aDescription)); mem_copy(pDst->m_aCommand, pSrc->m_aCommand, Len+1); } @@ -1209,7 +1209,7 @@ void CGameContext::ConForceVote(IConsole::IResult *pResult, void *pUserData) pOption = pOption->m_pNext; } - + if(!pOption) { str_format(aBuf, sizeof(aBuf), "'%s' isn't an option on this server", pValue); @@ -1247,7 +1247,7 @@ void CGameContext::ConForceVote(IConsole::IResult *pResult, void *pUserData) pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "Invalid client id to move"); return; } - + str_format(aBuf, sizeof(aBuf), "set_team %d -1", SpectateID); pSelf->Console()->ExecuteLine(aBuf); } @@ -1323,10 +1323,10 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/) m_pConsole = Kernel()->RequestInterface<IConsole>(); m_World.SetGameServer(this); m_Events.SetGameServer(this); - + //if(!data) // only load once //data = load_data_from_memory(internal_data); - + for(int i = 0; i < NUM_NETOBJTYPES; i++) Server()->SnapSetStaticsize(i, m_NetObjHandler.GetObjSize(i)); @@ -1354,22 +1354,22 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/) // create all entities from the game layer CMapItemLayerTilemap *pTileMap = m_Layers.GameLayer(); CTile *pTiles = (CTile *)Kernel()->RequestInterface<IMap>()->GetData(pTileMap->m_Data); - - - - + + + + /* num_spawn_points[0] = 0; num_spawn_points[1] = 0; num_spawn_points[2] = 0; */ - + for(int y = 0; y < pTileMap->m_Height; y++) { for(int x = 0; x < pTileMap->m_Width; x++) { int Index = pTiles[y*pTileMap->m_Width+x].m_Index; - + if(Index >= ENTITY_OFFSET) { vec2 Pos(x*32.0f+16.0f, y*32.0f+16.0f); @@ -1403,7 +1403,7 @@ void CGameContext::OnSnap(int ClientID) m_World.Snap(ClientID); m_pController->Snap(ClientID); m_Events.Snap(ClientID); - + for(int i = 0; i < MAX_CLIENTS; i++) { if(m_apPlayers[i]) |