From e4345307c13d39104a9be99d192f0781f4ce6873 Mon Sep 17 00:00:00 2001 From: necropotame Date: Wed, 15 Mar 2017 11:11:01 +0100 Subject: [PATCH 1/2] Fix #662 (timer command displays the wrong state) --- src/game/server/ddracechat.cpp | 97 +++++++++++++++++----------------- 1 file changed, 48 insertions(+), 49 deletions(-) diff --git a/src/game/server/ddracechat.cpp b/src/game/server/ddracechat.cpp index cd60ba73b..21a18709f 100644 --- a/src/game/server/ddracechat.cpp +++ b/src/game/server/ddracechat.cpp @@ -1283,60 +1283,59 @@ void CGameContext::ConSetTimerType(IConsole::IResult *pResult, void *pUserData) if (!pPlayer) return; - const char msg[3][128] = {"game/round timer.", "broadcast.", "both game/round timer and broadcast."}; + if(pResult->NumArguments() > 0) + { + int OldType = pPlayer->m_TimerType; + + if(str_comp_nocase(pResult->GetString(0), "gametimer") == 0) + { + if(pPlayer->m_ClientVersion >= VERSION_DDNET_GAMETICK) + pPlayer->m_TimerType = CPlayer::TIMERTYPE_GAMETIMER; + else + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "timer", "gametimer is not supported by your client."); + } + else if(str_comp_nocase(pResult->GetString(0), "broadcast") == 0) + pPlayer->m_TimerType = CPlayer::TIMERTYPE_BROADCAST; + else if(str_comp_nocase(pResult->GetString(0), "both") == 0) + { + if(pPlayer->m_ClientVersion >= VERSION_DDNET_GAMETICK) + pPlayer->m_TimerType = CPlayer::TIMERTYPE_GAMETIMER_AND_BROADCAST; + else + { + pPlayer->m_TimerType = CPlayer::TIMERTYPE_BROADCAST; + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "timer", "gametimer is not supported by your client."); + } + } + else if(str_comp_nocase(pResult->GetString(0), "none") == 0) + pPlayer->m_TimerType = CPlayer::TIMERTYPE_NONE; + else if(str_comp_nocase(pResult->GetString(0), "cycle") == 0) + { + if(pPlayer->m_ClientVersion >= VERSION_DDNET_GAMETICK) + { + if(pPlayer->m_TimerType < CPlayer::TIMERTYPE_NONE) + pPlayer->m_TimerType++; + else if(pPlayer->m_TimerType == CPlayer::TIMERTYPE_NONE) + pPlayer->m_TimerType = CPlayer::TIMERTYPE_GAMETIMER; + } + else + { + if(pPlayer->m_TimerType < CPlayer::TIMERTYPE_NONE) + pPlayer->m_TimerType = CPlayer::TIMERTYPE_NONE; + else if(pPlayer->m_TimerType == CPlayer::TIMERTYPE_NONE) + pPlayer->m_TimerType = CPlayer::TIMERTYPE_BROADCAST; + } + } + + if((OldType == CPlayer::TIMERTYPE_BROADCAST || OldType == CPlayer::TIMERTYPE_GAMETIMER_AND_BROADCAST) && (pPlayer->m_TimerType == CPlayer::TIMERTYPE_GAMETIMER || pPlayer->m_TimerType == CPlayer::TIMERTYPE_NONE)) + pSelf->SendBroadcast("", pResult->m_ClientID); + } + char aBuf[128]; + const char msg[3][128] = {"game/round timer.", "broadcast.", "both game/round timer and broadcast."}; if(pPlayer->m_TimerType <= CPlayer::TIMERTYPE_GAMETIMER_AND_BROADCAST && pPlayer->m_TimerType >= CPlayer::TIMERTYPE_GAMETIMER) str_format(aBuf, sizeof(aBuf), "Timer is displayed in %s", msg[pPlayer->m_TimerType]); else if(pPlayer->m_TimerType == CPlayer::TIMERTYPE_NONE) str_format(aBuf, sizeof(aBuf), "Timer isn't displayed."); - - int OldType = pPlayer->m_TimerType; - - if(pResult->NumArguments() == 0) { - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD,"timer",aBuf); - return; - } - else if(str_comp_nocase(pResult->GetString(0), "gametimer") == 0) - { - if(pPlayer->m_ClientVersion >= VERSION_DDNET_GAMETICK) - pPlayer->m_TimerType = CPlayer::TIMERTYPE_GAMETIMER; - else - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "timer", "gametimer is not supported by your client."); - } - else if(str_comp_nocase(pResult->GetString(0), "broadcast") == 0) - pPlayer->m_TimerType = CPlayer::TIMERTYPE_BROADCAST; - else if(str_comp_nocase(pResult->GetString(0), "both") == 0) - { - if(pPlayer->m_ClientVersion >= VERSION_DDNET_GAMETICK) - pPlayer->m_TimerType = CPlayer::TIMERTYPE_GAMETIMER_AND_BROADCAST; - else - { - pPlayer->m_TimerType = CPlayer::TIMERTYPE_BROADCAST; - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "timer", "gametimer is not supported by your client."); - } - } - else if(str_comp_nocase(pResult->GetString(0), "none") == 0) - pPlayer->m_TimerType = CPlayer::TIMERTYPE_NONE; - else if(str_comp_nocase(pResult->GetString(0), "cycle") == 0) - { - if(pPlayer->m_ClientVersion >= VERSION_DDNET_GAMETICK) - { - if(pPlayer->m_TimerType < CPlayer::TIMERTYPE_NONE) - pPlayer->m_TimerType++; - else if(pPlayer->m_TimerType == CPlayer::TIMERTYPE_NONE) - pPlayer->m_TimerType = CPlayer::TIMERTYPE_GAMETIMER; - } - else - { - if(pPlayer->m_TimerType < CPlayer::TIMERTYPE_NONE) - pPlayer->m_TimerType = CPlayer::TIMERTYPE_NONE; - else if(pPlayer->m_TimerType == CPlayer::TIMERTYPE_NONE) - pPlayer->m_TimerType = CPlayer::TIMERTYPE_BROADCAST; - } - } - - if((OldType == CPlayer::TIMERTYPE_BROADCAST || OldType == CPlayer::TIMERTYPE_GAMETIMER_AND_BROADCAST) && (pPlayer->m_TimerType == CPlayer::TIMERTYPE_GAMETIMER || pPlayer->m_TimerType == CPlayer::TIMERTYPE_NONE)) - pSelf->SendBroadcast("", pResult->m_ClientID); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "timer", aBuf); } From 4027b3dc0132a2b72a426e90eaef8a3b8120c235 Mon Sep 17 00:00:00 2001 From: necropotame Date: Wed, 15 Mar 2017 12:20:40 +0100 Subject: [PATCH 2/2] Add error message in case of invalid argument for /timer --- src/game/server/ddracechat.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/game/server/ddracechat.cpp b/src/game/server/ddracechat.cpp index 21a18709f..43f94dbad 100644 --- a/src/game/server/ddracechat.cpp +++ b/src/game/server/ddracechat.cpp @@ -1272,6 +1272,8 @@ void CGameContext::ConTime(IConsole::IResult *pResult, void *pUserData) pSelf->SendBroadcast(aBuftime, pResult->m_ClientID); } +static const char s_aaMsg[3][128] = {"game/round timer.", "broadcast.", "both game/round timer and broadcast."}; + void CGameContext::ConSetTimerType(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *) pUserData; @@ -1283,6 +1285,8 @@ void CGameContext::ConSetTimerType(IConsole::IResult *pResult, void *pUserData) if (!pPlayer) return; + char aBuf[128]; + if(pResult->NumArguments() > 0) { int OldType = pPlayer->m_TimerType; @@ -1325,15 +1329,19 @@ void CGameContext::ConSetTimerType(IConsole::IResult *pResult, void *pUserData) pPlayer->m_TimerType = CPlayer::TIMERTYPE_BROADCAST; } } - + else + { + str_format(aBuf, sizeof(aBuf), "Unknown \"%s\" parameter. Accepted values: gametimer, broadcast, both, none, cycle", pResult->GetString(0)); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "timer", aBuf); + return; + } + if((OldType == CPlayer::TIMERTYPE_BROADCAST || OldType == CPlayer::TIMERTYPE_GAMETIMER_AND_BROADCAST) && (pPlayer->m_TimerType == CPlayer::TIMERTYPE_GAMETIMER || pPlayer->m_TimerType == CPlayer::TIMERTYPE_NONE)) pSelf->SendBroadcast("", pResult->m_ClientID); } - char aBuf[128]; - const char msg[3][128] = {"game/round timer.", "broadcast.", "both game/round timer and broadcast."}; if(pPlayer->m_TimerType <= CPlayer::TIMERTYPE_GAMETIMER_AND_BROADCAST && pPlayer->m_TimerType >= CPlayer::TIMERTYPE_GAMETIMER) - str_format(aBuf, sizeof(aBuf), "Timer is displayed in %s", msg[pPlayer->m_TimerType]); + str_format(aBuf, sizeof(aBuf), "Timer is displayed in %s", s_aaMsg[pPlayer->m_TimerType]); else if(pPlayer->m_TimerType == CPlayer::TIMERTYPE_NONE) str_format(aBuf, sizeof(aBuf), "Timer isn't displayed.");