6 REGISTER_NET_TEMP(net_debug)
8 NET_HANDLE(net_debug, bool isNew)
10 Net_Accept(net_debug);
11 this.sv_entnum = ReadShort();
12 if (ReadByte()) make_pure(this);
13 this.origin_x = ReadCoord();
14 this.origin_y = ReadCoord();
15 this.origin_z = ReadCoord();
16 setorigin(this, this.origin);
17 this.debug = true; // identify server entities by this
18 this.classname = strzone(ReadString());
19 this.sourceLocFile = strzone(ReadString());
20 this.sourceLocLine = ReadInt24_t();
26 bool debug_send(entity this, entity to, int sf)
28 int channel = MSG_ONE;
30 WriteHeader(channel, net_debug);
31 WriteShort(channel, num_for_edict(this));
32 WriteByte(channel, is_pure(this));
33 WriteCoord(channel, this.origin.x);
34 WriteCoord(channel, this.origin.y);
35 WriteCoord(channel, this.origin.z);
36 WriteString(channel, this.classname);
37 WriteString(channel, this.sourceLocFile);
38 WriteInt24_t(channel, this.sourceLocLine);
43 bool autocvar_debugdraw;
47 vector project_3d_to_2d(vector vec);
50 if (!autocvar_debugdraw) return;
51 static int debugdraw_frame;
54 FOREACH_ENTITY(true, LAMBDA(
55 if (it.debugdraw_last == debugdraw_frame) continue;
57 for (entity e = findradius(it.origin, 100); e; e = e.chain)
59 if (e.debugdraw_last == debugdraw_frame) continue;
60 e.debugdraw_last = debugdraw_frame;
61 vector rgb = (e.debug) ? '0 0 1' : '1 0 0';
64 if (autocvar_debugdraw < 2) continue;
67 vector pos = project_3d_to_2d(e.origin);
68 if (pos.z < 0) continue;
71 drawcolorcodedstring2(pos,
72 sprintf("%d: '%s'@%s:%d", (e.debug ? e.sv_entnum : num_for_edict(e)),
73 e.classname, e.sourceLocFile, e.sourceLocLine),
74 size * '1 1 0', rgb, 0.5, DRAWFLAG_NORMAL);
82 GENERIC_COMMAND(debugdraw_sv, "Dump all server entities")
86 case CMD_REQUEST_COMMAND:
88 if (!autocvar_debugdraw) return;
91 for (entity e = NULL; (e = findfloat(e, debug, 0)) && rem > 0; )
93 if (autocvar_debugdraw < 2 && is_pure(e)) continue;
94 debug_send(e, nextent(NULL), 0);
98 LOG_INFOF("%d server entities sent\n", n - rem);
103 case CMD_REQUEST_USAGE:
105 LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " debugdraw_sv"));