show enter/leave team change messages in demos

This commit is contained in:
oy 2012-08-04 17:45:16 +02:00
parent 4333f832f7
commit 93c169c71d
5 changed files with 105 additions and 30 deletions

View file

@ -323,6 +323,17 @@ Messages = [
NetStringStrict("m_pReason"),
]),
## Demo messages
NetMessage("De_ClientEnter", [
NetStringStrict("m_pName"),
NetIntRange("m_Team", 'TEAM_SPECTATORS', 'TEAM_BLUE'),
]),
NetMessage("De_ClientLeave", [
NetStringStrict("m_pName"),
NetStringStrict("m_pReason"),
]),
### Client messages
NetMessage("Cl_Say", [
NetBool("m_Team"),

View file

@ -526,10 +526,15 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker)
if(m_LocalClientID != -1)
{
char aBuf[128];
str_format(aBuf, sizeof(aBuf), Localize("'%s' entered and joined the %s"), pMsg->m_pName, GetTeamName(pMsg->m_Team, m_GameInfo.m_GameFlags&GAMEFLAG_TEAMS));
m_pChat->AddLine(-1, 0, aBuf);
//todo record msg
DoEnterMessage(pMsg->m_pName, pMsg->m_Team);
if(m_pDemoRecorder->IsRecording())
{
CNetMsg_De_ClientEnter Msg;
Msg.m_pName = pMsg->m_pName;
Msg.m_Team = pMsg->m_Team;
Client()->SendPackMsg(&Msg, MSGFLAG_NOSEND|MSGFLAG_RECORD);
}
}
}
@ -567,12 +572,12 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker)
return;
}
char aBuf[128];
if(pMsg->m_pReason[0])
str_format(aBuf, sizeof(aBuf), Localize("'%s' has left the game (%s)"), m_aClients[pMsg->m_ClientID].m_aName, pMsg->m_pReason);
else
str_format(aBuf, sizeof(aBuf), Localize("'%s' has left the game"), m_aClients[pMsg->m_ClientID].m_aName);
m_pChat->AddLine(-1, 0, aBuf);
DoLeaveMessage(m_aClients[pMsg->m_ClientID].m_aName, pMsg->m_pReason);
CNetMsg_De_ClientLeave Msg;
Msg.m_pName = m_aClients[pMsg->m_ClientID].m_aName;
Msg.m_pReason = pMsg->m_pReason;
Client()->SendPackMsg(&Msg, MSGFLAG_NOSEND|MSGFLAG_RECORD);
m_GameInfo.m_NumPlayers--;
// calculate team-balance
@ -592,24 +597,26 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker)
m_GameInfo.m_MatchNum = pMsg->m_MatchNum;
m_GameInfo.m_MatchCurrent = pMsg->m_MatchCurrent;
}
else if(MsgId == NETMSGTYPE_SV_TEAM && Client()->State() != IClient::STATE_DEMOPLAYBACK)
else if(MsgId == NETMSGTYPE_SV_TEAM)
{
Client()->RecordGameMessage(false);
CNetMsg_Sv_Team *pMsg = (CNetMsg_Sv_Team *)pRawMsg;
// calculate team-balance
if(m_aClients[pMsg->m_ClientID].m_Team != TEAM_SPECTATORS)
m_GameInfo.m_aTeamSize[m_aClients[pMsg->m_ClientID].m_Team]--;
m_aClients[pMsg->m_ClientID].m_Team = pMsg->m_Team;
if(m_aClients[pMsg->m_ClientID].m_Team != TEAM_SPECTATORS)
m_GameInfo.m_aTeamSize[m_aClients[pMsg->m_ClientID].m_Team]++;
if(pMsg->m_Silent == 0)
if(Client()->State() != IClient::STATE_DEMOPLAYBACK)
{
char aBuf[128];
str_format(aBuf, sizeof(aBuf), Localize("'%s' joined the %s"), m_aClients[pMsg->m_ClientID].m_aName, GetTeamName(pMsg->m_Team, m_GameInfo.m_GameFlags&GAMEFLAG_TEAMS));
m_pChat->AddLine(-1, 0, aBuf);
// calculate team-balance
if(m_aClients[pMsg->m_ClientID].m_Team != TEAM_SPECTATORS)
m_GameInfo.m_aTeamSize[m_aClients[pMsg->m_ClientID].m_Team]--;
m_aClients[pMsg->m_ClientID].m_Team = pMsg->m_Team;
if(m_aClients[pMsg->m_ClientID].m_Team != TEAM_SPECTATORS)
m_GameInfo.m_aTeamSize[m_aClients[pMsg->m_ClientID].m_Team]++;
m_aClients[pMsg->m_ClientID].UpdateRenderInfo(false);
}
m_aClients[pMsg->m_ClientID].UpdateRenderInfo(false);
if(pMsg->m_Silent == 0)
{
DoTeamChangeMessage(m_aClients[pMsg->m_ClientID].m_aName, pMsg->m_Team);
}
}
else if(MsgId == NETMSGTYPE_SV_READYTOENTER)
{
@ -637,6 +644,16 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker)
else
g_GameClient.m_pSounds->Play(CSounds::CHN_GLOBAL, pMsg->m_SoundID, 1.0f);
}
else if(MsgId == NETMSGTYPE_DE_CLIENTENTER && Client()->State() == IClient::STATE_DEMOPLAYBACK)
{
CNetMsg_De_ClientEnter *pMsg = (CNetMsg_De_ClientEnter *)pRawMsg;
DoEnterMessage(pMsg->m_pName, pMsg->m_Team);
}
else if(MsgId == NETMSGTYPE_DE_CLIENTLEAVE && Client()->State() == IClient::STATE_DEMOPLAYBACK)
{
CNetMsg_De_ClientLeave *pMsg = (CNetMsg_De_ClientLeave *)pRawMsg;
DoLeaveMessage(pMsg->m_pName, pMsg->m_pReason);
}
}
void CGameClient::OnStateChange(int NewState, int OldState)
@ -1228,6 +1245,30 @@ void CGameClient::CClientData::Reset()
UpdateRenderInfo(false);
}
void CGameClient::DoEnterMessage(const char *pName, int Team)
{
char aBuf[128];
str_format(aBuf, sizeof(aBuf), Localize("'%s' entered and joined the %s"), pName, GetTeamName(Team, m_GameInfo.m_GameFlags&GAMEFLAG_TEAMS));
m_pChat->AddLine(-1, 0, aBuf);
}
void CGameClient::DoLeaveMessage(const char *pName, const char *pReason)
{
char aBuf[128];
if(pReason[0])
str_format(aBuf, sizeof(aBuf), Localize("'%s' has left the game (%s)"), pName, pReason);
else
str_format(aBuf, sizeof(aBuf), Localize("'%s' has left the game"), pName);
m_pChat->AddLine(-1, 0, aBuf);
}
void CGameClient::DoTeamChangeMessage(const char *pName, int Team)
{
char aBuf[128];
str_format(aBuf, sizeof(aBuf), Localize("'%s' joined the %s"), pName, GetTeamName(Team, m_GameInfo.m_GameFlags&GAMEFLAG_TEAMS));
m_pChat->AddLine(-1, 0, aBuf);
}
void CGameClient::SendSwitchTeam(int Team)
{
CNetMsg_Cl_SetTeam Msg;

View file

@ -232,6 +232,10 @@ public:
virtual const char *NetVersion();
const char *GetTeamName(int Team, bool Teamplay) const;
//
void DoEnterMessage(const char *pName, int Team);
void DoLeaveMessage(const char *pName, const char *pReason);
void DoTeamChangeMessage(const char *pName, int Team);
// actions
// TODO: move these

View file

@ -615,6 +615,14 @@ void CGameContext::OnClientEnter(int ClientID)
// local info
NewClientInfoMsg.m_Local = 1;
Server()->SendPackMsg(&NewClientInfoMsg, MSGFLAG_VITAL|MSGFLAG_NORECORD, ClientID);
if(Server()->DemoRecorder_IsRecording())
{
CNetMsg_De_ClientEnter Msg;
Msg.m_pName = NewClientInfoMsg.m_pName;
Msg.m_Team = NewClientInfoMsg.m_Team;
Server()->SendPackMsg(&Msg, MSGFLAG_NOSEND, -1);
}
}
void CGameContext::OnClientConnected(int ClientID, bool Dummy)
@ -642,17 +650,28 @@ void CGameContext::OnClientTeamChange(int ClientID)
void CGameContext::OnClientDrop(int ClientID, const char *pReason)
{
// update clients on drop
if(Server()->ClientIngame(ClientID))
{
if(Server()->DemoRecorder_IsRecording())
{
CNetMsg_De_ClientLeave Msg;
Msg.m_pName = Server()->ClientName(ClientID);
Msg.m_pReason = pReason;
Server()->SendPackMsg(&Msg, MSGFLAG_NOSEND, -1);
}
CNetMsg_Sv_ClientDrop Msg;
Msg.m_ClientID = ClientID;
Msg.m_pReason = pReason;
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL|MSGFLAG_NORECORD, -1);
}
AbortVoteOnDisconnect(ClientID);
m_pController->OnPlayerDisconnect(m_apPlayers[ClientID]);
delete m_apPlayers[ClientID];
m_apPlayers[ClientID] = 0;
// update clients on drop
CNetMsg_Sv_ClientDrop Msg;
Msg.m_ClientID = ClientID;
Msg.m_pReason = pReason;
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL|MSGFLAG_NORECORD, -1);
m_VoteUpdate = true;
}

View file

@ -1098,7 +1098,7 @@ void IGameController::DoTeamChange(CPlayer *pPlayer, int Team, bool DoChatMsg)
Msg.m_ClientID = ClientID;
Msg.m_Team = Team;
Msg.m_Silent = DoChatMsg ? 0 : 1;
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL|MSGFLAG_NORECORD, -1);
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, -1);
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "team_join player='%d:%s' m_Team=%d", ClientID, Server()->ClientName(ClientID), Team);