diff --git a/src/game/client/components/chillerbot/chathelper.cpp b/src/game/client/components/chillerbot/chathelper.cpp index 6cd6f8690b3..476c3477d92 100644 --- a/src/game/client/components/chillerbot/chathelper.cpp +++ b/src/game/client/components/chillerbot/chathelper.cpp @@ -30,6 +30,7 @@ void CChatHelper::OnInit() m_NextMessageSend = 0; m_aLastAfkPing[0] = '\0'; mem_zero(m_aSendBuffer, sizeof(m_aSendBuffer)); + mem_zero(m_aPendingReplys, sizeof(m_aPendingReplys)); } void CChatHelper::OnRender() @@ -110,12 +111,14 @@ void CChatHelper::ConReplyToLastPing(IConsole::IResult *pResult, void *pUserData // given there is any respondable message is still in the stack while(aMessage[0]) { - pSelf->PopPing(aName, sizeof(aName), aClan, sizeof(aClan), aMessage, sizeof(aMessage)); + // pSelf->PopPing(aName, sizeof(aName), aClan, sizeof(aClan), aMessage, sizeof(aMessage)); + pSelf->GetLatestPing(aName, sizeof(aName), aClan, sizeof(aClan), aMessage, sizeof(aMessage)); CReplyToPing ReplyToPing = CReplyToPing(pSelf, aName, aClan, aMessage, aResponse, sizeof(aResponse)); if(ReplyToPing.Reply()) { if(aResponse[0]) { + pSelf->AddPendingReply(aResponse); pSelf->m_pClient->m_Chat.Say(0, aResponse); break; } @@ -246,8 +249,6 @@ void CChatHelper::OnChatMessage(int ClientID, int Team, const char *pMsg) Highlighted = true; if(Team == 3) // whisper recv Highlighted = true; - if(!Highlighted) - return; char aName[64]; str_copy(aName, m_pClient->m_aClients[ClientID].m_aName, sizeof(aName)); if(ClientID == 63 && !str_comp_num(m_pClient->m_aClients[ClientID].m_aName, " ", 2)) @@ -256,9 +257,17 @@ void CChatHelper::OnChatMessage(int ClientID, int Team, const char *pMsg) // dbg_msg("chillerbot", "fixname 128 player '%s' -> '%s'", m_pClient->m_aClients[ClientID].m_aName, aName); } // ignore own and dummys messages + bool OwnOrDummy = false; if(!str_comp(aName, m_pClient->m_aClients[m_pClient->m_LocalIDs[0]].m_aName)) - return; + OwnOrDummy = true; if(Client()->DummyConnected() && !str_comp(aName, m_pClient->m_aClients[m_pClient->m_LocalIDs[1]].m_aName)) + OwnOrDummy = true; + if(OwnOrDummy) + { + CheckPendingReplys(pMsg); + return; + } + if(!Highlighted) return; if(m_LangParser.IsGreeting(pMsg)) { diff --git a/src/game/client/components/chillerbot/chathelper.h b/src/game/client/components/chillerbot/chathelper.h index 73c23e2fc51..772f408f1e7 100644 --- a/src/game/client/components/chillerbot/chathelper.h +++ b/src/game/client/components/chillerbot/chathelper.h @@ -59,6 +59,7 @@ class CChatHelper : public CComponent Popping of the stack will always give you the most recent message. */ CLastPing m_aLastPings[PING_QUEUE_SIZE]; + char m_aPendingReplys[PING_QUEUE_SIZE][1024]; void PushPing(const char *pName, const char *pClan, const char *pMessage) { @@ -71,10 +72,18 @@ class CChatHelper : public CComponent m_aLastPings[0].m_ReciveTime = time_get(); } void PopPing(char *pName, int SizeOfName, char *pClan, int SizeOfClan, char *pMessage, int SizeOfMessage) + { + GetLatestPing(pName, SizeOfName, pClan, SizeOfClan, pMessage, SizeOfMessage); + ShiftPings(); + } + void GetLatestPing(char *pName, int SizeOfName, char *pClan, int SizeOfClan, char *pMessage, int SizeOfMessage) { str_copy(pName, m_aLastPings[0].m_aName, SizeOfName); str_copy(pClan, m_aLastPings[0].m_aClan, SizeOfClan); str_copy(pMessage, m_aLastPings[0].m_aMessage, SizeOfMessage); + } + void ShiftPings() + { m_aLastPings[PING_QUEUE_SIZE - 1].m_aName[0] = '\0'; m_aLastPings[PING_QUEUE_SIZE - 1].m_aClan[0] = '\0'; m_aLastPings[PING_QUEUE_SIZE - 1].m_aMessage[0] = '\0'; @@ -82,6 +91,44 @@ class CChatHelper : public CComponent m_aLastPings[i] = m_aLastPings[i + 1]; } + bool AddPendingReply(const char *pResponse) + { + for(auto &Reply : m_aPendingReplys) + { + if(Reply[0]) + { + if(!str_comp(Reply, pResponse)) + return true; + continue; + } + + str_copy(Reply, pResponse, sizeof(Reply)); + return true; + } + dbg_assert(true, "pending replys full"); + return false; + } + bool CheckPendingReplys(const char *pMessage) + { + dbg_msg("chathelper", "checking message='%s'", pMessage); + for(auto &Reply : m_aPendingReplys) + { + if(!Reply[0]) + continue; + + dbg_msg("chathelper", "checking message='%s' repls='%s'", pMessage, Reply); + if(!str_comp(pMessage, Reply)) + { + // yea this shouldnt work + // str comp against the actual ping we are popping + dbg_msg("chathelper", "shifiting message='%s'", pMessage); + ShiftPings(); + return true; + } + } + return false; + } + char m_aGreetName[32]; char m_aLastAfkPing[2048]; char m_aSendBuffer[MAX_CHAT_BUFFER_LEN][2048];