DEADSOFTWARE

game: disable shells for server
[d2df-sdl.git] / src / game / g_netmsg.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 unit g_netmsg;
18 interface
20 uses e_msg, g_net, g_triggers, Classes, SysUtils, md5;
22 const
23 NET_MSG_INFO = 100;
25 NET_MSG_CHAT = 101;
26 NET_MSG_SND = 102;
27 NET_MSG_GFX = 103;
28 NET_MSG_GEVENT = 104;
29 NET_MSG_SCORE = 105;
30 NET_MSG_COOP = 106;
31 NET_MSG_FLAG = 107;
32 NET_MSG_REQFST = 108;
33 NET_MSG_GSET = 109;
35 NET_MSG_PLR = 111;
36 NET_MSG_PLRPOS = 112;
37 NET_MSG_PLRSTA = 113;
38 NET_MSG_PLRDEL = 114;
39 NET_MSG_PLRDMG = 115;
40 NET_MSG_PLRDIE = 116;
41 NET_MSG_PLRFIRE= 117;
42 NET_MSG_PLRSET = 119;
43 NET_MSG_CHEAT = 120;
45 NET_MSG_ISPAWN = 121;
46 NET_MSG_IDEL = 122;
48 NET_MSG_MSPAWN = 131;
49 NET_MSG_MPOS = 132;
50 NET_MSG_MSTATE = 133;
51 NET_MSG_MSHOT = 134;
52 NET_MSG_MDEL = 135;
54 NET_MSG_PSTATE = 141;
55 NET_MSG_PTEX = 142;
57 NET_MSG_TSOUND = 151;
58 NET_MSG_TMUSIC = 152;
60 NET_MSG_SHDEL = 161;
61 NET_MSG_SHADD = 162;
62 NET_MSG_SHPOS = 163;
64 NET_MSG_RCON_AUTH = 191;
65 NET_MSG_RCON_CMD = 192;
66 NET_MSG_TIME_SYNC = 194;
67 NET_MSG_VOTE_EVENT = 195;
69 {
70 NET_MSG_MAP_REQUEST = 201;
71 NET_MSG_MAP_RESPONSE = 202;
72 NET_MSG_RES_REQUEST = 203;
73 NET_MSG_RES_RESPONSE = 204;
74 }
76 NET_CHAT_SYSTEM = 0;
77 NET_CHAT_PLAYER = 1;
78 NET_CHAT_TEAM = 2;
80 NET_RCON_NOAUTH = 0;
81 NET_RCON_PWGOOD = 1;
82 NET_RCON_PWBAD = 2;
84 NET_GFX_SPARK = 1;
85 NET_GFX_TELE = 2;
86 NET_GFX_RESPAWN = 3;
87 NET_GFX_FIRE = 4;
88 NET_GFX_EXPLODE = 5;
89 NET_GFX_BFGEXPL = 6;
90 NET_GFX_BFGHIT = 7;
91 NET_GFX_SHELL1 = 8;
92 NET_GFX_SHELL2 = 9;
93 NET_GFX_SHELL3 = 10;
95 NET_EV_MAPSTART = 1;
96 NET_EV_MAPEND = 2;
97 NET_EV_CHANGE_TEAM = 3;
98 NET_EV_PLAYER_KICK = 4;
99 NET_EV_PLAYER_BAN = 5;
100 NET_EV_LMS_WARMUP = 6;
101 NET_EV_LMS_SURVIVOR = 7;
102 NET_EV_RCON = 8;
103 NET_EV_BIGTEXT = 9;
104 NET_EV_SCORE = 10;
105 NET_EV_SCORE_MSG = 11;
106 NET_EV_LMS_START = 12;
107 NET_EV_LMS_WIN = 13;
108 NET_EV_TLMS_WIN = 14;
109 NET_EV_LMS_LOSE = 15;
110 NET_EV_LMS_DRAW = 16;
111 NET_EV_KILLCOMBO = 17;
112 NET_EV_PLAYER_TOUCH = 18;
113 NET_EV_SECRET = 19;
114 NET_EV_INTER_READY = 20;
115 NET_EV_LMS_NOSPAWN = 21;
117 NET_VE_STARTED = 1;
118 NET_VE_PASSED = 2;
119 NET_VE_FAILED = 3;
120 NET_VE_VOTE = 4;
121 NET_VE_REVOKE = 5;
122 NET_VE_INPROGRESS = 6;
124 NET_FLAG_GET = 1;
125 NET_FLAG_DROP = 2;
126 NET_FLAG_CAP = 3;
127 NET_FLAG_RETURN = 4;
129 NET_CHEAT_SUICIDE = 1;
130 NET_CHEAT_SPECTATE = 2;
131 NET_CHEAT_READY = 3;
133 NET_MAX_DIFFTIME = 5000 div 36;
135 // HOST MESSAGES
137 procedure MH_ProcessFirstSpawn (C: pTNetClient);
139 procedure MH_RECV_Info(C: pTNetClient; var M: TMsg);
140 procedure MH_RECV_Chat(C: pTNetClient; var M: TMsg);
141 procedure MH_RECV_FullStateRequest(C: pTNetClient; var M: TMsg);
142 function MH_RECV_PlayerPos(C: pTNetClient; var M: TMsg): Word;
143 procedure MH_RECV_PlayerSettings(C: pTNetClient; var M: TMsg);
144 procedure MH_RECV_CheatRequest(C: pTNetClient; var M: TMsg);
145 procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
146 procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
147 //procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
148 //procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
149 procedure MH_RECV_Vote(C: pTNetClient; var M: TMsg);
151 // GAME
152 procedure MH_SEND_Everything(CreatePlayers: Boolean {= False}; ID: Integer {= NET_EVERYONE});
153 procedure MH_SEND_Info(ID: Byte);
154 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
155 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
156 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
157 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
158 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
159 procedure MH_SEND_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
160 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
161 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
162 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
163 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
164 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
165 // PLAYER
166 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
167 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
168 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
169 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
170 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
171 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
172 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
173 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
174 // ITEM
175 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
176 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
177 // PANEL
178 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
179 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
180 // MONSTER
181 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
182 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
183 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
184 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
185 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
186 // TRIGGER
187 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
188 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
189 // MISC
190 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
191 procedure MH_SEND_VoteEvent(EvType: Byte;
192 StrArg1: string = 'a'; StrArg2: string = 'b';
193 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
194 ID: Integer = NET_EVERYONE);
196 // CLIENT MESSAGES //
198 // GAME
199 procedure MC_RECV_Chat(var M: TMsg);
200 procedure MC_RECV_Effect(var M: TMsg);
201 procedure MC_RECV_Sound(var M: TMsg);
202 procedure MC_RECV_GameStats(var M: TMsg);
203 procedure MC_RECV_CoopStats(var M: TMsg);
204 procedure MC_RECV_GameEvent(var M: TMsg);
205 procedure MC_RECV_FlagEvent(var M: TMsg);
206 procedure MC_RECV_GameSettings(var M: TMsg);
207 // PLAYER
208 function MC_RECV_PlayerCreate(var M: TMsg): Word;
209 function MC_RECV_PlayerPos(var M: TMsg): Word;
210 function MC_RECV_PlayerStats(var M: TMsg): Word;
211 function MC_RECV_PlayerDelete(var M: TMsg): Word;
212 function MC_RECV_PlayerDamage(var M: TMsg): Word;
213 function MC_RECV_PlayerDeath(var M: TMsg): Word;
214 function MC_RECV_PlayerFire(var M: TMsg): Word;
215 procedure MC_RECV_PlayerSettings(var M: TMsg);
216 // ITEM
217 procedure MC_RECV_ItemSpawn(var M: TMsg);
218 procedure MC_RECV_ItemDestroy(var M: TMsg);
219 // PANEL
220 procedure MC_RECV_PanelTexture(var M: TMsg);
221 procedure MC_RECV_PanelState(var M: TMsg);
222 // MONSTER
223 procedure MC_RECV_MonsterSpawn(var M: TMsg);
224 procedure MC_RECV_MonsterPos(var M: TMsg);
225 procedure MC_RECV_MonsterState(var M: TMsg);
226 procedure MC_RECV_MonsterShot(var M: TMsg);
227 procedure MC_RECV_MonsterDelete(var M: TMsg);
228 // SHOT
229 procedure MC_RECV_CreateShot(var M: TMsg);
230 procedure MC_RECV_UpdateShot(var M: TMsg);
231 procedure MC_RECV_DeleteShot(var M: TMsg);
232 // TRIGGER
233 procedure MC_RECV_TriggerSound(var M: TMsg);
234 procedure MC_RECV_TriggerMusic(var M: TMsg);
235 // MISC
236 procedure MC_RECV_TimeSync(var M: TMsg);
237 procedure MC_RECV_VoteEvent(var M: TMsg);
238 // SERVICE
239 procedure MC_SEND_Info(Password: string);
240 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
241 procedure MC_SEND_PlayerPos();
242 procedure MC_SEND_FullStateRequest();
243 procedure MC_SEND_PlayerSettings();
244 procedure MC_SEND_CheatRequest(Kind: Byte);
245 procedure MC_SEND_RCONPassword(Password: string);
246 procedure MC_SEND_RCONCommand(Cmd: string);
247 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
248 // DOWNLOAD
249 //procedure MC_SEND_MapRequest();
250 //procedure MC_SEND_ResRequest(const resName: AnsiString);
253 type
254 TExternalResourceInfo = record
255 Name: string[255];
256 md5: TMD5Digest;
257 end;
259 TResDataMsg = record
260 MsgId: Byte;
261 FileSize: Integer;
262 FileData: AByte;
263 end;
265 TMapDataMsg = record
266 MsgId: Byte;
267 FileSize: Integer;
268 FileData: AByte;
269 ExternalResources: array of TExternalResourceInfo;
270 end;
272 function IsValidFileName(const S: String): Boolean;
273 function IsValidFilePath(const S: String): Boolean;
276 implementation
278 uses
279 {$IFDEF ENABLE_MENU}
280 g_gui,
281 {$ENDIF}
282 {$IFDEF ENABLE_GFX}
283 g_gfx,
284 {$ENDIF}
285 {$IFDEF ENABLE_SHELLS}
286 g_shells,
287 {$ENDIF}
288 Math, ENet, e_input, e_log, g_base, g_basic,
289 g_textures, g_sound, g_console, g_options,
290 g_game, g_player, g_map, g_panel, g_items, g_weapons, g_phys,
291 g_language, g_monsters, g_netmaster, utils, wadreader, MAPDEF
294 const
295 NET_KEY_LEFT = 1;
296 NET_KEY_RIGHT = 2;
297 NET_KEY_UP = 4;
298 NET_KEY_DOWN = 8;
299 NET_KEY_JUMP = 16;
300 NET_KEY_FIRE = 32;
301 NET_KEY_OPEN = 64;
302 NET_KEY_NW = 256;
303 NET_KEY_PW = 512;
304 NET_KEY_CHAT = 2048;
305 NET_KEY_FORCEDIR = 4096;
307 //var
308 //kBytePrev: Word = 0;
309 //kDirPrev: TDirection = D_LEFT;
310 //HostGameTime: Word = 0;
313 function IsValidFileName(const S: String): Boolean;
314 const
315 Forbidden: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
316 var
317 I: Integer;
318 begin
319 Result := S <> '';
320 for I := 1 to Length(S) do
321 Result := Result and (not(S[I] in Forbidden));
322 end;
324 function IsValidFilePath(const S: String): Boolean;
325 var
326 I: Integer;
327 begin
328 Result := False;
329 if not IsValidFileName(S) then exit;
330 if FileExists(S) then exit;
331 I := LastDelimiter('\/', S);
332 if (I > 0) then
333 if (not DirectoryExists(Copy(S, 1, I-1))) then
334 exit;
335 Result := True;
336 end;
339 // HOST MESSAGES //
342 // GAME
344 procedure MH_RECV_Chat(C: pTNetClient; var M: TMsg);
345 var
346 Txt: string;
347 Mode: Byte;
348 PID: Word;
349 Pl: TPlayer;
350 begin
351 PID := C^.Player;
352 Pl := g_Player_Get(PID);
354 Txt := M.ReadString();
355 Mode := M.ReadByte();
356 if (Mode = NET_CHAT_SYSTEM) then
357 Mode := NET_CHAT_PLAYER; // prevent sending system messages from clients
358 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
359 Mode := NET_CHAT_PLAYER; // revert to player chat in non-team game
361 if Pl = nil then
362 MH_SEND_Chat(Txt, Mode)
363 else
364 MH_SEND_Chat(Pl.Name + ': ' + Txt, Mode, IfThen(Mode = NET_CHAT_TEAM, Pl.Team, NET_EVERYONE));
365 end;
367 procedure MH_RECV_Info(C: pTNetClient; var M: TMsg);
368 var
369 Ver, PName, Model, Pw: string;
370 R, G, B, T: Byte;
371 PID: Word;
372 Color: TRGB;
373 I: Integer;
374 begin
375 Ver := M.ReadString();
376 Pw := M.ReadString();
377 PName := M.ReadString();
378 Model := M.ReadString();
379 R := M.ReadByte();
380 G := M.ReadByte();
381 B := M.ReadByte();
382 T := M.ReadByte();
384 if Ver <> GAME_VERSION then
385 begin
386 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
387 _lc[I_NET_DISC_VERSION]);
388 enet_peer_disconnect(C^.Peer, NET_DISC_VERSION);
389 Exit;
390 end;
392 if g_Net_IsHostBanned(C^.Peer^.address.host) then
393 begin
394 if g_Net_IsHostBanned(C^.Peer^.address.host, True) then
395 begin
396 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
397 _lc[I_NET_DISC_BAN]);
398 enet_peer_disconnect(C^.Peer, NET_DISC_BAN);
399 end
400 else
401 begin
402 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
403 _lc[I_NET_DISC_BAN]);
404 enet_peer_disconnect(C^.Peer, NET_DISC_TEMPBAN);
405 end;
406 Exit;
407 end;
409 if NetPassword <> '' then
410 if AnsiLowerCase(NetPassword) <> AnsiLowerCase(Pw) then
411 begin
412 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
413 _lc[I_NET_DISC_PASSWORD]);
414 enet_peer_disconnect(C^.Peer, NET_DISC_PASSWORD);
415 Exit;
416 end;
418 Color.R := R;
419 Color.B := B;
420 Color.G := G;
422 PID := g_Player_Create(Model, Color, T, False);
423 with g_Player_Get(PID) do
424 begin
425 Name := PName;
426 Reset(True);
427 end;
429 C^.Player := PID;
430 C^.WaitForFirstSpawn := false;
432 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
433 e_WriteLog('NET: Client ' + PName + ' [' + IntToStr(C^.ID) +
434 '] connected. Assigned player #' + IntToStr(PID) + '.', TMsgType.Notify);
436 MH_SEND_Info(C^.ID);
438 with g_Player_Get(PID) do
439 begin
440 Name := PName;
441 FClientID := C^.ID;
442 // round in progress, don't spawn
443 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C.ID, C.Player]);
444 //e_LogWritefln('spawning player with pid #%u...', [PID]);
445 //Respawn(gGameSettings.GameType = GT_SINGLE);
446 //k8: no, do not spawn a player yet, wait for "request full state" packet
447 Lives := 0;
448 Spectate;
449 FNoRespawn := True;
450 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
451 // that is, if we'll set it to `true`, the player can be spawned after
452 // warmup time ran out, for example, regardless of the real player state.
453 // also, this seems to work only for the initial connection. further
454 // map changes could initiate resource downloading, but the player will
455 // be spawned immediately.
456 // the proper solution will require another player state, "ephemeral".
457 // the player should start any map in "ephemeral" state, and turned into
458 // real mobj only when they sent a special "i am ready" packet. this packet
459 // must be sent after receiving the full state, so the player will get a full
460 // map view before going into game.
461 FWantsInGame := false;
462 C^.WaitForFirstSpawn := true;
463 end;
465 //if not C^.WaitForFirstSpawn then
466 begin
467 for I := Low(NetClients) to High(NetClients) do
468 begin
469 if NetClients[I].ID = C^.ID then Continue;
470 MH_SEND_PlayerCreate(PID, NetClients[I].ID);
471 MH_SEND_PlayerPos(True, PID, NetClients[I].ID);
472 MH_SEND_PlayerStats(PID, NetClients[I].ID);
473 end;
474 end;
476 if gState in [STATE_INTERCUSTOM, STATE_FOLD] then
477 MH_SEND_GameEvent(NET_EV_MAPEND, 0, 'N', C^.ID);
479 if NetUseMaster then
480 begin
481 //g_Net_Slist_Update;
482 g_Net_Slist_Pulse();
483 end;
484 end;
487 procedure MH_ProcessFirstSpawn (C: pTNetClient);
488 var
489 plr: TPlayer;
490 begin
491 if not C.WaitForFirstSpawn then exit;
492 plr := g_Player_Get(C^.Player);
493 if not assigned(plr) then exit;
494 g_Net_Slist_ServerPlayerComes();
495 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C.ID, C.Player]);
496 C.WaitForFirstSpawn := false;
497 plr.FNoRespawn := false;
498 plr.FWantsInGame := true; // TODO: look into this later
500 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
501 begin
502 plr.Spectate;
503 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN, 0, 'N', C.ID);
504 end
505 else
506 begin
507 plr.Respawn(False);
508 if gLMSRespawn > LMS_RESPAWN_NONE then
509 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime, 'N', C.ID);
510 end;
511 end;
514 procedure MH_RECV_FullStateRequest(C: pTNetClient; var M: TMsg);
515 begin
516 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
517 if gGameOn then
518 begin
519 MH_SEND_Everything((C^.State = NET_STATE_AUTH), C^.ID)
520 end
521 else
522 begin
523 C^.RequestedFullUpdate := True;
524 end;
525 end;
527 // PLAYER
529 function MH_RECV_PlayerPos(C: pTNetClient; var M: TMsg): Word;
530 var
531 Dir, i: Byte;
532 WeaponSelect: Word;
533 PID: Word;
534 kByte: Word;
535 Pl: TPlayer;
536 GT: LongWord;
537 begin
538 Result := 0;
539 if not gGameOn then Exit;
541 GT := M.ReadLongWord();
542 PID := C^.Player;
543 Pl := g_Player_Get(PID);
544 if Pl = nil then
545 Exit;
547 if (GT > gTime + NET_MAX_DIFFTIME) or (GT < Pl.NetTime) then Exit;
549 with Pl do
550 begin
551 NetTime := GT;
552 kByte := M.ReadWord();
553 Dir := M.ReadByte();
554 WeaponSelect := M.ReadWord();
555 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
556 if Direction <> TDirection(Dir) then
557 JustTeleported := False;
559 SetDirection(TDirection(Dir));
560 ReleaseKeys;
562 if kByte = NET_KEY_CHAT then
563 begin
564 PressKey(KEY_CHAT, 10000);
565 Exit;
566 end;
568 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
569 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
570 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
571 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
572 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
573 if LongBool(kByte and NET_KEY_FIRE) then PressKey(KEY_FIRE, 10000);
574 if LongBool(kByte and NET_KEY_OPEN) then PressKey(KEY_OPEN, 10000);
575 if LongBool(kByte and NET_KEY_NW) then PressKey(KEY_NEXTWEAPON, 10000);
576 if LongBool(kByte and NET_KEY_PW) then PressKey(KEY_PREVWEAPON, 10000);
578 for i := 0 to 15 do
579 begin
580 if (WeaponSelect and Word(1 shl i)) <> 0 then
581 begin
582 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
583 QueueWeaponSwitch(i);
584 end;
585 end;
586 end;
588 // MH_SEND_PlayerPos(False, PID, C^.ID);
589 end;
591 procedure MH_RECV_CheatRequest(C: pTNetClient; var M: TMsg);
592 var
593 CheatKind: Byte;
594 Pl: TPlayer;
595 begin
596 Pl := g_Player_Get(C^.Player);
597 if Pl = nil then Exit;
599 CheatKind := M.ReadByte();
601 case CheatKind of
602 NET_CHEAT_SUICIDE:
603 Pl.Damage(SUICIDE_DAMAGE, Pl.UID, 0, 0, HIT_SELF);
604 NET_CHEAT_SPECTATE:
605 begin
606 if Pl.FSpectator then
607 begin
608 if (gGameSettings.MaxLives = 0) or (gLMSRespawn > LMS_RESPAWN_NONE) then
609 Pl.Respawn(False)
610 else
611 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN, Pl.UID);
612 end
613 else
614 Pl.Spectate;
615 end;
616 NET_CHEAT_READY:
617 begin
618 if gState <> STATE_INTERCUSTOM then Exit;
619 Pl.FReady := not Pl.FReady;
620 if Pl.FReady then
621 begin
622 MH_SEND_GameEvent(NET_EV_INTER_READY, Pl.UID, 'Y');
623 Inc(gInterReadyCount);
624 end
625 else
626 begin
627 MH_SEND_GameEvent(NET_EV_INTER_READY, Pl.UID, 'N');
628 Dec(gInterReadyCount);
629 end;
630 end;
631 end;
632 end;
634 procedure MH_RECV_PlayerSettings(C: pTNetClient; var M: TMsg);
635 var
636 TmpName: string;
637 TmpModel: string;
638 TmpColor: TRGB;
639 TmpTeam: Byte;
640 Pl: TPlayer;
641 begin
642 TmpName := M.ReadString();
643 TmpModel := M.ReadString();
644 TmpColor.R := M.ReadByte();
645 TmpColor.G := M.ReadByte();
646 TmpColor.B := M.ReadByte();
647 TmpTeam := M.ReadByte();
649 Pl := g_Player_Get(C^.Player);
650 if Pl = nil then Exit;
652 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
653 Pl.SwitchTeam
654 else
655 Pl.SetColor(TmpColor);
657 if Pl.Name <> TmpName then
658 begin
659 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
660 Pl.Name := TmpName;
661 end;
663 if TmpModel <> Pl.Model.GetName() then
664 Pl.SetModel(TmpModel);
666 MH_SEND_PlayerSettings(Pl.UID, TmpModel);
667 end;
669 // RCON
671 procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
672 var
673 Pwd: string;
674 begin
675 Pwd := M.ReadString();
676 if not NetAllowRCON then Exit;
677 if Pwd = NetRCONPassword then
678 begin
679 C^.RCONAuth := True;
680 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWGOOD, 'N', C^.ID);
681 end
682 else
683 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWBAD, 'N', C^.ID);
684 end;
686 procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
687 var
688 Cmd: string;
689 begin
690 Cmd := M.ReadString();
691 if not NetAllowRCON then Exit;
692 if not C^.RCONAuth then
693 begin
694 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_NOAUTH, 'N', C^.ID);
695 Exit;
696 end;
697 g_Console_Process(Cmd);
698 end;
700 // MISC
702 procedure MH_RECV_Vote(C: pTNetClient; var M: TMsg);
703 var
704 Start: Boolean;
705 Name, Command: string;
706 Need: Integer;
707 Pl: TPlayer;
708 begin
709 Start := M.ReadByte() <> 0;
710 Command := M.ReadString();
712 Pl := g_Player_Get(C^.Player);
713 if Pl = nil then Exit;
714 Name := Pl.Name;
716 if Start then
717 begin
718 if not g_Console_CommandBlacklisted(Command) then
719 g_Game_StartVote(Command, Name);
720 end
721 else if gVoteInProgress then
722 begin
723 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
724 Need := Floor((NetClientCount+1)/2.0) + 1
725 else
726 Need := Floor(NetClientCount/2.0) + 1;
727 if C^.Voted then
728 begin
729 Dec(gVoteCount);
730 C^.Voted := False;
731 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [Name, gVoteCount, Need]), True);
732 MH_SEND_VoteEvent(NET_VE_REVOKE, Name, 'a', gVoteCount, Need);
733 end
734 else
735 begin
736 Inc(gVoteCount);
737 C^.Voted := True;
738 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Name, gVoteCount, Need]), True);
739 MH_SEND_VoteEvent(NET_VE_VOTE, Name, 'a', gVoteCount, Need);
740 g_Game_CheckVote;
741 end;
742 end;
743 end;
745 // GAME (SEND)
747 procedure MH_SEND_Everything(CreatePlayers: Boolean {= False}; ID: Integer {= NET_EVERYONE});
749 function sendItemRespawn (it: PItem): Boolean;
750 begin
751 result := false; // don't stop
752 MH_SEND_ItemSpawn(True, it.myid, ID);
753 end;
755 function sendMonSpawn (mon: TMonster): Boolean;
756 begin
757 result := false; // don't stop
758 MH_SEND_MonsterSpawn(mon.UID, ID);
759 end;
761 function sendPanelState (pan: TPanel): Boolean;
762 begin
763 result := false; // don't stop
764 MH_SEND_PanelState(pan.guid, ID); // anyway, to sync mplats
765 if (pan.CanChangeTexture) then MH_SEND_PanelTexture(pan.guid, pan.LastAnimLoop, ID);
766 end;
768 var
769 I: Integer;
770 begin
771 if (ID >= 0) and (ID < length(NetClients)) then
772 begin
773 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID, NetClients[ID].Player]);
774 MH_ProcessFirstSpawn(@NetClients[ID]);
775 end;
777 if gPlayers <> nil then
778 begin
779 for I := Low(gPlayers) to High(gPlayers) do
780 begin
781 if gPlayers[I] <> nil then
782 begin
783 if CreatePlayers then MH_SEND_PlayerCreate(gPlayers[I].UID, ID);
784 MH_SEND_PlayerPos(True, gPlayers[I].UID, ID);
785 MH_SEND_PlayerStats(gPlayers[I].UID, ID);
787 if (gPlayers[I].Flag <> FLAG_NONE) and (gGameSettings.GameMode = GM_CTF) then
788 begin
789 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED, gPlayers[I].Flag, gPlayers[I].UID, True, ID);
790 end;
791 end;
792 end;
793 end;
795 g_Items_ForEachAlive(sendItemRespawn, true); // backwards
796 g_Mons_ForEach(sendMonSpawn);
797 g_Map_ForEachPanel(sendPanelState);
799 if gTriggers <> nil then
800 begin
801 for I := Low(gTriggers) to High(gTriggers) do
802 begin
803 if gTriggers[I].TriggerType = TRIGGER_SOUND then
804 begin
805 MH_SEND_TriggerSound(gTriggers[I], ID);
806 end;
807 end;
808 end;
810 if Shots <> nil then
811 begin
812 for I := Low(Shots) to High(Shots) do
813 begin
814 if Shots[i].ShotType in [6, 7, 8] then
815 begin
816 MH_SEND_CreateShot(i, ID);
817 end;
818 end;
819 end;
821 MH_SEND_TriggerMusic(ID);
823 MH_SEND_GameStats(ID);
824 MH_SEND_CoopStats(ID);
826 if gGameSettings.GameMode = GM_CTF then
827 begin
828 if gFlags[FLAG_RED].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_RED].State, FLAG_RED, 0, True, ID);
829 if gFlags[FLAG_BLUE].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_BLUE].State, FLAG_BLUE, 0, True, ID);
830 end;
832 if CreatePlayers and (ID >= 0) then NetClients[ID].State := NET_STATE_GAME;
834 g_Net_Flush();
835 end;
837 procedure MH_SEND_Info(ID: Byte);
838 begin
839 NetOut.Clear();
841 NetOut.Write(Byte(NET_MSG_INFO));
842 NetOut.Write(ID);
843 NetOut.Write(NetClients[ID].Player);
844 NetOut.Write(ExtractFileName(gGameSettings.WAD));
845 NetOut.Write(g_ExtractFileName(gMapInfo.Map));
846 NetOut.Write(gWADHash);
847 NetOut.Write(gGameSettings.GameMode);
848 NetOut.Write(gGameSettings.GoalLimit);
849 NetOut.Write(gGameSettings.TimeLimit);
850 NetOut.Write(gGameSettings.MaxLives);
851 NetOut.Write(gGameSettings.Options);
852 NetOut.Write(gTime);
854 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
855 end;
857 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
858 var
859 Name: string;
860 i: Integer;
861 Team: Byte;
862 begin
863 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
864 Mode := NET_CHAT_PLAYER;
866 Team := 0;
867 if (Mode = NET_CHAT_TEAM) then
868 begin
869 for i := Low(gPlayers) to High(gPlayers) do
870 if (gPlayers[i] <> nil) and (gPlayers[i].FClientID >= 0) and
871 (gPlayers[i].Team = ID) then
872 begin
873 NetOut.Write(Byte(NET_MSG_CHAT));
874 NetOut.Write(Txt);
875 NetOut.Write(Mode);
876 g_Net_Host_Send(gPlayers[i].FClientID, True, NET_CHAN_CHAT);
877 end;
878 Team := ID;
879 ID := NET_EVERYONE;
880 end
881 else
882 begin
883 NetOut.Write(Byte(NET_MSG_CHAT));
884 NetOut.Write(Txt);
885 NetOut.Write(Mode);
886 g_Net_Host_Send(ID, True, NET_CHAN_CHAT);
887 end;
889 if Mode = NET_CHAT_SYSTEM then
890 Exit;
892 if ID = NET_EVERYONE then
893 begin
894 if Mode = NET_CHAT_PLAYER then
895 begin
896 g_Console_Add(Txt, True);
897 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
898 g_Game_ChatSound(b_Text_Unformat(Txt));
899 end
900 else
901 if Mode = NET_CHAT_TEAM then
902 if gPlayer1 <> nil then
903 begin
904 if (gPlayer1.Team = TEAM_RED) and (Team = TEAM_RED) then
905 begin
906 g_Console_Add(#18'[Team] '#2 + Txt, True);
907 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
908 g_Game_ChatSound(b_Text_Unformat(Txt));
909 end
910 else if (gPlayer1.Team = TEAM_BLUE) and (Team = TEAM_BLUE) then
911 begin
912 g_Console_Add(#20'[Team] '#2 + Txt, True);
913 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
914 g_Game_ChatSound(b_Text_Unformat(Txt));
915 end;
916 end;
917 end
918 else
919 begin
920 Name := g_Net_ClientName_ByID(ID);
921 g_Console_Add('-> ' + Name + ': ' + Txt, True);
922 e_WriteLog('[Tell ' + Name + '] ' + b_Text_Unformat(Txt), TMsgType.Notify);
923 g_Game_ChatSound(b_Text_Unformat(Txt), False);
924 end;
925 end;
927 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
928 begin
929 NetOut.Write(Byte(NET_MSG_GFX));
930 NetOut.Write(Kind);
931 NetOut.Write(X);
932 NetOut.Write(Y);
933 NetOut.Write(Ang);
935 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
936 end;
938 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
939 begin
940 NetOut.Write(Byte(NET_MSG_SND));
941 NetOut.Write(Name);
942 if Pos then
943 begin
944 NetOut.Write(Byte(1));
945 NetOut.Write(X);
946 NetOut.Write(Y);
947 end
948 else
949 NetOut.Write(Byte(0));
951 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
952 end;
954 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
955 begin
956 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
958 NetOut.Write(Byte(NET_MSG_SHADD));
959 NetOut.Write(Proj);
960 NetOut.Write(Shots[Proj].ShotType);
961 NetOut.Write(Shots[Proj].Target);
962 NetOut.Write(Shots[Proj].SpawnerUID);
963 NetOut.Write(Shots[Proj].Timeout);
964 NetOut.Write(Shots[Proj].Obj.X);
965 NetOut.Write(Shots[Proj].Obj.Y);
966 NetOut.Write(Shots[Proj].Obj.Vel.X);
967 NetOut.Write(Shots[Proj].Obj.Vel.Y);
969 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
970 end;
972 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
973 begin
974 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
976 NetOut.Write(Byte(NET_MSG_SHPOS));
977 NetOut.Write(Proj);
978 NetOut.Write(Shots[Proj].Obj.X);
979 NetOut.Write(Shots[Proj].Obj.Y);
980 NetOut.Write(Shots[Proj].Obj.Vel.X);
981 NetOut.Write(Shots[Proj].Obj.Vel.Y);
983 g_Net_Host_Send(ID, False, NET_CHAN_SHOTS);
984 end;
986 procedure MH_Send_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
987 begin
988 NetOut.Write(Byte(NET_MSG_SHDEL));
989 NetOut.Write(Proj);
990 NetOut.Write(Byte(Loud));
991 NetOut.Write(X);
992 NetOut.Write(Y);
994 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
995 end;
997 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
998 begin
999 NetOut.Write(Byte(NET_MSG_SCORE));
1000 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1001 begin
1002 NetOut.Write(gTeamStat[TEAM_RED].Goals);
1003 NetOut.Write(gTeamStat[TEAM_BLUE].Goals);
1004 end
1005 else
1006 if gGameSettings.GameMode = GM_COOP then
1007 begin
1008 NetOut.Write(gCoopMonstersKilled);
1009 NetOut.Write(gCoopSecretsFound);
1010 end;
1012 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1013 end;
1015 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
1016 begin
1017 NetOut.Write(Byte(NET_MSG_COOP));
1018 NetOut.Write(gTotalMonsters);
1019 NetOut.Write(gSecretsCount);
1020 NetOut.Write(gCoopTotalMonstersKilled);
1021 NetOut.Write(gCoopTotalSecretsFound);
1022 NetOut.Write(gCoopTotalMonsters);
1023 NetOut.Write(gCoopTotalSecrets);
1024 end;
1026 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
1027 begin
1028 NetOut.Write(Byte(NET_MSG_GEVENT));
1029 NetOut.Write(EvType);
1030 NetOut.Write(EvNum);
1031 NetOut.Write(EvStr);
1032 NetOut.Write(Byte(gLastMap));
1033 NetOut.Write(gTime);
1034 if (EvType = NET_EV_MAPSTART) and isWadPath(EvStr) then
1035 begin
1036 NetOut.Write(Byte(1));
1037 NetOut.Write(gWADHash);
1038 end else
1039 NetOut.Write(Byte(0));
1041 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
1042 end;
1044 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
1045 begin
1046 NetOut.Write(Byte(NET_MSG_FLAG));
1047 NetOut.Write(EvType);
1048 NetOut.Write(Flag);
1049 NetOut.Write(Byte(Quiet));
1050 NetOut.Write(PID);
1051 NetOut.Write(gFlags[Flag].State);
1052 NetOut.Write(gFlags[Flag].CaptureTime);
1053 NetOut.Write(gFlags[Flag].Obj.X);
1054 NetOut.Write(gFlags[Flag].Obj.Y);
1055 NetOut.Write(gFlags[Flag].Obj.Vel.X);
1056 NetOut.Write(gFlags[Flag].Obj.Vel.Y);
1058 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1059 end;
1061 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
1062 begin
1063 NetOut.Write(Byte(NET_MSG_GSET));
1064 NetOut.Write(gGameSettings.GameMode);
1065 NetOut.Write(gGameSettings.GoalLimit);
1066 NetOut.Write(gGameSettings.TimeLimit);
1067 NetOut.Write(gGameSettings.MaxLives);
1068 NetOut.Write(gGameSettings.Options);
1070 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1071 end;
1073 // PLAYER (SEND)
1075 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
1076 var
1077 P: TPlayer;
1078 begin
1079 P := g_Player_Get(PID);
1080 if P = nil then Exit;
1082 NetOut.Write(Byte(NET_MSG_PLR));
1083 NetOut.Write(PID);
1084 NetOut.Write(P.Name);
1086 NetOut.Write(P.FActualModelName);
1087 NetOut.Write(P.FColor.R);
1088 NetOut.Write(P.FColor.G);
1089 NetOut.Write(P.FColor.B);
1090 NetOut.Write(P.Team);
1092 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT)
1093 end;
1095 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
1096 var
1097 kByte: Word;
1098 Pl: TPlayer;
1099 begin
1100 Pl := g_Player_Get(PID);
1101 if Pl = nil then Exit;
1102 if Pl.FDummy then Exit;
1104 NetOut.Write(Byte(NET_MSG_PLRPOS));
1105 NetOut.Write(gTime);
1106 NetOut.Write(PID);
1108 kByte := 0;
1110 with Pl do
1111 begin
1112 NetOut.Write(FPing);
1113 NetOut.Write(FLoss);
1114 if IsKeyPressed(KEY_CHAT) then
1115 kByte := NET_KEY_CHAT
1116 else
1117 begin
1118 if IsKeyPressed(KEY_LEFT) then kByte := kByte or NET_KEY_LEFT;
1119 if IsKeyPressed(KEY_RIGHT) then kByte := kByte or NET_KEY_RIGHT;
1120 if IsKeyPressed(KEY_UP) then kByte := kByte or NET_KEY_UP;
1121 if IsKeyPressed(KEY_DOWN) then kByte := kByte or NET_KEY_DOWN;
1122 if IsKeyPressed(KEY_JUMP) then kByte := kByte or NET_KEY_JUMP;
1123 end;
1125 if JustTeleported then kByte := kByte or NET_KEY_FORCEDIR;
1127 NetOut.Write(kByte);
1128 if Direction = TDirection.D_LEFT then NetOut.Write(Byte(0)) else NetOut.Write(Byte(1));
1129 NetOut.Write(GameX);
1130 NetOut.Write(GameY);
1131 NetOut.Write(GameVelX);
1132 NetOut.Write(GameVelY);
1133 NetOut.Write(GameAccelX);
1134 NetOut.Write(GameAccelY);
1135 end;
1137 g_Net_Host_Send(ID, Reliable, NET_CHAN_PLAYERPOS);
1138 end;
1140 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
1141 var
1142 P: TPlayer;
1143 I: Integer;
1144 begin
1145 P := g_Player_Get(PID);
1146 if P = nil then Exit;
1148 NetOut.Write(Byte(NET_MSG_PLRSTA));
1149 NetOut.Write(PID);
1151 with P do
1152 begin
1153 NetOut.Write(Byte(alive));
1154 NetOut.Write(Byte(GodMode));
1155 NetOut.Write(Health);
1156 NetOut.Write(Armor);
1157 NetOut.Write(Air);
1158 NetOut.Write(JetFuel);
1159 NetOut.Write(Lives);
1160 NetOut.Write(Team);
1162 for I := WP_FIRST to WP_LAST do
1163 NetOut.Write(Byte(FWeapon[I]));
1165 for I := A_BULLETS to A_HIGH do
1166 NetOut.Write(FAmmo[I]);
1168 for I := A_BULLETS to A_HIGH do
1169 NetOut.Write(FMaxAmmo[I]);
1171 for I := MR_SUIT to MR_MAX do
1172 NetOut.Write(LongWord(FMegaRulez[I]));
1174 NetOut.Write(Byte(R_ITEM_BACKPACK in FRulez));
1175 NetOut.Write(Byte(R_KEY_RED in FRulez));
1176 NetOut.Write(Byte(R_KEY_GREEN in FRulez));
1177 NetOut.Write(Byte(R_KEY_BLUE in FRulez));
1178 NetOut.Write(Byte(R_BERSERK in FRulez));
1180 NetOut.Write(Frags);
1181 NetOut.Write(Death);
1183 NetOut.Write(CurrWeap);
1185 NetOut.Write(Byte(FSpectator));
1186 NetOut.Write(Byte(FGhost));
1187 NetOut.Write(Byte(FPhysics));
1188 NetOut.Write(Byte(FNoRespawn));
1189 NetOut.Write(Byte(FJetpack));
1190 NetOut.Write(FFireTime);
1191 NetOut.Write(Byte(FFlaming));
1192 NetOut.Write(FSpawnInvul);
1193 end;
1195 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1196 end;
1198 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
1199 begin
1200 NetOut.Write(Byte(NET_MSG_PLRDMG));
1201 NetOut.Write(PID);
1202 NetOut.Write(Kind);
1203 NetOut.Write(Attacker);
1204 NetOut.Write(Value);
1205 NetOut.Write(VX);
1206 NetOut.Write(VY);
1208 g_Net_Host_Send(ID, False, NET_CHAN_PLAYER);
1209 end;
1211 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
1212 begin
1213 NetOut.Write(Byte(NET_MSG_PLRDIE));
1214 NetOut.Write(PID);
1215 NetOut.Write(KillType);
1216 NetOut.Write(DeathType);
1217 NetOut.Write(Attacker);
1219 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1220 end;
1222 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
1223 begin
1224 NetOut.Write(Byte(NET_MSG_PLRFIRE));
1225 NetOut.Write(PID);
1226 NetOut.Write(Weapon);
1227 NetOut.Write(X);
1228 NetOut.Write(Y);
1229 NetOut.Write(AX);
1230 NetOut.Write(AY);
1231 NetOut.Write(ShotID);
1233 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1234 end;
1236 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
1237 begin
1238 NetOut.Write(Byte(NET_MSG_PLRDEL));
1239 NetOut.Write(PID);
1241 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1242 end;
1244 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
1245 var
1246 Pl: TPlayer;
1247 begin
1248 Pl := g_Player_Get(PID);
1249 if Pl = nil then Exit;
1251 NetOut.Write(Byte(NET_MSG_PLRSET));
1252 NetOut.Write(PID);
1253 NetOut.Write(Pl.Name);
1254 if Mdl = '' then
1255 NetOut.Write(Pl.Model.GetName())
1256 else
1257 NetOut.Write(Mdl);
1258 NetOut.Write(Pl.FColor.R);
1259 NetOut.Write(Pl.FColor.G);
1260 NetOut.Write(Pl.FColor.B);
1261 NetOut.Write(Pl.Team);
1263 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1264 end;
1266 // ITEM (SEND)
1268 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1269 var
1270 it: PItem;
1271 tt: Byte;
1272 begin
1273 it := g_Items_ByIdx(IID);
1275 NetOut.Write(Byte(NET_MSG_ISPAWN));
1276 NetOut.Write(IID);
1277 NetOut.Write(Byte(Quiet));
1278 tt := it.ItemType;
1279 if it.dropped then tt := tt or $80;
1280 NetOut.Write(tt);
1281 NetOut.Write(Byte(it.Fall));
1282 NetOut.Write(Byte(it.Respawnable));
1283 NetOut.Write(it.Obj.X);
1284 NetOut.Write(it.Obj.Y);
1285 NetOut.Write(it.Obj.Vel.X);
1286 NetOut.Write(it.Obj.Vel.Y);
1288 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1289 end;
1291 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1292 begin
1293 NetOut.Write(Byte(NET_MSG_IDEL));
1294 NetOut.Write(IID);
1295 NetOut.Write(Byte(Quiet));
1297 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1298 end;
1300 // PANEL
1302 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
1303 var
1304 TP: TPanel;
1305 begin
1306 TP := g_Map_PanelByGUID(PGUID);
1307 if (TP = nil) then exit;
1309 with TP do
1310 begin
1311 NetOut.Write(Byte(NET_MSG_PTEX));
1312 NetOut.Write(LongWord(PGUID));
1313 NetOut.Write(FCurTexture);
1314 NetOut.Write(FCurFrame);
1315 NetOut.Write(FCurFrameCount);
1316 NetOut.Write(AnimLoop);
1317 end;
1319 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1320 end;
1322 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
1323 var
1324 TP: TPanel;
1325 mpflags: Byte = 0;
1326 begin
1327 TP := g_Map_PanelByGUID(PGUID);
1328 if (TP = nil) then exit;
1330 NetOut.Write(Byte(NET_MSG_PSTATE));
1331 NetOut.Write(LongWord(PGUID));
1332 NetOut.Write(Byte(TP.Enabled));
1333 NetOut.Write(TP.LiftType);
1334 NetOut.Write(TP.X);
1335 NetOut.Write(TP.Y);
1336 NetOut.Write(Word(TP.Width));
1337 NetOut.Write(Word(TP.Height));
1338 // mplats
1339 NetOut.Write(LongInt(TP.movingSpeedX));
1340 NetOut.Write(LongInt(TP.movingSpeedY));
1341 NetOut.Write(LongInt(TP.movingStartX));
1342 NetOut.Write(LongInt(TP.movingStartY));
1343 NetOut.Write(LongInt(TP.movingEndX));
1344 NetOut.Write(LongInt(TP.movingEndY));
1345 NetOut.Write(LongInt(TP.sizeSpeedX));
1346 NetOut.Write(LongInt(TP.sizeSpeedY));
1347 NetOut.Write(LongInt(TP.sizeEndX));
1348 NetOut.Write(LongInt(TP.sizeEndY));
1349 if TP.movingActive then mpflags := mpflags or 1;
1350 if TP.moveOnce then mpflags := mpflags or 2;
1351 NetOut.Write(Byte(mpflags));
1353 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1354 end;
1356 // TRIGGER
1358 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
1359 begin
1360 if gTriggers = nil then Exit;
1361 if T.Sound = nil then Exit;
1363 NetOut.Write(Byte(NET_MSG_TSOUND));
1364 NetOut.Write(T.ClientID);
1365 NetOut.Write(Byte(T.Sound.IsPlaying));
1366 NetOut.Write(LongWord(T.Sound.GetPosition));
1367 NetOut.Write(T.SoundPlayCount);
1369 g_Net_Host_Send(ID, True);
1370 end;
1372 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
1373 begin
1374 NetOut.Write(Byte(NET_MSG_TMUSIC));
1375 NetOut.Write(gMusic.Name);
1376 NetOut.Write(Byte(gMusic.IsPlaying));
1377 NetOut.Write(LongWord(gMusic.GetPosition));
1378 NetOut.Write(Byte(gMusic.SpecPause or gMusic.IsPaused));
1380 g_Net_Host_Send(ID, True);
1381 end;
1383 // MONSTER
1385 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
1386 var
1387 M: TMonster;
1388 begin
1389 M := g_Monsters_ByUID(UID);
1390 if M = nil then
1391 Exit;
1393 with M do
1394 begin
1395 NetOut.Write(Byte(NET_MSG_MSPAWN));
1396 NetOut.Write(UID);
1397 NetOut.Write(MonsterType);
1398 NetOut.Write(MonsterState);
1399 NetOut.Write(MonsterAnim);
1400 NetOut.Write(MonsterTargetUID);
1401 NetOut.Write(MonsterTargetTime);
1402 NetOut.Write(MonsterBehaviour);
1403 NetOut.Write(MonsterSleep);
1404 NetOut.Write(MonsterHealth);
1405 NetOut.Write(MonsterAmmo);
1406 NetOut.Write(GameX);
1407 NetOut.Write(GameY);
1408 NetOut.Write(GameVelX);
1409 NetOut.Write(GameVelY);
1410 NetOut.Write(Byte(GameDirection));
1411 end;
1413 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1414 end;
1416 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
1417 var
1418 M: TMonster;
1419 begin
1420 M := g_Monsters_ByUID(UID);
1421 if M = nil then Exit;
1423 NetOut.Write(Byte(NET_MSG_MPOS));
1424 NetOut.Write(UID);
1426 with M do
1427 begin
1428 NetOut.Write(GameX);
1429 NetOut.Write(GameY);
1430 NetOut.Write(GameVelX);
1431 NetOut.Write(GameVelY);
1432 NetOut.Write(Byte(GameDirection));
1433 end;
1435 g_Net_Host_Send(ID, False, NET_CHAN_MONSTERPOS);
1436 end;
1438 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
1439 var
1440 M: TMonster;
1441 begin
1442 M := g_Monsters_ByUID(UID);
1443 if M = nil then Exit;
1445 NetOut.Write(Byte(NET_MSG_MSTATE));
1446 NetOut.Write(UID);
1448 with M do
1449 begin
1450 NetOut.Write(MonsterState);
1451 NetOut.Write(ForcedAnim);
1452 NetOut.Write(MonsterTargetUID);
1453 NetOut.Write(MonsterTargetTime);
1454 NetOut.Write(MonsterSleep);
1455 NetOut.Write(MonsterHealth);
1456 NetOut.Write(MonsterAmmo);
1457 NetOut.Write(MonsterPain);
1458 NetOut.Write(Byte(AnimIsReverse));
1459 NetOut.Write(FFireTime);
1460 end;
1462 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1463 end;
1465 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
1466 begin
1467 NetOut.Write(Byte(NET_MSG_MSHOT));
1468 NetOut.Write(UID);
1469 NetOut.Write(X);
1470 NetOut.Write(Y);
1471 NetOut.Write(VX);
1472 NetOut.Write(VY);
1474 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1475 end;
1477 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
1478 var
1479 M: TMonster;
1480 begin
1481 M := g_Monsters_ByUID(UID);
1482 if M = nil then Exit;
1484 NetOut.Write(Byte(NET_MSG_MDEL));
1485 NetOut.Write(UID);
1487 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1488 end;
1490 // MISC
1492 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
1493 begin
1494 NetOut.Write(Byte(NET_MSG_TIME_SYNC));
1495 NetOut.Write(Time);
1497 g_Net_Host_Send(ID, False, NET_CHAN_SERVICE);
1498 end;
1500 procedure MH_SEND_VoteEvent(EvType: Byte;
1501 StrArg1: string = 'a'; StrArg2: string = 'b';
1502 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
1503 ID: Integer = NET_EVERYONE);
1504 begin
1505 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
1506 NetOut.Write(EvType);
1507 NetOut.Write(IntArg1);
1508 NetOut.Write(IntArg2);
1509 NetOut.Write(StrArg1);
1510 NetOut.Write(StrArg2);
1512 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1513 end;
1515 // CLIENT MESSAGES //
1517 // GAME
1519 procedure MC_RECV_Chat(var M: TMsg);
1520 var
1521 Txt: string;
1522 Mode: Byte;
1523 begin
1524 Txt := M.ReadString();
1525 Mode := M.ReadByte();
1527 if Mode <> NET_CHAT_SYSTEM then
1528 begin
1529 if NetDeafLevel = 0 then
1530 begin
1531 if Mode = NET_CHAT_PLAYER then
1532 begin
1533 g_Console_Add(Txt, True);
1534 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1535 g_Game_ChatSound(b_Text_Unformat(Txt));
1536 end else
1537 if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then
1538 begin
1539 if gPlayer1.Team = TEAM_RED then
1540 g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True);
1541 if gPlayer1.Team = TEAM_BLUE then
1542 g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True);
1543 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1544 g_Game_ChatSound(b_Text_Unformat(Txt));
1545 end;
1546 end;
1547 end else if (NetDeafLevel < 2) then
1548 g_Console_Add(Txt, True);
1549 end;
1551 procedure MC_RECV_Effect(var M: TMsg);
1552 var
1553 Kind: Byte;
1554 X, Y: Integer;
1555 Ang: SmallInt;
1556 begin
1557 if not gGameOn then Exit;
1558 Kind := M.ReadByte();
1559 X := M.ReadLongInt();
1560 Y := M.ReadLongInt();
1561 Ang := M.ReadSmallInt();
1563 case Kind of
1564 NET_GFX_SPARK:
1565 begin
1566 {$IFDEF ENABLE_GFX}
1567 g_GFX_Spark(X, Y, 2 + Random(2), Ang, 0, 0);
1568 {$ENDIF}
1569 end;
1570 NET_GFX_TELE:
1571 begin
1572 {$IFDEF ENABLE_GFX}
1573 g_GFX_QueueEffect(R_GFX_TELEPORT_FAST, X, Y);
1574 {$ENDIF}
1575 if Ang = 1 then
1576 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
1577 end;
1578 NET_GFX_EXPLODE:
1579 begin
1580 {$IFDEF ENABLE_GFX}
1581 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET, X - 64, Y - 64);
1582 {$ENDIF}
1583 if Ang = 1 then
1584 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X, Y);
1585 end;
1586 NET_GFX_BFGEXPL:
1587 begin
1588 {$IFDEF ENABLE_GFX}
1589 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG, X - 64, Y - 64);
1590 {$ENDIF}
1591 if Ang = 1 then
1592 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X, Y);
1593 end;
1594 NET_GFX_BFGHIT:
1595 begin
1596 {$IFDEF ENABLE_GFX}
1597 g_GFX_QueueEffect(R_GFX_BFG_HIT, X - 32, Y - 32);
1598 {$ENDIF}
1599 end;
1600 NET_GFX_FIRE:
1601 begin
1602 {$IFDEF ENABLE_GFX}
1603 g_GFX_QueueEffect(R_GFX_FIRE, X, Y);
1604 {$ENDIF}
1605 if Ang = 1 then
1606 g_Sound_PlayExAt('SOUND_FIRE', X, Y);
1607 end;
1608 NET_GFX_RESPAWN:
1609 begin
1610 {$IFDEF ENABLE_GFX}
1611 g_GFX_QueueEffect(R_GFX_ITEM_RESPAWN, X, Y);
1612 {$ENDIF}
1613 if Ang = 1 then
1614 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
1615 end;
1616 NET_GFX_SHELL1:
1617 begin
1618 {$IFDEF ENABLE_SHELLS}
1619 g_Shells_Create(X, Y, 0, -2, SHELL_BULLET);
1620 {$ENDIF}
1621 end;
1622 NET_GFX_SHELL2:
1623 begin
1624 {$IFDEF ENABLE_SHELLS}
1625 g_Shells_Create(X, Y, 0, -2, SHELL_SHELL);
1626 {$ENDIF}
1627 end;
1628 NET_GFX_SHELL3:
1629 begin
1630 {$IFDEF ENABLE_SHELLS}
1631 g_Shells_Create(X, Y, 0, -2, SHELL_SHELL);
1632 g_Shells_Create(X, Y, 0, -2, SHELL_SHELL);
1633 {$ENDIF}
1634 end;
1635 end;
1636 end;
1638 procedure MC_RECV_Sound(var M: TMsg);
1639 var
1640 Name: string;
1641 X, Y: Integer;
1642 Pos: Boolean;
1643 begin
1644 Name := M.ReadString();
1645 Pos := M.ReadByte() <> 0;
1646 if Pos then
1647 begin
1648 X := M.ReadLongInt();
1649 Y := M.ReadLongInt();
1650 g_Sound_PlayExAt(Name, X, Y);
1651 end
1652 else
1653 g_Sound_PlayEx(Name);
1654 end;
1656 procedure MC_RECV_CreateShot(var M: TMsg);
1657 var
1658 I, X, Y, XV, YV: Integer;
1659 Timeout: LongWord;
1660 Target, Spawner: Word;
1661 ShType: Byte;
1662 begin
1663 I := M.ReadLongInt();
1664 ShType := M.ReadByte();
1665 Target := M.ReadWord();
1666 Spawner := M.ReadWord();
1667 Timeout := M.ReadLongWord();
1668 X := M.ReadLongInt();
1669 Y := M.ReadLongInt();
1670 XV := M.ReadLongInt();
1671 YV := M.ReadLongInt();
1673 I := g_Weapon_CreateShot(I, ShType, Spawner, Target, X, Y, XV, YV);
1674 if (Shots <> nil) and (I <= High(Shots)) then
1675 begin
1676 Shots[I].Timeout := Timeout;
1677 //Shots[I].Target := Target; // TODO: find a use for Target later
1678 end;
1679 end;
1681 procedure MC_RECV_UpdateShot(var M: TMsg);
1682 var
1683 I, TX, TY, TXV, TYV: Integer;
1684 begin
1685 I := M.ReadLongInt();
1686 TX := M.ReadLongInt();
1687 TY := M.ReadLongInt();
1688 TXV := M.ReadLongInt();
1689 TYV := M.ReadLongInt();
1691 if (Shots <> nil) and (I <= High(Shots)) then
1692 with (Shots[i]) do
1693 begin
1694 Obj.X := TX;
1695 Obj.Y := TY;
1696 Obj.Vel.X := TXV;
1697 Obj.Vel.Y := TYV;
1698 end;
1699 end;
1701 procedure MC_RECV_DeleteShot(var M: TMsg);
1702 var
1703 I, X, Y: Integer;
1704 L: Boolean;
1705 begin
1706 if not gGameOn then Exit;
1707 I := M.ReadLongInt();
1708 L := (M.ReadByte() <> 0);
1709 X := M.ReadLongInt();
1710 Y := M.ReadLongInt();
1712 g_Weapon_DestroyShot(I, X, Y, L);
1713 end;
1715 procedure MC_RECV_GameStats(var M: TMsg);
1716 begin
1717 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1718 begin
1719 gTeamStat[TEAM_RED].Goals := M.ReadSmallInt();
1720 gTeamStat[TEAM_BLUE].Goals := M.ReadSmallInt();
1721 end
1722 else
1723 if gGameSettings.GameMode = GM_COOP then
1724 begin
1725 gCoopMonstersKilled := M.ReadWord();
1726 gCoopSecretsFound := M.ReadWord();
1727 end;
1728 end;
1730 procedure MC_RECV_CoopStats(var M: TMsg);
1731 begin
1732 gTotalMonsters := M.ReadLongInt();
1733 gSecretsCount := M.ReadLongInt();
1734 gCoopTotalMonstersKilled := M.ReadWord();
1735 gCoopTotalSecretsFound := M.ReadWord();
1736 gCoopTotalMonsters := M.ReadWord();
1737 gCoopTotalSecrets := M.ReadWord();
1738 end;
1740 procedure MC_RECV_GameEvent(var M: TMsg);
1741 var
1742 EvType: Byte;
1743 EvNum: Integer;
1744 EvStr: string;
1745 EvTime: LongWord;
1746 BHash: Boolean;
1747 EvHash: TMD5Digest;
1748 pl: TPlayer;
1749 i1, i2: TStrings_Locale;
1750 pln: String;
1751 cnt: Byte;
1752 goodCmd: Boolean = true;
1753 begin
1754 FillChar(EvHash, Sizeof(EvHash), 0);
1755 EvType := M.ReadByte();
1756 EvNum := M.ReadLongInt();
1757 EvStr := M.ReadString();
1758 gLastMap := M.ReadByte() <> 0;
1759 if gLastMap and (gGameSettings.GameMode = GM_COOP) then gStatsOff := True;
1760 gStatsPressed := True;
1761 EvTime := M.ReadLongWord();
1762 BHash := M.ReadByte() <> 0;
1763 if BHash then
1764 EvHash := M.ReadMD5();
1766 gTime := EvTime;
1768 if (g_Res_received_map_start <> 0) then
1769 begin
1770 if (g_Res_received_map_start < 0) then exit;
1771 goodCmd := false;
1772 case EvType of
1773 NET_EV_MAPSTART: goodCmd := true;
1774 NET_EV_MAPEND: goodCmd := true;
1775 NET_EV_PLAYER_KICK: goodCmd := true;
1776 NET_EV_PLAYER_BAN: goodCmd := true;
1777 NET_EV_LMS_WARMUP: goodCmd := true;
1778 end;
1779 if not goodCmd then exit;
1780 end;
1782 case EvType of
1783 NET_EV_MAPSTART:
1784 begin
1785 if (g_Res_received_map_start <> 0) then
1786 begin
1787 g_Res_received_map_start := -1;
1788 end
1789 else
1790 begin
1791 gGameOn := False;
1792 g_Game_ClearLoading();
1793 g_Game_StopAllSounds(True);
1795 gSwitchGameMode := Byte(EvNum);
1796 gGameSettings.GameMode := gSwitchGameMode;
1798 gWADHash := EvHash;
1799 if not g_Game_StartMap(false{asMegawad}, EvStr, True) then
1800 begin
1801 if not isWadPath(EvStr) then
1802 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + EvStr]))
1803 else
1804 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [EvStr]));
1805 Exit;
1806 end;
1808 MC_SEND_FullStateRequest;
1809 end;
1810 end;
1812 NET_EV_MAPEND:
1813 begin
1814 gLMSRespawn := LMS_RESPAWN_NONE;
1815 gLMSRespawnTime := 0;
1816 if (g_Res_received_map_start <> 0) then
1817 begin
1818 g_Res_received_map_start := -1;
1819 end
1820 else
1821 begin
1822 gMissionFailed := EvNum <> 0;
1823 gExit := EXIT_ENDLEVELCUSTOM;
1824 end;
1825 end;
1827 NET_EV_RCON:
1828 begin
1829 case EvNum of
1830 NET_RCON_NOAUTH:
1831 g_Console_Add(_lc[I_NET_RCON_NOAUTH], True);
1832 NET_RCON_PWGOOD:
1833 g_Console_Add(_lc[I_NET_RCON_PWD_VALID], True);
1834 NET_RCON_PWBAD:
1835 g_Console_Add(_lc[I_NET_RCON_PWD_INVALID], True);
1836 end;
1837 end;
1839 NET_EV_CHANGE_TEAM:
1840 begin
1841 if NetDeafLevel < 2 then
1842 begin
1843 if EvNum = TEAM_RED then
1844 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True);
1845 if EvNum = TEAM_BLUE then
1846 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True);
1847 end;
1848 end;
1850 NET_EV_PLAYER_KICK:
1851 begin
1852 g_Console_Add(Format(_lc[I_PLAYER_KICK], [EvStr]), True);
1853 if (g_Res_received_map_start <> 0) then g_Res_received_map_start := -1;
1854 end;
1856 NET_EV_PLAYER_BAN:
1857 begin
1858 g_Console_Add(Format(_lc[I_PLAYER_BAN], [EvStr]), True);
1859 if (g_Res_received_map_start <> 0) then g_Res_received_map_start := -1;
1860 end;
1862 NET_EV_LMS_WARMUP:
1863 begin
1864 if EvNum > 0 then
1865 begin
1866 gLMSRespawn := LMS_RESPAWN_WARMUP;
1867 gLMSRespawnTime := gTime + EvNum;
1868 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [EvNum div 1000]), True);
1869 end
1870 else if gPlayer1 = nil then
1871 begin
1872 g_Console_Add(_lc[I_PLAYER_SPECT4], True);
1873 end;
1874 end;
1876 NET_EV_LMS_SURVIVOR:
1877 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True);
1879 NET_EV_BIGTEXT:
1880 if NetDeafLevel < 2 then g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum));
1882 NET_EV_SCORE:
1883 begin
1884 pl := g_Player_Get(EvNum and $FFFF);
1885 if pl = nil then
1886 pln := '?'
1887 else
1888 pln := pl.Name;
1889 cnt := (EvNum shr 16) and $FF;
1890 if Pos('w', EvStr) = 0 then
1891 begin
1892 // Default score
1893 if Pos('t', EvStr) = 0 then
1894 begin
1895 // Player +/- score
1896 if Pos('-', EvStr) = 0 then
1897 begin
1898 if Pos('e', EvStr) = 0 then
1899 i1 := I_PLAYER_SCORE_ADD_OWN
1900 else
1901 i1 := I_PLAYER_SCORE_ADD_ENEMY;
1902 end else
1903 begin
1904 if Pos('e', EvStr) = 0 then
1905 i1 := I_PLAYER_SCORE_SUB_OWN
1906 else
1907 i1 := I_PLAYER_SCORE_SUB_ENEMY;
1908 end;
1909 // Which team
1910 if Pos('r', EvStr) > 0 then
1911 i2 := I_PLAYER_SCORE_TO_RED
1912 else
1913 i2 := I_PLAYER_SCORE_TO_BLUE;
1914 g_Console_Add(Format(_lc[i1], [pln, cnt, _lc[i2]]), True);
1915 end else
1916 begin
1917 // Team +/- score
1918 if Pos('-', EvStr) = 0 then
1919 i1 := I_PLAYER_SCORE_ADD_TEAM
1920 else
1921 i1 := I_PLAYER_SCORE_SUB_TEAM;
1922 // Which team
1923 if Pos('r', EvStr) > 0 then
1924 i2 := I_PLAYER_SCORE_RED
1925 else
1926 i2 := I_PLAYER_SCORE_BLUE;
1927 g_Console_Add(Format(_lc[i1], [_lc[i2], cnt]), True);
1928 end;
1929 end else
1930 begin
1931 // Game Win
1932 if Pos('e', EvStr) = 0 then
1933 i1 := I_PLAYER_SCORE_WIN_OWN
1934 else
1935 i1 := I_PLAYER_SCORE_WIN_ENEMY;
1936 // Which team
1937 if Pos('r', EvStr) > 0 then
1938 i2 := I_PLAYER_SCORE_TO_RED
1939 else
1940 i2 := I_PLAYER_SCORE_TO_BLUE;
1941 g_Console_Add(Format(_lc[i1], [pln, _lc[i2]]), True);
1942 end;
1943 end;
1945 NET_EV_SCORE_MSG:
1946 begin
1947 if EvNum = TEAM_RED then
1948 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1949 if EvNum = TEAM_BLUE then
1950 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1951 if EvNum = -TEAM_RED then
1952 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1953 if EvNum = -TEAM_BLUE then
1954 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1955 end;
1957 NET_EV_LMS_START:
1958 begin
1959 g_Player_RemoveAllCorpses;
1960 gLMSRespawn := LMS_RESPAWN_NONE;
1961 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
1962 end;
1964 NET_EV_LMS_WIN:
1965 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(EvStr)]), 144);
1967 NET_EV_TLMS_WIN:
1968 begin
1969 if EvNum = TEAM_RED then
1970 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
1971 if EvNum = TEAM_BLUE then
1972 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
1973 end;
1975 NET_EV_LMS_LOSE:
1976 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
1978 NET_EV_LMS_DRAW:
1979 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
1981 NET_EV_LMS_NOSPAWN:
1982 g_Console_Add(_lc[I_PLAYER_SPECT4], True);
1984 NET_EV_KILLCOMBO:
1985 g_Game_Announce_KillCombo(EvNum);
1987 NET_EV_PLAYER_TOUCH:
1988 begin
1989 pl := g_Player_Get(EvNum);
1990 if pl <> nil then
1991 pl.Touch();
1992 end;
1994 NET_EV_SECRET:
1995 begin
1996 pl := g_Player_Get(EvNum);
1997 if pl <> nil then
1998 begin
1999 g_Console_Add(Format(_lc[I_PLAYER_SECRET], [pl.Name]), True);
2000 g_Sound_PlayEx('SOUND_GAME_SECRET');
2001 end;
2002 end;
2004 NET_EV_INTER_READY:
2005 begin
2006 pl := g_Player_Get(EvNum);
2007 if pl <> nil then pl.FReady := (EvStr = 'Y');
2008 end;
2009 end;
2010 end;
2012 procedure MC_RECV_FlagEvent(var M: TMsg);
2013 var
2014 PID: Word;
2015 Pl: TPlayer;
2016 EvType: Byte;
2017 Fl, a: Byte;
2018 Quiet: Boolean;
2019 s, ts: string;
2020 begin
2021 EvType := M.ReadByte();
2022 Fl := M.ReadByte();
2024 if Fl = FLAG_NONE then Exit;
2026 Quiet := (M.ReadByte() <> 0);
2027 PID := M.ReadWord();
2029 gFlags[Fl].State := M.ReadByte();
2030 gFlags[Fl].CaptureTime := M.ReadLongWord();
2031 gFlags[Fl].Obj.X := M.ReadLongInt();
2032 gFlags[Fl].Obj.Y := M.ReadLongInt();
2033 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
2034 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
2036 Pl := g_Player_Get(PID);
2037 if (Pl = nil) and
2038 (EvType <> FLAG_STATE_NORMAL) and
2039 (EvType <> FLAG_STATE_DROPPED) and
2040 (EvType <> FLAG_STATE_RETURNED) then
2041 Exit;
2043 case EvType of
2044 FLAG_STATE_NORMAL:
2045 begin
2046 if Quiet or (Pl = nil) then Exit;
2048 if Fl = FLAG_RED then
2049 s := _lc[I_PLAYER_FLAG_RED]
2050 else
2051 s := _lc[I_PLAYER_FLAG_BLUE];
2053 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2055 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2056 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2057 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2058 a := 0
2059 else
2060 a := 1;
2062 if not sound_ret_flag[a].IsPlaying() then
2063 sound_ret_flag[a].Play();
2064 end;
2066 FLAG_STATE_CAPTURED:
2067 begin
2068 if (Pl <> nil) then Pl.SetFlag(Fl);
2070 if Quiet then Exit;
2072 if Fl = FLAG_RED then
2073 s := _lc[I_PLAYER_FLAG_RED]
2074 else
2075 s := _lc[I_PLAYER_FLAG_BLUE];
2077 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [Pl.Name, s]), True);
2078 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
2080 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2081 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2082 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2083 a := 0
2084 else
2085 a := 1;
2087 if not sound_get_flag[a].IsPlaying() then
2088 sound_get_flag[a].Play();
2089 end;
2091 FLAG_STATE_DROPPED:
2092 begin
2093 if (Pl <> nil) then Pl.SetFlag(FLAG_NONE);
2095 if Quiet or (Pl = nil) then Exit;
2097 if Fl = FLAG_RED then
2098 s := _lc[I_PLAYER_FLAG_RED]
2099 else
2100 s := _lc[I_PLAYER_FLAG_BLUE];
2102 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [Pl.Name, s]), True);
2103 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
2105 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2106 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2107 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2108 a := 0
2109 else
2110 a := 1;
2112 if not sound_lost_flag[a].IsPlaying() then
2113 sound_lost_flag[a].Play();
2114 end;
2116 FLAG_STATE_SCORED:
2117 begin
2118 g_Map_ResetFlag(FLAG_RED);
2119 g_Map_ResetFlag(FLAG_BLUE);
2120 if Quiet or (Pl = nil) then Exit;
2121 Pl.SetFlag(FLAG_NONE);
2123 if Fl = FLAG_RED then
2124 s := _lc[I_PLAYER_FLAG_RED]
2125 else
2126 s := _lc[I_PLAYER_FLAG_BLUE];
2128 ts := Format('%.4d', [gFlags[Fl].CaptureTime]);
2129 Insert('.', ts, Length(ts) + 1 - 3);
2130 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [Pl.Name, s, ts]), True);
2131 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
2133 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2134 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2135 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2136 a := 0
2137 else
2138 a := 1;
2140 if not sound_cap_flag[a].IsPlaying() then
2141 sound_cap_flag[a].Play();
2142 end;
2144 FLAG_STATE_RETURNED:
2145 begin
2146 g_Map_ResetFlag(Fl);
2147 if Quiet then Exit;
2149 if Fl = FLAG_RED then
2150 s := _lc[I_PLAYER_FLAG_RED]
2151 else
2152 s := _lc[I_PLAYER_FLAG_BLUE];
2154 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2156 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2157 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2158 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2159 a := 0
2160 else
2161 a := 1;
2163 if not sound_ret_flag[a].IsPlaying() then
2164 sound_ret_flag[a].Play();
2165 end;
2166 end;
2167 end;
2169 procedure MC_RECV_GameSettings(var M: TMsg);
2170 begin
2171 gGameSettings.GameMode := M.ReadByte();
2172 gGameSettings.GoalLimit := M.ReadWord();
2173 gGameSettings.TimeLimit := M.ReadWord();
2174 gGameSettings.MaxLives := M.ReadByte();
2175 gGameSettings.Options := M.ReadLongWord();
2176 end;
2178 // PLAYER
2180 function MC_RECV_PlayerCreate(var M: TMsg): Word;
2181 var
2182 PID, DID: Word;
2183 PName, Model: string;
2184 Color: TRGB;
2185 T: Byte;
2186 Pl: TPlayer;
2187 begin
2188 PID := M.ReadWord();
2189 Pl := g_Player_Get(PID);
2191 PName := M.ReadString();
2192 Model := M.ReadString();
2193 Color.R := M.ReadByte();
2194 Color.G := M.ReadByte();
2195 Color.B := M.ReadByte();
2196 T := M.ReadByte();
2198 Result := 0;
2199 if (PID <> NetPlrUID1) and (PID <> NetPlrUID2) then
2200 begin
2201 if (Pl <> nil) then Exit;
2202 DID := g_Player_Create(Model, Color, T, False);
2203 with g_Player_Get(DID) do
2204 begin
2205 UID := PID;
2206 Name := PName;
2207 Reset(True);
2208 end;
2209 end
2210 else
2211 begin
2212 if (PID = NetPlrUID1) and (gPlayer1 <> nil) then begin
2213 gPlayer1.UID := PID;
2214 gPlayer1.Model.SetColor(Color.R, Color.G, Color.B);
2215 gPlayer1.ChangeTeam(T);
2216 end;
2217 if (PID = NetPlrUID2) and (gPlayer2 <> nil) then begin
2218 gPlayer2.UID := PID;
2219 gPlayer2.Model.SetColor(Color.R, Color.G, Color.B);
2220 gPlayer2.ChangeTeam(T);
2221 end;
2222 end;
2224 if NetDeafLevel < 3 then
2225 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
2226 e_WriteLog('NET: Player ' + PName + ' [' + IntToStr(PID) + '] added.', TMsgType.Notify);
2227 Result := PID;
2228 end;
2230 function MC_RECV_PlayerPos(var M: TMsg): Word;
2231 var
2232 GT: LongWord;
2233 PID: Word;
2234 kByte: Word;
2235 Pl: TPlayer;
2236 Dir: Byte;
2237 TmpX, TmpY: Integer;
2238 begin
2239 Result := 0;
2241 GT := M.ReadLongWord();
2242 if GT < gTime - NET_MAX_DIFFTIME then
2243 begin
2244 gTime := GT;
2245 Exit;
2246 end;
2247 gTime := GT;
2249 PID := M.ReadWord();
2250 Pl := g_Player_Get(PID);
2252 if Pl = nil then Exit;
2254 Result := PID;
2256 with Pl do
2257 begin
2258 FPing := M.ReadWord();
2259 FLoss := M.ReadByte();
2260 kByte := M.ReadWord();
2261 Dir := M.ReadByte();
2263 TmpX := M.ReadLongInt();
2264 TmpY := M.ReadLongInt();
2266 ReleaseKeys;
2268 if LongBool(kByte and NET_KEY_CHAT) then
2269 PressKey(KEY_CHAT, 10000)
2270 else
2271 begin
2272 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
2273 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
2274 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
2275 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
2276 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
2277 end;
2279 JustTeleported := LongBool(kByte and NET_KEY_FORCEDIR);
2281 if ((Pl <> gPlayer1) and (Pl <> gPlayer2)) or JustTeleported then
2282 SetDirection(TDirection(Dir));
2284 GameVelX := M.ReadLongInt();
2285 GameVelY := M.ReadLongInt();
2286 GameAccelX := M.ReadLongInt();
2287 GameAccelY := M.ReadLongInt();
2288 SetLerp(TmpX, TmpY);
2289 if NetForcePlayerUpdate then Update();
2290 end;
2291 end;
2293 function MC_RECV_PlayerStats(var M: TMsg): Word;
2294 var
2295 PID: Word;
2296 Pl: TPlayer;
2297 I, OldFire: Integer;
2298 OldJet, Flam: Boolean;
2299 NewTeam: Byte;
2300 begin
2301 PID := M.ReadWord();
2302 Pl := g_Player_Get(PID);
2303 Result := 0;
2304 if Pl = nil then
2305 Exit;
2307 with Pl do
2308 begin
2309 alive := (M.ReadByte() <> 0);
2310 GodMode := (M.ReadByte() <> 0);
2311 Health := M.ReadLongInt();
2312 Armor := M.ReadLongInt();
2313 Air := M.ReadLongInt();
2314 JetFuel := M.ReadLongInt();
2315 Lives := M.ReadByte();
2316 NewTeam := M.ReadByte();
2318 for I := WP_FIRST to WP_LAST do
2319 FWeapon[I] := (M.ReadByte() <> 0);
2321 for I := A_BULLETS to A_HIGH do
2322 FAmmo[I] := M.ReadWord();
2324 for I := A_BULLETS to A_HIGH do
2325 FMaxAmmo[I] := M.ReadWord();
2327 for I := MR_SUIT to MR_MAX do
2328 FMegaRulez[I] := M.ReadLongWord();
2330 FRulez := [];
2331 if (M.ReadByte() <> 0) then
2332 FRulez := FRulez + [R_ITEM_BACKPACK];
2333 if (M.ReadByte() <> 0) then
2334 FRulez := FRulez + [R_KEY_RED];
2335 if (M.ReadByte() <> 0) then
2336 FRulez := FRulez + [R_KEY_GREEN];
2337 if (M.ReadByte() <> 0) then
2338 FRulez := FRulez + [R_KEY_BLUE];
2339 if (M.ReadByte() <> 0) then
2340 FRulez := FRulez + [R_BERSERK];
2342 Frags := M.ReadLongInt();
2343 Death := M.ReadLongInt();
2345 SetWeapon(M.ReadByte());
2347 FSpectator := M.ReadByte() <> 0;
2348 if FSpectator then
2349 begin
2350 if UID = NetPlrUID1 then
2351 begin
2352 gSpectLatchPID1 := UID;
2353 gPlayer1 := nil;
2354 end;
2355 if UID = NetPlrUID2 then
2356 begin
2357 gSpectLatchPID2 := UID;
2358 gPlayer2 := nil;
2359 end;
2360 end
2361 else
2362 begin
2363 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) and (UID = gSpectLatchPID1) then
2364 begin
2365 gPlayer1 := Pl;
2366 gSpectLatchPID1 := 0;
2367 end;
2368 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) and (UID = gSpectLatchPID2) then
2369 begin
2370 gPlayer2 := Pl;
2371 gSpectLatchPID2 := 0;
2372 end;
2373 end;
2374 FGhost := M.ReadByte() <> 0;
2375 FPhysics := M.ReadByte() <> 0;
2376 FNoRespawn := M.ReadByte() <> 0;
2377 OldJet := FJetpack;
2378 FJetpack := M.ReadByte() <> 0;
2379 OldFire := FFireTime;
2380 FFireTime := M.ReadLongInt();
2381 if (OldFire <= 0) and (FFireTime > 0) then
2382 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
2383 Flam := M.ReadByte() <> 0;
2384 FSpawnInvul := M.ReadLongInt();
2385 if OldJet and not FJetpack then
2386 JetpackOff
2387 else if not OldJet and FJetpack then
2388 JetpackOn;
2389 if FFlaming and not Flam then
2390 FlamerOff;
2391 if Team <> NewTeam then
2392 Pl.ChangeTeam(NewTeam);
2393 end;
2395 Result := PID;
2396 end;
2398 function MC_RECV_PlayerDamage(var M: TMsg): Word;
2399 var
2400 PID: Word;
2401 Pl: TPlayer;
2402 Kind: Byte;
2403 Attacker, Value: Word;
2404 VX, VY: Integer;
2405 begin
2406 Result := 0;
2407 if not gGameOn then Exit;
2408 PID := M.ReadWord();
2409 Pl := g_Player_Get(PID);
2410 if Pl = nil then Exit;
2412 Kind := M.ReadByte();
2413 Attacker := M.ReadWord();
2414 Value := M.ReadWord();
2415 VX := M.ReadWord();
2416 VY := M.ReadWord();
2418 with Pl do
2419 Damage(Value, Attacker, VX, VY, Kind);
2421 Result := PID;
2422 end;
2424 function MC_RECV_PlayerDeath(var M: TMsg): Word;
2425 var
2426 PID: Word;
2427 Pl: TPlayer;
2428 KillType, DeathType: Byte;
2429 Attacker: Word;
2430 begin
2431 Result := 0;
2432 if not gGameOn then Exit;
2433 PID := M.ReadWord();
2434 Pl := g_Player_Get(PID);
2435 if Pl = nil then Exit;
2437 KillType := M.ReadByte();
2438 DeathType := M.ReadByte();
2439 Attacker := M.ReadWord();
2441 with Pl do
2442 begin
2443 Kill(KillType, Attacker, DeathType);
2444 SoftReset;
2445 end;
2446 end;
2448 function MC_RECV_PlayerDelete(var M: TMsg): Word;
2449 var
2450 PID: Word;
2451 Pl: TPlayer;
2452 begin
2453 PID := M.ReadWord();
2454 Pl := g_Player_Get(PID);
2455 Result := 0;
2456 if Pl = nil then Exit;
2458 if NetDeafLevel < 3 then
2459 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2460 e_WriteLog('NET: Player ' + Pl.Name + ' [' + IntToStr(PID) + '] removed.', TMsgType.Notify);
2462 g_Player_Remove(PID);
2464 Result := PID;
2465 end;
2467 function MC_RECV_PlayerFire(var M: TMsg): Word;
2468 var
2469 PID: Word;
2470 Weap: Byte;
2471 Pl: TPlayer;
2472 X, Y, AX, AY: Integer;
2473 SHID: Integer;
2474 begin
2475 Result := 0;
2476 if not gGameOn then Exit;
2477 PID := M.ReadWord();
2478 Pl := g_Player_Get(PID);
2479 if Pl = nil then Exit;
2481 Weap := M.ReadByte();
2482 X := M.ReadLongInt();
2483 Y := M.ReadLongInt();
2484 AX := M.ReadLongInt();
2485 AY := M.ReadLongInt();
2486 SHID := M.ReadLongInt();
2488 with Pl do
2489 if alive then NetFire(Weap, X, Y, AX, AY, SHID);
2490 end;
2492 procedure MC_RECV_PlayerSettings(var M: TMsg);
2493 var
2494 TmpName: string;
2495 TmpModel: string;
2496 TmpColor: TRGB;
2497 TmpTeam: Byte;
2498 Pl: TPlayer;
2499 PID: Word;
2500 begin
2501 PID := M.ReadWord();
2502 Pl := g_Player_Get(PID);
2503 if Pl = nil then Exit;
2505 TmpName := M.ReadString();
2506 TmpModel := M.ReadString();
2507 TmpColor.R := M.ReadByte();
2508 TmpColor.G := M.ReadByte();
2509 TmpColor.B := M.ReadByte();
2510 TmpTeam := M.ReadByte();
2512 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
2513 begin
2514 Pl.ChangeTeam(TmpTeam);
2515 if gPlayer1 = Pl then
2516 gPlayer1Settings.Team := TmpTeam;
2517 if gPlayer2 = Pl then
2518 gPlayer2Settings.Team := TmpTeam;
2519 end else
2520 Pl.SetColor(TmpColor);
2522 if Pl.Name <> TmpName then
2523 begin
2524 if NetDeafLevel < 3 then
2525 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
2526 Pl.Name := TmpName;
2527 end;
2529 if TmpModel <> Pl.Model.GetName() then
2530 Pl.SetModel(TmpModel);
2531 end;
2533 // ITEM
2535 procedure MC_RECV_ItemSpawn(var M: TMsg);
2536 var
2537 ID: Word;
2538 X, Y, VX, VY: Integer;
2539 T: Byte;
2540 Quiet, Fall{, Resp}: Boolean;
2541 it: PItem;
2542 begin
2543 if not gGameOn then Exit;
2544 ID := M.ReadWord();
2545 Quiet := M.ReadByte() <> 0;
2546 T := M.ReadByte();
2547 Fall := M.ReadByte() <> 0;
2548 {Resp :=} M.ReadByte();
2549 X := M.ReadLongInt();
2550 Y := M.ReadLongInt();
2551 VX := M.ReadLongInt();
2552 VY := M.ReadLongInt();
2554 g_Items_Create(X, Y, T and $7F, Fall, False, False, ID);
2555 if ((T and $80) <> 0) then g_Items_SetDrop(ID);
2557 it := g_Items_ByIdx(ID);
2558 it.Obj.Vel.X := VX;
2559 it.Obj.Vel.Y := VY;
2561 if not Quiet then
2562 begin
2563 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
2564 {$IFDEF ENABLE_GFX}
2565 g_GFX_QueueEffect(R_GFX_ITEM_RESPAWN, X+(it.Obj.Rect.Width div 2)-16, Y+(it.Obj.Rect.Height div 2)-16);
2566 {$ENDIF}
2567 end;
2568 end;
2570 procedure MC_RECV_ItemDestroy(var M: TMsg);
2571 var
2572 ID: Word;
2573 Quiet: Boolean;
2574 begin
2575 if not gGameOn then Exit;
2576 ID := M.ReadWord();
2577 Quiet := M.ReadByte() <> 0;
2579 if not g_Items_ValidId(ID) then exit;
2581 if not Quiet then g_Items_EmitPickupSound(ID);
2583 g_Items_Remove(ID);
2584 end;
2586 // PANEL
2588 procedure MC_RECV_PanelTexture(var M: TMsg);
2589 var
2590 TP: TPanel;
2591 PGUID: Integer;
2592 Tex, Fr: Integer;
2593 Loop, Cnt: Byte;
2594 begin
2595 if not gGameOn then Exit;
2597 PGUID := Integer(M.ReadLongWord());
2598 Tex := M.ReadLongInt();
2599 Fr := M.ReadLongInt();
2600 Cnt := M.ReadByte();
2601 Loop := M.ReadByte();
2603 TP := g_Map_PanelByGUID(PGUID);
2604 if (TP <> nil) then
2605 begin
2606 // switch texture
2607 TP.SetTexture(Tex, Loop);
2608 TP.SetFrame(Fr, Cnt);
2609 end;
2610 end;
2612 procedure MC_RECV_PanelState(var M: TMsg);
2613 var
2614 PGUID: Integer;
2615 E: Boolean;
2616 Lift: Byte;
2617 X, Y, W, H: Integer;
2618 TP: TPanel;
2619 speedX, speedY, startX, startY, endX, endY: Integer;
2620 sizeSpX, sizeSpY, sizeEX, sizeEY: Integer;
2621 mpflags: Byte;
2622 begin
2623 if not gGameOn then Exit;
2625 PGUID := Integer(M.ReadLongWord());
2626 E := (M.ReadByte() <> 0);
2627 Lift := M.ReadByte();
2628 X := M.ReadLongInt();
2629 Y := M.ReadLongInt();
2630 W := M.ReadWord();
2631 H := M.ReadWord();
2632 // mplats
2633 speedX := M.ReadLongInt();
2634 speedY := M.ReadLongInt();
2635 startX := M.ReadLongInt();
2636 startY := M.ReadLongInt();
2637 endX := M.ReadLongInt();
2638 endY := M.ReadLongInt();
2639 sizeSpX := M.ReadLongInt();
2640 sizeSpY := M.ReadLongInt();
2641 sizeEX := M.ReadLongInt();
2642 sizeEY := M.ReadLongInt();
2643 mpflags := M.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2645 TP := g_Map_PanelByGUID(PGUID);
2646 if (TP = nil) then exit;
2648 // update lifts state
2649 if TP.isGLift then g_Map_SetLiftGUID(PGUID, Lift);
2651 // update enabled/disabled state for all panels
2652 if E then g_Map_EnableWallGUID(PGUID) else g_Map_DisableWallGUID(PGUID);
2654 // update panel position, as it can be moved (mplat)
2655 TP.X := X;
2656 TP.Y := Y;
2657 TP.Width := W;
2658 TP.Height := H;
2659 // update mplat state
2660 TP.movingSpeedX := speedX;
2661 TP.movingSpeedY := speedY;
2662 TP.movingStartX := startX;
2663 TP.movingStartY := startY;
2664 TP.movingEndX := endX;
2665 TP.movingEndY := endY;
2666 TP.sizeSpeedX := sizeSpX;
2667 TP.sizeSpeedY := sizeSpY;
2668 TP.sizeEndX := sizeEX;
2669 TP.sizeEndY := sizeEY;
2670 TP.movingActive := ((mpflags and 1) <> 0);
2671 TP.moveOnce := ((mpflags and 2) <> 0);
2672 // notify panel of it's position/size change, so it can fix other internal structures
2673 TP.positionChanged();
2674 end;
2676 // TRIGGERS
2678 procedure MC_RECV_TriggerSound(var M: TMsg);
2679 var
2680 SPlaying: Boolean;
2681 SPos, SID: LongWord;
2682 SCount: LongInt;
2683 I: Integer;
2684 begin
2685 if not gGameOn then Exit;
2686 if gTriggers = nil then Exit;
2688 SID := M.ReadLongWord();
2689 SPlaying := M.ReadByte() <> 0;
2690 SPos := M.ReadLongWord();
2691 SCount := M.ReadLongInt();
2693 for I := Low(gTriggers) to High(gTriggers) do
2694 if gTriggers[I].TriggerType = TRIGGER_SOUND then
2695 if gTriggers[I].ClientID = SID then
2696 with gTriggers[I] do
2697 begin
2698 if Sound <> nil then
2699 begin
2700 if SPlaying then
2701 begin
2702 if tgcLocal then
2703 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), tgcVolume/255.0)
2704 else
2705 Sound.PlayPanVolume((tgcPan-127.0)/128.0, tgcVolume/255.0);
2706 Sound.SetPosition(SPos);
2707 end
2708 else
2709 if Sound.IsPlaying then Sound.Stop;
2710 end;
2712 SoundPlayCount := SCount;
2713 end;
2714 end;
2716 procedure MC_RECV_TriggerMusic(var M: TMsg);
2717 var
2718 MName: string;
2719 MPlaying: Boolean;
2720 MPos: LongWord;
2721 MPaused: Boolean;
2722 begin
2723 if not gGameOn then Exit;
2725 MName := M.ReadString();
2726 MPlaying := M.ReadByte() <> 0;
2727 MPos := M.ReadLongWord();
2728 MPaused := M.ReadByte() <> 0;
2729 MPos := MPos+1; //k8: stfu, fpc!
2731 if MPlaying then
2732 begin
2733 gMusic.SetByName(MName);
2734 gMusic.Play(True);
2735 // gMusic.SetPosition(MPos);
2736 gMusic.SpecPause := MPaused;
2737 end
2738 else
2739 if gMusic.IsPlaying then gMusic.Stop;
2740 end;
2742 // MONSTERS
2744 procedure MC_RECV_MonsterSpawn(var M: TMsg);
2745 var
2746 ID: Word;
2747 MType, MState, MDir, MAnim, MBehav: Byte;
2748 X, Y, VX, VY, MTargTime, MHealth, MAmmo, MSleep: Integer;
2749 MTarg: Word;
2750 Mon: TMonster;
2751 begin
2752 ID := M.ReadWord();
2753 Mon := g_Monsters_ByUID(ID);
2754 if Mon <> nil then
2755 Exit;
2757 MType := M.ReadByte();
2758 MState := M.ReadByte();
2759 MAnim := M.ReadByte();
2760 MTarg := M.ReadWord();
2761 MTargTime := M.ReadLongInt();
2762 MBehav := M.ReadByte();
2763 MSleep := M.ReadLongInt();
2764 MHealth := M.ReadLongInt();
2765 MAmmo := M.ReadLongInt();
2767 X := M.ReadLongInt();
2768 Y := M.ReadLongInt();
2769 VX := M.ReadLongInt();
2770 VY := M.ReadLongInt();
2771 MDir := M.ReadByte();
2773 g_Monsters_Create(MType, X, Y, TDirection(MDir), False, ID);
2774 Mon := g_Monsters_ByUID(ID);
2775 if Mon = nil then
2776 Exit;
2778 with Mon do
2779 begin
2781 MonsterAnim := MAnim;
2782 MonsterTargetUID := MTarg;
2783 MonsterTargetTime := MTargTime;
2784 MonsterBehaviour := MBehav;
2785 MonsterSleep := MSleep;
2786 MonsterAmmo := MAmmo;
2787 SetHealth(MHealth);
2789 SetState(MState);
2791 setPosition(X, Y); // this will call positionChanged();
2792 GameVelX := VX;
2793 GameVelY := VY;
2794 end;
2795 end;
2797 procedure MC_RECV_MonsterPos(var M: TMsg);
2798 var
2799 Mon: TMonster;
2800 ID: Word;
2801 X, Y: Integer;
2802 begin
2803 ID := M.ReadWord();
2804 Mon := g_Monsters_ByUID(ID);
2805 if Mon = nil then
2806 Exit;
2808 with Mon do
2809 begin
2810 X := M.ReadLongInt();
2811 Y := M.ReadLongInt();
2812 Mon.setPosition(X, Y); // this will call `positionChanged()`
2813 GameVelX := M.ReadLongInt();
2814 GameVelY := M.ReadLongInt();
2815 GameDirection := TDirection(M.ReadByte());
2816 end;
2817 end;
2819 procedure MC_RECV_MonsterState(var M: TMsg);
2820 var
2821 ID, OldFire: Integer;
2822 MState, MFAnm: Byte;
2823 Mon: TMonster;
2824 AnimRevert: Boolean;
2825 begin
2826 ID := M.ReadWord();
2827 Mon := g_Monsters_ByUID(ID);
2828 if Mon = nil then Exit;
2830 MState := M.ReadByte();
2831 MFAnm := M.ReadByte();
2833 with Mon do
2834 begin
2835 MonsterTargetUID := M.ReadWord();
2836 MonsterTargetTime := M.ReadLongInt();
2837 MonsterSleep := M.ReadLongInt();
2838 MonsterHealth := M.ReadLongInt();
2839 MonsterAmmo := M.ReadLongInt();
2840 MonsterPain := M.ReadLongInt();
2841 AnimRevert := M.ReadByte() <> 0;
2842 OldFire := FFireTime;
2843 FFireTime := M.ReadLongInt();
2844 if (OldFire <= 0) and (FFireTime > 0) then
2845 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
2846 RevertAnim(AnimRevert);
2848 if MonsterState <> MState then
2849 begin
2850 if (MState = MONSTATE_GO) and (MonsterState = MONSTATE_SLEEP) then WakeUpSound();
2851 if (MState = MONSTATE_DIE) then DieSound();
2852 if (MState = MONSTATE_PAIN) then MakeBloodSimple(Min(200, MonsterPain));
2853 if (MState = MONSTATE_ATTACK) then kick(nil);
2854 if (MState = MONSTATE_DEAD) then SetDeadAnim();
2856 SetState(MState, MFAnm);
2857 end;
2858 end;
2859 end;
2861 procedure MC_RECV_MonsterShot(var M: TMsg);
2862 var
2863 ID: Integer;
2864 Mon: TMonster;
2865 X, Y, VX, VY: Integer;
2866 begin
2867 ID := M.ReadWord();
2869 Mon := g_Monsters_ByUID(ID);
2870 if Mon = nil then Exit;
2872 X := M.ReadLongInt();
2873 Y := M.ReadLongInt();
2874 VX := M.ReadLongInt();
2875 VY := M.ReadLongInt();
2877 Mon.ClientAttack(X, Y, VX, VY);
2878 end;
2880 procedure MC_RECV_MonsterDelete(var M: TMsg);
2881 var
2882 ID: Integer;
2883 Mon: TMonster;
2884 begin
2885 ID := M.ReadWord();
2886 Mon := g_Monsters_ByUID(ID);
2887 if Mon = nil then Exit;
2888 Mon.SetState(5);
2889 Mon.MonsterRemoved := True;
2890 end;
2892 procedure MC_RECV_TimeSync(var M: TMsg);
2893 var
2894 Time: LongWord;
2895 begin
2896 Time := M.ReadLongWord();
2898 if gState = STATE_INTERCUSTOM then
2899 gServInterTime := Min(Time, 255);
2900 end;
2902 procedure MC_RECV_VoteEvent(var M: TMsg);
2903 var
2904 EvID: Byte;
2905 Str1, Str2: string;
2906 Int1, Int2: SmallInt;
2907 begin
2908 EvID := M.ReadByte();
2909 Int1 := M.ReadSmallInt();
2910 Int2 := M.ReadSmallInt();
2911 Str1 := M.ReadString();
2912 Str2 := M.ReadString();
2914 if NetDeafLevel < 2 then
2915 case EvID of
2916 NET_VE_STARTED:
2917 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True);
2918 NET_VE_PASSED:
2919 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True);
2920 NET_VE_FAILED:
2921 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
2922 NET_VE_VOTE:
2923 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True);
2924 NET_VE_INPROGRESS:
2925 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True);
2926 end;
2927 end;
2929 // CLIENT SEND
2931 procedure MC_SEND_Info(Password: string);
2932 begin
2933 NetOut.Clear();
2935 NetOut.Write(Byte(NET_MSG_INFO));
2936 NetOut.Write(GAME_VERSION);
2937 NetOut.Write(Password);
2938 NetOut.Write(gPlayer1Settings.Name);
2939 NetOut.Write(gPlayer1Settings.Model);
2940 NetOut.Write(gPlayer1Settings.Color.R);
2941 NetOut.Write(gPlayer1Settings.Color.G);
2942 NetOut.Write(gPlayer1Settings.Color.B);
2943 NetOut.Write(gPlayer1Settings.Team);
2945 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2946 end;
2948 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
2949 begin
2950 NetOut.Write(Byte(NET_MSG_CHAT));
2951 NetOut.Write(Txt);
2952 NetOut.Write(Mode);
2954 g_Net_Client_Send(True, NET_CHAN_CHAT);
2955 end;
2957 procedure MC_SEND_PlayerPos();
2958 var
2959 kByte: Word;
2960 Predict: Boolean;
2961 strafeDir: Byte;
2962 WeaponSelect: Word = 0;
2963 i: Integer;
2964 begin
2965 if not gGameOn then Exit;
2966 if gPlayers = nil then Exit;
2967 if gPlayer1 = nil then Exit;
2969 kByte := 0;
2970 Predict := NetPredictSelf; // and (not NetGotKeys);
2972 {$IFDEF DISABLE_MENU}
2973 if (not gConsoleShow) and (not gChatShow) then
2974 {$ELSE}
2975 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2976 {$ENDIF}
2977 begin
2978 strafeDir := P1MoveButton shr 4;
2979 P1MoveButton := P1MoveButton and $0F;
2981 if gPlayerAction[0, ACTION_MOVELEFT] and (not gPlayerAction[0, ACTION_MOVERIGHT]) then
2982 P1MoveButton := 1
2983 else if (not gPlayerAction[0, ACTION_MOVELEFT]) and gPlayerAction[0, ACTION_MOVERIGHT] then
2984 P1MoveButton := 2
2985 else if (not gPlayerAction[0, ACTION_MOVELEFT]) and (not gPlayerAction[0, ACTION_MOVERIGHT]) then
2986 P1MoveButton := 0;
2988 // strafing
2989 if gPlayerAction[0, ACTION_STRAFE] then
2990 begin
2991 // new strafe mechanics
2992 if (strafeDir = 0) then
2993 strafeDir := P1MoveButton; // start strafing
2994 // now set direction according to strafe (reversed)
2995 if (strafeDir = 2) then
2996 gPlayer1.SetDirection(TDirection.D_LEFT)
2997 else if (strafeDir = 1) then
2998 gPlayer1.SetDirection(TDirection.D_RIGHT)
2999 end
3000 else
3001 begin
3002 strafeDir := 0; // not strafing anymore
3003 if (P1MoveButton = 2) and gPlayerAction[0, ACTION_MOVELEFT] then
3004 gPlayer1.SetDirection(TDirection.D_LEFT)
3005 else if (P1MoveButton = 1) and gPlayerAction[0, ACTION_MOVERIGHT] then
3006 gPlayer1.SetDirection(TDirection.D_RIGHT)
3007 else if P1MoveButton <> 0 then
3008 gPlayer1.SetDirection(TDirection(P1MoveButton-1));
3009 end;
3011 gPlayer1.ReleaseKeys;
3012 if P1MoveButton = 1 then
3013 begin
3014 kByte := kByte or NET_KEY_LEFT;
3015 if Predict then gPlayer1.PressKey(KEY_LEFT, 10000);
3016 end;
3017 if P1MoveButton = 2 then
3018 begin
3019 kByte := kByte or NET_KEY_RIGHT;
3020 if Predict then gPlayer1.PressKey(KEY_RIGHT, 10000);
3021 end;
3022 if gPlayerAction[0, ACTION_LOOKUP] then
3023 begin
3024 kByte := kByte or NET_KEY_UP;
3025 gPlayer1.PressKey(KEY_UP, 10000);
3026 end;
3027 if gPlayerAction[0, ACTION_LOOKDOWN] then
3028 begin
3029 kByte := kByte or NET_KEY_DOWN;
3030 gPlayer1.PressKey(KEY_DOWN, 10000);
3031 end;
3032 if gPlayerAction[0, ACTION_JUMP] then
3033 begin
3034 kByte := kByte or NET_KEY_JUMP;
3035 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3036 end;
3037 if gPlayerAction[0, ACTION_ATTACK] then kByte := kByte or NET_KEY_FIRE;
3038 if gPlayerAction[0, ACTION_ACTIVATE] then kByte := kByte or NET_KEY_OPEN;
3039 if gPlayerAction[0, ACTION_WEAPNEXT] then kByte := kByte or NET_KEY_NW;
3040 if gPlayerAction[0, ACTION_WEAPPREV] then kByte := kByte or NET_KEY_PW;
3042 gPlayerAction[0, ACTION_WEAPNEXT] := False; // HACK, remove after readyweaon&pendinweapon implementation
3043 gPlayerAction[0, ACTION_WEAPPREV] := False; // HACK, remove after readyweaon&pendinweapon implementation
3045 for i := WP_FIRST to WP_LAST do
3046 begin
3047 if gSelectWeapon[0, i] then
3048 begin
3049 WeaponSelect := WeaponSelect or Word(1 shl i);
3050 gSelectWeapon[0, i] := False
3051 end
3052 end;
3054 // fix movebutton state
3055 P1MoveButton := P1MoveButton or (strafeDir shl 4);
3056 end
3057 else
3058 kByte := NET_KEY_CHAT;
3060 NetOut.Write(Byte(NET_MSG_PLRPOS));
3061 NetOut.Write(gTime);
3062 NetOut.Write(kByte);
3063 NetOut.Write(Byte(gPlayer1.Direction));
3064 NetOut.Write(WeaponSelect);
3065 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3066 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS);
3068 //kBytePrev := kByte;
3069 //kDirPrev := gPlayer1.Direction;
3070 end;
3072 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
3073 begin
3074 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
3075 NetOut.Write(Byte(Start));
3076 NetOut.Write(Command);
3077 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3078 end;
3080 procedure MC_SEND_PlayerSettings();
3081 begin
3082 NetOut.Write(Byte(NET_MSG_PLRSET));
3083 NetOut.Write(gPlayer1Settings.Name);
3084 NetOut.Write(gPlayer1Settings.Model);
3085 NetOut.Write(gPlayer1Settings.Color.R);
3086 NetOut.Write(gPlayer1Settings.Color.G);
3087 NetOut.Write(gPlayer1Settings.Color.B);
3088 NetOut.Write(gPlayer1Settings.Team);
3090 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3091 end;
3093 procedure MC_SEND_FullStateRequest();
3094 begin
3095 NetOut.Write(Byte(NET_MSG_REQFST));
3097 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3098 end;
3100 procedure MC_SEND_CheatRequest(Kind: Byte);
3101 begin
3102 NetOut.Write(Byte(NET_MSG_CHEAT));
3103 NetOut.Write(Kind);
3105 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3106 end;
3107 procedure MC_SEND_RCONPassword(Password: string);
3108 begin
3109 NetOut.Write(Byte(NET_MSG_RCON_AUTH));
3110 NetOut.Write(Password);
3112 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3113 end;
3114 procedure MC_SEND_RCONCommand(Cmd: string);
3115 begin
3116 NetOut.Write(Byte(NET_MSG_RCON_CMD));
3117 NetOut.Write(Cmd);
3119 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3120 end;
3123 end.