Add converse command

This commit is contained in:
def 2013-10-18 11:42:35 +02:00
parent 9f45368225
commit 34e568f41b
6 changed files with 63 additions and 6 deletions

View file

@ -698,6 +698,11 @@ void CGameContext::ConMe(IConsole::IResult *pResult, void *pUserData)
"/me is disabled on this server, admin can enable it by using sv_slash_me");
}
void CGameContext::ConConverse(IConsole::IResult *pResult, void *pUserData)
{
// This will never be called
}
void CGameContext::ConWhisper(IConsole::IResult *pResult, void *pUserData)
{
// This will never be called

View file

@ -15,6 +15,8 @@ CHAT_COMMAND("info", "", CFGFLAG_CHAT|CFGFLAG_SERVER, ConInfo, this, "Shows info
CHAT_COMMAND("me", "r", CFGFLAG_CHAT|CFGFLAG_SERVER, ConMe, this, "Like the famous irc command '/me says hi' will display '<yourname> says hi'")
CHAT_COMMAND("w", "sr", CFGFLAG_CHAT|CFGFLAG_SERVER, ConWhisper, this, "Whisper something to someone (private message)")
CHAT_COMMAND("whisper", "sr", CFGFLAG_CHAT|CFGFLAG_SERVER, ConWhisper, this, "Whisper something to someone (private message)")
CHAT_COMMAND("c", "r", CFGFLAG_CHAT|CFGFLAG_SERVER, ConConverse, this, "Converse with the last person you whispered to (private message)");
CHAT_COMMAND("converse", "r", CFGFLAG_CHAT|CFGFLAG_SERVER, ConConverse, this, "Converse with the last person you whispered to (private message)");
CHAT_COMMAND("pause", "", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTogglePause, this, "Toggles pause (if not activated on the server, it toggles spec)")
CHAT_COMMAND("spec", "", CFGFLAG_CHAT|CFGFLAG_SERVER, ConToggleSpec, this, "Toggles spec")
CHAT_COMMAND("rankteam", "?r", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTeamRank, this, "Shows the team rank of player with name r (your team rank by default)")

View file

@ -759,6 +759,13 @@ void CGameContext::OnClientDrop(int ClientID, const char *pReason)
if(m_apPlayers[i] && m_apPlayers[i]->m_SpectatorID == ClientID)
m_apPlayers[i]->m_SpectatorID = SPEC_FREEVIEW;
}
// update conversation targets
for(int i = 0; i < MAX_CLIENTS; ++i)
{
if(m_apPlayers[i] && m_apPlayers[i]->m_LastWhisperTo == ClientID)
m_apPlayers[i]->m_LastWhisperTo = -1;
}
}
void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
@ -822,6 +829,18 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
str_copy(pWhisperMsg, pMsg->m_pMessage + 9, 256);
Whisper(pPlayer->GetCID(), pWhisperMsg);
}
else if (str_comp_nocase_num(pMsg->m_pMessage+1, "c ", 2) == 0)
{
char pWhisperMsg[256];
str_copy(pWhisperMsg, pMsg->m_pMessage + 3, 256);
Converse(pPlayer->GetCID(), pWhisperMsg);
}
else if (str_comp_nocase_num(pMsg->m_pMessage+1, "converse ", 9) == 0)
{
char pWhisperMsg[256];
str_copy(pWhisperMsg, pMsg->m_pMessage + 10, 256);
Converse(pPlayer->GetCID(), pWhisperMsg);
}
else
{
if(g_Config.m_SvSpamprotection
@ -2337,9 +2356,6 @@ void CGameContext::Whisper(int ClientID, char *pStr)
pMessage = pStr;
if (!CheckClientID2(ClientID))
return;
char aBuf[256];
if (Error)
@ -2356,9 +2372,38 @@ void CGameContext::Whisper(int ClientID, char *pStr)
return;
}
str_format(aBuf, sizeof(aBuf), "[← %s] %s", Server()->ClientName(ClientID), pMessage);
SendChatTarget(Victim, aBuf);
WhisperID(ClientID, Victim, pMessage);
}
str_format(aBuf, sizeof(aBuf), "[→ %s] %s", Server()->ClientName(Victim), pMessage);
void CGameContext::WhisperID(int ClientID, int VictimID, char *pMessage)
{
if (!CheckClientID2(ClientID))
return;
if (!CheckClientID2(VictimID))
return;
m_apPlayers[ClientID]->m_LastWhisperTo = VictimID;
char aBuf[256];
str_format(aBuf, sizeof(aBuf), "[← %s] %s", Server()->ClientName(ClientID), pMessage);
SendChatTarget(VictimID, aBuf);
str_format(aBuf, sizeof(aBuf), "[→ %s] %s", Server()->ClientName(VictimID), pMessage);
SendChatTarget(ClientID, aBuf);
}
void CGameContext::Converse(int ClientID, char *pStr)
{
CPlayer *pPlayer = m_apPlayers[ClientID];
if (!pPlayer)
return;
if (pPlayer->m_LastWhisperTo < 0)
SendChatTarget(ClientID, "You do not have an ongoing conversation. Whisper to someone to start one");
else
{
WhisperID(ClientID, pPlayer->m_LastWhisperTo, pStr);
}
}

View file

@ -243,6 +243,7 @@ private:
static void ConJoinTeam(IConsole::IResult *pResult, void *pUserData);
static void ConMe(IConsole::IResult *pResult, void *pUserData);
static void ConWhisper(IConsole::IResult *pResult, void *pUserData);
static void ConConverse(IConsole::IResult *pResult, void *pUserData);
static void ConSetEyeEmote(IConsole::IResult *pResult, void *pUserData);
static void ConToggleBroadcast(IConsole::IResult *pResult, void *pUserData);
static void ConEyeEmote(IConsole::IResult *pResult, void *pUserData);
@ -275,6 +276,8 @@ private:
int m_NumMutes;
void Mute(IConsole::IResult *pResult, NETADDR *Addr, int Secs, const char *pDisplayName);
void Whisper(int ClientID, char *pStr);
void WhisperID(int ClientID, int VictimID, char *pMessage);
void Converse(int ClientID, char *pStr);
public:
CLayers *Layers() { return &m_Layers; }

View file

@ -43,6 +43,7 @@ CPlayer::CPlayer(CGameContext *pGameServer, int ClientID, int Team)
m_TimerType = g_Config.m_SvDefaultTimerType;
m_DefEmote = EMOTE_NORMAL;
m_Afk = false;
m_LastWhisperTo = -1;
//New Year
if (g_Config.m_SvEvents)

View file

@ -64,6 +64,7 @@ public:
int m_LastKill;
int m_LastCommands[4];
int m_LastCommandPos;
int m_LastWhisperTo;
// TODO: clean this up
struct