1
0
Fork 0
mirror of https://github.com/galaxyhaxz/devilution synced 2024-11-14 16:29:02 +00:00
devilution/2020_03_31/Source/msgcmd.cpp

59 lines
1.1 KiB
C++
Raw Normal View History

2020-11-29 00:24:54 +00:00
#include "diablo.h"
#include "list.h"
#define COMMAND_LEN 128
struct EXTERNMESSAGE {
LIST_LINK(EXTERNMESSAGE) m_Link;
char command[COMMAND_LEN];
~EXTERNMESSAGE()
{
// BUGFIX: this is already called by m_Link's destructor
m_Link.Unlink();
}
static void operator delete(void *p) {
if (p)
SMemFree(p, "delete", SLOG_FUNCTION, 0);
}
};
static TList<EXTERNMESSAGE> sgChat_Cmd;
void msgcmd_cmd_cleanup()
{
sgChat_Cmd.DeleteAll();
}
void msgcmd_send_chat()
{
DWORD tick;
struct EXTERNMESSAGE *msg = sgChat_Cmd.Head();
if (msg) {
static DWORD sgdwMsgCmdTimer;
tick = GetTickCount();
if (tick - sgdwMsgCmdTimer >= 2000) {
sgdwMsgCmdTimer = tick;
SNetSendServerChatCommand(msg->command);
sgChat_Cmd.Remove(msg);
}
}
}
BOOL msgcmd_add_server_cmd_W(const char *chat_message)
{
if (chat_message[0] != '/')
return FALSE;
msgcmd_add_server_cmd(chat_message);
return TRUE;
}
void msgcmd_add_server_cmd(const char *command)
{
size_t len = strlen(command);
if (len && ++len <= COMMAND_LEN) {
struct EXTERNMESSAGE *msg = sgChat_Cmd.Create();
memcpy(msg->command, command, len);
}
}