cleaned up Sv_VoteOptionListAdd message

This commit is contained in:
oy 2012-08-19 10:40:30 +02:00
parent 8b5dddf2ba
commit 37b43caba8
6 changed files with 27 additions and 98 deletions

View file

@ -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"),

View file

@ -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;

View file

@ -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);

View file

@ -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();

View file

@ -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

View file

@ -10,6 +10,7 @@ enum
VOTE_REASON_LENGTH=16,
MAX_VOTE_OPTIONS=128,
MAX_VOTE_OPTION_ADD=21,
VOTE_COOLDOWN=60,
};