Conflicts:
	src/game/server/gamecontext.cpp
This commit is contained in:
GreYFoXGTi 2010-11-09 17:30:30 +02:00
commit 17cb8a6ffb
9 changed files with 392 additions and 468 deletions

View file

@ -27,6 +27,7 @@ public:
virtual int GetInteger(unsigned Index) = 0;
virtual float GetFloat(unsigned Index) = 0;
virtual const char *GetString(unsigned Index) = 0;
virtual int GetVictim() = 0;
int NumArguments() const { return m_NumArgs; }
};
@ -45,6 +46,9 @@ public:
typedef void (*FCommandCallback)(IResult *pResult, void *pUserData, int ClientId);
typedef void (*FChainCommandCallback)(IResult *pResult, void *pUserData, FCommandCallback pfnCallback, void *pCallbackUserData);
typedef bool (*FCompareClientsCallback)(int ClientLevel, int Victim, void *pUserData);
typedef bool (*FClientOnlineCallback)(int ClientId, void *pUserData);
virtual CCommandInfo *GetCommandInfo(const char *pName, int FlagMask) = 0;
virtual void PossibleCommands(const char *pStr, int FlagMask, FPossibleCallback pfnCallback, void *pUser) = 0;
virtual void ParseArguments(int NumArgs, const char **ppArguments) = 0;
@ -68,6 +72,9 @@ public:
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;
virtual void RegisterCompareClientsCallback(FCompareClientsCallback pfnCallback, void *pUserData) = 0;
virtual void RegisterClientOnlineCallback(FClientOnlineCallback pfnCallback, void *pUserData) = 0;
};
extern IConsole *CreateConsole(int FlagMask);

View file

@ -1144,6 +1144,8 @@ int CServer::Run()
//
Console()->RegisterPrintCallback(SendRconLineAuthed, this);
Console()->RegisterPrintResponseCallback(SendRconLineAuthed, this);
Console()->RegisterClientOnlineCallback(ClientOnline, this);
Console()->RegisterCompareClientsCallback(CompareClients, this);
// load map
if(!LoadMap(g_Config.m_SvMap))
@ -1544,11 +1546,30 @@ void CServer::ConLogin(IConsole::IResult *pResult, void *pUser, int ClientId)
((CServer *)pUser)->SetRconLevel(ClientId, 0);
}
bool CServer::CompareClients(int ClientLevel, int Victim, void *pUser)
{
CServer* pSelf = (CServer *)pUser;
if(!ClientOnline(Victim, pSelf))
return false;
return clamp(ClientLevel, 0, 4) > clamp(pSelf->m_aClients[Victim].m_Authed, 0, 4);
}
bool CServer::ClientOnline(int ClientId, void *pUser)
{
CServer* pSelf = (CServer *)pUser;
if(ClientId < 0 || ClientId >= MAX_CLIENTS)
return false;
return pSelf->m_aClients[ClientId].m_State != CClient::STATE_EMPTY;
}
void CServer::RegisterCommands()
{
m_pConsole = Kernel()->RequestInterface<IConsole>();
Console()->Register("kick", "i?t", CFGFLAG_SERVER, ConKick, this, "", 2);
Console()->Register("kick", "v?t", CFGFLAG_SERVER, ConKick, this, "", 2);
Console()->Register("ban", "s?ir", CFGFLAG_SERVER|CFGFLAG_STORE, ConBan, this, "", 2);
Console()->Register("unban", "s", CFGFLAG_SERVER|CFGFLAG_STORE, ConUnban, this, "", 2);
Console()->Register("bans", "", CFGFLAG_SERVER|CFGFLAG_STORE, ConBans, this, "", 2);

View file

@ -211,6 +211,9 @@ public:
static void ConchainMaxclientsperipUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConLogin(IConsole::IResult *pResult, void *pUser, int ClientId);
static bool CompareClients(int ClientId, int Victim, void *pUser);
static bool ClientOnline(int ClientId, void *pUser);
void RegisterCommands();
void SetRconLevel(int ClientId, int Level);

View file

@ -23,7 +23,10 @@ enum
CFGFLAG_SAVE=1,
CFGFLAG_CLIENT=2,
CFGFLAG_SERVER=4,
CFGFLAG_STORE=8
CFGFLAG_STORE=8,
CMDFLAG_CHEAT=16,
CMDFLAG_TIMER=32,
CMDFLAG_HELPERCMD=64,
};
#endif

View file

@ -1,5 +1,6 @@
#include <new>
#include <base/system.h>
#include <base/math.h>
#include <engine/shared/protocol.h>
#include <engine/storage.h>
#include "console.h"
@ -28,6 +29,36 @@ float CConsole::CResult::GetFloat(unsigned Index)
return str_tofloat(m_apArgs[Index]);
}
int CConsole::CResult::GetVictim()
{
return m_Victim;
}
void CConsole::CResult::ResetVictim()
{
m_Victim = -3;
}
bool CConsole::CResult::HasVictim()
{
return m_Victim != -3;
}
void CConsole::CResult::SetVictim(int Victim)
{
m_Victim = clamp<int>(Victim, 0, MAX_CLIENTS);
}
void CConsole::CResult::SetVictim(const char *pVictim)
{
if(!str_comp(pVictim, "me"))
m_Victim = -2;
if(!str_comp(pVictim, "all"))
m_Victim = -1;
m_Victim = clamp<int>(str_toint(pVictim), 0, MAX_CLIENTS);
}
// the maximum number of tokens occurs in a string of length CONSOLE_MAX_STR_LENGTH with tokens size 1 separated by single spaces
@ -63,6 +94,8 @@ int CConsole::ParseArgs(CResult *pResult, const char *pFormat)
int Optional = 0;
int Error = 0;
pResult->ResetVictim();
pStr = pResult->m_pArgsStart;
while(1)
@ -122,10 +155,15 @@ int CConsole::ParseArgs(CResult *pResult, const char *pFormat)
}
else
{
if (Command != 'v')
pResult->AddArgument(pStr);
else
pResult->SetVictim(pStr);
if(Command == 'r') // rest of the string
break;
else if(Command == 'v')
pStr = str_skip_to_whitespace(pStr);
else if(Command == 'i') // validate int
pStr = str_skip_to_whitespace(pStr);
else if(Command == 'f') // validate float
@ -167,6 +205,33 @@ void CConsole::ReleaseAlternativePrintCallback()
m_PrintUsed--;
}
void CConsole::RegisterClientOnlineCallback(FClientOnlineCallback pfnCallback, void *pUserData)
{
m_pfnClientOnlineCallback = pfnCallback;
m_pClientOnlineUserdata = pUserData;
}
void CConsole::RegisterCompareClientsCallback(FCompareClientsCallback pfnCallback, void *pUserData)
{
m_pfnCompareClientsCallback = pfnCallback;
m_pCompareClientsUserdata = pUserData;
}
bool CConsole::ClientOnline(int ClientId)
{
if(!m_pfnClientOnlineCallback)
return true;
return m_pfnClientOnlineCallback(ClientId, m_pClientOnlineUserdata);
}
bool CConsole::CompareClients(int ClientId, int Victim)
{
if(!m_pfnCompareClientsCallback)
return true;
return m_pfnCompareClientsCallback(ClientId, Victim, m_pCompareClientsUserdata);
}
void CConsole::Print(int Level, const char *pFrom, const char *pStr)
{
@ -335,17 +400,12 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, const int Client
m_ExecutionQueue.m_pLast->m_pCommandUserData = pCommand->m_pUserData;
m_ExecutionQueue.AddEntry();
}
else if(pCommand->m_Level <= ClientLevel)
{
RegisterAlternativePrintCallback(pfnAlternativePrintCallback, pUserData);
RegisterAlternativePrintResponseCallback(pfnAlternativePrintResponseCallback, pResponseUserData);
pCommand->m_pfnCallback(pResult, pCommand->m_pUserData, ClientId);
ReleaseAlternativePrintResponseCallback();
ReleaseAlternativePrintCallback();
}
else
{
if(pResult->GetVictim() == -2)
pResult->SetVictim(ClientId);
if((ClientLevel < pCommand->m_Level && !(pCommand->m_Flags & CMDFLAG_HELPERCMD)) || (ClientLevel < 1 && (pCommand->m_Flags & CMDFLAG_HELPERCMD)))
{
RegisterAlternativePrintResponseCallback(pfnAlternativePrintResponseCallback, pResponseUserData);
@ -356,13 +416,93 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, const int Client
}
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);
str_format(aBuf, sizeof(aBuf), "You have too low level to use command: %s. Your level: %d. Need level: %d", pCommand->m_pName, ClientLevel, pCommand->m_Level);
dbg_msg("server", "client tried rcon command ('%s') without permisson. ClientId=%d ", pCommand->m_pName, ClientId);
}
PrintResponse(OUTPUT_LEVEL_STANDARD, "Console", aBuf);
ReleaseAlternativePrintResponseCallback();
}
else if(ClientLevel == 1 && (pCommand->m_Flags & CMDFLAG_HELPERCMD) && pResult->GetVictim() != ClientId)
{
RegisterAlternativePrintResponseCallback(pfnAlternativePrintResponseCallback, pResponseUserData);
PrintResponse(OUTPUT_LEVEL_STANDARD, "Console", "As a helper you can't use commands on others.");
dbg_msg("server", "helper tried rcon command ('%s') on others without permission. ClientId=%d", pCommand->m_pName, ClientId);
ReleaseAlternativePrintResponseCallback();
}
else if(!g_Config.m_SvCheats && (pCommand->m_Flags & CMDFLAG_CHEAT))
{
RegisterAlternativePrintResponseCallback(pfnAlternativePrintResponseCallback, pResponseUserData);
PrintResponse(OUTPUT_LEVEL_STANDARD, "Console", "Cheats are not available on this server");
dbg_msg("server", "client tried rcon cheat ('%s') with cheats off. ClientId=%d", pCommand->m_pName, ClientId);
ReleaseAlternativePrintResponseCallback();
}
else if(!g_Config.m_SvTimer && (pCommand->m_Flags & CMDFLAG_TIMER))
{
RegisterAlternativePrintResponseCallback(pfnAlternativePrintResponseCallback, pResponseUserData);
PrintResponse(OUTPUT_LEVEL_STANDARD, "Console", "Timer commands are not available on this server");
dbg_msg("server", "client tried timer command ('%s') with timer commands off. ClientId=%d", pCommand->m_pName, ClientId);
ReleaseAlternativePrintResponseCallback();
}
else
{
if (pResult->HasVictim())
{
if(pResult->GetVictim() == -1)
{
for (int i = 0; i < MAX_CLIENTS; i++)
{
if (ClientOnline(i) && CompareClients(ClientLevel, i))
{
pResult->SetVictim(i);
RegisterAlternativePrintCallback(pfnAlternativePrintCallback, pUserData);
RegisterAlternativePrintResponseCallback(pfnAlternativePrintResponseCallback, pResponseUserData);
pCommand->m_pfnCallback(pResult, pCommand->m_pUserData, ClientId);
ReleaseAlternativePrintResponseCallback();
ReleaseAlternativePrintCallback();
}
}
}
else
{
if (!ClientOnline(pResult->GetVictim()))
{
RegisterAlternativePrintResponseCallback(pfnAlternativePrintResponseCallback, pResponseUserData);
PrintResponse(OUTPUT_LEVEL_STANDARD, "Console", "client is offline");
ReleaseAlternativePrintResponseCallback();
}
else if (!CompareClients(ClientLevel, pResult->GetVictim()) && ClientId != pResult->GetVictim())
{
RegisterAlternativePrintResponseCallback(pfnAlternativePrintResponseCallback, pResponseUserData);
PrintResponse(OUTPUT_LEVEL_STANDARD, "Console", "you can not use commands on players with the same or higher level than you");
ReleaseAlternativePrintResponseCallback();
}
else
{
RegisterAlternativePrintCallback(pfnAlternativePrintCallback, pUserData);
RegisterAlternativePrintResponseCallback(pfnAlternativePrintResponseCallback, pResponseUserData);
pCommand->m_pfnCallback(pResult, pCommand->m_pUserData, ClientId);
ReleaseAlternativePrintResponseCallback();
ReleaseAlternativePrintCallback();
}
}
}
else
{
RegisterAlternativePrintCallback(pfnAlternativePrintCallback, pUserData);
RegisterAlternativePrintResponseCallback(pfnAlternativePrintResponseCallback, pResponseUserData);
pCommand->m_pfnCallback(pResult, pCommand->m_pUserData, ClientId);
ReleaseAlternativePrintResponseCallback();
ReleaseAlternativePrintCallback();
}
}
}
}
}
else if(Stroke)
@ -585,6 +725,11 @@ CConsole::CConsole(int FlagMask)
m_pfnAlternativePrintResponseCallback = 0;
m_PrintResponseUsed = 0;
m_pfnClientOnlineCallback = 0;
m_pfnCompareClientsCallback = 0;
m_pClientOnlineUserdata = 0;
m_pCompareClientsUserdata = 0;
m_pStorage = 0;
// register some basic commands

View file

@ -59,6 +59,11 @@ class CConsole : public IConsole
void *m_pAlternativePrintResponseCallbackUserdata;
int m_PrintResponseUsed;
FCompareClientsCallback m_pfnCompareClientsCallback;
void *m_pCompareClientsUserdata;
FClientOnlineCallback m_pfnClientOnlineCallback;
void *m_pClientOnlineUserdata;
enum
{
CONSOLE_MAX_STR_LENGTH = 1024,
@ -74,14 +79,22 @@ class CConsole : public IConsole
const char *m_pCommand;
const char *m_apArgs[MAX_PARTS];
int m_Victim;
void AddArgument(const char *pArg)
{
m_apArgs[m_NumArgs++] = pArg;
}
void ResetVictim();
bool HasVictim();
void SetVictim(int Victim);
void SetVictim(const char *pVictim);
virtual const char *GetString(unsigned Index);
virtual int GetInteger(unsigned Index);
virtual float GetFloat(unsigned Index);
virtual int GetVictim();
};
int ParseStart(CResult *pResult, const char *pString, int Length);
@ -141,6 +154,12 @@ public:
virtual void RegisterAlternativePrintResponseCallback(FPrintCallback pfnAlternativePrintCallback, void *pAlternativeUserData);
virtual void ReleaseAlternativePrintResponseCallback();
virtual void RegisterCompareClientsCallback(FCompareClientsCallback pfnCallback, void *pUserData);
virtual void RegisterClientOnlineCallback(FClientOnlineCallback pfnCallback, void *pUserData);
virtual bool CompareClients(int ClientLevel, int Victim);
virtual bool ClientOnline(int ClientId);
virtual void Print(int Level, const char *pFrom, const char *pStr);
virtual void PrintResponse(int Level, const char *pFrom, const char *pStr);
};

View file

@ -7,59 +7,45 @@
#endif
CONSOLE_COMMAND("clear_votes", "", CFGFLAG_SERVER, ConClearVotes, this, "Clears the vote list", 4)
CONSOLE_COMMAND("kill_pl", "i", CFGFLAG_SERVER, ConKillPlayer, this, "Kills player i and announces the kill", 2)
CONSOLE_COMMAND("logout", "?i", CFGFLAG_SERVER, ConLogOut, this, "If you are a helper or didn't specify [i] it logs you out, otherwise it logs player i out", 0)
CONSOLE_COMMAND("helper", "i", CFGFLAG_SERVER, ConSetlvl1, this, "Authenticates player i to the Level of 1", 2)
CONSOLE_COMMAND("moder", "i", CFGFLAG_SERVER, ConSetlvl2, this, "Authenticates player i to the Level of 2", 3)
CONSOLE_COMMAND("admin", "i", CFGFLAG_SERVER, ConSetlvl3, this, "Authenticates player i to the Level of 3 (CAUTION: Irreversible, once he is an admin you can't control him)", 3)
CONSOLE_COMMAND("mute", "ii", CFGFLAG_SERVER, ConMute, this, "Mutes player i1 for i2 seconds", 2)
CONSOLE_COMMAND("invis_me", "", CFGFLAG_SERVER, ConInvisMe, this, "Makes you invisible", 1)
CONSOLE_COMMAND("vis_me", "", CFGFLAG_SERVER, ConVisMe, this, "Makes you visible again", 1)
CONSOLE_COMMAND("invis", "i", CFGFLAG_SERVER, ConInvis, this, "Makes player i invisible", 2)
CONSOLE_COMMAND("vis", "i", CFGFLAG_SERVER, ConVis, this, "Makes player i visible again", 2)
CONSOLE_COMMAND("timerstop", "i", CFGFLAG_SERVER, ConTimerStop, this, "Stops the timer of player i", 2)
CONSOLE_COMMAND("timerstart", "i", CFGFLAG_SERVER, ConTimerStart, this, "Starts the timer of player i", 2)
CONSOLE_COMMAND("timerrestart", "i", CFGFLAG_SERVER, ConTimerReStart, this, "Sets the timer of player i to 0 and starts it", 2)
CONSOLE_COMMAND("timerzero", "i", CFGFLAG_SERVER, ConTimerZero, this, "Sets the timer of player i to 0 and stops it", 2)
CONSOLE_COMMAND("tele", "ii", CFGFLAG_SERVER, ConTeleport, this, "Teleports player i1 to player i2", 2)
CONSOLE_COMMAND("freeze", "i?i", CFGFLAG_SERVER, ConFreeze, this, "Freezes player i1 for i2 seconds (infinity by default)", 2)
CONSOLE_COMMAND("unfreeze", "i", CFGFLAG_SERVER, ConUnFreeze, this, "Unfreezes player i", 2)
CONSOLE_COMMAND("addweapon", "i?i", CFGFLAG_SERVER, ConAddWeapon, this, "First optional parameter is client id, next parameter is weapon (all = -1, hammer = 0, gun = 1, shotgun = 2, grenade = 3, rifle = 4, ninja = 5)", 1)
CONSOLE_COMMAND("removeweapon", "i?i", CFGFLAG_SERVER, ConRemoveWeapon, this, "First optional parameter is client id, next parameter is weapon (all = -1, hammer = 0, gun = 1, shotgun = 2, grenade = 3, rifle = 4)", 1)
CONSOLE_COMMAND("shotgun", "i", CFGFLAG_SERVER, ConShotgun, this, "Gives a shotgun to player i", 2)
CONSOLE_COMMAND("shotgun_me", "", CFGFLAG_SERVER, ConShotgunMe, this, "Gives shotgun to yourself", 1)
CONSOLE_COMMAND("grenade", "i", CFGFLAG_SERVER, ConGrenade, this, "Gives a grenade launcher to player i", 2)
CONSOLE_COMMAND("grenade_me", "", CFGFLAG_SERVER, ConGrenadeMe, this, "Gives grenade launcher to yourself", 1)
CONSOLE_COMMAND("rifle", "i", CFGFLAG_SERVER, ConRifle, this, "Gives a rifle to player i", 2)
CONSOLE_COMMAND("rifle_me", "", CFGFLAG_SERVER, ConRifleMe, this, "Gives rifle to yourself", 1)
CONSOLE_COMMAND("weapons", "i", CFGFLAG_SERVER, ConWeapons, this, "Gives all weapons to player i", 2)
CONSOLE_COMMAND("weapons_me", "", CFGFLAG_SERVER, ConWeaponsMe, this, "Gives all weapons to yourself", 1)
CONSOLE_COMMAND("unshotgun", "i", CFGFLAG_SERVER, ConUnShotgun, this, "Takes a shotgun from player i", 2)
CONSOLE_COMMAND("unshotgun_me", "", CFGFLAG_SERVER, ConUnShotgunMe, this, "Takes shotgun from yourself", 1)
CONSOLE_COMMAND("ungrenade", "i", CFGFLAG_SERVER, ConUnGrenade, this, "Takes a grenade launcher from player i", 2)
CONSOLE_COMMAND("ungrenade_me", "", CFGFLAG_SERVER, ConUnGrenadeMe, this, "Takes grenade launcher from yourself", 1)
CONSOLE_COMMAND("unrifle", "i", CFGFLAG_SERVER, ConUnRifle, this, "Takes a rifle from player i", 2)
CONSOLE_COMMAND("unrifle_me", "", CFGFLAG_SERVER, ConUnRifleMe, this, "Takes rifle from yourself", 1)
CONSOLE_COMMAND("unweapons", "i", CFGFLAG_SERVER, ConUnWeapons, this, "Takes all weapons from player i", 2)
CONSOLE_COMMAND("unweapons_me", "", CFGFLAG_SERVER, ConUnWeaponsMe, this, "Takes all weapons from yourself", 1)
CONSOLE_COMMAND("ninja", "i", CFGFLAG_SERVER, ConNinja, this, "Makes player i a ninja", 2)
CONSOLE_COMMAND("ninja_me", "", CFGFLAG_SERVER, ConNinjaMe, this, "Makes yourself a ninja", 1)
CONSOLE_COMMAND("hammer_me", "i", CFGFLAG_SERVER, ConHammerMe, this, "Sets your hammer power to i", 1)
CONSOLE_COMMAND("hammer", "ii", CFGFLAG_SERVER, ConHammer, this, "Sets the hammer power of player i1 to i2", 2)
CONSOLE_COMMAND("super", "i", CFGFLAG_SERVER, ConSuper, this, "Makes player i super", 2)
CONSOLE_COMMAND("unsuper", "i", CFGFLAG_SERVER, ConUnSuper, this, "Removes super from player i", 2)
CONSOLE_COMMAND("super_me", "", CFGFLAG_SERVER, ConSuperMe, this, "Makes yourself super", 1)
CONSOLE_COMMAND("unsuper_me", "", CFGFLAG_SERVER, ConUnSuperMe, this, "Removes super from yourself", 1)
CONSOLE_COMMAND("left", "?i", CFGFLAG_SERVER, ConGoLeft, this, "Makes you or player i move 1 tile left", 1)
CONSOLE_COMMAND("right", "?i", CFGFLAG_SERVER, ConGoRight, this, "Makes you or player i move 1 tile right", 1)
CONSOLE_COMMAND("up", "?i", CFGFLAG_SERVER, ConGoUp, this, "Makes you or player i move 1 tile up", 1)
CONSOLE_COMMAND("down", "?i", CFGFLAG_SERVER, ConGoDown, this, "Makes you or player i move 1 tile down", 1)
CONSOLE_COMMAND("move", "ii?i", CFGFLAG_SERVER, ConMove, this, "First optional parameter is client id, next parameters are x-axis change and y-axis change (1 = 1 tile)", 1)
CONSOLE_COMMAND("move_raw", "ii?i", CFGFLAG_SERVER, ConMoveRaw, this, "First optional parameter is client id, next parameters are x-axis change and y-axis change (1 = 1 pixel)", 1)
CONSOLE_COMMAND("kill", "v", CFGFLAG_SERVER, ConKillPlayer, this, "Kills player i and announces the kill", 2)
CONSOLE_COMMAND("logout", "v", CFGFLAG_SERVER, ConLogOut, this, "If you are a helper or didn't specify [i] it logs you out, otherwise it logs player i out", 0)
CONSOLE_COMMAND("helper", "v", CFGFLAG_SERVER, ConSetlvl1, this, "Authenticates player i to the Level of 1", 2)
CONSOLE_COMMAND("moder", "v", CFGFLAG_SERVER, ConSetlvl2, this, "Authenticates player i to the Level of 2", 3)
CONSOLE_COMMAND("admin", "v", CFGFLAG_SERVER, ConSetlvl3, this, "Authenticates player i to the Level of 3 (CAUTION: Irreversible, once he is an admin you can't control him)", 3)
CONSOLE_COMMAND("mute", "vi", CFGFLAG_SERVER, ConMute, this, "Mutes player i1 for i2 seconds", 2)
CONSOLE_COMMAND("invis", "v", CFGFLAG_SERVER|CMDFLAG_CHEAT|CMDFLAG_HELPERCMD, ConInvis, this, "Makes player i invisible", 2)
CONSOLE_COMMAND("vis", "v", CFGFLAG_SERVER|CMDFLAG_CHEAT|CMDFLAG_HELPERCMD, ConVis, this, "Makes player i visible again", 2)
CONSOLE_COMMAND("timerstop", "v", CFGFLAG_SERVER|CMDFLAG_TIMER, ConTimerStop, this, "Stops the timer of player i", 2)
CONSOLE_COMMAND("timerstart", "v", CFGFLAG_SERVER|CMDFLAG_TIMER, ConTimerStart, this, "Starts the timer of player i", 2)
CONSOLE_COMMAND("timerrestart", "v", CFGFLAG_SERVER|CMDFLAG_TIMER, ConTimerReStart, this, "Sets the timer of player i to 0 and starts it", 2)
CONSOLE_COMMAND("timerzero", "v", CFGFLAG_SERVER|CMDFLAG_TIMER, ConTimerZero, this, "Sets the timer of player i to 0 and stops it", 2)
CONSOLE_COMMAND("tele", "vi", CFGFLAG_SERVER|CMDFLAG_CHEAT|CMDFLAG_HELPERCMD, ConTeleport, this, "Teleports player i1 to player i2", 2)
CONSOLE_COMMAND("freeze", "v?i", CFGFLAG_SERVER|CMDFLAG_CHEAT|CMDFLAG_HELPERCMD, ConFreeze, this, "Freezes player i1 for i2 seconds (infinity by default)", 2)
CONSOLE_COMMAND("unfreeze", "v", CFGFLAG_SERVER|CMDFLAG_CHEAT|CMDFLAG_HELPERCMD, ConUnFreeze, this, "Unfreezes player i", 2)
CONSOLE_COMMAND("addweapon", "v?i", CFGFLAG_SERVER|CMDFLAG_CHEAT|CMDFLAG_HELPERCMD, ConAddWeapon, this, "First optional parameter is client id, next parameter is weapon (all = -1, hammer = 0, gun = 1, shotgun = 2, grenade = 3, rifle = 4, ninja = 5)", 1)
CONSOLE_COMMAND("removeweapon", "v?i", CFGFLAG_SERVER|CMDFLAG_CHEAT|CMDFLAG_HELPERCMD, ConRemoveWeapon, this, "First optional parameter is client id, next parameter is weapon (all = -1, hammer = 0, gun = 1, shotgun = 2, grenade = 3, rifle = 4)", 1)
CONSOLE_COMMAND("shotgun", "v", CFGFLAG_SERVER|CMDFLAG_CHEAT|CMDFLAG_HELPERCMD, ConShotgun, this, "Gives a shotgun to player i", 2)
CONSOLE_COMMAND("grenade", "v", CFGFLAG_SERVER|CMDFLAG_CHEAT|CMDFLAG_HELPERCMD, ConGrenade, this, "Gives a grenade launcher to player i", 2)
CONSOLE_COMMAND("rifle", "v", CFGFLAG_SERVER|CMDFLAG_CHEAT|CMDFLAG_HELPERCMD, ConRifle, this, "Gives a rifle to player i", 2)
CONSOLE_COMMAND("weapons", "v", CFGFLAG_SERVER|CMDFLAG_CHEAT|CMDFLAG_HELPERCMD, ConWeapons, this, "Gives all weapons to player i", 2)
CONSOLE_COMMAND("unshotgun", "v", CFGFLAG_SERVER|CMDFLAG_HELPERCMD, ConUnShotgun, this, "Takes a shotgun from player i", 2)
CONSOLE_COMMAND("ungrenade", "v", CFGFLAG_SERVER|CMDFLAG_HELPERCMD, ConUnGrenade, this, "Takes a grenade launcher from player i", 2)
CONSOLE_COMMAND("unrifle", "v", CFGFLAG_SERVER|CMDFLAG_HELPERCMD, ConUnRifle, this, "Takes a rifle from player i", 2)
CONSOLE_COMMAND("unweapons", "v", CFGFLAG_SERVER|CMDFLAG_HELPERCMD, ConUnWeapons, this, "Takes all weapons from player i", 2)
CONSOLE_COMMAND("ninja", "v", CFGFLAG_SERVER|CMDFLAG_CHEAT|CMDFLAG_HELPERCMD, ConNinja, this, "Makes player i a ninja", 2)
CONSOLE_COMMAND("hammer", "vi", CFGFLAG_SERVER|CMDFLAG_CHEAT|CMDFLAG_HELPERCMD, ConHammer, this, "Sets the hammer power of player i1 to i2", 2)
CONSOLE_COMMAND("super", "v", CFGFLAG_SERVER|CMDFLAG_CHEAT|CMDFLAG_HELPERCMD, ConSuper, this, "Makes player i super", 2)
CONSOLE_COMMAND("unsuper", "v", CFGFLAG_SERVER|CMDFLAG_HELPERCMD, ConUnSuper, this, "Removes super from player i", 2)
CONSOLE_COMMAND("left", "v", CFGFLAG_SERVER|CMDFLAG_CHEAT|CMDFLAG_HELPERCMD, ConGoLeft, this, "Makes you or player i move 1 tile left", 1)
CONSOLE_COMMAND("right", "v", CFGFLAG_SERVER|CMDFLAG_CHEAT|CMDFLAG_HELPERCMD, ConGoRight, this, "Makes you or player i move 1 tile right", 1)
CONSOLE_COMMAND("up", "v", CFGFLAG_SERVER|CMDFLAG_CHEAT|CMDFLAG_HELPERCMD, ConGoUp, this, "Makes you or player i move 1 tile up", 1)
CONSOLE_COMMAND("down", "v", CFGFLAG_SERVER|CMDFLAG_CHEAT|CMDFLAG_HELPERCMD, ConGoDown, this, "Makes you or player i move 1 tile down", 1)
CONSOLE_COMMAND("move", "vii", CFGFLAG_SERVER|CMDFLAG_CHEAT|CMDFLAG_HELPERCMD, ConMove, this, "First optional parameter is client id, next parameters are x-axis change and y-axis change (1 = 1 tile)", 1)
CONSOLE_COMMAND("move_raw", "vii", CFGFLAG_SERVER|CMDFLAG_CHEAT|CMDFLAG_HELPERCMD, ConMoveRaw, this, "First optional parameter is client id, next parameters are x-axis change and y-axis change (1 = 1 pixel)", 1)
CONSOLE_COMMAND("broadtime", "", CFGFLAG_SERVER, ConBroadTime, this, "Toggles Showing the time string in race", -1)
CONSOLE_COMMAND("cmdlist", "", CFGFLAG_SERVER, ConCmdList, this, "Shows the list of all commands", -1)
CONSOLE_COMMAND("credits", "", CFGFLAG_SERVER, ConCredits, this, "Shows the credits of the DDRace mod", -1)
CONSOLE_COMMAND("emote", "?s?i", CFGFLAG_SERVER, ConEyeEmote, this, "Sets your tee's eye emote", -1)
CONSOLE_COMMAND("emote", "?si", CFGFLAG_SERVER, ConEyeEmote, this, "Sets your tee's eye emote", -1)
CONSOLE_COMMAND("broadmsg", "", CFGFLAG_SERVER, ConToggleBroadcast, this, "Toggle Showing the Server's Broadcast message during race", -1)
CONSOLE_COMMAND("eyeemote", "", CFGFLAG_SERVER, ConEyeEmote, this, "Toggles whether you automatically use eyeemotes with standard emotes", -1)
CONSOLE_COMMAND("flags", "", CFGFLAG_SERVER, ConFlags, this, "Shows gameplay information for this server", -1)

View file

@ -618,7 +618,7 @@ void CGameContext::OnClientEnter(int ClientId)
m_VoteUpdate = true;
}
bool compare_players(CPlayer *pl1, CPlayer *pl2)
bool ComparePlayers(CPlayer *pl1, CPlayer *pl2)
{
if(((pl1->m_Authed >= 0) ? pl1->m_Authed : 0) > ((pl2->m_Authed >= 0) ? pl2->m_Authed : 0))
return true;
@ -862,7 +862,7 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId)
SendChatTarget(ClientId, "You can't kick yourself");
return;
}
if(compare_players(m_apPlayers[KickId], pPlayer))
if(ComparePlayers(m_apPlayers[KickId], pPlayer))
{
SendChatTarget(ClientId, "You can't kick admins");
m_apPlayers[ClientId]->m_Last_KickVote = time_get();
@ -1182,15 +1182,15 @@ void CGameContext::ConSay(IConsole::IResult *pResult, void *pUserData, int Clien
void CGameContext::ConSetTeam(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
int Victim = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
int Team = clamp(pResult->GetInteger(1), -1, 1);
int Victim = pResult->GetVictim();
int Team = clamp(pResult->GetInteger(0), -1, 1);
if(!pSelf->m_apPlayers[Victim])
return;
char aBuf[256];
str_format(aBuf, sizeof(aBuf), "moved client %d to team %d", Victim, Team);
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
if(!pSelf->m_apPlayers[Victim] || !compare_players(pSelf->m_apPlayers[ClientId], pSelf->m_apPlayers[Victim]))
if(!pSelf->m_apPlayers[Victim])
return;
pSelf->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
pSelf->m_apPlayers[ClientId]->SetTeam(Team);
//(void)pSelf->m_pController->CheckTeamBalance();
@ -1273,88 +1273,49 @@ void CGameContext::ConchainSpecialMotdupdate(IConsole::IResult *pResult, void *p
}
bool CGameContext::CheatsAvailable()
{
if(!g_Config.m_SvCheats)
{
Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "cheats", "Cheats are not available on this server.");
}
return g_Config.m_SvCheats;
}
void CGameContext::ConGoLeft(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->MoveCharacter(ClientId, (pResult->NumArguments() > 0) ? pResult->GetInteger(0) : ClientId, -1, 0);
pSelf->MoveCharacter(ClientId, pResult->GetVictim(), -1, 0);
}
void CGameContext::ConGoRight(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->MoveCharacter(ClientId, (pResult->NumArguments() > 0) ? pResult->GetInteger(0) : ClientId, 1, 0);
pSelf->MoveCharacter(ClientId, pResult->GetVictim(), 1, 0);
}
void CGameContext::ConGoDown(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->MoveCharacter(ClientId, (pResult->NumArguments() > 0) ? pResult->GetInteger(0) : ClientId, 0, 1);
pSelf->MoveCharacter(ClientId, pResult->GetVictim(), 0, 1);
}
void CGameContext::ConGoUp(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->MoveCharacter(ClientId, (pResult->NumArguments() > 0) ? pResult->GetInteger(0) : ClientId, 0, -1);
pSelf->MoveCharacter(ClientId, pResult->GetVictim(), 0, -1);
}
void CGameContext::ConMove(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if (pResult->NumArguments() > 2)
pSelf->MoveCharacter(ClientId, pResult->GetInteger(0), pResult->GetInteger(1), pResult->GetInteger(2));
else
pSelf->MoveCharacter(ClientId, ClientId, pResult->GetInteger(0), pResult->GetInteger(1));
pSelf->MoveCharacter(ClientId, pResult->GetVictim(), pResult->GetInteger(0), pResult->GetInteger(1));
}
void CGameContext::ConMoveRaw(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if (pResult->NumArguments() > 2)
pSelf->MoveCharacter(ClientId, pResult->GetInteger(0), pResult->GetInteger(1), pResult->GetInteger(2), true);
else
pSelf->MoveCharacter(ClientId, ClientId, pResult->GetInteger(0), pResult->GetInteger(1), true);
pSelf->MoveCharacter(ClientId, pResult->GetVictim(), pResult->GetInteger(0), pResult->GetInteger(1), true);
}
void CGameContext::MoveCharacter(int ClientId, int Victim, int X, int Y, bool Raw)
{
if(!CheatsAvailable())
return;
if(clamp(Victim, 0, (int) MAX_CLIENTS - 1) != Victim || GetPlayerChar(ClientId) == 0)
{
Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", "invalid client id");
return;
}
if(ClientId != Victim && m_apPlayers[ClientId]->m_Authed <= 1)
{
Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", "You have too low level to move the tees of other players");
return;
}
if(ClientId != Victim && !compare_players(m_apPlayers[ClientId], m_apPlayers[Victim]))
{
Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", "You can't move the tee of players with the same or a higher rank");
return;
}
CCharacter* pChr = GetPlayerChar(ClientId);
if(!pChr)
return;
pChr->m_Core.m_Pos.x += ((Raw) ? 1 : 32) * X;
pChr->m_Core.m_Pos.y += ((Raw) ? 1 : 32) * Y;
@ -1365,12 +1326,13 @@ void CGameContext::MoveCharacter(int ClientId, int Victim, int X, int Y, bool Ra
void CGameContext::ConMute(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
int Victim = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
int Seconds = pResult->GetInteger(1);
int Victim = pResult->GetVictim();
int Seconds = pResult->GetInteger(0);
char buf[512];
if(Seconds < 10)
Seconds = 10;
if(pSelf->m_apPlayers[Victim] && (compare_players(pSelf->m_apPlayers[ClientId],pSelf->m_apPlayers[Victim])))
if(pSelf->m_apPlayers[Victim]->m_Muted < Seconds * pSelf->Server()->TickSpeed())
{
pSelf->m_apPlayers[Victim]->m_Muted = Seconds * pSelf->Server()->TickSpeed();
str_format(buf, sizeof(buf), "%s muted by %s for %d seconds", pSelf->Server()->ClientName(Victim), pSelf->Server()->ClientName(ClientId), Seconds);
@ -1381,9 +1343,9 @@ void CGameContext::ConMute(IConsole::IResult *pResult, void *pUserData, int Clie
void CGameContext::ConSetlvl3(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
int Victim = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
int Victim = pResult->GetVictim();
CServer* pServ = (CServer*)pSelf->Server();
if(pSelf->m_apPlayers[Victim] && (compare_players(pSelf->m_apPlayers[ClientId],pSelf->m_apPlayers[Victim]) || ClientId == Victim))
if(pSelf->m_apPlayers[Victim])
{
pSelf->m_apPlayers[Victim]->m_Authed = 3;
pServ->SetRconLevel(Victim, 3);
@ -1393,9 +1355,9 @@ void CGameContext::ConSetlvl3(IConsole::IResult *pResult, void *pUserData, int C
void CGameContext::ConSetlvl2(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
int Victim = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
int Victim = pResult->GetVictim();
CServer* pServ = (CServer*)pSelf->Server();
if(pSelf->m_apPlayers[Victim] && (compare_players(pSelf->m_apPlayers[ClientId],pSelf->m_apPlayers[Victim]) || ClientId == Victim))
if(pSelf->m_apPlayers[Victim])
{
pSelf->m_apPlayers[Victim]->m_Authed = 2;
pServ->SetRconLevel(Victim, 2);
@ -1405,9 +1367,9 @@ void CGameContext::ConSetlvl2(IConsole::IResult *pResult, void *pUserData, int C
void CGameContext::ConSetlvl1(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
int Victim = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
int Victim = pResult->GetVictim();
CServer* pServ = (CServer*)pSelf->Server();
if(pSelf->m_apPlayers[Victim] && (compare_players(pSelf->m_apPlayers[ClientId],pSelf->m_apPlayers[Victim]) || ClientId == Victim))
if(pSelf->m_apPlayers[Victim])
{
pSelf->m_apPlayers[Victim]->m_Authed = 1;
pServ->SetRconLevel(Victim, 1);
@ -1417,11 +1379,10 @@ void CGameContext::ConSetlvl1(IConsole::IResult *pResult, void *pUserData, int C
void CGameContext::ConLogOut(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
int Victim = ClientId;
if(pResult->NumArguments() && pSelf->m_apPlayers[Victim]->m_Authed > 1)
Victim = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
int Victim = pResult->GetVictim();
CServer* pServ = (CServer*)pSelf->Server();
if(pSelf->m_apPlayers[Victim] && (compare_players(pSelf->m_apPlayers[ClientId],pSelf->m_apPlayers[Victim]) || ClientId == Victim))
if(pSelf->m_apPlayers[Victim])
{
pSelf->m_apPlayers[Victim]->m_Authed = -1;
pServ->SetRconLevel(Victim, -1);
@ -1431,53 +1392,43 @@ void CGameContext::ConLogOut(IConsole::IResult *pResult, void *pUserData, int Cl
void CGameContext::ConKillPlayer(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
int Victim = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
if(!pSelf->m_apPlayers[Victim])
return;
int Victim = pResult->GetVictim();
if(pSelf->m_apPlayers[Victim] && compare_players(pSelf->m_apPlayers[ClientId],pSelf->m_apPlayers[Victim]))
if(pSelf->m_apPlayers[Victim])
{
pSelf->m_apPlayers[Victim]->KillCharacter(WEAPON_GAME);
char buf[512];
str_format(buf, sizeof(buf), "%s killed by %s", pSelf->Server()->ClientName(Victim), pSelf->Server()->ClientName(ClientId));
str_format(buf, sizeof(buf), "%s was killed by %s", pSelf->Server()->ClientName(Victim), pSelf->Server()->ClientName(ClientId));
pSelf->SendChat(-1, CGameContext::CHAT_ALL, buf);
}
}
void CGameContext::ConNinjaMe(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->ModifyWeapons(ClientId, ClientId, WEAPON_NINJA, false);
}
void CGameContext::ConNinja(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->ModifyWeapons(ClientId, pResult->GetInteger(0), WEAPON_NINJA, false);
pSelf->ModifyWeapons(ClientId, pResult->GetVictim(), WEAPON_NINJA, false);
}
void CGameContext::ConHammer(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(!pSelf->CheatsAvailable()) return;
char buf[128];
int Victim = pResult->GetVictim();
char buf[128];
int type = pResult->GetInteger(0);
int Victim = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
int type = pResult->GetInteger(1);
CCharacter* chr = pSelf->GetPlayerChar(Victim);
if(!chr)
return;
CServer* pServ = (CServer*)pSelf->Server();
if(type>3 || type<0)
{
pSelf->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Select hammer between 0 and 3");
}
else
{
if(pSelf->m_apPlayers[Victim] && compare_players(pSelf->m_apPlayers[ClientId],pSelf->m_apPlayers[Victim]))
{
chr->m_HammerType = type;
if(!g_Config.m_SvCheatTime)
@ -1485,41 +1436,12 @@ void CGameContext::ConHammer(IConsole::IResult *pResult, void *pUserData, int Cl
str_format(buf, sizeof(buf), "Hammer of '%s' ClientId=%d setted to %d", pServ->ClientName(ClientId), Victim, type);
pSelf->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", buf);
}
}
}
void CGameContext::ConHammerMe(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(!pSelf->CheatsAvailable()) return;
char buf[128];
int type = pResult->GetInteger(0);
CCharacter* chr = pSelf->GetPlayerChar(ClientId);
if(!chr)
return;
CServer* pServ = (CServer*)pSelf->Server();
if(type>3 || type<0)
{
pSelf->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Select hammer between 0 and 3");
}
else
{
chr->m_HammerType = type;
if(!g_Config.m_SvCheatTime)
chr->m_DDRaceState = DDRACE_CHEAT;
str_format(buf, sizeof(buf), "Hammer setted to %d",type);
pSelf->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", buf);
}
}
void CGameContext::ConSuper(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(!pSelf->CheatsAvailable()) return;
int Victim = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
if(pSelf->m_apPlayers[Victim] && compare_players(pSelf->m_apPlayers[ClientId],pSelf->m_apPlayers[Victim]))
{
int Victim = pResult->GetVictim();
CCharacter* chr = pSelf->GetPlayerChar(Victim);
if(chr && !chr->m_Super)
{
@ -1531,215 +1453,82 @@ void CGameContext::ConSuper(IConsole::IResult *pResult, void *pUserData, int Cli
if(!g_Config.m_SvCheatTime)
chr->m_DDRaceState = DDRACE_CHEAT;
}
}
}
void CGameContext::ConUnSuper(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(!pSelf->CheatsAvailable()) return;
int Victim = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
if(pSelf->m_apPlayers[Victim] && compare_players(pSelf->m_apPlayers[ClientId],pSelf->m_apPlayers[Victim]))
{
int Victim = pResult->GetVictim();
CCharacter* chr = pSelf->GetPlayerChar(Victim);
if(chr && chr->m_Super)
{
chr->m_Super = false;
chr->Teams()->SetForceCharacterTeam(Victim, chr->m_TeamBeforeSuper);
}
}
}
void CGameContext::ConSuperMe(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(!pSelf->CheatsAvailable()) return;
if(pSelf->m_apPlayers[ClientId])
{
CCharacter* chr = pSelf->GetPlayerChar(ClientId);
if(chr && !chr->m_Super)
{
chr->m_Super = true;
chr->UnFreeze();
chr->m_TeamBeforeSuper = chr->Team();
dbg_msg("Teamb4super","%d",chr->m_TeamBeforeSuper = chr->Team());
chr->Teams()->SetCharacterTeam(ClientId, TEAM_SUPER);
if(!g_Config.m_SvCheatTime)
chr->m_DDRaceState = DDRACE_CHEAT;
}
}
}
void CGameContext::ConUnSuperMe(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(!pSelf->CheatsAvailable()) return;
if(pSelf->m_apPlayers[ClientId])
{
CCharacter* chr = pSelf->GetPlayerChar(ClientId);
if(chr && chr->m_Super)
{
chr->m_Super = false;
chr->Teams()->SetForceCharacterTeam(ClientId, chr->m_TeamBeforeSuper);
}
}
}
void CGameContext::ConShotgun(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->ModifyWeapons(ClientId, pResult->GetInteger(0), WEAPON_SHOTGUN, false);
}
void CGameContext::ConShotgunMe(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->ModifyWeapons(ClientId, ClientId, WEAPON_SHOTGUN, false);
pSelf->ModifyWeapons(ClientId, pResult->GetVictim(), WEAPON_SHOTGUN, false);
}
void CGameContext::ConGrenade(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->ModifyWeapons(ClientId, pResult->GetInteger(0), WEAPON_GRENADE, false);
}
void CGameContext::ConGrenadeMe(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->ModifyWeapons(ClientId, ClientId, WEAPON_GRENADE, false);
pSelf->ModifyWeapons(ClientId, pResult->GetVictim(), WEAPON_GRENADE, false);
}
void CGameContext::ConRifle(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->ModifyWeapons(ClientId, pResult->GetInteger(0), WEAPON_RIFLE, false);
}
void CGameContext::ConRifleMe(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->ModifyWeapons(ClientId, ClientId, WEAPON_RIFLE, false);
pSelf->ModifyWeapons(ClientId, pResult->GetVictim(), WEAPON_RIFLE, false);
}
void CGameContext::ConWeapons(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->ModifyWeapons(ClientId, pResult->GetInteger(0), -1, false);
}
void CGameContext::ConWeaponsMe(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->ModifyWeapons(ClientId, ClientId, -1, false);
pSelf->ModifyWeapons(ClientId, pResult->GetVictim(), -1, false);
}
void CGameContext::ConUnShotgun(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->ModifyWeapons(ClientId, pResult->GetInteger(0), WEAPON_SHOTGUN, true);
}
void CGameContext::ConUnShotgunMe(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->ModifyWeapons(ClientId, ClientId, WEAPON_SHOTGUN, true);
pSelf->ModifyWeapons(ClientId, pResult->GetVictim(), WEAPON_SHOTGUN, true);
}
void CGameContext::ConUnGrenade(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->ModifyWeapons(ClientId, pResult->GetInteger(0), WEAPON_GRENADE, true);
}
void CGameContext::ConUnGrenadeMe(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->ModifyWeapons(ClientId, ClientId, WEAPON_GRENADE, true);
pSelf->ModifyWeapons(ClientId, pResult->GetVictim(), WEAPON_GRENADE, true);
}
void CGameContext::ConUnRifle(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->ModifyWeapons(ClientId, pResult->GetInteger(0), WEAPON_RIFLE, true);
}
void CGameContext::ConUnRifleMe(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->ModifyWeapons(ClientId, ClientId, WEAPON_RIFLE, true);
pSelf->ModifyWeapons(ClientId, pResult->GetVictim(), WEAPON_RIFLE, true);
}
void CGameContext::ConUnWeapons(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->ModifyWeapons(ClientId, pResult->GetInteger(0), -1, true);
}
void CGameContext::ConUnWeaponsMe(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->ModifyWeapons(ClientId, ClientId, -1, true);
pSelf->ModifyWeapons(ClientId, pResult->GetVictim(), -1, true);
}
void CGameContext::ConAddWeapon(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if (pResult->NumArguments() > 1)
pSelf->ModifyWeapons(ClientId, pResult->GetInteger(0), pResult->GetInteger(1), false);
else
pSelf->ModifyWeapons(ClientId, ClientId, pResult->GetInteger(0), false);
pSelf->ModifyWeapons(ClientId, pResult->GetVictim(), pResult->GetInteger(0), false);
}
void CGameContext::ConRemoveWeapon(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if (pResult->NumArguments() > 1)
pSelf->ModifyWeapons(ClientId, pResult->GetInteger(0), pResult->GetInteger(1), true);
else
pSelf->ModifyWeapons(ClientId, ClientId, pResult->GetInteger(0), true);
pSelf->ModifyWeapons(ClientId, pResult->GetVictim(), pResult->GetInteger(0), true);
}
void CGameContext::ModifyWeapons(int ClientId, int Victim, int Weapon, bool Remove)
{
if(!CheatsAvailable())
return;
if(clamp(Victim, 0, (int) MAX_CLIENTS - 1) != Victim || GetPlayerChar(ClientId) == 0)
{
Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", "invalid client id");
return;
}
if(ClientId != Victim && m_apPlayers[ClientId]->m_Authed <= 1)
{
Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", "You have too low level to add/remove weapons from other players");
return;
}
if(ClientId != Victim && !compare_players(m_apPlayers[ClientId], m_apPlayers[Victim]))
{
Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", "You can't add/remove weapons from players with the same or a higher rank");
return;
}
if(clamp(Weapon, -1, NUM_WEAPONS - 1) != Weapon)
{
Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", "invalid weapon id");
@ -1747,6 +1536,9 @@ void CGameContext::ModifyWeapons(int ClientId, int Victim, int Weapon, bool Remo
}
CCharacter* pChr = GetPlayerChar(Victim);
if(!pChr)
return;
if(Weapon == -1)
{
if(Remove && pChr->m_ActiveWeapon == WEAPON_SHOTGUN || pChr->m_ActiveWeapon == WEAPON_GRENADE || pChr->m_ActiveWeapon == WEAPON_RIFLE)
@ -1789,19 +1581,15 @@ void CGameContext::ModifyWeapons(int ClientId, int Victim, int Weapon, bool Remo
void CGameContext::ConTeleport(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(!pSelf->CheatsAvailable()) return;
int Victim = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
int cid2 = clamp(pResult->GetInteger(1), 0, (int)MAX_CLIENTS-1);
if(pSelf->m_apPlayers[Victim] && pSelf->m_apPlayers[cid2])
int Victim = pResult->GetVictim();
int TeleTo = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
if(pSelf->m_apPlayers[TeleTo])
{
if(ClientId==Victim
|| (compare_players(pSelf->m_apPlayers[ClientId],pSelf->m_apPlayers[Victim]) && compare_players(pSelf->m_apPlayers[ClientId],pSelf->m_apPlayers[cid2]))
|| (compare_players(pSelf->m_apPlayers[ClientId],pSelf->m_apPlayers[Victim]) && cid2==ClientId))
{
CCharacter* chr = pSelf->GetPlayerChar(Victim);
if(chr)
{
chr->m_Core.m_Pos = pSelf->m_apPlayers[cid2]->m_ViewPos;
chr->m_Core.m_Pos = pSelf->m_apPlayers[TeleTo]->m_ViewPos;
if(!g_Config.m_SvCheatTime)
chr->m_DDRaceState = DDRACE_CHEAT;
}
@ -1812,69 +1600,51 @@ void CGameContext::ConTeleport(IConsole::IResult *pResult, void *pUserData, int
void CGameContext::ConTimerStop(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
char buf[128];
CServer* pServ = (CServer*)pSelf->Server();
if(!g_Config.m_SvTimer)
{
int Victim = pResult->GetVictim();
int Victim = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
char buf[128];
CCharacter* chr = pSelf->GetPlayerChar(Victim);
if(!chr)
return;
if(pSelf->m_apPlayers[Victim] && compare_players(pSelf->m_apPlayers[ClientId],pSelf->m_apPlayers[Victim]))
if(pSelf->m_apPlayers[Victim])
{
chr->m_DDRaceState=DDRACE_CHEAT;
str_format(buf, sizeof(buf), "'%s' ClientId=%d Hasn't time now (Timer Stopped)", pServ->ClientName(ClientId), Victim);
pSelf->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", buf);
}
}
else
{
pSelf->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Timer commands are disabled");
}
}
void CGameContext::ConTimerStart(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
char buf[128];
CServer* pServ = (CServer*)pSelf->Server();
if(!g_Config.m_SvTimer)
{
int Victim = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
int Victim = pResult->GetVictim();
char buf[128];
CCharacter* chr = pSelf->GetPlayerChar(Victim);
if(!chr)
return;
if(pSelf->m_apPlayers[Victim] && compare_players(pSelf->m_apPlayers[ClientId],pSelf->m_apPlayers[Victim]))
if(pSelf->m_apPlayers[Victim])
{
chr->m_DDRaceState = DDRACE_STARTED;
str_format(buf, sizeof(buf), "'%s' ClientId=%d Has time now (Timer Started)", pServ->ClientName(ClientId), Victim);
pSelf->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", buf);
}
}
else
{
pSelf->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Timer commands are disabled");
}
}
void CGameContext::ConTimerZero(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(!pSelf->CheatsAvailable()) return;
char buf[128];
CServer* pServ = (CServer*)pSelf->Server();
if(!g_Config.m_SvTimer)
{
int Victim = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
int Victim = pResult->GetVictim();
char buf[128];
CCharacter* chr = pSelf->GetPlayerChar(Victim);
if(!chr)
return;
if(pSelf->m_apPlayers[Victim] && compare_players(pSelf->m_apPlayers[ClientId],pSelf->m_apPlayers[Victim]))
if(pSelf->m_apPlayers[Victim])
{
chr->m_StartTime = pSelf->Server()->Tick();
chr->m_RefreshTime = pSelf->Server()->Tick();
@ -1882,28 +1652,19 @@ void CGameContext::ConTimerZero(IConsole::IResult *pResult, void *pUserData, int
str_format(buf, sizeof(buf), "'%s' ClientId=%d time has been reset & stopped.", pServ->ClientName(ClientId), Victim);
pSelf->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", buf);
}
}
else
{
pSelf->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Timer commands are disabled");
}
}
void CGameContext::ConTimerReStart(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
if(!pSelf->CheatsAvailable()) return;
char buf[128];
int Victim = pResult->GetVictim();
CServer* pServ = (CServer*)pSelf->Server();
if(!g_Config.m_SvTimer)
{
int Victim = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
char buf[128];
CCharacter* chr = pSelf->GetPlayerChar(Victim);
if(!chr)
return;
if(pSelf->m_apPlayers[Victim] && compare_players(pSelf->m_apPlayers[ClientId],pSelf->m_apPlayers[Victim]))
if(pSelf->m_apPlayers[Victim])
{
chr->m_StartTime = pSelf->Server()->Tick();
chr->m_RefreshTime = pSelf->Server()->Tick();
@ -1911,27 +1672,24 @@ void CGameContext::ConTimerReStart(IConsole::IResult *pResult, void *pUserData,
str_format(buf, sizeof(buf), "'%s' ClientId=%d time has been reset & stopped.", pServ->ClientName(ClientId), Victim);
pSelf->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", buf);
}
}
else
{
pSelf->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", "Timer commands are disabled");
}
}
void CGameContext::ConFreeze(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
//if(!pSelf->CheatsAvailable()) return;
char buf[128];
int time=-1;
int Victim = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
if(pResult->NumArguments()>1)
int Victim = pResult->GetVictim();
char buf[128];
if(pResult->NumArguments() >= 1)
time = clamp(pResult->GetInteger(1), -1, 29999);
CCharacter* chr = pSelf->GetPlayerChar(Victim);
if(!chr)
return;
if(pSelf->m_apPlayers[Victim] && compare_players(pSelf->m_apPlayers[ClientId],pSelf->m_apPlayers[Victim]))
if(pSelf->m_apPlayers[Victim])
{
chr->Freeze(((time!=0&&time!=-1)?(pSelf->Server()->TickSpeed()*time):(-1)));
chr->m_pPlayer->m_RconFreeze = true;
@ -1945,9 +1703,9 @@ void CGameContext::ConFreeze(IConsole::IResult *pResult, void *pUserData, int Cl
void CGameContext::ConUnFreeze(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
//if(!pSelf->CheatsAvailable()) return;
int Victim = pResult->GetVictim();
char buf[128];
int Victim = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
CCharacter* chr = pSelf->GetPlayerChar(Victim);
if(!chr)
return;
@ -1956,35 +1714,18 @@ void CGameContext::ConUnFreeze(IConsole::IResult *pResult, void *pUserData, int
CServer* pServ = (CServer*)pSelf->Server();
str_format(buf, sizeof(buf), "'%s' ClientId=%d has been UnFreezed.", pServ->ClientName(ClientId), Victim);
pSelf->Console()->PrintResponse(IConsole::OUTPUT_LEVEL_STANDARD, "info", buf);
}
void CGameContext::ConInvisMe(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
//if(!pSelf->CheatsAvailable()) return;
if(!pSelf->m_apPlayers[ClientId])
return;
pSelf->m_apPlayers[ClientId]->m_Invisible = true;
}
void CGameContext::ConVisMe(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
//if(!pSelf->CheatsAvailable()) return;
if(!pSelf->m_apPlayers[ClientId])
return;
pSelf->m_apPlayers[ClientId]->m_Invisible = false;
}
void CGameContext::ConInvis(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
char buf[128];
int Victim = pResult->GetVictim();
if(!pSelf->m_apPlayers[ClientId])
return;
char buf[128];
int Victim = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
if(pSelf->m_apPlayers[Victim] && compare_players(pSelf->m_apPlayers[ClientId],pSelf->m_apPlayers[Victim]))
if(pSelf->m_apPlayers[Victim])
{
pSelf->m_apPlayers[Victim]->m_Invisible = true;
CServer* pServ = (CServer*)pSelf->Server();
@ -1996,11 +1737,12 @@ void CGameContext::ConInvis(IConsole::IResult *pResult, void *pUserData, int Cli
void CGameContext::ConVis(IConsole::IResult *pResult, void *pUserData, int ClientId)
{
CGameContext *pSelf = (CGameContext *)pUserData;
int Victim = pResult->GetVictim();
if(!pSelf->m_apPlayers[ClientId])
return;
char buf[128];
int Victim = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
if(pSelf->m_apPlayers[Victim] && compare_players(pSelf->m_apPlayers[ClientId],pSelf->m_apPlayers[Victim]))
if(pSelf->m_apPlayers[Victim])
{
pSelf->m_apPlayers[Victim]->m_Invisible = false;
CServer* pServ = (CServer*)pSelf->Server();
@ -2390,7 +2132,7 @@ void CGameContext::OnConsoleInit()
Console()->Register("restart", "?i", CFGFLAG_SERVER, ConRestart, this, "Kills all players", 3);
Console()->Register("broadcast", "r", CFGFLAG_SERVER, ConBroadcast, this, "Changes the broadcast message for a moment", 3);
Console()->Register("say", "r", CFGFLAG_SERVER, ConSay, this, "Sends a server message to all players", 3);
Console()->Register("set_team", "ii", CFGFLAG_SERVER, ConSetTeam, this, "Changes the team of player i1 to team i2", 2);
Console()->Register("set_team", "vi", CFGFLAG_SERVER, ConSetTeam, this, "Changes the team of player i1 to team i2", 2);
Console()->Register("addvote", "r", CFGFLAG_SERVER, ConAddVote, this, "Adds a vote entry to the clients", 4);
Console()->Register("tune", "si", CFGFLAG_SERVER, ConTuneParam, this, "Modifies tune parameter s to value i", 4);

View file

@ -186,8 +186,6 @@ public:
void SendVoteStatus(int ClientId, int Total, int Yes, int No);
void AbortVoteKickOnDisconnect(int ClientId);
bool CheatsAvailable();
bool m_VoteKick;
int m_VoteCreator;
int64 m_VoteCloseTime;