From 69df267bb1898a39d59a78f1252283014359a637 Mon Sep 17 00:00:00 2001 From: def Date: Wed, 29 Jan 2014 02:04:02 +0100 Subject: [PATCH] Don't allow random_map when no maps are available in votes --- src/game/server/gamecontext.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 91f283582..2cbc0d3d9 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -1547,6 +1547,7 @@ void CGameContext::ConRandomMap(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; int NumMaps = 0; + int NumVotes = 0; int OurMap; char* pMapName; char pQuotedMapName[64]; @@ -1554,13 +1555,23 @@ void CGameContext::ConRandomMap(IConsole::IResult *pResult, void *pUserData) CVoteOptionServer *pOption = pSelf->m_pVoteOptionFirst; while(pOption) { - NumMaps++; + if(strncmp(pOption->m_aCommand, "change_map ", 11) == 0 + || strncmp(pOption->m_aCommand, "sv_map ", 7) == 0) + NumMaps++; + + NumVotes++; pOption = pOption->m_pNext; } + if(!NumMaps) + { + pSelf->SendChat(-1, CGameContext::CHAT_ALL, "random_map called, but no maps available in votes"); + return; + } + while(true) { - OurMap = rand() % NumMaps; + OurMap = rand() % NumVotes; pOption = pSelf->m_pVoteOptionFirst; while(OurMap > 0)