DEADSOFTWARE

Player: Add sounds for CTF game
[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, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 unit g_netmsg;
19 interface
21 uses e_msg, g_net, g_triggers, Classes, SysUtils, md5;
23 const
24 NET_MSG_INFO = 100;
26 NET_MSG_CHAT = 101;
27 NET_MSG_SND = 102;
28 NET_MSG_GFX = 103;
29 NET_MSG_GEVENT = 104;
30 NET_MSG_SCORE = 105;
31 NET_MSG_COOP = 106;
32 NET_MSG_FLAG = 107;
33 NET_MSG_REQFST = 108;
34 NET_MSG_GSET = 109;
36 NET_MSG_PLR = 111;
37 NET_MSG_PLRPOS = 112;
38 NET_MSG_PLRSTA = 113;
39 NET_MSG_PLRDEL = 114;
40 NET_MSG_PLRDMG = 115;
41 NET_MSG_PLRDIE = 116;
42 NET_MSG_PLRFIRE= 117;
43 NET_MSG_PLRSET = 119;
44 NET_MSG_CHEAT = 120;
46 NET_MSG_ISPAWN = 121;
47 NET_MSG_IDEL = 122;
49 NET_MSG_MSPAWN = 131;
50 NET_MSG_MPOS = 132;
51 NET_MSG_MSTATE = 133;
52 NET_MSG_MSHOT = 134;
53 NET_MSG_MDEL = 135;
55 NET_MSG_PSTATE = 141;
56 NET_MSG_PTEX = 142;
58 NET_MSG_TSOUND = 151;
59 NET_MSG_TMUSIC = 152;
61 NET_MSG_SHDEL = 161;
62 NET_MSG_SHADD = 162;
63 NET_MSG_SHPOS = 163;
65 NET_MSG_RCON_AUTH = 191;
66 NET_MSG_RCON_CMD = 192;
67 NET_MSG_TIME_SYNC = 194;
68 NET_MSG_VOTE_EVENT = 195;
70 NET_MSG_MAP_REQUEST = 201;
71 NET_MSG_MAP_RESPONSE = 202;
72 NET_MSG_RES_REQUEST = 203;
73 NET_MSG_RES_RESPONSE = 204;
75 NET_CHAT_SYSTEM = 0;
76 NET_CHAT_PLAYER = 1;
77 NET_CHAT_TEAM = 2;
79 NET_RCON_NOAUTH = 0;
80 NET_RCON_PWGOOD = 1;
81 NET_RCON_PWBAD = 2;
83 NET_GFX_SPARK = 1;
84 NET_GFX_TELE = 2;
85 NET_GFX_RESPAWN = 3;
86 NET_GFX_FIRE = 4;
87 NET_GFX_EXPLODE = 5;
88 NET_GFX_BFGEXPL = 6;
89 NET_GFX_BFGHIT = 7;
90 NET_GFX_SHELL1 = 8;
91 NET_GFX_SHELL2 = 9;
92 NET_GFX_SHELL3 = 10;
94 NET_EV_MAPSTART = 1;
95 NET_EV_MAPEND = 2;
96 NET_EV_CHANGE_TEAM = 3;
97 NET_EV_PLAYER_KICK = 4;
98 NET_EV_PLAYER_BAN = 5;
99 NET_EV_LMS_WARMUP = 6;
100 NET_EV_LMS_SURVIVOR = 7;
101 NET_EV_RCON = 8;
102 NET_EV_BIGTEXT = 9;
103 NET_EV_SCORE = 10;
104 NET_EV_SCORE_MSG = 11;
105 NET_EV_LMS_START = 12;
106 NET_EV_LMS_WIN = 13;
107 NET_EV_TLMS_WIN = 14;
108 NET_EV_LMS_LOSE = 15;
109 NET_EV_LMS_DRAW = 16;
110 NET_EV_KILLCOMBO = 17;
111 NET_EV_PLAYER_TOUCH = 18;
113 NET_VE_STARTED = 1;
114 NET_VE_PASSED = 2;
115 NET_VE_FAILED = 3;
116 NET_VE_VOTE = 4;
117 NET_VE_REVOKE = 5;
118 NET_VE_INPROGRESS = 6;
120 NET_FLAG_GET = 1;
121 NET_FLAG_DROP = 2;
122 NET_FLAG_CAP = 3;
123 NET_FLAG_RETURN = 4;
125 NET_CHEAT_SUICIDE = 1;
126 NET_CHEAT_SPECTATE = 2;
128 NET_MAX_DIFFTIME = 5000 div 36;
130 // HOST MESSAGES
132 procedure MH_RECV_Info(C: pTNetClient; var M: TMsg);
133 procedure MH_RECV_Chat(C: pTNetClient; var M: TMsg);
134 procedure MH_RECV_FullStateRequest(C: pTNetClient; var M: TMsg);
135 function MH_RECV_PlayerPos(C: pTNetClient; var M: TMsg): Word;
136 procedure MH_RECV_PlayerSettings(C: pTNetClient; var M: TMsg);
137 procedure MH_RECV_CheatRequest(C: pTNetClient; var M: TMsg);
138 procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
139 procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
140 procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
141 procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
142 procedure MH_RECV_Vote(C: pTNetClient; var M: TMsg);
144 // GAME
145 procedure MH_SEND_Everything(CreatePlayers: Boolean = False; ID: Integer = NET_EVERYONE);
146 procedure MH_SEND_Info(ID: Byte);
147 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
148 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
149 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
150 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
151 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
152 procedure MH_SEND_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
153 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
154 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
155 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
156 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
157 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
158 // PLAYER
159 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
160 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
161 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
162 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
163 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
164 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
165 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
166 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
167 // ITEM
168 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
169 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
170 // PANEL
171 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
172 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
173 // MONSTER
174 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
175 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
176 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
177 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
178 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
179 // TRIGGER
180 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
181 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
182 // MISC
183 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
184 procedure MH_SEND_VoteEvent(EvType: Byte;
185 StrArg1: string = 'a'; StrArg2: string = 'b';
186 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
187 ID: Integer = NET_EVERYONE);
189 // CLIENT MESSAGES //
191 // GAME
192 procedure MC_RECV_Chat(var M: TMsg);
193 procedure MC_RECV_Effect(var M: TMsg);
194 procedure MC_RECV_Sound(var M: TMsg);
195 procedure MC_RECV_GameStats(var M: TMsg);
196 procedure MC_RECV_CoopStats(var M: TMsg);
197 procedure MC_RECV_GameEvent(var M: TMsg);
198 procedure MC_RECV_FlagEvent(var M: TMsg);
199 procedure MC_RECV_GameSettings(var M: TMsg);
200 // PLAYER
201 function MC_RECV_PlayerCreate(var M: TMsg): Word;
202 function MC_RECV_PlayerPos(var M: TMsg): Word;
203 function MC_RECV_PlayerStats(var M: TMsg): Word;
204 function MC_RECV_PlayerDelete(var M: TMsg): Word;
205 function MC_RECV_PlayerDamage(var M: TMsg): Word;
206 function MC_RECV_PlayerDeath(var M: TMsg): Word;
207 function MC_RECV_PlayerFire(var M: TMsg): Word;
208 procedure MC_RECV_PlayerSettings(var M: TMsg);
209 // ITEM
210 procedure MC_RECV_ItemSpawn(var M: TMsg);
211 procedure MC_RECV_ItemDestroy(var M: TMsg);
212 // PANEL
213 procedure MC_RECV_PanelTexture(var M: TMsg);
214 procedure MC_RECV_PanelState(var M: TMsg);
215 // MONSTER
216 procedure MC_RECV_MonsterSpawn(var M: TMsg);
217 procedure MC_RECV_MonsterPos(var M: TMsg);
218 procedure MC_RECV_MonsterState(var M: TMsg);
219 procedure MC_RECV_MonsterShot(var M: TMsg);
220 procedure MC_RECV_MonsterDelete(var M: TMsg);
221 // SHOT
222 procedure MC_RECV_CreateShot(var M: TMsg);
223 procedure MC_RECV_UpdateShot(var M: TMsg);
224 procedure MC_RECV_DeleteShot(var M: TMsg);
225 // TRIGGER
226 procedure MC_RECV_TriggerSound(var M: TMsg);
227 procedure MC_RECV_TriggerMusic(var M: TMsg);
228 // MISC
229 procedure MC_RECV_TimeSync(var M: TMsg);
230 procedure MC_RECV_VoteEvent(var M: TMsg);
231 // SERVICE
232 procedure MC_SEND_Info(Password: string);
233 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
234 procedure MC_SEND_PlayerPos();
235 procedure MC_SEND_FullStateRequest();
236 procedure MC_SEND_PlayerSettings();
237 procedure MC_SEND_CheatRequest(Kind: Byte);
238 procedure MC_SEND_RCONPassword(Password: string);
239 procedure MC_SEND_RCONCommand(Cmd: string);
240 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
241 // DOWNLOAD
242 procedure MC_SEND_MapRequest();
243 procedure MC_SEND_ResRequest(const resName: AnsiString);
245 type
246 TExternalResourceInfo = record
247 Name: string[255];
248 md5: TMD5Digest;
249 end;
251 TResDataMsg = record
252 MsgId: Byte;
253 FileSize: Integer;
254 FileData: AByte;
255 end;
257 TMapDataMsg = record
258 MsgId: Byte;
259 FileSize: Integer;
260 FileData: AByte;
261 ExternalResources: array of TExternalResourceInfo;
262 end;
264 function MapDataFromMsgStream(msgStream: TMemoryStream):TMapDataMsg;
265 function ResDataFromMsgStream(msgStream: TMemoryStream):TResDataMsg;
267 implementation
269 uses
270 Math, ENet, e_input, e_graphics, e_log,
271 g_textures, g_gfx, g_sound, g_console, g_basic, g_options, g_main,
272 g_game, g_player, g_map, g_panel, g_items, g_weapons, g_phys, g_gui,
273 g_language, g_monsters, g_netmaster, utils, wadreader, MAPDEF;
275 const
276 NET_KEY_LEFT = 1;
277 NET_KEY_RIGHT = 2;
278 NET_KEY_UP = 4;
279 NET_KEY_DOWN = 8;
280 NET_KEY_JUMP = 16;
281 NET_KEY_FIRE = 32;
282 NET_KEY_OPEN = 64;
283 NET_KEY_NW = 256;
284 NET_KEY_PW = 512;
285 NET_KEY_CHAT = 2048;
286 NET_KEY_FORCEDIR = 4096;
288 //var
289 //kBytePrev: Word = 0;
290 //kDirPrev: TDirection = D_LEFT;
291 //HostGameTime: Word = 0;
293 // HOST MESSAGES //
296 // GAME
298 procedure MH_RECV_Chat(C: pTNetClient; var M: TMsg);
299 var
300 Txt: string;
301 Mode: Byte;
302 PID: Word;
303 Pl: TPlayer;
304 begin
305 PID := C^.Player;
306 Pl := g_Player_Get(PID);
308 Txt := M.ReadString();
309 Mode := M.ReadByte();
310 if (Mode = NET_CHAT_SYSTEM) then
311 Mode := NET_CHAT_PLAYER; // prevent sending system messages from clients
312 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
313 Mode := NET_CHAT_PLAYER; // revert to player chat in non-team game
315 if Pl = nil then
316 MH_SEND_Chat(Txt, Mode)
317 else
318 MH_SEND_Chat(Pl.Name + ': ' + Txt, Mode, IfThen(Mode = NET_CHAT_TEAM, Pl.Team, NET_EVERYONE));
319 end;
321 procedure MH_RECV_Info(C: pTNetClient; var M: TMsg);
322 var
323 Ver, PName, Model, Pw: string;
324 R, G, B, T: Byte;
325 PID: Word;
326 Color: TRGB;
327 I: Integer;
328 begin
329 Ver := M.ReadString();
330 Pw := M.ReadString();
331 PName := M.ReadString();
332 Model := M.ReadString();
333 R := M.ReadByte();
334 G := M.ReadByte();
335 B := M.ReadByte();
336 T := M.ReadByte();
338 if Ver <> GAME_VERSION then
339 begin
340 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
341 _lc[I_NET_DISC_VERSION]);
342 enet_peer_disconnect(C^.Peer, NET_DISC_VERSION);
343 Exit;
344 end;
346 if g_Net_IsHostBanned(C^.Peer^.address.host) then
347 begin
348 if g_Net_IsHostBanned(C^.Peer^.address.host, True) then
349 begin
350 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
351 _lc[I_NET_DISC_BAN]);
352 enet_peer_disconnect(C^.Peer, NET_DISC_BAN);
353 end
354 else
355 begin
356 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
357 _lc[I_NET_DISC_BAN]);
358 enet_peer_disconnect(C^.Peer, NET_DISC_TEMPBAN);
359 end;
360 Exit;
361 end;
363 if NetPassword <> '' then
364 if AnsiLowerCase(NetPassword) <> AnsiLowerCase(Pw) then
365 begin
366 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
367 _lc[I_NET_DISC_PASSWORD]);
368 enet_peer_disconnect(C^.Peer, NET_DISC_PASSWORD);
369 Exit;
370 end;
372 Color.R := R;
373 Color.B := B;
374 Color.G := G;
376 PID := g_Player_Create(Model, Color, T, False);
377 with g_Player_Get(PID) do
378 begin
379 Name := PName;
380 Reset(True);
381 end;
383 C^.Player := PID;
385 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
386 e_WriteLog('NET: Client ' + PName + ' [' + IntToStr(C^.ID) +
387 '] connected. Assigned player #' + IntToStr(PID) + '.', TMsgType.Notify);
389 MH_SEND_Info(C^.ID);
391 with g_Player_Get(PID) do
392 begin
393 Name := PName;
394 FClientID := C^.ID;
395 // round in progress, don't spawn
396 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
397 begin
398 Lives := 0;
399 FNoRespawn := True;
400 Spectate;
401 FWantsInGame := True; // TODO: look into this later
402 end
403 else
404 Respawn(gGameSettings.GameType = GT_SINGLE);
405 end;
407 for I := Low(NetClients) to High(NetClients) do
408 begin
409 if NetClients[I].ID = C^.ID then Continue;
410 MH_SEND_PlayerCreate(PID, NetClients[I].ID);
411 MH_SEND_PlayerPos(True, PID, NetClients[I].ID);
412 MH_SEND_PlayerStats(PID, NetClients[I].ID);
413 end;
415 if gState in [STATE_INTERCUSTOM, STATE_FOLD] then
416 MH_SEND_GameEvent(NET_EV_MAPEND, 0, 'N', C^.ID);
418 if NetUseMaster then g_Net_Slist_Update;
419 end;
421 procedure MH_RECV_FullStateRequest(C: pTNetClient; var M: TMsg);
422 begin
423 if gGameOn then
424 MH_SEND_Everything((C^.State = NET_STATE_AUTH), C^.ID)
425 else
426 C^.RequestedFullUpdate := True;
427 end;
429 // PLAYER
431 function MH_RECV_PlayerPos(C: pTNetClient; var M: TMsg): Word;
432 var
433 Dir, i: Byte;
434 WeaponSelect: Word;
435 PID: Word;
436 kByte: Word;
437 Pl: TPlayer;
438 GT: LongWord;
439 begin
440 Result := 0;
441 if not gGameOn then Exit;
443 GT := M.ReadLongWord();
444 PID := C^.Player;
445 Pl := g_Player_Get(PID);
446 if Pl = nil then
447 Exit;
449 if (GT > gTime + NET_MAX_DIFFTIME) or (GT < Pl.NetTime) then Exit;
451 with Pl do
452 begin
453 NetTime := GT;
454 kByte := M.ReadWord();
455 Dir := M.ReadByte();
456 WeaponSelect := M.ReadWord();
457 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
458 if Direction <> TDirection(Dir) then
459 JustTeleported := False;
461 SetDirection(TDirection(Dir));
462 ReleaseKeys;
464 if kByte = NET_KEY_CHAT then
465 begin
466 PressKey(KEY_CHAT, 10000);
467 Exit;
468 end;
470 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
471 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
472 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
473 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
474 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
475 if LongBool(kByte and NET_KEY_FIRE) then PressKey(KEY_FIRE, 10000);
476 if LongBool(kByte and NET_KEY_OPEN) then PressKey(KEY_OPEN, 10000);
477 if LongBool(kByte and NET_KEY_NW) then PressKey(KEY_NEXTWEAPON, 10000);
478 if LongBool(kByte and NET_KEY_PW) then PressKey(KEY_PREVWEAPON, 10000);
480 for i := 0 to 15 do
481 begin
482 if (WeaponSelect and Word(1 shl i)) <> 0 then
483 begin
484 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
485 QueueWeaponSwitch(i);
486 end;
487 end;
488 end;
490 // MH_SEND_PlayerPos(False, PID, C^.ID);
491 end;
493 procedure MH_RECV_CheatRequest(C: pTNetClient; var M: TMsg);
494 var
495 CheatKind: Byte;
496 Pl: TPlayer;
497 begin
498 Pl := g_Player_Get(C^.Player);
499 if Pl = nil then Exit;
501 CheatKind := M.ReadByte();
503 case CheatKind of
504 NET_CHEAT_SUICIDE:
505 Pl.Damage(SUICIDE_DAMAGE, Pl.UID, 0, 0, HIT_SELF);
506 NET_CHEAT_SPECTATE:
507 begin
508 if Pl.FSpectator then
509 Pl.Respawn(False)
510 else
511 Pl.Spectate;
512 end;
513 end;
514 end;
516 procedure MH_RECV_PlayerSettings(C: pTNetClient; var M: TMsg);
517 var
518 TmpName: string;
519 TmpModel: string;
520 TmpColor: TRGB;
521 TmpTeam: Byte;
522 Pl: TPlayer;
523 begin
524 TmpName := M.ReadString();
525 TmpModel := M.ReadString();
526 TmpColor.R := M.ReadByte();
527 TmpColor.G := M.ReadByte();
528 TmpColor.B := M.ReadByte();
529 TmpTeam := M.ReadByte();
531 Pl := g_Player_Get(C^.Player);
532 if Pl = nil then Exit;
534 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
535 Pl.SwitchTeam
536 else
537 Pl.SetColor(TmpColor);
539 if Pl.Name <> TmpName then
540 begin
541 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
542 Pl.Name := TmpName;
543 end;
545 if TmpModel <> Pl.Model.Name then
546 Pl.SetModel(TmpModel);
548 MH_SEND_PlayerSettings(Pl.UID, TmpModel);
549 end;
551 // RCON
553 procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
554 var
555 Pwd: string;
556 begin
557 Pwd := M.ReadString();
558 if not NetAllowRCON then Exit;
559 if Pwd = NetRCONPassword then
560 begin
561 C^.RCONAuth := True;
562 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWGOOD, 'N', C^.ID);
563 end
564 else
565 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWBAD, 'N', C^.ID);
566 end;
568 procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
569 var
570 Cmd: string;
571 begin
572 Cmd := M.ReadString();
573 if not NetAllowRCON then Exit;
574 if not C^.RCONAuth then
575 begin
576 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_NOAUTH, 'N', C^.ID);
577 Exit;
578 end;
579 g_Console_Process(Cmd);
580 end;
582 // MISC
584 procedure MH_RECV_Vote(C: pTNetClient; var M: TMsg);
585 var
586 Start: Boolean;
587 Name, Command: string;
588 Need: Integer;
589 Pl: TPlayer;
590 begin
591 Start := M.ReadByte() <> 0;
592 Command := M.ReadString();
594 Pl := g_Player_Get(C^.Player);
595 if Pl = nil then Exit;
596 Name := Pl.Name;
598 if Start then
599 begin
600 if not g_Console_CommandBlacklisted(Command) then
601 g_Game_StartVote(Command, Name);
602 end
603 else if gVoteInProgress then
604 begin
605 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
606 Need := Floor((NetClientCount+1)/2.0) + 1
607 else
608 Need := Floor(NetClientCount/2.0) + 1;
609 if C^.Voted then
610 begin
611 Dec(gVoteCount);
612 C^.Voted := False;
613 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [Name, gVoteCount, Need]), True);
614 MH_SEND_VoteEvent(NET_VE_REVOKE, Name, 'a', gVoteCount, Need);
615 end
616 else
617 begin
618 Inc(gVoteCount);
619 C^.Voted := True;
620 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Name, gVoteCount, Need]), True);
621 MH_SEND_VoteEvent(NET_VE_VOTE, Name, 'a', gVoteCount, Need);
622 g_Game_CheckVote;
623 end;
624 end;
625 end;
627 // GAME (SEND)
629 procedure MH_SEND_Everything(CreatePlayers: Boolean = False; ID: Integer = NET_EVERYONE);
631 function sendItemRespawn (it: PItem): Boolean;
632 begin
633 result := false; // don't stop
634 MH_SEND_ItemSpawn(True, it.myid, ID);
635 end;
637 function sendMonSpawn (mon: TMonster): Boolean;
638 begin
639 result := false; // don't stop
640 MH_SEND_MonsterSpawn(mon.UID, ID);
641 end;
643 function sendPanelState (pan: TPanel): Boolean;
644 begin
645 result := false; // don't stop
646 MH_SEND_PanelState(pan.guid, ID); // anyway, to sync mplats
647 if (pan.CanChangeTexture) then MH_SEND_PanelTexture(pan.guid, pan.LastAnimLoop, ID);
648 end;
650 var
651 I: Integer;
652 begin
653 if gPlayers <> nil then
654 begin
655 for I := Low(gPlayers) to High(gPlayers) do
656 begin
657 if gPlayers[I] <> nil then
658 begin
659 if CreatePlayers then MH_SEND_PlayerCreate(gPlayers[I].UID, ID);
660 MH_SEND_PlayerPos(True, gPlayers[I].UID, ID);
661 MH_SEND_PlayerStats(gPlayers[I].UID, ID);
663 if (gPlayers[I].Flag <> FLAG_NONE) and (gGameSettings.GameMode = GM_CTF) then
664 begin
665 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED, gPlayers[I].Flag, gPlayers[I].UID, True, ID);
666 end;
667 end;
668 end;
669 end;
671 g_Items_ForEachAlive(sendItemRespawn, true); // backwards
672 g_Mons_ForEach(sendMonSpawn);
673 g_Map_ForEachPanel(sendPanelState);
675 if gTriggers <> nil then
676 begin
677 for I := Low(gTriggers) to High(gTriggers) do
678 begin
679 if gTriggers[I].TriggerType = TRIGGER_SOUND then
680 begin
681 MH_SEND_TriggerSound(gTriggers[I], ID);
682 end;
683 end;
684 end;
686 if Shots <> nil then
687 begin
688 for I := Low(Shots) to High(Shots) do
689 begin
690 if Shots[i].ShotType in [6, 7, 8] then
691 begin
692 MH_SEND_CreateShot(i, ID);
693 end;
694 end;
695 end;
697 MH_SEND_TriggerMusic(ID);
699 MH_SEND_GameStats(ID);
700 MH_SEND_CoopStats(ID);
702 if gGameSettings.GameMode = GM_CTF then
703 begin
704 if gFlags[FLAG_RED].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_RED].State, FLAG_RED, 0, True, ID);
705 if gFlags[FLAG_BLUE].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_BLUE].State, FLAG_BLUE, 0, True, ID);
706 end;
708 if CreatePlayers and (ID >= 0) then NetClients[ID].State := NET_STATE_GAME;
710 if gLMSRespawn > LMS_RESPAWN_NONE then
711 begin
712 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000, 'N', ID);
713 end;
714 end;
716 procedure MH_SEND_Info(ID: Byte);
717 var
718 Map: string;
719 begin
720 Map := g_ExtractFileName(gMapInfo.Map);
722 NetOut.Clear();
724 NetOut.Write(Byte(NET_MSG_INFO));
725 NetOut.Write(ID);
726 NetOut.Write(NetClients[ID].Player);
727 NetOut.Write(gGameSettings.WAD);
728 NetOut.Write(Map);
729 NetOut.Write(gWADHash);
730 NetOut.Write(gGameSettings.GameMode);
731 NetOut.Write(gGameSettings.GoalLimit);
732 NetOut.Write(gGameSettings.TimeLimit);
733 NetOut.Write(gGameSettings.MaxLives);
734 NetOut.Write(gGameSettings.Options);
735 NetOut.Write(gTime);
737 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
738 end;
740 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
741 var
742 Name: string;
743 i: Integer;
744 Team: Byte;
745 begin
746 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
747 Mode := NET_CHAT_PLAYER;
749 Team := 0;
750 if (Mode = NET_CHAT_TEAM) then
751 begin
752 for i := Low(gPlayers) to High(gPlayers) do
753 if (gPlayers[i] <> nil) and (gPlayers[i].FClientID >= 0) and
754 (gPlayers[i].Team = ID) then
755 begin
756 NetOut.Write(Byte(NET_MSG_CHAT));
757 NetOut.Write(Txt);
758 NetOut.Write(Mode);
759 g_Net_Host_Send(gPlayers[i].FClientID, True, NET_CHAN_CHAT);
760 end;
761 Team := ID;
762 ID := NET_EVERYONE;
763 end
764 else
765 begin
766 NetOut.Write(Byte(NET_MSG_CHAT));
767 NetOut.Write(Txt);
768 NetOut.Write(Mode);
769 g_Net_Host_Send(ID, True, NET_CHAN_CHAT);
770 end;
772 if Mode = NET_CHAT_SYSTEM then
773 Exit;
775 if ID = NET_EVERYONE then
776 begin
777 if Mode = NET_CHAT_PLAYER then
778 begin
779 g_Console_Add(Txt, True);
780 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
781 g_Game_ChatSound(b_Text_Unformat(Txt));
782 end
783 else
784 if Mode = NET_CHAT_TEAM then
785 if gPlayer1 <> nil then
786 begin
787 if (gPlayer1.Team = TEAM_RED) and (Team = TEAM_RED) then
788 begin
789 g_Console_Add(#18'[Team] '#2 + Txt, True);
790 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
791 g_Game_ChatSound(b_Text_Unformat(Txt));
792 end
793 else if (gPlayer1.Team = TEAM_BLUE) and (Team = TEAM_BLUE) then
794 begin
795 g_Console_Add(#20'[Team] '#2 + Txt, True);
796 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
797 g_Game_ChatSound(b_Text_Unformat(Txt));
798 end;
799 end;
800 end
801 else
802 begin
803 Name := g_Net_ClientName_ByID(ID);
804 g_Console_Add('-> ' + Name + ': ' + Txt, True);
805 e_WriteLog('[Tell ' + Name + '] ' + b_Text_Unformat(Txt), TMsgType.Notify);
806 g_Game_ChatSound(b_Text_Unformat(Txt), False);
807 end;
808 end;
810 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
811 begin
812 NetOut.Write(Byte(NET_MSG_GFX));
813 NetOut.Write(Kind);
814 NetOut.Write(X);
815 NetOut.Write(Y);
816 NetOut.Write(Ang);
818 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
819 end;
821 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
822 begin
823 NetOut.Write(Byte(NET_MSG_SND));
824 NetOut.Write(Name);
825 if Pos then
826 begin
827 NetOut.Write(Byte(1));
828 NetOut.Write(X);
829 NetOut.Write(Y);
830 end
831 else
832 NetOut.Write(Byte(0));
834 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
835 end;
837 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
838 begin
839 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
841 NetOut.Write(Byte(NET_MSG_SHADD));
842 NetOut.Write(Proj);
843 NetOut.Write(Shots[Proj].ShotType);
844 NetOut.Write(Shots[Proj].Target);
845 NetOut.Write(Shots[Proj].SpawnerUID);
846 NetOut.Write(Shots[Proj].Timeout);
847 NetOut.Write(Shots[Proj].Obj.X);
848 NetOut.Write(Shots[Proj].Obj.Y);
849 NetOut.Write(Shots[Proj].Obj.Vel.X);
850 NetOut.Write(Shots[Proj].Obj.Vel.Y);
852 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
853 end;
855 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
856 begin
857 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
859 NetOut.Write(Byte(NET_MSG_SHPOS));
860 NetOut.Write(Proj);
861 NetOut.Write(Shots[Proj].Obj.X);
862 NetOut.Write(Shots[Proj].Obj.Y);
863 NetOut.Write(Shots[Proj].Obj.Vel.X);
864 NetOut.Write(Shots[Proj].Obj.Vel.Y);
866 g_Net_Host_Send(ID, False, NET_CHAN_SHOTS);
867 end;
869 procedure MH_Send_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
870 begin
871 NetOut.Write(Byte(NET_MSG_SHDEL));
872 NetOut.Write(Proj);
873 NetOut.Write(Byte(Loud));
874 NetOut.Write(X);
875 NetOut.Write(Y);
877 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
878 end;
880 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
881 begin
882 NetOut.Write(Byte(NET_MSG_SCORE));
883 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
884 begin
885 NetOut.Write(gTeamStat[TEAM_RED].Goals);
886 NetOut.Write(gTeamStat[TEAM_BLUE].Goals);
887 end
888 else
889 if gGameSettings.GameMode = GM_COOP then
890 begin
891 NetOut.Write(gCoopMonstersKilled);
892 NetOut.Write(gCoopSecretsFound);
893 end;
895 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
896 end;
898 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
899 begin
900 NetOut.Write(Byte(NET_MSG_COOP));
901 NetOut.Write(gTotalMonsters);
902 NetOut.Write(gSecretsCount);
903 NetOut.Write(gCoopTotalMonstersKilled);
904 NetOut.Write(gCoopTotalSecretsFound);
905 NetOut.Write(gCoopTotalMonsters);
906 NetOut.Write(gCoopTotalSecrets);
907 end;
909 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
910 begin
911 NetOut.Write(Byte(NET_MSG_GEVENT));
912 NetOut.Write(EvType);
913 NetOut.Write(EvNum);
914 NetOut.Write(EvStr);
915 NetOut.Write(Byte(gLastMap));
916 NetOut.Write(gTime);
917 if (EvType = NET_EV_MAPSTART) and isWadPath(EvStr) then
918 begin
919 NetOut.Write(Byte(1));
920 NetOut.Write(gWADHash);
921 end else
922 NetOut.Write(Byte(0));
924 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
925 end;
927 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
928 begin
929 NetOut.Write(Byte(NET_MSG_FLAG));
930 NetOut.Write(EvType);
931 NetOut.Write(Flag);
932 NetOut.Write(Byte(Quiet));
933 NetOut.Write(PID);
934 NetOut.Write(gFlags[Flag].State);
935 NetOut.Write(gFlags[Flag].CaptureTime);
936 NetOut.Write(gFlags[Flag].Obj.X);
937 NetOut.Write(gFlags[Flag].Obj.Y);
938 NetOut.Write(gFlags[Flag].Obj.Vel.X);
939 NetOut.Write(gFlags[Flag].Obj.Vel.Y);
941 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
942 end;
944 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
945 begin
946 NetOut.Write(Byte(NET_MSG_GSET));
947 NetOut.Write(gGameSettings.GameMode);
948 NetOut.Write(gGameSettings.GoalLimit);
949 NetOut.Write(gGameSettings.TimeLimit);
950 NetOut.Write(gGameSettings.MaxLives);
951 NetOut.Write(gGameSettings.Options);
953 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
954 end;
956 // PLAYER (SEND)
958 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
959 var
960 P: TPlayer;
961 begin
962 P := g_Player_Get(PID);
963 if P = nil then Exit;
965 NetOut.Write(Byte(NET_MSG_PLR));
966 NetOut.Write(PID);
967 NetOut.Write(P.Name);
969 NetOut.Write(P.FActualModelName);
970 NetOut.Write(P.FColor.R);
971 NetOut.Write(P.FColor.G);
972 NetOut.Write(P.FColor.B);
973 NetOut.Write(P.Team);
975 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT)
976 end;
978 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
979 var
980 kByte: Word;
981 Pl: TPlayer;
982 begin
983 Pl := g_Player_Get(PID);
984 if Pl = nil then Exit;
985 if Pl.FDummy then Exit;
987 NetOut.Write(Byte(NET_MSG_PLRPOS));
988 NetOut.Write(gTime);
989 NetOut.Write(PID);
991 kByte := 0;
993 with Pl do
994 begin
995 NetOut.Write(FPing);
996 NetOut.Write(FLoss);
997 if IsKeyPressed(KEY_CHAT) then
998 kByte := NET_KEY_CHAT
999 else
1000 begin
1001 if IsKeyPressed(KEY_LEFT) then kByte := kByte or NET_KEY_LEFT;
1002 if IsKeyPressed(KEY_RIGHT) then kByte := kByte or NET_KEY_RIGHT;
1003 if IsKeyPressed(KEY_UP) then kByte := kByte or NET_KEY_UP;
1004 if IsKeyPressed(KEY_DOWN) then kByte := kByte or NET_KEY_DOWN;
1005 if IsKeyPressed(KEY_JUMP) then kByte := kByte or NET_KEY_JUMP;
1006 if JustTeleported then kByte := kByte or NET_KEY_FORCEDIR;
1007 end;
1009 NetOut.Write(kByte);
1010 if Direction = TDirection.D_LEFT then NetOut.Write(Byte(0)) else NetOut.Write(Byte(1));
1011 NetOut.Write(GameX);
1012 NetOut.Write(GameY);
1013 NetOut.Write(GameVelX);
1014 NetOut.Write(GameVelY);
1015 NetOut.Write(GameAccelX);
1016 NetOut.Write(GameAccelY);
1017 end;
1019 g_Net_Host_Send(ID, Reliable, NET_CHAN_PLAYERPOS);
1020 end;
1022 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
1023 var
1024 P: TPlayer;
1025 I: Integer;
1026 begin
1027 P := g_Player_Get(PID);
1028 if P = nil then Exit;
1030 NetOut.Write(Byte(NET_MSG_PLRSTA));
1031 NetOut.Write(PID);
1033 with P do
1034 begin
1035 NetOut.Write(Byte(alive));
1036 NetOut.Write(Byte(GodMode));
1037 NetOut.Write(Health);
1038 NetOut.Write(Armor);
1039 NetOut.Write(Air);
1040 NetOut.Write(JetFuel);
1041 NetOut.Write(Lives);
1042 NetOut.Write(Team);
1044 for I := WP_FIRST to WP_LAST do
1045 NetOut.Write(Byte(FWeapon[I]));
1047 for I := A_BULLETS to A_HIGH do
1048 NetOut.Write(FAmmo[I]);
1050 for I := A_BULLETS to A_HIGH do
1051 NetOut.Write(FMaxAmmo[I]);
1053 for I := MR_SUIT to MR_MAX do
1054 NetOut.Write(LongWord(FMegaRulez[I]));
1056 NetOut.Write(Byte(R_ITEM_BACKPACK in FRulez));
1057 NetOut.Write(Byte(R_KEY_RED in FRulez));
1058 NetOut.Write(Byte(R_KEY_GREEN in FRulez));
1059 NetOut.Write(Byte(R_KEY_BLUE in FRulez));
1060 NetOut.Write(Byte(R_BERSERK in FRulez));
1062 NetOut.Write(Frags);
1063 NetOut.Write(Death);
1065 NetOut.Write(CurrWeap);
1067 NetOut.Write(Byte(FSpectator));
1068 NetOut.Write(Byte(FGhost));
1069 NetOut.Write(Byte(FPhysics));
1070 NetOut.Write(Byte(FNoRespawn));
1071 NetOut.Write(Byte(FJetpack));
1072 NetOut.Write(FFireTime);
1073 end;
1075 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1076 end;
1078 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
1079 begin
1080 NetOut.Write(Byte(NET_MSG_PLRDMG));
1081 NetOut.Write(PID);
1082 NetOut.Write(Kind);
1083 NetOut.Write(Attacker);
1084 NetOut.Write(Value);
1085 NetOut.Write(VX);
1086 NetOut.Write(VY);
1088 g_Net_Host_Send(ID, False, NET_CHAN_PLAYER);
1089 end;
1091 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
1092 begin
1093 NetOut.Write(Byte(NET_MSG_PLRDIE));
1094 NetOut.Write(PID);
1095 NetOut.Write(KillType);
1096 NetOut.Write(DeathType);
1097 NetOut.Write(Attacker);
1099 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1100 end;
1102 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
1103 begin
1104 NetOut.Write(Byte(NET_MSG_PLRFIRE));
1105 NetOut.Write(PID);
1106 NetOut.Write(Weapon);
1107 NetOut.Write(X);
1108 NetOut.Write(Y);
1109 NetOut.Write(AX);
1110 NetOut.Write(AY);
1111 NetOut.Write(ShotID);
1113 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1114 end;
1116 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
1117 begin
1118 NetOut.Write(Byte(NET_MSG_PLRDEL));
1119 NetOut.Write(PID);
1121 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1122 end;
1124 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
1125 var
1126 Pl: TPlayer;
1127 begin
1128 Pl := g_Player_Get(PID);
1129 if Pl = nil then Exit;
1131 NetOut.Write(Byte(NET_MSG_PLRSET));
1132 NetOut.Write(PID);
1133 NetOut.Write(Pl.Name);
1134 if Mdl = '' then
1135 NetOut.Write(Pl.Model.Name)
1136 else
1137 NetOut.Write(Mdl);
1138 NetOut.Write(Pl.FColor.R);
1139 NetOut.Write(Pl.FColor.G);
1140 NetOut.Write(Pl.FColor.B);
1141 NetOut.Write(Pl.Team);
1143 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1144 end;
1146 // ITEM (SEND)
1148 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1149 var
1150 it: PItem;
1151 tt: Byte;
1152 begin
1153 it := g_Items_ByIdx(IID);
1155 NetOut.Write(Byte(NET_MSG_ISPAWN));
1156 NetOut.Write(IID);
1157 NetOut.Write(Byte(Quiet));
1158 tt := it.ItemType;
1159 if it.dropped then tt := tt or $80;
1160 NetOut.Write(tt);
1161 NetOut.Write(Byte(it.Fall));
1162 NetOut.Write(Byte(it.Respawnable));
1163 NetOut.Write(it.Obj.X);
1164 NetOut.Write(it.Obj.Y);
1165 NetOut.Write(it.Obj.Vel.X);
1166 NetOut.Write(it.Obj.Vel.Y);
1168 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1169 end;
1171 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1172 begin
1173 NetOut.Write(Byte(NET_MSG_IDEL));
1174 NetOut.Write(IID);
1175 NetOut.Write(Byte(Quiet));
1177 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1178 end;
1180 // PANEL
1182 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
1183 var
1184 TP: TPanel;
1185 begin
1186 TP := g_Map_PanelByGUID(PGUID);
1187 if (TP = nil) then exit;
1189 with TP do
1190 begin
1191 NetOut.Write(Byte(NET_MSG_PTEX));
1192 NetOut.Write(LongWord(PGUID));
1193 NetOut.Write(FCurTexture);
1194 NetOut.Write(FCurFrame);
1195 NetOut.Write(FCurFrameCount);
1196 NetOut.Write(AnimLoop);
1197 end;
1199 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1200 end;
1202 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
1203 var
1204 TP: TPanel;
1205 mpflags: Byte = 0;
1206 begin
1207 TP := g_Map_PanelByGUID(PGUID);
1208 if (TP = nil) then exit;
1210 NetOut.Write(Byte(NET_MSG_PSTATE));
1211 NetOut.Write(LongWord(PGUID));
1212 NetOut.Write(Byte(TP.Enabled));
1213 NetOut.Write(TP.LiftType);
1214 NetOut.Write(TP.X);
1215 NetOut.Write(TP.Y);
1216 NetOut.Write(Word(TP.Width));
1217 NetOut.Write(Word(TP.Height));
1218 // mplats
1219 NetOut.Write(LongInt(TP.movingSpeedX));
1220 NetOut.Write(LongInt(TP.movingSpeedY));
1221 NetOut.Write(LongInt(TP.movingStartX));
1222 NetOut.Write(LongInt(TP.movingStartY));
1223 NetOut.Write(LongInt(TP.movingEndX));
1224 NetOut.Write(LongInt(TP.movingEndY));
1225 NetOut.Write(LongInt(TP.sizeSpeedX));
1226 NetOut.Write(LongInt(TP.sizeSpeedY));
1227 NetOut.Write(LongInt(TP.sizeEndX));
1228 NetOut.Write(LongInt(TP.sizeEndY));
1229 if TP.movingActive then mpflags := mpflags or 1;
1230 if TP.moveOnce then mpflags := mpflags or 2;
1231 NetOut.Write(Byte(mpflags));
1233 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1234 end;
1236 // TRIGGER
1238 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
1239 begin
1240 if gTriggers = nil then Exit;
1241 if T.Sound = nil then Exit;
1243 NetOut.Write(Byte(NET_MSG_TSOUND));
1244 NetOut.Write(T.ClientID);
1245 NetOut.Write(Byte(T.Sound.IsPlaying));
1246 NetOut.Write(LongWord(T.Sound.GetPosition));
1247 NetOut.Write(T.SoundPlayCount);
1249 g_Net_Host_Send(ID, True);
1250 end;
1252 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
1253 begin
1254 NetOut.Write(Byte(NET_MSG_TMUSIC));
1255 NetOut.Write(gMusic.Name);
1256 NetOut.Write(Byte(gMusic.IsPlaying));
1257 NetOut.Write(LongWord(gMusic.GetPosition));
1258 NetOut.Write(Byte(gMusic.SpecPause or gMusic.IsPaused));
1260 g_Net_Host_Send(ID, True);
1261 end;
1263 // MONSTER
1265 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
1266 var
1267 M: TMonster;
1268 begin
1269 M := g_Monsters_ByUID(UID);
1270 if M = nil then
1271 Exit;
1273 with M do
1274 begin
1275 NetOut.Write(Byte(NET_MSG_MSPAWN));
1276 NetOut.Write(UID);
1277 NetOut.Write(MonsterType);
1278 NetOut.Write(MonsterState);
1279 NetOut.Write(MonsterAnim);
1280 NetOut.Write(MonsterTargetUID);
1281 NetOut.Write(MonsterTargetTime);
1282 NetOut.Write(MonsterBehaviour);
1283 NetOut.Write(MonsterSleep);
1284 NetOut.Write(MonsterHealth);
1285 NetOut.Write(MonsterAmmo);
1286 NetOut.Write(GameX);
1287 NetOut.Write(GameY);
1288 NetOut.Write(GameVelX);
1289 NetOut.Write(GameVelY);
1290 NetOut.Write(Byte(GameDirection));
1291 end;
1293 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1294 end;
1296 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
1297 var
1298 M: TMonster;
1299 begin
1300 M := g_Monsters_ByUID(UID);
1301 if M = nil then Exit;
1303 NetOut.Write(Byte(NET_MSG_MPOS));
1304 NetOut.Write(UID);
1306 with M do
1307 begin
1308 NetOut.Write(GameX);
1309 NetOut.Write(GameY);
1310 NetOut.Write(GameVelX);
1311 NetOut.Write(GameVelY);
1312 NetOut.Write(Byte(GameDirection));
1313 end;
1315 g_Net_Host_Send(ID, False, NET_CHAN_MONSTERPOS);
1316 end;
1318 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
1319 var
1320 M: TMonster;
1321 begin
1322 M := g_Monsters_ByUID(UID);
1323 if M = nil then Exit;
1325 NetOut.Write(Byte(NET_MSG_MSTATE));
1326 NetOut.Write(UID);
1328 with M do
1329 begin
1330 NetOut.Write(MonsterState);
1331 NetOut.Write(ForcedAnim);
1332 NetOut.Write(MonsterTargetUID);
1333 NetOut.Write(MonsterTargetTime);
1334 NetOut.Write(MonsterSleep);
1335 NetOut.Write(MonsterHealth);
1336 NetOut.Write(MonsterAmmo);
1337 NetOut.Write(MonsterPain);
1338 NetOut.Write(Byte(AnimIsReverse));
1339 NetOut.Write(FFireTime);
1340 end;
1342 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1343 end;
1345 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
1346 begin
1347 NetOut.Write(Byte(NET_MSG_MSHOT));
1348 NetOut.Write(UID);
1349 NetOut.Write(X);
1350 NetOut.Write(Y);
1351 NetOut.Write(VX);
1352 NetOut.Write(VY);
1354 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1355 end;
1357 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
1358 var
1359 M: TMonster;
1360 begin
1361 M := g_Monsters_ByUID(UID);
1362 if M = nil then Exit;
1364 NetOut.Write(Byte(NET_MSG_MDEL));
1365 NetOut.Write(UID);
1367 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1368 end;
1370 // MISC
1372 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
1373 begin
1374 NetOut.Write(Byte(NET_MSG_TIME_SYNC));
1375 NetOut.Write(Time);
1377 g_Net_Host_Send(ID, False, NET_CHAN_SERVICE);
1378 end;
1380 procedure MH_SEND_VoteEvent(EvType: Byte;
1381 StrArg1: string = 'a'; StrArg2: string = 'b';
1382 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
1383 ID: Integer = NET_EVERYONE);
1384 begin
1385 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
1386 NetOut.Write(EvType);
1387 NetOut.Write(IntArg1);
1388 NetOut.Write(IntArg2);
1389 NetOut.Write(StrArg1);
1390 NetOut.Write(StrArg2);
1392 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1393 end;
1395 // CLIENT MESSAGES //
1397 // GAME
1399 procedure MC_RECV_Chat(var M: TMsg);
1400 var
1401 Txt: string;
1402 Mode: Byte;
1403 begin
1404 Txt := M.ReadString();
1405 Mode := M.ReadByte();
1407 if Mode <> NET_CHAT_SYSTEM then
1408 begin
1409 if Mode = NET_CHAT_PLAYER then
1410 begin
1411 g_Console_Add(Txt, True);
1412 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1413 g_Game_ChatSound(b_Text_Unformat(Txt));
1414 end else
1415 if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then
1416 begin
1417 if gPlayer1.Team = TEAM_RED then
1418 g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True);
1419 if gPlayer1.Team = TEAM_BLUE then
1420 g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True);
1421 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1422 g_Game_ChatSound(b_Text_Unformat(Txt));
1423 end;
1424 end else
1425 g_Console_Add(Txt, True);
1426 end;
1428 procedure MC_RECV_Effect(var M: TMsg);
1429 var
1430 Kind: Byte;
1431 X, Y: Integer;
1432 Ang: SmallInt;
1433 Anim: TAnimation;
1434 ID: LongWord;
1435 begin
1436 if not gGameOn then Exit;
1437 Kind := M.ReadByte();
1438 X := M.ReadLongInt();
1439 Y := M.ReadLongInt();
1440 Ang := M.ReadSmallInt();
1442 case Kind of
1443 NET_GFX_SPARK:
1444 g_GFX_Spark(X, Y, 2 + Random(2), Ang, 0, 0);
1446 NET_GFX_TELE:
1447 begin
1448 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
1449 begin
1450 Anim := TAnimation.Create(ID, False, 3);
1451 g_GFX_OnceAnim(X, Y, Anim);
1452 Anim.Free();
1453 end;
1454 if Ang = 1 then
1455 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
1456 end;
1458 NET_GFX_EXPLODE:
1459 begin
1460 if g_Frames_Get(ID, 'FRAMES_EXPLODE_ROCKET') then
1461 begin
1462 Anim := TAnimation.Create(ID, False, 6);
1463 Anim.Blending := False;
1464 g_GFX_OnceAnim(X-64, Y-64, Anim);
1465 Anim.Free();
1466 end;
1467 if Ang = 1 then
1468 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X, Y);
1469 end;
1471 NET_GFX_BFGEXPL:
1472 begin
1473 if g_Frames_Get(ID, 'FRAMES_EXPLODE_BFG') then
1474 begin
1475 Anim := TAnimation.Create(ID, False, 6);
1476 Anim.Blending := False;
1477 g_GFX_OnceAnim(X-64, Y-64, Anim);
1478 Anim.Free();
1479 end;
1480 if Ang = 1 then
1481 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X, Y);
1482 end;
1484 NET_GFX_BFGHIT:
1485 begin
1486 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1487 begin
1488 Anim := TAnimation.Create(ID, False, 4);
1489 g_GFX_OnceAnim(X-32, Y-32, Anim);
1490 Anim.Free();
1491 end;
1492 end;
1494 NET_GFX_FIRE:
1495 begin
1496 if g_Frames_Get(ID, 'FRAMES_FIRE') then
1497 begin
1498 Anim := TAnimation.Create(ID, False, 4);
1499 g_GFX_OnceAnim(X, Y, Anim);
1500 Anim.Free();
1501 end;
1502 if Ang = 1 then
1503 g_Sound_PlayExAt('SOUND_FIRE', X, Y);
1504 end;
1506 NET_GFX_RESPAWN:
1507 begin
1508 if g_Frames_Get(ID, 'FRAMES_ITEM_RESPAWN') then
1509 begin
1510 Anim := TAnimation.Create(ID, False, 4);
1511 g_GFX_OnceAnim(X, Y, Anim);
1512 Anim.Free();
1513 end;
1514 if Ang = 1 then
1515 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
1516 end;
1518 NET_GFX_SHELL1:
1519 g_Player_CreateShell(X, Y, 0, -2, SHELL_BULLET);
1521 NET_GFX_SHELL2:
1522 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1524 NET_GFX_SHELL3:
1525 begin
1526 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1527 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1528 end;
1529 end;
1530 end;
1532 procedure MC_RECV_Sound(var M: TMsg);
1533 var
1534 Name: string;
1535 X, Y: Integer;
1536 Pos: Boolean;
1537 begin
1538 Name := M.ReadString();
1539 Pos := M.ReadByte() <> 0;
1540 if Pos then
1541 begin
1542 X := M.ReadLongInt();
1543 Y := M.ReadLongInt();
1544 g_Sound_PlayExAt(Name, X, Y);
1545 end
1546 else
1547 g_Sound_PlayEx(Name);
1548 end;
1550 procedure MC_RECV_CreateShot(var M: TMsg);
1551 var
1552 I, X, Y, XV, YV: Integer;
1553 Timeout: LongWord;
1554 Target, Spawner: Word;
1555 ShType: Byte;
1556 begin
1557 I := M.ReadLongInt();
1558 ShType := M.ReadByte();
1559 Target := M.ReadWord();
1560 Spawner := M.ReadWord();
1561 Timeout := M.ReadLongWord();
1562 X := M.ReadLongInt();
1563 Y := M.ReadLongInt();
1564 XV := M.ReadLongInt();
1565 YV := M.ReadLongInt();
1567 I := g_Weapon_CreateShot(I, ShType, Spawner, Target, X, Y, XV, YV);
1568 if (Shots <> nil) and (I <= High(Shots)) then
1569 begin
1570 Shots[I].Timeout := Timeout;
1571 //Shots[I].Target := Target; // TODO: find a use for Target later
1572 end;
1573 end;
1575 procedure MC_RECV_UpdateShot(var M: TMsg);
1576 var
1577 I, TX, TY, TXV, TYV: Integer;
1578 begin
1579 I := M.ReadLongInt();
1580 TX := M.ReadLongInt();
1581 TY := M.ReadLongInt();
1582 TXV := M.ReadLongInt();
1583 TYV := M.ReadLongInt();
1585 if (Shots <> nil) and (I <= High(Shots)) then
1586 with (Shots[i]) do
1587 begin
1588 Obj.X := TX;
1589 Obj.Y := TY;
1590 Obj.Vel.X := TXV;
1591 Obj.Vel.Y := TYV;
1592 end;
1593 end;
1595 procedure MC_RECV_DeleteShot(var M: TMsg);
1596 var
1597 I, X, Y: Integer;
1598 L: Boolean;
1599 begin
1600 if not gGameOn then Exit;
1601 I := M.ReadLongInt();
1602 L := (M.ReadByte() <> 0);
1603 X := M.ReadLongInt();
1604 Y := M.ReadLongInt();
1606 g_Weapon_DestroyShot(I, X, Y, L);
1607 end;
1609 procedure MC_RECV_GameStats(var M: TMsg);
1610 begin
1611 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1612 begin
1613 gTeamStat[TEAM_RED].Goals := M.ReadSmallInt();
1614 gTeamStat[TEAM_BLUE].Goals := M.ReadSmallInt();
1615 end
1616 else
1617 if gGameSettings.GameMode = GM_COOP then
1618 begin
1619 gCoopMonstersKilled := M.ReadWord();
1620 gCoopSecretsFound := M.ReadWord();
1621 end;
1622 end;
1624 procedure MC_RECV_CoopStats(var M: TMsg);
1625 begin
1626 gTotalMonsters := M.ReadLongInt();
1627 gSecretsCount := M.ReadLongInt();
1628 gCoopTotalMonstersKilled := M.ReadWord();
1629 gCoopTotalSecretsFound := M.ReadWord();
1630 gCoopTotalMonsters := M.ReadWord();
1631 gCoopTotalSecrets := M.ReadWord();
1632 end;
1634 procedure MC_RECV_GameEvent(var M: TMsg);
1635 var
1636 EvType: Byte;
1637 EvNum: Integer;
1638 EvStr: string;
1639 EvTime: LongWord;
1640 BHash: Boolean;
1641 EvHash: TMD5Digest;
1642 pl: TPlayer;
1643 i1, i2: TStrings_Locale;
1644 pln: String;
1645 cnt: Byte;
1646 begin
1647 FillChar(EvHash, Sizeof(EvHash), 0);
1648 EvType := M.ReadByte();
1649 EvNum := M.ReadLongInt();
1650 EvStr := M.ReadString();
1651 gLastMap := M.ReadByte() <> 0;
1652 if gLastMap and (gGameSettings.GameMode = GM_COOP) then gStatsOff := True;
1653 gStatsPressed := True;
1654 EvTime := M.ReadLongWord();
1655 BHash := M.ReadByte() <> 0;
1656 if BHash then
1657 EvHash := M.ReadMD5();
1659 gTime := EvTime;
1661 case EvType of
1662 NET_EV_MAPSTART:
1663 begin
1664 gGameOn := False;
1665 g_Game_ClearLoading();
1666 g_Game_StopAllSounds(True);
1668 gSwitchGameMode := Byte(EvNum);
1669 gGameSettings.GameMode := gSwitchGameMode;
1671 gWADHash := EvHash;
1672 if not g_Game_StartMap(EvStr, True) then
1673 begin
1674 if not isWadPath(EvStr) then
1675 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + EvStr]))
1676 else
1677 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [EvStr]));
1678 Exit;
1679 end;
1681 MC_SEND_FullStateRequest;
1682 end;
1684 NET_EV_MAPEND:
1685 begin
1686 gMissionFailed := EvNum <> 0;
1687 gExit := EXIT_ENDLEVELCUSTOM;
1688 end;
1690 NET_EV_RCON:
1691 begin
1692 case EvNum of
1693 NET_RCON_NOAUTH:
1694 g_Console_Add(_lc[I_NET_RCON_NOAUTH], True);
1695 NET_RCON_PWGOOD:
1696 g_Console_Add(_lc[I_NET_RCON_PWD_VALID], True);
1697 NET_RCON_PWBAD:
1698 g_Console_Add(_lc[I_NET_RCON_PWD_INVALID], True);
1699 end;
1700 end;
1702 NET_EV_CHANGE_TEAM:
1703 begin
1704 if EvNum = TEAM_RED then
1705 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True);
1706 if EvNum = TEAM_BLUE then
1707 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True);
1708 end;
1710 NET_EV_PLAYER_KICK:
1711 g_Console_Add(Format(_lc[I_PLAYER_KICK], [EvStr]), True);
1713 NET_EV_PLAYER_BAN:
1714 g_Console_Add(Format(_lc[I_PLAYER_BAN], [EvStr]), True);
1716 NET_EV_LMS_WARMUP:
1717 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [EvNum]), True);
1719 NET_EV_LMS_SURVIVOR:
1720 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True);
1722 NET_EV_BIGTEXT:
1723 g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum));
1725 NET_EV_SCORE:
1726 begin
1727 pl := g_Player_Get(EvNum and $FFFF);
1728 if pl = nil then
1729 pln := '?'
1730 else
1731 pln := pl.Name;
1732 cnt := (EvNum shr 16) and $FF;
1733 if Pos('w', EvStr) = 0 then
1734 begin
1735 // Default score
1736 if Pos('t', EvStr) = 0 then
1737 begin
1738 // Player +/- score
1739 if Pos('-', EvStr) = 0 then
1740 begin
1741 if Pos('e', EvStr) = 0 then
1742 i1 := I_PLAYER_SCORE_ADD_OWN
1743 else
1744 i1 := I_PLAYER_SCORE_ADD_ENEMY;
1745 end else
1746 begin
1747 if Pos('e', EvStr) = 0 then
1748 i1 := I_PLAYER_SCORE_SUB_OWN
1749 else
1750 i1 := I_PLAYER_SCORE_SUB_ENEMY;
1751 end;
1752 // Which team
1753 if Pos('r', EvStr) > 0 then
1754 i2 := I_PLAYER_SCORE_TO_RED
1755 else
1756 i2 := I_PLAYER_SCORE_TO_BLUE;
1757 g_Console_Add(Format(_lc[i1], [pln, cnt, _lc[i2]]), True);
1758 end else
1759 begin
1760 // Team +/- score
1761 if Pos('-', EvStr) = 0 then
1762 i1 := I_PLAYER_SCORE_ADD_TEAM
1763 else
1764 i1 := I_PLAYER_SCORE_SUB_TEAM;
1765 // Which team
1766 if Pos('r', EvStr) > 0 then
1767 i2 := I_PLAYER_SCORE_RED
1768 else
1769 i2 := I_PLAYER_SCORE_BLUE;
1770 g_Console_Add(Format(_lc[i1], [_lc[i2], cnt]), True);
1771 end;
1772 end else
1773 begin
1774 // Game Win
1775 if Pos('e', EvStr) = 0 then
1776 i1 := I_PLAYER_SCORE_WIN_OWN
1777 else
1778 i1 := I_PLAYER_SCORE_WIN_ENEMY;
1779 // Which team
1780 if Pos('r', EvStr) > 0 then
1781 i2 := I_PLAYER_SCORE_TO_RED
1782 else
1783 i2 := I_PLAYER_SCORE_TO_BLUE;
1784 g_Console_Add(Format(_lc[i1], [pln, _lc[i2]]), True);
1785 end;
1786 end;
1788 NET_EV_SCORE_MSG:
1789 begin
1790 if EvNum = TEAM_RED then
1791 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1792 if EvNum = TEAM_BLUE then
1793 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1794 if EvNum = -TEAM_RED then
1795 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1796 if EvNum = -TEAM_BLUE then
1797 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1798 end;
1800 NET_EV_LMS_START:
1801 begin
1802 g_Player_RemoveAllCorpses;
1803 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
1804 end;
1806 NET_EV_LMS_WIN:
1807 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(EvStr)]), 144);
1809 NET_EV_TLMS_WIN:
1810 begin
1811 if EvNum = TEAM_RED then
1812 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
1813 if EvNum = TEAM_BLUE then
1814 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
1815 end;
1817 NET_EV_LMS_LOSE:
1818 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
1820 NET_EV_LMS_DRAW:
1821 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
1823 NET_EV_KILLCOMBO:
1824 g_Game_Announce_KillCombo(EvNum);
1826 NET_EV_PLAYER_TOUCH:
1827 begin
1828 pl := g_Player_Get(EvNum);
1829 if pl <> nil then
1830 pl.Touch();
1831 end;
1833 end;
1834 end;
1836 procedure MC_RECV_FlagEvent(var M: TMsg);
1837 var
1838 PID: Word;
1839 Pl: TPlayer;
1840 EvType: Byte;
1841 Fl, a: Byte;
1842 Quiet: Boolean;
1843 s, ts: string;
1844 begin
1845 EvType := M.ReadByte();
1846 Fl := M.ReadByte();
1848 if Fl = FLAG_NONE then Exit;
1850 Quiet := (M.ReadByte() <> 0);
1851 PID := M.ReadWord();
1853 gFlags[Fl].State := M.ReadByte();
1854 gFlags[Fl].CaptureTime := M.ReadLongWord();
1855 gFlags[Fl].Obj.X := M.ReadLongInt();
1856 gFlags[Fl].Obj.Y := M.ReadLongInt();
1857 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
1858 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
1860 Pl := g_Player_Get(PID);
1861 if (Pl = nil) and
1862 (EvType <> FLAG_STATE_NORMAL) and
1863 (EvType <> FLAG_STATE_DROPPED) and
1864 (EvType <> FLAG_STATE_RETURNED) then
1865 Exit;
1867 case EvType of
1868 FLAG_STATE_NORMAL:
1869 begin
1870 if Quiet or (Pl = nil) then Exit;
1872 if Fl = FLAG_RED then
1873 s := _lc[I_PLAYER_FLAG_RED]
1874 else
1875 s := _lc[I_PLAYER_FLAG_BLUE];
1877 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
1879 if ((Pl = gPlayer1) or (Pl = gPlayer2)
1880 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
1881 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
1882 a := 0
1883 else
1884 a := 1;
1886 if not sound_ret_flag[a].IsPlaying() then
1887 sound_ret_flag[a].Play();
1888 end;
1890 FLAG_STATE_CAPTURED:
1891 begin
1892 if (Pl <> nil) then Pl.SetFlag(Fl);
1894 if Quiet then Exit;
1896 if Fl = FLAG_RED then
1897 s := _lc[I_PLAYER_FLAG_RED]
1898 else
1899 s := _lc[I_PLAYER_FLAG_BLUE];
1901 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [Pl.Name, s]), True);
1902 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
1904 if ((Pl = gPlayer1) or (Pl = gPlayer2)
1905 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
1906 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
1907 a := 0
1908 else
1909 a := 1;
1911 if not sound_get_flag[a].IsPlaying() then
1912 sound_get_flag[a].Play();
1913 end;
1915 FLAG_STATE_DROPPED:
1916 begin
1917 if (Pl <> nil) then Pl.SetFlag(FLAG_NONE);
1919 if Quiet or (Pl = nil) then Exit;
1921 if Fl = FLAG_RED then
1922 s := _lc[I_PLAYER_FLAG_RED]
1923 else
1924 s := _lc[I_PLAYER_FLAG_BLUE];
1926 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [Pl.Name, s]), True);
1927 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
1929 if ((Pl = gPlayer1) or (Pl = gPlayer2)
1930 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
1931 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
1932 a := 0
1933 else
1934 a := 1;
1936 if not sound_lost_flag[a].IsPlaying() then
1937 sound_lost_flag[a].Play();
1938 end;
1940 FLAG_STATE_SCORED:
1941 begin
1942 g_Map_ResetFlag(FLAG_RED);
1943 g_Map_ResetFlag(FLAG_BLUE);
1944 if Quiet or (Pl = nil) then Exit;
1945 Pl.SetFlag(FLAG_NONE);
1947 if Fl = FLAG_RED then
1948 s := _lc[I_PLAYER_FLAG_RED]
1949 else
1950 s := _lc[I_PLAYER_FLAG_BLUE];
1952 ts := Format('%.4d', [gFlags[Fl].CaptureTime]);
1953 Insert('.', ts, Length(ts) + 1 - 3);
1954 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [Pl.Name, s, ts]), True);
1955 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
1957 if ((Pl = gPlayer1) or (Pl = gPlayer2)
1958 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
1959 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
1960 a := 0
1961 else
1962 a := 1;
1964 if not sound_cap_flag[a].IsPlaying() then
1965 sound_cap_flag[a].Play();
1966 end;
1968 FLAG_STATE_RETURNED:
1969 begin
1970 g_Map_ResetFlag(Fl);
1971 if Quiet then Exit;
1973 if Fl = FLAG_RED then
1974 s := _lc[I_PLAYER_FLAG_RED]
1975 else
1976 s := _lc[I_PLAYER_FLAG_BLUE];
1978 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
1980 if ((Pl = gPlayer1) or (Pl = gPlayer2)
1981 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
1982 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
1983 a := 0
1984 else
1985 a := 1;
1987 if not sound_ret_flag[a].IsPlaying() then
1988 sound_ret_flag[a].Play();
1989 end;
1990 end;
1991 end;
1993 procedure MC_RECV_GameSettings(var M: TMsg);
1994 begin
1995 gGameSettings.GameMode := M.ReadByte();
1996 gGameSettings.GoalLimit := M.ReadWord();
1997 gGameSettings.TimeLimit := M.ReadWord();
1998 gGameSettings.MaxLives := M.ReadByte();
1999 gGameSettings.Options := M.ReadLongWord();
2000 end;
2002 // PLAYER
2004 function MC_RECV_PlayerCreate(var M: TMsg): Word;
2005 var
2006 PID, DID: Word;
2007 PName, Model: string;
2008 Color: TRGB;
2009 T: Byte;
2010 Pl: TPlayer;
2011 begin
2012 PID := M.ReadWord();
2013 Pl := g_Player_Get(PID);
2015 PName := M.ReadString();
2016 Model := M.ReadString();
2017 Color.R := M.ReadByte();
2018 Color.G := M.ReadByte();
2019 Color.B := M.ReadByte();
2020 T := M.ReadByte();
2022 Result := 0;
2023 if (PID <> NetPlrUID1) and (PID <> NetPlrUID2) then
2024 begin
2025 if (Pl <> nil) then Exit;
2026 DID := g_Player_Create(Model, Color, T, False);
2027 with g_Player_Get(DID) do
2028 begin
2029 UID := PID;
2030 Name := PName;
2031 Reset(True);
2032 end;
2033 end
2034 else
2035 begin
2036 if (PID = NetPlrUID1) and (gPlayer1 <> nil) then begin
2037 gPlayer1.UID := PID;
2038 gPlayer1.Model.SetColor(Color.R, Color.G, Color.B);
2039 gPlayer1.ChangeTeam(T);
2040 end;
2041 if (PID = NetPlrUID2) and (gPlayer2 <> nil) then begin
2042 gPlayer2.UID := PID;
2043 gPlayer2.Model.SetColor(Color.R, Color.G, Color.B);
2044 gPlayer2.ChangeTeam(T);
2045 end;
2046 end;
2048 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
2049 e_WriteLog('NET: Player ' + PName + ' [' + IntToStr(PID) + '] added.', TMsgType.Notify);
2050 Result := PID;
2051 end;
2053 function MC_RECV_PlayerPos(var M: TMsg): Word;
2054 var
2055 GT: LongWord;
2056 PID: Word;
2057 kByte: Word;
2058 Pl: TPlayer;
2059 Dir: Byte;
2060 TmpX, TmpY: Integer;
2061 begin
2062 Result := 0;
2064 GT := M.ReadLongWord();
2065 if GT < gTime - NET_MAX_DIFFTIME then
2066 begin
2067 gTime := GT;
2068 Exit;
2069 end;
2070 gTime := GT;
2072 PID := M.ReadWord();
2073 Pl := g_Player_Get(PID);
2075 if Pl = nil then Exit;
2077 Result := PID;
2079 with Pl do
2080 begin
2081 FPing := M.ReadWord();
2082 FLoss := M.ReadByte();
2083 kByte := M.ReadWord();
2084 Dir := M.ReadByte();
2086 TmpX := M.ReadLongInt();
2087 TmpY := M.ReadLongInt();
2089 ReleaseKeys;
2091 if (kByte = NET_KEY_CHAT) then
2092 PressKey(KEY_CHAT, 10000)
2093 else
2094 begin
2095 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
2096 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
2097 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
2098 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
2099 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
2100 end;
2102 if ((Pl <> gPlayer1) and (Pl <> gPlayer2)) or LongBool(kByte and NET_KEY_FORCEDIR) then
2103 SetDirection(TDirection(Dir));
2105 GameVelX := M.ReadLongInt();
2106 GameVelY := M.ReadLongInt();
2107 GameAccelX := M.ReadLongInt();
2108 GameAccelY := M.ReadLongInt();
2109 SetLerp(TmpX, TmpY);
2110 if NetForcePlayerUpdate then Update();
2111 end;
2112 end;
2114 function MC_RECV_PlayerStats(var M: TMsg): Word;
2115 var
2116 PID: Word;
2117 Pl: TPlayer;
2118 I: Integer;
2119 OldJet: Boolean;
2120 NewTeam: Byte;
2121 begin
2122 PID := M.ReadWord();
2123 Pl := g_Player_Get(PID);
2124 Result := 0;
2125 if Pl = nil then
2126 Exit;
2128 with Pl do
2129 begin
2130 alive := (M.ReadByte() <> 0);
2131 GodMode := (M.ReadByte() <> 0);
2132 Health := M.ReadLongInt();
2133 Armor := M.ReadLongInt();
2134 Air := M.ReadLongInt();
2135 JetFuel := M.ReadLongInt();
2136 Lives := M.ReadByte();
2137 NewTeam := M.ReadByte();
2139 for I := WP_FIRST to WP_LAST do
2140 FWeapon[I] := (M.ReadByte() <> 0);
2142 for I := A_BULLETS to A_HIGH do
2143 FAmmo[I] := M.ReadWord();
2145 for I := A_BULLETS to A_HIGH do
2146 FMaxAmmo[I] := M.ReadWord();
2148 for I := MR_SUIT to MR_MAX do
2149 FMegaRulez[I] := M.ReadLongWord();
2151 FRulez := [];
2152 if (M.ReadByte() <> 0) then
2153 FRulez := FRulez + [R_ITEM_BACKPACK];
2154 if (M.ReadByte() <> 0) then
2155 FRulez := FRulez + [R_KEY_RED];
2156 if (M.ReadByte() <> 0) then
2157 FRulez := FRulez + [R_KEY_GREEN];
2158 if (M.ReadByte() <> 0) then
2159 FRulez := FRulez + [R_KEY_BLUE];
2160 if (M.ReadByte() <> 0) then
2161 FRulez := FRulez + [R_BERSERK];
2163 Frags := M.ReadLongInt();
2164 Death := M.ReadLongInt();
2166 SetWeapon(M.ReadByte());
2168 FSpectator := M.ReadByte() <> 0;
2169 if FSpectator then
2170 begin
2171 if Pl = gPlayer1 then
2172 begin
2173 gLMSPID1 := UID;
2174 gPlayer1 := nil;
2175 end;
2176 if Pl = gPlayer2 then
2177 begin
2178 gLMSPID2 := UID;
2179 gPlayer2 := nil;
2180 end;
2181 end
2182 else
2183 begin
2184 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
2185 gPlayer1 := g_Player_Get(gLMSPID1);
2186 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
2187 gPlayer2 := g_Player_Get(gLMSPID2);
2188 end;
2189 FGhost := M.ReadByte() <> 0;
2190 FPhysics := M.ReadByte() <> 0;
2191 FNoRespawn := M.ReadByte() <> 0;
2192 OldJet := FJetpack;
2193 FJetpack := M.ReadByte() <> 0;
2194 FFireTime := M.ReadLongInt();
2195 if OldJet and not FJetpack then
2196 JetpackOff
2197 else if not OldJet and FJetpack then
2198 JetpackOn;
2199 if Team <> NewTeam then
2200 Pl.ChangeTeam(NewTeam);
2201 end;
2203 Result := PID;
2204 end;
2206 function MC_RECV_PlayerDamage(var M: TMsg): Word;
2207 var
2208 PID: Word;
2209 Pl: TPlayer;
2210 Kind: Byte;
2211 Attacker, Value: Word;
2212 VX, VY: Integer;
2213 begin
2214 Result := 0;
2215 if not gGameOn then Exit;
2216 PID := M.ReadWord();
2217 Pl := g_Player_Get(PID);
2218 if Pl = nil then Exit;
2220 Kind := M.ReadByte();
2221 Attacker := M.ReadWord();
2222 Value := M.ReadWord();
2223 VX := M.ReadWord();
2224 VY := M.ReadWord();
2226 with Pl do
2227 Damage(Value, Attacker, VX, VY, Kind);
2229 Result := PID;
2230 end;
2232 function MC_RECV_PlayerDeath(var M: TMsg): Word;
2233 var
2234 PID: Word;
2235 Pl: TPlayer;
2236 KillType, DeathType: Byte;
2237 Attacker: Word;
2238 begin
2239 Result := 0;
2240 if not gGameOn then Exit;
2241 PID := M.ReadWord();
2242 Pl := g_Player_Get(PID);
2243 if Pl = nil then Exit;
2245 KillType := M.ReadByte();
2246 DeathType := M.ReadByte();
2247 Attacker := M.ReadWord();
2249 with Pl do
2250 begin
2251 Kill(KillType, Attacker, DeathType);
2252 SoftReset;
2253 end;
2254 end;
2256 function MC_RECV_PlayerDelete(var M: TMsg): Word;
2257 var
2258 PID: Word;
2259 Pl: TPlayer;
2260 begin
2261 PID := M.ReadWord();
2262 Pl := g_Player_Get(PID);
2263 Result := 0;
2264 if Pl = nil then Exit;
2266 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2267 e_WriteLog('NET: Player ' + Pl.Name + ' [' + IntToStr(PID) + '] removed.', TMsgType.Notify);
2269 g_Player_Remove(PID);
2271 Result := PID;
2272 end;
2274 function MC_RECV_PlayerFire(var M: TMsg): Word;
2275 var
2276 PID: Word;
2277 Weap: Byte;
2278 Pl: TPlayer;
2279 X, Y, AX, AY: Integer;
2280 SHID: Integer;
2281 begin
2282 Result := 0;
2283 if not gGameOn then Exit;
2284 PID := M.ReadWord();
2285 Pl := g_Player_Get(PID);
2286 if Pl = nil then Exit;
2288 Weap := M.ReadByte();
2289 X := M.ReadLongInt();
2290 Y := M.ReadLongInt();
2291 AX := M.ReadLongInt();
2292 AY := M.ReadLongInt();
2293 SHID := M.ReadLongInt();
2295 with Pl do
2296 if alive then NetFire(Weap, X, Y, AX, AY, SHID);
2297 end;
2299 procedure MC_RECV_PlayerSettings(var M: TMsg);
2300 var
2301 TmpName: string;
2302 TmpModel: string;
2303 TmpColor: TRGB;
2304 TmpTeam: Byte;
2305 Pl: TPlayer;
2306 PID: Word;
2307 begin
2308 PID := M.ReadWord();
2309 Pl := g_Player_Get(PID);
2310 if Pl = nil then Exit;
2312 TmpName := M.ReadString();
2313 TmpModel := M.ReadString();
2314 TmpColor.R := M.ReadByte();
2315 TmpColor.G := M.ReadByte();
2316 TmpColor.B := M.ReadByte();
2317 TmpTeam := M.ReadByte();
2319 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
2320 begin
2321 Pl.ChangeTeam(TmpTeam);
2322 if gPlayer1 = Pl then
2323 gPlayer1Settings.Team := TmpTeam;
2324 if gPlayer2 = Pl then
2325 gPlayer2Settings.Team := TmpTeam;
2326 end else
2327 Pl.SetColor(TmpColor);
2329 if Pl.Name <> TmpName then
2330 begin
2331 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
2332 Pl.Name := TmpName;
2333 end;
2335 if TmpModel <> Pl.Model.Name then
2336 Pl.SetModel(TmpModel);
2337 end;
2339 // ITEM
2341 procedure MC_RECV_ItemSpawn(var M: TMsg);
2342 var
2343 ID: Word;
2344 AID: DWord;
2345 X, Y, VX, VY: Integer;
2346 T: Byte;
2347 Quiet, Fall{, Resp}: Boolean;
2348 Anim: TAnimation;
2349 it: PItem;
2350 begin
2351 if not gGameOn then Exit;
2352 ID := M.ReadWord();
2353 Quiet := M.ReadByte() <> 0;
2354 T := M.ReadByte();
2355 Fall := M.ReadByte() <> 0;
2356 {Resp :=} M.ReadByte();
2357 X := M.ReadLongInt();
2358 Y := M.ReadLongInt();
2359 VX := M.ReadLongInt();
2360 VY := M.ReadLongInt();
2362 g_Items_Create(X, Y, T and $7F, Fall, False, False, ID);
2363 if ((T and $80) <> 0) then g_Items_SetDrop(ID);
2365 it := g_Items_ByIdx(ID);
2366 it.Obj.Vel.X := VX;
2367 it.Obj.Vel.Y := VY;
2369 if not Quiet then
2370 begin
2371 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
2372 if g_Frames_Get(AID, 'FRAMES_ITEM_RESPAWN') then
2373 begin
2374 Anim := TAnimation.Create(AID, False, 4);
2375 g_GFX_OnceAnim(X+(it.Obj.Rect.Width div 2)-16, Y+(it.Obj.Rect.Height div 2)-16, Anim);
2376 Anim.Free();
2377 end;
2378 end;
2379 end;
2381 procedure MC_RECV_ItemDestroy(var M: TMsg);
2382 var
2383 ID: Word;
2384 Quiet: Boolean;
2385 begin
2386 if not gGameOn then Exit;
2387 ID := M.ReadWord();
2388 Quiet := M.ReadByte() <> 0;
2390 if not g_Items_ValidId(ID) then exit;
2392 if not Quiet then g_Items_EmitPickupSound(ID);
2394 g_Items_Remove(ID);
2395 end;
2397 // PANEL
2399 procedure MC_RECV_PanelTexture(var M: TMsg);
2400 var
2401 TP: TPanel;
2402 PGUID: Integer;
2403 Tex, Fr: Integer;
2404 Loop, Cnt: Byte;
2405 begin
2406 if not gGameOn then Exit;
2408 PGUID := Integer(M.ReadLongWord());
2409 Tex := M.ReadLongInt();
2410 Fr := M.ReadLongInt();
2411 Cnt := M.ReadByte();
2412 Loop := M.ReadByte();
2414 TP := g_Map_PanelByGUID(PGUID);
2415 if (TP <> nil) then
2416 begin
2417 // switch texture
2418 TP.SetTexture(Tex, Loop);
2419 TP.SetFrame(Fr, Cnt);
2420 end;
2421 end;
2423 procedure MC_RECV_PanelState(var M: TMsg);
2424 var
2425 PGUID: Integer;
2426 E: Boolean;
2427 Lift: Byte;
2428 X, Y, W, H: Integer;
2429 TP: TPanel;
2430 speedX, speedY, startX, startY, endX, endY: Integer;
2431 sizeSpX, sizeSpY, sizeEX, sizeEY: Integer;
2432 mpflags: Byte;
2433 begin
2434 if not gGameOn then Exit;
2436 PGUID := Integer(M.ReadLongWord());
2437 E := (M.ReadByte() <> 0);
2438 Lift := M.ReadByte();
2439 X := M.ReadLongInt();
2440 Y := M.ReadLongInt();
2441 W := M.ReadWord();
2442 H := M.ReadWord();
2443 // mplats
2444 speedX := M.ReadLongInt();
2445 speedY := M.ReadLongInt();
2446 startX := M.ReadLongInt();
2447 startY := M.ReadLongInt();
2448 endX := M.ReadLongInt();
2449 endY := M.ReadLongInt();
2450 sizeSpX := M.ReadLongInt();
2451 sizeSpY := M.ReadLongInt();
2452 sizeEX := M.ReadLongInt();
2453 sizeEY := M.ReadLongInt();
2454 mpflags := M.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2456 TP := g_Map_PanelByGUID(PGUID);
2457 if (TP = nil) then exit;
2459 // update lifts state
2460 if TP.isGLift then g_Map_SetLiftGUID(PGUID, Lift);
2462 // update enabled/disabled state for all panels
2463 if E then g_Map_EnableWallGUID(PGUID) else g_Map_DisableWallGUID(PGUID);
2465 // update panel position, as it can be moved (mplat)
2466 TP.X := X;
2467 TP.Y := Y;
2468 TP.Width := W;
2469 TP.Height := H;
2470 // update mplat state
2471 TP.movingSpeedX := speedX;
2472 TP.movingSpeedY := speedY;
2473 TP.movingStartX := startX;
2474 TP.movingStartY := startY;
2475 TP.movingEndX := endX;
2476 TP.movingEndY := endY;
2477 TP.sizeSpeedX := sizeSpX;
2478 TP.sizeSpeedY := sizeSpY;
2479 TP.sizeEndX := sizeEX;
2480 TP.sizeEndY := sizeEY;
2481 TP.movingActive := ((mpflags and 1) <> 0);
2482 TP.moveOnce := ((mpflags and 2) <> 0);
2483 // notify panel of it's position/size change, so it can fix other internal structures
2484 TP.positionChanged();
2485 end;
2487 // TRIGGERS
2489 procedure MC_RECV_TriggerSound(var M: TMsg);
2490 var
2491 SPlaying: Boolean;
2492 SPos, SID: LongWord;
2493 SCount: LongInt;
2494 I: Integer;
2495 begin
2496 if not gGameOn then Exit;
2497 if gTriggers = nil then Exit;
2499 SID := M.ReadLongWord();
2500 SPlaying := M.ReadByte() <> 0;
2501 SPos := M.ReadLongWord();
2502 SCount := M.ReadLongInt();
2504 for I := Low(gTriggers) to High(gTriggers) do
2505 if gTriggers[I].TriggerType = TRIGGER_SOUND then
2506 if gTriggers[I].ClientID = SID then
2507 with gTriggers[I] do
2508 begin
2509 if Sound <> nil then
2510 begin
2511 if SPlaying then
2512 begin
2513 if tgcLocal then
2514 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), tgcVolume/255.0)
2515 else
2516 Sound.PlayPanVolume((tgcPan-127.0)/128.0, tgcVolume/255.0);
2517 Sound.SetPosition(SPos);
2518 end
2519 else
2520 if Sound.IsPlaying then Sound.Stop;
2521 end;
2523 SoundPlayCount := SCount;
2524 end;
2525 end;
2527 procedure MC_RECV_TriggerMusic(var M: TMsg);
2528 var
2529 MName: string;
2530 MPlaying: Boolean;
2531 MPos: LongWord;
2532 MPaused: Boolean;
2533 begin
2534 if not gGameOn then Exit;
2536 MName := M.ReadString();
2537 MPlaying := M.ReadByte() <> 0;
2538 MPos := M.ReadLongWord();
2539 MPaused := M.ReadByte() <> 0;
2541 if MPlaying then
2542 begin
2543 gMusic.SetByName(MName);
2544 gMusic.Play(True);
2545 gMusic.SetPosition(MPos);
2546 gMusic.SpecPause := MPaused;
2547 end
2548 else
2549 if gMusic.IsPlaying then gMusic.Stop;
2550 end;
2552 // MONSTERS
2554 procedure MC_RECV_MonsterSpawn(var M: TMsg);
2555 var
2556 ID: Word;
2557 MType, MState, MDir, MAnim, MBehav: Byte;
2558 X, Y, VX, VY, MTargTime, MHealth, MAmmo, MSleep: Integer;
2559 MTarg: Word;
2560 Mon: TMonster;
2561 begin
2562 ID := M.ReadWord();
2563 Mon := g_Monsters_ByUID(ID);
2564 if Mon <> nil then
2565 Exit;
2567 MType := M.ReadByte();
2568 MState := M.ReadByte();
2569 MAnim := M.ReadByte();
2570 MTarg := M.ReadWord();
2571 MTargTime := M.ReadLongInt();
2572 MBehav := M.ReadByte();
2573 MSleep := M.ReadLongInt();
2574 MHealth := M.ReadLongInt();
2575 MAmmo := M.ReadLongInt();
2577 X := M.ReadLongInt();
2578 Y := M.ReadLongInt();
2579 VX := M.ReadLongInt();
2580 VY := M.ReadLongInt();
2581 MDir := M.ReadByte();
2583 g_Monsters_Create(MType, X, Y, TDirection(MDir), False, ID);
2584 Mon := g_Monsters_ByUID(ID);
2585 if Mon = nil then
2586 Exit;
2588 with Mon do
2589 begin
2591 MonsterAnim := MAnim;
2592 MonsterTargetUID := MTarg;
2593 MonsterTargetTime := MTargTime;
2594 MonsterBehaviour := MBehav;
2595 MonsterSleep := MSleep;
2596 MonsterAmmo := MAmmo;
2597 SetHealth(MHealth);
2599 SetState(MState);
2601 setPosition(X, Y); // this will call positionChanged();
2602 GameVelX := VX;
2603 GameVelY := VY;
2604 end;
2605 end;
2607 procedure MC_RECV_MonsterPos(var M: TMsg);
2608 var
2609 Mon: TMonster;
2610 ID: Word;
2611 X, Y: Integer;
2612 begin
2613 ID := M.ReadWord();
2614 Mon := g_Monsters_ByUID(ID);
2615 if Mon = nil then
2616 Exit;
2618 with Mon do
2619 begin
2620 X := M.ReadLongInt();
2621 Y := M.ReadLongInt();
2622 Mon.setPosition(X, Y); // this will call `positionChanged()`
2623 GameVelX := M.ReadLongInt();
2624 GameVelY := M.ReadLongInt();
2625 GameDirection := TDirection(M.ReadByte());
2626 end;
2627 end;
2629 procedure MC_RECV_MonsterState(var M: TMsg);
2630 var
2631 ID: Integer;
2632 MState, MFAnm: Byte;
2633 Mon: TMonster;
2634 AnimRevert: Boolean;
2635 begin
2636 ID := M.ReadWord();
2637 Mon := g_Monsters_ByUID(ID);
2638 if Mon = nil then Exit;
2640 MState := M.ReadByte();
2641 MFAnm := M.ReadByte();
2643 with Mon do
2644 begin
2645 MonsterTargetUID := M.ReadWord();
2646 MonsterTargetTime := M.ReadLongInt();
2647 MonsterSleep := M.ReadLongInt();
2648 MonsterHealth := M.ReadLongInt();
2649 MonsterAmmo := M.ReadLongInt();
2650 MonsterPain := M.ReadLongInt();
2651 AnimRevert := M.ReadByte() <> 0;
2652 FFireTime := M.ReadLongInt();
2653 RevertAnim(AnimRevert);
2655 if MonsterState <> MState then
2656 begin
2657 if (MState = MONSTATE_GO) and (MonsterState = MONSTATE_SLEEP) then WakeUpSound();
2658 if (MState = MONSTATE_DIE) then DieSound();
2659 if (MState = MONSTATE_PAIN) then MakeBloodSimple(Min(200, MonsterPain));
2660 if (MState = MONSTATE_ATTACK) then kick(nil);
2661 if (MState = MONSTATE_DEAD) then SetDeadAnim();
2663 SetState(MState, MFAnm);
2664 end;
2665 end;
2666 end;
2668 procedure MC_RECV_MonsterShot(var M: TMsg);
2669 var
2670 ID: Integer;
2671 Mon: TMonster;
2672 X, Y, VX, VY: Integer;
2673 begin
2674 ID := M.ReadWord();
2676 Mon := g_Monsters_ByUID(ID);
2677 if Mon = nil then Exit;
2679 X := M.ReadLongInt();
2680 Y := M.ReadLongInt();
2681 VX := M.ReadLongInt();
2682 VY := M.ReadLongInt();
2684 Mon.ClientAttack(X, Y, VX, VY);
2685 end;
2687 procedure MC_RECV_MonsterDelete(var M: TMsg);
2688 var
2689 ID: Integer;
2690 Mon: TMonster;
2691 begin
2692 ID := M.ReadWord();
2693 Mon := g_Monsters_ByUID(ID);
2694 if Mon = nil then Exit;
2695 Mon.SetState(5);
2696 Mon.MonsterRemoved := True;
2697 end;
2699 procedure MC_RECV_TimeSync(var M: TMsg);
2700 var
2701 Time: LongWord;
2702 begin
2703 Time := M.ReadLongWord();
2705 if gState = STATE_INTERCUSTOM then
2706 gServInterTime := Min(Time, 255);
2707 end;
2709 procedure MC_RECV_VoteEvent(var M: TMsg);
2710 var
2711 EvID: Byte;
2712 Str1, Str2: string;
2713 Int1, Int2: SmallInt;
2714 begin
2715 EvID := M.ReadByte();
2716 Int1 := M.ReadSmallInt();
2717 Int2 := M.ReadSmallInt();
2718 Str1 := M.ReadString();
2719 Str2 := M.ReadString();
2721 case EvID of
2722 NET_VE_STARTED:
2723 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True);
2724 NET_VE_PASSED:
2725 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True);
2726 NET_VE_FAILED:
2727 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
2728 NET_VE_VOTE:
2729 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True);
2730 NET_VE_INPROGRESS:
2731 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True);
2732 end;
2733 end;
2735 // CLIENT SEND
2737 procedure MC_SEND_Info(Password: string);
2738 begin
2739 NetOut.Clear();
2741 NetOut.Write(Byte(NET_MSG_INFO));
2742 NetOut.Write(GAME_VERSION);
2743 NetOut.Write(Password);
2744 NetOut.Write(gPlayer1Settings.Name);
2745 NetOut.Write(gPlayer1Settings.Model);
2746 NetOut.Write(gPlayer1Settings.Color.R);
2747 NetOut.Write(gPlayer1Settings.Color.G);
2748 NetOut.Write(gPlayer1Settings.Color.B);
2749 NetOut.Write(gPlayer1Settings.Team);
2751 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2752 end;
2754 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
2755 begin
2756 NetOut.Write(Byte(NET_MSG_CHAT));
2757 NetOut.Write(Txt);
2758 NetOut.Write(Mode);
2760 g_Net_Client_Send(True, NET_CHAN_CHAT);
2761 end;
2763 function isKeyPressed (key1: Word; key2: Word): Boolean;
2764 begin
2765 if (key1 <> 0) and e_KeyPressed(key1) then begin result := true; exit; end;
2766 if (key2 <> 0) and e_KeyPressed(key2) then begin result := true; exit; end;
2767 result := false;
2768 end;
2770 procedure MC_SEND_PlayerPos();
2771 var
2772 kByte: Word;
2773 Predict: Boolean;
2774 strafeDir: Byte;
2775 WeaponSelect: Word = 0;
2776 I: Integer;
2777 begin
2778 if not gGameOn then Exit;
2779 if gPlayers = nil then Exit;
2780 if gPlayer1 = nil then Exit;
2782 kByte := 0;
2783 Predict := NetPredictSelf; // and (not NetGotKeys);
2785 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2786 begin
2787 strafeDir := P1MoveButton shr 4;
2788 P1MoveButton := P1MoveButton and $0F;
2789 with gGameControls.P1Control do
2790 begin
2791 if isKeyPressed(KeyLeft, KeyLeft2) and (not isKeyPressed(KeyRight, KeyRight2)) then P1MoveButton := 1
2792 else if (not isKeyPressed(KeyLeft, KeyLeft2)) and isKeyPressed(KeyRight, KeyRight2) then P1MoveButton := 2
2793 else if (not isKeyPressed(KeyLeft, KeyLeft2)) and (not isKeyPressed(KeyRight, KeyRight2)) then P1MoveButton := 0;
2795 // strafing
2796 if isKeyPressed(KeyStrafe, KeyStrafe2) then
2797 begin
2798 // new strafe mechanics
2799 if (strafeDir = 0) then strafeDir := P1MoveButton; // start strafing
2800 // now set direction according to strafe (reversed)
2801 if (strafeDir = 2) then gPlayer1.SetDirection(TDirection.D_LEFT)
2802 else if (strafeDir = 1) then gPlayer1.SetDirection(TDirection.D_RIGHT);
2803 end
2804 else
2805 begin
2806 if (P1MoveButton = 2) and isKeyPressed(KeyLeft, KeyLeft2) then gPlayer1.SetDirection(TDirection.D_LEFT)
2807 else if (P1MoveButton = 1) and isKeyPressed(KeyRight, KeyRight2) then gPlayer1.SetDirection(TDirection.D_RIGHT)
2808 else if P1MoveButton <> 0 then gPlayer1.SetDirection(TDirection(P1MoveButton-1));
2809 end;
2811 gPlayer1.ReleaseKeys;
2812 if P1MoveButton = 1 then
2813 begin
2814 kByte := kByte or NET_KEY_LEFT;
2815 if Predict then gPlayer1.PressKey(KEY_LEFT, 10000);
2816 end;
2817 if P1MoveButton = 2 then
2818 begin
2819 kByte := kByte or NET_KEY_RIGHT;
2820 if Predict then gPlayer1.PressKey(KEY_RIGHT, 10000);
2821 end;
2822 if isKeyPressed(KeyUp, KeyUp2) then
2823 begin
2824 kByte := kByte or NET_KEY_UP;
2825 gPlayer1.PressKey(KEY_UP, 10000);
2826 end;
2827 if isKeyPressed(KeyDown, KeyDown2) then
2828 begin
2829 kByte := kByte or NET_KEY_DOWN;
2830 gPlayer1.PressKey(KEY_DOWN, 10000);
2831 end;
2832 if isKeyPressed(KeyJump, KeyJump2) then
2833 begin
2834 kByte := kByte or NET_KEY_JUMP;
2835 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2836 end;
2837 if isKeyPressed(KeyFire, KeyFire2) then kByte := kByte or NET_KEY_FIRE;
2838 if isKeyPressed(KeyOpen, KeyOpen2) then kByte := kByte or NET_KEY_OPEN;
2839 if isKeyPressed(KeyNextWeapon, KeyNextWeapon2) then kByte := kByte or NET_KEY_NW;
2840 if isKeyPressed(KeyPrevWeapon, KeyPrevWeapon2) then kByte := kByte or NET_KEY_PW;
2841 for I := 0 to High(KeyWeapon) do
2842 if isKeyPressed(KeyWeapon[I], KeyWeapon2[I]) then
2843 WeaponSelect := WeaponSelect or Word(1 shl I);
2844 end;
2845 // fix movebutton state
2846 P1MoveButton := P1MoveButton or (strafeDir shl 4);
2847 end
2848 else
2849 kByte := NET_KEY_CHAT;
2851 NetOut.Write(Byte(NET_MSG_PLRPOS));
2852 NetOut.Write(gTime);
2853 NetOut.Write(kByte);
2854 NetOut.Write(Byte(gPlayer1.Direction));
2855 NetOut.Write(WeaponSelect);
2856 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2857 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS);
2859 //kBytePrev := kByte;
2860 //kDirPrev := gPlayer1.Direction;
2861 end;
2863 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
2864 begin
2865 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
2866 NetOut.Write(Byte(Start));
2867 NetOut.Write(Command);
2868 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2869 end;
2871 procedure MC_SEND_PlayerSettings();
2872 begin
2873 NetOut.Write(Byte(NET_MSG_PLRSET));
2874 NetOut.Write(gPlayer1Settings.Name);
2875 NetOut.Write(gPlayer1Settings.Model);
2876 NetOut.Write(gPlayer1Settings.Color.R);
2877 NetOut.Write(gPlayer1Settings.Color.G);
2878 NetOut.Write(gPlayer1Settings.Color.B);
2879 NetOut.Write(gPlayer1Settings.Team);
2881 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2882 end;
2884 procedure MC_SEND_FullStateRequest();
2885 begin
2886 NetOut.Write(Byte(NET_MSG_REQFST));
2888 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2889 end;
2891 procedure MC_SEND_CheatRequest(Kind: Byte);
2892 begin
2893 NetOut.Write(Byte(NET_MSG_CHEAT));
2894 NetOut.Write(Kind);
2896 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2897 end;
2898 procedure MC_SEND_RCONPassword(Password: string);
2899 begin
2900 NetOut.Write(Byte(NET_MSG_RCON_AUTH));
2901 NetOut.Write(Password);
2903 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2904 end;
2905 procedure MC_SEND_RCONCommand(Cmd: string);
2906 begin
2907 NetOut.Write(Byte(NET_MSG_RCON_CMD));
2908 NetOut.Write(Cmd);
2910 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2911 end;
2913 // i have no idea why all this stuff is in here
2915 function ReadFile(const FileName: TFileName): AByte;
2916 var
2917 FileStream : TStream;
2918 fname: string;
2919 begin
2920 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName]), TMsgType.Notify);
2921 fname := findDiskWad(FileName);
2922 if length(fname) = 0 then
2923 begin
2924 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName]), TMsgType.Fatal);
2925 SetLength(Result, 0);
2926 exit;
2927 end;
2928 e_WriteLog(Format('NETWORK: found file "%s"', [fname]), TMsgType.Notify);
2929 Result := nil;
2930 FileStream := openDiskFileRO(fname);
2931 try
2932 if FileStream.Size > 0 then
2933 begin
2934 SetLength(Result, FileStream.Size);
2935 FileStream.Read(Result[0], FileStream.Size);
2936 end;
2937 finally
2938 FileStream.Free;
2939 end;
2940 end;
2942 function CreateMapDataMsg(const FileName: TFileName; ResList: TStringList): TMapDataMsg;
2943 var
2944 i: Integer;
2945 begin
2946 Result.MsgId := NET_MSG_MAP_RESPONSE;
2947 Result.FileData := ReadFile(FileName);
2948 Result.FileSize := Length(Result.FileData);
2950 SetLength(Result.ExternalResources, ResList.Count);
2951 for i:=0 to ResList.Count-1 do
2952 begin
2953 Result.ExternalResources[i].Name := ResList.Strings[i];
2954 Result.ExternalResources[i].md5 := MD5File(GameDir+'/wads/'+ResList.Strings[i]);
2955 end;
2956 end;
2958 procedure ResDataMsgToBytes(var bytes: AByte; const ResData: TResDataMsg);
2959 var
2960 ResultStream: TMemoryStream;
2961 begin
2962 ResultStream := TMemoryStream.Create;
2964 ResultStream.WriteBuffer(ResData.MsgId, SizeOf(ResData.MsgId)); //msgId
2965 ResultStream.WriteBuffer(ResData.FileSize, SizeOf(ResData.FileSize)); //file size
2966 ResultStream.WriteBuffer(ResData.FileData[0], ResData.FileSize); //file data
2968 SetLength(bytes, ResultStream.Size);
2969 ResultStream.Seek(0, soFromBeginning);
2970 ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
2972 ResultStream.Free;
2973 end;
2975 function ResDataFromMsgStream(msgStream: TMemoryStream):TResDataMsg;
2976 begin
2977 msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
2978 msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize));
2979 SetLength(Result.FileData, Result.FileSize);
2980 msgStream.ReadBuffer(Result.FileData[0], Result.FileSize);
2981 end;
2983 procedure MapDataMsgToBytes(var bytes: AByte; const MapDataMsg: TMapDataMsg);
2984 var
2985 ResultStream: TMemoryStream;
2986 resCount: Integer;
2987 begin
2988 resCount := Length(MapDataMsg.ExternalResources);
2990 ResultStream := TMemoryStream.Create;
2992 ResultStream.WriteBuffer(MapDataMsg.MsgId, SizeOf(MapDataMsg.MsgId)); //msgId
2993 ResultStream.WriteBuffer(MapDataMsg.FileSize, SizeOf(MapDataMsg.FileSize)); //file size
2994 ResultStream.WriteBuffer(MapDataMsg.FileData[0], MapDataMsg.FileSize); //file data
2996 ResultStream.WriteBuffer(resCount, SizeOf(resCount)); //res count
2997 ResultStream.WriteBuffer(MapDataMsg.ExternalResources[0], resCount*SizeOf(TExternalResourceInfo)); //res data
2999 SetLength(bytes, ResultStream.Size);
3000 ResultStream.Seek(0, soFromBeginning);
3001 ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
3003 ResultStream.Free;
3004 end;
3006 function MapDataFromMsgStream(msgStream: TMemoryStream):TMapDataMsg;
3007 var
3008 resCount: Integer;
3009 begin
3010 msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
3011 msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize)); //file size
3013 SetLength(Result.FileData, Result.FileSize);
3014 msgStream.ReadBuffer(Result.FileData[0], Result.FileSize); //file data
3016 msgStream.ReadBuffer(resCount, SizeOf(resCount)); //res count
3017 SetLength(Result.ExternalResources, resCount);
3019 msgStream.ReadBuffer(Result.ExternalResources[0], resCount * SizeOf(TExternalResourceInfo)); //res data
3020 end;
3022 function IsValidFileName(const S: String): Boolean;
3023 const
3024 Forbidden: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
3025 var
3026 I: Integer;
3027 begin
3028 Result := S <> '';
3029 for I := 1 to Length(S) do
3030 Result := Result and (not(S[I] in Forbidden));
3031 end;
3033 function IsValidFilePath(const S: String): Boolean;
3034 var
3035 I: Integer;
3036 begin
3037 Result := False;
3038 if not IsValidFileName(S) then exit;
3039 if FileExists(S) then exit;
3040 I := LastDelimiter('\/', S);
3041 if (I > 0) then
3042 if (not DirectoryExists(Copy(S, 1, I-1))) then
3043 exit;
3044 Result := True;
3045 end;
3047 procedure MC_SEND_MapRequest();
3048 begin
3049 NetOut.Write(Byte(NET_MSG_MAP_REQUEST));
3050 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3051 end;
3053 procedure MC_SEND_ResRequest(const resName: AnsiString);
3054 begin
3055 NetOut.Write(Byte(NET_MSG_RES_REQUEST));
3056 NetOut.Write(resName);
3057 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3058 end;
3060 procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
3061 var
3062 payload: AByte;
3063 peer: pENetPeer;
3064 mapDataMsg: TMapDataMsg;
3065 begin
3066 e_WriteLog('NET: Received map request from ' +
3067 DecodeIPV4(C^.Peer.address.host), TMsgType.Notify);
3069 mapDataMsg := CreateMapDataMsg(MapsDir + gGameSettings.WAD, gExternalResources);
3070 peer := NetClients[C^.ID].Peer;
3072 MapDataMsgToBytes(payload, mapDataMsg);
3073 g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
3075 payload := nil;
3076 mapDataMsg.FileData := nil;
3077 mapDataMsg.ExternalResources := nil;
3078 end;
3080 procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
3081 var
3082 payload: AByte;
3083 peer: pENetPeer;
3084 FileName: String;
3085 resDataMsg: TResDataMsg;
3086 begin
3087 FileName := ExtractFileName(M.ReadString());
3088 e_WriteLog('NET: Received res request: ' + FileName +
3089 ' from ' + DecodeIPV4(C^.Peer.address.host), TMsgType.Notify);
3091 if not IsValidFilePath(FileName) then
3092 begin
3093 e_WriteLog('Invalid filename: ' + FileName, TMsgType.Warning);
3094 exit;
3095 end;
3097 peer := NetClients[C^.ID].Peer;
3099 if gExternalResources.IndexOf(FileName) > -1 then
3100 begin
3101 resDataMsg.MsgId := NET_MSG_RES_RESPONSE;
3102 resDataMsg.FileData := ReadFile(GameDir+'/wads/'+FileName);
3103 resDataMsg.FileSize := Length(resDataMsg.FileData);
3105 ResDataMsgToBytes(payload, resDataMsg);
3106 g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
3107 end;
3108 end;
3110 end.