mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
chat commands redirect to rcon and vice versa by heinrich5991
This commit is contained in:
parent
ac3ce7589a
commit
332fb1de09
|
@ -54,12 +54,20 @@ public:
|
|||
virtual void Chain(const char *pName, FChainCommandCallback pfnChainFunc, void *pUser) = 0;
|
||||
virtual void StoreCommands(bool Store, int ClientId) = 0;
|
||||
|
||||
virtual void ExecuteLine(const char *Sptr, const int ClientLevel, const int ClientId) = 0;
|
||||
virtual void ExecuteLineStroked(int Stroke, const char *pStr, const int ClientLevel, const int ClientId) = 0;
|
||||
virtual void ExecuteFile(const char *pFilename) = 0;
|
||||
virtual void ExecuteLine(const char *Sptr, const int ClientLevel, const int ClientId, FPrintCallback pfnAlternativePrintCallback = 0, void *pUserData = 0, FPrintCallback pfnAlternativePrintResponseCallback = 0, void *pResponseUserData = 0) = 0;
|
||||
virtual void ExecuteLineStroked(int Stroke, const char *pStr, const int ClientLevel, const int ClientId, FPrintCallback pfnAlternativePrintCallback = 0, void *pUserData = 0, FPrintCallback pfnAlternativePrintResponseCallback = 0, void *pResponseUserData = 0) = 0;
|
||||
virtual void ExecuteFile(const char *pFilename, FPrintCallback pfnAlternativePrintCallback = 0, void *pUserData = 0, FPrintCallback pfnAlternativePrintResponseCallback = 0, void *pResponseUserData = 0) = 0;
|
||||
|
||||
virtual void RegisterPrintCallback(FPrintCallback pfnPrintCallback, void *pUserData) = 0;
|
||||
virtual void RegisterAlternativePrintCallback(FPrintCallback pfnAlternativePrintCallback, void *pAlternativeUserData) = 0;
|
||||
virtual void ReleaseAlternativePrintCallback() = 0;
|
||||
|
||||
virtual void RegisterPrintResponseCallback(FPrintCallback pfnPrintResponseCallback, void *pUserData) = 0;
|
||||
virtual void RegisterAlternativePrintResponseCallback(FPrintCallback pfnAlternativePrintCallback, void *pAlternativeUserData) = 0;
|
||||
virtual void ReleaseAlternativePrintResponseCallback() = 0;
|
||||
|
||||
virtual void Print(int Level, const char *pFrom, const char *pStr) = 0;
|
||||
virtual void PrintResponse(int Level, const char *pFrom, const char *pStr) = 0;
|
||||
};
|
||||
|
||||
extern IConsole *CreateConsole(int FlagMask);
|
||||
|
|
|
@ -618,6 +618,23 @@ void CServer::SendRconLineAuthed(const char *pLine, void *pUser)
|
|||
ReentryGuard--;
|
||||
}
|
||||
|
||||
void CServer::SendRconResponse(const char *pLine, void *pUser)
|
||||
{
|
||||
RconResponseInfo *pInfo = (RconResponseInfo *)pUser;
|
||||
CServer *pThis = pInfo->m_Server;
|
||||
static volatile int ReentryGuard = 0;
|
||||
|
||||
if(ReentryGuard)
|
||||
return;
|
||||
|
||||
ReentryGuard++;
|
||||
|
||||
if(pThis->m_aClients[pInfo->m_ClientId].m_State != CClient::STATE_EMPTY)
|
||||
pThis->SendRconLine(pInfo->m_ClientId, pLine);
|
||||
|
||||
ReentryGuard--;
|
||||
}
|
||||
|
||||
void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
||||
{
|
||||
int ClientId = pPacket->m_ClientID;
|
||||
|
@ -795,11 +812,23 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
|
||||
if(Unpacker.Error() == 0/* && m_aClients[ClientId].m_Authed*/)
|
||||
{
|
||||
Console()->RegisterAlternativePrintCallback(0, 0);
|
||||
|
||||
char aBuf[256];
|
||||
if(m_aClients[ClientId].m_Authed > 0)
|
||||
if(m_aClients[ClientId].m_Authed >= 0)
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "'%s' ClientId=%d Level=%d Rcon='%s'", ClientName(ClientId), ClientId, m_aClients[ClientId].m_Authed, pCmd); Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBuf); m_RconClientId = ClientId;
|
||||
Console()->ExecuteLine(pCmd, m_aClients[ClientId].m_Authed, ClientId);
|
||||
str_format(aBuf, sizeof(aBuf), "'%s' ClientId=%d Level=%d Rcon='%s'", ClientName(ClientId), ClientId, m_aClients[ClientId].m_Authed, pCmd);
|
||||
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBuf);
|
||||
|
||||
Console()->ReleaseAlternativePrintCallback();
|
||||
|
||||
m_RconClientId = ClientId;
|
||||
|
||||
RconResponseInfo Info;
|
||||
Info.m_Server = this;
|
||||
Info.m_ClientId = ClientId;
|
||||
|
||||
Console()->ExecuteLine(pCmd, m_aClients[ClientId].m_Authed, ClientId, SendRconLineAuthed, this, SendRconResponse, &Info);
|
||||
m_RconClientId = -1;
|
||||
}
|
||||
else
|
||||
|
@ -1153,6 +1182,7 @@ int CServer::Run()
|
|||
|
||||
//
|
||||
Console()->RegisterPrintCallback(SendRconLineAuthed, this);
|
||||
Console()->RegisterPrintResponseCallback(SendRconLineAuthed, this);
|
||||
|
||||
// load map
|
||||
if(!LoadMap(g_Config.m_SvMap))
|
||||
|
@ -1341,7 +1371,7 @@ void CServer::ConKick(IConsole::IResult *pResult, void *pUser, int ClientId)
|
|||
if(ClientId1 < 0 || ClientId1 >= MAX_CLIENTS || ((CServer *)pUser)->m_aClients[ClientId1].m_State == CClient::STATE_EMPTY)
|
||||
{
|
||||
str_format(buf, sizeof(buf),"Invalid Client ID %d", ClientId1);
|
||||
((CServer *)pUser)->SendRconLine(ClientId,buf);
|
||||
((CServer *)pUser)->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", buf);
|
||||
}
|
||||
else if (ClientId == -1 || ((CServer *)pUser)->m_aClients[ClientId].m_Authed > ((CServer *)pUser)->m_aClients[ClientId1].m_Authed)
|
||||
{
|
||||
|
@ -1382,7 +1412,7 @@ void CServer::ConBan(IConsole::IResult *pResult, void *pUser, int ClientId1)
|
|||
Addr.port = AddrCheck.port = 0;
|
||||
if(net_addr_comp(&Addr, &AddrCheck) == 0)
|
||||
{
|
||||
pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "you can't ban yourself");
|
||||
pServer->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "server", "you can't ban yourself");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1394,7 +1424,7 @@ void CServer::ConBan(IConsole::IResult *pResult, void *pUser, int ClientId1)
|
|||
{
|
||||
if (((CServer *)pUser)->m_aClients[ClientId1].m_Authed <= ((CServer *)pUser)->m_aClients[i].m_Authed)
|
||||
{
|
||||
pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "you can't ban an a player with the higher or same rank!");
|
||||
pServer->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "server", "you can't ban an a player with the higher or same rank!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1409,12 +1439,12 @@ void CServer::ConBan(IConsole::IResult *pResult, void *pUser, int ClientId1)
|
|||
|
||||
if(ClientId < 0 || ClientId >= MAX_CLIENTS || pServer->m_aClients[ClientId].m_State == CClient::STATE_EMPTY)
|
||||
{
|
||||
pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid client id");
|
||||
pServer->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid client id");
|
||||
return;
|
||||
}
|
||||
else if(pServer->m_RconClientId == ClientId)
|
||||
{
|
||||
pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "you can't ban yourself");
|
||||
pServer->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "server", "you can't ban yourself");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1423,7 +1453,7 @@ void CServer::ConBan(IConsole::IResult *pResult, void *pUser, int ClientId1)
|
|||
}
|
||||
else
|
||||
{
|
||||
pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid network address to ban");
|
||||
pServer->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid network address to ban");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1455,7 +1485,7 @@ void CServer::ConUnban(IConsole::IResult *pResult, void *pUser, int ClientId)
|
|||
int BanIndex = str_toint(pStr);
|
||||
CNetServer::CBanInfo Info;
|
||||
if(BanIndex < 0 || !pServer->m_NetServer.BanGet(BanIndex, &Info))
|
||||
pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid ban index");
|
||||
pServer->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid ban index");
|
||||
else if(!pServer->BanRemove(Info.m_Addr))
|
||||
{
|
||||
char aBuf[256];
|
||||
|
@ -1464,7 +1494,7 @@ void CServer::ConUnban(IConsole::IResult *pResult, void *pUser, int ClientId)
|
|||
}
|
||||
}
|
||||
else
|
||||
pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid network address");
|
||||
pServer->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid network address");
|
||||
}
|
||||
|
||||
void CServer::ConBans(IConsole::IResult *pResult, void *pUser, int ClientId)
|
||||
|
@ -1489,10 +1519,10 @@ void CServer::ConBans(IConsole::IResult *pResult, void *pUser, int ClientId)
|
|||
unsigned t = Info.m_Expires - Now;
|
||||
str_format(aBuf, sizeof(aBuf), "#%d %d.%d.%d.%d for %d minutes and %d seconds", i, Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3], t/60, t%60);
|
||||
}
|
||||
pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf);
|
||||
pServer->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf);
|
||||
}
|
||||
str_format(aBuf, sizeof(aBuf), "%d ban(s)", Num);
|
||||
pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf);
|
||||
pServer->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf);
|
||||
}
|
||||
|
||||
void CServer::ConStatus(IConsole::IResult *pResult, void *pUser, int ClientId)
|
||||
|
@ -1514,7 +1544,7 @@ void CServer::ConStatus(IConsole::IResult *pResult, void *pUser, int ClientId)
|
|||
else
|
||||
str_format(aBuf, sizeof(aBuf), "id=%d addr=%d.%d.%d.%d:%d connecting",
|
||||
i, Addr.ip[0], Addr.ip[1], Addr.ip[2], Addr.ip[3], Addr.port);
|
||||
pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf);
|
||||
pServer->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1527,8 +1557,9 @@ void CServer::ConShutdown(IConsole::IResult *pResult, void *pUser, int ClientId)
|
|||
void CServer::ConRecord(IConsole::IResult *pResult, void *pUser, int ClientId)
|
||||
{
|
||||
char aFilename[512];
|
||||
CServer *pServer = (CServer *)pUser;
|
||||
str_format(aFilename, sizeof(aFilename), "demos/%s.demo", pResult->GetString(0));
|
||||
((CServer *)pUser)->m_DemoRecorder.Start(((CServer *)pUser)->Storage(), ((CServer *)pUser)->Console(), aFilename, ((CServer *)pUser)->GameServer()->NetVersion(), ((CServer *)pUser)->m_aCurrentMap, ((CServer *)pUser)->m_CurrentMapCrc, "server");
|
||||
pServer->m_DemoRecorder.Start(pServer->Storage(), pServer->Console(), aFilename, pServer->GameServer()->NetVersion(), pServer->m_aCurrentMap, pServer->m_CurrentMapCrc, "server");
|
||||
}
|
||||
|
||||
void CServer::ConStopRecord(IConsole::IResult *pResult, void *pUser, int ClientId)
|
||||
|
|
|
@ -170,6 +170,13 @@ public:
|
|||
void SendMap(int ClientId);
|
||||
void SendRconLine(int ClientId, const char *pLine);
|
||||
static void SendRconLineAuthed(const char *pLine, void *pUser);
|
||||
static void SendRconResponse(const char *pLine, void *pUser);
|
||||
|
||||
struct RconResponseInfo
|
||||
{
|
||||
CServer *m_Server;
|
||||
int m_ClientId;
|
||||
};
|
||||
|
||||
void ProcessClientPacket(CNetChunk *pPacket);
|
||||
|
||||
|
|
|
@ -157,6 +157,23 @@ void CConsole::RegisterPrintCallback(FPrintCallback pfnPrintCallback, void *pUse
|
|||
m_pPrintCallbackUserdata = pUserData;
|
||||
}
|
||||
|
||||
void CConsole::RegisterAlternativePrintCallback(FPrintCallback pfnAlternativePrintCallback, void *pAlternativeUserData)
|
||||
{
|
||||
while (m_pfnAlternativePrintCallback != pfnAlternativePrintCallback && m_PrintUsed)
|
||||
; // wait for other threads to finish their commands, TODO: implement this with LOCK
|
||||
|
||||
m_pfnAlternativePrintCallback = pfnAlternativePrintCallback;
|
||||
m_pAlternativePrintCallbackUserdata = pAlternativeUserData;
|
||||
|
||||
m_PrintUsed++;
|
||||
}
|
||||
|
||||
void CConsole::ReleaseAlternativePrintCallback()
|
||||
{
|
||||
m_PrintUsed--;
|
||||
}
|
||||
|
||||
|
||||
void CConsole::Print(int Level, const char *pFrom, const char *pStr)
|
||||
{
|
||||
dbg_msg(pFrom ,"%s", pStr);
|
||||
|
@ -164,11 +181,53 @@ void CConsole::Print(int Level, const char *pFrom, const char *pStr)
|
|||
{
|
||||
char aBuf[1024];
|
||||
str_format(aBuf, sizeof(aBuf), "[%s]: %s", pFrom, pStr);
|
||||
m_pfnPrintCallback(aBuf, m_pPrintCallbackUserdata);
|
||||
if (!m_pfnAlternativePrintCallback || m_PrintUsed == 0)
|
||||
m_pfnPrintCallback(aBuf, m_pPrintCallbackUserdata);
|
||||
else
|
||||
m_pfnAlternativePrintCallback(aBuf, m_pAlternativePrintCallbackUserdata);
|
||||
}
|
||||
}
|
||||
|
||||
void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, const int ClientLevel, const int ClientId)
|
||||
void CConsole::RegisterPrintResponseCallback(FPrintCallback pfnPrintResponseCallback, void *pUserData)
|
||||
{
|
||||
m_pfnPrintResponseCallback = pfnPrintResponseCallback;
|
||||
m_pPrintResponseCallbackUserdata = pUserData;
|
||||
}
|
||||
|
||||
void CConsole::RegisterAlternativePrintResponseCallback(FPrintCallback pfnAlternativePrintResponseCallback, void *pAlternativeUserData)
|
||||
{
|
||||
while (m_pfnAlternativePrintResponseCallback != pfnAlternativePrintResponseCallback && m_PrintResponseUsed)
|
||||
; // wait for other threads to finish their commands, TODO: implement this with LOCK
|
||||
|
||||
m_pfnAlternativePrintResponseCallback = pfnAlternativePrintResponseCallback;
|
||||
m_pAlternativePrintResponseCallbackUserdata = pAlternativeUserData;
|
||||
|
||||
m_PrintResponseUsed++;
|
||||
}
|
||||
|
||||
void CConsole::ReleaseAlternativePrintResponseCallback()
|
||||
{
|
||||
m_PrintResponseUsed--;
|
||||
}
|
||||
|
||||
|
||||
void CConsole::PrintResponse(int Level, const char *pFrom, const char *pStr)
|
||||
{
|
||||
dbg_msg(pFrom ,"%s", pStr);
|
||||
if (Level <= g_Config.m_ConsoleOutputLevel && m_pfnPrintResponseCallback)
|
||||
{
|
||||
char aBuf[1024];
|
||||
str_format(aBuf, sizeof(aBuf), "[%s]: %s", pFrom, pStr);
|
||||
if (!m_pfnAlternativePrintResponseCallback || m_PrintResponseUsed == 0)
|
||||
m_pfnPrintResponseCallback(aBuf, m_pPrintResponseCallbackUserdata);
|
||||
else
|
||||
m_pfnAlternativePrintResponseCallback(aBuf, m_pAlternativePrintResponseCallbackUserdata);
|
||||
}
|
||||
}
|
||||
|
||||
void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, const int ClientLevel, const int ClientId,
|
||||
FPrintCallback pfnAlternativePrintCallback, void *pUserData,
|
||||
FPrintCallback pfnAlternativePrintResponseCallback, void *pResponseUserData)
|
||||
{
|
||||
CResult *pResult = new(&m_ExecutionQueue.m_pLast->m_Result) CResult;
|
||||
|
||||
|
@ -220,9 +279,13 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, const int Client
|
|||
{
|
||||
if(ParseArgs(pResult, pCommand->m_pParams))
|
||||
{
|
||||
RegisterAlternativePrintResponseCallback(pfnAlternativePrintResponseCallback, pResponseUserData);
|
||||
|
||||
char aBuf[256];
|
||||
str_format(aBuf, sizeof(aBuf), "Invalid arguments... Usage: %s %s", pCommand->m_pName, pCommand->m_pParams);
|
||||
Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf);
|
||||
PrintResponse(OUTPUT_LEVEL_STANDARD, "Console", aBuf);
|
||||
|
||||
ReleaseAlternativePrintResponseCallback();
|
||||
}
|
||||
else if(m_StoreCommands && pCommand->m_Flags&CFGFLAG_STORE)
|
||||
{
|
||||
|
@ -232,26 +295,42 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, const int Client
|
|||
}
|
||||
else if(pCommand->m_Level <= ClientLevel)
|
||||
{
|
||||
RegisterAlternativePrintCallback(pfnAlternativePrintCallback, pUserData);
|
||||
RegisterAlternativePrintResponseCallback(pfnAlternativePrintResponseCallback, pResponseUserData);
|
||||
|
||||
pCommand->m_pfnCallback(pResult, pCommand->m_pUserData, ClientId);
|
||||
|
||||
ReleaseAlternativePrintResponseCallback();
|
||||
ReleaseAlternativePrintCallback();
|
||||
}
|
||||
else
|
||||
{
|
||||
RegisterAlternativePrintResponseCallback(pfnAlternativePrintResponseCallback, pResponseUserData);
|
||||
|
||||
char aBuf[256];
|
||||
if (pCommand->m_Level == 100 && ClientLevel < 100)
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "You can't use this command: %s", pCommand->m_pName);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "You have low level to use command: %s. Your level: %d. Need level: %d", pCommand->m_pName, ClientLevel, pCommand->m_Level);
|
||||
}
|
||||
Print(OUTPUT_LEVEL_STANDARD, "Console",aBuf);
|
||||
PrintResponse(OUTPUT_LEVEL_STANDARD, "Console", aBuf);
|
||||
|
||||
ReleaseAlternativePrintResponseCallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(Stroke)
|
||||
{
|
||||
RegisterAlternativePrintResponseCallback(pfnAlternativePrintResponseCallback, pResponseUserData);
|
||||
|
||||
char aBuf[256];
|
||||
str_format(aBuf, sizeof(aBuf), "No such command: %s.", pResult->m_pCommand);
|
||||
Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf);
|
||||
PrintResponse(OUTPUT_LEVEL_STANDARD, "Console", aBuf);
|
||||
|
||||
ReleaseAlternativePrintResponseCallback();
|
||||
}
|
||||
|
||||
pStr = pNextPart;
|
||||
|
@ -286,14 +365,20 @@ CConsole::CCommand *CConsole::FindCommand(const char *pName, int FlagMask)
|
|||
return 0x0;
|
||||
}
|
||||
|
||||
void CConsole::ExecuteLine(const char *pStr, const int ClientLevel, const int ClientId)
|
||||
void CConsole::ExecuteLine(const char *pStr, const int ClientLevel, const int ClientId,
|
||||
FPrintCallback pfnAlternativePrintCallback, void *pUserData,
|
||||
FPrintCallback pfnAlternativePrintResponseCallback, void *pResponseUserData)
|
||||
{
|
||||
CConsole::ExecuteLineStroked(1, pStr, ClientLevel, ClientId); // press it
|
||||
CConsole::ExecuteLineStroked(0, pStr, ClientLevel, ClientId); // then release it
|
||||
CConsole::ExecuteLineStroked(1, pStr, ClientLevel, ClientId,
|
||||
pfnAlternativePrintCallback, pUserData, pfnAlternativePrintResponseCallback, pResponseUserData); // press it
|
||||
CConsole::ExecuteLineStroked(0, pStr, ClientLevel, ClientId,
|
||||
pfnAlternativePrintCallback, pUserData, pfnAlternativePrintResponseCallback, pResponseUserData); // then release it
|
||||
}
|
||||
|
||||
|
||||
void CConsole::ExecuteFile(const char *pFilename)
|
||||
void CConsole::ExecuteFile(const char *pFilename,
|
||||
FPrintCallback pfnAlternativePrintCallback, void *pUserData,
|
||||
FPrintCallback pfnAlternativePrintResponseCallback, void *pResponseUserData)
|
||||
{
|
||||
// make sure that this isn't being executed already
|
||||
for(CExecFile *pCur = m_pFirstExec; pCur; pCur = pCur->m_pPrev)
|
||||
|
@ -321,19 +406,26 @@ void CConsole::ExecuteFile(const char *pFilename)
|
|||
char *pLine;
|
||||
CLineReader lr;
|
||||
|
||||
RegisterAlternativePrintCallback(pfnAlternativePrintCallback, pUserData);
|
||||
|
||||
str_format(aBuf, sizeof(aBuf), "executing '%s'", pFilename);
|
||||
Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf);
|
||||
lr.Init(File);
|
||||
ReleaseAlternativePrintCallback();
|
||||
|
||||
while((pLine = lr.Get()))
|
||||
ExecuteLine(pLine, 4, -1);
|
||||
ExecuteLine(pLine, 4, -1, pfnAlternativePrintCallback, pUserData, pfnAlternativePrintResponseCallback, pResponseUserData);
|
||||
|
||||
io_close(File);
|
||||
}
|
||||
else
|
||||
{
|
||||
RegisterAlternativePrintCallback(pfnAlternativePrintCallback, pUserData);
|
||||
|
||||
str_format(aBuf, sizeof(aBuf), "failed to open '%s'", pFilename);
|
||||
Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf);
|
||||
|
||||
ReleaseAlternativePrintCallback();
|
||||
}
|
||||
|
||||
m_pFirstExec = pPrev;
|
||||
|
@ -387,7 +479,7 @@ static void IntVariableCommand(IConsole::IResult *pResult, void *pUserData, int
|
|||
{
|
||||
char aBuf[1024];
|
||||
str_format(aBuf, sizeof(aBuf), "Value: %d", *(pData->m_pVariable));
|
||||
pData->m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", aBuf);
|
||||
pData->m_pConsole->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "Console", aBuf);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -396,33 +488,33 @@ static void StrVariableCommand(IConsole::IResult *pResult, void *pUserData, int
|
|||
CStrVariableData *pData = (CStrVariableData *)pUserData;
|
||||
|
||||
if(pResult->NumArguments())
|
||||
{
|
||||
const char *pString = pResult->GetString(0);
|
||||
if(!str_utf8_check(pString))
|
||||
{
|
||||
char Temp[4];
|
||||
int Length = 0;
|
||||
while(*pString)
|
||||
{
|
||||
int Size = str_utf8_encode(Temp, static_cast<const unsigned char>(*pString++));
|
||||
if(Length+Size < pData->m_MaxSize)
|
||||
{
|
||||
mem_copy(pData->m_pStr+Length, &Temp, Size);
|
||||
Length += Size;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
pData->m_pStr[Length] = 0;
|
||||
}
|
||||
else
|
||||
str_copy(pData->m_pStr, pString, pData->m_MaxSize);
|
||||
}
|
||||
{
|
||||
const char *pString = pResult->GetString(0);
|
||||
if(!str_utf8_check(pString))
|
||||
{
|
||||
char Temp[4];
|
||||
int Length = 0;
|
||||
while(*pString)
|
||||
{
|
||||
int Size = str_utf8_encode(Temp, static_cast<const unsigned char>(*pString++));
|
||||
if(Length+Size < pData->m_MaxSize)
|
||||
{
|
||||
mem_copy(pData->m_pStr+Length, &Temp, Size);
|
||||
Length += Size;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
pData->m_pStr[Length] = 0;
|
||||
}
|
||||
else
|
||||
str_copy(pData->m_pStr, pString, pData->m_MaxSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
char aBuf[1024];
|
||||
str_format(aBuf, sizeof(aBuf), "Value: %s", pData->m_pStr);
|
||||
pData->m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Console", aBuf);
|
||||
pData->m_pConsole->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "Console", aBuf);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -435,8 +527,18 @@ CConsole::CConsole(int FlagMask)
|
|||
m_ExecutionQueue.Reset();
|
||||
m_pFirstCommand = 0;
|
||||
m_pFirstExec = 0;
|
||||
|
||||
m_pPrintCallbackUserdata = 0;
|
||||
m_pfnPrintCallback = 0;
|
||||
m_pAlternativePrintCallbackUserdata = 0;
|
||||
m_pfnAlternativePrintCallback = 0;
|
||||
m_PrintUsed = 0;
|
||||
|
||||
m_pPrintResponseCallbackUserdata = 0;
|
||||
m_pfnPrintResponseCallback = 0;
|
||||
m_pAlternativePrintResponseCallbackUserdata = 0;
|
||||
m_pfnAlternativePrintResponseCallback = 0;
|
||||
m_PrintResponseUsed = 0;
|
||||
|
||||
m_pStorage = 0;
|
||||
|
||||
|
@ -509,9 +611,11 @@ void CConsole::Chain(const char *pName, FChainCommandCallback pfnChainFunc, void
|
|||
|
||||
if(!pCommand)
|
||||
{
|
||||
RegisterAlternativePrintCallback(0, 0);
|
||||
char aBuf[256];
|
||||
str_format(aBuf, sizeof(aBuf), "failed to chain '%s'", pName);
|
||||
Print(IConsole::OUTPUT_LEVEL_DEBUG, "console", aBuf);
|
||||
ReleaseAlternativePrintCallback();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,11 +44,20 @@ class CConsole : public IConsole
|
|||
static void Con_Echo(IResult *pResult, void *pUserData, int ClientId);
|
||||
static void Con_Exec(IResult *pResult, void *pUserData, int ClientId);
|
||||
|
||||
void ExecuteFileRecurse(const char *pFilename);
|
||||
void ExecuteLineStroked(int Stroke, const char *pStr, const int ClientLevel, const int ClientId);
|
||||
void ExecuteFileRecurse(const char *pFilename, FPrintCallback pfnAlternativePrintCallback = 0, void *pUserData = 0, FPrintCallback pfnAlternativePrintResponseCallback = 0, void *pResponseUserData = 0);
|
||||
virtual void ExecuteLineStroked(int Stroke, const char *pStr, const int ClientLevel, const int ClientId, FPrintCallback pfnAlternativePrintCallback = 0, void *pUserData = 0, FPrintCallback pfnAlternativePrintResponseCallback = 0, void *pResponseUserData = 0);
|
||||
|
||||
FPrintCallback m_pfnPrintCallback;
|
||||
void *m_pPrintCallbackUserdata;
|
||||
FPrintCallback m_pfnAlternativePrintCallback;
|
||||
void *m_pAlternativePrintCallbackUserdata;
|
||||
int m_PrintUsed;
|
||||
|
||||
FPrintCallback m_pfnPrintResponseCallback;
|
||||
void *m_pPrintResponseCallbackUserdata;
|
||||
FPrintCallback m_pfnAlternativePrintResponseCallback;
|
||||
void *m_pAlternativePrintResponseCallbackUserdata;
|
||||
int m_PrintResponseUsed;
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -119,11 +128,19 @@ public:
|
|||
virtual void Chain(const char *pName, FChainCommandCallback pfnChainFunc, void *pUser);
|
||||
virtual void StoreCommands(bool Store, int ClientId);
|
||||
|
||||
virtual void ExecuteLine(const char *pStr, const int ClientLevel, const int ClientId);
|
||||
virtual void ExecuteFile(const char *pFilename);
|
||||
virtual void ExecuteLine(const char *pStr, const int ClientLevel, const int ClientId, FPrintCallback pfnAlternativePrintCallback = 0, void *pUserData = 0, FPrintCallback pfnAlternativePrintResponseCallback = 0, void *pResponseUserData = 0);
|
||||
virtual void ExecuteFile(const char *pFilename, FPrintCallback pfnAlternativePrintCallback = 0, void *pUserData = 0, FPrintCallback pfnAlternativePrintResponseCallback = 0, void *pResponseUserData = 0);
|
||||
|
||||
virtual void RegisterPrintCallback(FPrintCallback pfnPrintCallback, void *pUserData);
|
||||
virtual void RegisterAlternativePrintCallback(FPrintCallback pfnAlternativePrintCallback, void *pAlternativeUserData);
|
||||
virtual void ReleaseAlternativePrintCallback();
|
||||
|
||||
virtual void RegisterPrintResponseCallback(FPrintCallback pfnPrintResponseCallback, void *pUserData);
|
||||
virtual void RegisterAlternativePrintResponseCallback(FPrintCallback pfnAlternativePrintCallback, void *pAlternativeUserData);
|
||||
virtual void ReleaseAlternativePrintResponseCallback();
|
||||
|
||||
virtual void Print(int Level, const char *pFrom, const char *pStr);
|
||||
virtual void PrintResponse(int Level, const char *pFrom, const char *pStr);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -114,6 +114,20 @@ class CGameContext : public IGameServer
|
|||
static void ConInvis(IConsole::IResult *pResult, void *pUserData, int ClientId);
|
||||
static void ConVis(IConsole::IResult *pResult, void *pUserData, int ClientId);
|
||||
|
||||
static void ConCredits(IConsole::IResult *pResult, void *pUserData, int ClientId);
|
||||
static void ConInfo(IConsole::IResult *pResult, void *pUserData, int ClientId);
|
||||
static void ConCmdList(IConsole::IResult *pResult, void *pUserData, int ClientId);
|
||||
static void ConHelp(IConsole::IResult *pResult, void *pUserData, int ClientId);
|
||||
static void ConFlags(IConsole::IResult *pResult, void *pUserData, int ClientId);
|
||||
static void ConRules(IConsole::IResult *pResult, void *pUserData, int ClientId);
|
||||
static void ConKill(IConsole::IResult *pResult, void *pUserData, int ClientId);
|
||||
static void ConTogglePause(IConsole::IResult *pResult, void *pUserData, int ClientId);
|
||||
static void ConTop5(IConsole::IResult *pResult, void *pUserData, int ClientId);
|
||||
static void ConRank(IConsole::IResult *pResult, void *pUserData, int ClientId);
|
||||
static void ConBroadTime(IConsole::IResult *pResult, void *pUserData, int ClientId);
|
||||
static void ConJoinTeam(IConsole::IResult *pResult, void *pUserData, int ClientId);
|
||||
static void ConToggleFly(IConsole::IResult *pResult, void *pUserData, int ClientId);
|
||||
|
||||
CGameContext(int Resetting);
|
||||
void Construct(int Resetting);
|
||||
|
||||
|
@ -148,7 +162,7 @@ public:
|
|||
void SendVoteStatus(int ClientId, int Total, int Yes, int No);
|
||||
void AbortVoteKickOnDisconnect(int ClientId);
|
||||
|
||||
bool CheatsAvailable(int ClientId);
|
||||
bool CheatsAvailable(IConsole *pConsole, int ClientId);
|
||||
|
||||
bool m_VoteKick;
|
||||
int m_VoteCreator;
|
||||
|
@ -228,6 +242,14 @@ public:
|
|||
void SendWeaponPickup(int ClientId, int Weapon);
|
||||
void SendBroadcast(const char *pText, int ClientId);
|
||||
|
||||
static void SendChatResponse(const char *pLine, void *pUser);
|
||||
static void SendChatResponseAll(const char *pLine, void *pUser);
|
||||
|
||||
struct ChatResponseInfo
|
||||
{
|
||||
CGameContext *m_GameContext;
|
||||
int m_To;
|
||||
};
|
||||
|
||||
//
|
||||
void CheckPureTuning();
|
||||
|
|
|
@ -226,7 +226,7 @@ void CFileScore::SaveScore(int ClientID, float Time, CCharacter *pChar)
|
|||
void CFileScore::ShowTop5(int ClientID, int Debut)
|
||||
{
|
||||
char aBuf[512];
|
||||
GameServer()->SendChatTarget(ClientID, "----------- Top 5 -----------");
|
||||
GameServer()->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "top5", "----------- Top 5 -----------");
|
||||
for(int i = 0; i < 5; i++)
|
||||
{
|
||||
if(i+Debut > m_Top.size())
|
||||
|
@ -234,9 +234,9 @@ void CFileScore::ShowTop5(int ClientID, int Debut)
|
|||
CPlayerScore *r = &m_Top[i+Debut-1];
|
||||
str_format(aBuf, sizeof(aBuf), "%d. %s Time: %d minute(s) %5.2f second(s)",
|
||||
i+Debut, r->m_aName, (int) r->m_Score/60, r->m_Score-((int)r->m_Score/60*60));
|
||||
GameServer()->SendChatTarget(ClientID, aBuf);
|
||||
GameServer()->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "top5", aBuf);
|
||||
}
|
||||
GameServer()->SendChatTarget(ClientID, "------------------------------");
|
||||
GameServer()->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "top5", "------------------------------");
|
||||
}
|
||||
|
||||
void CFileScore::ShowRank(int ClientID, const char* pName, bool Search)
|
||||
|
@ -268,5 +268,5 @@ void CFileScore::ShowRank(int ClientID, const char* pName, bool Search)
|
|||
else
|
||||
str_format(aBuf, sizeof(aBuf), "%s is not ranked", Search?pName:Server()->ClientName(ClientID));
|
||||
|
||||
GameServer()->SendChatTarget(ClientID, aBuf);
|
||||
GameServer()->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "rank", aBuf);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue