add new protocol data type for IP addresses

(to avoid casting IPs to signed integer)

also mute single number debug messages for compound data structures like
string and key: no longer print a debug message for every char of a string
This commit is contained in:
ac-stef
2017-06-27 15:15:23 +02:00
parent f581506960
commit 0148c5b9a9
3 changed files with 52 additions and 8 deletions
+25 -2
View File
@@ -3,9 +3,9 @@
#include "cube.h"
#ifdef _DEBUG
bool protocoldbg = false;
bool protocoldbg = false, debugmute = false;
void protocoldebug(bool enable) { protocoldbg = enable; }
#define DEBUGCOND (protocoldbg)
#define DEBUGCOND (protocoldbg && !debugmute)
#endif
// all network traffic is in 32bit ints, which are then compressed using the following simple scheme (assumes that most values are small).
@@ -123,9 +123,11 @@ float getfloat(ucharbuf &p)
template<class T>
static inline void sendstring_(const char *text, T &p)
{
DEBUGCODE(debugmute = true);
const char *t = text;
if(t) { while(*t) putint(p, *t++); }
putint(p, 0);
DEBUGCODE(debugmute = false);
DEBUGVAR(text);
}
void sendstring(const char *t, ucharbuf &p) { sendstring_(t, p); }
@@ -134,6 +136,7 @@ void sendstring(const char *t, vector<uchar> &p) { sendstring_(t, p); }
void getstring(char *text, ucharbuf &p, int len)
{
DEBUGCODE(debugmute = true);
char *t = text;
do
{
@@ -142,9 +145,29 @@ void getstring(char *text, ucharbuf &p, int len)
*t = getint(p);
}
while(*t++);
DEBUGCODE(debugmute = false);
DEBUGVAR(text);
}
template<class T>
static inline void putip4_(T &p, enet_uint32 ip)
{
DEBUGCODE(string IP; iptoa(ip, IP));
DEBUGVAR(IP);
p.put(ip); p.put(ip>>8); p.put(ip>>16); p.put(ip>>24);
}
void putip4(ucharbuf &p, enet_uint32 ip) { putip4_(p, ip); }
void putip4(packetbuf &p, enet_uint32 ip) { putip4_(p, ip); }
void putip4(vector<uchar> &p, enet_uint32 ip) { putip4_(p, ip); }
enet_uint32 getip4(ucharbuf &p)
{
enet_uint32 ip = p.get() | (p.get()<<8) | (p.get()<<16) | (p.get()<<24);
DEBUGCODE(string IP; iptoa(ip, IP));
DEBUGVAR(IP);
return ip;
}
#define GZMSGBUFSIZE ((MAXGZMSGSIZE * 11) / 10)
static uchar *gzbuf = new uchar[GZMSGBUFSIZE]; // not thread-safe, but nesting is no problem