-#ifndef NET_H
-#define NET_H
+#pragma once
#include "registry.qh"
#include "sort.qh"
.string netname;
.int m_id;
-.bool(entity this, bool isNew) m_read;
-#define NET_HANDLE(id, param) bool Net_Handle_##id(entity this, param)
+.bool(entity this, entity sender, bool isNew) m_read;
+#define NET_HANDLE(id, param) bool Net_Handle_##id(entity this, entity sender, param)
#ifdef CSQC
[[accumulate]] NET_HANDLE(id, bool isnew) \
{ \
this = self; \
- this.sourceLocFile = __FILE__; \
- this.sourceLocLine = __LINE__; \
+ this.sourceLoc = __FILE__ ":" STR(__LINE__); \
if (!this) isnew = true; \
} \
REGISTER(LinkedEntities, NET, id, m_id, new_pure(net_linked_packet)) \
{
if (e.classname == "") e.classname = "net_linked";
- if (e.model == "" || self.modelindex == 0)
+ if (e.model == "" || e.modelindex == 0)
{
vector mi = e.mins;
vector ma = e.maxs;
void UncustomizeEntitiesRun()
{
- for (entity e = NULL; (e = findfloat(e, uncustomizeentityforclient_set, 1)); )
- WITH(entity, self, e, e.uncustomizeentityforclient());
+ FOREACH_ENTITY_FLOAT(uncustomizeentityforclient_set, true, LAMBDA(
+ WITH(entity, self, it, it.uncustomizeentityforclient());
+ ));
}
STRING_ITERATOR(g_buf, string_null, 0);
int ReadByte();
- void Net_ClientCommand(string command)
+ void Net_ClientCommand(entity sender, string command)
{
// command matches `c2s "(.+)"`
string buf = substring(command, argv_start_index(1) + 1, -2);
for (int C2S; (C2S = ReadByte()) >= 0; )
{
entity reader = C2S_Protocol_from(C2S);
- if (reader && reader.m_read && reader.m_read(NULL, true)) continue;
+ if (reader && reader.m_read && reader.m_read(NULL, sender, true)) continue;
LOG_SEVEREF("Net_ClientCommand() with malformed C2S=%d\n", C2S);
return;
}
} MACRO_END
#endif
-#define ReadRegistry(r) r##_from(Read_byte())
-#define WriteRegistry(r, to, it) Write_byte(to, it.m_id)
+#define ReadRegistered(r) r##_from(Read_byte())
+#define WriteRegistered(r, to, it) Write_byte(to, it.m_id)
#define Read_byte() ReadByte()
#define Write_byte(to, f) WriteByte(to, f)
}
// allow writing to also pass through to spectators (like so spectators see the same centerprints as players for example)
- #define WRITESPECTATABLE_MSG_ONE_VARNAME(varname, statement) \
- entity varname; varname = msg_entity; \
- FOR_EACH_REALCLIENT(msg_entity) \
- if (msg_entity == varname || (msg_entity.classname == STR_SPECTATOR && msg_entity.enemy == varname)) \
- statement msg_entity = varname
- #define WRITESPECTATABLE_MSG_ONE(statement) \
- MACRO_BEGIN \
- { \
- WRITESPECTATABLE_MSG_ONE_VARNAME(oldmsg_entity, statement); \
- } MACRO_END
- #define WRITESPECTATABLE(msg, statement) \
- if (msg == MSG_ONE) WRITESPECTATABLE_MSG_ONE(statement); \
- else \
- statement float WRITESPECTATABLE_workaround = 0
+ #define WRITESPECTATABLE_MSG_ONE(to, statement) MACRO_BEGIN { \
+ entity prev = msg_entity; \
+ entity dst = to; \
+ FOREACH_CLIENT(IS_REAL_CLIENT(it), { \
+ if (it == dst || (it.classname == STR_SPECTATOR && it.enemy == dst)) \
+ { \
+ msg_entity = it; \
+ LAMBDA(statement); \
+ } \
+ }); \
+ msg_entity = prev; \
+ } MACRO_END
#endif
#endif
-
-#endif