DEADSOFTWARE

6c3137a229e3ff97d34e34166271c13ef67a26a3
[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_WARMUP 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_WARMUP) 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 if JustTeleported then kByte := kByte or NET_KEY_FORCEDIR;
1114 end;
1116 NetOut.Write(kByte);
1117 if Direction = TDirection.D_LEFT then NetOut.Write(Byte(0)) else NetOut.Write(Byte(1));
1118 NetOut.Write(GameX);
1119 NetOut.Write(GameY);
1120 NetOut.Write(GameVelX);
1121 NetOut.Write(GameVelY);
1122 NetOut.Write(GameAccelX);
1123 NetOut.Write(GameAccelY);
1124 end;
1126 g_Net_Host_Send(ID, Reliable, NET_CHAN_PLAYERPOS);
1127 end;
1129 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
1130 var
1131 P: TPlayer;
1132 I: Integer;
1133 begin
1134 P := g_Player_Get(PID);
1135 if P = nil then Exit;
1137 NetOut.Write(Byte(NET_MSG_PLRSTA));
1138 NetOut.Write(PID);
1140 with P do
1141 begin
1142 NetOut.Write(Byte(alive));
1143 NetOut.Write(Byte(GodMode));
1144 NetOut.Write(Health);
1145 NetOut.Write(Armor);
1146 NetOut.Write(Air);
1147 NetOut.Write(JetFuel);
1148 NetOut.Write(Lives);
1149 NetOut.Write(Team);
1151 for I := WP_FIRST to WP_LAST do
1152 NetOut.Write(Byte(FWeapon[I]));
1154 for I := A_BULLETS to A_HIGH do
1155 NetOut.Write(FAmmo[I]);
1157 for I := A_BULLETS to A_HIGH do
1158 NetOut.Write(FMaxAmmo[I]);
1160 for I := MR_SUIT to MR_MAX do
1161 NetOut.Write(LongWord(FMegaRulez[I]));
1163 NetOut.Write(Byte(R_ITEM_BACKPACK in FRulez));
1164 NetOut.Write(Byte(R_KEY_RED in FRulez));
1165 NetOut.Write(Byte(R_KEY_GREEN in FRulez));
1166 NetOut.Write(Byte(R_KEY_BLUE in FRulez));
1167 NetOut.Write(Byte(R_BERSERK in FRulez));
1169 NetOut.Write(Frags);
1170 NetOut.Write(Death);
1172 NetOut.Write(CurrWeap);
1174 NetOut.Write(Byte(FSpectator));
1175 NetOut.Write(Byte(FGhost));
1176 NetOut.Write(Byte(FPhysics));
1177 NetOut.Write(Byte(FNoRespawn));
1178 NetOut.Write(Byte(FJetpack));
1179 NetOut.Write(FFireTime);
1180 NetOut.Write(Byte(FFlaming));
1181 NetOut.Write(FSpawnInvul);
1182 end;
1184 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1185 end;
1187 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
1188 begin
1189 NetOut.Write(Byte(NET_MSG_PLRDMG));
1190 NetOut.Write(PID);
1191 NetOut.Write(Kind);
1192 NetOut.Write(Attacker);
1193 NetOut.Write(Value);
1194 NetOut.Write(VX);
1195 NetOut.Write(VY);
1197 g_Net_Host_Send(ID, False, NET_CHAN_PLAYER);
1198 end;
1200 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
1201 begin
1202 NetOut.Write(Byte(NET_MSG_PLRDIE));
1203 NetOut.Write(PID);
1204 NetOut.Write(KillType);
1205 NetOut.Write(DeathType);
1206 NetOut.Write(Attacker);
1208 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1209 end;
1211 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
1212 begin
1213 NetOut.Write(Byte(NET_MSG_PLRFIRE));
1214 NetOut.Write(PID);
1215 NetOut.Write(Weapon);
1216 NetOut.Write(X);
1217 NetOut.Write(Y);
1218 NetOut.Write(AX);
1219 NetOut.Write(AY);
1220 NetOut.Write(ShotID);
1222 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1223 end;
1225 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
1226 begin
1227 NetOut.Write(Byte(NET_MSG_PLRDEL));
1228 NetOut.Write(PID);
1230 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1231 end;
1233 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
1234 var
1235 Pl: TPlayer;
1236 begin
1237 Pl := g_Player_Get(PID);
1238 if Pl = nil then Exit;
1240 NetOut.Write(Byte(NET_MSG_PLRSET));
1241 NetOut.Write(PID);
1242 NetOut.Write(Pl.Name);
1243 if Mdl = '' then
1244 NetOut.Write(Pl.Model.Name)
1245 else
1246 NetOut.Write(Mdl);
1247 NetOut.Write(Pl.FColor.R);
1248 NetOut.Write(Pl.FColor.G);
1249 NetOut.Write(Pl.FColor.B);
1250 NetOut.Write(Pl.Team);
1252 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1253 end;
1255 // ITEM (SEND)
1257 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1258 var
1259 it: PItem;
1260 tt: Byte;
1261 begin
1262 it := g_Items_ByIdx(IID);
1264 NetOut.Write(Byte(NET_MSG_ISPAWN));
1265 NetOut.Write(IID);
1266 NetOut.Write(Byte(Quiet));
1267 tt := it.ItemType;
1268 if it.dropped then tt := tt or $80;
1269 NetOut.Write(tt);
1270 NetOut.Write(Byte(it.Fall));
1271 NetOut.Write(Byte(it.Respawnable));
1272 NetOut.Write(it.Obj.X);
1273 NetOut.Write(it.Obj.Y);
1274 NetOut.Write(it.Obj.Vel.X);
1275 NetOut.Write(it.Obj.Vel.Y);
1277 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1278 end;
1280 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1281 begin
1282 NetOut.Write(Byte(NET_MSG_IDEL));
1283 NetOut.Write(IID);
1284 NetOut.Write(Byte(Quiet));
1286 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1287 end;
1289 // PANEL
1291 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
1292 var
1293 TP: TPanel;
1294 begin
1295 TP := g_Map_PanelByGUID(PGUID);
1296 if (TP = nil) then exit;
1298 with TP do
1299 begin
1300 NetOut.Write(Byte(NET_MSG_PTEX));
1301 NetOut.Write(LongWord(PGUID));
1302 NetOut.Write(FCurTexture);
1303 NetOut.Write(FCurFrame);
1304 NetOut.Write(FCurFrameCount);
1305 NetOut.Write(AnimLoop);
1306 end;
1308 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1309 end;
1311 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
1312 var
1313 TP: TPanel;
1314 mpflags: Byte = 0;
1315 begin
1316 TP := g_Map_PanelByGUID(PGUID);
1317 if (TP = nil) then exit;
1319 NetOut.Write(Byte(NET_MSG_PSTATE));
1320 NetOut.Write(LongWord(PGUID));
1321 NetOut.Write(Byte(TP.Enabled));
1322 NetOut.Write(TP.LiftType);
1323 NetOut.Write(TP.X);
1324 NetOut.Write(TP.Y);
1325 NetOut.Write(Word(TP.Width));
1326 NetOut.Write(Word(TP.Height));
1327 // mplats
1328 NetOut.Write(LongInt(TP.movingSpeedX));
1329 NetOut.Write(LongInt(TP.movingSpeedY));
1330 NetOut.Write(LongInt(TP.movingStartX));
1331 NetOut.Write(LongInt(TP.movingStartY));
1332 NetOut.Write(LongInt(TP.movingEndX));
1333 NetOut.Write(LongInt(TP.movingEndY));
1334 NetOut.Write(LongInt(TP.sizeSpeedX));
1335 NetOut.Write(LongInt(TP.sizeSpeedY));
1336 NetOut.Write(LongInt(TP.sizeEndX));
1337 NetOut.Write(LongInt(TP.sizeEndY));
1338 if TP.movingActive then mpflags := mpflags or 1;
1339 if TP.moveOnce then mpflags := mpflags or 2;
1340 NetOut.Write(Byte(mpflags));
1342 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1343 end;
1345 // TRIGGER
1347 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
1348 begin
1349 if gTriggers = nil then Exit;
1350 if T.Sound = nil then Exit;
1352 NetOut.Write(Byte(NET_MSG_TSOUND));
1353 NetOut.Write(T.ClientID);
1354 NetOut.Write(Byte(T.Sound.IsPlaying));
1355 NetOut.Write(LongWord(T.Sound.GetPosition));
1356 NetOut.Write(T.SoundPlayCount);
1358 g_Net_Host_Send(ID, True);
1359 end;
1361 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
1362 begin
1363 NetOut.Write(Byte(NET_MSG_TMUSIC));
1364 NetOut.Write(gMusic.Name);
1365 NetOut.Write(Byte(gMusic.IsPlaying));
1366 NetOut.Write(LongWord(gMusic.GetPosition));
1367 NetOut.Write(Byte(gMusic.SpecPause or gMusic.IsPaused));
1369 g_Net_Host_Send(ID, True);
1370 end;
1372 // MONSTER
1374 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
1375 var
1376 M: TMonster;
1377 begin
1378 M := g_Monsters_ByUID(UID);
1379 if M = nil then
1380 Exit;
1382 with M do
1383 begin
1384 NetOut.Write(Byte(NET_MSG_MSPAWN));
1385 NetOut.Write(UID);
1386 NetOut.Write(MonsterType);
1387 NetOut.Write(MonsterState);
1388 NetOut.Write(MonsterAnim);
1389 NetOut.Write(MonsterTargetUID);
1390 NetOut.Write(MonsterTargetTime);
1391 NetOut.Write(MonsterBehaviour);
1392 NetOut.Write(MonsterSleep);
1393 NetOut.Write(MonsterHealth);
1394 NetOut.Write(MonsterAmmo);
1395 NetOut.Write(GameX);
1396 NetOut.Write(GameY);
1397 NetOut.Write(GameVelX);
1398 NetOut.Write(GameVelY);
1399 NetOut.Write(Byte(GameDirection));
1400 end;
1402 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1403 end;
1405 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
1406 var
1407 M: TMonster;
1408 begin
1409 M := g_Monsters_ByUID(UID);
1410 if M = nil then Exit;
1412 NetOut.Write(Byte(NET_MSG_MPOS));
1413 NetOut.Write(UID);
1415 with M do
1416 begin
1417 NetOut.Write(GameX);
1418 NetOut.Write(GameY);
1419 NetOut.Write(GameVelX);
1420 NetOut.Write(GameVelY);
1421 NetOut.Write(Byte(GameDirection));
1422 end;
1424 g_Net_Host_Send(ID, False, NET_CHAN_MONSTERPOS);
1425 end;
1427 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
1428 var
1429 M: TMonster;
1430 begin
1431 M := g_Monsters_ByUID(UID);
1432 if M = nil then Exit;
1434 NetOut.Write(Byte(NET_MSG_MSTATE));
1435 NetOut.Write(UID);
1437 with M do
1438 begin
1439 NetOut.Write(MonsterState);
1440 NetOut.Write(ForcedAnim);
1441 NetOut.Write(MonsterTargetUID);
1442 NetOut.Write(MonsterTargetTime);
1443 NetOut.Write(MonsterSleep);
1444 NetOut.Write(MonsterHealth);
1445 NetOut.Write(MonsterAmmo);
1446 NetOut.Write(MonsterPain);
1447 NetOut.Write(Byte(AnimIsReverse));
1448 NetOut.Write(FFireTime);
1449 end;
1451 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1452 end;
1454 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
1455 begin
1456 NetOut.Write(Byte(NET_MSG_MSHOT));
1457 NetOut.Write(UID);
1458 NetOut.Write(X);
1459 NetOut.Write(Y);
1460 NetOut.Write(VX);
1461 NetOut.Write(VY);
1463 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1464 end;
1466 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
1467 var
1468 M: TMonster;
1469 begin
1470 M := g_Monsters_ByUID(UID);
1471 if M = nil then Exit;
1473 NetOut.Write(Byte(NET_MSG_MDEL));
1474 NetOut.Write(UID);
1476 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1477 end;
1479 // MISC
1481 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
1482 begin
1483 NetOut.Write(Byte(NET_MSG_TIME_SYNC));
1484 NetOut.Write(Time);
1486 g_Net_Host_Send(ID, False, NET_CHAN_SERVICE);
1487 end;
1489 procedure MH_SEND_VoteEvent(EvType: Byte;
1490 StrArg1: string = 'a'; StrArg2: string = 'b';
1491 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
1492 ID: Integer = NET_EVERYONE);
1493 begin
1494 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
1495 NetOut.Write(EvType);
1496 NetOut.Write(IntArg1);
1497 NetOut.Write(IntArg2);
1498 NetOut.Write(StrArg1);
1499 NetOut.Write(StrArg2);
1501 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1502 end;
1504 // CLIENT MESSAGES //
1506 // GAME
1508 procedure MC_RECV_Chat(var M: TMsg);
1509 var
1510 Txt: string;
1511 Mode: Byte;
1512 begin
1513 Txt := M.ReadString();
1514 Mode := M.ReadByte();
1516 if Mode <> NET_CHAT_SYSTEM then
1517 begin
1518 if Mode = NET_CHAT_PLAYER then
1519 begin
1520 g_Console_Add(Txt, True);
1521 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1522 g_Game_ChatSound(b_Text_Unformat(Txt));
1523 end else
1524 if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then
1525 begin
1526 if gPlayer1.Team = TEAM_RED then
1527 g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True);
1528 if gPlayer1.Team = TEAM_BLUE then
1529 g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True);
1530 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1531 g_Game_ChatSound(b_Text_Unformat(Txt));
1532 end;
1533 end else
1534 g_Console_Add(Txt, True);
1535 end;
1537 procedure MC_RECV_Effect(var M: TMsg);
1538 var
1539 Kind: Byte;
1540 X, Y: Integer;
1541 Ang: SmallInt;
1542 Anim: TAnimation;
1543 ID: LongWord;
1544 begin
1545 if not gGameOn then Exit;
1546 Kind := M.ReadByte();
1547 X := M.ReadLongInt();
1548 Y := M.ReadLongInt();
1549 Ang := M.ReadSmallInt();
1551 case Kind of
1552 NET_GFX_SPARK:
1553 g_GFX_Spark(X, Y, 2 + Random(2), Ang, 0, 0);
1555 NET_GFX_TELE:
1556 begin
1557 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
1558 begin
1559 Anim := TAnimation.Create(ID, False, 3);
1560 g_GFX_OnceAnim(X, Y, Anim);
1561 Anim.Free();
1562 end;
1563 if Ang = 1 then
1564 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
1565 end;
1567 NET_GFX_EXPLODE:
1568 begin
1569 if g_Frames_Get(ID, 'FRAMES_EXPLODE_ROCKET') then
1570 begin
1571 Anim := TAnimation.Create(ID, False, 6);
1572 Anim.Blending := False;
1573 g_GFX_OnceAnim(X-64, Y-64, Anim);
1574 Anim.Free();
1575 end;
1576 if Ang = 1 then
1577 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X, Y);
1578 end;
1580 NET_GFX_BFGEXPL:
1581 begin
1582 if g_Frames_Get(ID, 'FRAMES_EXPLODE_BFG') then
1583 begin
1584 Anim := TAnimation.Create(ID, False, 6);
1585 Anim.Blending := False;
1586 g_GFX_OnceAnim(X-64, Y-64, Anim);
1587 Anim.Free();
1588 end;
1589 if Ang = 1 then
1590 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X, Y);
1591 end;
1593 NET_GFX_BFGHIT:
1594 begin
1595 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1596 begin
1597 Anim := TAnimation.Create(ID, False, 4);
1598 g_GFX_OnceAnim(X-32, Y-32, Anim);
1599 Anim.Free();
1600 end;
1601 end;
1603 NET_GFX_FIRE:
1604 begin
1605 if g_Frames_Get(ID, 'FRAMES_FIRE') then
1606 begin
1607 Anim := TAnimation.Create(ID, False, 4);
1608 g_GFX_OnceAnim(X, Y, Anim);
1609 Anim.Free();
1610 end;
1611 if Ang = 1 then
1612 g_Sound_PlayExAt('SOUND_FIRE', X, Y);
1613 end;
1615 NET_GFX_RESPAWN:
1616 begin
1617 if g_Frames_Get(ID, 'FRAMES_ITEM_RESPAWN') then
1618 begin
1619 Anim := TAnimation.Create(ID, False, 4);
1620 g_GFX_OnceAnim(X, Y, Anim);
1621 Anim.Free();
1622 end;
1623 if Ang = 1 then
1624 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
1625 end;
1627 NET_GFX_SHELL1:
1628 g_Player_CreateShell(X, Y, 0, -2, SHELL_BULLET);
1630 NET_GFX_SHELL2:
1631 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1633 NET_GFX_SHELL3:
1634 begin
1635 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1636 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1637 end;
1638 end;
1639 end;
1641 procedure MC_RECV_Sound(var M: TMsg);
1642 var
1643 Name: string;
1644 X, Y: Integer;
1645 Pos: Boolean;
1646 begin
1647 Name := M.ReadString();
1648 Pos := M.ReadByte() <> 0;
1649 if Pos then
1650 begin
1651 X := M.ReadLongInt();
1652 Y := M.ReadLongInt();
1653 g_Sound_PlayExAt(Name, X, Y);
1654 end
1655 else
1656 g_Sound_PlayEx(Name);
1657 end;
1659 procedure MC_RECV_CreateShot(var M: TMsg);
1660 var
1661 I, X, Y, XV, YV: Integer;
1662 Timeout: LongWord;
1663 Target, Spawner: Word;
1664 ShType: Byte;
1665 begin
1666 I := M.ReadLongInt();
1667 ShType := M.ReadByte();
1668 Target := M.ReadWord();
1669 Spawner := M.ReadWord();
1670 Timeout := M.ReadLongWord();
1671 X := M.ReadLongInt();
1672 Y := M.ReadLongInt();
1673 XV := M.ReadLongInt();
1674 YV := M.ReadLongInt();
1676 I := g_Weapon_CreateShot(I, ShType, Spawner, Target, X, Y, XV, YV);
1677 if (Shots <> nil) and (I <= High(Shots)) then
1678 begin
1679 Shots[I].Timeout := Timeout;
1680 //Shots[I].Target := Target; // TODO: find a use for Target later
1681 end;
1682 end;
1684 procedure MC_RECV_UpdateShot(var M: TMsg);
1685 var
1686 I, TX, TY, TXV, TYV: Integer;
1687 begin
1688 I := M.ReadLongInt();
1689 TX := M.ReadLongInt();
1690 TY := M.ReadLongInt();
1691 TXV := M.ReadLongInt();
1692 TYV := M.ReadLongInt();
1694 if (Shots <> nil) and (I <= High(Shots)) then
1695 with (Shots[i]) do
1696 begin
1697 Obj.X := TX;
1698 Obj.Y := TY;
1699 Obj.Vel.X := TXV;
1700 Obj.Vel.Y := TYV;
1701 end;
1702 end;
1704 procedure MC_RECV_DeleteShot(var M: TMsg);
1705 var
1706 I, X, Y: Integer;
1707 L: Boolean;
1708 begin
1709 if not gGameOn then Exit;
1710 I := M.ReadLongInt();
1711 L := (M.ReadByte() <> 0);
1712 X := M.ReadLongInt();
1713 Y := M.ReadLongInt();
1715 g_Weapon_DestroyShot(I, X, Y, L);
1716 end;
1718 procedure MC_RECV_GameStats(var M: TMsg);
1719 begin
1720 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1721 begin
1722 gTeamStat[TEAM_RED].Goals := M.ReadSmallInt();
1723 gTeamStat[TEAM_BLUE].Goals := M.ReadSmallInt();
1724 end
1725 else
1726 if gGameSettings.GameMode = GM_COOP then
1727 begin
1728 gCoopMonstersKilled := M.ReadWord();
1729 gCoopSecretsFound := M.ReadWord();
1730 end;
1731 end;
1733 procedure MC_RECV_CoopStats(var M: TMsg);
1734 begin
1735 gTotalMonsters := M.ReadLongInt();
1736 gSecretsCount := M.ReadLongInt();
1737 gCoopTotalMonstersKilled := M.ReadWord();
1738 gCoopTotalSecretsFound := M.ReadWord();
1739 gCoopTotalMonsters := M.ReadWord();
1740 gCoopTotalSecrets := M.ReadWord();
1741 end;
1743 procedure MC_RECV_GameEvent(var M: TMsg);
1744 var
1745 EvType: Byte;
1746 EvNum: Integer;
1747 EvStr: string;
1748 EvTime: LongWord;
1749 BHash: Boolean;
1750 EvHash: TMD5Digest;
1751 pl: TPlayer;
1752 i1, i2: TStrings_Locale;
1753 pln: String;
1754 cnt: Byte;
1755 goodCmd: Boolean = true;
1756 begin
1757 FillChar(EvHash, Sizeof(EvHash), 0);
1758 EvType := M.ReadByte();
1759 EvNum := M.ReadLongInt();
1760 EvStr := M.ReadString();
1761 gLastMap := M.ReadByte() <> 0;
1762 if gLastMap and (gGameSettings.GameMode = GM_COOP) then gStatsOff := True;
1763 gStatsPressed := True;
1764 EvTime := M.ReadLongWord();
1765 BHash := M.ReadByte() <> 0;
1766 if BHash then
1767 EvHash := M.ReadMD5();
1769 gTime := EvTime;
1771 if (g_Res_received_map_start <> 0) then
1772 begin
1773 if (g_Res_received_map_start < 0) then exit;
1774 goodCmd := false;
1775 case EvType of
1776 NET_EV_MAPSTART: goodCmd := true;
1777 NET_EV_MAPEND: goodCmd := true;
1778 NET_EV_PLAYER_KICK: goodCmd := true;
1779 NET_EV_PLAYER_BAN: goodCmd := true;
1780 NET_EV_LMS_WARMUP: goodCmd := true;
1781 end;
1782 if not goodCmd then exit;
1783 end;
1785 case EvType of
1786 NET_EV_MAPSTART:
1787 begin
1788 if (g_Res_received_map_start <> 0) then
1789 begin
1790 g_Res_received_map_start := -1;
1791 end
1792 else
1793 begin
1794 gGameOn := False;
1795 g_Game_ClearLoading();
1796 g_Game_StopAllSounds(True);
1798 gSwitchGameMode := Byte(EvNum);
1799 gGameSettings.GameMode := gSwitchGameMode;
1801 gWADHash := EvHash;
1802 if not g_Game_StartMap(false{asMegawad}, EvStr, True) then
1803 begin
1804 if not isWadPath(EvStr) then
1805 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + EvStr]))
1806 else
1807 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [EvStr]));
1808 Exit;
1809 end;
1811 MC_SEND_FullStateRequest;
1812 end;
1813 end;
1815 NET_EV_MAPEND:
1816 begin
1817 gLMSRespawn := LMS_RESPAWN_NONE;
1818 gLMSRespawnTime := 0;
1819 if (g_Res_received_map_start <> 0) then
1820 begin
1821 g_Res_received_map_start := -1;
1822 end
1823 else
1824 begin
1825 gMissionFailed := EvNum <> 0;
1826 gExit := EXIT_ENDLEVELCUSTOM;
1827 end;
1828 end;
1830 NET_EV_RCON:
1831 begin
1832 case EvNum of
1833 NET_RCON_NOAUTH:
1834 g_Console_Add(_lc[I_NET_RCON_NOAUTH], True);
1835 NET_RCON_PWGOOD:
1836 g_Console_Add(_lc[I_NET_RCON_PWD_VALID], True);
1837 NET_RCON_PWBAD:
1838 g_Console_Add(_lc[I_NET_RCON_PWD_INVALID], True);
1839 end;
1840 end;
1842 NET_EV_CHANGE_TEAM:
1843 begin
1844 if EvNum = TEAM_RED then
1845 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True);
1846 if EvNum = TEAM_BLUE then
1847 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True);
1848 end;
1850 NET_EV_PLAYER_KICK:
1851 begin
1852 g_Console_Add(Format(_lc[I_PLAYER_KICK], [EvStr]), True);
1853 if (g_Res_received_map_start <> 0) then g_Res_received_map_start := -1;
1854 end;
1856 NET_EV_PLAYER_BAN:
1857 begin
1858 g_Console_Add(Format(_lc[I_PLAYER_BAN], [EvStr]), True);
1859 if (g_Res_received_map_start <> 0) then g_Res_received_map_start := -1;
1860 end;
1862 NET_EV_LMS_WARMUP:
1863 begin
1864 if EvNum > 0 then
1865 begin
1866 gLMSRespawn := LMS_RESPAWN_WARMUP;
1867 gLMSRespawnTime := gTime + EvNum;
1868 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [EvNum div 1000]), True);
1869 end
1870 else if gPlayer1 = nil then
1871 begin
1872 g_Console_Add(_lc[I_PLAYER_SPECT4], True);
1873 end;
1874 end;
1876 NET_EV_LMS_SURVIVOR:
1877 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True);
1879 NET_EV_BIGTEXT:
1880 g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum));
1882 NET_EV_SCORE:
1883 begin
1884 pl := g_Player_Get(EvNum and $FFFF);
1885 if pl = nil then
1886 pln := '?'
1887 else
1888 pln := pl.Name;
1889 cnt := (EvNum shr 16) and $FF;
1890 if Pos('w', EvStr) = 0 then
1891 begin
1892 // Default score
1893 if Pos('t', EvStr) = 0 then
1894 begin
1895 // Player +/- score
1896 if Pos('-', EvStr) = 0 then
1897 begin
1898 if Pos('e', EvStr) = 0 then
1899 i1 := I_PLAYER_SCORE_ADD_OWN
1900 else
1901 i1 := I_PLAYER_SCORE_ADD_ENEMY;
1902 end else
1903 begin
1904 if Pos('e', EvStr) = 0 then
1905 i1 := I_PLAYER_SCORE_SUB_OWN
1906 else
1907 i1 := I_PLAYER_SCORE_SUB_ENEMY;
1908 end;
1909 // Which team
1910 if Pos('r', EvStr) > 0 then
1911 i2 := I_PLAYER_SCORE_TO_RED
1912 else
1913 i2 := I_PLAYER_SCORE_TO_BLUE;
1914 g_Console_Add(Format(_lc[i1], [pln, cnt, _lc[i2]]), True);
1915 end else
1916 begin
1917 // Team +/- score
1918 if Pos('-', EvStr) = 0 then
1919 i1 := I_PLAYER_SCORE_ADD_TEAM
1920 else
1921 i1 := I_PLAYER_SCORE_SUB_TEAM;
1922 // Which team
1923 if Pos('r', EvStr) > 0 then
1924 i2 := I_PLAYER_SCORE_RED
1925 else
1926 i2 := I_PLAYER_SCORE_BLUE;
1927 g_Console_Add(Format(_lc[i1], [_lc[i2], cnt]), True);
1928 end;
1929 end else
1930 begin
1931 // Game Win
1932 if Pos('e', EvStr) = 0 then
1933 i1 := I_PLAYER_SCORE_WIN_OWN
1934 else
1935 i1 := I_PLAYER_SCORE_WIN_ENEMY;
1936 // Which team
1937 if Pos('r', EvStr) > 0 then
1938 i2 := I_PLAYER_SCORE_TO_RED
1939 else
1940 i2 := I_PLAYER_SCORE_TO_BLUE;
1941 g_Console_Add(Format(_lc[i1], [pln, _lc[i2]]), True);
1942 end;
1943 end;
1945 NET_EV_SCORE_MSG:
1946 begin
1947 if EvNum = TEAM_RED then
1948 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1949 if EvNum = TEAM_BLUE then
1950 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1951 if EvNum = -TEAM_RED then
1952 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1953 if EvNum = -TEAM_BLUE then
1954 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1955 end;
1957 NET_EV_LMS_START:
1958 begin
1959 g_Player_RemoveAllCorpses;
1960 gLMSRespawn := LMS_RESPAWN_NONE;
1961 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
1962 end;
1964 NET_EV_LMS_WIN:
1965 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(EvStr)]), 144);
1967 NET_EV_TLMS_WIN:
1968 begin
1969 if EvNum = TEAM_RED then
1970 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
1971 if EvNum = TEAM_BLUE then
1972 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
1973 end;
1975 NET_EV_LMS_LOSE:
1976 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
1978 NET_EV_LMS_DRAW:
1979 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
1981 NET_EV_LMS_NOSPAWN:
1982 g_Console_Add(_lc[I_PLAYER_SPECT4], True);
1984 NET_EV_KILLCOMBO:
1985 g_Game_Announce_KillCombo(EvNum);
1987 NET_EV_PLAYER_TOUCH:
1988 begin
1989 pl := g_Player_Get(EvNum);
1990 if pl <> nil then
1991 pl.Touch();
1992 end;
1994 NET_EV_SECRET:
1995 begin
1996 pl := g_Player_Get(EvNum);
1997 if pl <> nil then
1998 begin
1999 g_Console_Add(Format(_lc[I_PLAYER_SECRET], [pl.Name]), True);
2000 g_Sound_PlayEx('SOUND_GAME_SECRET');
2001 end;
2002 end;
2004 NET_EV_INTER_READY:
2005 begin
2006 pl := g_Player_Get(EvNum);
2007 if pl <> nil then pl.FReady := (EvStr = 'Y');
2008 end;
2009 end;
2010 end;
2012 procedure MC_RECV_FlagEvent(var M: TMsg);
2013 var
2014 PID: Word;
2015 Pl: TPlayer;
2016 EvType: Byte;
2017 Fl, a: Byte;
2018 Quiet: Boolean;
2019 s, ts: string;
2020 begin
2021 EvType := M.ReadByte();
2022 Fl := M.ReadByte();
2024 if Fl = FLAG_NONE then Exit;
2026 Quiet := (M.ReadByte() <> 0);
2027 PID := M.ReadWord();
2029 gFlags[Fl].State := M.ReadByte();
2030 gFlags[Fl].CaptureTime := M.ReadLongWord();
2031 gFlags[Fl].Obj.X := M.ReadLongInt();
2032 gFlags[Fl].Obj.Y := M.ReadLongInt();
2033 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
2034 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
2036 Pl := g_Player_Get(PID);
2037 if (Pl = nil) and
2038 (EvType <> FLAG_STATE_NORMAL) and
2039 (EvType <> FLAG_STATE_DROPPED) and
2040 (EvType <> FLAG_STATE_RETURNED) then
2041 Exit;
2043 case EvType of
2044 FLAG_STATE_NORMAL:
2045 begin
2046 if Quiet or (Pl = nil) then Exit;
2048 if Fl = FLAG_RED then
2049 s := _lc[I_PLAYER_FLAG_RED]
2050 else
2051 s := _lc[I_PLAYER_FLAG_BLUE];
2053 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2055 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2056 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2057 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2058 a := 0
2059 else
2060 a := 1;
2062 if not sound_ret_flag[a].IsPlaying() then
2063 sound_ret_flag[a].Play();
2064 end;
2066 FLAG_STATE_CAPTURED:
2067 begin
2068 if (Pl <> nil) then Pl.SetFlag(Fl);
2070 if Quiet then Exit;
2072 if Fl = FLAG_RED then
2073 s := _lc[I_PLAYER_FLAG_RED]
2074 else
2075 s := _lc[I_PLAYER_FLAG_BLUE];
2077 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [Pl.Name, s]), True);
2078 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
2080 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2081 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2082 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2083 a := 0
2084 else
2085 a := 1;
2087 if not sound_get_flag[a].IsPlaying() then
2088 sound_get_flag[a].Play();
2089 end;
2091 FLAG_STATE_DROPPED:
2092 begin
2093 if (Pl <> nil) then Pl.SetFlag(FLAG_NONE);
2095 if Quiet or (Pl = nil) then Exit;
2097 if Fl = FLAG_RED then
2098 s := _lc[I_PLAYER_FLAG_RED]
2099 else
2100 s := _lc[I_PLAYER_FLAG_BLUE];
2102 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [Pl.Name, s]), True);
2103 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
2105 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2106 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2107 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2108 a := 0
2109 else
2110 a := 1;
2112 if not sound_lost_flag[a].IsPlaying() then
2113 sound_lost_flag[a].Play();
2114 end;
2116 FLAG_STATE_SCORED:
2117 begin
2118 g_Map_ResetFlag(FLAG_RED);
2119 g_Map_ResetFlag(FLAG_BLUE);
2120 if Quiet or (Pl = nil) then Exit;
2121 Pl.SetFlag(FLAG_NONE);
2123 if Fl = FLAG_RED then
2124 s := _lc[I_PLAYER_FLAG_RED]
2125 else
2126 s := _lc[I_PLAYER_FLAG_BLUE];
2128 ts := Format('%.4d', [gFlags[Fl].CaptureTime]);
2129 Insert('.', ts, Length(ts) + 1 - 3);
2130 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [Pl.Name, s, ts]), True);
2131 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
2133 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2134 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2135 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2136 a := 0
2137 else
2138 a := 1;
2140 if not sound_cap_flag[a].IsPlaying() then
2141 sound_cap_flag[a].Play();
2142 end;
2144 FLAG_STATE_RETURNED:
2145 begin
2146 g_Map_ResetFlag(Fl);
2147 if Quiet then Exit;
2149 if Fl = FLAG_RED then
2150 s := _lc[I_PLAYER_FLAG_RED]
2151 else
2152 s := _lc[I_PLAYER_FLAG_BLUE];
2154 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2156 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2157 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2158 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2159 a := 0
2160 else
2161 a := 1;
2163 if not sound_ret_flag[a].IsPlaying() then
2164 sound_ret_flag[a].Play();
2165 end;
2166 end;
2167 end;
2169 procedure MC_RECV_GameSettings(var M: TMsg);
2170 begin
2171 gGameSettings.GameMode := M.ReadByte();
2172 gGameSettings.GoalLimit := M.ReadWord();
2173 gGameSettings.TimeLimit := M.ReadWord();
2174 gGameSettings.MaxLives := M.ReadByte();
2175 gGameSettings.Options := M.ReadLongWord();
2176 end;
2178 // PLAYER
2180 function MC_RECV_PlayerCreate(var M: TMsg): Word;
2181 var
2182 PID, DID: Word;
2183 PName, Model: string;
2184 Color: TRGB;
2185 T: Byte;
2186 Pl: TPlayer;
2187 begin
2188 PID := M.ReadWord();
2189 Pl := g_Player_Get(PID);
2191 PName := M.ReadString();
2192 Model := M.ReadString();
2193 Color.R := M.ReadByte();
2194 Color.G := M.ReadByte();
2195 Color.B := M.ReadByte();
2196 T := M.ReadByte();
2198 Result := 0;
2199 if (PID <> NetPlrUID1) and (PID <> NetPlrUID2) then
2200 begin
2201 if (Pl <> nil) then Exit;
2202 DID := g_Player_Create(Model, Color, T, False);
2203 with g_Player_Get(DID) do
2204 begin
2205 UID := PID;
2206 Name := PName;
2207 Reset(True);
2208 end;
2209 end
2210 else
2211 begin
2212 if (PID = NetPlrUID1) and (gPlayer1 <> nil) then begin
2213 gPlayer1.UID := PID;
2214 gPlayer1.Model.SetColor(Color.R, Color.G, Color.B);
2215 gPlayer1.ChangeTeam(T);
2216 end;
2217 if (PID = NetPlrUID2) and (gPlayer2 <> nil) then begin
2218 gPlayer2.UID := PID;
2219 gPlayer2.Model.SetColor(Color.R, Color.G, Color.B);
2220 gPlayer2.ChangeTeam(T);
2221 end;
2222 end;
2224 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
2225 e_WriteLog('NET: Player ' + PName + ' [' + IntToStr(PID) + '] added.', TMsgType.Notify);
2226 Result := PID;
2227 end;
2229 function MC_RECV_PlayerPos(var M: TMsg): Word;
2230 var
2231 GT: LongWord;
2232 PID: Word;
2233 kByte: Word;
2234 Pl: TPlayer;
2235 Dir: Byte;
2236 TmpX, TmpY: Integer;
2237 begin
2238 Result := 0;
2240 GT := M.ReadLongWord();
2241 if GT < gTime - NET_MAX_DIFFTIME then
2242 begin
2243 gTime := GT;
2244 Exit;
2245 end;
2246 gTime := GT;
2248 PID := M.ReadWord();
2249 Pl := g_Player_Get(PID);
2251 if Pl = nil then Exit;
2253 Result := PID;
2255 with Pl do
2256 begin
2257 FPing := M.ReadWord();
2258 FLoss := M.ReadByte();
2259 kByte := M.ReadWord();
2260 Dir := M.ReadByte();
2262 TmpX := M.ReadLongInt();
2263 TmpY := M.ReadLongInt();
2265 ReleaseKeys;
2267 if (kByte = NET_KEY_CHAT) then
2268 PressKey(KEY_CHAT, 10000)
2269 else
2270 begin
2271 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
2272 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
2273 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
2274 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
2275 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
2276 end;
2278 if ((Pl <> gPlayer1) and (Pl <> gPlayer2)) or LongBool(kByte and NET_KEY_FORCEDIR) then
2279 SetDirection(TDirection(Dir));
2281 GameVelX := M.ReadLongInt();
2282 GameVelY := M.ReadLongInt();
2283 GameAccelX := M.ReadLongInt();
2284 GameAccelY := M.ReadLongInt();
2285 SetLerp(TmpX, TmpY);
2286 if NetForcePlayerUpdate then Update();
2287 end;
2288 end;
2290 function MC_RECV_PlayerStats(var M: TMsg): Word;
2291 var
2292 PID: Word;
2293 Pl: TPlayer;
2294 I, OldFire: Integer;
2295 OldJet, Flam: Boolean;
2296 NewTeam: Byte;
2297 begin
2298 PID := M.ReadWord();
2299 Pl := g_Player_Get(PID);
2300 Result := 0;
2301 if Pl = nil then
2302 Exit;
2304 with Pl do
2305 begin
2306 alive := (M.ReadByte() <> 0);
2307 GodMode := (M.ReadByte() <> 0);
2308 Health := M.ReadLongInt();
2309 Armor := M.ReadLongInt();
2310 Air := M.ReadLongInt();
2311 JetFuel := M.ReadLongInt();
2312 Lives := M.ReadByte();
2313 NewTeam := M.ReadByte();
2315 for I := WP_FIRST to WP_LAST do
2316 FWeapon[I] := (M.ReadByte() <> 0);
2318 for I := A_BULLETS to A_HIGH do
2319 FAmmo[I] := M.ReadWord();
2321 for I := A_BULLETS to A_HIGH do
2322 FMaxAmmo[I] := M.ReadWord();
2324 for I := MR_SUIT to MR_MAX do
2325 FMegaRulez[I] := M.ReadLongWord();
2327 FRulez := [];
2328 if (M.ReadByte() <> 0) then
2329 FRulez := FRulez + [R_ITEM_BACKPACK];
2330 if (M.ReadByte() <> 0) then
2331 FRulez := FRulez + [R_KEY_RED];
2332 if (M.ReadByte() <> 0) then
2333 FRulez := FRulez + [R_KEY_GREEN];
2334 if (M.ReadByte() <> 0) then
2335 FRulez := FRulez + [R_KEY_BLUE];
2336 if (M.ReadByte() <> 0) then
2337 FRulez := FRulez + [R_BERSERK];
2339 Frags := M.ReadLongInt();
2340 Death := M.ReadLongInt();
2342 SetWeapon(M.ReadByte());
2344 FSpectator := M.ReadByte() <> 0;
2345 if FSpectator then
2346 begin
2347 if Pl = gPlayer1 then
2348 begin
2349 gSpectLatchPID1 := UID;
2350 gPlayer1 := nil;
2351 end;
2352 if Pl = gPlayer2 then
2353 begin
2354 gSpectLatchPID2 := UID;
2355 gPlayer2 := nil;
2356 end;
2357 end
2358 else
2359 begin
2360 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) and (UID = gSpectLatchPID1) then
2361 begin
2362 gPlayer1 := Pl;
2363 gSpectLatchPID1 := 0;
2364 end;
2365 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) and (UID = gSpectLatchPID2) then
2366 begin
2367 gPlayer2 := Pl;
2368 gSpectLatchPID2 := 0;
2369 end;
2370 end;
2371 FGhost := M.ReadByte() <> 0;
2372 FPhysics := M.ReadByte() <> 0;
2373 FNoRespawn := M.ReadByte() <> 0;
2374 OldJet := FJetpack;
2375 FJetpack := M.ReadByte() <> 0;
2376 OldFire := FFireTime;
2377 FFireTime := M.ReadLongInt();
2378 if (OldFire <= 0) and (FFireTime > 0) then
2379 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
2380 Flam := M.ReadByte() <> 0;
2381 FSpawnInvul := M.ReadLongInt();
2382 if OldJet and not FJetpack then
2383 JetpackOff
2384 else if not OldJet and FJetpack then
2385 JetpackOn;
2386 if FFlaming and not Flam then
2387 FlamerOff;
2388 if Team <> NewTeam then
2389 Pl.ChangeTeam(NewTeam);
2390 end;
2392 Result := PID;
2393 end;
2395 function MC_RECV_PlayerDamage(var M: TMsg): Word;
2396 var
2397 PID: Word;
2398 Pl: TPlayer;
2399 Kind: Byte;
2400 Attacker, Value: Word;
2401 VX, VY: Integer;
2402 begin
2403 Result := 0;
2404 if not gGameOn then Exit;
2405 PID := M.ReadWord();
2406 Pl := g_Player_Get(PID);
2407 if Pl = nil then Exit;
2409 Kind := M.ReadByte();
2410 Attacker := M.ReadWord();
2411 Value := M.ReadWord();
2412 VX := M.ReadWord();
2413 VY := M.ReadWord();
2415 with Pl do
2416 Damage(Value, Attacker, VX, VY, Kind);
2418 Result := PID;
2419 end;
2421 function MC_RECV_PlayerDeath(var M: TMsg): Word;
2422 var
2423 PID: Word;
2424 Pl: TPlayer;
2425 KillType, DeathType: Byte;
2426 Attacker: Word;
2427 begin
2428 Result := 0;
2429 if not gGameOn then Exit;
2430 PID := M.ReadWord();
2431 Pl := g_Player_Get(PID);
2432 if Pl = nil then Exit;
2434 KillType := M.ReadByte();
2435 DeathType := M.ReadByte();
2436 Attacker := M.ReadWord();
2438 with Pl do
2439 begin
2440 Kill(KillType, Attacker, DeathType);
2441 SoftReset;
2442 end;
2443 end;
2445 function MC_RECV_PlayerDelete(var M: TMsg): Word;
2446 var
2447 PID: Word;
2448 Pl: TPlayer;
2449 begin
2450 PID := M.ReadWord();
2451 Pl := g_Player_Get(PID);
2452 Result := 0;
2453 if Pl = nil then Exit;
2455 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2456 e_WriteLog('NET: Player ' + Pl.Name + ' [' + IntToStr(PID) + '] removed.', TMsgType.Notify);
2458 g_Player_Remove(PID);
2460 Result := PID;
2461 end;
2463 function MC_RECV_PlayerFire(var M: TMsg): Word;
2464 var
2465 PID: Word;
2466 Weap: Byte;
2467 Pl: TPlayer;
2468 X, Y, AX, AY: Integer;
2469 SHID: Integer;
2470 begin
2471 Result := 0;
2472 if not gGameOn then Exit;
2473 PID := M.ReadWord();
2474 Pl := g_Player_Get(PID);
2475 if Pl = nil then Exit;
2477 Weap := M.ReadByte();
2478 X := M.ReadLongInt();
2479 Y := M.ReadLongInt();
2480 AX := M.ReadLongInt();
2481 AY := M.ReadLongInt();
2482 SHID := M.ReadLongInt();
2484 with Pl do
2485 if alive then NetFire(Weap, X, Y, AX, AY, SHID);
2486 end;
2488 procedure MC_RECV_PlayerSettings(var M: TMsg);
2489 var
2490 TmpName: string;
2491 TmpModel: string;
2492 TmpColor: TRGB;
2493 TmpTeam: Byte;
2494 Pl: TPlayer;
2495 PID: Word;
2496 begin
2497 PID := M.ReadWord();
2498 Pl := g_Player_Get(PID);
2499 if Pl = nil then Exit;
2501 TmpName := M.ReadString();
2502 TmpModel := M.ReadString();
2503 TmpColor.R := M.ReadByte();
2504 TmpColor.G := M.ReadByte();
2505 TmpColor.B := M.ReadByte();
2506 TmpTeam := M.ReadByte();
2508 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
2509 begin
2510 Pl.ChangeTeam(TmpTeam);
2511 if gPlayer1 = Pl then
2512 gPlayer1Settings.Team := TmpTeam;
2513 if gPlayer2 = Pl then
2514 gPlayer2Settings.Team := TmpTeam;
2515 end else
2516 Pl.SetColor(TmpColor);
2518 if Pl.Name <> TmpName then
2519 begin
2520 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
2521 Pl.Name := TmpName;
2522 end;
2524 if TmpModel <> Pl.Model.Name then
2525 Pl.SetModel(TmpModel);
2526 end;
2528 // ITEM
2530 procedure MC_RECV_ItemSpawn(var M: TMsg);
2531 var
2532 ID: Word;
2533 AID: DWord;
2534 X, Y, VX, VY: Integer;
2535 T: Byte;
2536 Quiet, Fall{, Resp}: Boolean;
2537 Anim: TAnimation;
2538 it: PItem;
2539 begin
2540 if not gGameOn then Exit;
2541 ID := M.ReadWord();
2542 Quiet := M.ReadByte() <> 0;
2543 T := M.ReadByte();
2544 Fall := M.ReadByte() <> 0;
2545 {Resp :=} M.ReadByte();
2546 X := M.ReadLongInt();
2547 Y := M.ReadLongInt();
2548 VX := M.ReadLongInt();
2549 VY := M.ReadLongInt();
2551 g_Items_Create(X, Y, T and $7F, Fall, False, False, ID);
2552 if ((T and $80) <> 0) then g_Items_SetDrop(ID);
2554 it := g_Items_ByIdx(ID);
2555 it.Obj.Vel.X := VX;
2556 it.Obj.Vel.Y := VY;
2558 if not Quiet then
2559 begin
2560 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
2561 if g_Frames_Get(AID, 'FRAMES_ITEM_RESPAWN') then
2562 begin
2563 Anim := TAnimation.Create(AID, False, 4);
2564 g_GFX_OnceAnim(X+(it.Obj.Rect.Width div 2)-16, Y+(it.Obj.Rect.Height div 2)-16, Anim);
2565 Anim.Free();
2566 end;
2567 end;
2568 end;
2570 procedure MC_RECV_ItemDestroy(var M: TMsg);
2571 var
2572 ID: Word;
2573 Quiet: Boolean;
2574 begin
2575 if not gGameOn then Exit;
2576 ID := M.ReadWord();
2577 Quiet := M.ReadByte() <> 0;
2579 if not g_Items_ValidId(ID) then exit;
2581 if not Quiet then g_Items_EmitPickupSound(ID);
2583 g_Items_Remove(ID);
2584 end;
2586 // PANEL
2588 procedure MC_RECV_PanelTexture(var M: TMsg);
2589 var
2590 TP: TPanel;
2591 PGUID: Integer;
2592 Tex, Fr: Integer;
2593 Loop, Cnt: Byte;
2594 begin
2595 if not gGameOn then Exit;
2597 PGUID := Integer(M.ReadLongWord());
2598 Tex := M.ReadLongInt();
2599 Fr := M.ReadLongInt();
2600 Cnt := M.ReadByte();
2601 Loop := M.ReadByte();
2603 TP := g_Map_PanelByGUID(PGUID);
2604 if (TP <> nil) then
2605 begin
2606 // switch texture
2607 TP.SetTexture(Tex, Loop);
2608 TP.SetFrame(Fr, Cnt);
2609 end;
2610 end;
2612 procedure MC_RECV_PanelState(var M: TMsg);
2613 var
2614 PGUID: Integer;
2615 E: Boolean;
2616 Lift: Byte;
2617 X, Y, W, H: Integer;
2618 TP: TPanel;
2619 speedX, speedY, startX, startY, endX, endY: Integer;
2620 sizeSpX, sizeSpY, sizeEX, sizeEY: Integer;
2621 mpflags: Byte;
2622 begin
2623 if not gGameOn then Exit;
2625 PGUID := Integer(M.ReadLongWord());
2626 E := (M.ReadByte() <> 0);
2627 Lift := M.ReadByte();
2628 X := M.ReadLongInt();
2629 Y := M.ReadLongInt();
2630 W := M.ReadWord();
2631 H := M.ReadWord();
2632 // mplats
2633 speedX := M.ReadLongInt();
2634 speedY := M.ReadLongInt();
2635 startX := M.ReadLongInt();
2636 startY := M.ReadLongInt();
2637 endX := M.ReadLongInt();
2638 endY := M.ReadLongInt();
2639 sizeSpX := M.ReadLongInt();
2640 sizeSpY := M.ReadLongInt();
2641 sizeEX := M.ReadLongInt();
2642 sizeEY := M.ReadLongInt();
2643 mpflags := M.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2645 TP := g_Map_PanelByGUID(PGUID);
2646 if (TP = nil) then exit;
2648 // update lifts state
2649 if TP.isGLift then g_Map_SetLiftGUID(PGUID, Lift);
2651 // update enabled/disabled state for all panels
2652 if E then g_Map_EnableWallGUID(PGUID) else g_Map_DisableWallGUID(PGUID);
2654 // update panel position, as it can be moved (mplat)
2655 TP.X := X;
2656 TP.Y := Y;
2657 TP.Width := W;
2658 TP.Height := H;
2659 // update mplat state
2660 TP.movingSpeedX := speedX;
2661 TP.movingSpeedY := speedY;
2662 TP.movingStartX := startX;
2663 TP.movingStartY := startY;
2664 TP.movingEndX := endX;
2665 TP.movingEndY := endY;
2666 TP.sizeSpeedX := sizeSpX;
2667 TP.sizeSpeedY := sizeSpY;
2668 TP.sizeEndX := sizeEX;
2669 TP.sizeEndY := sizeEY;
2670 TP.movingActive := ((mpflags and 1) <> 0);
2671 TP.moveOnce := ((mpflags and 2) <> 0);
2672 // notify panel of it's position/size change, so it can fix other internal structures
2673 TP.positionChanged();
2674 end;
2676 // TRIGGERS
2678 procedure MC_RECV_TriggerSound(var M: TMsg);
2679 var
2680 SPlaying: Boolean;
2681 SPos, SID: LongWord;
2682 SCount: LongInt;
2683 I: Integer;
2684 begin
2685 if not gGameOn then Exit;
2686 if gTriggers = nil then Exit;
2688 SID := M.ReadLongWord();
2689 SPlaying := M.ReadByte() <> 0;
2690 SPos := M.ReadLongWord();
2691 SCount := M.ReadLongInt();
2693 for I := Low(gTriggers) to High(gTriggers) do
2694 if gTriggers[I].TriggerType = TRIGGER_SOUND then
2695 if gTriggers[I].ClientID = SID then
2696 with gTriggers[I] do
2697 begin
2698 if Sound <> nil then
2699 begin
2700 if SPlaying then
2701 begin
2702 if tgcLocal then
2703 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), tgcVolume/255.0)
2704 else
2705 Sound.PlayPanVolume((tgcPan-127.0)/128.0, tgcVolume/255.0);
2706 Sound.SetPosition(SPos);
2707 end
2708 else
2709 if Sound.IsPlaying then Sound.Stop;
2710 end;
2712 SoundPlayCount := SCount;
2713 end;
2714 end;
2716 procedure MC_RECV_TriggerMusic(var M: TMsg);
2717 var
2718 MName: string;
2719 MPlaying: Boolean;
2720 MPos: LongWord;
2721 MPaused: Boolean;
2722 begin
2723 if not gGameOn then Exit;
2725 MName := M.ReadString();
2726 MPlaying := M.ReadByte() <> 0;
2727 MPos := M.ReadLongWord();
2728 MPaused := M.ReadByte() <> 0;
2729 MPos := MPos+1; //k8: stfu, fpc!
2731 if MPlaying then
2732 begin
2733 gMusic.SetByName(MName);
2734 gMusic.Play(True);
2735 // gMusic.SetPosition(MPos);
2736 gMusic.SpecPause := MPaused;
2737 end
2738 else
2739 if gMusic.IsPlaying then gMusic.Stop;
2740 end;
2742 // MONSTERS
2744 procedure MC_RECV_MonsterSpawn(var M: TMsg);
2745 var
2746 ID: Word;
2747 MType, MState, MDir, MAnim, MBehav: Byte;
2748 X, Y, VX, VY, MTargTime, MHealth, MAmmo, MSleep: Integer;
2749 MTarg: Word;
2750 Mon: TMonster;
2751 begin
2752 ID := M.ReadWord();
2753 Mon := g_Monsters_ByUID(ID);
2754 if Mon <> nil then
2755 Exit;
2757 MType := M.ReadByte();
2758 MState := M.ReadByte();
2759 MAnim := M.ReadByte();
2760 MTarg := M.ReadWord();
2761 MTargTime := M.ReadLongInt();
2762 MBehav := M.ReadByte();
2763 MSleep := M.ReadLongInt();
2764 MHealth := M.ReadLongInt();
2765 MAmmo := M.ReadLongInt();
2767 X := M.ReadLongInt();
2768 Y := M.ReadLongInt();
2769 VX := M.ReadLongInt();
2770 VY := M.ReadLongInt();
2771 MDir := M.ReadByte();
2773 g_Monsters_Create(MType, X, Y, TDirection(MDir), False, ID);
2774 Mon := g_Monsters_ByUID(ID);
2775 if Mon = nil then
2776 Exit;
2778 with Mon do
2779 begin
2781 MonsterAnim := MAnim;
2782 MonsterTargetUID := MTarg;
2783 MonsterTargetTime := MTargTime;
2784 MonsterBehaviour := MBehav;
2785 MonsterSleep := MSleep;
2786 MonsterAmmo := MAmmo;
2787 SetHealth(MHealth);
2789 SetState(MState);
2791 setPosition(X, Y); // this will call positionChanged();
2792 GameVelX := VX;
2793 GameVelY := VY;
2794 end;
2795 end;
2797 procedure MC_RECV_MonsterPos(var M: TMsg);
2798 var
2799 Mon: TMonster;
2800 ID: Word;
2801 X, Y: Integer;
2802 begin
2803 ID := M.ReadWord();
2804 Mon := g_Monsters_ByUID(ID);
2805 if Mon = nil then
2806 Exit;
2808 with Mon do
2809 begin
2810 X := M.ReadLongInt();
2811 Y := M.ReadLongInt();
2812 Mon.setPosition(X, Y); // this will call `positionChanged()`
2813 GameVelX := M.ReadLongInt();
2814 GameVelY := M.ReadLongInt();
2815 GameDirection := TDirection(M.ReadByte());
2816 end;
2817 end;
2819 procedure MC_RECV_MonsterState(var M: TMsg);
2820 var
2821 ID, OldFire: Integer;
2822 MState, MFAnm: Byte;
2823 Mon: TMonster;
2824 AnimRevert: Boolean;
2825 begin
2826 ID := M.ReadWord();
2827 Mon := g_Monsters_ByUID(ID);
2828 if Mon = nil then Exit;
2830 MState := M.ReadByte();
2831 MFAnm := M.ReadByte();
2833 with Mon do
2834 begin
2835 MonsterTargetUID := M.ReadWord();
2836 MonsterTargetTime := M.ReadLongInt();
2837 MonsterSleep := M.ReadLongInt();
2838 MonsterHealth := M.ReadLongInt();
2839 MonsterAmmo := M.ReadLongInt();
2840 MonsterPain := M.ReadLongInt();
2841 AnimRevert := M.ReadByte() <> 0;
2842 OldFire := FFireTime;
2843 FFireTime := M.ReadLongInt();
2844 if (OldFire <= 0) and (FFireTime > 0) then
2845 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
2846 RevertAnim(AnimRevert);
2848 if MonsterState <> MState then
2849 begin
2850 if (MState = MONSTATE_GO) and (MonsterState = MONSTATE_SLEEP) then WakeUpSound();
2851 if (MState = MONSTATE_DIE) then DieSound();
2852 if (MState = MONSTATE_PAIN) then MakeBloodSimple(Min(200, MonsterPain));
2853 if (MState = MONSTATE_ATTACK) then kick(nil);
2854 if (MState = MONSTATE_DEAD) then SetDeadAnim();
2856 SetState(MState, MFAnm);
2857 end;
2858 end;
2859 end;
2861 procedure MC_RECV_MonsterShot(var M: TMsg);
2862 var
2863 ID: Integer;
2864 Mon: TMonster;
2865 X, Y, VX, VY: Integer;
2866 begin
2867 ID := M.ReadWord();
2869 Mon := g_Monsters_ByUID(ID);
2870 if Mon = nil then Exit;
2872 X := M.ReadLongInt();
2873 Y := M.ReadLongInt();
2874 VX := M.ReadLongInt();
2875 VY := M.ReadLongInt();
2877 Mon.ClientAttack(X, Y, VX, VY);
2878 end;
2880 procedure MC_RECV_MonsterDelete(var M: TMsg);
2881 var
2882 ID: Integer;
2883 Mon: TMonster;
2884 begin
2885 ID := M.ReadWord();
2886 Mon := g_Monsters_ByUID(ID);
2887 if Mon = nil then Exit;
2888 Mon.SetState(5);
2889 Mon.MonsterRemoved := True;
2890 end;
2892 procedure MC_RECV_TimeSync(var M: TMsg);
2893 var
2894 Time: LongWord;
2895 begin
2896 Time := M.ReadLongWord();
2898 if gState = STATE_INTERCUSTOM then
2899 gServInterTime := Min(Time, 255);
2900 end;
2902 procedure MC_RECV_VoteEvent(var M: TMsg);
2903 var
2904 EvID: Byte;
2905 Str1, Str2: string;
2906 Int1, Int2: SmallInt;
2907 begin
2908 EvID := M.ReadByte();
2909 Int1 := M.ReadSmallInt();
2910 Int2 := M.ReadSmallInt();
2911 Str1 := M.ReadString();
2912 Str2 := M.ReadString();
2914 case EvID of
2915 NET_VE_STARTED:
2916 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True);
2917 NET_VE_PASSED:
2918 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True);
2919 NET_VE_FAILED:
2920 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
2921 NET_VE_VOTE:
2922 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True);
2923 NET_VE_INPROGRESS:
2924 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True);
2925 end;
2926 end;
2928 // CLIENT SEND
2930 procedure MC_SEND_Info(Password: string);
2931 begin
2932 NetOut.Clear();
2934 NetOut.Write(Byte(NET_MSG_INFO));
2935 NetOut.Write(GAME_VERSION);
2936 NetOut.Write(Password);
2937 NetOut.Write(gPlayer1Settings.Name);
2938 NetOut.Write(gPlayer1Settings.Model);
2939 NetOut.Write(gPlayer1Settings.Color.R);
2940 NetOut.Write(gPlayer1Settings.Color.G);
2941 NetOut.Write(gPlayer1Settings.Color.B);
2942 NetOut.Write(gPlayer1Settings.Team);
2944 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2945 end;
2947 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
2948 begin
2949 NetOut.Write(Byte(NET_MSG_CHAT));
2950 NetOut.Write(Txt);
2951 NetOut.Write(Mode);
2953 g_Net_Client_Send(True, NET_CHAN_CHAT);
2954 end;
2956 procedure MC_SEND_PlayerPos();
2957 var
2958 kByte: Word;
2959 Predict: Boolean;
2960 strafeDir: Byte;
2961 WeaponSelect: Word = 0;
2962 i: Integer;
2963 begin
2964 if not gGameOn then Exit;
2965 if gPlayers = nil then Exit;
2966 if gPlayer1 = nil then Exit;
2968 kByte := 0;
2969 Predict := NetPredictSelf; // and (not NetGotKeys);
2971 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2972 begin
2973 strafeDir := P1MoveButton shr 4;
2974 P1MoveButton := P1MoveButton and $0F;
2976 if gPlayerAction[0, ACTION_MOVELEFT] and (not gPlayerAction[0, ACTION_MOVERIGHT]) then
2977 P1MoveButton := 1
2978 else if (not gPlayerAction[0, ACTION_MOVELEFT]) and gPlayerAction[0, ACTION_MOVERIGHT] then
2979 P1MoveButton := 2
2980 else if (not gPlayerAction[0, ACTION_MOVELEFT]) and (not gPlayerAction[0, ACTION_MOVERIGHT]) then
2981 P1MoveButton := 0;
2983 // strafing
2984 if gPlayerAction[0, ACTION_STRAFE] then
2985 begin
2986 // new strafe mechanics
2987 if (strafeDir = 0) then
2988 strafeDir := P1MoveButton; // start strafing
2989 // now set direction according to strafe (reversed)
2990 if (strafeDir = 2) then
2991 gPlayer1.SetDirection(TDirection.D_LEFT)
2992 else if (strafeDir = 1) then
2993 gPlayer1.SetDirection(TDirection.D_RIGHT)
2994 end
2995 else
2996 begin
2997 strafeDir := 0; // not strafing anymore
2998 if (P1MoveButton = 2) and gPlayerAction[0, ACTION_MOVELEFT] then
2999 gPlayer1.SetDirection(TDirection.D_LEFT)
3000 else if (P1MoveButton = 1) and gPlayerAction[0, ACTION_MOVERIGHT] then
3001 gPlayer1.SetDirection(TDirection.D_RIGHT)
3002 else if P1MoveButton <> 0 then
3003 gPlayer1.SetDirection(TDirection(P1MoveButton-1));
3004 end;
3006 gPlayer1.ReleaseKeys;
3007 if P1MoveButton = 1 then
3008 begin
3009 kByte := kByte or NET_KEY_LEFT;
3010 if Predict then gPlayer1.PressKey(KEY_LEFT, 10000);
3011 end;
3012 if P1MoveButton = 2 then
3013 begin
3014 kByte := kByte or NET_KEY_RIGHT;
3015 if Predict then gPlayer1.PressKey(KEY_RIGHT, 10000);
3016 end;
3017 if gPlayerAction[0, ACTION_LOOKUP] then
3018 begin
3019 kByte := kByte or NET_KEY_UP;
3020 gPlayer1.PressKey(KEY_UP, 10000);
3021 end;
3022 if gPlayerAction[0, ACTION_LOOKDOWN] then
3023 begin
3024 kByte := kByte or NET_KEY_DOWN;
3025 gPlayer1.PressKey(KEY_DOWN, 10000);
3026 end;
3027 if gPlayerAction[0, ACTION_JUMP] then
3028 begin
3029 kByte := kByte or NET_KEY_JUMP;
3030 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3031 end;
3032 if gPlayerAction[0, ACTION_ATTACK] then kByte := kByte or NET_KEY_FIRE;
3033 if gPlayerAction[0, ACTION_ACTIVATE] then kByte := kByte or NET_KEY_OPEN;
3034 if gPlayerAction[0, ACTION_WEAPNEXT] then kByte := kByte or NET_KEY_NW;
3035 if gPlayerAction[0, ACTION_WEAPPREV] then kByte := kByte or NET_KEY_PW;
3037 gPlayerAction[0, ACTION_WEAPNEXT] := False; // HACK, remove after readyweaon&pendinweapon implementation
3038 gPlayerAction[0, ACTION_WEAPPREV] := False; // HACK, remove after readyweaon&pendinweapon implementation
3040 for i := WP_FIRST to WP_LAST do
3041 begin
3042 if gSelectWeapon[0, i] then
3043 begin
3044 WeaponSelect := WeaponSelect or Word(1 shl i);
3045 gSelectWeapon[0, i] := False
3046 end
3047 end;
3049 // fix movebutton state
3050 P1MoveButton := P1MoveButton or (strafeDir shl 4);
3051 end
3052 else
3053 kByte := NET_KEY_CHAT;
3055 NetOut.Write(Byte(NET_MSG_PLRPOS));
3056 NetOut.Write(gTime);
3057 NetOut.Write(kByte);
3058 NetOut.Write(Byte(gPlayer1.Direction));
3059 NetOut.Write(WeaponSelect);
3060 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3061 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS);
3063 //kBytePrev := kByte;
3064 //kDirPrev := gPlayer1.Direction;
3065 end;
3067 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
3068 begin
3069 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
3070 NetOut.Write(Byte(Start));
3071 NetOut.Write(Command);
3072 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3073 end;
3075 procedure MC_SEND_PlayerSettings();
3076 begin
3077 NetOut.Write(Byte(NET_MSG_PLRSET));
3078 NetOut.Write(gPlayer1Settings.Name);
3079 NetOut.Write(gPlayer1Settings.Model);
3080 NetOut.Write(gPlayer1Settings.Color.R);
3081 NetOut.Write(gPlayer1Settings.Color.G);
3082 NetOut.Write(gPlayer1Settings.Color.B);
3083 NetOut.Write(gPlayer1Settings.Team);
3085 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3086 end;
3088 procedure MC_SEND_FullStateRequest();
3089 begin
3090 NetOut.Write(Byte(NET_MSG_REQFST));
3092 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3093 end;
3095 procedure MC_SEND_CheatRequest(Kind: Byte);
3096 begin
3097 NetOut.Write(Byte(NET_MSG_CHEAT));
3098 NetOut.Write(Kind);
3100 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3101 end;
3102 procedure MC_SEND_RCONPassword(Password: string);
3103 begin
3104 NetOut.Write(Byte(NET_MSG_RCON_AUTH));
3105 NetOut.Write(Password);
3107 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3108 end;
3109 procedure MC_SEND_RCONCommand(Cmd: string);
3110 begin
3111 NetOut.Write(Byte(NET_MSG_RCON_CMD));
3112 NetOut.Write(Cmd);
3114 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3115 end;
3118 end.