mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Vote random unfinished map with defined nr of stars
This commit is contained in:
parent
3dd24c3dee
commit
dcc64f1902
|
@ -1048,7 +1048,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
|
|||
SendChatTarget(ClientID, "Invalid option");
|
||||
return;
|
||||
}
|
||||
if(!m_apPlayers[ClientID]->m_Authed && (strncmp(pOption->m_aCommand, "sv_map ", 7) == 0 || strncmp(pOption->m_aCommand, "change_map ", 11) == 0 || strncmp(pOption->m_aCommand, "random_map", 10) == 0 || strncmp(pOption->m_aCommand, "random_unfinished_map", 10) == 0) && time_get() < m_LastMapVote + (time_freq() * g_Config.m_SvVoteMapTimeDelay))
|
||||
if(!m_apPlayers[ClientID]->m_Authed && (strncmp(pOption->m_aCommand, "sv_map ", 7) == 0 || strncmp(pOption->m_aCommand, "change_map ", 11) == 0 || strncmp(pOption->m_aCommand, "random_map", 11) == 0 || strncmp(pOption->m_aCommand, "random_unfinished_map", 22) == 0) && time_get() < m_LastMapVote + (time_freq() * g_Config.m_SvVoteMapTimeDelay))
|
||||
{
|
||||
char chatmsg[512] = {0};
|
||||
str_format(chatmsg, sizeof(chatmsg), "There's a %d second delay between map-votes, please wait %d seconds.", g_Config.m_SvVoteMapTimeDelay,((m_LastMapVote+(g_Config.m_SvVoteMapTimeDelay * time_freq()))/time_freq())-(time_get()/time_freq()));
|
||||
|
@ -1056,10 +1056,21 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
str_format(aChatmsg, sizeof(aChatmsg), "'%s' called vote to change server option '%s' (%s)", Server()->ClientName(ClientID),
|
||||
pOption->m_aDescription, pReason);
|
||||
str_format(aDesc, sizeof(aDesc), "%s", pOption->m_aDescription);
|
||||
str_format(aCmd, sizeof(aCmd), "%s", pOption->m_aCommand);
|
||||
|
||||
if((strncmp(pOption->m_aCommand, "random_map", 11) == 0 || strncmp(pOption->m_aCommand, "random_unfinished_map", 22) == 0) && str_length(pReason) == 1 && pReason[0] >= '1' && pReason[0] <= '5')
|
||||
{
|
||||
int stars = pReason[0] - '1';
|
||||
str_format(aCmd, sizeof(aCmd), "%s %d", pOption->m_aCommand, stars);
|
||||
}
|
||||
else
|
||||
{
|
||||
str_format(aCmd, sizeof(aCmd), "%s", pOption->m_aCommand);
|
||||
}
|
||||
|
||||
m_LastMapVote = time_get();
|
||||
break;
|
||||
}
|
||||
|
@ -1746,6 +1757,10 @@ void CGameContext::ConRandomMap(IConsole::IResult *pResult, void *pUserData)
|
|||
int OurMap;
|
||||
char* pMapName;
|
||||
char pQuotedMapName[64];
|
||||
int stars = 0;
|
||||
|
||||
if (pResult->NumArguments())
|
||||
stars = pResult->GetInteger(0);
|
||||
|
||||
CVoteOptionServer *pOption = pSelf->m_pVoteOptionFirst;
|
||||
while(pOption)
|
||||
|
@ -1795,7 +1810,12 @@ void CGameContext::ConRandomMap(IConsole::IResult *pResult, void *pUserData)
|
|||
void CGameContext::ConRandomUnfinishedMap(IConsole::IResult *pResult, void *pUserData)
|
||||
{
|
||||
CGameContext *pSelf = (CGameContext *)pUserData;
|
||||
pSelf->m_pScore->RandomUnfinishedMap(pSelf->m_VoteCreator);
|
||||
|
||||
int stars = 0;
|
||||
if (pResult->NumArguments())
|
||||
stars = pResult->GetInteger(0);
|
||||
|
||||
pSelf->m_pScore->RandomUnfinishedMap(pSelf->m_VoteCreator, stars);
|
||||
}
|
||||
|
||||
void CGameContext::ConRestart(IConsole::IResult *pResult, void *pUserData)
|
||||
|
@ -2200,8 +2220,8 @@ void CGameContext::OnConsoleInit()
|
|||
Console()->Register("tune_zone_leave", "is", CFGFLAG_SERVER, ConTuneSetZoneMsgLeave, this, "which message to display on zone leave; use 0 for normal area");
|
||||
Console()->Register("pause_game", "", CFGFLAG_SERVER, ConPause, this, "Pause/unpause game");
|
||||
Console()->Register("change_map", "?r", CFGFLAG_SERVER|CFGFLAG_STORE, ConChangeMap, this, "Change map");
|
||||
Console()->Register("random_map", "", CFGFLAG_SERVER, ConRandomMap, this, "Random map");
|
||||
Console()->Register("random_unfinished_map", "", CFGFLAG_SERVER, ConRandomUnfinishedMap, this, "Random unfinished map");
|
||||
Console()->Register("random_map", "?i", CFGFLAG_SERVER, ConRandomMap, this, "Random map");
|
||||
Console()->Register("random_unfinished_map", "?i", CFGFLAG_SERVER, ConRandomUnfinishedMap, this, "Random unfinished map");
|
||||
Console()->Register("restart", "?i", CFGFLAG_SERVER|CFGFLAG_STORE, ConRestart, this, "Restart in x seconds (0 = abort)");
|
||||
Console()->Register("broadcast", "r", CFGFLAG_SERVER, ConBroadcast, this, "Broadcast message");
|
||||
Console()->Register("say", "r", CFGFLAG_SERVER, ConSay, this, "Say in chat");
|
||||
|
|
|
@ -59,7 +59,7 @@ public:
|
|||
virtual void ShowTopPoints(IConsole::IResult *pResult, int ClientID, void *pUserData, int Debut=1) = 0;
|
||||
virtual void ShowPoints(int ClientID, const char* pName, bool Search=false) = 0;
|
||||
|
||||
virtual void RandomUnfinishedMap(int ClientID) = 0;
|
||||
virtual void RandomUnfinishedMap(int ClientID, int stars) = 0;
|
||||
|
||||
virtual void SaveTeam(int Team, const char* Code, int ClientID) = 0;
|
||||
virtual void LoadTeam(const char* Code, int ClientID) = 0;
|
||||
|
|
|
@ -321,7 +321,7 @@ void CFileScore::ShowPoints(int ClientID, const char* pName, bool Search)
|
|||
GameServer()->SendChatTarget(ClientID, aBuf);
|
||||
}
|
||||
|
||||
void CFileScore::RandomUnfinishedMap(int ClientID)
|
||||
void CFileScore::RandomUnfinishedMap(int ClientID, int stars)
|
||||
{
|
||||
char aBuf[512];
|
||||
str_format(aBuf, sizeof(aBuf), "Random unfinished map not supported in file based servers");
|
||||
|
|
|
@ -79,7 +79,7 @@ public:
|
|||
|
||||
virtual void ShowTopPoints(IConsole::IResult *pResult, int ClientID, void *pUserData, int Debut);
|
||||
virtual void ShowPoints(int ClientID, const char* pName, bool Search);
|
||||
virtual void RandomUnfinishedMap(int ClientID);
|
||||
virtual void RandomUnfinishedMap(int ClientID, int stars);
|
||||
virtual void SaveTeam(int Team, const char* Code, int ClientID);
|
||||
virtual void LoadTeam(const char* Code, int ClientID);
|
||||
};
|
||||
|
|
|
@ -1477,7 +1477,10 @@ void CSqlScore::RandomUnfinishedMapThread(void *pUser)
|
|||
pData->m_pSqlData->ClearString(pData->m_aName);
|
||||
|
||||
char aBuf[512];
|
||||
str_format(aBuf, sizeof(aBuf), "select * from %s_maps where Server = \"%s\" and not exists (select * from %s_race where Name = \"%s\" and %s_race.Map = %s_maps.Map) order by RAND() limit 1;", pData->m_pSqlData->m_pPrefix, g_Config.m_SvServerType, pData->m_pSqlData->m_pPrefix, pData->m_aName, pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_pPrefix);
|
||||
if(pData->m_Num)
|
||||
str_format(aBuf, sizeof(aBuf), "select * from %s_maps where Server = \"%s\" and Stars = \"%d\" and not exists (select * from %s_race where Name = \"%s\" and %s_race.Map = %s_maps.Map) order by RAND() limit 1;", pData->m_pSqlData->m_pPrefix, g_Config.m_SvServerType, pData->m_Num, pData->m_pSqlData->m_pPrefix, pData->m_aName, pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_pPrefix);
|
||||
else
|
||||
str_format(aBuf, sizeof(aBuf), "select * from %s_maps where Server = \"%s\" and not exists (select * from %s_race where Name = \"%s\" and %s_race.Map = %s_maps.Map) order by RAND() limit 1;", pData->m_pSqlData->m_pPrefix, g_Config.m_SvServerType, pData->m_pSqlData->m_pPrefix, pData->m_aName, pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_pPrefix);
|
||||
pData->m_pSqlData->m_pResults = pData->m_pSqlData->m_pStatement->executeQuery(aBuf);
|
||||
|
||||
if(pData->m_pSqlData->m_pResults->rowsCount() != 1)
|
||||
|
@ -1516,9 +1519,10 @@ void CSqlScore::RandomUnfinishedMapThread(void *pUser)
|
|||
lock_release(gs_SqlLock);
|
||||
}
|
||||
|
||||
void CSqlScore::RandomUnfinishedMap(int ClientID)
|
||||
void CSqlScore::RandomUnfinishedMap(int ClientID, int stars)
|
||||
{
|
||||
CSqlScoreData *Tmp = new CSqlScoreData();
|
||||
Tmp->m_Num = stars;
|
||||
Tmp->m_ClientID = ClientID;
|
||||
str_copy(Tmp->m_aName, GameServer()->Server()->ClientName(ClientID), MAX_NAME_LENGTH);
|
||||
Tmp->m_pSqlData = this;
|
||||
|
|
|
@ -89,7 +89,7 @@ public:
|
|||
virtual void ShowPoints(int ClientID, const char* pName, bool Search = false);
|
||||
virtual void ShowTopPoints(IConsole::IResult *pResult, int ClientID,
|
||||
void *pUserData, int Debut = 1);
|
||||
virtual void RandomUnfinishedMap(int ClientID);
|
||||
virtual void RandomUnfinishedMap(int ClientID, int stars);
|
||||
virtual void SaveTeam(int Team, const char* Code, int ClientID);
|
||||
virtual void LoadTeam(const char* Code, int ClientID);
|
||||
static void agoTimeToString(int agoTime, char agoString[]);
|
||||
|
|
Loading…
Reference in a new issue