Added TargetID in Sv_Chat for whispers

This commit is contained in:
LordSk 2018-11-20 20:53:39 +01:00
parent 208000d157
commit 0bf36fbbe5
4 changed files with 33 additions and 35 deletions

View file

@ -246,6 +246,7 @@ Messages = [
NetMessage("Sv_Chat", [
NetIntRange("m_Mode", 0, 'NUM_CHATS-1'),
NetIntRange("m_ClientID", -1, 'MAX_CLIENTS-1'),
NetIntRange("m_TargetID", -1, 'MAX_CLIENTS-1'),
NetStringStrict("m_pMessage"),
]),

View file

@ -359,11 +359,11 @@ void CChat::OnMessage(int MsgType, void *pRawMsg)
if(MsgType == NETMSGTYPE_SV_CHAT)
{
CNetMsg_Sv_Chat *pMsg = (CNetMsg_Sv_Chat *)pRawMsg;
AddLine(pMsg->m_ClientID, pMsg->m_Mode, pMsg->m_pMessage);
AddLine(pMsg->m_ClientID, pMsg->m_Mode, pMsg->m_pMessage, pMsg->m_TargetID);
}
}
void CChat::AddLine(int ClientID, int Mode, const char *pLine)
void CChat::AddLine(int ClientID, int Mode, const char *pLine, int TargetID)
{
if(*pLine == 0 || (ClientID != -1 && (!g_Config.m_ClShowsocial || m_pClient->m_aClients[ClientID].m_aName[0] == '\0' || // unknown client
m_pClient->m_aClients[ClientID].m_ChatIgnore ||
@ -419,6 +419,7 @@ void CChat::AddLine(int ClientID, int Mode, const char *pLine)
m_aLines[m_CurrentLine].m_Size[0].y = -1.0f;
m_aLines[m_CurrentLine].m_Size[1].y = -1.0f;
m_aLines[m_CurrentLine].m_ClientID = ClientID;
m_aLines[m_CurrentLine].m_TargetID = TargetID;
m_aLines[m_CurrentLine].m_Mode = Mode;
m_aLines[m_CurrentLine].m_NameColor = -2;
@ -790,34 +791,27 @@ void CChat::OnRender()
}
char aBuf[48];
if(Line.m_Mode == CHAT_TEAM)
{
TextColor = ColorTeamPre;
str_format(aBuf, sizeof(aBuf), "[%s] ", Localize("Team"));
TextRender()->TextShadowed(&Cursor, aBuf, -1, ShadowOffset, ShadowColor, TextColor);
}
else if(Line.m_Mode == CHAT_WHISPER)
if(Line.m_Mode == CHAT_WHISPER)
{
TextColor = ColorWhisper;
ShadowColor = ShadowWhisper;
str_format(aBuf, sizeof(aBuf), "[%s] ", Localize("Whisper"));
const int LocalCID = m_pClient->m_LocalClientID;
if(Line.m_ClientID == LocalCID && Line.m_TargetID >= 0)
{
str_format(aBuf, sizeof(aBuf), "%s [%s] ", Localize("To"),
m_pClient->m_aClients[Line.m_TargetID].m_aName);
}
else if(Line.m_TargetID == LocalCID)
{
str_format(aBuf, sizeof(aBuf), "%s [%s] ", Localize("From"),
m_pClient->m_aClients[Line.m_ClientID].m_aName);
}
else
dbg_break();
TextRender()->TextShadowed(&Cursor, aBuf, -1, ShadowOffset, ShadowColor, TextColor);
}
// we have to break protocol to make that work
// CNetMsg_Sv_Chat needs a TargetID, like Cl_Chat
#if 0
if(line.m_Mode == CHAT_WHISPER)
{
TextColor = vec4(1.0f, 0.5f, 0.9f, Blend);
if(line.m_ClientID == m_pClient->m_LocalClientID)
TextRender()->TextEx(&Cursor, "To ", -1);
else
TextRender()->TextEx(&Cursor, "From ", -1);
}
#endif
// render name
if(Line.m_ClientID == -1)
TextColor = ColorSystem;

View file

@ -20,6 +20,7 @@ class CChat : public CComponent
int64 m_Time;
vec2 m_Size[2];
int m_ClientID;
int m_TargetID;
int m_Mode;
int m_NameColor;
char m_aName[64];
@ -74,7 +75,7 @@ public:
bool IsActive() const { return m_Mode != CHAT_NONE; }
void AddLine(int ClientID, int Team, const char *pLine);
void AddLine(int ClientID, int Team, const char *pLine, int TargetID = -1);
void EnableMode(int Team);

View file

@ -214,6 +214,7 @@ void CGameContext::SendChat(int ChatterClientID, int Mode, int To, const char *p
Msg.m_Mode = Mode;
Msg.m_ClientID = ChatterClientID;
Msg.m_pMessage = pText;
Msg.m_TargetID = -1;
if(Mode == CHAT_ALL)
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, -1);
@ -234,6 +235,7 @@ void CGameContext::SendChat(int ChatterClientID, int Mode, int To, const char *p
else // Mode == CHAT_WHISPER
{
// send to the clients
Msg.m_TargetID = To;
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ChatterClientID);
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, To);
}