mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-14 03:58:18 +00:00
Added swap functionality to server client:
- New chat command - Swaps character's position with other tee using existing Save/Load methods.
This commit is contained in:
parent
7d3fdec98a
commit
94dbae981f
|
@ -27,6 +27,7 @@ CHAT_COMMAND("dnd", "", CFGFLAG_CHAT | CFGFLAG_SERVER | CFGFLAG_NONTEEHISTORIC,
|
||||||
CHAT_COMMAND("mapinfo", "?r[map]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConMapInfo, this, "Show info about the map with name r gives (current map by default)")
|
CHAT_COMMAND("mapinfo", "?r[map]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConMapInfo, this, "Show info about the map with name r gives (current map by default)")
|
||||||
CHAT_COMMAND("timeout", "?s[code]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConTimeout, this, "Set timeout protection code s")
|
CHAT_COMMAND("timeout", "?s[code]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConTimeout, this, "Set timeout protection code s")
|
||||||
CHAT_COMMAND("practice", "?i['0'|'1']", CFGFLAG_CHAT | CFGFLAG_SERVER, ConPractice, this, "Enable cheats (currently only /rescue) for your current team's run, but you can't earn a rank")
|
CHAT_COMMAND("practice", "?i['0'|'1']", CFGFLAG_CHAT | CFGFLAG_SERVER, ConPractice, this, "Enable cheats (currently only /rescue) for your current team's run, but you can't earn a rank")
|
||||||
|
CHAT_COMMAND("swap", "?r[player name]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConSwap, this, "Swaps your position with a teammates")
|
||||||
CHAT_COMMAND("save", "?r[code]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConSave, this, "Save team with code r.")
|
CHAT_COMMAND("save", "?r[code]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConSave, this, "Save team with code r.")
|
||||||
CHAT_COMMAND("load", "?r[code]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConLoad, this, "Load with code r. /load to check your existing saves")
|
CHAT_COMMAND("load", "?r[code]", CFGFLAG_CHAT | CFGFLAG_SERVER, ConLoad, this, "Load with code r. /load to check your existing saves")
|
||||||
CHAT_COMMAND("map", "?r[map]", CFGFLAG_CHAT | CFGFLAG_SERVER | CFGFLAG_NONTEEHISTORIC, ConMap, this, "Vote a map by name")
|
CHAT_COMMAND("map", "?r[map]", CFGFLAG_CHAT | CFGFLAG_SERVER | CFGFLAG_NONTEEHISTORIC, ConMap, this, "Vote a map by name")
|
||||||
|
|
|
@ -674,6 +674,100 @@ void CGameContext::ConPractice(IConsole::IResult *pResult, void *pUserData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CGameContext::ConSwap(IConsole::IResult *pResult, void *pUserData)
|
||||||
|
{
|
||||||
|
CGameContext *pSelf = (CGameContext *)pUserData;
|
||||||
|
const char *pName = pResult->GetString(0);
|
||||||
|
|
||||||
|
if(!CheckClientID(pResult->m_ClientID))
|
||||||
|
return;
|
||||||
|
|
||||||
|
CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID];
|
||||||
|
if(!pPlayer)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(pSelf->ProcessSpamProtection(pResult->m_ClientID))
|
||||||
|
return;
|
||||||
|
|
||||||
|
CGameTeams &Teams = ((CGameControllerDDRace *)pSelf->m_pController)->m_Teams;
|
||||||
|
|
||||||
|
int Team = Teams.m_Core.Team(pResult->m_ClientID);
|
||||||
|
|
||||||
|
if(Team < TEAM_FLOCK || (Team == TEAM_FLOCK && g_Config.m_SvTeam != 3) || Team >= TEAM_SUPER)
|
||||||
|
{
|
||||||
|
pSelf->Console()->Print(
|
||||||
|
IConsole::OUTPUT_LEVEL_STANDARD,
|
||||||
|
"print",
|
||||||
|
"Join a team to use swap feature, which means you can swap positions with each other.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TargetClientId = -1;
|
||||||
|
for(int i = 0; i < MAX_CLIENTS; i++)
|
||||||
|
{
|
||||||
|
if(!str_comp(pName, pSelf->Server()->ClientName(i)))
|
||||||
|
{
|
||||||
|
TargetClientId = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TargetNotFound = TargetClientId < 0;
|
||||||
|
if(TargetNotFound)
|
||||||
|
{
|
||||||
|
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "swap", "Player not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TargetIsSelf = TargetClientId == pResult->m_ClientID;
|
||||||
|
if(TargetIsSelf)
|
||||||
|
{
|
||||||
|
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "swap", "Can't swap with yourself.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TargetTeam = Teams.m_Core.Team(TargetClientId);
|
||||||
|
|
||||||
|
bool DifferentTeam = TargetTeam != Team;
|
||||||
|
if(DifferentTeam)
|
||||||
|
{
|
||||||
|
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "swap", "Player on a different team");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CPlayer *pSwapPlayer = pSelf->m_apPlayers[TargetClientId];
|
||||||
|
if(!pSwapPlayer)
|
||||||
|
{ //Not sure what could cause this state.
|
||||||
|
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "swap", "Swap failed, try again in a few seconds.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SwapPending = pSwapPlayer->m_ClientSwapID != pResult->m_ClientID;
|
||||||
|
if(SwapPending)
|
||||||
|
{
|
||||||
|
pPlayer->m_ClientSwapID = TargetClientId;
|
||||||
|
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "swap", "Swap request sent. Player needs to confirm swap.");
|
||||||
|
|
||||||
|
char aBuf[512];
|
||||||
|
str_format(aBuf, sizeof(aBuf), "'%s' has requested to swap positions with you. Type /swap to confirm the swap.)", pSelf->Server()->ClientName(pResult->m_ClientID));
|
||||||
|
|
||||||
|
pSelf->SendChatTarget(TargetClientId, aBuf);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CSaveTee PrimarySavedTee;
|
||||||
|
PrimarySavedTee.Save(pPlayer->GetCharacter());
|
||||||
|
|
||||||
|
CSaveTee SecondarySavedTee;
|
||||||
|
SecondarySavedTee.Save(pSwapPlayer->GetCharacter());
|
||||||
|
|
||||||
|
PrimarySavedTee.Load(pSwapPlayer->GetCharacter(), Team);
|
||||||
|
SecondarySavedTee.Load(pPlayer->GetCharacter(), Team);
|
||||||
|
|
||||||
|
pPlayer->m_ClientSwapID = -1;
|
||||||
|
pSwapPlayer->m_ClientSwapID = -1;
|
||||||
|
}
|
||||||
|
|
||||||
void CGameContext::ConSave(IConsole::IResult *pResult, void *pUserData)
|
void CGameContext::ConSave(IConsole::IResult *pResult, void *pUserData)
|
||||||
{
|
{
|
||||||
CGameContext *pSelf = (CGameContext *)pUserData;
|
CGameContext *pSelf = (CGameContext *)pUserData;
|
||||||
|
|
|
@ -356,6 +356,7 @@ private:
|
||||||
static void ConMapInfo(IConsole::IResult *pResult, void *pUserData);
|
static void ConMapInfo(IConsole::IResult *pResult, void *pUserData);
|
||||||
static void ConTimeout(IConsole::IResult *pResult, void *pUserData);
|
static void ConTimeout(IConsole::IResult *pResult, void *pUserData);
|
||||||
static void ConPractice(IConsole::IResult *pResult, void *pUserData);
|
static void ConPractice(IConsole::IResult *pResult, void *pUserData);
|
||||||
|
static void ConSwap(IConsole::IResult *pResult, void *pUserData);
|
||||||
static void ConSave(IConsole::IResult *pResult, void *pUserData);
|
static void ConSave(IConsole::IResult *pResult, void *pUserData);
|
||||||
static void ConLoad(IConsole::IResult *pResult, void *pUserData);
|
static void ConLoad(IConsole::IResult *pResult, void *pUserData);
|
||||||
static void ConMap(IConsole::IResult *pResult, void *pUserData);
|
static void ConMap(IConsole::IResult *pResult, void *pUserData);
|
||||||
|
|
|
@ -138,6 +138,7 @@ void CPlayer::Reset()
|
||||||
m_NotEligibleForFinish = false;
|
m_NotEligibleForFinish = false;
|
||||||
m_EligibleForFinishCheck = 0;
|
m_EligibleForFinishCheck = 0;
|
||||||
m_VotedForPractice = false;
|
m_VotedForPractice = false;
|
||||||
|
m_ClientSwapID = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int PlayerFlags_SevenToSix(int Flags)
|
static int PlayerFlags_SevenToSix(int Flags)
|
||||||
|
|
|
@ -210,6 +210,7 @@ public:
|
||||||
bool m_NotEligibleForFinish;
|
bool m_NotEligibleForFinish;
|
||||||
int64 m_EligibleForFinishCheck;
|
int64 m_EligibleForFinishCheck;
|
||||||
bool m_VotedForPractice;
|
bool m_VotedForPractice;
|
||||||
|
int m_ClientSwapID;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue