From 37b43caba84de43b2a369de39d32632369ee796c Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 19 Aug 2012 10:40:30 +0200 Subject: [PATCH] cleaned up Sv_VoteOptionListAdd message --- datasrc/network.py | 12 +---- src/game/client/components/voting.cpp | 26 ---------- src/game/client/components/voting.h | 2 +- src/game/client/gameclient.cpp | 12 +++++ src/game/server/gamecontext.cpp | 72 ++++----------------------- src/game/voting.h | 1 + 6 files changed, 27 insertions(+), 98 deletions(-) diff --git a/datasrc/network.py b/datasrc/network.py index 292042182..34625c4b2 100644 --- a/datasrc/network.py +++ b/datasrc/network.py @@ -269,17 +269,9 @@ Messages = [ NetEnum("m_Emoticon", Emoticons), ]), - NetMessage("Sv_VoteClearOptions", [ - ]), + NetMessage("Sv_VoteClearOptions", []), - NetMessage("Sv_VoteOptionListAdd", [ - NetIntRange("m_NumOptions", 1, 15), - NetStringStrict("m_pDescription0"), NetStringStrict("m_pDescription1"), NetStringStrict("m_pDescription2"), - NetStringStrict("m_pDescription3"), NetStringStrict("m_pDescription4"), NetStringStrict("m_pDescription5"), - NetStringStrict("m_pDescription6"), NetStringStrict("m_pDescription7"), NetStringStrict("m_pDescription8"), - NetStringStrict("m_pDescription9"), NetStringStrict("m_pDescription10"), NetStringStrict("m_pDescription11"), - NetStringStrict("m_pDescription12"), NetStringStrict("m_pDescription13"), NetStringStrict("m_pDescription14"), - ]), + NetMessage("Sv_VoteOptionListAdd", []), NetMessage("Sv_VoteOptionAdd", [ NetStringStrict("m_pDescription"), diff --git a/src/game/client/components/voting.cpp b/src/game/client/components/voting.cpp index 6dccfef3b..bc32a4298 100644 --- a/src/game/client/components/voting.cpp +++ b/src/game/client/components/voting.cpp @@ -240,32 +240,6 @@ void CVoting::OnMessage(int MsgType, void *pRawMsg) { ClearOptions(); } - else if(MsgType == NETMSGTYPE_SV_VOTEOPTIONLISTADD) - { - CNetMsg_Sv_VoteOptionListAdd *pMsg = (CNetMsg_Sv_VoteOptionListAdd *)pRawMsg; - int NumOptions = pMsg->m_NumOptions; - for(int i = 0; i < NumOptions; ++i) - { - switch(i) - { - case 0: AddOption(pMsg->m_pDescription0); break; - case 1: AddOption(pMsg->m_pDescription1); break; - case 2: AddOption(pMsg->m_pDescription2); break; - case 3: AddOption(pMsg->m_pDescription3); break; - case 4: AddOption(pMsg->m_pDescription4); break; - case 5: AddOption(pMsg->m_pDescription5); break; - case 6: AddOption(pMsg->m_pDescription6); break; - case 7: AddOption(pMsg->m_pDescription7); break; - case 8: AddOption(pMsg->m_pDescription8); break; - case 9: AddOption(pMsg->m_pDescription9); break; - case 10: AddOption(pMsg->m_pDescription10); break; - case 11: AddOption(pMsg->m_pDescription11); break; - case 12: AddOption(pMsg->m_pDescription12); break; - case 13: AddOption(pMsg->m_pDescription13); break; - case 14: AddOption(pMsg->m_pDescription14); - } - } - } else if(MsgType == NETMSGTYPE_SV_VOTEOPTIONADD) { CNetMsg_Sv_VoteOptionAdd *pMsg = (CNetMsg_Sv_VoteOptionAdd *)pRawMsg; diff --git a/src/game/client/components/voting.h b/src/game/client/components/voting.h index 7a1ab8385..e87e4945e 100644 --- a/src/game/client/components/voting.h +++ b/src/game/client/components/voting.h @@ -22,7 +22,6 @@ class CVoting : public CComponent int m_Yes, m_No, m_Pass, m_Total; int m_CallvoteBlockTick; - void AddOption(const char *pDescription); void ClearOptions(); void Callvote(const char *pType, const char *pValue, const char *pReason, bool ForceVote); @@ -45,6 +44,7 @@ public: void CallvoteSpectate(int ClientID, const char *pReason, bool ForceVote = false); void CallvoteKick(int ClientID, const char *pReason, bool ForceVote = false); void CallvoteOption(int OptionID, const char *pReason, bool ForceVote = false); + void AddOption(const char *pDescription); void RemovevoteOption(int OptionID); void AddvoteOption(const char *pDescription, const char *pCommand); diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index f14f999be..5f54cd579 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -521,6 +521,18 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker) m_Tuning = NewTuning; return; } + else if(MsgId == NETMSGTYPE_SV_VOTEOPTIONLISTADD) + { + int NumOptions = pUnpacker->GetInt(); + for(int i = 0; i < NumOptions; i++) + { + const char *pDescription = pUnpacker->GetString(CUnpacker::SANITIZE_CC); + if(pUnpacker->Error()) + return; + + m_pVoting->AddOption(pDescription); + } + } else if(MsgId == NETMSGTYPE_SV_GAMEMSG) { int GameMsgID = pUnpacker->GetInt(); diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index f2333e8f7..4d01ad918 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -911,72 +911,22 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) CNetMsg_Sv_VoteClearOptions ClearMsg; Server()->SendPackMsg(&ClearMsg, MSGFLAG_VITAL, ClientID); - CNetMsg_Sv_VoteOptionListAdd OptionMsg; - int NumOptions = 0; - OptionMsg.m_pDescription0 = ""; - OptionMsg.m_pDescription1 = ""; - OptionMsg.m_pDescription2 = ""; - OptionMsg.m_pDescription3 = ""; - OptionMsg.m_pDescription4 = ""; - OptionMsg.m_pDescription5 = ""; - OptionMsg.m_pDescription6 = ""; - OptionMsg.m_pDescription7 = ""; - OptionMsg.m_pDescription8 = ""; - OptionMsg.m_pDescription9 = ""; - OptionMsg.m_pDescription10 = ""; - OptionMsg.m_pDescription11 = ""; - OptionMsg.m_pDescription12 = ""; - OptionMsg.m_pDescription13 = ""; - OptionMsg.m_pDescription14 = ""; CVoteOptionServer *pCurrent = m_pVoteOptionFirst; while(pCurrent) { - switch(NumOptions++) + // count options for actual packet + int NumOptions = 0; + for(CVoteOptionServer *p = pCurrent; p && NumOptions < MAX_VOTE_OPTION_ADD; p = p->m_pNext, ++NumOptions); + + // pack and send vote list packet + CMsgPacker Msg(NETMSGTYPE_SV_VOTEOPTIONLISTADD); + Msg.AddInt(NumOptions); + while(pCurrent && NumOptions--) { - case 0: OptionMsg.m_pDescription0 = pCurrent->m_aDescription; break; - case 1: OptionMsg.m_pDescription1 = pCurrent->m_aDescription; break; - case 2: OptionMsg.m_pDescription2 = pCurrent->m_aDescription; break; - case 3: OptionMsg.m_pDescription3 = pCurrent->m_aDescription; break; - case 4: OptionMsg.m_pDescription4 = pCurrent->m_aDescription; break; - case 5: OptionMsg.m_pDescription5 = pCurrent->m_aDescription; break; - case 6: OptionMsg.m_pDescription6 = pCurrent->m_aDescription; break; - case 7: OptionMsg.m_pDescription7 = pCurrent->m_aDescription; break; - case 8: OptionMsg.m_pDescription8 = pCurrent->m_aDescription; break; - case 9: OptionMsg.m_pDescription9 = pCurrent->m_aDescription; break; - case 10: OptionMsg.m_pDescription10 = pCurrent->m_aDescription; break; - case 11: OptionMsg.m_pDescription11 = pCurrent->m_aDescription; break; - case 12: OptionMsg.m_pDescription12 = pCurrent->m_aDescription; break; - case 13: OptionMsg.m_pDescription13 = pCurrent->m_aDescription; break; - case 14: - { - OptionMsg.m_pDescription14 = pCurrent->m_aDescription; - OptionMsg.m_NumOptions = NumOptions; - Server()->SendPackMsg(&OptionMsg, MSGFLAG_VITAL, ClientID); - OptionMsg = CNetMsg_Sv_VoteOptionListAdd(); - NumOptions = 0; - OptionMsg.m_pDescription1 = ""; - OptionMsg.m_pDescription2 = ""; - OptionMsg.m_pDescription3 = ""; - OptionMsg.m_pDescription4 = ""; - OptionMsg.m_pDescription5 = ""; - OptionMsg.m_pDescription6 = ""; - OptionMsg.m_pDescription7 = ""; - OptionMsg.m_pDescription8 = ""; - OptionMsg.m_pDescription9 = ""; - OptionMsg.m_pDescription10 = ""; - OptionMsg.m_pDescription11 = ""; - OptionMsg.m_pDescription12 = ""; - OptionMsg.m_pDescription13 = ""; - OptionMsg.m_pDescription14 = ""; - } + Msg.AddString(pCurrent->m_aDescription, VOTE_DESC_LENGTH); + pCurrent = pCurrent->m_pNext; } - pCurrent = pCurrent->m_pNext; - } - if(NumOptions > 0) - { - OptionMsg.m_NumOptions = NumOptions; - Server()->SendPackMsg(&OptionMsg, MSGFLAG_VITAL, ClientID); - NumOptions = 0; + Server()->SendMsg(&Msg, MSGFLAG_VITAL, ClientID); } // send tuning parameters to client diff --git a/src/game/voting.h b/src/game/voting.h index 12f786a4b..2235cbb77 100644 --- a/src/game/voting.h +++ b/src/game/voting.h @@ -10,6 +10,7 @@ enum VOTE_REASON_LENGTH=16, MAX_VOTE_OPTIONS=128, + MAX_VOTE_OPTION_ADD=21, VOTE_COOLDOWN=60, };