From a7bba97ddbb49f626951c4cb7fb72a9ba879f64c Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 30 Mar 2022 23:50:47 +0200 Subject: Brought NetMsg closer to standard --- NetEx/NetMsg.cpp | 44 +++++++++++++++++++++------------------- NetEx/NetMsg.h | 61 ++++++++++++++++++++++++-------------------------------- 2 files changed, 50 insertions(+), 55 deletions(-) (limited to 'NetEx') diff --git a/NetEx/NetMsg.cpp b/NetEx/NetMsg.cpp index 63489d9..4e775da 100644 --- a/NetEx/NetMsg.cpp +++ b/NetEx/NetMsg.cpp @@ -3,30 +3,33 @@ Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors Copyright (c) 1997-2006, Destroyer Studios LLC. - AUTHOR: John DiCamillo + AUTHOR: John DiCamillo - OVERVIEW - ======== - User level network message + OVERVIEW + ======== + User level network message */ -#include #include "NetMsg.h" -// +-------------------------------------------------------------------+ +#include +#include -static DWORD net_msg_sequence = 1; -// +-------------------------------------------------------------------+ +static std::uint32_t net_msg_sequence = 1; -NetMsg::NetMsg(DWORD nid, void* d, int l, BYTE f) - : msgid(net_msg_sequence++), netid(nid), len(l), flags(f) + +NetMsg::NetMsg(std::uint32_t nid, void* d, int l, std::uint8_t f) : + msgid(net_msg_sequence++), + netid(nid), + len(l), + flags(f) { - data = new BYTE[len]; + data = new std::uint8_t[len]; if (data) { - CopyMemory(data, d, len); + std::memcpy(data, d, len); if (len < MAX_SIZE) data[1] = len; @@ -38,12 +41,14 @@ NetMsg::NetMsg(DWORD nid, void* d, int l, BYTE f) } } -// +-------------------------------------------------------------------+ -NetMsg::NetMsg(DWORD nid, BYTE type, const char* text, int l, BYTE f) - : msgid(net_msg_sequence++), netid(nid), len(2+l), flags(f) +NetMsg::NetMsg(std::uint32_t nid, std::uint8_t type, const char* text, int l, std::uint8_t f) : + msgid(net_msg_sequence++), + netid(nid), + len(2+l), + flags(f) { - data = new BYTE[len]; + data = new std::uint8_t[len]; if (data) { data[0] = type; @@ -54,23 +59,22 @@ NetMsg::NetMsg(DWORD nid, BYTE type, const char* text, int l, BYTE f) data[1] = 0; if (len > 2) - CopyMemory(data+2, text, len-2); + std::memcpy(data + 2, text, len - 2); } else { len = 0; } } -// +-------------------------------------------------------------------+ NetMsg::~NetMsg() { delete [] data; } -// +-------------------------------------------------------------------+ -int NetMsg::operator < (const NetMsg& m) const +int +NetMsg::operator < (const NetMsg& m) const { if (data[0] == MULTIPART && m.data[0] == MULTIPART) { NetMsgMultipart* p1 = (NetMsgMultipart*) data; diff --git a/NetEx/NetMsg.h b/NetEx/NetMsg.h index 1a8585f..4e1cf18 100644 --- a/NetEx/NetMsg.h +++ b/NetEx/NetMsg.h @@ -3,25 +3,19 @@ Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors Copyright (c) 1997-2006, Destroyer Studios LLC. - AUTHOR: John DiCamillo + AUTHOR: John DiCamillo - OVERVIEW - ======== - User level network message + OVERVIEW + ======== + User level network message */ - #ifndef NetMsg_h #define NetMsg_h -#include -#include "NetAddr.h" -#include "NetGram.h" -#include "NetSock.h" -#include "List.h" +#include -// +-------------------------------------------------------------------+ class NetMsg { @@ -30,52 +24,49 @@ public: enum FLAGS { RELIABLE = 0x01, PRIORITY = 0x02, SCATTER = 0x04 }; enum TYPES { INVALID = 0, - RESERVED = 0xF0, - MULTIPART = 0xF1 + RESERVED = 0xF0, + MULTIPART = 0xF1 }; enum { MAX_SIZE = 250 }; - NetMsg(DWORD nid, void* d, int l, BYTE f=0); - NetMsg(DWORD nid, BYTE type, const char* text, int len, BYTE f=0); + NetMsg(std::uint32_t nid, void* d, int l, std::uint8_t f=0); + NetMsg(std::uint32_t nid, std::uint8_t type, const char* text, int len, std::uint8_t f=0); ~NetMsg(); int operator == (const NetMsg& m) const { return msgid == m.msgid && netid == m.netid; } int operator < (const NetMsg& m) const; - DWORD Sequence() const { return msgid; } - DWORD NetID() const { return netid; } - const BYTE* Data() const { return data; } - BYTE Type() const { return data ? *data : 0; } - int Length() const { return len; } - BYTE Flags() const { return flags; } + std::uint32_t Sequence() const { return msgid; } + std::uint32_t NetID() const { return netid; } + const std::uint8_t* Data() const { return data; } + std::uint8_t Type() const { return data ? *data : 0; } + int Length() const { return len; } + std::uint8_t Flags() const { return flags; } bool IsReliable() const { return flags & RELIABLE ? true : false; } bool IsPriority() const { return flags & PRIORITY ? true : false; } bool IsScatter() const { return flags & SCATTER ? true : false; } - void SetSequence(DWORD s) { msgid = s; } + void SetSequence(std::uint32_t s) { msgid = s; } private: - DWORD msgid; - DWORD netid; - BYTE* data; + std::uint32_t msgid; + std::uint32_t netid; + std::uint8_t* data; int len; - BYTE flags; + std::uint8_t flags; }; -// +-------------------------------------------------------------------+ struct NetMsgMultipart { - BYTE type; - BYTE len; - DWORD msgid; - DWORD partno; - DWORD nparts; - BYTE payload[256]; + std::uint8_t type; + std::uint8_t len; + std::uint32_t msgid; + std::uint32_t partno; + std::uint32_t nparts; + std::uint8_t payload[256]; }; -// +-------------------------------------------------------------------+ - #endif // NetMsg_h -- cgit v1.1