DEADSOFTWARE

17942e24e65b63be12b38c02f369ee7a0d9f0e6d
[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;
286 NET_KEY_RIGHT = 2;
287 NET_KEY_UP = 4;
288 NET_KEY_DOWN = 8;
289 NET_KEY_JUMP = 16;
290 NET_KEY_FIRE = 32;
291 NET_KEY_OPEN = 64;
292 NET_KEY_NW = 256;
293 NET_KEY_PW = 512;
294 NET_KEY_CHAT = 2048;
295 NET_KEY_FORCEDIR = 4096;
297 //var
298 //kBytePrev: Word = 0;
299 //kDirPrev: TDirection = D_LEFT;
300 //HostGameTime: Word = 0;
303 function IsValidFileName(const S: String): Boolean;
304 const
305 Forbidden: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
306 var
307 I: Integer;
308 begin
309 Result := S <> '';
310 for I := 1 to Length(S) do
311 Result := Result and (not(S[I] in Forbidden));
312 end;
314 function IsValidFilePath(const S: String): Boolean;
315 var
316 I: Integer;
317 begin
318 Result := False;
319 if not IsValidFileName(S) then exit;
320 if FileExists(S) then exit;
321 I := LastDelimiter('\/', S);
322 if (I > 0) then
323 if (not DirectoryExists(Copy(S, 1, I-1))) then
324 exit;
325 Result := True;
326 end;
329 // HOST MESSAGES //
332 // GAME
334 procedure MH_RECV_Chat(C: pTNetClient; var M: TMsg);
335 var
336 Txt: string;
337 Mode: Byte;
338 PID: Word;
339 Pl: TPlayer;
340 begin
341 PID := C^.Player;
342 Pl := g_Player_Get(PID);
344 Txt := M.ReadString();
345 Mode := M.ReadByte();
346 if (Mode = NET_CHAT_SYSTEM) then
347 Mode := NET_CHAT_PLAYER; // prevent sending system messages from clients
348 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
349 Mode := NET_CHAT_PLAYER; // revert to player chat in non-team game
351 if Pl = nil then
352 MH_SEND_Chat(Txt, Mode)
353 else
354 MH_SEND_Chat(Pl.Name + ': ' + Txt, Mode, IfThen(Mode = NET_CHAT_TEAM, Pl.Team, NET_EVERYONE));
355 end;
357 procedure MH_RECV_Info(C: pTNetClient; var M: TMsg);
358 var
359 Ver, PName, Model, Pw: string;
360 R, G, B, T: Byte;
361 PID: Word;
362 Color: TRGB;
363 I: Integer;
364 begin
365 Ver := M.ReadString();
366 Pw := M.ReadString();
367 PName := M.ReadString();
368 Model := M.ReadString();
369 R := M.ReadByte();
370 G := M.ReadByte();
371 B := M.ReadByte();
372 T := M.ReadByte();
374 if Ver <> GAME_VERSION then
375 begin
376 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
377 _lc[I_NET_DISC_VERSION]);
378 enet_peer_disconnect(C^.Peer, NET_DISC_VERSION);
379 Exit;
380 end;
382 if g_Net_IsHostBanned(C^.Peer^.address.host) then
383 begin
384 if g_Net_IsHostBanned(C^.Peer^.address.host, True) then
385 begin
386 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
387 _lc[I_NET_DISC_BAN]);
388 enet_peer_disconnect(C^.Peer, NET_DISC_BAN);
389 end
390 else
391 begin
392 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
393 _lc[I_NET_DISC_BAN]);
394 enet_peer_disconnect(C^.Peer, NET_DISC_TEMPBAN);
395 end;
396 Exit;
397 end;
399 if NetPassword <> '' then
400 if AnsiLowerCase(NetPassword) <> AnsiLowerCase(Pw) then
401 begin
402 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
403 _lc[I_NET_DISC_PASSWORD]);
404 enet_peer_disconnect(C^.Peer, NET_DISC_PASSWORD);
405 Exit;
406 end;
408 Color.R := R;
409 Color.B := B;
410 Color.G := G;
412 PID := g_Player_Create(Model, Color, T, False);
413 with g_Player_Get(PID) do
414 begin
415 Name := PName;
416 Reset(True);
417 end;
419 C^.Player := PID;
420 C^.WaitForFirstSpawn := false;
422 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
423 e_WriteLog('NET: Client ' + PName + ' [' + IntToStr(C^.ID) +
424 '] connected. Assigned player #' + IntToStr(PID) + '.', TMsgType.Notify);
426 MH_SEND_Info(C^.ID);
428 with g_Player_Get(PID) do
429 begin
430 Name := PName;
431 FClientID := C^.ID;
432 // round in progress, don't spawn
433 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C.ID, C.Player]);
434 //e_LogWritefln('spawning player with pid #%u...', [PID]);
435 //Respawn(gGameSettings.GameType = GT_SINGLE);
436 //k8: no, do not spawn a player yet, wait for "request full state" packet
437 Lives := 0;
438 Spectate;
439 FNoRespawn := True;
440 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
441 // that is, if we'll set it to `true`, the player can be spawned after
442 // warmup time ran out, for example, regardless of the real player state.
443 // also, this seems to work only for the initial connection. further
444 // map changes could initiate resource downloading, but the player will
445 // be spawned immediately.
446 // the proper solution will require another player state, "ephemeral".
447 // the player should start any map in "ephemeral" state, and turned into
448 // real mobj only when they sent a special "i am ready" packet. this packet
449 // must be sent after receiving the full state, so the player will get a full
450 // map view before going into game.
451 FWantsInGame := false;
452 C^.WaitForFirstSpawn := true;
453 end;
455 //if not C^.WaitForFirstSpawn then
456 begin
457 for I := Low(NetClients) to High(NetClients) do
458 begin
459 if NetClients[I].ID = C^.ID then Continue;
460 MH_SEND_PlayerCreate(PID, NetClients[I].ID);
461 MH_SEND_PlayerPos(True, PID, NetClients[I].ID);
462 MH_SEND_PlayerStats(PID, NetClients[I].ID);
463 end;
464 end;
466 if gState in [STATE_INTERCUSTOM, STATE_FOLD] then
467 MH_SEND_GameEvent(NET_EV_MAPEND, 0, 'N', C^.ID);
469 if NetUseMaster then
470 begin
471 //g_Net_Slist_Update;
472 g_Net_Slist_Pulse();
473 end;
474 end;
477 procedure MH_ProcessFirstSpawn (C: pTNetClient);
478 var
479 plr: TPlayer;
480 begin
481 if not C.WaitForFirstSpawn then exit;
482 plr := g_Player_Get(C^.Player);
483 if not assigned(plr) then exit;
484 g_Net_Slist_ServerPlayerComes();
485 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C.ID, C.Player]);
486 C.WaitForFirstSpawn := false;
487 plr.FNoRespawn := false;
488 plr.FWantsInGame := true; // TODO: look into this later
490 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
491 begin
492 plr.Spectate;
493 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN, 0, 'N', C.ID);
494 end
495 else
496 begin
497 plr.Respawn(False);
498 if gLMSRespawn > LMS_RESPAWN_NONE then
499 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime, 'N', C.ID);
500 end;
501 end;
504 procedure MH_RECV_FullStateRequest(C: pTNetClient; var M: TMsg);
505 begin
506 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
507 if gGameOn then
508 begin
509 MH_SEND_Everything((C^.State = NET_STATE_AUTH), C^.ID)
510 end
511 else
512 begin
513 C^.RequestedFullUpdate := True;
514 end;
515 end;
517 // PLAYER
519 function MH_RECV_PlayerPos(C: pTNetClient; var M: TMsg): Word;
520 var
521 Dir, i: Byte;
522 WeaponSelect: Word;
523 PID: Word;
524 kByte: Word;
525 Pl: TPlayer;
526 GT: LongWord;
527 begin
528 Result := 0;
529 if not gGameOn then Exit;
531 GT := M.ReadLongWord();
532 PID := C^.Player;
533 Pl := g_Player_Get(PID);
534 if Pl = nil then
535 Exit;
537 if (GT > gTime + NET_MAX_DIFFTIME) or (GT < Pl.NetTime) then Exit;
539 with Pl do
540 begin
541 NetTime := GT;
542 kByte := M.ReadWord();
543 Dir := 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);
565 if LongBool(kByte and NET_KEY_NW) then PressKey(KEY_NEXTWEAPON, 10000);
566 if LongBool(kByte and NET_KEY_PW) then PressKey(KEY_PREVWEAPON, 10000);
568 for i := 0 to 15 do
569 begin
570 if (WeaponSelect and Word(1 shl i)) <> 0 then
571 begin
572 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
573 QueueWeaponSwitch(i);
574 end;
575 end;
576 end;
578 // MH_SEND_PlayerPos(False, PID, C^.ID);
579 end;
581 procedure MH_RECV_CheatRequest(C: pTNetClient; var M: TMsg);
582 var
583 CheatKind: Byte;
584 Pl: TPlayer;
585 begin
586 Pl := g_Player_Get(C^.Player);
587 if Pl = nil then Exit;
589 CheatKind := M.ReadByte();
591 case CheatKind of
592 NET_CHEAT_SUICIDE:
593 Pl.Damage(SUICIDE_DAMAGE, Pl.UID, 0, 0, HIT_SELF);
594 NET_CHEAT_SPECTATE:
595 begin
596 if Pl.FSpectator then
597 begin
598 if (gGameSettings.MaxLives = 0) or (gLMSRespawn > LMS_RESPAWN_NONE) then
599 Pl.Respawn(False)
600 else
601 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN, Pl.UID);
602 end
603 else
604 Pl.Spectate;
605 end;
606 NET_CHEAT_READY:
607 begin
608 if gState <> STATE_INTERCUSTOM then Exit;
609 Pl.FReady := not Pl.FReady;
610 if Pl.FReady then
611 begin
612 MH_SEND_GameEvent(NET_EV_INTER_READY, Pl.UID, 'Y');
613 Inc(gInterReadyCount);
614 end
615 else
616 begin
617 MH_SEND_GameEvent(NET_EV_INTER_READY, Pl.UID, 'N');
618 Dec(gInterReadyCount);
619 end;
620 end;
621 end;
622 end;
624 procedure MH_RECV_PlayerSettings(C: pTNetClient; var M: TMsg);
625 var
626 TmpName: string;
627 TmpModel: string;
628 TmpColor: TRGB;
629 TmpTeam: Byte;
630 Pl: TPlayer;
631 begin
632 TmpName := M.ReadString();
633 TmpModel := M.ReadString();
634 TmpColor.R := M.ReadByte();
635 TmpColor.G := M.ReadByte();
636 TmpColor.B := M.ReadByte();
637 TmpTeam := M.ReadByte();
639 Pl := g_Player_Get(C^.Player);
640 if Pl = nil then Exit;
642 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
643 Pl.SwitchTeam
644 else
645 Pl.SetColor(TmpColor);
647 if Pl.Name <> TmpName then
648 begin
649 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
650 Pl.Name := TmpName;
651 end;
653 if TmpModel <> Pl.Model.Name then
654 Pl.SetModel(TmpModel);
656 MH_SEND_PlayerSettings(Pl.UID, TmpModel);
657 end;
659 // RCON
661 procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
662 var
663 Pwd: string;
664 begin
665 Pwd := M.ReadString();
666 if not NetAllowRCON then Exit;
667 if Pwd = NetRCONPassword then
668 begin
669 C^.RCONAuth := True;
670 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWGOOD, 'N', C^.ID);
671 end
672 else
673 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWBAD, 'N', C^.ID);
674 end;
676 procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
677 var
678 Cmd: string;
679 begin
680 Cmd := M.ReadString();
681 if not NetAllowRCON then Exit;
682 if not C^.RCONAuth then
683 begin
684 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_NOAUTH, 'N', C^.ID);
685 Exit;
686 end;
687 g_Console_Process(Cmd);
688 end;
690 // MISC
692 procedure MH_RECV_Vote(C: pTNetClient; var M: TMsg);
693 var
694 Start: Boolean;
695 Name, Command: string;
696 Need: Integer;
697 Pl: TPlayer;
698 begin
699 Start := M.ReadByte() <> 0;
700 Command := M.ReadString();
702 Pl := g_Player_Get(C^.Player);
703 if Pl = nil then Exit;
704 Name := Pl.Name;
706 if Start then
707 begin
708 if not g_Console_CommandBlacklisted(Command) then
709 g_Game_StartVote(Command, Name);
710 end
711 else if gVoteInProgress then
712 begin
713 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
714 Need := Floor((NetClientCount+1)/2.0) + 1
715 else
716 Need := Floor(NetClientCount/2.0) + 1;
717 if C^.Voted then
718 begin
719 Dec(gVoteCount);
720 C^.Voted := False;
721 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [Name, gVoteCount, Need]), True);
722 MH_SEND_VoteEvent(NET_VE_REVOKE, Name, 'a', gVoteCount, Need);
723 end
724 else
725 begin
726 Inc(gVoteCount);
727 C^.Voted := True;
728 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Name, gVoteCount, Need]), True);
729 MH_SEND_VoteEvent(NET_VE_VOTE, Name, 'a', gVoteCount, Need);
730 g_Game_CheckVote;
731 end;
732 end;
733 end;
735 // GAME (SEND)
737 procedure MH_SEND_Everything(CreatePlayers: Boolean {= False}; ID: Integer {= NET_EVERYONE});
739 function sendItemRespawn (it: PItem): Boolean;
740 begin
741 result := false; // don't stop
742 MH_SEND_ItemSpawn(True, it.myid, ID);
743 end;
745 function sendMonSpawn (mon: TMonster): Boolean;
746 begin
747 result := false; // don't stop
748 MH_SEND_MonsterSpawn(mon.UID, ID);
749 end;
751 function sendPanelState (pan: TPanel): Boolean;
752 begin
753 result := false; // don't stop
754 MH_SEND_PanelState(pan.guid, ID); // anyway, to sync mplats
755 if (pan.CanChangeTexture) then MH_SEND_PanelTexture(pan.guid, pan.LastAnimLoop, ID);
756 end;
758 var
759 I: Integer;
760 begin
761 if (ID >= 0) and (ID < length(NetClients)) then
762 begin
763 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID, NetClients[ID].Player]);
764 MH_ProcessFirstSpawn(@NetClients[ID]);
765 end;
767 if gPlayers <> nil then
768 begin
769 for I := Low(gPlayers) to High(gPlayers) do
770 begin
771 if gPlayers[I] <> nil then
772 begin
773 if CreatePlayers then MH_SEND_PlayerCreate(gPlayers[I].UID, ID);
774 MH_SEND_PlayerPos(True, gPlayers[I].UID, ID);
775 MH_SEND_PlayerStats(gPlayers[I].UID, ID);
777 if (gPlayers[I].Flag <> FLAG_NONE) and (gGameSettings.GameMode = GM_CTF) then
778 begin
779 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED, gPlayers[I].Flag, gPlayers[I].UID, True, ID);
780 end;
781 end;
782 end;
783 end;
785 g_Items_ForEachAlive(sendItemRespawn, true); // backwards
786 g_Mons_ForEach(sendMonSpawn);
787 g_Map_ForEachPanel(sendPanelState);
789 if gTriggers <> nil then
790 begin
791 for I := Low(gTriggers) to High(gTriggers) do
792 begin
793 if gTriggers[I].TriggerType = TRIGGER_SOUND then
794 begin
795 MH_SEND_TriggerSound(gTriggers[I], ID);
796 end;
797 end;
798 end;
800 if Shots <> nil then
801 begin
802 for I := Low(Shots) to High(Shots) do
803 begin
804 if Shots[i].ShotType in [6, 7, 8] then
805 begin
806 MH_SEND_CreateShot(i, ID);
807 end;
808 end;
809 end;
811 MH_SEND_TriggerMusic(ID);
813 MH_SEND_GameStats(ID);
814 MH_SEND_CoopStats(ID);
816 if gGameSettings.GameMode = GM_CTF then
817 begin
818 if gFlags[FLAG_RED].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_RED].State, FLAG_RED, 0, True, ID);
819 if gFlags[FLAG_BLUE].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_BLUE].State, FLAG_BLUE, 0, True, ID);
820 end;
822 if CreatePlayers and (ID >= 0) then NetClients[ID].State := NET_STATE_GAME;
824 g_Net_Flush();
825 end;
827 procedure MH_SEND_Info(ID: Byte);
828 begin
829 NetOut.Clear();
831 NetOut.Write(Byte(NET_MSG_INFO));
832 NetOut.Write(ID);
833 NetOut.Write(NetClients[ID].Player);
834 NetOut.Write(ExtractFileName(gGameSettings.WAD));
835 NetOut.Write(g_ExtractFileName(gMapInfo.Map));
836 NetOut.Write(gWADHash);
837 NetOut.Write(gGameSettings.GameMode);
838 NetOut.Write(gGameSettings.GoalLimit);
839 NetOut.Write(gGameSettings.TimeLimit);
840 NetOut.Write(gGameSettings.MaxLives);
841 NetOut.Write(gGameSettings.Options);
842 NetOut.Write(gTime);
844 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
845 end;
847 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
848 var
849 Name: string;
850 i: Integer;
851 Team: Byte;
852 begin
853 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
854 Mode := NET_CHAT_PLAYER;
856 Team := 0;
857 if (Mode = NET_CHAT_TEAM) then
858 begin
859 for i := Low(gPlayers) to High(gPlayers) do
860 if (gPlayers[i] <> nil) and (gPlayers[i].FClientID >= 0) and
861 (gPlayers[i].Team = ID) then
862 begin
863 NetOut.Write(Byte(NET_MSG_CHAT));
864 NetOut.Write(Txt);
865 NetOut.Write(Mode);
866 g_Net_Host_Send(gPlayers[i].FClientID, True, NET_CHAN_CHAT);
867 end;
868 Team := ID;
869 ID := NET_EVERYONE;
870 end
871 else
872 begin
873 NetOut.Write(Byte(NET_MSG_CHAT));
874 NetOut.Write(Txt);
875 NetOut.Write(Mode);
876 g_Net_Host_Send(ID, True, NET_CHAN_CHAT);
877 end;
879 if Mode = NET_CHAT_SYSTEM then
880 Exit;
882 if ID = NET_EVERYONE then
883 begin
884 if Mode = NET_CHAT_PLAYER then
885 begin
886 g_Console_Add(Txt, True);
887 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
888 g_Game_ChatSound(b_Text_Unformat(Txt));
889 end
890 else
891 if Mode = NET_CHAT_TEAM then
892 if gPlayer1 <> nil then
893 begin
894 if (gPlayer1.Team = TEAM_RED) and (Team = TEAM_RED) then
895 begin
896 g_Console_Add(#18'[Team] '#2 + Txt, True);
897 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
898 g_Game_ChatSound(b_Text_Unformat(Txt));
899 end
900 else if (gPlayer1.Team = TEAM_BLUE) and (Team = TEAM_BLUE) then
901 begin
902 g_Console_Add(#20'[Team] '#2 + Txt, True);
903 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
904 g_Game_ChatSound(b_Text_Unformat(Txt));
905 end;
906 end;
907 end
908 else
909 begin
910 Name := g_Net_ClientName_ByID(ID);
911 g_Console_Add('-> ' + Name + ': ' + Txt, True);
912 e_WriteLog('[Tell ' + Name + '] ' + b_Text_Unformat(Txt), TMsgType.Notify);
913 g_Game_ChatSound(b_Text_Unformat(Txt), False);
914 end;
915 end;
917 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
918 begin
919 NetOut.Write(Byte(NET_MSG_GFX));
920 NetOut.Write(Kind);
921 NetOut.Write(X);
922 NetOut.Write(Y);
923 NetOut.Write(Ang);
925 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
926 end;
928 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
929 begin
930 NetOut.Write(Byte(NET_MSG_SND));
931 NetOut.Write(Name);
932 if Pos then
933 begin
934 NetOut.Write(Byte(1));
935 NetOut.Write(X);
936 NetOut.Write(Y);
937 end
938 else
939 NetOut.Write(Byte(0));
941 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
942 end;
944 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
945 begin
946 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
948 NetOut.Write(Byte(NET_MSG_SHADD));
949 NetOut.Write(Proj);
950 NetOut.Write(Shots[Proj].ShotType);
951 NetOut.Write(Shots[Proj].Target);
952 NetOut.Write(Shots[Proj].SpawnerUID);
953 NetOut.Write(Shots[Proj].Timeout);
954 NetOut.Write(Shots[Proj].Obj.X);
955 NetOut.Write(Shots[Proj].Obj.Y);
956 NetOut.Write(Shots[Proj].Obj.Vel.X);
957 NetOut.Write(Shots[Proj].Obj.Vel.Y);
959 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
960 end;
962 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
963 begin
964 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
966 NetOut.Write(Byte(NET_MSG_SHPOS));
967 NetOut.Write(Proj);
968 NetOut.Write(Shots[Proj].Obj.X);
969 NetOut.Write(Shots[Proj].Obj.Y);
970 NetOut.Write(Shots[Proj].Obj.Vel.X);
971 NetOut.Write(Shots[Proj].Obj.Vel.Y);
973 g_Net_Host_Send(ID, False, NET_CHAN_SHOTS);
974 end;
976 procedure MH_Send_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
977 begin
978 NetOut.Write(Byte(NET_MSG_SHDEL));
979 NetOut.Write(Proj);
980 NetOut.Write(Byte(Loud));
981 NetOut.Write(X);
982 NetOut.Write(Y);
984 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
985 end;
987 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
988 begin
989 NetOut.Write(Byte(NET_MSG_SCORE));
990 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
991 begin
992 NetOut.Write(gTeamStat[TEAM_RED].Goals);
993 NetOut.Write(gTeamStat[TEAM_BLUE].Goals);
994 end
995 else
996 if gGameSettings.GameMode = GM_COOP then
997 begin
998 NetOut.Write(gCoopMonstersKilled);
999 NetOut.Write(gCoopSecretsFound);
1000 end;
1002 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1003 end;
1005 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
1006 begin
1007 NetOut.Write(Byte(NET_MSG_COOP));
1008 NetOut.Write(gTotalMonsters);
1009 NetOut.Write(gSecretsCount);
1010 NetOut.Write(gCoopTotalMonstersKilled);
1011 NetOut.Write(gCoopTotalSecretsFound);
1012 NetOut.Write(gCoopTotalMonsters);
1013 NetOut.Write(gCoopTotalSecrets);
1014 end;
1016 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
1017 begin
1018 NetOut.Write(Byte(NET_MSG_GEVENT));
1019 NetOut.Write(EvType);
1020 NetOut.Write(EvNum);
1021 NetOut.Write(EvStr);
1022 NetOut.Write(Byte(gLastMap));
1023 NetOut.Write(gTime);
1024 if (EvType = NET_EV_MAPSTART) and isWadPath(EvStr) then
1025 begin
1026 NetOut.Write(Byte(1));
1027 NetOut.Write(gWADHash);
1028 end else
1029 NetOut.Write(Byte(0));
1031 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
1032 end;
1034 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
1035 begin
1036 NetOut.Write(Byte(NET_MSG_FLAG));
1037 NetOut.Write(EvType);
1038 NetOut.Write(Flag);
1039 NetOut.Write(Byte(Quiet));
1040 NetOut.Write(PID);
1041 NetOut.Write(gFlags[Flag].State);
1042 NetOut.Write(gFlags[Flag].CaptureTime);
1043 NetOut.Write(gFlags[Flag].Obj.X);
1044 NetOut.Write(gFlags[Flag].Obj.Y);
1045 NetOut.Write(gFlags[Flag].Obj.Vel.X);
1046 NetOut.Write(gFlags[Flag].Obj.Vel.Y);
1048 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1049 end;
1051 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
1052 begin
1053 NetOut.Write(Byte(NET_MSG_GSET));
1054 NetOut.Write(gGameSettings.GameMode);
1055 NetOut.Write(gGameSettings.GoalLimit);
1056 NetOut.Write(gGameSettings.TimeLimit);
1057 NetOut.Write(gGameSettings.MaxLives);
1058 NetOut.Write(gGameSettings.Options);
1060 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1061 end;
1063 // PLAYER (SEND)
1065 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
1066 var
1067 P: TPlayer;
1068 begin
1069 P := g_Player_Get(PID);
1070 if P = nil then Exit;
1072 NetOut.Write(Byte(NET_MSG_PLR));
1073 NetOut.Write(PID);
1074 NetOut.Write(P.Name);
1076 NetOut.Write(P.FActualModelName);
1077 NetOut.Write(P.FColor.R);
1078 NetOut.Write(P.FColor.G);
1079 NetOut.Write(P.FColor.B);
1080 NetOut.Write(P.Team);
1082 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT)
1083 end;
1085 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
1086 var
1087 kByte: Word;
1088 Pl: TPlayer;
1089 begin
1090 Pl := g_Player_Get(PID);
1091 if Pl = nil then Exit;
1092 if Pl.FDummy then Exit;
1094 NetOut.Write(Byte(NET_MSG_PLRPOS));
1095 NetOut.Write(gTime);
1096 NetOut.Write(PID);
1098 kByte := 0;
1100 with Pl do
1101 begin
1102 NetOut.Write(FPing);
1103 NetOut.Write(FLoss);
1104 if IsKeyPressed(KEY_CHAT) then
1105 kByte := NET_KEY_CHAT
1106 else
1107 begin
1108 if IsKeyPressed(KEY_LEFT) then kByte := kByte or NET_KEY_LEFT;
1109 if IsKeyPressed(KEY_RIGHT) then kByte := kByte or NET_KEY_RIGHT;
1110 if IsKeyPressed(KEY_UP) then kByte := kByte or NET_KEY_UP;
1111 if IsKeyPressed(KEY_DOWN) then kByte := kByte or NET_KEY_DOWN;
1112 if IsKeyPressed(KEY_JUMP) then kByte := kByte or NET_KEY_JUMP;
1113 end;
1115 if JustTeleported then kByte := kByte or NET_KEY_FORCEDIR;
1117 NetOut.Write(kByte);
1118 if Direction = TDirection.D_LEFT then NetOut.Write(Byte(0)) else NetOut.Write(Byte(1));
1119 NetOut.Write(GameX);
1120 NetOut.Write(GameY);
1121 NetOut.Write(GameVelX);
1122 NetOut.Write(GameVelY);
1123 NetOut.Write(GameAccelX);
1124 NetOut.Write(GameAccelY);
1125 end;
1127 g_Net_Host_Send(ID, Reliable, NET_CHAN_PLAYERPOS);
1128 end;
1130 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
1131 var
1132 P: TPlayer;
1133 I: Integer;
1134 begin
1135 P := g_Player_Get(PID);
1136 if P = nil then Exit;
1138 NetOut.Write(Byte(NET_MSG_PLRSTA));
1139 NetOut.Write(PID);
1141 with P do
1142 begin
1143 NetOut.Write(Byte(alive));
1144 NetOut.Write(Byte(GodMode));
1145 NetOut.Write(Health);
1146 NetOut.Write(Armor);
1147 NetOut.Write(Air);
1148 NetOut.Write(JetFuel);
1149 NetOut.Write(Lives);
1150 NetOut.Write(Team);
1152 for I := WP_FIRST to WP_LAST do
1153 NetOut.Write(Byte(FWeapon[I]));
1155 for I := A_BULLETS to A_HIGH do
1156 NetOut.Write(FAmmo[I]);
1158 for I := A_BULLETS to A_HIGH do
1159 NetOut.Write(FMaxAmmo[I]);
1161 for I := MR_SUIT to MR_MAX do
1162 NetOut.Write(LongWord(FMegaRulez[I]));
1164 NetOut.Write(Byte(R_ITEM_BACKPACK in FRulez));
1165 NetOut.Write(Byte(R_KEY_RED in FRulez));
1166 NetOut.Write(Byte(R_KEY_GREEN in FRulez));
1167 NetOut.Write(Byte(R_KEY_BLUE in FRulez));
1168 NetOut.Write(Byte(R_BERSERK in FRulez));
1170 NetOut.Write(Frags);
1171 NetOut.Write(Death);
1173 NetOut.Write(CurrWeap);
1175 NetOut.Write(Byte(FSpectator));
1176 NetOut.Write(Byte(FGhost));
1177 NetOut.Write(Byte(FPhysics));
1178 NetOut.Write(Byte(FNoRespawn));
1179 NetOut.Write(Byte(FJetpack));
1180 NetOut.Write(FFireTime);
1181 NetOut.Write(Byte(FFlaming));
1182 NetOut.Write(FSpawnInvul);
1183 end;
1185 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1186 end;
1188 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
1189 begin
1190 NetOut.Write(Byte(NET_MSG_PLRDMG));
1191 NetOut.Write(PID);
1192 NetOut.Write(Kind);
1193 NetOut.Write(Attacker);
1194 NetOut.Write(Value);
1195 NetOut.Write(VX);
1196 NetOut.Write(VY);
1198 g_Net_Host_Send(ID, False, NET_CHAN_PLAYER);
1199 end;
1201 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
1202 begin
1203 NetOut.Write(Byte(NET_MSG_PLRDIE));
1204 NetOut.Write(PID);
1205 NetOut.Write(KillType);
1206 NetOut.Write(DeathType);
1207 NetOut.Write(Attacker);
1209 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1210 end;
1212 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
1213 begin
1214 NetOut.Write(Byte(NET_MSG_PLRFIRE));
1215 NetOut.Write(PID);
1216 NetOut.Write(Weapon);
1217 NetOut.Write(X);
1218 NetOut.Write(Y);
1219 NetOut.Write(AX);
1220 NetOut.Write(AY);
1221 NetOut.Write(ShotID);
1223 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1224 end;
1226 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
1227 begin
1228 NetOut.Write(Byte(NET_MSG_PLRDEL));
1229 NetOut.Write(PID);
1231 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1232 end;
1234 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
1235 var
1236 Pl: TPlayer;
1237 begin
1238 Pl := g_Player_Get(PID);
1239 if Pl = nil then Exit;
1241 NetOut.Write(Byte(NET_MSG_PLRSET));
1242 NetOut.Write(PID);
1243 NetOut.Write(Pl.Name);
1244 if Mdl = '' then
1245 NetOut.Write(Pl.Model.Name)
1246 else
1247 NetOut.Write(Mdl);
1248 NetOut.Write(Pl.FColor.R);
1249 NetOut.Write(Pl.FColor.G);
1250 NetOut.Write(Pl.FColor.B);
1251 NetOut.Write(Pl.Team);
1253 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1254 end;
1256 // ITEM (SEND)
1258 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1259 var
1260 it: PItem;
1261 tt: Byte;
1262 begin
1263 it := g_Items_ByIdx(IID);
1265 NetOut.Write(Byte(NET_MSG_ISPAWN));
1266 NetOut.Write(IID);
1267 NetOut.Write(Byte(Quiet));
1268 tt := it.ItemType;
1269 if it.dropped then tt := tt or $80;
1270 NetOut.Write(tt);
1271 NetOut.Write(Byte(it.Fall));
1272 NetOut.Write(Byte(it.Respawnable));
1273 NetOut.Write(it.Obj.X);
1274 NetOut.Write(it.Obj.Y);
1275 NetOut.Write(it.Obj.Vel.X);
1276 NetOut.Write(it.Obj.Vel.Y);
1278 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1279 end;
1281 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1282 begin
1283 NetOut.Write(Byte(NET_MSG_IDEL));
1284 NetOut.Write(IID);
1285 NetOut.Write(Byte(Quiet));
1287 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1288 end;
1290 // PANEL
1292 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
1293 var
1294 TP: TPanel;
1295 begin
1296 TP := g_Map_PanelByGUID(PGUID);
1297 if (TP = nil) then exit;
1299 with TP do
1300 begin
1301 NetOut.Write(Byte(NET_MSG_PTEX));
1302 NetOut.Write(LongWord(PGUID));
1303 NetOut.Write(FCurTexture);
1304 NetOut.Write(FCurFrame);
1305 NetOut.Write(FCurFrameCount);
1306 NetOut.Write(AnimLoop);
1307 end;
1309 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1310 end;
1312 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
1313 var
1314 TP: TPanel;
1315 mpflags: Byte = 0;
1316 begin
1317 TP := g_Map_PanelByGUID(PGUID);
1318 if (TP = nil) then exit;
1320 NetOut.Write(Byte(NET_MSG_PSTATE));
1321 NetOut.Write(LongWord(PGUID));
1322 NetOut.Write(Byte(TP.Enabled));
1323 NetOut.Write(TP.LiftType);
1324 NetOut.Write(TP.X);
1325 NetOut.Write(TP.Y);
1326 NetOut.Write(Word(TP.Width));
1327 NetOut.Write(Word(TP.Height));
1328 // mplats
1329 NetOut.Write(LongInt(TP.movingSpeedX));
1330 NetOut.Write(LongInt(TP.movingSpeedY));
1331 NetOut.Write(LongInt(TP.movingStartX));
1332 NetOut.Write(LongInt(TP.movingStartY));
1333 NetOut.Write(LongInt(TP.movingEndX));
1334 NetOut.Write(LongInt(TP.movingEndY));
1335 NetOut.Write(LongInt(TP.sizeSpeedX));
1336 NetOut.Write(LongInt(TP.sizeSpeedY));
1337 NetOut.Write(LongInt(TP.sizeEndX));
1338 NetOut.Write(LongInt(TP.sizeEndY));
1339 if TP.movingActive then mpflags := mpflags or 1;
1340 if TP.moveOnce then mpflags := mpflags or 2;
1341 NetOut.Write(Byte(mpflags));
1343 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1344 end;
1346 // TRIGGER
1348 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
1349 begin
1350 if gTriggers = nil then Exit;
1351 if T.Sound = nil then Exit;
1353 NetOut.Write(Byte(NET_MSG_TSOUND));
1354 NetOut.Write(T.ClientID);
1355 NetOut.Write(Byte(T.Sound.IsPlaying));
1356 NetOut.Write(LongWord(T.Sound.GetPosition));
1357 NetOut.Write(T.SoundPlayCount);
1359 g_Net_Host_Send(ID, True);
1360 end;
1362 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
1363 begin
1364 NetOut.Write(Byte(NET_MSG_TMUSIC));
1365 NetOut.Write(gMusic.Name);
1366 NetOut.Write(Byte(gMusic.IsPlaying));
1367 NetOut.Write(LongWord(gMusic.GetPosition));
1368 NetOut.Write(Byte(gMusic.SpecPause or gMusic.IsPaused));
1370 g_Net_Host_Send(ID, True);
1371 end;
1373 // MONSTER
1375 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
1376 var
1377 M: TMonster;
1378 begin
1379 M := g_Monsters_ByUID(UID);
1380 if M = nil then
1381 Exit;
1383 with M do
1384 begin
1385 NetOut.Write(Byte(NET_MSG_MSPAWN));
1386 NetOut.Write(UID);
1387 NetOut.Write(MonsterType);
1388 NetOut.Write(MonsterState);
1389 NetOut.Write(MonsterAnim);
1390 NetOut.Write(MonsterTargetUID);
1391 NetOut.Write(MonsterTargetTime);
1392 NetOut.Write(MonsterBehaviour);
1393 NetOut.Write(MonsterSleep);
1394 NetOut.Write(MonsterHealth);
1395 NetOut.Write(MonsterAmmo);
1396 NetOut.Write(GameX);
1397 NetOut.Write(GameY);
1398 NetOut.Write(GameVelX);
1399 NetOut.Write(GameVelY);
1400 NetOut.Write(Byte(GameDirection));
1401 end;
1403 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1404 end;
1406 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
1407 var
1408 M: TMonster;
1409 begin
1410 M := g_Monsters_ByUID(UID);
1411 if M = nil then Exit;
1413 NetOut.Write(Byte(NET_MSG_MPOS));
1414 NetOut.Write(UID);
1416 with M do
1417 begin
1418 NetOut.Write(GameX);
1419 NetOut.Write(GameY);
1420 NetOut.Write(GameVelX);
1421 NetOut.Write(GameVelY);
1422 NetOut.Write(Byte(GameDirection));
1423 end;
1425 g_Net_Host_Send(ID, False, NET_CHAN_MONSTERPOS);
1426 end;
1428 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
1429 var
1430 M: TMonster;
1431 begin
1432 M := g_Monsters_ByUID(UID);
1433 if M = nil then Exit;
1435 NetOut.Write(Byte(NET_MSG_MSTATE));
1436 NetOut.Write(UID);
1438 with M do
1439 begin
1440 NetOut.Write(MonsterState);
1441 NetOut.Write(ForcedAnim);
1442 NetOut.Write(MonsterTargetUID);
1443 NetOut.Write(MonsterTargetTime);
1444 NetOut.Write(MonsterSleep);
1445 NetOut.Write(MonsterHealth);
1446 NetOut.Write(MonsterAmmo);
1447 NetOut.Write(MonsterPain);
1448 NetOut.Write(Byte(AnimIsReverse));
1449 NetOut.Write(FFireTime);
1450 end;
1452 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1453 end;
1455 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
1456 begin
1457 NetOut.Write(Byte(NET_MSG_MSHOT));
1458 NetOut.Write(UID);
1459 NetOut.Write(X);
1460 NetOut.Write(Y);
1461 NetOut.Write(VX);
1462 NetOut.Write(VY);
1464 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1465 end;
1467 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
1468 var
1469 M: TMonster;
1470 begin
1471 M := g_Monsters_ByUID(UID);
1472 if M = nil then Exit;
1474 NetOut.Write(Byte(NET_MSG_MDEL));
1475 NetOut.Write(UID);
1477 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1478 end;
1480 // MISC
1482 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
1483 begin
1484 NetOut.Write(Byte(NET_MSG_TIME_SYNC));
1485 NetOut.Write(Time);
1487 g_Net_Host_Send(ID, False, NET_CHAN_SERVICE);
1488 end;
1490 procedure MH_SEND_VoteEvent(EvType: Byte;
1491 StrArg1: string = 'a'; StrArg2: string = 'b';
1492 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
1493 ID: Integer = NET_EVERYONE);
1494 begin
1495 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
1496 NetOut.Write(EvType);
1497 NetOut.Write(IntArg1);
1498 NetOut.Write(IntArg2);
1499 NetOut.Write(StrArg1);
1500 NetOut.Write(StrArg2);
1502 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1503 end;
1505 // CLIENT MESSAGES //
1507 // GAME
1509 procedure MC_RECV_Chat(var M: TMsg);
1510 var
1511 Txt: string;
1512 Mode: Byte;
1513 begin
1514 Txt := M.ReadString();
1515 Mode := M.ReadByte();
1517 if Mode <> NET_CHAT_SYSTEM then
1518 begin
1519 if Mode = NET_CHAT_PLAYER then
1520 begin
1521 g_Console_Add(Txt, True);
1522 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1523 g_Game_ChatSound(b_Text_Unformat(Txt));
1524 end else
1525 if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then
1526 begin
1527 if gPlayer1.Team = TEAM_RED then
1528 g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True);
1529 if gPlayer1.Team = TEAM_BLUE then
1530 g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True);
1531 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1532 g_Game_ChatSound(b_Text_Unformat(Txt));
1533 end;
1534 end else
1535 g_Console_Add(Txt, True);
1536 end;
1538 procedure MC_RECV_Effect(var M: TMsg);
1539 var
1540 Kind: Byte;
1541 X, Y: Integer;
1542 Ang: SmallInt;
1543 Anim: TAnimation;
1544 ID: LongWord;
1545 begin
1546 if not gGameOn then Exit;
1547 Kind := M.ReadByte();
1548 X := M.ReadLongInt();
1549 Y := M.ReadLongInt();
1550 Ang := M.ReadSmallInt();
1552 case Kind of
1553 NET_GFX_SPARK:
1554 g_GFX_Spark(X, Y, 2 + Random(2), Ang, 0, 0);
1556 NET_GFX_TELE:
1557 begin
1558 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
1559 begin
1560 Anim := TAnimation.Create(ID, False, 3);
1561 g_GFX_OnceAnim(X, Y, Anim);
1562 Anim.Free();
1563 end;
1564 if Ang = 1 then
1565 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
1566 end;
1568 NET_GFX_EXPLODE:
1569 begin
1570 if g_Frames_Get(ID, 'FRAMES_EXPLODE_ROCKET') then
1571 begin
1572 Anim := TAnimation.Create(ID, False, 6);
1573 Anim.Blending := False;
1574 g_GFX_OnceAnim(X-64, Y-64, Anim);
1575 Anim.Free();
1576 end;
1577 if Ang = 1 then
1578 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X, Y);
1579 end;
1581 NET_GFX_BFGEXPL:
1582 begin
1583 if g_Frames_Get(ID, 'FRAMES_EXPLODE_BFG') then
1584 begin
1585 Anim := TAnimation.Create(ID, False, 6);
1586 Anim.Blending := False;
1587 g_GFX_OnceAnim(X-64, Y-64, Anim);
1588 Anim.Free();
1589 end;
1590 if Ang = 1 then
1591 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X, Y);
1592 end;
1594 NET_GFX_BFGHIT:
1595 begin
1596 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1597 begin
1598 Anim := TAnimation.Create(ID, False, 4);
1599 g_GFX_OnceAnim(X-32, Y-32, Anim);
1600 Anim.Free();
1601 end;
1602 end;
1604 NET_GFX_FIRE:
1605 begin
1606 if g_Frames_Get(ID, 'FRAMES_FIRE') then
1607 begin
1608 Anim := TAnimation.Create(ID, False, 4);
1609 g_GFX_OnceAnim(X, Y, Anim);
1610 Anim.Free();
1611 end;
1612 if Ang = 1 then
1613 g_Sound_PlayExAt('SOUND_FIRE', X, Y);
1614 end;
1616 NET_GFX_RESPAWN:
1617 begin
1618 if g_Frames_Get(ID, 'FRAMES_ITEM_RESPAWN') then
1619 begin
1620 Anim := TAnimation.Create(ID, False, 4);
1621 g_GFX_OnceAnim(X, Y, Anim);
1622 Anim.Free();
1623 end;
1624 if Ang = 1 then
1625 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
1626 end;
1628 NET_GFX_SHELL1:
1629 g_Player_CreateShell(X, Y, 0, -2, SHELL_BULLET);
1631 NET_GFX_SHELL2:
1632 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1634 NET_GFX_SHELL3:
1635 begin
1636 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1637 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1638 end;
1639 end;
1640 end;
1642 procedure MC_RECV_Sound(var M: TMsg);
1643 var
1644 Name: string;
1645 X, Y: Integer;
1646 Pos: Boolean;
1647 begin
1648 Name := M.ReadString();
1649 Pos := M.ReadByte() <> 0;
1650 if Pos then
1651 begin
1652 X := M.ReadLongInt();
1653 Y := M.ReadLongInt();
1654 g_Sound_PlayExAt(Name, X, Y);
1655 end
1656 else
1657 g_Sound_PlayEx(Name);
1658 end;
1660 procedure MC_RECV_CreateShot(var M: TMsg);
1661 var
1662 I, X, Y, XV, YV: Integer;
1663 Timeout: LongWord;
1664 Target, Spawner: Word;
1665 ShType: Byte;
1666 begin
1667 I := M.ReadLongInt();
1668 ShType := M.ReadByte();
1669 Target := M.ReadWord();
1670 Spawner := M.ReadWord();
1671 Timeout := M.ReadLongWord();
1672 X := M.ReadLongInt();
1673 Y := M.ReadLongInt();
1674 XV := M.ReadLongInt();
1675 YV := M.ReadLongInt();
1677 I := g_Weapon_CreateShot(I, ShType, Spawner, Target, X, Y, XV, YV);
1678 if (Shots <> nil) and (I <= High(Shots)) then
1679 begin
1680 Shots[I].Timeout := Timeout;
1681 //Shots[I].Target := Target; // TODO: find a use for Target later
1682 end;
1683 end;
1685 procedure MC_RECV_UpdateShot(var M: TMsg);
1686 var
1687 I, TX, TY, TXV, TYV: Integer;
1688 begin
1689 I := M.ReadLongInt();
1690 TX := M.ReadLongInt();
1691 TY := M.ReadLongInt();
1692 TXV := M.ReadLongInt();
1693 TYV := M.ReadLongInt();
1695 if (Shots <> nil) and (I <= High(Shots)) then
1696 with (Shots[i]) do
1697 begin
1698 Obj.X := TX;
1699 Obj.Y := TY;
1700 Obj.Vel.X := TXV;
1701 Obj.Vel.Y := TYV;
1702 end;
1703 end;
1705 procedure MC_RECV_DeleteShot(var M: TMsg);
1706 var
1707 I, X, Y: Integer;
1708 L: Boolean;
1709 begin
1710 if not gGameOn then Exit;
1711 I := M.ReadLongInt();
1712 L := (M.ReadByte() <> 0);
1713 X := M.ReadLongInt();
1714 Y := M.ReadLongInt();
1716 g_Weapon_DestroyShot(I, X, Y, L);
1717 end;
1719 procedure MC_RECV_GameStats(var M: TMsg);
1720 begin
1721 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1722 begin
1723 gTeamStat[TEAM_RED].Goals := M.ReadSmallInt();
1724 gTeamStat[TEAM_BLUE].Goals := M.ReadSmallInt();
1725 end
1726 else
1727 if gGameSettings.GameMode = GM_COOP then
1728 begin
1729 gCoopMonstersKilled := M.ReadWord();
1730 gCoopSecretsFound := M.ReadWord();
1731 end;
1732 end;
1734 procedure MC_RECV_CoopStats(var M: TMsg);
1735 begin
1736 gTotalMonsters := M.ReadLongInt();
1737 gSecretsCount := M.ReadLongInt();
1738 gCoopTotalMonstersKilled := M.ReadWord();
1739 gCoopTotalSecretsFound := M.ReadWord();
1740 gCoopTotalMonsters := M.ReadWord();
1741 gCoopTotalSecrets := M.ReadWord();
1742 end;
1744 procedure MC_RECV_GameEvent(var M: TMsg);
1745 var
1746 EvType: Byte;
1747 EvNum: Integer;
1748 EvStr: string;
1749 EvTime: LongWord;
1750 BHash: Boolean;
1751 EvHash: TMD5Digest;
1752 pl: TPlayer;
1753 i1, i2: TStrings_Locale;
1754 pln: String;
1755 cnt: Byte;
1756 goodCmd: Boolean = true;
1757 begin
1758 FillChar(EvHash, Sizeof(EvHash), 0);
1759 EvType := M.ReadByte();
1760 EvNum := M.ReadLongInt();
1761 EvStr := M.ReadString();
1762 gLastMap := M.ReadByte() <> 0;
1763 if gLastMap and (gGameSettings.GameMode = GM_COOP) then gStatsOff := True;
1764 gStatsPressed := True;
1765 EvTime := M.ReadLongWord();
1766 BHash := M.ReadByte() <> 0;
1767 if BHash then
1768 EvHash := M.ReadMD5();
1770 gTime := EvTime;
1772 if (g_Res_received_map_start <> 0) then
1773 begin
1774 if (g_Res_received_map_start < 0) then exit;
1775 goodCmd := false;
1776 case EvType of
1777 NET_EV_MAPSTART: goodCmd := true;
1778 NET_EV_MAPEND: goodCmd := true;
1779 NET_EV_PLAYER_KICK: goodCmd := true;
1780 NET_EV_PLAYER_BAN: goodCmd := true;
1781 NET_EV_LMS_WARMUP: goodCmd := true;
1782 end;
1783 if not goodCmd then exit;
1784 end;
1786 case EvType of
1787 NET_EV_MAPSTART:
1788 begin
1789 if (g_Res_received_map_start <> 0) then
1790 begin
1791 g_Res_received_map_start := -1;
1792 end
1793 else
1794 begin
1795 gGameOn := False;
1796 g_Game_ClearLoading();
1797 g_Game_StopAllSounds(True);
1799 gSwitchGameMode := Byte(EvNum);
1800 gGameSettings.GameMode := gSwitchGameMode;
1802 gWADHash := EvHash;
1803 if not g_Game_StartMap(false{asMegawad}, EvStr, True) then
1804 begin
1805 if not isWadPath(EvStr) then
1806 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + EvStr]))
1807 else
1808 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [EvStr]));
1809 Exit;
1810 end;
1812 MC_SEND_FullStateRequest;
1813 end;
1814 end;
1816 NET_EV_MAPEND:
1817 begin
1818 gLMSRespawn := LMS_RESPAWN_NONE;
1819 gLMSRespawnTime := 0;
1820 if (g_Res_received_map_start <> 0) then
1821 begin
1822 g_Res_received_map_start := -1;
1823 end
1824 else
1825 begin
1826 gMissionFailed := EvNum <> 0;
1827 gExit := EXIT_ENDLEVELCUSTOM;
1828 end;
1829 end;
1831 NET_EV_RCON:
1832 begin
1833 case EvNum of
1834 NET_RCON_NOAUTH:
1835 g_Console_Add(_lc[I_NET_RCON_NOAUTH], True);
1836 NET_RCON_PWGOOD:
1837 g_Console_Add(_lc[I_NET_RCON_PWD_VALID], True);
1838 NET_RCON_PWBAD:
1839 g_Console_Add(_lc[I_NET_RCON_PWD_INVALID], True);
1840 end;
1841 end;
1843 NET_EV_CHANGE_TEAM:
1844 begin
1845 if EvNum = TEAM_RED then
1846 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True);
1847 if EvNum = TEAM_BLUE then
1848 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True);
1849 end;
1851 NET_EV_PLAYER_KICK:
1852 begin
1853 g_Console_Add(Format(_lc[I_PLAYER_KICK], [EvStr]), True);
1854 if (g_Res_received_map_start <> 0) then g_Res_received_map_start := -1;
1855 end;
1857 NET_EV_PLAYER_BAN:
1858 begin
1859 g_Console_Add(Format(_lc[I_PLAYER_BAN], [EvStr]), True);
1860 if (g_Res_received_map_start <> 0) then g_Res_received_map_start := -1;
1861 end;
1863 NET_EV_LMS_WARMUP:
1864 begin
1865 if EvNum > 0 then
1866 begin
1867 gLMSRespawn := LMS_RESPAWN_WARMUP;
1868 gLMSRespawnTime := gTime + EvNum;
1869 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [EvNum div 1000]), True);
1870 end
1871 else if gPlayer1 = nil then
1872 begin
1873 g_Console_Add(_lc[I_PLAYER_SPECT4], True);
1874 end;
1875 end;
1877 NET_EV_LMS_SURVIVOR:
1878 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True);
1880 NET_EV_BIGTEXT:
1881 g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum));
1883 NET_EV_SCORE:
1884 begin
1885 pl := g_Player_Get(EvNum and $FFFF);
1886 if pl = nil then
1887 pln := '?'
1888 else
1889 pln := pl.Name;
1890 cnt := (EvNum shr 16) and $FF;
1891 if Pos('w', EvStr) = 0 then
1892 begin
1893 // Default score
1894 if Pos('t', EvStr) = 0 then
1895 begin
1896 // Player +/- score
1897 if Pos('-', EvStr) = 0 then
1898 begin
1899 if Pos('e', EvStr) = 0 then
1900 i1 := I_PLAYER_SCORE_ADD_OWN
1901 else
1902 i1 := I_PLAYER_SCORE_ADD_ENEMY;
1903 end else
1904 begin
1905 if Pos('e', EvStr) = 0 then
1906 i1 := I_PLAYER_SCORE_SUB_OWN
1907 else
1908 i1 := I_PLAYER_SCORE_SUB_ENEMY;
1909 end;
1910 // Which team
1911 if Pos('r', EvStr) > 0 then
1912 i2 := I_PLAYER_SCORE_TO_RED
1913 else
1914 i2 := I_PLAYER_SCORE_TO_BLUE;
1915 g_Console_Add(Format(_lc[i1], [pln, cnt, _lc[i2]]), True);
1916 end else
1917 begin
1918 // Team +/- score
1919 if Pos('-', EvStr) = 0 then
1920 i1 := I_PLAYER_SCORE_ADD_TEAM
1921 else
1922 i1 := I_PLAYER_SCORE_SUB_TEAM;
1923 // Which team
1924 if Pos('r', EvStr) > 0 then
1925 i2 := I_PLAYER_SCORE_RED
1926 else
1927 i2 := I_PLAYER_SCORE_BLUE;
1928 g_Console_Add(Format(_lc[i1], [_lc[i2], cnt]), True);
1929 end;
1930 end else
1931 begin
1932 // Game Win
1933 if Pos('e', EvStr) = 0 then
1934 i1 := I_PLAYER_SCORE_WIN_OWN
1935 else
1936 i1 := I_PLAYER_SCORE_WIN_ENEMY;
1937 // Which team
1938 if Pos('r', EvStr) > 0 then
1939 i2 := I_PLAYER_SCORE_TO_RED
1940 else
1941 i2 := I_PLAYER_SCORE_TO_BLUE;
1942 g_Console_Add(Format(_lc[i1], [pln, _lc[i2]]), True);
1943 end;
1944 end;
1946 NET_EV_SCORE_MSG:
1947 begin
1948 if EvNum = TEAM_RED then
1949 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1950 if EvNum = TEAM_BLUE then
1951 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1952 if EvNum = -TEAM_RED then
1953 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1954 if EvNum = -TEAM_BLUE then
1955 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1956 end;
1958 NET_EV_LMS_START:
1959 begin
1960 g_Player_RemoveAllCorpses;
1961 gLMSRespawn := LMS_RESPAWN_NONE;
1962 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
1963 end;
1965 NET_EV_LMS_WIN:
1966 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(EvStr)]), 144);
1968 NET_EV_TLMS_WIN:
1969 begin
1970 if EvNum = TEAM_RED then
1971 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
1972 if EvNum = TEAM_BLUE then
1973 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
1974 end;
1976 NET_EV_LMS_LOSE:
1977 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
1979 NET_EV_LMS_DRAW:
1980 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
1982 NET_EV_LMS_NOSPAWN:
1983 g_Console_Add(_lc[I_PLAYER_SPECT4], True);
1985 NET_EV_KILLCOMBO:
1986 g_Game_Announce_KillCombo(EvNum);
1988 NET_EV_PLAYER_TOUCH:
1989 begin
1990 pl := g_Player_Get(EvNum);
1991 if pl <> nil then
1992 pl.Touch();
1993 end;
1995 NET_EV_SECRET:
1996 begin
1997 pl := g_Player_Get(EvNum);
1998 if pl <> nil then
1999 begin
2000 g_Console_Add(Format(_lc[I_PLAYER_SECRET], [pl.Name]), True);
2001 g_Sound_PlayEx('SOUND_GAME_SECRET');
2002 end;
2003 end;
2005 NET_EV_INTER_READY:
2006 begin
2007 pl := g_Player_Get(EvNum);
2008 if pl <> nil then pl.FReady := (EvStr = 'Y');
2009 end;
2010 end;
2011 end;
2013 procedure MC_RECV_FlagEvent(var M: TMsg);
2014 var
2015 PID: Word;
2016 Pl: TPlayer;
2017 EvType: Byte;
2018 Fl, a: Byte;
2019 Quiet: Boolean;
2020 s, ts: string;
2021 begin
2022 EvType := M.ReadByte();
2023 Fl := M.ReadByte();
2025 if Fl = FLAG_NONE then Exit;
2027 Quiet := (M.ReadByte() <> 0);
2028 PID := M.ReadWord();
2030 gFlags[Fl].State := M.ReadByte();
2031 gFlags[Fl].CaptureTime := M.ReadLongWord();
2032 gFlags[Fl].Obj.X := M.ReadLongInt();
2033 gFlags[Fl].Obj.Y := M.ReadLongInt();
2034 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
2035 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
2037 Pl := g_Player_Get(PID);
2038 if (Pl = nil) and
2039 (EvType <> FLAG_STATE_NORMAL) and
2040 (EvType <> FLAG_STATE_DROPPED) and
2041 (EvType <> FLAG_STATE_RETURNED) then
2042 Exit;
2044 case EvType of
2045 FLAG_STATE_NORMAL:
2046 begin
2047 if Quiet or (Pl = nil) then Exit;
2049 if Fl = FLAG_RED then
2050 s := _lc[I_PLAYER_FLAG_RED]
2051 else
2052 s := _lc[I_PLAYER_FLAG_BLUE];
2054 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2056 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2057 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2058 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2059 a := 0
2060 else
2061 a := 1;
2063 if not sound_ret_flag[a].IsPlaying() then
2064 sound_ret_flag[a].Play();
2065 end;
2067 FLAG_STATE_CAPTURED:
2068 begin
2069 if (Pl <> nil) then Pl.SetFlag(Fl);
2071 if Quiet then Exit;
2073 if Fl = FLAG_RED then
2074 s := _lc[I_PLAYER_FLAG_RED]
2075 else
2076 s := _lc[I_PLAYER_FLAG_BLUE];
2078 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [Pl.Name, s]), True);
2079 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
2081 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2082 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2083 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2084 a := 0
2085 else
2086 a := 1;
2088 if not sound_get_flag[a].IsPlaying() then
2089 sound_get_flag[a].Play();
2090 end;
2092 FLAG_STATE_DROPPED:
2093 begin
2094 if (Pl <> nil) then Pl.SetFlag(FLAG_NONE);
2096 if Quiet or (Pl = nil) then Exit;
2098 if Fl = FLAG_RED then
2099 s := _lc[I_PLAYER_FLAG_RED]
2100 else
2101 s := _lc[I_PLAYER_FLAG_BLUE];
2103 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [Pl.Name, s]), True);
2104 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
2106 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2107 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2108 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2109 a := 0
2110 else
2111 a := 1;
2113 if not sound_lost_flag[a].IsPlaying() then
2114 sound_lost_flag[a].Play();
2115 end;
2117 FLAG_STATE_SCORED:
2118 begin
2119 g_Map_ResetFlag(FLAG_RED);
2120 g_Map_ResetFlag(FLAG_BLUE);
2121 if Quiet or (Pl = nil) then Exit;
2122 Pl.SetFlag(FLAG_NONE);
2124 if Fl = FLAG_RED then
2125 s := _lc[I_PLAYER_FLAG_RED]
2126 else
2127 s := _lc[I_PLAYER_FLAG_BLUE];
2129 ts := Format('%.4d', [gFlags[Fl].CaptureTime]);
2130 Insert('.', ts, Length(ts) + 1 - 3);
2131 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [Pl.Name, s, ts]), True);
2132 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
2134 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2135 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2136 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2137 a := 0
2138 else
2139 a := 1;
2141 if not sound_cap_flag[a].IsPlaying() then
2142 sound_cap_flag[a].Play();
2143 end;
2145 FLAG_STATE_RETURNED:
2146 begin
2147 g_Map_ResetFlag(Fl);
2148 if Quiet then Exit;
2150 if Fl = FLAG_RED then
2151 s := _lc[I_PLAYER_FLAG_RED]
2152 else
2153 s := _lc[I_PLAYER_FLAG_BLUE];
2155 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2157 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2158 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2159 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2160 a := 0
2161 else
2162 a := 1;
2164 if not sound_ret_flag[a].IsPlaying() then
2165 sound_ret_flag[a].Play();
2166 end;
2167 end;
2168 end;
2170 procedure MC_RECV_GameSettings(var M: TMsg);
2171 begin
2172 gGameSettings.GameMode := M.ReadByte();
2173 gGameSettings.GoalLimit := M.ReadWord();
2174 gGameSettings.TimeLimit := M.ReadWord();
2175 gGameSettings.MaxLives := M.ReadByte();
2176 gGameSettings.Options := M.ReadLongWord();
2177 end;
2179 // PLAYER
2181 function MC_RECV_PlayerCreate(var M: TMsg): Word;
2182 var
2183 PID, DID: Word;
2184 PName, Model: string;
2185 Color: TRGB;
2186 T: Byte;
2187 Pl: TPlayer;
2188 begin
2189 PID := M.ReadWord();
2190 Pl := g_Player_Get(PID);
2192 PName := M.ReadString();
2193 Model := M.ReadString();
2194 Color.R := M.ReadByte();
2195 Color.G := M.ReadByte();
2196 Color.B := M.ReadByte();
2197 T := M.ReadByte();
2199 Result := 0;
2200 if (PID <> NetPlrUID1) and (PID <> NetPlrUID2) then
2201 begin
2202 if (Pl <> nil) then Exit;
2203 DID := g_Player_Create(Model, Color, T, False);
2204 with g_Player_Get(DID) do
2205 begin
2206 UID := PID;
2207 Name := PName;
2208 Reset(True);
2209 end;
2210 end
2211 else
2212 begin
2213 if (PID = NetPlrUID1) and (gPlayer1 <> nil) then begin
2214 gPlayer1.UID := PID;
2215 gPlayer1.Model.SetColor(Color.R, Color.G, Color.B);
2216 gPlayer1.ChangeTeam(T);
2217 end;
2218 if (PID = NetPlrUID2) and (gPlayer2 <> nil) then begin
2219 gPlayer2.UID := PID;
2220 gPlayer2.Model.SetColor(Color.R, Color.G, Color.B);
2221 gPlayer2.ChangeTeam(T);
2222 end;
2223 end;
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 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2459 e_WriteLog('NET: Player ' + Pl.Name + ' [' + IntToStr(PID) + '] removed.', TMsgType.Notify);
2461 g_Player_Remove(PID);
2463 Result := PID;
2464 end;
2466 function MC_RECV_PlayerFire(var M: TMsg): Word;
2467 var
2468 PID: Word;
2469 Weap: Byte;
2470 Pl: TPlayer;
2471 X, Y, AX, AY: Integer;
2472 SHID: Integer;
2473 begin
2474 Result := 0;
2475 if not gGameOn then Exit;
2476 PID := M.ReadWord();
2477 Pl := g_Player_Get(PID);
2478 if Pl = nil then Exit;
2480 Weap := M.ReadByte();
2481 X := M.ReadLongInt();
2482 Y := M.ReadLongInt();
2483 AX := M.ReadLongInt();
2484 AY := M.ReadLongInt();
2485 SHID := M.ReadLongInt();
2487 with Pl do
2488 if alive then NetFire(Weap, X, Y, AX, AY, SHID);
2489 end;
2491 procedure MC_RECV_PlayerSettings(var M: TMsg);
2492 var
2493 TmpName: string;
2494 TmpModel: string;
2495 TmpColor: TRGB;
2496 TmpTeam: Byte;
2497 Pl: TPlayer;
2498 PID: Word;
2499 begin
2500 PID := M.ReadWord();
2501 Pl := g_Player_Get(PID);
2502 if Pl = nil then Exit;
2504 TmpName := M.ReadString();
2505 TmpModel := M.ReadString();
2506 TmpColor.R := M.ReadByte();
2507 TmpColor.G := M.ReadByte();
2508 TmpColor.B := M.ReadByte();
2509 TmpTeam := M.ReadByte();
2511 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
2512 begin
2513 Pl.ChangeTeam(TmpTeam);
2514 if gPlayer1 = Pl then
2515 gPlayer1Settings.Team := TmpTeam;
2516 if gPlayer2 = Pl then
2517 gPlayer2Settings.Team := TmpTeam;
2518 end else
2519 Pl.SetColor(TmpColor);
2521 if Pl.Name <> TmpName then
2522 begin
2523 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
2524 Pl.Name := TmpName;
2525 end;
2527 if TmpModel <> Pl.Model.Name then
2528 Pl.SetModel(TmpModel);
2529 end;
2531 // ITEM
2533 procedure MC_RECV_ItemSpawn(var M: TMsg);
2534 var
2535 ID: Word;
2536 AID: DWord;
2537 X, Y, VX, VY: Integer;
2538 T: Byte;
2539 Quiet, Fall{, Resp}: Boolean;
2540 Anim: TAnimation;
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 if g_Frames_Get(AID, 'FRAMES_ITEM_RESPAWN') then
2565 begin
2566 Anim := TAnimation.Create(AID, False, 4);
2567 g_GFX_OnceAnim(X+(it.Obj.Rect.Width div 2)-16, Y+(it.Obj.Rect.Height div 2)-16, Anim);
2568 Anim.Free();
2569 end;
2570 end;
2571 end;
2573 procedure MC_RECV_ItemDestroy(var M: TMsg);
2574 var
2575 ID: Word;
2576 Quiet: Boolean;
2577 begin
2578 if not gGameOn then Exit;
2579 ID := M.ReadWord();
2580 Quiet := M.ReadByte() <> 0;
2582 if not g_Items_ValidId(ID) then exit;
2584 if not Quiet then g_Items_EmitPickupSound(ID);
2586 g_Items_Remove(ID);
2587 end;
2589 // PANEL
2591 procedure MC_RECV_PanelTexture(var M: TMsg);
2592 var
2593 TP: TPanel;
2594 PGUID: Integer;
2595 Tex, Fr: Integer;
2596 Loop, Cnt: Byte;
2597 begin
2598 if not gGameOn then Exit;
2600 PGUID := Integer(M.ReadLongWord());
2601 Tex := M.ReadLongInt();
2602 Fr := M.ReadLongInt();
2603 Cnt := M.ReadByte();
2604 Loop := M.ReadByte();
2606 TP := g_Map_PanelByGUID(PGUID);
2607 if (TP <> nil) then
2608 begin
2609 // switch texture
2610 TP.SetTexture(Tex, Loop);
2611 TP.SetFrame(Fr, Cnt);
2612 end;
2613 end;
2615 procedure MC_RECV_PanelState(var M: TMsg);
2616 var
2617 PGUID: Integer;
2618 E: Boolean;
2619 Lift: Byte;
2620 X, Y, W, H: Integer;
2621 TP: TPanel;
2622 speedX, speedY, startX, startY, endX, endY: Integer;
2623 sizeSpX, sizeSpY, sizeEX, sizeEY: Integer;
2624 mpflags: Byte;
2625 begin
2626 if not gGameOn then Exit;
2628 PGUID := Integer(M.ReadLongWord());
2629 E := (M.ReadByte() <> 0);
2630 Lift := M.ReadByte();
2631 X := M.ReadLongInt();
2632 Y := M.ReadLongInt();
2633 W := M.ReadWord();
2634 H := M.ReadWord();
2635 // mplats
2636 speedX := M.ReadLongInt();
2637 speedY := M.ReadLongInt();
2638 startX := M.ReadLongInt();
2639 startY := M.ReadLongInt();
2640 endX := M.ReadLongInt();
2641 endY := M.ReadLongInt();
2642 sizeSpX := M.ReadLongInt();
2643 sizeSpY := M.ReadLongInt();
2644 sizeEX := M.ReadLongInt();
2645 sizeEY := M.ReadLongInt();
2646 mpflags := M.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2648 TP := g_Map_PanelByGUID(PGUID);
2649 if (TP = nil) then exit;
2651 // update lifts state
2652 if TP.isGLift then g_Map_SetLiftGUID(PGUID, Lift);
2654 // update enabled/disabled state for all panels
2655 if E then g_Map_EnableWallGUID(PGUID) else g_Map_DisableWallGUID(PGUID);
2657 // update panel position, as it can be moved (mplat)
2658 TP.X := X;
2659 TP.Y := Y;
2660 TP.Width := W;
2661 TP.Height := H;
2662 // update mplat state
2663 TP.movingSpeedX := speedX;
2664 TP.movingSpeedY := speedY;
2665 TP.movingStartX := startX;
2666 TP.movingStartY := startY;
2667 TP.movingEndX := endX;
2668 TP.movingEndY := endY;
2669 TP.sizeSpeedX := sizeSpX;
2670 TP.sizeSpeedY := sizeSpY;
2671 TP.sizeEndX := sizeEX;
2672 TP.sizeEndY := sizeEY;
2673 TP.movingActive := ((mpflags and 1) <> 0);
2674 TP.moveOnce := ((mpflags and 2) <> 0);
2675 // notify panel of it's position/size change, so it can fix other internal structures
2676 TP.positionChanged();
2677 end;
2679 // TRIGGERS
2681 procedure MC_RECV_TriggerSound(var M: TMsg);
2682 var
2683 SPlaying: Boolean;
2684 SPos, SID: LongWord;
2685 SCount: LongInt;
2686 I: Integer;
2687 begin
2688 if not gGameOn then Exit;
2689 if gTriggers = nil then Exit;
2691 SID := M.ReadLongWord();
2692 SPlaying := M.ReadByte() <> 0;
2693 SPos := M.ReadLongWord();
2694 SCount := M.ReadLongInt();
2696 for I := Low(gTriggers) to High(gTriggers) do
2697 if gTriggers[I].TriggerType = TRIGGER_SOUND then
2698 if gTriggers[I].ClientID = SID then
2699 with gTriggers[I] do
2700 begin
2701 if Sound <> nil then
2702 begin
2703 if SPlaying then
2704 begin
2705 if tgcLocal then
2706 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), tgcVolume/255.0)
2707 else
2708 Sound.PlayPanVolume((tgcPan-127.0)/128.0, tgcVolume/255.0);
2709 Sound.SetPosition(SPos);
2710 end
2711 else
2712 if Sound.IsPlaying then Sound.Stop;
2713 end;
2715 SoundPlayCount := SCount;
2716 end;
2717 end;
2719 procedure MC_RECV_TriggerMusic(var M: TMsg);
2720 var
2721 MName: string;
2722 MPlaying: Boolean;
2723 MPos: LongWord;
2724 MPaused: Boolean;
2725 begin
2726 if not gGameOn then Exit;
2728 MName := M.ReadString();
2729 MPlaying := M.ReadByte() <> 0;
2730 MPos := M.ReadLongWord();
2731 MPaused := M.ReadByte() <> 0;
2732 MPos := MPos+1; //k8: stfu, fpc!
2734 if MPlaying then
2735 begin
2736 gMusic.SetByName(MName);
2737 gMusic.Play(True);
2738 // gMusic.SetPosition(MPos);
2739 gMusic.SpecPause := MPaused;
2740 end
2741 else
2742 if gMusic.IsPlaying then gMusic.Stop;
2743 end;
2745 // MONSTERS
2747 procedure MC_RECV_MonsterSpawn(var M: TMsg);
2748 var
2749 ID: Word;
2750 MType, MState, MDir, MAnim, MBehav: Byte;
2751 X, Y, VX, VY, MTargTime, MHealth, MAmmo, MSleep: Integer;
2752 MTarg: Word;
2753 Mon: TMonster;
2754 begin
2755 ID := M.ReadWord();
2756 Mon := g_Monsters_ByUID(ID);
2757 if Mon <> nil then
2758 Exit;
2760 MType := M.ReadByte();
2761 MState := M.ReadByte();
2762 MAnim := M.ReadByte();
2763 MTarg := M.ReadWord();
2764 MTargTime := M.ReadLongInt();
2765 MBehav := M.ReadByte();
2766 MSleep := M.ReadLongInt();
2767 MHealth := M.ReadLongInt();
2768 MAmmo := M.ReadLongInt();
2770 X := M.ReadLongInt();
2771 Y := M.ReadLongInt();
2772 VX := M.ReadLongInt();
2773 VY := M.ReadLongInt();
2774 MDir := M.ReadByte();
2776 g_Monsters_Create(MType, X, Y, TDirection(MDir), False, ID);
2777 Mon := g_Monsters_ByUID(ID);
2778 if Mon = nil then
2779 Exit;
2781 with Mon do
2782 begin
2784 MonsterAnim := MAnim;
2785 MonsterTargetUID := MTarg;
2786 MonsterTargetTime := MTargTime;
2787 MonsterBehaviour := MBehav;
2788 MonsterSleep := MSleep;
2789 MonsterAmmo := MAmmo;
2790 SetHealth(MHealth);
2792 SetState(MState);
2794 setPosition(X, Y); // this will call positionChanged();
2795 GameVelX := VX;
2796 GameVelY := VY;
2797 end;
2798 end;
2800 procedure MC_RECV_MonsterPos(var M: TMsg);
2801 var
2802 Mon: TMonster;
2803 ID: Word;
2804 X, Y: Integer;
2805 begin
2806 ID := M.ReadWord();
2807 Mon := g_Monsters_ByUID(ID);
2808 if Mon = nil then
2809 Exit;
2811 with Mon do
2812 begin
2813 X := M.ReadLongInt();
2814 Y := M.ReadLongInt();
2815 Mon.setPosition(X, Y); // this will call `positionChanged()`
2816 GameVelX := M.ReadLongInt();
2817 GameVelY := M.ReadLongInt();
2818 GameDirection := TDirection(M.ReadByte());
2819 end;
2820 end;
2822 procedure MC_RECV_MonsterState(var M: TMsg);
2823 var
2824 ID, OldFire: Integer;
2825 MState, MFAnm: Byte;
2826 Mon: TMonster;
2827 AnimRevert: Boolean;
2828 begin
2829 ID := M.ReadWord();
2830 Mon := g_Monsters_ByUID(ID);
2831 if Mon = nil then Exit;
2833 MState := M.ReadByte();
2834 MFAnm := M.ReadByte();
2836 with Mon do
2837 begin
2838 MonsterTargetUID := M.ReadWord();
2839 MonsterTargetTime := M.ReadLongInt();
2840 MonsterSleep := M.ReadLongInt();
2841 MonsterHealth := M.ReadLongInt();
2842 MonsterAmmo := M.ReadLongInt();
2843 MonsterPain := M.ReadLongInt();
2844 AnimRevert := M.ReadByte() <> 0;
2845 OldFire := FFireTime;
2846 FFireTime := M.ReadLongInt();
2847 if (OldFire <= 0) and (FFireTime > 0) then
2848 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
2849 RevertAnim(AnimRevert);
2851 if MonsterState <> MState then
2852 begin
2853 if (MState = MONSTATE_GO) and (MonsterState = MONSTATE_SLEEP) then WakeUpSound();
2854 if (MState = MONSTATE_DIE) then DieSound();
2855 if (MState = MONSTATE_PAIN) then MakeBloodSimple(Min(200, MonsterPain));
2856 if (MState = MONSTATE_ATTACK) then kick(nil);
2857 if (MState = MONSTATE_DEAD) then SetDeadAnim();
2859 SetState(MState, MFAnm);
2860 end;
2861 end;
2862 end;
2864 procedure MC_RECV_MonsterShot(var M: TMsg);
2865 var
2866 ID: Integer;
2867 Mon: TMonster;
2868 X, Y, VX, VY: Integer;
2869 begin
2870 ID := M.ReadWord();
2872 Mon := g_Monsters_ByUID(ID);
2873 if Mon = nil then Exit;
2875 X := M.ReadLongInt();
2876 Y := M.ReadLongInt();
2877 VX := M.ReadLongInt();
2878 VY := M.ReadLongInt();
2880 Mon.ClientAttack(X, Y, VX, VY);
2881 end;
2883 procedure MC_RECV_MonsterDelete(var M: TMsg);
2884 var
2885 ID: Integer;
2886 Mon: TMonster;
2887 begin
2888 ID := M.ReadWord();
2889 Mon := g_Monsters_ByUID(ID);
2890 if Mon = nil then Exit;
2891 Mon.SetState(5);
2892 Mon.MonsterRemoved := True;
2893 end;
2895 procedure MC_RECV_TimeSync(var M: TMsg);
2896 var
2897 Time: LongWord;
2898 begin
2899 Time := M.ReadLongWord();
2901 if gState = STATE_INTERCUSTOM then
2902 gServInterTime := Min(Time, 255);
2903 end;
2905 procedure MC_RECV_VoteEvent(var M: TMsg);
2906 var
2907 EvID: Byte;
2908 Str1, Str2: string;
2909 Int1, Int2: SmallInt;
2910 begin
2911 EvID := M.ReadByte();
2912 Int1 := M.ReadSmallInt();
2913 Int2 := M.ReadSmallInt();
2914 Str1 := M.ReadString();
2915 Str2 := M.ReadString();
2917 case EvID of
2918 NET_VE_STARTED:
2919 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True);
2920 NET_VE_PASSED:
2921 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True);
2922 NET_VE_FAILED:
2923 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
2924 NET_VE_VOTE:
2925 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True);
2926 NET_VE_INPROGRESS:
2927 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True);
2928 end;
2929 end;
2931 // CLIENT SEND
2933 procedure MC_SEND_Info(Password: string);
2934 begin
2935 NetOut.Clear();
2937 NetOut.Write(Byte(NET_MSG_INFO));
2938 NetOut.Write(GAME_VERSION);
2939 NetOut.Write(Password);
2940 NetOut.Write(gPlayer1Settings.Name);
2941 NetOut.Write(gPlayer1Settings.Model);
2942 NetOut.Write(gPlayer1Settings.Color.R);
2943 NetOut.Write(gPlayer1Settings.Color.G);
2944 NetOut.Write(gPlayer1Settings.Color.B);
2945 NetOut.Write(gPlayer1Settings.Team);
2947 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2948 end;
2950 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
2951 begin
2952 NetOut.Write(Byte(NET_MSG_CHAT));
2953 NetOut.Write(Txt);
2954 NetOut.Write(Mode);
2956 g_Net_Client_Send(True, NET_CHAN_CHAT);
2957 end;
2959 procedure MC_SEND_PlayerPos();
2960 var
2961 kByte: Word;
2962 Predict: Boolean;
2963 strafeDir: Byte;
2964 WeaponSelect: Word = 0;
2965 i: Integer;
2966 begin
2967 if not gGameOn then Exit;
2968 if gPlayers = nil then Exit;
2969 if gPlayer1 = nil then Exit;
2971 kByte := 0;
2972 Predict := NetPredictSelf; // and (not NetGotKeys);
2974 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2975 begin
2976 strafeDir := P1MoveButton shr 4;
2977 P1MoveButton := P1MoveButton and $0F;
2979 if gPlayerAction[0, ACTION_MOVELEFT] and (not gPlayerAction[0, ACTION_MOVERIGHT]) then
2980 P1MoveButton := 1
2981 else if (not gPlayerAction[0, ACTION_MOVELEFT]) and gPlayerAction[0, ACTION_MOVERIGHT] then
2982 P1MoveButton := 2
2983 else if (not gPlayerAction[0, ACTION_MOVELEFT]) and (not gPlayerAction[0, ACTION_MOVERIGHT]) then
2984 P1MoveButton := 0;
2986 // strafing
2987 if gPlayerAction[0, ACTION_STRAFE] then
2988 begin
2989 // new strafe mechanics
2990 if (strafeDir = 0) then
2991 strafeDir := P1MoveButton; // start strafing
2992 // now set direction according to strafe (reversed)
2993 if (strafeDir = 2) then
2994 gPlayer1.SetDirection(TDirection.D_LEFT)
2995 else if (strafeDir = 1) then
2996 gPlayer1.SetDirection(TDirection.D_RIGHT)
2997 end
2998 else
2999 begin
3000 strafeDir := 0; // not strafing anymore
3001 if (P1MoveButton = 2) and gPlayerAction[0, ACTION_MOVELEFT] then
3002 gPlayer1.SetDirection(TDirection.D_LEFT)
3003 else if (P1MoveButton = 1) and gPlayerAction[0, ACTION_MOVERIGHT] then
3004 gPlayer1.SetDirection(TDirection.D_RIGHT)
3005 else if P1MoveButton <> 0 then
3006 gPlayer1.SetDirection(TDirection(P1MoveButton-1));
3007 end;
3009 gPlayer1.ReleaseKeys;
3010 if P1MoveButton = 1 then
3011 begin
3012 kByte := kByte or NET_KEY_LEFT;
3013 if Predict then gPlayer1.PressKey(KEY_LEFT, 10000);
3014 end;
3015 if P1MoveButton = 2 then
3016 begin
3017 kByte := kByte or NET_KEY_RIGHT;
3018 if Predict then gPlayer1.PressKey(KEY_RIGHT, 10000);
3019 end;
3020 if gPlayerAction[0, ACTION_LOOKUP] then
3021 begin
3022 kByte := kByte or NET_KEY_UP;
3023 gPlayer1.PressKey(KEY_UP, 10000);
3024 end;
3025 if gPlayerAction[0, ACTION_LOOKDOWN] then
3026 begin
3027 kByte := kByte or NET_KEY_DOWN;
3028 gPlayer1.PressKey(KEY_DOWN, 10000);
3029 end;
3030 if gPlayerAction[0, ACTION_JUMP] then
3031 begin
3032 kByte := kByte or NET_KEY_JUMP;
3033 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3034 end;
3035 if gPlayerAction[0, ACTION_ATTACK] then kByte := kByte or NET_KEY_FIRE;
3036 if gPlayerAction[0, ACTION_ACTIVATE] then kByte := kByte or NET_KEY_OPEN;
3037 if gPlayerAction[0, ACTION_WEAPNEXT] then kByte := kByte or NET_KEY_NW;
3038 if gPlayerAction[0, ACTION_WEAPPREV] then kByte := kByte or NET_KEY_PW;
3040 gPlayerAction[0, ACTION_WEAPNEXT] := False; // HACK, remove after readyweaon&pendinweapon implementation
3041 gPlayerAction[0, ACTION_WEAPPREV] := False; // HACK, remove after readyweaon&pendinweapon implementation
3043 for i := WP_FIRST to WP_LAST do
3044 begin
3045 if gSelectWeapon[0, i] then
3046 begin
3047 WeaponSelect := WeaponSelect or Word(1 shl i);
3048 gSelectWeapon[0, i] := False
3049 end
3050 end;
3052 // fix movebutton state
3053 P1MoveButton := P1MoveButton or (strafeDir shl 4);
3054 end
3055 else
3056 kByte := NET_KEY_CHAT;
3058 NetOut.Write(Byte(NET_MSG_PLRPOS));
3059 NetOut.Write(gTime);
3060 NetOut.Write(kByte);
3061 NetOut.Write(Byte(gPlayer1.Direction));
3062 NetOut.Write(WeaponSelect);
3063 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3064 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS);
3066 //kBytePrev := kByte;
3067 //kDirPrev := gPlayer1.Direction;
3068 end;
3070 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
3071 begin
3072 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
3073 NetOut.Write(Byte(Start));
3074 NetOut.Write(Command);
3075 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3076 end;
3078 procedure MC_SEND_PlayerSettings();
3079 begin
3080 NetOut.Write(Byte(NET_MSG_PLRSET));
3081 NetOut.Write(gPlayer1Settings.Name);
3082 NetOut.Write(gPlayer1Settings.Model);
3083 NetOut.Write(gPlayer1Settings.Color.R);
3084 NetOut.Write(gPlayer1Settings.Color.G);
3085 NetOut.Write(gPlayer1Settings.Color.B);
3086 NetOut.Write(gPlayer1Settings.Team);
3088 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3089 end;
3091 procedure MC_SEND_FullStateRequest();
3092 begin
3093 NetOut.Write(Byte(NET_MSG_REQFST));
3095 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3096 end;
3098 procedure MC_SEND_CheatRequest(Kind: Byte);
3099 begin
3100 NetOut.Write(Byte(NET_MSG_CHEAT));
3101 NetOut.Write(Kind);
3103 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3104 end;
3105 procedure MC_SEND_RCONPassword(Password: string);
3106 begin
3107 NetOut.Write(Byte(NET_MSG_RCON_AUTH));
3108 NetOut.Write(Password);
3110 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3111 end;
3112 procedure MC_SEND_RCONCommand(Cmd: string);
3113 begin
3114 NetOut.Write(Byte(NET_MSG_RCON_CMD));
3115 NetOut.Write(Cmd);
3117 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3118 end;
3121 end.