Merge pull request #748 from Learath2/dd_pr_invite2

Add the invite system back
This commit is contained in:
Dennis Felsing 2017-04-24 12:28:56 +02:00 committed by GitHub
commit c610b5fd71
5 changed files with 75 additions and 2 deletions

View file

@ -766,6 +766,49 @@ void CGameContext::ConLockTeam(IConsole::IResult *pResult, void *pUserData)
"This team can't be locked"); "This team can't be locked");
} }
void CGameContext::ConInviteTeam(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
CGameControllerDDRace *pController = (CGameControllerDDRace *)pSelf->m_pController;
const char *pName = pResult->GetString(0);
int Team = pController->m_Teams.m_Core.Team(pResult->m_ClientID);
if(Team > TEAM_FLOCK && Team < TEAM_SUPER)
{
int Target = -1;
for(int i = 0; i < MAX_CLIENTS; i++)
{
if(!str_comp(pName, pSelf->Server()->ClientName(i)))
{
Target = i;
break;
}
}
if(Target < 0)
{
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "invite", "Player not found");
return;
}
if(pController->m_Teams.IsInvited(Team, Target))
{
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "invite", "Player already invited");
return;
}
pController->m_Teams.SetClientInvited(Team, Target, true);
char aBuf[512];
str_format(aBuf, sizeof aBuf, "'%s' invited you to team %d.", pSelf->Server()->ClientName(pResult->m_ClientID), Team);
pSelf->SendChatTarget(Target, aBuf);
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "invite", "Player has been notified");
}
else
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "invite", "Can't invite players to this team");
}
void CGameContext::ConJoinTeam(IConsole::IResult *pResult, void *pUserData) void CGameContext::ConJoinTeam(IConsole::IResult *pResult, void *pUserData)
{ {
CGameContext *pSelf = (CGameContext *) pUserData; CGameContext *pSelf = (CGameContext *) pUserData;
@ -817,10 +860,10 @@ void CGameContext::ConJoinTeam(IConsole::IResult *pResult, void *pUserData)
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "join", pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "join",
"You can\'t change teams that fast!"); "You can\'t change teams that fast!");
} }
else if(pResult->GetInteger(0) > 0 && pResult->GetInteger(0) < MAX_CLIENTS && pController->m_Teams.TeamLocked(pResult->GetInteger(0))) else if(pResult->GetInteger(0) > 0 && pResult->GetInteger(0) < MAX_CLIENTS && pController->m_Teams.TeamLocked(pResult->GetInteger(0)) && !pController->m_Teams.IsInvited(pResult->GetInteger(0), pResult->m_ClientID))
{ {
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "join", pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "join",
"This team is locked using /lock."); "This team is locked using /lock. Only members of the team can invite you or unlock it using /lock.");
} }
else if(pResult->GetInteger(0) > 0 && pResult->GetInteger(0) < MAX_CLIENTS && pController->m_Teams.Count(pResult->GetInteger(0)) >= g_Config.m_SvTeamMaxSize) else if(pResult->GetInteger(0) > 0 && pResult->GetInteger(0) < MAX_CLIENTS && pController->m_Teams.Count(pResult->GetInteger(0)) >= g_Config.m_SvTeamMaxSize)
{ {

View file

@ -31,6 +31,7 @@ CHAT_COMMAND("rank", "?r[playername]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConRank, thi
CHAT_COMMAND("rules", "", CFGFLAG_CHAT|CFGFLAG_SERVER, ConRules, this, "Shows the server rules") CHAT_COMMAND("rules", "", CFGFLAG_CHAT|CFGFLAG_SERVER, ConRules, this, "Shows the server rules")
CHAT_COMMAND("team", "?i[id]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConJoinTeam, this, "Lets you join team i (shows your team if left blank)") CHAT_COMMAND("team", "?i[id]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConJoinTeam, this, "Lets you join team i (shows your team if left blank)")
CHAT_COMMAND("lock", "?i['0'|'1']", CFGFLAG_CHAT|CFGFLAG_SERVER, ConLockTeam, this, "Lock team so no-one else can join it") CHAT_COMMAND("lock", "?i['0'|'1']", CFGFLAG_CHAT|CFGFLAG_SERVER, ConLockTeam, this, "Lock team so no-one else can join it")
CHAT_COMMAND("invite", "r[player name]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConInviteTeam, this, "Invite a person to a locked team")
CHAT_COMMAND("top5team", "?i[rank to start with]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTeamTop5, this, "Shows five team ranks of the ladder beginning with rank i (1 by default)") CHAT_COMMAND("top5team", "?i[rank to start with]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTeamTop5, this, "Shows five team ranks of the ladder beginning with rank i (1 by default)")
CHAT_COMMAND("teamtop5", "?i[rank to start with]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTeamTop5, this, "Shows five team ranks of the ladder beginning with rank i (1 by default)") CHAT_COMMAND("teamtop5", "?i[rank to start with]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTeamTop5, this, "Shows five team ranks of the ladder beginning with rank i (1 by default)")
CHAT_COMMAND("top5", "?i[rank to start with]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTop5, this, "Shows five ranks of the ladder beginning with rank i (1 by default)") CHAT_COMMAND("top5", "?i[rank to start with]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTop5, this, "Shows five ranks of the ladder beginning with rank i (1 by default)")

View file

@ -298,6 +298,7 @@ private:
static void ConBroadTime(IConsole::IResult *pResult, void *pUserData); static void ConBroadTime(IConsole::IResult *pResult, void *pUserData);
static void ConJoinTeam(IConsole::IResult *pResult, void *pUserData); static void ConJoinTeam(IConsole::IResult *pResult, void *pUserData);
static void ConLockTeam(IConsole::IResult *pResult, void *pUserData); static void ConLockTeam(IConsole::IResult *pResult, void *pUserData);
static void ConInviteTeam(IConsole::IResult *pResult, void *pUserData);
static void ConMe(IConsole::IResult *pResult, void *pUserData); static void ConMe(IConsole::IResult *pResult, void *pUserData);
static void ConWhisper(IConsole::IResult *pResult, void *pUserData); static void ConWhisper(IConsole::IResult *pResult, void *pUserData);
static void ConConverse(IConsole::IResult *pResult, void *pUserData); static void ConConverse(IConsole::IResult *pResult, void *pUserData);

View file

@ -20,6 +20,7 @@ void CGameTeams::Reset()
m_LastChat[i] = 0; m_LastChat[i] = 0;
m_TeamLocked[i] = false; m_TeamLocked[i] = false;
m_IsSaving[i] = false; m_IsSaving[i] = false;
m_Invited[i] = 0;
} }
} }
@ -649,6 +650,25 @@ void CGameTeams::SetTeamLock(int Team, bool Lock)
m_TeamLocked[Team] = Lock; m_TeamLocked[Team] = Lock;
} }
void CGameTeams::ResetInvited(int Team)
{
m_Invited[Team] = 0;
for (int i = 0; i < MAX_CLIENTS; i++)
if(m_Core.Team(i) == Team && GameServer()->m_apPlayers[i])
m_Invited[Team] |= 1ULL << i;
}
void CGameTeams::SetClientInvited(int Team, int ClientID, bool Invited)
{
if(Team > TEAM_FLOCK && Team < TEAM_SUPER)
{
if(Invited)
m_Invited[Team] |= 1ULL << ClientID;
else
m_Invited[Team] &= ~(1ULL << ClientID);
}
}
void CGameTeams::KillSavedTeam(int Team) void CGameTeams::KillSavedTeam(int Team)
{ {
// Set so that no finish is accidentally given to some of the players // Set so that no finish is accidentally given to some of the players

View file

@ -12,6 +12,7 @@ class CGameTeams
bool m_TeeFinished[MAX_CLIENTS]; bool m_TeeFinished[MAX_CLIENTS];
bool m_TeamLocked[MAX_CLIENTS]; bool m_TeamLocked[MAX_CLIENTS];
bool m_IsSaving[MAX_CLIENTS]; bool m_IsSaving[MAX_CLIENTS];
uint64_t m_Invited[MAX_CLIENTS];
class CGameContext * m_pGameContext; class CGameContext * m_pGameContext;
@ -69,6 +70,8 @@ public:
void SendTeamsState(int Cid); void SendTeamsState(int Cid);
void SetTeamLock(int Team, bool Lock); void SetTeamLock(int Team, bool Lock);
void ResetInvited(int Team);
void SetClientInvited(int Team, int ClientID, bool Invited);
int m_LastChat[MAX_CLIENTS]; int m_LastChat[MAX_CLIENTS];
@ -101,6 +104,11 @@ public:
return m_TeamLocked[Team]; return m_TeamLocked[Team];
} }
bool IsInvited(int Team, int ClientID)
{
return m_Invited[Team] & 1LL << ClientID;
}
void SetFinished(int ClientID, bool finished) void SetFinished(int ClientID, bool finished)
{ {
m_TeeFinished[ClientID] = finished; m_TeeFinished[ClientID] = finished;