DEADSOFTWARE

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