mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Add random_unfinished_map
This commit is contained in:
parent
94c3547b0f
commit
a7329d0a14
|
@ -1053,7 +1053,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) && 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", 10) == 0 || strncmp(pOption->m_aCommand, "random_unfinished_map", 10) == 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()));
|
||||
|
@ -1769,6 +1769,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(pResult->m_ClientID);
|
||||
}
|
||||
|
||||
void CGameContext::ConRestart(IConsole::IResult *pResult, void *pUserData)
|
||||
{
|
||||
CGameContext *pSelf = (CGameContext *)pUserData;
|
||||
|
@ -2171,7 +2177,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|CFGFLAG_STORE, ConRandomMap, this, "Random 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("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");
|
||||
|
|
|
@ -66,6 +66,7 @@ class CGameContext : public IGameServer
|
|||
static void ConPause(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConChangeMap(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConRandomMap(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConRandomUnfinishedMap(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConRestart(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConBroadcast(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConSay(IConsole::IResult *pResult, void *pUserData);
|
||||
|
|
|
@ -58,6 +58,8 @@ 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;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -320,3 +320,10 @@ void CFileScore::ShowPoints(int ClientID, const char* pName, bool Search)
|
|||
str_format(aBuf, sizeof(aBuf), "Points not supported in file based servers");
|
||||
GameServer()->SendChatTarget(ClientID, aBuf);
|
||||
}
|
||||
|
||||
void CFileScore::RandomUnfinishedMap(int ClientID)
|
||||
{
|
||||
char aBuf[512];
|
||||
str_format(aBuf, sizeof(aBuf), "Random unfinished map not supported in file based servers");
|
||||
GameServer()->SendChatTarget(ClientID, aBuf);
|
||||
}
|
||||
|
|
|
@ -79,6 +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);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1431,4 +1431,72 @@ void CSqlScore::ShowTopPoints(IConsole::IResult *pResult, int ClientID, void *pU
|
|||
#endif
|
||||
}
|
||||
|
||||
void CSqlScore::RandomUnfinishedMapThread(void *pUser)
|
||||
{
|
||||
lock_wait(gs_SqlLock);
|
||||
|
||||
CSqlScoreData *pData = (CSqlScoreData *)pUser;
|
||||
|
||||
// Connect to database
|
||||
if(pData->m_pSqlData->Connect())
|
||||
{
|
||||
try
|
||||
{
|
||||
char originalName[MAX_NAME_LENGTH];
|
||||
strcpy(originalName,pData->m_aName);
|
||||
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);
|
||||
pData->m_pSqlData->m_pResults = pData->m_pSqlData->m_pStatement->executeQuery(aBuf);
|
||||
|
||||
if(pData->m_pSqlData->m_pResults->rowsCount() != 1)
|
||||
{
|
||||
pData->m_pSqlData->GameServer()->SendChatTarget(pData->m_ClientID, "You have no unfinished maps on this server!");
|
||||
}
|
||||
else
|
||||
{
|
||||
pData->m_pSqlData->m_pResults->next();
|
||||
char aMap[128];
|
||||
strcpy(aMap, pData->m_pSqlData->m_pResults->getString("Map").c_str());
|
||||
|
||||
str_format(aBuf, sizeof(aBuf), "change_map \"%s\"", aMap);
|
||||
pData->m_pSqlData->GameServer()->Console()->ExecuteLine(aBuf);
|
||||
}
|
||||
|
||||
dbg_msg("SQL", "Voting random unfinished map done");
|
||||
|
||||
// delete results and statement
|
||||
delete pData->m_pSqlData->m_pResults;
|
||||
}
|
||||
catch (sql::SQLException &e)
|
||||
{
|
||||
char aBuf[256];
|
||||
str_format(aBuf, sizeof(aBuf), "MySQL Error: %s", e.what());
|
||||
dbg_msg("SQL", aBuf);
|
||||
dbg_msg("SQL", "ERROR: Could not vote random unfinished map");
|
||||
}
|
||||
|
||||
// disconnect from database
|
||||
pData->m_pSqlData->Disconnect();
|
||||
}
|
||||
|
||||
delete pData;
|
||||
|
||||
lock_release(gs_SqlLock);
|
||||
}
|
||||
|
||||
void CSqlScore::RandomUnfinishedMap(int ClientID)
|
||||
{
|
||||
CSqlScoreData *Tmp = new CSqlScoreData();
|
||||
Tmp->m_ClientID = ClientID;
|
||||
str_copy(Tmp->m_aName, GameServer()->Server()->ClientName(ClientID), MAX_NAME_LENGTH);
|
||||
Tmp->m_pSqlData = this;
|
||||
|
||||
void *RandomUnfinishedThread = thread_create(RandomUnfinishedMapThread, Tmp);
|
||||
#if defined(CONF_FAMILY_UNIX)
|
||||
pthread_detach((pthread_t)RandomUnfinishedThread);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -52,6 +52,7 @@ class CSqlScore: public IScore
|
|||
static void ShowTimesThread(void *pUser);
|
||||
static void ShowPointsThread(void *pUser);
|
||||
static void ShowTopPointsThread(void *pUser);
|
||||
static void RandomUnfinishedMapThread(void *pUser);
|
||||
|
||||
void Init();
|
||||
|
||||
|
@ -86,6 +87,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);
|
||||
static void agoTimeToString(int agoTime, char agoString[]);
|
||||
};
|
||||
|
||||
|
|
|
@ -129,6 +129,8 @@ MACRO_CONFIG_INT(SvMapUpdateRate, sv_mapupdaterate, 5, 1, 100, CFGFLAG_SERVER, "
|
|||
|
||||
MACRO_CONFIG_INT(SvSkinStealAction, sv_skinstealaction, 0, 0, 1, CFGFLAG_SERVER, "How to punish skin stealing (currently only 1 = force pinky)")
|
||||
|
||||
MACRO_CONFIG_STR(SvServerType, sv_server_type, 64, "none", CFGFLAG_SERVER, "Type of the server (novice, moderate, ...)")
|
||||
|
||||
// debug
|
||||
#ifdef CONF_DEBUG // this one can crash the server if not used correctly
|
||||
MACRO_CONFIG_INT(DbgDummies, dbg_dummies, 0, 0, 15, CFGFLAG_SERVER, "")
|
||||
|
|
Loading…
Reference in a new issue