DEADSOFTWARE

6d004e814fcb61fcb5aea62b26126a5cc3138778
[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 Math, ENet, e_input, e_graphics, e_log,
280 g_textures, g_gfx, g_sound, g_console, g_basic, g_options, g_main,
281 g_game, g_player, g_map, g_panel, g_items, g_weapons, g_phys, g_gui,
282 g_language, g_monsters, g_netmaster, utils, wadreader, MAPDEF;
284 const
285 NET_KEY_LEFT = 1 shl 0;
286 NET_KEY_RIGHT = 1 shl 1;
287 NET_KEY_UP = 1 shl 2;
288 NET_KEY_DOWN = 1 shl 3;
289 NET_KEY_JUMP = 1 shl 4;
290 NET_KEY_FIRE = 1 shl 5;
291 NET_KEY_OPEN = 1 shl 6;
292 NET_KEY_CHAT = 1 shl 7;
293 NET_KEY_FORCEDIR = 1 shl 8;
295 //var
296 //kBytePrev: Word = 0;
297 //kDirPrev: TDirection = D_LEFT;
298 //HostGameTime: Word = 0;
301 function IsValidFileName(const S: String): Boolean;
302 const
303 Forbidden: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
304 var
305 I: Integer;
306 begin
307 Result := S <> '';
308 for I := 1 to Length(S) do
309 Result := Result and (not(S[I] in Forbidden));
310 end;
312 function IsValidFilePath(const S: String): Boolean;
313 var
314 I: Integer;
315 begin
316 Result := False;
317 if not IsValidFileName(S) then exit;
318 if FileExists(S) then exit;
319 I := LastDelimiter('\/', S);
320 if (I > 0) then
321 if (not DirectoryExists(Copy(S, 1, I-1))) then
322 exit;
323 Result := True;
324 end;
327 // HOST MESSAGES //
330 // GAME
332 procedure MH_RECV_Chat(C: pTNetClient; var M: TMsg);
333 var
334 Txt: string;
335 Mode: Byte;
336 PID: Word;
337 Pl: TPlayer;
338 begin
339 PID := C^.Player;
340 Pl := g_Player_Get(PID);
342 Txt := M.ReadString();
343 Mode := M.ReadByte();
344 if (Mode = NET_CHAT_SYSTEM) then
345 Mode := NET_CHAT_PLAYER; // prevent sending system messages from clients
346 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
347 Mode := NET_CHAT_PLAYER; // revert to player chat in non-team game
349 if Pl = nil then
350 MH_SEND_Chat(Txt, Mode)
351 else
352 MH_SEND_Chat(Pl.Name + ': ' + Txt, Mode, IfThen(Mode = NET_CHAT_TEAM, Pl.Team, NET_EVERYONE));
353 end;
355 procedure MH_RECV_Info(C: pTNetClient; var M: TMsg);
356 var
357 Ver, PName, Model, Pw: string;
358 R, G, B, T: Byte;
359 PID: Word;
360 Color: TRGB;
361 I: Integer;
362 begin
363 Ver := M.ReadString();
364 Pw := M.ReadString();
365 PName := M.ReadString();
366 Model := M.ReadString();
367 R := M.ReadByte();
368 G := M.ReadByte();
369 B := M.ReadByte();
370 T := M.ReadByte();
372 if Ver <> GAME_VERSION then
373 begin
374 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
375 _lc[I_NET_DISC_VERSION]);
376 enet_peer_disconnect(C^.Peer, NET_DISC_VERSION);
377 Exit;
378 end;
380 if g_Net_IsHostBanned(C^.Peer^.address.host) then
381 begin
382 if g_Net_IsHostBanned(C^.Peer^.address.host, True) then
383 begin
384 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
385 _lc[I_NET_DISC_BAN]);
386 enet_peer_disconnect(C^.Peer, NET_DISC_BAN);
387 end
388 else
389 begin
390 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
391 _lc[I_NET_DISC_BAN]);
392 enet_peer_disconnect(C^.Peer, NET_DISC_TEMPBAN);
393 end;
394 Exit;
395 end;
397 if NetPassword <> '' then
398 if AnsiLowerCase(NetPassword) <> AnsiLowerCase(Pw) then
399 begin
400 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
401 _lc[I_NET_DISC_PASSWORD]);
402 enet_peer_disconnect(C^.Peer, NET_DISC_PASSWORD);
403 Exit;
404 end;
406 Color.R := R;
407 Color.B := B;
408 Color.G := G;
410 PID := g_Player_Create(Model, Color, T, False);
411 with g_Player_Get(PID) do
412 begin
413 Name := PName;
414 Reset(True);
415 end;
417 C^.Player := PID;
418 C^.WaitForFirstSpawn := false;
420 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
421 e_WriteLog('NET: Client ' + PName + ' [' + IntToStr(C^.ID) +
422 '] connected. Assigned player #' + IntToStr(PID) + '.', TMsgType.Notify);
424 MH_SEND_Info(C^.ID);
426 with g_Player_Get(PID) do
427 begin
428 Name := PName;
429 FClientID := C^.ID;
430 // round in progress, don't spawn
431 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C.ID, C.Player]);
432 //e_LogWritefln('spawning player with pid #%u...', [PID]);
433 //Respawn(gGameSettings.GameType = GT_SINGLE);
434 //k8: no, do not spawn a player yet, wait for "request full state" packet
435 Lives := 0;
436 Spectate;
437 FNoRespawn := True;
438 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
439 // that is, if we'll set it to `true`, the player can be spawned after
440 // warmup time ran out, for example, regardless of the real player state.
441 // also, this seems to work only for the initial connection. further
442 // map changes could initiate resource downloading, but the player will
443 // be spawned immediately.
444 // the proper solution will require another player state, "ephemeral".
445 // the player should start any map in "ephemeral" state, and turned into
446 // real mobj only when they sent a special "i am ready" packet. this packet
447 // must be sent after receiving the full state, so the player will get a full
448 // map view before going into game.
449 FWantsInGame := false;
450 C^.WaitForFirstSpawn := true;
451 end;
453 //if not C^.WaitForFirstSpawn then
454 begin
455 for I := Low(NetClients) to High(NetClients) do
456 begin
457 if NetClients[I].ID = C^.ID then Continue;
458 MH_SEND_PlayerCreate(PID, NetClients[I].ID);
459 MH_SEND_PlayerPos(True, PID, NetClients[I].ID);
460 MH_SEND_PlayerStats(PID, NetClients[I].ID);
461 end;
462 end;
464 if gState in [STATE_INTERCUSTOM, STATE_FOLD] then
465 MH_SEND_GameEvent(NET_EV_MAPEND, 0, 'N', C^.ID);
467 if NetUseMaster then
468 begin
469 //g_Net_Slist_Update;
470 g_Net_Slist_Pulse();
471 end;
472 end;
475 procedure MH_ProcessFirstSpawn (C: pTNetClient);
476 var
477 plr: TPlayer;
478 begin
479 if not C.WaitForFirstSpawn then exit;
480 plr := g_Player_Get(C^.Player);
481 if not assigned(plr) then exit;
482 g_Net_Slist_ServerPlayerComes();
483 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C.ID, C.Player]);
484 C.WaitForFirstSpawn := false;
485 plr.FNoRespawn := false;
486 plr.FWantsInGame := true; // TODO: look into this later
488 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
489 begin
490 plr.Spectate;
491 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN, 0, 'N', C.ID);
492 end
493 else
494 begin
495 plr.Respawn(False);
496 if gLMSRespawn > LMS_RESPAWN_NONE then
497 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime, 'N', C.ID);
498 end;
499 end;
502 procedure MH_RECV_FullStateRequest(C: pTNetClient; var M: TMsg);
503 begin
504 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
505 if gGameOn then
506 begin
507 MH_SEND_Everything((C^.State = NET_STATE_AUTH), C^.ID)
508 end
509 else
510 begin
511 C^.RequestedFullUpdate := True;
512 end;
513 end;
515 // PLAYER
517 function MH_RECV_PlayerPos(C: pTNetClient; var M: TMsg): Word;
518 var
519 Dir, i: Byte;
520 WeaponAct: Byte;
521 WeaponSelect: Word;
522 PID: Word;
523 kByte: Word;
524 Pl: TPlayer;
525 GT: LongWord;
526 begin
527 Result := 0;
528 if not gGameOn then Exit;
530 GT := M.ReadLongWord();
531 PID := C^.Player;
532 Pl := g_Player_Get(PID);
533 if Pl = nil then
534 Exit;
536 if (GT > gTime + NET_MAX_DIFFTIME) or (GT < Pl.NetTime) then Exit;
538 with Pl do
539 begin
540 NetTime := GT;
541 kByte := M.ReadWord();
542 Dir := M.ReadByte();
543 WeaponAct := M.ReadByte();
544 WeaponSelect := M.ReadWord();
545 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
546 if Direction <> TDirection(Dir) then
547 JustTeleported := False;
549 SetDirection(TDirection(Dir));
550 ReleaseKeys;
552 if kByte = NET_KEY_CHAT then
553 begin
554 PressKey(KEY_CHAT, 10000);
555 Exit;
556 end;
558 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
559 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
560 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
561 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
562 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
563 if LongBool(kByte and NET_KEY_FIRE) then PressKey(KEY_FIRE, 10000);
564 if LongBool(kByte and NET_KEY_OPEN) then PressKey(KEY_OPEN, 10000);
566 for i := 0 to 7 do
567 begin
568 if (WeaponAct and Byte(1 shl i)) <> 0 then
569 begin
570 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
571 ProcessWeaponAction(i);
572 end;
573 end;
575 for i := 0 to 15 do
576 begin
577 if (WeaponSelect and Word(1 shl i)) <> 0 then
578 begin
579 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
580 QueueWeaponSwitch(i);
581 end;
582 end;
583 end;
585 // MH_SEND_PlayerPos(False, PID, C^.ID);
586 end;
588 procedure MH_RECV_CheatRequest(C: pTNetClient; var M: TMsg);
589 var
590 CheatKind: Byte;
591 Pl: TPlayer;
592 begin
593 Pl := g_Player_Get(C^.Player);
594 if Pl = nil then Exit;
596 CheatKind := M.ReadByte();
598 case CheatKind of
599 NET_CHEAT_SUICIDE:
600 Pl.Damage(SUICIDE_DAMAGE, Pl.UID, 0, 0, HIT_SELF);
601 NET_CHEAT_SPECTATE:
602 begin
603 if Pl.FSpectator then
604 begin
605 if (gGameSettings.MaxLives = 0) or (gLMSRespawn > LMS_RESPAWN_NONE) then
606 Pl.Respawn(False)
607 else
608 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN, Pl.UID);
609 end
610 else
611 Pl.Spectate;
612 end;
613 NET_CHEAT_READY:
614 begin
615 if gState <> STATE_INTERCUSTOM then Exit;
616 Pl.FReady := not Pl.FReady;
617 if Pl.FReady then
618 begin
619 MH_SEND_GameEvent(NET_EV_INTER_READY, Pl.UID, 'Y');
620 Inc(gInterReadyCount);
621 end
622 else
623 begin
624 MH_SEND_GameEvent(NET_EV_INTER_READY, Pl.UID, 'N');
625 Dec(gInterReadyCount);
626 end;
627 end;
628 end;
629 end;
631 procedure MH_RECV_PlayerSettings(C: pTNetClient; var M: TMsg);
632 var
633 TmpName: string;
634 TmpModel: string;
635 TmpColor: TRGB;
636 TmpTeam: Byte;
637 Pl: TPlayer;
638 begin
639 TmpName := M.ReadString();
640 TmpModel := M.ReadString();
641 TmpColor.R := M.ReadByte();
642 TmpColor.G := M.ReadByte();
643 TmpColor.B := M.ReadByte();
644 TmpTeam := M.ReadByte();
646 Pl := g_Player_Get(C^.Player);
647 if Pl = nil then Exit;
649 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
650 Pl.SwitchTeam
651 else
652 Pl.SetColor(TmpColor);
654 if Pl.Name <> TmpName then
655 begin
656 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
657 Pl.Name := TmpName;
658 end;
660 if TmpModel <> Pl.Model.Name then
661 Pl.SetModel(TmpModel);
663 MH_SEND_PlayerSettings(Pl.UID, TmpModel);
664 end;
666 // RCON
668 procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
669 var
670 Pwd: string;
671 begin
672 Pwd := M.ReadString();
673 if not NetAllowRCON then Exit;
674 if Pwd = NetRCONPassword then
675 begin
676 C^.RCONAuth := True;
677 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWGOOD, 'N', C^.ID);
678 end
679 else
680 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWBAD, 'N', C^.ID);
681 end;
683 procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
684 var
685 Cmd: string;
686 begin
687 Cmd := M.ReadString();
688 if not NetAllowRCON then Exit;
689 if not C^.RCONAuth then
690 begin
691 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_NOAUTH, 'N', C^.ID);
692 Exit;
693 end;
694 g_Console_Process(Cmd);
695 end;
697 // MISC
699 procedure MH_RECV_Vote(C: pTNetClient; var M: TMsg);
700 var
701 Start: Boolean;
702 Name, Command: string;
703 Need: Integer;
704 Pl: TPlayer;
705 begin
706 Start := M.ReadByte() <> 0;
707 Command := M.ReadString();
709 Pl := g_Player_Get(C^.Player);
710 if Pl = nil then Exit;
711 Name := Pl.Name;
713 if Start then
714 begin
715 if not g_Console_CommandBlacklisted(Command) then
716 g_Game_StartVote(Command, Name);
717 end
718 else if gVoteInProgress then
719 begin
720 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
721 Need := Floor((NetClientCount+1)/2.0) + 1
722 else
723 Need := Floor(NetClientCount/2.0) + 1;
724 if C^.Voted then
725 begin
726 Dec(gVoteCount);
727 C^.Voted := False;
728 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [Name, gVoteCount, Need]), True);
729 MH_SEND_VoteEvent(NET_VE_REVOKE, Name, 'a', gVoteCount, Need);
730 end
731 else
732 begin
733 Inc(gVoteCount);
734 C^.Voted := True;
735 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Name, gVoteCount, Need]), True);
736 MH_SEND_VoteEvent(NET_VE_VOTE, Name, 'a', gVoteCount, Need);
737 g_Game_CheckVote;
738 end;
739 end;
740 end;
742 // GAME (SEND)
744 procedure MH_SEND_Everything(CreatePlayers: Boolean {= False}; ID: Integer {= NET_EVERYONE});
746 function sendItemRespawn (it: PItem): Boolean;
747 begin
748 result := false; // don't stop
749 MH_SEND_ItemSpawn(True, it.myid, ID);
750 end;
752 function sendMonSpawn (mon: TMonster): Boolean;
753 begin
754 result := false; // don't stop
755 MH_SEND_MonsterSpawn(mon.UID, ID);
756 end;
758 function sendPanelState (pan: TPanel): Boolean;
759 begin
760 result := false; // don't stop
761 MH_SEND_PanelState(pan.guid, ID); // anyway, to sync mplats
762 if (pan.CanChangeTexture) then MH_SEND_PanelTexture(pan.guid, pan.LastAnimLoop, ID);
763 end;
765 var
766 I: Integer;
767 begin
768 if (ID >= 0) and (ID < length(NetClients)) then
769 begin
770 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID, NetClients[ID].Player]);
771 MH_ProcessFirstSpawn(@NetClients[ID]);
772 end;
774 if gPlayers <> nil then
775 begin
776 for I := Low(gPlayers) to High(gPlayers) do
777 begin
778 if gPlayers[I] <> nil then
779 begin
780 if CreatePlayers then MH_SEND_PlayerCreate(gPlayers[I].UID, ID);
781 MH_SEND_PlayerPos(True, gPlayers[I].UID, ID);
782 MH_SEND_PlayerStats(gPlayers[I].UID, ID);
784 if (gPlayers[I].Flag <> FLAG_NONE) and (gGameSettings.GameMode = GM_CTF) then
785 begin
786 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED, gPlayers[I].Flag, gPlayers[I].UID, True, ID);
787 end;
788 end;
789 end;
790 end;
792 g_Items_ForEachAlive(sendItemRespawn, true); // backwards
793 g_Mons_ForEach(sendMonSpawn);
794 g_Map_ForEachPanel(sendPanelState);
796 if gTriggers <> nil then
797 begin
798 for I := Low(gTriggers) to High(gTriggers) do
799 begin
800 if gTriggers[I].TriggerType = TRIGGER_SOUND then
801 begin
802 MH_SEND_TriggerSound(gTriggers[I], ID);
803 end;
804 end;
805 end;
807 if Shots <> nil then
808 begin
809 for I := Low(Shots) to High(Shots) do
810 begin
811 if Shots[i].ShotType in [6, 7, 8] then
812 begin
813 MH_SEND_CreateShot(i, ID);
814 end;
815 end;
816 end;
818 MH_SEND_TriggerMusic(ID);
820 MH_SEND_GameStats(ID);
821 MH_SEND_CoopStats(ID);
823 if gGameSettings.GameMode = GM_CTF then
824 begin
825 if gFlags[FLAG_RED].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_RED].State, FLAG_RED, 0, True, ID);
826 if gFlags[FLAG_BLUE].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_BLUE].State, FLAG_BLUE, 0, True, ID);
827 end;
829 if CreatePlayers and (ID >= 0) then NetClients[ID].State := NET_STATE_GAME;
831 g_Net_Flush();
832 end;
834 procedure MH_SEND_Info(ID: Byte);
835 begin
836 NetOut.Clear();
838 NetOut.Write(Byte(NET_MSG_INFO));
839 NetOut.Write(ID);
840 NetOut.Write(NetClients[ID].Player);
841 NetOut.Write(ExtractFileName(gGameSettings.WAD));
842 NetOut.Write(g_ExtractFileName(gMapInfo.Map));
843 NetOut.Write(gWADHash);
844 NetOut.Write(gGameSettings.GameMode);
845 NetOut.Write(gGameSettings.GoalLimit);
846 NetOut.Write(gGameSettings.TimeLimit);
847 NetOut.Write(gGameSettings.MaxLives);
848 NetOut.Write(gGameSettings.Options);
849 NetOut.Write(gTime);
851 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
852 end;
854 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
855 var
856 Name: string;
857 i: Integer;
858 Team: Byte;
859 begin
860 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
861 Mode := NET_CHAT_PLAYER;
863 Team := 0;
864 if (Mode = NET_CHAT_TEAM) then
865 begin
866 for i := Low(gPlayers) to High(gPlayers) do
867 if (gPlayers[i] <> nil) and (gPlayers[i].FClientID >= 0) and
868 (gPlayers[i].Team = ID) then
869 begin
870 NetOut.Write(Byte(NET_MSG_CHAT));
871 NetOut.Write(Txt);
872 NetOut.Write(Mode);
873 g_Net_Host_Send(gPlayers[i].FClientID, True, NET_CHAN_CHAT);
874 end;
875 Team := ID;
876 ID := NET_EVERYONE;
877 end
878 else
879 begin
880 NetOut.Write(Byte(NET_MSG_CHAT));
881 NetOut.Write(Txt);
882 NetOut.Write(Mode);
883 g_Net_Host_Send(ID, True, NET_CHAN_CHAT);
884 end;
886 if Mode = NET_CHAT_SYSTEM then
887 Exit;
889 if ID = NET_EVERYONE then
890 begin
891 if Mode = NET_CHAT_PLAYER then
892 begin
893 g_Console_Add(Txt, True);
894 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
895 g_Game_ChatSound(b_Text_Unformat(Txt));
896 end
897 else
898 if Mode = NET_CHAT_TEAM then
899 if gPlayer1 <> nil then
900 begin
901 if (gPlayer1.Team = TEAM_RED) and (Team = TEAM_RED) then
902 begin
903 g_Console_Add(#18'[Team] '#2 + Txt, True);
904 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
905 g_Game_ChatSound(b_Text_Unformat(Txt));
906 end
907 else if (gPlayer1.Team = TEAM_BLUE) and (Team = TEAM_BLUE) then
908 begin
909 g_Console_Add(#20'[Team] '#2 + Txt, True);
910 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
911 g_Game_ChatSound(b_Text_Unformat(Txt));
912 end;
913 end;
914 end
915 else
916 begin
917 Name := g_Net_ClientName_ByID(ID);
918 g_Console_Add('-> ' + Name + ': ' + Txt, True);
919 e_WriteLog('[Tell ' + Name + '] ' + b_Text_Unformat(Txt), TMsgType.Notify);
920 g_Game_ChatSound(b_Text_Unformat(Txt), False);
921 end;
922 end;
924 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
925 begin
926 NetOut.Write(Byte(NET_MSG_GFX));
927 NetOut.Write(Kind);
928 NetOut.Write(X);
929 NetOut.Write(Y);
930 NetOut.Write(Ang);
932 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
933 end;
935 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
936 begin
937 NetOut.Write(Byte(NET_MSG_SND));
938 NetOut.Write(Name);
939 if Pos then
940 begin
941 NetOut.Write(Byte(1));
942 NetOut.Write(X);
943 NetOut.Write(Y);
944 end
945 else
946 NetOut.Write(Byte(0));
948 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
949 end;
951 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
952 begin
953 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
955 NetOut.Write(Byte(NET_MSG_SHADD));
956 NetOut.Write(Proj);
957 NetOut.Write(Shots[Proj].ShotType);
958 NetOut.Write(Shots[Proj].Target);
959 NetOut.Write(Shots[Proj].SpawnerUID);
960 NetOut.Write(Shots[Proj].Timeout);
961 NetOut.Write(Shots[Proj].Obj.X);
962 NetOut.Write(Shots[Proj].Obj.Y);
963 NetOut.Write(Shots[Proj].Obj.Vel.X);
964 NetOut.Write(Shots[Proj].Obj.Vel.Y);
966 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
967 end;
969 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
970 begin
971 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
973 NetOut.Write(Byte(NET_MSG_SHPOS));
974 NetOut.Write(Proj);
975 NetOut.Write(Shots[Proj].Obj.X);
976 NetOut.Write(Shots[Proj].Obj.Y);
977 NetOut.Write(Shots[Proj].Obj.Vel.X);
978 NetOut.Write(Shots[Proj].Obj.Vel.Y);
980 g_Net_Host_Send(ID, False, NET_CHAN_SHOTS);
981 end;
983 procedure MH_Send_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
984 begin
985 NetOut.Write(Byte(NET_MSG_SHDEL));
986 NetOut.Write(Proj);
987 NetOut.Write(Byte(Loud));
988 NetOut.Write(X);
989 NetOut.Write(Y);
991 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
992 end;
994 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
995 begin
996 NetOut.Write(Byte(NET_MSG_SCORE));
997 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
998 begin
999 NetOut.Write(gTeamStat[TEAM_RED].Goals);
1000 NetOut.Write(gTeamStat[TEAM_BLUE].Goals);
1001 end
1002 else
1003 if gGameSettings.GameMode = GM_COOP then
1004 begin
1005 NetOut.Write(gCoopMonstersKilled);
1006 NetOut.Write(gCoopSecretsFound);
1007 end;
1009 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1010 end;
1012 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
1013 begin
1014 NetOut.Write(Byte(NET_MSG_COOP));
1015 NetOut.Write(gTotalMonsters);
1016 NetOut.Write(gSecretsCount);
1017 NetOut.Write(gCoopTotalMonstersKilled);
1018 NetOut.Write(gCoopTotalSecretsFound);
1019 NetOut.Write(gCoopTotalMonsters);
1020 NetOut.Write(gCoopTotalSecrets);
1021 end;
1023 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
1024 begin
1025 NetOut.Write(Byte(NET_MSG_GEVENT));
1026 NetOut.Write(EvType);
1027 NetOut.Write(EvNum);
1028 NetOut.Write(EvStr);
1029 NetOut.Write(Byte(gLastMap));
1030 NetOut.Write(gTime);
1031 if (EvType = NET_EV_MAPSTART) and isWadPath(EvStr) then
1032 begin
1033 NetOut.Write(Byte(1));
1034 NetOut.Write(gWADHash);
1035 end else
1036 NetOut.Write(Byte(0));
1038 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
1039 end;
1041 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
1042 begin
1043 NetOut.Write(Byte(NET_MSG_FLAG));
1044 NetOut.Write(EvType);
1045 NetOut.Write(Flag);
1046 NetOut.Write(Byte(Quiet));
1047 NetOut.Write(PID);
1048 NetOut.Write(gFlags[Flag].State);
1049 NetOut.Write(gFlags[Flag].CaptureTime);
1050 NetOut.Write(gFlags[Flag].Obj.X);
1051 NetOut.Write(gFlags[Flag].Obj.Y);
1052 NetOut.Write(gFlags[Flag].Obj.Vel.X);
1053 NetOut.Write(gFlags[Flag].Obj.Vel.Y);
1055 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1056 end;
1058 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
1059 begin
1060 NetOut.Write(Byte(NET_MSG_GSET));
1061 NetOut.Write(gGameSettings.GameMode);
1062 NetOut.Write(gGameSettings.GoalLimit);
1063 NetOut.Write(gGameSettings.TimeLimit);
1064 NetOut.Write(gGameSettings.MaxLives);
1065 NetOut.Write(gGameSettings.Options);
1067 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1068 end;
1070 // PLAYER (SEND)
1072 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
1073 var
1074 P: TPlayer;
1075 begin
1076 P := g_Player_Get(PID);
1077 if P = nil then Exit;
1079 NetOut.Write(Byte(NET_MSG_PLR));
1080 NetOut.Write(PID);
1081 NetOut.Write(P.Name);
1083 NetOut.Write(P.FActualModelName);
1084 NetOut.Write(P.FColor.R);
1085 NetOut.Write(P.FColor.G);
1086 NetOut.Write(P.FColor.B);
1087 NetOut.Write(P.Team);
1089 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT)
1090 end;
1092 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
1093 var
1094 kByte: Word;
1095 Pl: TPlayer;
1096 begin
1097 Pl := g_Player_Get(PID);
1098 if Pl = nil then Exit;
1099 if Pl.FDummy then Exit;
1101 NetOut.Write(Byte(NET_MSG_PLRPOS));
1102 NetOut.Write(gTime);
1103 NetOut.Write(PID);
1105 kByte := 0;
1107 with Pl do
1108 begin
1109 NetOut.Write(FPing);
1110 NetOut.Write(FLoss);
1111 if IsKeyPressed(KEY_CHAT) then
1112 kByte := NET_KEY_CHAT
1113 else
1114 begin
1115 if IsKeyPressed(KEY_LEFT) then kByte := kByte or NET_KEY_LEFT;
1116 if IsKeyPressed(KEY_RIGHT) then kByte := kByte or NET_KEY_RIGHT;
1117 if IsKeyPressed(KEY_UP) then kByte := kByte or NET_KEY_UP;
1118 if IsKeyPressed(KEY_DOWN) then kByte := kByte or NET_KEY_DOWN;
1119 if IsKeyPressed(KEY_JUMP) then kByte := kByte or NET_KEY_JUMP;
1120 end;
1122 if JustTeleported then kByte := kByte or NET_KEY_FORCEDIR;
1124 NetOut.Write(kByte);
1125 if Direction = TDirection.D_LEFT then NetOut.Write(Byte(0)) else NetOut.Write(Byte(1));
1126 NetOut.Write(GameX);
1127 NetOut.Write(GameY);
1128 NetOut.Write(GameVelX);
1129 NetOut.Write(GameVelY);
1130 NetOut.Write(GameAccelX);
1131 NetOut.Write(GameAccelY);
1132 end;
1134 g_Net_Host_Send(ID, Reliable, NET_CHAN_PLAYERPOS);
1135 end;
1137 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
1138 var
1139 P: TPlayer;
1140 I: Integer;
1141 begin
1142 P := g_Player_Get(PID);
1143 if P = nil then Exit;
1145 NetOut.Write(Byte(NET_MSG_PLRSTA));
1146 NetOut.Write(PID);
1148 with P do
1149 begin
1150 NetOut.Write(Byte(alive));
1151 NetOut.Write(Byte(GodMode));
1152 NetOut.Write(Health);
1153 NetOut.Write(Armor);
1154 NetOut.Write(Air);
1155 NetOut.Write(JetFuel);
1156 NetOut.Write(Lives);
1157 NetOut.Write(Team);
1159 for I := WP_FIRST to WP_LAST do
1160 NetOut.Write(Byte(FWeapon[I]));
1162 for I := A_BULLETS to A_HIGH do
1163 NetOut.Write(FAmmo[I]);
1165 for I := A_BULLETS to A_HIGH do
1166 NetOut.Write(FMaxAmmo[I]);
1168 for I := MR_SUIT to MR_MAX do
1169 NetOut.Write(LongWord(FMegaRulez[I]));
1171 NetOut.Write(Byte(R_ITEM_BACKPACK in FRulez));
1172 NetOut.Write(Byte(R_KEY_RED in FRulez));
1173 NetOut.Write(Byte(R_KEY_GREEN in FRulez));
1174 NetOut.Write(Byte(R_KEY_BLUE in FRulez));
1175 NetOut.Write(Byte(R_BERSERK in FRulez));
1177 NetOut.Write(Frags);
1178 NetOut.Write(Death);
1180 NetOut.Write(CurrWeap);
1182 NetOut.Write(Byte(FSpectator));
1183 NetOut.Write(Byte(FGhost));
1184 NetOut.Write(Byte(FPhysics));
1185 NetOut.Write(Byte(FNoRespawn));
1186 NetOut.Write(Byte(FJetpack));
1187 NetOut.Write(FFireTime);
1188 NetOut.Write(Byte(FFlaming));
1189 NetOut.Write(FSpawnInvul);
1190 end;
1192 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1193 end;
1195 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
1196 begin
1197 NetOut.Write(Byte(NET_MSG_PLRDMG));
1198 NetOut.Write(PID);
1199 NetOut.Write(Kind);
1200 NetOut.Write(Attacker);
1201 NetOut.Write(Value);
1202 NetOut.Write(VX);
1203 NetOut.Write(VY);
1205 g_Net_Host_Send(ID, False, NET_CHAN_PLAYER);
1206 end;
1208 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
1209 begin
1210 NetOut.Write(Byte(NET_MSG_PLRDIE));
1211 NetOut.Write(PID);
1212 NetOut.Write(KillType);
1213 NetOut.Write(DeathType);
1214 NetOut.Write(Attacker);
1216 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1217 end;
1219 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
1220 begin
1221 NetOut.Write(Byte(NET_MSG_PLRFIRE));
1222 NetOut.Write(PID);
1223 NetOut.Write(Weapon);
1224 NetOut.Write(X);
1225 NetOut.Write(Y);
1226 NetOut.Write(AX);
1227 NetOut.Write(AY);
1228 NetOut.Write(ShotID);
1230 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1231 end;
1233 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
1234 begin
1235 NetOut.Write(Byte(NET_MSG_PLRDEL));
1236 NetOut.Write(PID);
1238 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1239 end;
1241 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
1242 var
1243 Pl: TPlayer;
1244 begin
1245 Pl := g_Player_Get(PID);
1246 if Pl = nil then Exit;
1248 NetOut.Write(Byte(NET_MSG_PLRSET));
1249 NetOut.Write(PID);
1250 NetOut.Write(Pl.Name);
1251 if Mdl = '' then
1252 NetOut.Write(Pl.Model.Name)
1253 else
1254 NetOut.Write(Mdl);
1255 NetOut.Write(Pl.FColor.R);
1256 NetOut.Write(Pl.FColor.G);
1257 NetOut.Write(Pl.FColor.B);
1258 NetOut.Write(Pl.Team);
1260 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1261 end;
1263 // ITEM (SEND)
1265 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1266 var
1267 it: PItem;
1268 tt: Byte;
1269 begin
1270 it := g_Items_ByIdx(IID);
1272 NetOut.Write(Byte(NET_MSG_ISPAWN));
1273 NetOut.Write(IID);
1274 NetOut.Write(Byte(Quiet));
1275 tt := it.ItemType;
1276 if it.dropped then tt := tt or $80;
1277 NetOut.Write(tt);
1278 NetOut.Write(Byte(it.Fall));
1279 NetOut.Write(Byte(it.Respawnable));
1280 NetOut.Write(it.Obj.X);
1281 NetOut.Write(it.Obj.Y);
1282 NetOut.Write(it.Obj.Vel.X);
1283 NetOut.Write(it.Obj.Vel.Y);
1285 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1286 end;
1288 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1289 begin
1290 NetOut.Write(Byte(NET_MSG_IDEL));
1291 NetOut.Write(IID);
1292 NetOut.Write(Byte(Quiet));
1294 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1295 end;
1297 // PANEL
1299 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
1300 var
1301 TP: TPanel;
1302 begin
1303 TP := g_Map_PanelByGUID(PGUID);
1304 if (TP = nil) then exit;
1306 with TP do
1307 begin
1308 NetOut.Write(Byte(NET_MSG_PTEX));
1309 NetOut.Write(LongWord(PGUID));
1310 NetOut.Write(FCurTexture);
1311 NetOut.Write(FCurFrame);
1312 NetOut.Write(FCurFrameCount);
1313 NetOut.Write(AnimLoop);
1314 end;
1316 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1317 end;
1319 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
1320 var
1321 TP: TPanel;
1322 mpflags: Byte = 0;
1323 begin
1324 TP := g_Map_PanelByGUID(PGUID);
1325 if (TP = nil) then exit;
1327 NetOut.Write(Byte(NET_MSG_PSTATE));
1328 NetOut.Write(LongWord(PGUID));
1329 NetOut.Write(Byte(TP.Enabled));
1330 NetOut.Write(TP.LiftType);
1331 NetOut.Write(TP.X);
1332 NetOut.Write(TP.Y);
1333 NetOut.Write(Word(TP.Width));
1334 NetOut.Write(Word(TP.Height));
1335 // mplats
1336 NetOut.Write(LongInt(TP.movingSpeedX));
1337 NetOut.Write(LongInt(TP.movingSpeedY));
1338 NetOut.Write(LongInt(TP.movingStartX));
1339 NetOut.Write(LongInt(TP.movingStartY));
1340 NetOut.Write(LongInt(TP.movingEndX));
1341 NetOut.Write(LongInt(TP.movingEndY));
1342 NetOut.Write(LongInt(TP.sizeSpeedX));
1343 NetOut.Write(LongInt(TP.sizeSpeedY));
1344 NetOut.Write(LongInt(TP.sizeEndX));
1345 NetOut.Write(LongInt(TP.sizeEndY));
1346 if TP.movingActive then mpflags := mpflags or 1;
1347 if TP.moveOnce then mpflags := mpflags or 2;
1348 NetOut.Write(Byte(mpflags));
1350 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1351 end;
1353 // TRIGGER
1355 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
1356 begin
1357 if gTriggers = nil then Exit;
1358 if T.Sound = nil then Exit;
1360 NetOut.Write(Byte(NET_MSG_TSOUND));
1361 NetOut.Write(T.ClientID);
1362 NetOut.Write(Byte(T.Sound.IsPlaying));
1363 NetOut.Write(LongWord(T.Sound.GetPosition));
1364 NetOut.Write(T.SoundPlayCount);
1366 g_Net_Host_Send(ID, True);
1367 end;
1369 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
1370 begin
1371 NetOut.Write(Byte(NET_MSG_TMUSIC));
1372 NetOut.Write(gMusic.Name);
1373 NetOut.Write(Byte(gMusic.IsPlaying));
1374 NetOut.Write(LongWord(gMusic.GetPosition));
1375 NetOut.Write(Byte(gMusic.SpecPause or gMusic.IsPaused));
1377 g_Net_Host_Send(ID, True);
1378 end;
1380 // MONSTER
1382 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
1383 var
1384 M: TMonster;
1385 begin
1386 M := g_Monsters_ByUID(UID);
1387 if M = nil then
1388 Exit;
1390 with M do
1391 begin
1392 NetOut.Write(Byte(NET_MSG_MSPAWN));
1393 NetOut.Write(UID);
1394 NetOut.Write(MonsterType);
1395 NetOut.Write(MonsterState);
1396 NetOut.Write(MonsterAnim);
1397 NetOut.Write(MonsterTargetUID);
1398 NetOut.Write(MonsterTargetTime);
1399 NetOut.Write(MonsterBehaviour);
1400 NetOut.Write(MonsterSleep);
1401 NetOut.Write(MonsterHealth);
1402 NetOut.Write(MonsterAmmo);
1403 NetOut.Write(GameX);
1404 NetOut.Write(GameY);
1405 NetOut.Write(GameVelX);
1406 NetOut.Write(GameVelY);
1407 NetOut.Write(Byte(GameDirection));
1408 end;
1410 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1411 end;
1413 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
1414 var
1415 M: TMonster;
1416 begin
1417 M := g_Monsters_ByUID(UID);
1418 if M = nil then Exit;
1420 NetOut.Write(Byte(NET_MSG_MPOS));
1421 NetOut.Write(UID);
1423 with M do
1424 begin
1425 NetOut.Write(GameX);
1426 NetOut.Write(GameY);
1427 NetOut.Write(GameVelX);
1428 NetOut.Write(GameVelY);
1429 NetOut.Write(Byte(GameDirection));
1430 end;
1432 g_Net_Host_Send(ID, False, NET_CHAN_MONSTERPOS);
1433 end;
1435 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
1436 var
1437 M: TMonster;
1438 begin
1439 M := g_Monsters_ByUID(UID);
1440 if M = nil then Exit;
1442 NetOut.Write(Byte(NET_MSG_MSTATE));
1443 NetOut.Write(UID);
1445 with M do
1446 begin
1447 NetOut.Write(MonsterState);
1448 NetOut.Write(ForcedAnim);
1449 NetOut.Write(MonsterTargetUID);
1450 NetOut.Write(MonsterTargetTime);
1451 NetOut.Write(MonsterSleep);
1452 NetOut.Write(MonsterHealth);
1453 NetOut.Write(MonsterAmmo);
1454 NetOut.Write(MonsterPain);
1455 NetOut.Write(Byte(AnimIsReverse));
1456 NetOut.Write(FFireTime);
1457 end;
1459 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1460 end;
1462 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
1463 begin
1464 NetOut.Write(Byte(NET_MSG_MSHOT));
1465 NetOut.Write(UID);
1466 NetOut.Write(X);
1467 NetOut.Write(Y);
1468 NetOut.Write(VX);
1469 NetOut.Write(VY);
1471 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1472 end;
1474 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
1475 var
1476 M: TMonster;
1477 begin
1478 M := g_Monsters_ByUID(UID);
1479 if M = nil then Exit;
1481 NetOut.Write(Byte(NET_MSG_MDEL));
1482 NetOut.Write(UID);
1484 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1485 end;
1487 // MISC
1489 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
1490 begin
1491 NetOut.Write(Byte(NET_MSG_TIME_SYNC));
1492 NetOut.Write(Time);
1494 g_Net_Host_Send(ID, False, NET_CHAN_SERVICE);
1495 end;
1497 procedure MH_SEND_VoteEvent(EvType: Byte;
1498 StrArg1: string = 'a'; StrArg2: string = 'b';
1499 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
1500 ID: Integer = NET_EVERYONE);
1501 begin
1502 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
1503 NetOut.Write(EvType);
1504 NetOut.Write(IntArg1);
1505 NetOut.Write(IntArg2);
1506 NetOut.Write(StrArg1);
1507 NetOut.Write(StrArg2);
1509 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1510 end;
1512 // CLIENT MESSAGES //
1514 // GAME
1516 procedure MC_RECV_Chat(var M: TMsg);
1517 var
1518 Txt: string;
1519 Mode: Byte;
1520 begin
1521 Txt := M.ReadString();
1522 Mode := M.ReadByte();
1524 if Mode <> NET_CHAT_SYSTEM then
1525 begin
1526 if NetDeafLevel = 0 then
1527 begin
1528 if Mode = NET_CHAT_PLAYER then
1529 begin
1530 g_Console_Add(Txt, True);
1531 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1532 g_Game_ChatSound(b_Text_Unformat(Txt));
1533 end else
1534 if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then
1535 begin
1536 if gPlayer1.Team = TEAM_RED then
1537 g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True);
1538 if gPlayer1.Team = TEAM_BLUE then
1539 g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True);
1540 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1541 g_Game_ChatSound(b_Text_Unformat(Txt));
1542 end;
1543 end;
1544 end else if (NetDeafLevel < 2) then
1545 g_Console_Add(Txt, True);
1546 end;
1548 procedure MC_RECV_Effect(var M: TMsg);
1549 var
1550 Kind: Byte;
1551 X, Y: Integer;
1552 Ang: SmallInt;
1553 Anim: TAnimation;
1554 ID: LongWord;
1555 begin
1556 if not gGameOn then Exit;
1557 Kind := M.ReadByte();
1558 X := M.ReadLongInt();
1559 Y := M.ReadLongInt();
1560 Ang := M.ReadSmallInt();
1562 case Kind of
1563 NET_GFX_SPARK:
1564 g_GFX_Spark(X, Y, 2 + Random(2), Ang, 0, 0);
1566 NET_GFX_TELE:
1567 begin
1568 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
1569 begin
1570 Anim := TAnimation.Create(ID, False, 3);
1571 g_GFX_OnceAnim(X, Y, Anim);
1572 Anim.Free();
1573 end;
1574 if Ang = 1 then
1575 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
1576 end;
1578 NET_GFX_EXPLODE:
1579 begin
1580 if g_Frames_Get(ID, 'FRAMES_EXPLODE_ROCKET') then
1581 begin
1582 Anim := TAnimation.Create(ID, False, 6);
1583 Anim.Blending := False;
1584 g_GFX_OnceAnim(X-64, Y-64, Anim);
1585 Anim.Free();
1586 end;
1587 if Ang = 1 then
1588 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X, Y);
1589 end;
1591 NET_GFX_BFGEXPL:
1592 begin
1593 if g_Frames_Get(ID, 'FRAMES_EXPLODE_BFG') then
1594 begin
1595 Anim := TAnimation.Create(ID, False, 6);
1596 Anim.Blending := False;
1597 g_GFX_OnceAnim(X-64, Y-64, Anim);
1598 Anim.Free();
1599 end;
1600 if Ang = 1 then
1601 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X, Y);
1602 end;
1604 NET_GFX_BFGHIT:
1605 begin
1606 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1607 begin
1608 Anim := TAnimation.Create(ID, False, 4);
1609 g_GFX_OnceAnim(X-32, Y-32, Anim);
1610 Anim.Free();
1611 end;
1612 end;
1614 NET_GFX_FIRE:
1615 begin
1616 if g_Frames_Get(ID, 'FRAMES_FIRE') then
1617 begin
1618 Anim := TAnimation.Create(ID, False, 4);
1619 g_GFX_OnceAnim(X, Y, Anim);
1620 Anim.Free();
1621 end;
1622 if Ang = 1 then
1623 g_Sound_PlayExAt('SOUND_FIRE', X, Y);
1624 end;
1626 NET_GFX_RESPAWN:
1627 begin
1628 if g_Frames_Get(ID, 'FRAMES_ITEM_RESPAWN') then
1629 begin
1630 Anim := TAnimation.Create(ID, False, 4);
1631 g_GFX_OnceAnim(X, Y, Anim);
1632 Anim.Free();
1633 end;
1634 if Ang = 1 then
1635 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
1636 end;
1638 NET_GFX_SHELL1:
1639 g_Player_CreateShell(X, Y, 0, -2, SHELL_BULLET);
1641 NET_GFX_SHELL2:
1642 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1644 NET_GFX_SHELL3:
1645 begin
1646 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1647 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1648 end;
1649 end;
1650 end;
1652 procedure MC_RECV_Sound(var M: TMsg);
1653 var
1654 Name: string;
1655 X, Y: Integer;
1656 Pos: Boolean;
1657 begin
1658 Name := M.ReadString();
1659 Pos := M.ReadByte() <> 0;
1660 if Pos then
1661 begin
1662 X := M.ReadLongInt();
1663 Y := M.ReadLongInt();
1664 g_Sound_PlayExAt(Name, X, Y);
1665 end
1666 else
1667 g_Sound_PlayEx(Name);
1668 end;
1670 procedure MC_RECV_CreateShot(var M: TMsg);
1671 var
1672 I, X, Y, XV, YV: Integer;
1673 Timeout: LongWord;
1674 Target, Spawner: Word;
1675 ShType: Byte;
1676 begin
1677 I := M.ReadLongInt();
1678 ShType := M.ReadByte();
1679 Target := M.ReadWord();
1680 Spawner := M.ReadWord();
1681 Timeout := M.ReadLongWord();
1682 X := M.ReadLongInt();
1683 Y := M.ReadLongInt();
1684 XV := M.ReadLongInt();
1685 YV := M.ReadLongInt();
1687 I := g_Weapon_CreateShot(I, ShType, Spawner, Target, X, Y, XV, YV);
1688 if (Shots <> nil) and (I <= High(Shots)) then
1689 begin
1690 Shots[I].Timeout := Timeout;
1691 //Shots[I].Target := Target; // TODO: find a use for Target later
1692 end;
1693 end;
1695 procedure MC_RECV_UpdateShot(var M: TMsg);
1696 var
1697 I, TX, TY, TXV, TYV: Integer;
1698 begin
1699 I := M.ReadLongInt();
1700 TX := M.ReadLongInt();
1701 TY := M.ReadLongInt();
1702 TXV := M.ReadLongInt();
1703 TYV := M.ReadLongInt();
1705 if (Shots <> nil) and (I <= High(Shots)) then
1706 with (Shots[i]) do
1707 begin
1708 Obj.X := TX;
1709 Obj.Y := TY;
1710 Obj.Vel.X := TXV;
1711 Obj.Vel.Y := TYV;
1712 end;
1713 end;
1715 procedure MC_RECV_DeleteShot(var M: TMsg);
1716 var
1717 I, X, Y: Integer;
1718 L: Boolean;
1719 begin
1720 if not gGameOn then Exit;
1721 I := M.ReadLongInt();
1722 L := (M.ReadByte() <> 0);
1723 X := M.ReadLongInt();
1724 Y := M.ReadLongInt();
1726 g_Weapon_DestroyShot(I, X, Y, L);
1727 end;
1729 procedure MC_RECV_GameStats(var M: TMsg);
1730 begin
1731 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1732 begin
1733 gTeamStat[TEAM_RED].Goals := M.ReadSmallInt();
1734 gTeamStat[TEAM_BLUE].Goals := M.ReadSmallInt();
1735 end
1736 else
1737 if gGameSettings.GameMode = GM_COOP then
1738 begin
1739 gCoopMonstersKilled := M.ReadWord();
1740 gCoopSecretsFound := M.ReadWord();
1741 end;
1742 end;
1744 procedure MC_RECV_CoopStats(var M: TMsg);
1745 begin
1746 gTotalMonsters := M.ReadLongInt();
1747 gSecretsCount := M.ReadLongInt();
1748 gCoopTotalMonstersKilled := M.ReadWord();
1749 gCoopTotalSecretsFound := M.ReadWord();
1750 gCoopTotalMonsters := M.ReadWord();
1751 gCoopTotalSecrets := M.ReadWord();
1752 end;
1754 procedure MC_RECV_GameEvent(var M: TMsg);
1755 var
1756 EvType: Byte;
1757 EvNum: Integer;
1758 EvStr: string;
1759 EvTime: LongWord;
1760 BHash: Boolean;
1761 EvHash: TMD5Digest;
1762 pl: TPlayer;
1763 i1, i2: TStrings_Locale;
1764 pln: String;
1765 cnt: Byte;
1766 goodCmd: Boolean = true;
1767 begin
1768 FillChar(EvHash, Sizeof(EvHash), 0);
1769 EvType := M.ReadByte();
1770 EvNum := M.ReadLongInt();
1771 EvStr := M.ReadString();
1772 gLastMap := M.ReadByte() <> 0;
1773 if gLastMap and (gGameSettings.GameMode = GM_COOP) then gStatsOff := True;
1774 gStatsPressed := True;
1775 EvTime := M.ReadLongWord();
1776 BHash := M.ReadByte() <> 0;
1777 if BHash then
1778 EvHash := M.ReadMD5();
1780 gTime := EvTime;
1782 if (g_Res_received_map_start <> 0) then
1783 begin
1784 if (g_Res_received_map_start < 0) then exit;
1785 goodCmd := false;
1786 case EvType of
1787 NET_EV_MAPSTART: goodCmd := true;
1788 NET_EV_MAPEND: goodCmd := true;
1789 NET_EV_PLAYER_KICK: goodCmd := true;
1790 NET_EV_PLAYER_BAN: goodCmd := true;
1791 NET_EV_LMS_WARMUP: goodCmd := true;
1792 end;
1793 if not goodCmd then exit;
1794 end;
1796 case EvType of
1797 NET_EV_MAPSTART:
1798 begin
1799 if (g_Res_received_map_start <> 0) then
1800 begin
1801 g_Res_received_map_start := -1;
1802 end
1803 else
1804 begin
1805 gGameOn := False;
1806 g_Game_ClearLoading();
1807 g_Game_StopAllSounds(True);
1809 gSwitchGameMode := Byte(EvNum);
1810 gGameSettings.GameMode := gSwitchGameMode;
1812 gWADHash := EvHash;
1813 if not g_Game_StartMap(false{asMegawad}, EvStr, True) then
1814 begin
1815 if not isWadPath(EvStr) then
1816 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + EvStr]))
1817 else
1818 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [EvStr]));
1819 Exit;
1820 end;
1822 MC_SEND_FullStateRequest;
1823 end;
1824 end;
1826 NET_EV_MAPEND:
1827 begin
1828 gLMSRespawn := LMS_RESPAWN_NONE;
1829 gLMSRespawnTime := 0;
1830 if (g_Res_received_map_start <> 0) then
1831 begin
1832 g_Res_received_map_start := -1;
1833 end
1834 else
1835 begin
1836 gMissionFailed := EvNum <> 0;
1837 gExit := EXIT_ENDLEVELCUSTOM;
1838 end;
1839 end;
1841 NET_EV_RCON:
1842 begin
1843 case EvNum of
1844 NET_RCON_NOAUTH:
1845 g_Console_Add(_lc[I_NET_RCON_NOAUTH], True);
1846 NET_RCON_PWGOOD:
1847 g_Console_Add(_lc[I_NET_RCON_PWD_VALID], True);
1848 NET_RCON_PWBAD:
1849 g_Console_Add(_lc[I_NET_RCON_PWD_INVALID], True);
1850 end;
1851 end;
1853 NET_EV_CHANGE_TEAM:
1854 begin
1855 if NetDeafLevel < 2 then
1856 begin
1857 if EvNum = TEAM_RED then
1858 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True);
1859 if EvNum = TEAM_BLUE then
1860 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True);
1861 end;
1862 end;
1864 NET_EV_PLAYER_KICK:
1865 begin
1866 g_Console_Add(Format(_lc[I_PLAYER_KICK], [EvStr]), True);
1867 if (g_Res_received_map_start <> 0) then g_Res_received_map_start := -1;
1868 end;
1870 NET_EV_PLAYER_BAN:
1871 begin
1872 g_Console_Add(Format(_lc[I_PLAYER_BAN], [EvStr]), True);
1873 if (g_Res_received_map_start <> 0) then g_Res_received_map_start := -1;
1874 end;
1876 NET_EV_LMS_WARMUP:
1877 begin
1878 if EvNum > 0 then
1879 begin
1880 gLMSRespawn := LMS_RESPAWN_WARMUP;
1881 gLMSRespawnTime := gTime + EvNum;
1882 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [EvNum div 1000]), True);
1883 end
1884 else if gPlayer1 = nil then
1885 begin
1886 g_Console_Add(_lc[I_PLAYER_SPECT4], True);
1887 end;
1888 end;
1890 NET_EV_LMS_SURVIVOR:
1891 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True);
1893 NET_EV_BIGTEXT:
1894 if NetDeafLevel < 2 then g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum));
1896 NET_EV_SCORE:
1897 begin
1898 pl := g_Player_Get(EvNum and $FFFF);
1899 if pl = nil then
1900 pln := '?'
1901 else
1902 pln := pl.Name;
1903 cnt := (EvNum shr 16) and $FF;
1904 if Pos('w', EvStr) = 0 then
1905 begin
1906 // Default score
1907 if Pos('t', EvStr) = 0 then
1908 begin
1909 // Player +/- score
1910 if Pos('-', EvStr) = 0 then
1911 begin
1912 if Pos('e', EvStr) = 0 then
1913 i1 := I_PLAYER_SCORE_ADD_OWN
1914 else
1915 i1 := I_PLAYER_SCORE_ADD_ENEMY;
1916 end else
1917 begin
1918 if Pos('e', EvStr) = 0 then
1919 i1 := I_PLAYER_SCORE_SUB_OWN
1920 else
1921 i1 := I_PLAYER_SCORE_SUB_ENEMY;
1922 end;
1923 // Which team
1924 if Pos('r', EvStr) > 0 then
1925 i2 := I_PLAYER_SCORE_TO_RED
1926 else
1927 i2 := I_PLAYER_SCORE_TO_BLUE;
1928 g_Console_Add(Format(_lc[i1], [pln, cnt, _lc[i2]]), True);
1929 end else
1930 begin
1931 // Team +/- score
1932 if Pos('-', EvStr) = 0 then
1933 i1 := I_PLAYER_SCORE_ADD_TEAM
1934 else
1935 i1 := I_PLAYER_SCORE_SUB_TEAM;
1936 // Which team
1937 if Pos('r', EvStr) > 0 then
1938 i2 := I_PLAYER_SCORE_RED
1939 else
1940 i2 := I_PLAYER_SCORE_BLUE;
1941 g_Console_Add(Format(_lc[i1], [_lc[i2], cnt]), True);
1942 end;
1943 end else
1944 begin
1945 // Game Win
1946 if Pos('e', EvStr) = 0 then
1947 i1 := I_PLAYER_SCORE_WIN_OWN
1948 else
1949 i1 := I_PLAYER_SCORE_WIN_ENEMY;
1950 // Which team
1951 if Pos('r', EvStr) > 0 then
1952 i2 := I_PLAYER_SCORE_TO_RED
1953 else
1954 i2 := I_PLAYER_SCORE_TO_BLUE;
1955 g_Console_Add(Format(_lc[i1], [pln, _lc[i2]]), True);
1956 end;
1957 end;
1959 NET_EV_SCORE_MSG:
1960 begin
1961 if EvNum = TEAM_RED then
1962 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1963 if EvNum = TEAM_BLUE then
1964 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1965 if EvNum = -TEAM_RED then
1966 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1967 if EvNum = -TEAM_BLUE then
1968 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1969 end;
1971 NET_EV_LMS_START:
1972 begin
1973 g_Player_RemoveAllCorpses;
1974 gLMSRespawn := LMS_RESPAWN_NONE;
1975 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
1976 end;
1978 NET_EV_LMS_WIN:
1979 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(EvStr)]), 144);
1981 NET_EV_TLMS_WIN:
1982 begin
1983 if EvNum = TEAM_RED then
1984 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
1985 if EvNum = TEAM_BLUE then
1986 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
1987 end;
1989 NET_EV_LMS_LOSE:
1990 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
1992 NET_EV_LMS_DRAW:
1993 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
1995 NET_EV_LMS_NOSPAWN:
1996 g_Console_Add(_lc[I_PLAYER_SPECT4], True);
1998 NET_EV_KILLCOMBO:
1999 g_Game_Announce_KillCombo(EvNum);
2001 NET_EV_PLAYER_TOUCH:
2002 begin
2003 pl := g_Player_Get(EvNum);
2004 if pl <> nil then
2005 pl.Touch();
2006 end;
2008 NET_EV_SECRET:
2009 begin
2010 pl := g_Player_Get(EvNum);
2011 if pl <> nil then
2012 begin
2013 g_Console_Add(Format(_lc[I_PLAYER_SECRET], [pl.Name]), True);
2014 g_Sound_PlayEx('SOUND_GAME_SECRET');
2015 end;
2016 end;
2018 NET_EV_INTER_READY:
2019 begin
2020 pl := g_Player_Get(EvNum);
2021 if pl <> nil then pl.FReady := (EvStr = 'Y');
2022 end;
2023 end;
2024 end;
2026 procedure MC_RECV_FlagEvent(var M: TMsg);
2027 var
2028 PID: Word;
2029 Pl: TPlayer;
2030 EvType: Byte;
2031 Fl, a: Byte;
2032 Quiet: Boolean;
2033 s, ts: string;
2034 begin
2035 EvType := M.ReadByte();
2036 Fl := M.ReadByte();
2038 if Fl = FLAG_NONE then Exit;
2040 Quiet := (M.ReadByte() <> 0);
2041 PID := M.ReadWord();
2043 gFlags[Fl].State := M.ReadByte();
2044 gFlags[Fl].CaptureTime := M.ReadLongWord();
2045 gFlags[Fl].Obj.X := M.ReadLongInt();
2046 gFlags[Fl].Obj.Y := M.ReadLongInt();
2047 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
2048 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
2050 Pl := g_Player_Get(PID);
2051 if (Pl = nil) and
2052 (EvType <> FLAG_STATE_NORMAL) and
2053 (EvType <> FLAG_STATE_DROPPED) and
2054 (EvType <> FLAG_STATE_RETURNED) then
2055 Exit;
2057 case EvType of
2058 FLAG_STATE_NORMAL:
2059 begin
2060 if Quiet or (Pl = nil) then Exit;
2062 if Fl = FLAG_RED then
2063 s := _lc[I_PLAYER_FLAG_RED]
2064 else
2065 s := _lc[I_PLAYER_FLAG_BLUE];
2067 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2069 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2070 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2071 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2072 a := 0
2073 else
2074 a := 1;
2076 if not sound_ret_flag[a].IsPlaying() then
2077 sound_ret_flag[a].Play();
2078 end;
2080 FLAG_STATE_CAPTURED:
2081 begin
2082 if (Pl <> nil) then Pl.SetFlag(Fl);
2084 if Quiet then Exit;
2086 if Fl = FLAG_RED then
2087 s := _lc[I_PLAYER_FLAG_RED]
2088 else
2089 s := _lc[I_PLAYER_FLAG_BLUE];
2091 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [Pl.Name, s]), True);
2092 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
2094 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2095 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2096 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2097 a := 0
2098 else
2099 a := 1;
2101 if not sound_get_flag[a].IsPlaying() then
2102 sound_get_flag[a].Play();
2103 end;
2105 FLAG_STATE_DROPPED:
2106 begin
2107 if (Pl <> nil) then Pl.SetFlag(FLAG_NONE);
2109 if Quiet or (Pl = nil) then Exit;
2111 if Fl = FLAG_RED then
2112 s := _lc[I_PLAYER_FLAG_RED]
2113 else
2114 s := _lc[I_PLAYER_FLAG_BLUE];
2116 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [Pl.Name, s]), True);
2117 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
2119 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2120 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2121 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2122 a := 0
2123 else
2124 a := 1;
2126 if not sound_lost_flag[a].IsPlaying() then
2127 sound_lost_flag[a].Play();
2128 end;
2130 FLAG_STATE_SCORED:
2131 begin
2132 g_Map_ResetFlag(FLAG_RED);
2133 g_Map_ResetFlag(FLAG_BLUE);
2134 if Quiet or (Pl = nil) then Exit;
2135 Pl.SetFlag(FLAG_NONE);
2137 if Fl = FLAG_RED then
2138 s := _lc[I_PLAYER_FLAG_RED]
2139 else
2140 s := _lc[I_PLAYER_FLAG_BLUE];
2142 ts := Format('%.4d', [gFlags[Fl].CaptureTime]);
2143 Insert('.', ts, Length(ts) + 1 - 3);
2144 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [Pl.Name, s, ts]), True);
2145 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
2147 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2148 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2149 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2150 a := 0
2151 else
2152 a := 1;
2154 if not sound_cap_flag[a].IsPlaying() then
2155 sound_cap_flag[a].Play();
2156 end;
2158 FLAG_STATE_RETURNED:
2159 begin
2160 g_Map_ResetFlag(Fl);
2161 if Quiet then Exit;
2163 if Fl = FLAG_RED then
2164 s := _lc[I_PLAYER_FLAG_RED]
2165 else
2166 s := _lc[I_PLAYER_FLAG_BLUE];
2168 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2170 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2171 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2172 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2173 a := 0
2174 else
2175 a := 1;
2177 if not sound_ret_flag[a].IsPlaying() then
2178 sound_ret_flag[a].Play();
2179 end;
2180 end;
2181 end;
2183 procedure MC_RECV_GameSettings(var M: TMsg);
2184 begin
2185 gGameSettings.GameMode := M.ReadByte();
2186 gGameSettings.GoalLimit := M.ReadWord();
2187 gGameSettings.TimeLimit := M.ReadWord();
2188 gGameSettings.MaxLives := M.ReadByte();
2189 gGameSettings.Options := M.ReadLongWord();
2190 end;
2192 // PLAYER
2194 function MC_RECV_PlayerCreate(var M: TMsg): Word;
2195 var
2196 PID, DID: Word;
2197 PName, Model: string;
2198 Color: TRGB;
2199 T: Byte;
2200 Pl: TPlayer;
2201 begin
2202 PID := M.ReadWord();
2203 Pl := g_Player_Get(PID);
2205 PName := M.ReadString();
2206 Model := M.ReadString();
2207 Color.R := M.ReadByte();
2208 Color.G := M.ReadByte();
2209 Color.B := M.ReadByte();
2210 T := M.ReadByte();
2212 Result := 0;
2213 if (PID <> NetPlrUID1) and (PID <> NetPlrUID2) then
2214 begin
2215 if (Pl <> nil) then Exit;
2216 DID := g_Player_Create(Model, Color, T, False);
2217 with g_Player_Get(DID) do
2218 begin
2219 UID := PID;
2220 Name := PName;
2221 Reset(True);
2222 end;
2223 end
2224 else
2225 begin
2226 if (PID = NetPlrUID1) and (gPlayer1 <> nil) then begin
2227 gPlayer1.UID := PID;
2228 gPlayer1.Model.SetColor(Color.R, Color.G, Color.B);
2229 gPlayer1.ChangeTeam(T);
2230 end;
2231 if (PID = NetPlrUID2) and (gPlayer2 <> nil) then begin
2232 gPlayer2.UID := PID;
2233 gPlayer2.Model.SetColor(Color.R, Color.G, Color.B);
2234 gPlayer2.ChangeTeam(T);
2235 end;
2236 end;
2238 if NetDeafLevel < 3 then
2239 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
2240 e_WriteLog('NET: Player ' + PName + ' [' + IntToStr(PID) + '] added.', TMsgType.Notify);
2241 Result := PID;
2242 end;
2244 function MC_RECV_PlayerPos(var M: TMsg): Word;
2245 var
2246 GT: LongWord;
2247 PID: Word;
2248 kByte: Word;
2249 Pl: TPlayer;
2250 Dir: Byte;
2251 TmpX, TmpY: Integer;
2252 begin
2253 Result := 0;
2255 GT := M.ReadLongWord();
2256 if GT < gTime - NET_MAX_DIFFTIME then
2257 begin
2258 gTime := GT;
2259 Exit;
2260 end;
2261 gTime := GT;
2263 PID := M.ReadWord();
2264 Pl := g_Player_Get(PID);
2266 if Pl = nil then Exit;
2268 Result := PID;
2270 with Pl do
2271 begin
2272 FPing := M.ReadWord();
2273 FLoss := M.ReadByte();
2274 kByte := M.ReadWord();
2275 Dir := M.ReadByte();
2277 TmpX := M.ReadLongInt();
2278 TmpY := M.ReadLongInt();
2280 ReleaseKeys;
2282 if LongBool(kByte and NET_KEY_CHAT) then
2283 PressKey(KEY_CHAT, 10000)
2284 else
2285 begin
2286 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
2287 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
2288 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
2289 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
2290 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
2291 end;
2293 JustTeleported := LongBool(kByte and NET_KEY_FORCEDIR);
2295 if ((Pl <> gPlayer1) and (Pl <> gPlayer2)) or JustTeleported then
2296 SetDirection(TDirection(Dir));
2298 GameVelX := M.ReadLongInt();
2299 GameVelY := M.ReadLongInt();
2300 GameAccelX := M.ReadLongInt();
2301 GameAccelY := M.ReadLongInt();
2302 SetLerp(TmpX, TmpY);
2303 if NetForcePlayerUpdate then Update();
2304 end;
2305 end;
2307 function MC_RECV_PlayerStats(var M: TMsg): Word;
2308 var
2309 PID: Word;
2310 Pl: TPlayer;
2311 I, OldFire: Integer;
2312 OldJet, Flam: Boolean;
2313 NewTeam: Byte;
2314 begin
2315 PID := M.ReadWord();
2316 Pl := g_Player_Get(PID);
2317 Result := 0;
2318 if Pl = nil then
2319 Exit;
2321 with Pl do
2322 begin
2323 alive := (M.ReadByte() <> 0);
2324 GodMode := (M.ReadByte() <> 0);
2325 Health := M.ReadLongInt();
2326 Armor := M.ReadLongInt();
2327 Air := M.ReadLongInt();
2328 JetFuel := M.ReadLongInt();
2329 Lives := M.ReadByte();
2330 NewTeam := M.ReadByte();
2332 for I := WP_FIRST to WP_LAST do
2333 FWeapon[I] := (M.ReadByte() <> 0);
2335 for I := A_BULLETS to A_HIGH do
2336 FAmmo[I] := M.ReadWord();
2338 for I := A_BULLETS to A_HIGH do
2339 FMaxAmmo[I] := M.ReadWord();
2341 for I := MR_SUIT to MR_MAX do
2342 FMegaRulez[I] := M.ReadLongWord();
2344 FRulez := [];
2345 if (M.ReadByte() <> 0) then
2346 FRulez := FRulez + [R_ITEM_BACKPACK];
2347 if (M.ReadByte() <> 0) then
2348 FRulez := FRulez + [R_KEY_RED];
2349 if (M.ReadByte() <> 0) then
2350 FRulez := FRulez + [R_KEY_GREEN];
2351 if (M.ReadByte() <> 0) then
2352 FRulez := FRulez + [R_KEY_BLUE];
2353 if (M.ReadByte() <> 0) then
2354 FRulez := FRulez + [R_BERSERK];
2356 Frags := M.ReadLongInt();
2357 Death := M.ReadLongInt();
2359 SetWeapon(M.ReadByte());
2361 FSpectator := M.ReadByte() <> 0;
2362 if FSpectator then
2363 begin
2364 if UID = NetPlrUID1 then
2365 begin
2366 gSpectLatchPID1 := UID;
2367 gPlayer1 := nil;
2368 end;
2369 if UID = NetPlrUID2 then
2370 begin
2371 gSpectLatchPID2 := UID;
2372 gPlayer2 := nil;
2373 end;
2374 end
2375 else
2376 begin
2377 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) and (UID = gSpectLatchPID1) then
2378 begin
2379 gPlayer1 := Pl;
2380 gSpectLatchPID1 := 0;
2381 end;
2382 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) and (UID = gSpectLatchPID2) then
2383 begin
2384 gPlayer2 := Pl;
2385 gSpectLatchPID2 := 0;
2386 end;
2387 end;
2388 FGhost := M.ReadByte() <> 0;
2389 FPhysics := M.ReadByte() <> 0;
2390 FNoRespawn := M.ReadByte() <> 0;
2391 OldJet := FJetpack;
2392 FJetpack := M.ReadByte() <> 0;
2393 OldFire := FFireTime;
2394 FFireTime := M.ReadLongInt();
2395 if (OldFire <= 0) and (FFireTime > 0) then
2396 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
2397 Flam := M.ReadByte() <> 0;
2398 FSpawnInvul := M.ReadLongInt();
2399 if OldJet and not FJetpack then
2400 JetpackOff
2401 else if not OldJet and FJetpack then
2402 JetpackOn;
2403 if FFlaming and not Flam then
2404 FlamerOff;
2405 if Team <> NewTeam then
2406 Pl.ChangeTeam(NewTeam);
2407 end;
2409 Result := PID;
2410 end;
2412 function MC_RECV_PlayerDamage(var M: TMsg): Word;
2413 var
2414 PID: Word;
2415 Pl: TPlayer;
2416 Kind: Byte;
2417 Attacker, Value: Word;
2418 VX, VY: Integer;
2419 begin
2420 Result := 0;
2421 if not gGameOn then Exit;
2422 PID := M.ReadWord();
2423 Pl := g_Player_Get(PID);
2424 if Pl = nil then Exit;
2426 Kind := M.ReadByte();
2427 Attacker := M.ReadWord();
2428 Value := M.ReadWord();
2429 VX := M.ReadWord();
2430 VY := M.ReadWord();
2432 with Pl do
2433 Damage(Value, Attacker, VX, VY, Kind);
2435 Result := PID;
2436 end;
2438 function MC_RECV_PlayerDeath(var M: TMsg): Word;
2439 var
2440 PID: Word;
2441 Pl: TPlayer;
2442 KillType, DeathType: Byte;
2443 Attacker: Word;
2444 begin
2445 Result := 0;
2446 if not gGameOn then Exit;
2447 PID := M.ReadWord();
2448 Pl := g_Player_Get(PID);
2449 if Pl = nil then Exit;
2451 KillType := M.ReadByte();
2452 DeathType := M.ReadByte();
2453 Attacker := M.ReadWord();
2455 with Pl do
2456 begin
2457 Kill(KillType, Attacker, DeathType);
2458 SoftReset;
2459 end;
2460 end;
2462 function MC_RECV_PlayerDelete(var M: TMsg): Word;
2463 var
2464 PID: Word;
2465 Pl: TPlayer;
2466 begin
2467 PID := M.ReadWord();
2468 Pl := g_Player_Get(PID);
2469 Result := 0;
2470 if Pl = nil then Exit;
2472 if NetDeafLevel < 3 then
2473 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2474 e_WriteLog('NET: Player ' + Pl.Name + ' [' + IntToStr(PID) + '] removed.', TMsgType.Notify);
2476 g_Player_Remove(PID);
2478 Result := PID;
2479 end;
2481 function MC_RECV_PlayerFire(var M: TMsg): Word;
2482 var
2483 PID: Word;
2484 Weap: Byte;
2485 Pl: TPlayer;
2486 X, Y, AX, AY: Integer;
2487 SHID: Integer;
2488 begin
2489 Result := 0;
2490 if not gGameOn then Exit;
2491 PID := M.ReadWord();
2492 Pl := g_Player_Get(PID);
2493 if Pl = nil then Exit;
2495 Weap := M.ReadByte();
2496 X := M.ReadLongInt();
2497 Y := M.ReadLongInt();
2498 AX := M.ReadLongInt();
2499 AY := M.ReadLongInt();
2500 SHID := M.ReadLongInt();
2502 with Pl do
2503 if alive then NetFire(Weap, X, Y, AX, AY, SHID);
2504 end;
2506 procedure MC_RECV_PlayerSettings(var M: TMsg);
2507 var
2508 TmpName: string;
2509 TmpModel: string;
2510 TmpColor: TRGB;
2511 TmpTeam: Byte;
2512 Pl: TPlayer;
2513 PID: Word;
2514 begin
2515 PID := M.ReadWord();
2516 Pl := g_Player_Get(PID);
2517 if Pl = nil then Exit;
2519 TmpName := M.ReadString();
2520 TmpModel := M.ReadString();
2521 TmpColor.R := M.ReadByte();
2522 TmpColor.G := M.ReadByte();
2523 TmpColor.B := M.ReadByte();
2524 TmpTeam := M.ReadByte();
2526 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
2527 begin
2528 Pl.ChangeTeam(TmpTeam);
2529 if gPlayer1 = Pl then
2530 gPlayer1Settings.Team := TmpTeam;
2531 if gPlayer2 = Pl then
2532 gPlayer2Settings.Team := TmpTeam;
2533 end else
2534 Pl.SetColor(TmpColor);
2536 if Pl.Name <> TmpName then
2537 begin
2538 if NetDeafLevel < 3 then
2539 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
2540 Pl.Name := TmpName;
2541 end;
2543 if TmpModel <> Pl.Model.Name then
2544 Pl.SetModel(TmpModel);
2545 end;
2547 // ITEM
2549 procedure MC_RECV_ItemSpawn(var M: TMsg);
2550 var
2551 ID: Word;
2552 AID: DWord;
2553 X, Y, VX, VY: Integer;
2554 T: Byte;
2555 Quiet, Fall{, Resp}: Boolean;
2556 Anim: TAnimation;
2557 it: PItem;
2558 begin
2559 if not gGameOn then Exit;
2560 ID := M.ReadWord();
2561 Quiet := M.ReadByte() <> 0;
2562 T := M.ReadByte();
2563 Fall := M.ReadByte() <> 0;
2564 {Resp :=} M.ReadByte();
2565 X := M.ReadLongInt();
2566 Y := M.ReadLongInt();
2567 VX := M.ReadLongInt();
2568 VY := M.ReadLongInt();
2570 g_Items_Create(X, Y, T and $7F, Fall, False, False, ID);
2571 if ((T and $80) <> 0) then g_Items_SetDrop(ID);
2573 it := g_Items_ByIdx(ID);
2574 it.Obj.Vel.X := VX;
2575 it.Obj.Vel.Y := VY;
2577 if not Quiet then
2578 begin
2579 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
2580 if g_Frames_Get(AID, 'FRAMES_ITEM_RESPAWN') then
2581 begin
2582 Anim := TAnimation.Create(AID, False, 4);
2583 g_GFX_OnceAnim(X+(it.Obj.Rect.Width div 2)-16, Y+(it.Obj.Rect.Height div 2)-16, Anim);
2584 Anim.Free();
2585 end;
2586 end;
2587 end;
2589 procedure MC_RECV_ItemDestroy(var M: TMsg);
2590 var
2591 ID: Word;
2592 Quiet: Boolean;
2593 begin
2594 if not gGameOn then Exit;
2595 ID := M.ReadWord();
2596 Quiet := M.ReadByte() <> 0;
2598 if not g_Items_ValidId(ID) then exit;
2600 if not Quiet then g_Items_EmitPickupSound(ID);
2602 g_Items_Remove(ID);
2603 end;
2605 // PANEL
2607 procedure MC_RECV_PanelTexture(var M: TMsg);
2608 var
2609 TP: TPanel;
2610 PGUID: Integer;
2611 Tex, Fr: Integer;
2612 Loop, Cnt: Byte;
2613 begin
2614 if not gGameOn then Exit;
2616 PGUID := Integer(M.ReadLongWord());
2617 Tex := M.ReadLongInt();
2618 Fr := M.ReadLongInt();
2619 Cnt := M.ReadByte();
2620 Loop := M.ReadByte();
2622 TP := g_Map_PanelByGUID(PGUID);
2623 if (TP <> nil) then
2624 begin
2625 // switch texture
2626 TP.SetTexture(Tex, Loop);
2627 TP.SetFrame(Fr, Cnt);
2628 end;
2629 end;
2631 procedure MC_RECV_PanelState(var M: TMsg);
2632 var
2633 PGUID: Integer;
2634 E: Boolean;
2635 Lift: Byte;
2636 X, Y, W, H: Integer;
2637 TP: TPanel;
2638 speedX, speedY, startX, startY, endX, endY: Integer;
2639 sizeSpX, sizeSpY, sizeEX, sizeEY: Integer;
2640 mpflags: Byte;
2641 begin
2642 if not gGameOn then Exit;
2644 PGUID := Integer(M.ReadLongWord());
2645 E := (M.ReadByte() <> 0);
2646 Lift := M.ReadByte();
2647 X := M.ReadLongInt();
2648 Y := M.ReadLongInt();
2649 W := M.ReadWord();
2650 H := M.ReadWord();
2651 // mplats
2652 speedX := M.ReadLongInt();
2653 speedY := M.ReadLongInt();
2654 startX := M.ReadLongInt();
2655 startY := M.ReadLongInt();
2656 endX := M.ReadLongInt();
2657 endY := M.ReadLongInt();
2658 sizeSpX := M.ReadLongInt();
2659 sizeSpY := M.ReadLongInt();
2660 sizeEX := M.ReadLongInt();
2661 sizeEY := M.ReadLongInt();
2662 mpflags := M.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2664 TP := g_Map_PanelByGUID(PGUID);
2665 if (TP = nil) then exit;
2667 // update lifts state
2668 if TP.isGLift then g_Map_SetLiftGUID(PGUID, Lift);
2670 // update enabled/disabled state for all panels
2671 if E then g_Map_EnableWallGUID(PGUID) else g_Map_DisableWallGUID(PGUID);
2673 // update panel position, as it can be moved (mplat)
2674 TP.X := X;
2675 TP.Y := Y;
2676 TP.Width := W;
2677 TP.Height := H;
2678 // update mplat state
2679 TP.movingSpeedX := speedX;
2680 TP.movingSpeedY := speedY;
2681 TP.movingStartX := startX;
2682 TP.movingStartY := startY;
2683 TP.movingEndX := endX;
2684 TP.movingEndY := endY;
2685 TP.sizeSpeedX := sizeSpX;
2686 TP.sizeSpeedY := sizeSpY;
2687 TP.sizeEndX := sizeEX;
2688 TP.sizeEndY := sizeEY;
2689 TP.movingActive := ((mpflags and 1) <> 0);
2690 TP.moveOnce := ((mpflags and 2) <> 0);
2691 // notify panel of it's position/size change, so it can fix other internal structures
2692 TP.positionChanged();
2693 end;
2695 // TRIGGERS
2697 procedure MC_RECV_TriggerSound(var M: TMsg);
2698 var
2699 SPlaying: Boolean;
2700 SPos, SID: LongWord;
2701 SCount: LongInt;
2702 I: Integer;
2703 begin
2704 if not gGameOn then Exit;
2705 if gTriggers = nil then Exit;
2707 SID := M.ReadLongWord();
2708 SPlaying := M.ReadByte() <> 0;
2709 SPos := M.ReadLongWord();
2710 SCount := M.ReadLongInt();
2712 for I := Low(gTriggers) to High(gTriggers) do
2713 if gTriggers[I].TriggerType = TRIGGER_SOUND then
2714 if gTriggers[I].ClientID = SID then
2715 with gTriggers[I] do
2716 begin
2717 if Sound <> nil then
2718 begin
2719 if SPlaying then
2720 begin
2721 if tgcLocal then
2722 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), tgcVolume/255.0)
2723 else
2724 Sound.PlayPanVolume((tgcPan-127.0)/128.0, tgcVolume/255.0);
2725 Sound.SetPosition(SPos);
2726 end
2727 else
2728 if Sound.IsPlaying then Sound.Stop;
2729 end;
2731 SoundPlayCount := SCount;
2732 end;
2733 end;
2735 procedure MC_RECV_TriggerMusic(var M: TMsg);
2736 var
2737 MName: string;
2738 MPlaying: Boolean;
2739 MPos: LongWord;
2740 MPaused: Boolean;
2741 begin
2742 if not gGameOn then Exit;
2744 MName := M.ReadString();
2745 MPlaying := M.ReadByte() <> 0;
2746 MPos := M.ReadLongWord();
2747 MPaused := M.ReadByte() <> 0;
2748 MPos := MPos+1; //k8: stfu, fpc!
2750 if MPlaying then
2751 begin
2752 gMusic.SetByName(MName);
2753 gMusic.Play(True);
2754 // gMusic.SetPosition(MPos);
2755 gMusic.SpecPause := MPaused;
2756 end
2757 else
2758 if gMusic.IsPlaying then gMusic.Stop;
2759 end;
2761 // MONSTERS
2763 procedure MC_RECV_MonsterSpawn(var M: TMsg);
2764 var
2765 ID: Word;
2766 MType, MState, MDir, MAnim, MBehav: Byte;
2767 X, Y, VX, VY, MTargTime, MHealth, MAmmo, MSleep: Integer;
2768 MTarg: Word;
2769 Mon: TMonster;
2770 begin
2771 ID := M.ReadWord();
2772 Mon := g_Monsters_ByUID(ID);
2773 if Mon <> nil then
2774 Exit;
2776 MType := M.ReadByte();
2777 MState := M.ReadByte();
2778 MAnim := M.ReadByte();
2779 MTarg := M.ReadWord();
2780 MTargTime := M.ReadLongInt();
2781 MBehav := M.ReadByte();
2782 MSleep := M.ReadLongInt();
2783 MHealth := M.ReadLongInt();
2784 MAmmo := M.ReadLongInt();
2786 X := M.ReadLongInt();
2787 Y := M.ReadLongInt();
2788 VX := M.ReadLongInt();
2789 VY := M.ReadLongInt();
2790 MDir := M.ReadByte();
2792 g_Monsters_Create(MType, X, Y, TDirection(MDir), False, ID);
2793 Mon := g_Monsters_ByUID(ID);
2794 if Mon = nil then
2795 Exit;
2797 with Mon do
2798 begin
2800 MonsterAnim := MAnim;
2801 MonsterTargetUID := MTarg;
2802 MonsterTargetTime := MTargTime;
2803 MonsterBehaviour := MBehav;
2804 MonsterSleep := MSleep;
2805 MonsterAmmo := MAmmo;
2806 SetHealth(MHealth);
2808 SetState(MState);
2810 setPosition(X, Y); // this will call positionChanged();
2811 GameVelX := VX;
2812 GameVelY := VY;
2813 end;
2814 end;
2816 procedure MC_RECV_MonsterPos(var M: TMsg);
2817 var
2818 Mon: TMonster;
2819 ID: Word;
2820 X, Y: Integer;
2821 begin
2822 ID := M.ReadWord();
2823 Mon := g_Monsters_ByUID(ID);
2824 if Mon = nil then
2825 Exit;
2827 with Mon do
2828 begin
2829 X := M.ReadLongInt();
2830 Y := M.ReadLongInt();
2831 Mon.setPosition(X, Y); // this will call `positionChanged()`
2832 GameVelX := M.ReadLongInt();
2833 GameVelY := M.ReadLongInt();
2834 GameDirection := TDirection(M.ReadByte());
2835 end;
2836 end;
2838 procedure MC_RECV_MonsterState(var M: TMsg);
2839 var
2840 ID, OldFire: Integer;
2841 MState, MFAnm: Byte;
2842 Mon: TMonster;
2843 AnimRevert: Boolean;
2844 begin
2845 ID := M.ReadWord();
2846 Mon := g_Monsters_ByUID(ID);
2847 if Mon = nil then Exit;
2849 MState := M.ReadByte();
2850 MFAnm := M.ReadByte();
2852 with Mon do
2853 begin
2854 MonsterTargetUID := M.ReadWord();
2855 MonsterTargetTime := M.ReadLongInt();
2856 MonsterSleep := M.ReadLongInt();
2857 MonsterHealth := M.ReadLongInt();
2858 MonsterAmmo := M.ReadLongInt();
2859 MonsterPain := M.ReadLongInt();
2860 AnimRevert := M.ReadByte() <> 0;
2861 OldFire := FFireTime;
2862 FFireTime := M.ReadLongInt();
2863 if (OldFire <= 0) and (FFireTime > 0) then
2864 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
2865 RevertAnim(AnimRevert);
2867 if MonsterState <> MState then
2868 begin
2869 if (MState = MONSTATE_GO) and (MonsterState = MONSTATE_SLEEP) then WakeUpSound();
2870 if (MState = MONSTATE_DIE) then DieSound();
2871 if (MState = MONSTATE_PAIN) then MakeBloodSimple(Min(200, MonsterPain));
2872 if (MState = MONSTATE_ATTACK) then kick(nil);
2873 if (MState = MONSTATE_DEAD) then SetDeadAnim();
2875 SetState(MState, MFAnm);
2876 end;
2877 end;
2878 end;
2880 procedure MC_RECV_MonsterShot(var M: TMsg);
2881 var
2882 ID: Integer;
2883 Mon: TMonster;
2884 X, Y, VX, VY: Integer;
2885 begin
2886 ID := M.ReadWord();
2888 Mon := g_Monsters_ByUID(ID);
2889 if Mon = nil then Exit;
2891 X := M.ReadLongInt();
2892 Y := M.ReadLongInt();
2893 VX := M.ReadLongInt();
2894 VY := M.ReadLongInt();
2896 Mon.ClientAttack(X, Y, VX, VY);
2897 end;
2899 procedure MC_RECV_MonsterDelete(var M: TMsg);
2900 var
2901 ID: Integer;
2902 Mon: TMonster;
2903 begin
2904 ID := M.ReadWord();
2905 Mon := g_Monsters_ByUID(ID);
2906 if Mon = nil then Exit;
2907 Mon.SetState(5);
2908 Mon.MonsterRemoved := True;
2909 end;
2911 procedure MC_RECV_TimeSync(var M: TMsg);
2912 var
2913 Time: LongWord;
2914 begin
2915 Time := M.ReadLongWord();
2917 if gState = STATE_INTERCUSTOM then
2918 gServInterTime := Min(Time, 255);
2919 end;
2921 procedure MC_RECV_VoteEvent(var M: TMsg);
2922 var
2923 EvID: Byte;
2924 Str1, Str2: string;
2925 Int1, Int2: SmallInt;
2926 begin
2927 EvID := M.ReadByte();
2928 Int1 := M.ReadSmallInt();
2929 Int2 := M.ReadSmallInt();
2930 Str1 := M.ReadString();
2931 Str2 := M.ReadString();
2933 if NetDeafLevel < 2 then
2934 case EvID of
2935 NET_VE_STARTED:
2936 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True);
2937 NET_VE_PASSED:
2938 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True);
2939 NET_VE_FAILED:
2940 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
2941 NET_VE_VOTE:
2942 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True);
2943 NET_VE_INPROGRESS:
2944 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True);
2945 end;
2946 end;
2948 // CLIENT SEND
2950 procedure MC_SEND_Info(Password: string);
2951 begin
2952 NetOut.Clear();
2954 NetOut.Write(Byte(NET_MSG_INFO));
2955 NetOut.Write(GAME_VERSION);
2956 NetOut.Write(Password);
2957 NetOut.Write(gPlayer1Settings.Name);
2958 NetOut.Write(gPlayer1Settings.Model);
2959 NetOut.Write(gPlayer1Settings.Color.R);
2960 NetOut.Write(gPlayer1Settings.Color.G);
2961 NetOut.Write(gPlayer1Settings.Color.B);
2962 NetOut.Write(gPlayer1Settings.Team);
2964 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2965 end;
2967 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
2968 begin
2969 NetOut.Write(Byte(NET_MSG_CHAT));
2970 NetOut.Write(Txt);
2971 NetOut.Write(Mode);
2973 g_Net_Client_Send(True, NET_CHAN_CHAT);
2974 end;
2976 procedure MC_SEND_PlayerPos();
2977 var
2978 kByte: Word;
2979 Predict: Boolean;
2980 strafeDir: Byte;
2981 WeaponAct: Byte = 0;
2982 WeaponSelect: Word = 0;
2983 i: Integer;
2984 begin
2985 if not gGameOn then Exit;
2986 if gPlayers = nil then Exit;
2987 if gPlayer1 = nil then Exit;
2989 kByte := 0;
2990 Predict := NetPredictSelf; // and (not NetGotKeys);
2992 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2993 begin
2994 strafeDir := P1MoveButton shr 4;
2995 P1MoveButton := P1MoveButton and $0F;
2997 if gPlayerAction[0, ACTION_MOVELEFT] and (not gPlayerAction[0, ACTION_MOVERIGHT]) then
2998 P1MoveButton := 1
2999 else if (not gPlayerAction[0, ACTION_MOVELEFT]) and gPlayerAction[0, ACTION_MOVERIGHT] then
3000 P1MoveButton := 2
3001 else if (not gPlayerAction[0, ACTION_MOVELEFT]) and (not gPlayerAction[0, ACTION_MOVERIGHT]) then
3002 P1MoveButton := 0;
3004 // strafing
3005 if gPlayerAction[0, ACTION_STRAFE] then
3006 begin
3007 // new strafe mechanics
3008 if (strafeDir = 0) then
3009 strafeDir := P1MoveButton; // start strafing
3010 // now set direction according to strafe (reversed)
3011 if (strafeDir = 2) then
3012 gPlayer1.SetDirection(TDirection.D_LEFT)
3013 else if (strafeDir = 1) then
3014 gPlayer1.SetDirection(TDirection.D_RIGHT)
3015 end
3016 else
3017 begin
3018 strafeDir := 0; // not strafing anymore
3019 if (P1MoveButton = 2) and gPlayerAction[0, ACTION_MOVELEFT] then
3020 gPlayer1.SetDirection(TDirection.D_LEFT)
3021 else if (P1MoveButton = 1) and gPlayerAction[0, ACTION_MOVERIGHT] then
3022 gPlayer1.SetDirection(TDirection.D_RIGHT)
3023 else if P1MoveButton <> 0 then
3024 gPlayer1.SetDirection(TDirection(P1MoveButton-1));
3025 end;
3027 gPlayer1.ReleaseKeys;
3028 if P1MoveButton = 1 then
3029 begin
3030 kByte := kByte or NET_KEY_LEFT;
3031 if Predict then gPlayer1.PressKey(KEY_LEFT, 10000);
3032 end;
3033 if P1MoveButton = 2 then
3034 begin
3035 kByte := kByte or NET_KEY_RIGHT;
3036 if Predict then gPlayer1.PressKey(KEY_RIGHT, 10000);
3037 end;
3038 if gPlayerAction[0, ACTION_LOOKUP] then
3039 begin
3040 kByte := kByte or NET_KEY_UP;
3041 gPlayer1.PressKey(KEY_UP, 10000);
3042 end;
3043 if gPlayerAction[0, ACTION_LOOKDOWN] then
3044 begin
3045 kByte := kByte or NET_KEY_DOWN;
3046 gPlayer1.PressKey(KEY_DOWN, 10000);
3047 end;
3048 if gPlayerAction[0, ACTION_JUMP] then
3049 begin
3050 kByte := kByte or NET_KEY_JUMP;
3051 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3052 end;
3053 if gPlayerAction[0, ACTION_ATTACK] then kByte := kByte or NET_KEY_FIRE;
3054 if gPlayerAction[0, ACTION_ACTIVATE] then kByte := kByte or NET_KEY_OPEN;
3056 for i := WP_FACT to WP_LACT do
3057 begin
3058 if gWeaponAction[0, i] then
3059 begin
3060 WeaponAct := WeaponAct or Byte(1 shl i);
3061 gWeaponAction[0, i] := False
3062 end
3063 end;
3065 for i := WP_FIRST to WP_LAST do
3066 begin
3067 if gSelectWeapon[0, i] then
3068 begin
3069 WeaponSelect := WeaponSelect or Word(1 shl i);
3070 gSelectWeapon[0, i] := False
3071 end
3072 end;
3074 // fix movebutton state
3075 P1MoveButton := P1MoveButton or (strafeDir shl 4);
3076 end
3077 else
3078 kByte := NET_KEY_CHAT;
3080 NetOut.Write(Byte(NET_MSG_PLRPOS));
3081 NetOut.Write(gTime);
3082 NetOut.Write(kByte);
3083 NetOut.Write(Byte(gPlayer1.Direction));
3084 NetOut.Write(WeaponAct);
3085 NetOut.Write(WeaponSelect);
3086 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3087 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS);
3089 //kBytePrev := kByte;
3090 //kDirPrev := gPlayer1.Direction;
3091 end;
3093 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
3094 begin
3095 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
3096 NetOut.Write(Byte(Start));
3097 NetOut.Write(Command);
3098 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3099 end;
3101 procedure MC_SEND_PlayerSettings();
3102 begin
3103 NetOut.Write(Byte(NET_MSG_PLRSET));
3104 NetOut.Write(gPlayer1Settings.Name);
3105 NetOut.Write(gPlayer1Settings.Model);
3106 NetOut.Write(gPlayer1Settings.Color.R);
3107 NetOut.Write(gPlayer1Settings.Color.G);
3108 NetOut.Write(gPlayer1Settings.Color.B);
3109 NetOut.Write(gPlayer1Settings.Team);
3111 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3112 end;
3114 procedure MC_SEND_FullStateRequest();
3115 begin
3116 NetOut.Write(Byte(NET_MSG_REQFST));
3118 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3119 end;
3121 procedure MC_SEND_CheatRequest(Kind: Byte);
3122 begin
3123 NetOut.Write(Byte(NET_MSG_CHEAT));
3124 NetOut.Write(Kind);
3126 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3127 end;
3128 procedure MC_SEND_RCONPassword(Password: string);
3129 begin
3130 NetOut.Write(Byte(NET_MSG_RCON_AUTH));
3131 NetOut.Write(Password);
3133 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3134 end;
3135 procedure MC_SEND_RCONCommand(Cmd: string);
3136 begin
3137 NetOut.Write(Byte(NET_MSG_RCON_CMD));
3138 NetOut.Write(Cmd);
3140 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3141 end;
3144 end.