X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Fnet.qh;h=7b3f581b38f059cd4e4252905ae0dcf243983209;hb=b2e9de184227b0f37a03cfd18accec576f904625;hp=56c80e02d1b13ca5dcf66105aa597bb7c28d67f3;hpb=04338413d72286b6f5a6377bc43a1fac55976a59;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/net.qh b/qcsrc/lib/net.qh index 56c80e02d..7b3f581b3 100644 --- a/qcsrc/lib/net.qh +++ b/qcsrc/lib/net.qh @@ -4,19 +4,30 @@ #include "sort.qh" #include "yenc.qh" +// netcode mismatch and not sure what caused it? developer_csqcentities 1 + .string netname; .int m_id; .bool(entity this, entity sender, bool isNew) m_read; #define NET_HANDLE(id, param) bool Net_Handle_##id(entity this, entity sender, param) +#define NET_GUARD(id) \ + bool Net_Handle_##id##_guard(entity this, entity sender, bool isNew) { \ + bool valid = false; \ + serialize_marker(to, valid); \ + if (!valid) LOG_FATALF("Last message not fully parsed: %s", _net_prevmsgstr); \ + _net_prevmsgstr = #id; \ + return Net_Handle_##id(this, sender, isNew); \ + } #ifdef CSQC +string _net_prevmsgstr; #define REGISTER_NET_TEMP(id) \ NET_HANDLE(id, bool); \ - REGISTER(TempEntities, NET, id, m_id, new_pure(net_temp_packet)) \ - { \ + NET_GUARD(id); \ + REGISTER(TempEntities, NET, id, m_id, new_pure(net_temp_packet)) { \ this.netname = #id; \ - this.m_read = Net_Handle_##id; \ + this.m_read = Net_Handle_##id##_guard; \ } #else #define REGISTER_NET_TEMP(id) \ @@ -39,16 +50,17 @@ STATIC_INIT(RegisterTempEntities_renumber) { FOREACH(TempEntities, true, it.m_id #ifdef CSQC #define REGISTER_NET_LINKED(id) \ - [[accumulate]] NET_HANDLE(id, bool isnew) \ + ACCUMULATE NET_HANDLE(id, bool isnew) \ { \ this = __self; \ this.sourceLoc = __FILE__ ":" STR(__LINE__); \ if (!this) isnew = true; \ } \ + NET_GUARD(id); \ REGISTER(LinkedEntities, NET, id, m_id, new_pure(net_linked_packet)) \ { \ this.netname = #id; \ - this.m_read = Net_Handle_##id; \ + this.m_read = Net_Handle_##id##_guard; \ } #else #define REGISTER_NET_LINKED(id) \ @@ -95,7 +107,6 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } #ifdef SVQC const int MSG_ENTITY = 5; - .int Version; // deprecated, use SendFlags .int SendFlags; IntrusiveList g_uncustomizables; @@ -190,8 +201,7 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } { if (g_buf == "") return; localcmd("\ncmd c2s \"", strreplace("$", "$$", g_buf), "\"\n"); - strunzone(g_buf); - g_buf = string_null; + strfree(g_buf); } #endif @@ -205,6 +215,7 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } MACRO_BEGIN { \ if (NET_##id##_istemp) WriteByte(to, SVC_TEMPENTITY); \ WriteByte(to, NET_##id.m_id); \ + bool _net_valid = false; serialize_marker(to, _net_valid); \ } MACRO_END #endif @@ -219,7 +230,11 @@ USING(Stream, int); #define stream_writing(stream) false #endif -#define serialize(T, stream, ...) serialize_##T(stream, __VA_ARGS__) +#define serialize(T, stream, ...) \ +MACRO_BEGIN \ + noref Stream _stream = stream; \ + serialize_##T(_stream, __VA_ARGS__); \ +MACRO_END #if defined(SVQC) #define serialize_byte(stream, this) \ @@ -246,13 +261,27 @@ USING(Stream, int); #endif #define serialize_vector(stream, this) \ - MACRO_BEGIN \ +MACRO_BEGIN \ vector _v = this; \ serialize_float(stream, _v.x); \ serialize_float(stream, _v.y); \ serialize_float(stream, _v.z); \ this = _v; \ - MACRO_END +MACRO_END + +#define serialize_marker(stream, this) \ +MACRO_BEGIN \ + if (NDEBUG) { \ + this = true; \ + } else { \ + int _de = 0xDE, _ad = 0xAD, _be = 0xBE, _ef = 0xEF; \ + serialize_byte(stream, _de); \ + serialize_byte(stream, _ad); \ + serialize_byte(stream, _be); \ + serialize_byte(stream, _ef); \ + this = (_de == 0xDE && _ad == 0xAD && _be == 0xBE && _ef == 0xEF); \ + } \ +MACRO_END // serialization: old @@ -270,8 +299,12 @@ USING(Stream, int); string s = string_null; yenc_single(b, s); string tmp = strcat(g_buf, s); - if (g_buf) strunzone(g_buf); - g_buf = strzone(tmp); + strcpy(g_buf, tmp); + } + void WriteShort(int to, int b) + { + WriteByte(to, (b >> 8) & 0xFF); + WriteByte(to, b & 0xFF); } #elif defined(SVQC) int ReadByte() @@ -280,6 +313,10 @@ USING(Stream, int); ydec_single(g_buf, ret); return ret; } + int ReadShort() + { + return (ReadByte() << 8) | (ReadByte()); + } void WriteByte(int to, int b); #endif @@ -311,14 +348,14 @@ USING(Stream, int); v += ReadByte(); // note: this is unsigned return v; } - #define ReadInt48_t() vec3(ReadInt24_t(), ReadInt24_t(), 0) + #define ReadInt48_t() vec2(ReadInt24_t(), ReadInt24_t()) #define ReadInt72_t() vec3(ReadInt24_t(), ReadInt24_t(), ReadInt24_t()) noref int _ReadSByte; #define ReadSByte() (_ReadSByte = ReadByte(), (_ReadSByte & BIT(7) ? -128 : 0) + (_ReadSByte & BITS(7))) #define ReadFloat() ReadCoord() #define ReadVector() vec3(ReadFloat(), ReadFloat(), ReadFloat()) - #define ReadVector2D() vec3(ReadFloat(), ReadFloat(), 0) + #define ReadVector2D() vec2(ReadFloat(), ReadFloat()) float ReadApproxPastTime() {