X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Fnet.qh;h=b1f5326a9bb5a441b5094de347cfe973086d5bd6;hb=235e1cf920d59aca16a705699c45e6d83818d5cd;hp=f0a9cc282dc4d24d28a7abb3d8b9097af3f0a982;hpb=aa14e2a0c66030cfde1c5d9d2c0882b5aa4816c1;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/net.qh b/qcsrc/lib/net.qh index f0a9cc282..b1f5326a9 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) \ @@ -45,10 +56,11 @@ STATIC_INIT(RegisterTempEntities_renumber) { FOREACH(TempEntities, true, it.m_id 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) \ @@ -97,11 +109,9 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } .int Version; // deprecated, use SendFlags .int SendFlags; - .bool(entity to, int sendflags) SendEntity; - /** return false to remove from the client */ - .bool(entity this, entity to, int sendflags) SendEntity3; - bool SendEntity_self(entity to, int sendflags) { SELFPARAM(); return this.SendEntity3(this, to, sendflags); } + IntrusiveList g_uncustomizables; + STATIC_INIT(g_uncustomizables) { g_uncustomizables = IL_NEW(); } void Net_LinkEntity(entity e, bool docull, float dt, bool(entity this, entity to, int sendflags) sendfunc) { @@ -115,8 +125,7 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } setsize(e, mi, ma); } - e.SendEntity = SendEntity_self; - e.SendEntity3 = sendfunc; + setSendEntity(e, sendfunc); e.SendFlags = 0xFFFFFF; if (!docull) e.effects |= EF_NODEPTHTEST; @@ -130,22 +139,24 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } void Net_UnlinkEntity(entity e) { - e.SendEntity = func_null; + setSendEntity(e, func_null); } - .void() uncustomizeentityforclient; + .void(entity this) uncustomizeentityforclient; .float uncustomizeentityforclient_set; - void SetCustomizer(entity e, float() customizer, void() uncustomizer) + void SetCustomizer(entity e, bool(entity this, entity client) customizer, void(entity this) uncustomizer) { - e.customizeentityforclient = customizer; + setcefc(e, customizer); e.uncustomizeentityforclient = uncustomizer; e.uncustomizeentityforclient_set = !!uncustomizer; + if(uncustomizer) + IL_PUSH(g_uncustomizables, e); } void UncustomizeEntitiesRun() { - FOREACH_ENTITY_FLOAT(uncustomizeentityforclient_set, true, WITHSELF(it, it.uncustomizeentityforclient())); + IL_EACH(g_uncustomizables, it.uncustomizeentityforclient_set, it.uncustomizeentityforclient(it)); } STRING_ITERATOR(g_buf, string_null, 0); @@ -162,13 +173,13 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } { entity reader = C2S_Protocol_from(C2S); if (reader && reader.m_read && reader.m_read(NULL, sender, true)) continue; - LOG_SEVEREF("Net_ClientCommand() with malformed C2S=%d\n", C2S); + LOG_SEVEREF("Net_ClientCommand() with malformed C2S=%d", C2S); return; } g_buf_i--; int expected = strlen(buf); - if (g_buf_i > expected) LOG_WARNINGF("Underflow: %d", g_buf_i - expected); - if (g_buf_i < expected) LOG_WARNINGF("Overrflow: %d", expected - g_buf_i); + if (g_buf_i > expected) LOG_WARNF("Underflow: %d", g_buf_i - expected); + if (g_buf_i < expected) LOG_WARNF("Overrflow: %d", expected - g_buf_i); } #endif @@ -182,7 +193,7 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } } MACRO_END #define Net_Reject() \ MACRO_BEGIN { \ - if (this) remove(this); \ + if (this) delete(this); \ } MACRO_END string g_buf; @@ -206,9 +217,76 @@ 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 +// serialization: new style + +USING(Stream, int); +#if defined(SVQC) + #define stream_reading(stream) false + #define stream_writing(stream) true +#elif defined(CSQC) + #define stream_reading(stream) true + #define stream_writing(stream) false +#endif + +#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) \ + MACRO_BEGIN \ + WriteByte(stream, this); \ + MACRO_END +#elif defined(CSQC) + #define serialize_byte(stream, this) \ + MACRO_BEGIN \ + this = ReadByte(); \ + MACRO_END +#endif + +#if defined(SVQC) + #define serialize_float(stream, this) \ + MACRO_BEGIN \ + WriteCoord(stream, this); \ + MACRO_END +#elif defined(CSQC) + #define serialize_float(stream, this) \ + MACRO_BEGIN \ + this = ReadCoord(); \ + MACRO_END +#endif + +#define serialize_vector(stream, this) \ +MACRO_BEGIN \ + vector _v = this; \ + serialize_float(stream, _v.x); \ + serialize_float(stream, _v.y); \ + serialize_float(stream, _v.z); \ + this = _v; \ +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 + #define ReadRegistered(r) r##_from(Read_byte()) #define WriteRegistered(r, to, it) Write_byte(to, it.m_id) @@ -245,12 +323,13 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } #define Read_string() ReadString() #define Write_string(to, f) WriteString(to, f) -#ifndef MENUQC +#ifdef GAMEQC const float APPROXPASTTIME_ACCURACY_REQUIREMENT = 0.05; #define APPROXPASTTIME_MAX (16384 * APPROXPASTTIME_ACCURACY_REQUIREMENT) #define APPROXPASTTIME_RANGE (64 * APPROXPASTTIME_ACCURACY_REQUIREMENT) #ifdef CSQC + float servertime; entity ReadCSQCEntity() { int f = ReadShort(); @@ -263,14 +342,14 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); } 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()) - int _ReadSByte; + 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() {