diff options
| author | oy <Tom_Adams@web.de> | 2011-03-25 09:49:21 +0100 |
|---|---|---|
| committer | oy <Tom_Adams@web.de> | 2011-03-25 09:49:21 +0100 |
| commit | 8ad3def65ea79f66c7508c219e05da3e5e117fe9 (patch) | |
| tree | 271fe1749241106456734d4d4e63e0171524b48a | |
| parent | d78c84b105341ac85d735445fa04265e64017802 (diff) | |
| download | zcatch-8ad3def65ea79f66c7508c219e05da3e5e117fe9.tar.gz zcatch-8ad3def65ea79f66c7508c219e05da3e5e117fe9.zip | |
added aliases for votes. Closes #144
| -rw-r--r-- | datasrc/network.py | 5 | ||||
| -rw-r--r-- | src/game/client/components/menus_ingame.cpp | 2 | ||||
| -rw-r--r-- | src/game/client/components/voting.cpp | 12 | ||||
| -rw-r--r-- | src/game/client/components/voting.h | 6 | ||||
| -rw-r--r-- | src/game/client/gameclient.cpp | 2 | ||||
| -rw-r--r-- | src/game/server/gamecontext.cpp | 33 | ||||
| -rw-r--r-- | src/game/server/gamecontext.h | 3 |
7 files changed, 30 insertions, 33 deletions
diff --git a/datasrc/network.py b/datasrc/network.py index ea2a034b..6bfaeea3 100644 --- a/datasrc/network.py +++ b/datasrc/network.py @@ -262,13 +262,12 @@ Messages = [ ]), NetMessage("Sv_VoteOption", [ - NetStringStrict("m_pCommand"), + NetStringStrict("m_pDescription"), ]), NetMessage("Sv_VoteSet", [ NetIntRange("m_Timeout", 0, 60), - NetStringStrict("m_pDescription"), - NetStringStrict("m_pCommand"), + NetStringStrict("m_pDescription") ]), NetMessage("Sv_VoteStatus", [ diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index 8844e73d..c9d39be1 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -344,7 +344,7 @@ void CMenus::RenderServerControlServer(CUIRect MainView) CListboxItem Item = UiDoListboxNextItem(pOption); if(Item.m_Visible) - UI()->DoLabelScaled(&Item.m_Rect, FormatCommand(pOption->m_aCommand), 16.0f, -1); + UI()->DoLabelScaled(&Item.m_Rect, FormatCommand(pOption->m_aDescription), 16.0f, -1); } m_CallvoteSelectedOption = UiDoListboxEnd(&s_ScrollValue, 0); diff --git a/src/game/client/components/voting.cpp b/src/game/client/components/voting.cpp index e2531818..3718a20a 100644 --- a/src/game/client/components/voting.cpp +++ b/src/game/client/components/voting.cpp @@ -48,7 +48,7 @@ void CVoting::CallvoteOption(int OptionId) { if(OptionId == 0) { - Callvote("option", pOption->m_aCommand); + Callvote("option", pOption->m_aDescription); break; } @@ -74,7 +74,7 @@ void CVoting::ForcevoteOption(int OptionId) { if(OptionId == 0) { - Client()->Rcon(pOption->m_aCommand); + Client()->Rcon(pOption->m_aDescription); break; } @@ -108,7 +108,6 @@ void CVoting::OnReset() { m_Closetime = 0; m_aDescription[0] = 0; - m_aCommand[0] = 0; m_Yes = m_No = m_Pass = m_Total = 0; m_Voted = 0; } @@ -128,7 +127,6 @@ void CVoting::OnMessage(int MsgType, void *pRawMsg) { OnReset(); str_copy(m_aDescription, pMsg->m_pDescription, sizeof(m_aDescription)); - str_copy(m_aCommand, pMsg->m_pCommand, sizeof(m_aCommand)); m_Closetime = time_get() + time_freq() * pMsg->m_Timeout; } else @@ -149,9 +147,8 @@ void CVoting::OnMessage(int MsgType, void *pRawMsg) else if(MsgType == NETMSGTYPE_SV_VOTEOPTION) { CNetMsg_Sv_VoteOption *pMsg = (CNetMsg_Sv_VoteOption *)pRawMsg; - int Len = str_length(pMsg->m_pCommand); - CVoteOption *pOption = (CVoteOption *)m_Heap.Allocate(sizeof(CVoteOption) + Len); + CVoteOption *pOption = (CVoteOption *)m_Heap.Allocate(sizeof(CVoteOption)); pOption->m_pNext = 0; pOption->m_pPrev = m_pLast; if(pOption->m_pPrev) @@ -160,8 +157,7 @@ void CVoting::OnMessage(int MsgType, void *pRawMsg) if(!m_pFirst) m_pFirst = pOption; - mem_copy(pOption->m_aCommand, pMsg->m_pCommand, Len+1); - + str_copy(pOption->m_aDescription, pMsg->m_pDescription, sizeof(pOption->m_aDescription)); } } diff --git a/src/game/client/components/voting.h b/src/game/client/components/voting.h index 87e0ec10..151ecbfc 100644 --- a/src/game/client/components/voting.h +++ b/src/game/client/components/voting.h @@ -14,8 +14,7 @@ class CVoting : public CComponent static void ConVote(IConsole::IResult *pResult, void *pUserData); int64 m_Closetime; - char m_aDescription[512]; - char m_aCommand[512]; + char m_aDescription[64]; int m_Voted; void ClearOptions(); @@ -27,7 +26,7 @@ public: { CVoteOption *m_pNext; CVoteOption *m_pPrev; - char m_aCommand[1]; + char m_aDescription[64]; }; CVoteOption *m_pFirst; @@ -52,7 +51,6 @@ public: bool IsVoting() { return m_Closetime != 0; } int TakenChoice() const { return m_Voted; } const char *VoteDescription() const { return m_aDescription; } - const char *VoteCommand() const { return m_aCommand; } int m_Yes, m_No, m_Pass, m_Total; }; diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 21180b40..c6419b34 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -197,7 +197,7 @@ void CGameClient::OnConsoleInit() Console()->Register("say", "r", CFGFLAG_SERVER, 0, 0, "Say in chat"); Console()->Register("set_team", "ii", CFGFLAG_SERVER, 0, 0, "Set team of player to team"); Console()->Register("set_team_all", "i", CFGFLAG_SERVER, 0, 0, "Set team of all players to team"); - Console()->Register("addvote", "r", CFGFLAG_SERVER, 0, 0, "Add a voting option"); + Console()->Register("add_vote", "sr", CFGFLAG_SERVER, 0, 0, "Add a voting option"); Console()->Register("clear_votes", "", CFGFLAG_SERVER, 0, 0, "Clears the voting options"); Console()->Register("vote", "r", CFGFLAG_SERVER, 0, 0, "Force a vote to yes/no"); diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 1612ebec..a65142c6 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -314,13 +314,11 @@ void CGameContext::SendVoteSet(int ClientID) { Msg.m_Timeout = (m_VoteCloseTime-time_get())/time_freq(); Msg.m_pDescription = m_aVoteDescription; - Msg.m_pCommand = ""; } else { Msg.m_Timeout = 0; Msg.m_pDescription = ""; - Msg.m_pCommand = ""; } Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID); } @@ -635,9 +633,9 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) CVoteOption *pOption = m_pVoteOptionFirst; while(pOption) { - if(str_comp_nocase(pMsg->m_Value, pOption->m_aCommand) == 0) + if(str_comp_nocase(pMsg->m_Value, pOption->m_aDescription) == 0) { - str_format(aChatmsg, sizeof(aChatmsg), "'%s' called vote to change server option '%s'", Server()->ClientName(ClientID), pOption->m_aCommand); + str_format(aChatmsg, sizeof(aChatmsg), "'%s' called vote to change server option '%s'", Server()->ClientName(ClientID), pOption->m_aDescription); str_format(aDesc, sizeof(aDesc), "%s", pOption->m_aCommand); str_format(aCmd, sizeof(aCmd), "%s", pOption->m_aCommand); break; @@ -811,7 +809,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) while(pCurrent) { CNetMsg_Sv_VoteOption OptionMsg; - OptionMsg.m_pCommand = pCurrent->m_aCommand; + OptionMsg.m_pDescription = pCurrent->m_aDescription; Server()->SendPackMsg(&OptionMsg, MSGFLAG_VITAL, ClientID); pCurrent = pCurrent->m_pNext; } @@ -974,31 +972,34 @@ void CGameContext::ConSetTeamAll(IConsole::IResult *pResult, void *pUserData) void CGameContext::ConAddVote(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; - const char *pString = pResult->GetString(0); + const char *pDescription = pResult->GetString(0); + const char *pCommand = pResult->GetString(1); // check for valid option - if(!pSelf->Console()->LineIsValid(pString)) + if(!pSelf->Console()->LineIsValid(pCommand)) { char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "skipped invalid option '%s'", pString); + str_format(aBuf, sizeof(aBuf), "skipped invalid option '%s'", pCommand); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); return; } + // check for duplicate entry CGameContext::CVoteOption *pOption = pSelf->m_pVoteOptionFirst; while(pOption) { - if(str_comp_nocase(pString, pOption->m_aCommand) == 0) + if(str_comp_nocase(pDescription, pOption->m_aCommand) == 0) { char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "option '%s' already exists", pString); + str_format(aBuf, sizeof(aBuf), "option '%s' already exists", pDescription); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); return; } pOption = pOption->m_pNext; } - int Len = str_length(pString); + // add the option + int Len = str_length(pCommand); pOption = (CGameContext::CVoteOption *)pSelf->m_pVoteOptionHeap->Allocate(sizeof(CGameContext::CVoteOption) + Len); pOption->m_pNext = 0; @@ -1009,13 +1010,15 @@ void CGameContext::ConAddVote(IConsole::IResult *pResult, void *pUserData) if(!pSelf->m_pVoteOptionFirst) pSelf->m_pVoteOptionFirst = pOption; - mem_copy(pOption->m_aCommand, pString, Len+1); + str_copy(pOption->m_aDescription, pDescription, sizeof(pOption->m_aDescription)); + mem_copy(pOption->m_aCommand, pCommand, Len+1); char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "added option '%s'", pOption->m_aCommand); + str_format(aBuf, sizeof(aBuf), "added option '%s' '%s'", pOption->m_aDescription, pOption->m_aCommand); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); + // send added option to the clients CNetMsg_Sv_VoteOption OptionMsg; - OptionMsg.m_pCommand = pOption->m_aCommand; + OptionMsg.m_pDescription = pOption->m_aDescription; pSelf->Server()->SendPackMsg(&OptionMsg, MSGFLAG_VITAL, -1); } @@ -1073,7 +1076,7 @@ void CGameContext::OnConsoleInit() Console()->Register("set_team", "ii", CFGFLAG_SERVER, ConSetTeam, this, ""); Console()->Register("set_team_all", "i", CFGFLAG_SERVER, ConSetTeamAll, this, ""); - Console()->Register("addvote", "r", CFGFLAG_SERVER, ConAddVote, this, ""); + Console()->Register("add_vote", "sr", CFGFLAG_SERVER, ConAddVote, this, ""); Console()->Register("clear_votes", "", CFGFLAG_SERVER, ConClearVotes, this, ""); Console()->Register("vote", "r", CFGFLAG_SERVER, ConVote, this, ""); diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index 7379b74d..19926290 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -93,7 +93,7 @@ public: int64 m_VoteCloseTime; bool m_VoteUpdate; int m_VotePos; - char m_aVoteDescription[512]; + char m_aVoteDescription[64]; char m_aVoteCommand[512]; int m_VoteEnforce; enum @@ -106,6 +106,7 @@ public: { CVoteOption *m_pNext; CVoteOption *m_pPrev; + char m_aDescription[64]; char m_aCommand[1]; }; CHeap *m_pVoteOptionHeap; |