12 #define NET_HANDLE(id, param) bool Net_Handle_##id(entity this, entity sender, param) 14 #define NET_GUARD(id) \ 15 bool Net_Handle_##id##_guard(entity this, entity sender, bool isNew) { \ 17 serialize_marker(to, valid); \ 18 if (!valid) LOG_FATALF("Last message not fully parsed: %s", _net_prevmsgstr); \ 19 _net_prevmsgstr = #id; \ 20 return Net_Handle_##id(this, sender, isNew); \ 24 string _net_prevmsgstr;
25 #define REGISTER_NET_TEMP(id) \ 26 NET_HANDLE(id, bool); \ 28 REGISTER(TempEntities, NET, id, m_id, new_pure(net_temp_packet)) { \ 30 this.m_read = Net_Handle_##id##_guard; \ 33 #define REGISTER_NET_TEMP(id) \ 34 const bool NET_##id##_istemp = true; \ 35 REGISTER(TempEntities, NET, id, m_id, new_pure(net_temp_packet)) \ 40 #define REGISTER_NET_S2C(id) REGISTER_NET_TEMP(id) 53 #define REGISTER_NET_LINKED(id) \ 54 ACCUMULATE NET_HANDLE(id, bool isnew) \ 57 this.sourceLoc = __FILE__":"STR(__LINE__); \ 58 if (!this) isnew = true; \ 61 REGISTER(LinkedEntities, NET, id, m_id, new_pure(net_linked_packet)) \ 64 this.m_read = Net_Handle_##id##_guard; \ 67 #define REGISTER_NET_LINKED(id) \ 68 const bool NET_##id##_istemp = false; \ 69 REGISTER(LinkedEntities, NET, id, m_id, new_pure(net_linked_packet)) \ 86 #define REGISTER_NET_C2S(id) \ 87 NET_HANDLE(id, bool); \ 88 REGISTER(C2S_Protocol, NET, id, m_id, new_pure(net_c2s_packet)) \ 91 this.m_read = Net_Handle_##id; \ 94 #define REGISTER_NET_C2S(id) \ 95 const bool NET_##id##_istemp = true; \ 96 REGISTER(C2S_Protocol, NET, id, m_id, new_pure(net_c2s_packet)) \ 111 const int MSG_ENTITY = 5;
120 if (e.classname ==
"")
122 LOG_WARN(
"Net_LinkEntity called on an entity without a classname, assigning default");
123 e.classname =
"net_linked";
126 if (e.model ==
"" || e.modelindex == 0)
130 _setmodel(e,
"null");
135 e.SendFlags = 0xFFFFFF;
141 e.nextthink =
time + dt;
146 void Net_UnlinkEntity(
entity e)
151 .void(
entity this) uncustomizeentityforclient;
152 .float uncustomizeentityforclient_set;
156 setcefc(e, customizer);
157 e.uncustomizeentityforclient = uncustomizer;
158 e.uncustomizeentityforclient_set = !!uncustomizer;
163 void UncustomizeEntitiesRun()
165 IL_EACH(g_uncustomizables, it.uncustomizeentityforclient_set, it.uncustomizeentityforclient(it));
172 void Net_ClientCommand(
entity sender,
string command)
176 if (buf ==
"")
return;
178 for (
int C2S; (C2S = ReadByte()) >= 0; )
181 if (reader && reader.m_read && reader.m_read(
NULL, sender,
true))
continue;
182 LOG_SEVEREF(
"Net_ClientCommand() with malformed C2S=%d", C2S);
186 int expected =
strlen(buf);
187 if (g_buf_i > expected)
LOG_WARNF(
"Underflow: %d", g_buf_i - expected);
188 if (g_buf_i < expected)
LOG_WARNF(
"Overrflow: %d", expected - g_buf_i);
194 const int MSG_C2S = 0;
196 #define Net_Accept(classname) \ 198 if (!this) this = new(classname); \ 200 #define Net_Reject() \ 202 if (this) delete(this); \ 209 if (g_buf ==
"")
return;
210 localcmd(
"\ncmd c2s \"", strreplace(
"$",
"$$", g_buf),
"\"\n");
216 #define WriteHeader(to, id) \ 217 WriteByte(to, NET_##id.m_id) 219 #define WriteHeader(to, id) \ 221 if (NET_##id##_istemp) WriteByte(to, SVC_TEMPENTITY); \ 222 WriteByte(to, NET_##id.m_id); \ 223 bool _net_valid = false; serialize_marker(to, _net_valid); \ 231 #define stream_reading(stream) false 232 #define stream_writing(stream) true 234 #define stream_reading(stream) true 235 #define stream_writing(stream) false 238 #define serialize(T, stream, ...) \ 240 noref Stream _stream = stream; \ 241 serialize_##T(_stream, __VA_ARGS__); \ 245 #define serialize_byte(stream, this) \ 247 WriteByte(stream, this); \ 250 #define serialize_byte(stream, this) \ 257 #define serialize_float(stream, this) \ 259 WriteCoord(stream, this); \ 262 #define serialize_float(stream, this) \ 264 this = ReadCoord(); \ 268 #define serialize_vector(stream, this) \ 271 serialize_float(stream, _v.x); \ 272 serialize_float(stream, _v.y); \ 273 serialize_float(stream, _v.z); \ 277 #define serialize_marker(stream, this) \ 282 int _de = 0xDE, _ad = 0xAD, _be = 0xBE, _ef = 0xEF; \ 283 serialize_byte(stream, _de); \ 284 serialize_byte(stream, _ad); \ 285 serialize_byte(stream, _be); \ 286 serialize_byte(stream, _ef); \ 287 this = (_de == 0xDE && _ad == 0xAD && _be == 0xBE && _ef == 0xEF); \ 293 #define ReadRegistered(r) REGISTRY_GET(r, Read_byte()) 294 #define WriteRegistered(r, to, it) Write_byte(to, it.m_id) 296 #define Read_byte() ReadByte() 297 #define Write_byte(to, f) WriteByte(to, f) 306 string tmp =
strcat(g_buf, s);
323 return (ReadByte() << 8) | (ReadByte());
328 #define Read_int() ReadInt24_t() 329 #define Write_int(to, f) WriteInt24_t(to, f) 331 #define Read_float() ReadFloat() 332 #define Write_float(to, f) WriteFloat(to, f) 334 #define Read_string() ReadString() 335 #define Write_string(to, f) WriteString(to, f) 338 const float APPROXPASTTIME_ACCURACY_REQUIREMENT = 0.05;
339 #define APPROXPASTTIME_MAX (16384 * APPROXPASTTIME_ACCURACY_REQUIREMENT) 340 #define APPROXPASTTIME_RANGE (64 * APPROXPASTTIME_ACCURACY_REQUIREMENT) 347 if (f == 0)
return NULL;
352 int v = ReadShort() << 8;
356 #define ReadInt48_t() vec2(ReadInt24_t(), ReadInt24_t()) 357 #define ReadInt72_t() vec3(ReadInt24_t(), ReadInt24_t(), ReadInt24_t()) 359 noref
int _ReadSByte;
360 #define ReadSByte() (_ReadSByte = ReadByte(), (_ReadSByte & BIT(7) ? -128 : 0) + (_ReadSByte & BITS(7))) 361 #define ReadFloat() ReadCoord() 362 #define ReadVector() vec3(ReadFloat(), ReadFloat(), ReadFloat()) 363 #define ReadVector2D() vec2(ReadFloat(), ReadFloat()) 364 #define ReadAngleVector() vec3(ReadAngle(), ReadAngle(), ReadAngle()) 365 #define ReadAngleVector2D() vec2(ReadAngle(), ReadAngle()) 367 int Readbits(
int num)
369 if (num > 16)
return ReadInt24_t();
370 if (num > 8)
return ReadShort();
374 float ReadApproxPastTime()
376 float dt = ReadByte();
379 dt = (APPROXPASTTIME_MAX / 256) * (dt / (256 - dt));
381 return servertime - dt;
385 void WriteInt24_t(
float dst,
float val)
391 void WriteInt48_t(
float dst,
vector val)
393 WriteInt24_t(dst, val.x);
394 WriteInt24_t(dst, val.y);
396 void WriteInt72_t(
float dst,
vector val)
398 WriteInt24_t(dst, val.x);
399 WriteInt24_t(dst, val.y);
400 WriteInt24_t(dst, val.z);
403 #define WriteFloat(to, f) WriteCoord(to, f) 404 #define WriteVector(to, v) MACRO_BEGIN WriteFloat(to, v.x); WriteFloat(to, v.y); WriteFloat(to, v.z); MACRO_END 405 #define WriteVector2D(to, v) MACRO_BEGIN WriteFloat(to, v.x); WriteFloat(to, v.y); MACRO_END 406 #define WriteAngleVector(to, v) MACRO_BEGIN WriteAngle(to, v.x); WriteAngle(to, v.y); WriteAngle(to, v.z); MACRO_END 407 #define WriteAngleVector2D(to, v) MACRO_BEGIN WriteAngle(to, v.x); WriteAngle(to, v.y); MACRO_END 409 void Writebits(
float dst,
float val,
int num)
411 if (num > 16) { WriteInt24_t(dst, val);
return; }
412 if (num > 8) {
WriteShort(dst, val);
return; }
421 void WriteApproxPastTime(
float dst,
float t)
430 dt = 256 * (dt / ((APPROXPASTTIME_MAX / 256) + dt));
439 #define WRITESPECTATABLE_MSG_ONE(to, statement) MACRO_BEGIN \ 440 entity prev = msg_entity; \ 442 FOREACH_CLIENT(IS_REAL_CLIENT(it), { \ 443 if (it == dst || (it.classname == STR_SPECTATOR && it.enemy == dst)) \
#define IL_EACH(this, cond, body)
STATIC_INIT(TempEntities_renumber)
#define yenc_single(c, ret)
#define REGISTRY_GET(id, i)
#define REGISTRY_CHECK(id)
limitations: NULL cannot be present elements can only be present once a maximum of IL_MAX lists can e...
const float EF_NODEPTHTEST
#define ydec_single(stringiter, ret)
#define REGISTRY_SORT(...)
#define REGISTER_REGISTRY(id)
#define REGISTRY_DEFINE_GET(id, null)
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
STRING_ITERATOR(_json, string_null, 0)
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define REGISTRY(id, max)
Declare a new registry.
#define setSendEntity(e, f)
vector(float skel, float bonenum) _skel_get_boneabs_hidden
#define STRING_ITERATOR_SET(this, s, i)
#define FOREACH(list, cond, body)