From cf359d9ea26cd304209bec88ab8d31f2edffed06 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 13 Sep 2019 03:54:43 +0200 Subject: [PATCH] Remove server chat --- CMakeLists.txt | 1 - Source/control.cpp | 2 - Source/diablo.cpp | 1 - Source/diablo.h | 1 - Source/list.h | 253 --------------------------------------------- Source/msgcmd.cpp | 82 --------------- Source/msgcmd.h | 10 -- Source/multi.cpp | 1 - 8 files changed, 351 deletions(-) delete mode 100644 Source/list.h delete mode 100644 Source/msgcmd.cpp delete mode 100644 Source/msgcmd.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 907bc713e..9e3070997 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -140,7 +140,6 @@ add_library(devilution STATIC Source/monster.cpp Source/movie.cpp Source/mpqapi.cpp - Source/msgcmd.cpp Source/msg.cpp Source/multi.cpp Source/nthread.cpp diff --git a/Source/control.cpp b/Source/control.cpp index e31fec1eb..1e11c18fa 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -2080,8 +2080,6 @@ void control_reset_talk_msg(char *msg) if (whisper[i]) pmask |= 1 << i; } - - if (!msgcmd_add_server_cmd_W(sgszTalkMsg)) NetSendCmdString(pmask, sgszTalkMsg); } diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 15857615c..b988c3c4e 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -169,7 +169,6 @@ void run_game_loop(unsigned int uMsg) } multi_process_network_packets(); game_loop(gbGameLoopStartup); - msgcmd_send_chat(); gbGameLoopStartup = FALSE; DrawAndBlit(); } diff --git a/Source/diablo.h b/Source/diablo.h index 9a5b08596..afc7f258a 100644 --- a/Source/diablo.h +++ b/Source/diablo.h @@ -46,7 +46,6 @@ #include "movie.h" #include "mpqapi.h" #include "msg.h" -#include "msgcmd.h" #include "multi.h" #include "nthread.h" #include "objdat.h" diff --git a/Source/list.h b/Source/list.h deleted file mode 100644 index dae3524e2..000000000 --- a/Source/list.h +++ /dev/null @@ -1,253 +0,0 @@ -/* Intrusive double-linked list implementation, - * based on https://github.com/webcoyote/coho/blob/master/Base/List.h - */ - -#include "../3rdParty/Storm/Source/storm.h" - -DEVILUTION_BEGIN_NAMESPACE - -#define OBJECT_NAME(obj) (((const char *)&typeid(obj)) + 8) - -/****************************************************************************** -* -* List definition macros -* -***/ - -// Define a field within a structure that will be used to link it into a list -#define LIST_LINK(T) TLink - -template -class TLink; - -/****************************************************************************** -* -* TList -* -***/ - -//============================================================================= -template -class TList { -public: - TList(); - ~TList(); - - void UnlinkAll(); - void DeleteAll(); - - T *Head(); - - enum InsertPos { - NONE = 0, - AFTER, - BEFORE - }; - - void Insert(T *node, InsertPos pos, T *ref); - T *Remove(T *node); - T *Create(InsertPos pos = BEFORE, size_t extra = 0, int memflags = 0); - -private: - size_t m_offset; - TLink m_link; - - TLink *GetLinkFromNode(T *node) const; - - // Hide copy-constructor and assignment operator - TList(const TList &); - TList &operator=(const TList &); - - static inline void SDelete(T *node) - { - SMemFree(node, (char *)OBJECT_NAME(T), SLOG_OBJECT, 0); - } -}; - -//============================================================================= -template -TList::~TList() -{ - // BUGFIX: Unlinking does not free memory, should use DeleteAll() - UnlinkAll(); -} - -//============================================================================= -template -TList::TList() -{ - size_t offset = offsetof(T, m_Link); - // Mark this node as the end of the list, with the link offset set - m_link.m_prevLink = &m_link; - m_offset = offset; - m_link.m_nextNode = (T *)~((size_t)&m_link - offset); -} - -//============================================================================= -template -void TList::DeleteAll() -{ - while (T *node = m_link.Next()) { - node->Delete(0x0); - SDelete(node); - } -} - -//============================================================================= -template -inline T *TList::Head() -{ - return m_link.Next(); -} - -//============================================================================= -template -inline TLink *TList::GetLinkFromNode(T *node) const -{ - // assert(m_offset != (size_t) -1); - // return (TLink *) ((size_t) node + m_offset); - return &node->m_Link; -} - -template -T *TList::Remove(T *node) -{ - TLink *link = node ? &node->m_Link : &m_link; - T *next = link->Next(); - node->Delete(0x0); - SDelete(node); - return next; -} - -template -T *TList::Create(InsertPos pos, size_t extra, int memflags) -{ - T *node = new (extra, memflags) T; - if (pos != NONE) - Insert(node, pos, NULL); - return node; -} - -template -void TList::Insert(T *node, InsertPos pos, T *ref) -{ - TLink *reflink; - TLink *i = node ? GetLinkFromNode(node) : &m_link; - if (i->IsLinked()) - i->Unlink(); - - reflink = ref ? GetLinkFromNode(ref) : &m_link; - - switch (pos) { - case AFTER: - i->InsertAfter(node, reflink, m_offset); - break; - case BEFORE: - i->InsertBefore(node, reflink); - break; - } -} - -//============================================================================= -template -void TList::UnlinkAll() -{ - for (;;) { - T *node = m_link.Next(); - if ((int)node <= 0) - break; - node->m_Link.Unlink(); - } -} - -/****************************************************************************** -* -* TLink -* -***/ - -//============================================================================= -template -class TLink { -public: - TLink() - : m_prevLink(NULL) - , m_nextNode(NULL) - { - } - ~TLink() - { - Unlink(); - } - - bool IsLinked() const - { - return m_prevLink != NULL; - } - void Unlink(); - - T *Next() - { - if ((ptrdiff_t)m_nextNode <= 0) - return NULL; - return m_nextNode; - } - - TLink *NextLink(size_t offset = -1) - { - if ((ptrdiff_t)m_nextNode <= 0) - return (TLink *)~((size_t)m_nextNode); - - if ((int)offset < 0) { - // Calculate the offset from a node pointer to a link structure - offset = (size_t)this - (size_t)m_prevLink->m_nextNode; - } - - // Get the link field for the next node - return (TLink *)((size_t)m_nextNode + offset); - } - - void InsertBefore(T *node, TLink *nextLink) - { - TLink *p = nextLink->m_prevLink; - m_prevLink = p; - m_nextNode = p->m_nextNode; - - p->m_nextNode = node; - nextLink->m_prevLink = this; - } - - inline void InsertAfter(T *node, TLink *prevLink, const size_t &offset) - { - m_prevLink = prevLink; - m_nextNode = prevLink->m_nextNode; - - prevLink->NextLink(offset)->m_prevLink = this; - prevLink->m_nextNode = node; - } - -private: - TLink *m_prevLink; // pointer to the previous >link field< - T *m_nextNode; // pointer to the next >object< - - // Hide copy-constructor and assignment operator - TLink(const TLink &); - TLink &operator=(const TLink &); - - friend class TList; -}; - -//============================================================================= -template -void TLink::Unlink() -{ - if (IsLinked()) { - NextLink()->m_prevLink = m_prevLink; - m_prevLink->m_nextNode = m_nextNode; - - m_prevLink = NULL; - m_nextNode = NULL; - } -} - -DEVILUTION_END_NAMESPACE diff --git a/Source/msgcmd.cpp b/Source/msgcmd.cpp deleted file mode 100644 index 35c9fe050..000000000 --- a/Source/msgcmd.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include // for placement new -#include // for offsetof -#include // for typeid - -#include "diablo.h" -#include "list.h" - -DEVILUTION_BEGIN_NAMESPACE - -#define COMMAND_LEN 128 - -// static float msgcmd_init_cpp_value = 0x7F800000; - -struct EXTERNMESSAGE { - LIST_LINK(EXTERNMESSAGE) - m_Link; - char command[COMMAND_LEN]; - void *operator new(size_t n, DWORD extralen, int flags) - { - return SMemAlloc(n + extralen, (char *)OBJECT_NAME(EXTERNMESSAGE), SLOG_OBJECT, flags | (1 << 3)); - } - void operator delete(void *address, DWORD extralen, int flags) - { - } - void operator delete(void *address) - { - } - void *Delete(DWORD flags); -}; - -void *EXTERNMESSAGE::Delete(DWORD flags) -{ - // BUGFIX: this is already called by m_Link's destructor - m_Link.Unlink(); - this->~EXTERNMESSAGE(); - if ((flags & 0x1) && this) { - SMemFree(this, "delete", SLOG_FUNCTION, 0); - } - return this; -} - -static TList 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); - } -} - -DEVILUTION_END_NAMESPACE diff --git a/Source/msgcmd.h b/Source/msgcmd.h deleted file mode 100644 index be57db0f1..000000000 --- a/Source/msgcmd.h +++ /dev/null @@ -1,10 +0,0 @@ -//HEADER_GOES_HERE -#ifndef __MSGCMD_H__ -#define __MSGCMD_H__ - -void msgcmd_cmd_cleanup(); -void msgcmd_send_chat(); -BOOL msgcmd_add_server_cmd_W(const char *chat_message); -void msgcmd_add_server_cmd(const char *command); - -#endif /* __MSGCMD_H__ */ diff --git a/Source/multi.cpp b/Source/multi.cpp index 7861b3179..27c7c20bd 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -612,7 +612,6 @@ void NetClose() tmsg_cleanup(); multi_event_handler(FALSE); SNetLeaveGame(3); - msgcmd_cmd_cleanup(); if (gbMaxPlayers > 1) Sleep(2000); }