DEADSOFTWARE

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