Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some #81 mess #82

Open
wants to merge 1 commit into
base: chillerbot
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/game/client/components/chillerbot/chathelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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))
Expand All @@ -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))
{
Expand Down
47 changes: 47 additions & 0 deletions src/game/client/components/chillerbot/chathelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -71,17 +72,63 @@ 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';
for(int i = 0; i < PING_QUEUE_SIZE - 1; i++)
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];
Expand Down