mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Victims without callback(s)
This commit is contained in:
parent
477594793b
commit
137a447065
|
@ -43,6 +43,10 @@ public:
|
|||
|
||||
int NumArguments() const { return m_NumArgs; }
|
||||
int m_ClientID;
|
||||
|
||||
// DDRace
|
||||
|
||||
virtual int GetVictim() = 0;
|
||||
};
|
||||
|
||||
class CCommandInfo
|
||||
|
|
|
@ -91,6 +91,8 @@ int CConsole::ParseArgs(CResult *pResult, const char *pFormat)
|
|||
int Optional = 0;
|
||||
int Error = 0;
|
||||
|
||||
pResult->ResetVictim();
|
||||
|
||||
pStr = pResult->m_pArgsStart;
|
||||
|
||||
while(1)
|
||||
|
@ -111,7 +113,20 @@ int CConsole::ParseArgs(CResult *pResult, const char *pFormat)
|
|||
if(!(*pStr)) // error, non optional command needs value
|
||||
{
|
||||
if(!Optional)
|
||||
{
|
||||
Error = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
while(*(pFormat - 1))
|
||||
{
|
||||
if(*(pFormat - 1) == 'v')
|
||||
{
|
||||
pResult->SetVictim(CResult::VICTIM_ME);
|
||||
break;
|
||||
}
|
||||
pFormat++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -150,10 +165,17 @@ int CConsole::ParseArgs(CResult *pResult, const char *pFormat)
|
|||
}
|
||||
else
|
||||
{
|
||||
pResult->AddArgument(pStr);
|
||||
char* pVictim = 0;
|
||||
|
||||
if (Command != 'v')
|
||||
pResult->AddArgument(pStr);
|
||||
else
|
||||
pVictim = pStr;
|
||||
|
||||
if(Command == 'r') // rest of the string
|
||||
break;
|
||||
else if(Command == 'v') // validate victim
|
||||
pStr = str_skip_to_whitespace(pStr);
|
||||
else if(Command == 'i') // validate int
|
||||
pStr = str_skip_to_whitespace(pStr);
|
||||
else if(Command == 'f') // validate float
|
||||
|
@ -166,6 +188,9 @@ int CConsole::ParseArgs(CResult *pResult, const char *pFormat)
|
|||
pStr[0] = 0;
|
||||
pStr++;
|
||||
}
|
||||
|
||||
if (pVictim)
|
||||
pResult->SetVictim(pVictim);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -323,9 +348,28 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, int ClientID)
|
|||
}
|
||||
else
|
||||
{
|
||||
if(Result.GetVictim() == CResult::VICTIM_ME)
|
||||
Result.SetVictim(ClientID);
|
||||
|
||||
if(pCommand->m_Flags&CMDFLAG_TEST && !g_Config.m_SvTestingCommands)
|
||||
return;
|
||||
pCommand->m_pfnCallback(&Result, pCommand->m_pUserData);
|
||||
|
||||
if (Result.HasVictim())
|
||||
{
|
||||
if(Result.GetVictim() == CResult::VICTIM_ALL)
|
||||
{
|
||||
for (int i = 0; i < MAX_CLIENTS; i++)
|
||||
{
|
||||
Result.SetVictim(i);
|
||||
pCommand->m_pfnCallback(&Result, pCommand->m_pUserData);
|
||||
}
|
||||
}
|
||||
else
|
||||
pCommand->m_pfnCallback(&Result, pCommand->m_pUserData);
|
||||
}
|
||||
else
|
||||
pCommand->m_pfnCallback(&Result, pCommand->m_pUserData);
|
||||
|
||||
if (pCommand->m_Flags&CMDFLAG_TEST)
|
||||
m_Cheated = true;
|
||||
}
|
||||
|
@ -874,3 +918,33 @@ void CConsole::ConUserCommandStatus(IResult *pResult, void *pUser)
|
|||
if(Used > 0)
|
||||
pConsole->Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf);
|
||||
}
|
||||
|
||||
int CConsole::CResult::GetVictim()
|
||||
{
|
||||
return m_Victim;
|
||||
}
|
||||
|
||||
void CConsole::CResult::ResetVictim()
|
||||
{
|
||||
m_Victim = VICTIM_NONE;
|
||||
}
|
||||
|
||||
bool CConsole::CResult::HasVictim()
|
||||
{
|
||||
return m_Victim != VICTIM_NONE;
|
||||
}
|
||||
|
||||
void CConsole::CResult::SetVictim(int Victim)
|
||||
{
|
||||
m_Victim = clamp<int>(Victim, VICTIM_NONE, MAX_CLIENTS - 1);
|
||||
}
|
||||
|
||||
void CConsole::CResult::SetVictim(const char *pVictim)
|
||||
{
|
||||
if(!str_comp(pVictim, "me"))
|
||||
m_Victim = VICTIM_ME;
|
||||
else if(!str_comp(pVictim, "all"))
|
||||
m_Victim = VICTIM_ALL;
|
||||
else
|
||||
m_Victim = clamp<int>(str_toint(pVictim), 0, MAX_CLIENTS - 1);
|
||||
}
|
||||
|
|
|
@ -114,6 +114,22 @@ class CConsole : public IConsole
|
|||
virtual const char *GetString(unsigned Index);
|
||||
virtual int GetInteger(unsigned Index);
|
||||
virtual float GetFloat(unsigned Index);
|
||||
|
||||
// DDRace
|
||||
|
||||
enum
|
||||
{
|
||||
VICTIM_NONE=-3,
|
||||
VICTIM_ME=-2,
|
||||
VICTIM_ALL=-1,
|
||||
};
|
||||
|
||||
int m_Victim;
|
||||
void ResetVictim();
|
||||
bool HasVictim();
|
||||
void SetVictim(int Victim);
|
||||
void SetVictim(const char *pVictim);
|
||||
virtual int GetVictim();
|
||||
};
|
||||
|
||||
int ParseStart(CResult *pResult, const char *pString, int Length);
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
#define CONSOLE_COMMAND(name, params, flags, callback, userdata, help)
|
||||
#endif
|
||||
|
||||
CONSOLE_COMMAND("kill_pl", "i", CFGFLAG_SERVER, ConKillPlayer, this, "Kills player i and announces the kill")
|
||||
CONSOLE_COMMAND("tele", "i", CFGFLAG_SERVER|CMDFLAG_TEST, ConTeleport, this, "Teleports you to player i")
|
||||
CONSOLE_COMMAND("kill_pl", "v", CFGFLAG_SERVER, ConKillPlayer, this, "Kills player i and announces the kill")
|
||||
CONSOLE_COMMAND("tele", "v", CFGFLAG_SERVER|CMDFLAG_TEST, ConTeleport, this, "Teleports you to player i")
|
||||
CONSOLE_COMMAND("addweapon", "i", CFGFLAG_SERVER|CMDFLAG_TEST, ConAddWeapon, this, "Gives weapon with id i to you (all = -1, hammer = 0, gun = 1, shotgun = 2, grenade = 3, rifle = 4, ninja = 5)")
|
||||
CONSOLE_COMMAND("removeweapon", "i", CFGFLAG_SERVER|CMDFLAG_TEST, ConRemoveWeapon, this, "removes weapon with id i from you (all = -1, hammer = 0, gun = 1, shotgun = 2, grenade = 3, rifle = 4)")
|
||||
CONSOLE_COMMAND("shotgun", "", CFGFLAG_SERVER|CMDFLAG_TEST, ConShotgun, this, "Gives a shotgun to you")
|
||||
|
@ -29,12 +29,12 @@ CONSOLE_COMMAND("down", "", CFGFLAG_SERVER|CMDFLAG_TEST, ConGoDown, this, "Makes
|
|||
CONSOLE_COMMAND("move", "ii", CFGFLAG_SERVER|CMDFLAG_TEST, ConMove, this, "Moves to the tile with x/y-number ii")
|
||||
CONSOLE_COMMAND("move_raw", "ii", CFGFLAG_SERVER|CMDFLAG_TEST, ConMoveRaw, this, "Moves to the point with x/y-coordinates ii")
|
||||
CONSOLE_COMMAND("force_pause", "ii", CFGFLAG_SERVER, ConForcePause, this, "Force i to pause for i seconds")
|
||||
CONSOLE_COMMAND("force_unpause", "i", CFGFLAG_SERVER, ConForcePause, this, "Set force-pause timer of v to 0.")
|
||||
CONSOLE_COMMAND("force_unpause", "v", CFGFLAG_SERVER, ConForcePause, this, "Set force-pause timer of v to 0.")
|
||||
|
||||
CONSOLE_COMMAND("mute", "", CFGFLAG_SERVER, ConMute, this, "");
|
||||
CONSOLE_COMMAND("muteid", "ii", CFGFLAG_SERVER, ConMuteID, this, "");
|
||||
CONSOLE_COMMAND("muteid", "vi", CFGFLAG_SERVER, ConMuteID, this, "");
|
||||
CONSOLE_COMMAND("muteip", "si", CFGFLAG_SERVER, ConMuteIP, this, "");
|
||||
CONSOLE_COMMAND("unmute", "i", CFGFLAG_SERVER, ConUnmute, this, "");
|
||||
CONSOLE_COMMAND("unmute", "v", CFGFLAG_SERVER, ConUnmute, this, "");
|
||||
CONSOLE_COMMAND("mutes", "", CFGFLAG_SERVER, ConMutes, this, "");
|
||||
#undef CONSOLE_COMMAND
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ void CGameContext::ConKillPlayer(IConsole::IResult *pResult, void *pUserData)
|
|||
{
|
||||
CGameContext *pSelf = (CGameContext *)pUserData;
|
||||
if(!CheckClientID(pResult->m_ClientID)) return;
|
||||
int Victim = pResult->GetInteger(0);
|
||||
int Victim = pResult->GetVictim();
|
||||
|
||||
if(pSelf->m_apPlayers[Victim])
|
||||
{
|
||||
|
@ -225,23 +225,21 @@ void CGameContext::ModifyWeapons(IConsole::IResult *pResult, void *pUserData, in
|
|||
pChr->GiveNinja();
|
||||
}
|
||||
|
||||
pChr->m_DDRaceState = DDRACE_CHEAT;
|
||||
pChr->m_DDRaceState = DDRACE_CHEAT;
|
||||
}
|
||||
|
||||
void CGameContext::ConTeleport(IConsole::IResult *pResult, void *pUserData)
|
||||
{
|
||||
CGameContext *pSelf = (CGameContext *)pUserData;
|
||||
if(!CheckClientID(pResult->m_ClientID)) return;
|
||||
int TeleTo = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
|
||||
if(!CheckClientID(pResult->GetVictim())) return;
|
||||
int TeleTo = pResult->GetVictim();
|
||||
if(pSelf->m_apPlayers[TeleTo])
|
||||
{
|
||||
CCharacter* pChr = pSelf->GetPlayerChar(pResult->m_ClientID);
|
||||
if(pChr)
|
||||
{
|
||||
CCharacter* pChr = pSelf->GetPlayerChar(pResult->m_ClientID);
|
||||
if(pChr)
|
||||
{
|
||||
pChr->Core()->m_Pos = pSelf->m_apPlayers[TeleTo]->m_ViewPos;
|
||||
pChr->m_DDRaceState = DDRACE_CHEAT;
|
||||
}
|
||||
pChr->Core()->m_Pos = pSelf->m_apPlayers[TeleTo]->m_ViewPos;
|
||||
pChr->m_DDRaceState = DDRACE_CHEAT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -340,7 +338,7 @@ void CGameContext::ConMute(IConsole::IResult *pResult, void *pUserData)
|
|||
void CGameContext::ConMuteID(IConsole::IResult *pResult, void *pUserData)
|
||||
{
|
||||
CGameContext *pSelf = (CGameContext *)pUserData;
|
||||
int Victim = pResult->GetInteger(0);
|
||||
int Victim = pResult->GetVictim();
|
||||
|
||||
NETADDR Addr;
|
||||
pSelf->Server()->GetClientAddr(Victim, &Addr);
|
||||
|
@ -366,7 +364,7 @@ void CGameContext::ConUnmute(IConsole::IResult *pResult, void *pUserData)
|
|||
CGameContext *pSelf = (CGameContext *)pUserData;
|
||||
char aIpBuf[64];
|
||||
char aBuf[64];
|
||||
int Victim = pResult->GetInteger(0);
|
||||
int Victim = pResult->GetVictim();
|
||||
|
||||
if(Victim < 0 || Victim >= pSelf->m_NumMutes)
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue