DEADSOFTWARE

Add sounds for flamethrower
[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 NetOut.Write(Byte(FFlaming));
1074 end;
1076 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1077 end;
1079 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
1080 begin
1081 NetOut.Write(Byte(NET_MSG_PLRDMG));
1082 NetOut.Write(PID);
1083 NetOut.Write(Kind);
1084 NetOut.Write(Attacker);
1085 NetOut.Write(Value);
1086 NetOut.Write(VX);
1087 NetOut.Write(VY);
1089 g_Net_Host_Send(ID, False, NET_CHAN_PLAYER);
1090 end;
1092 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
1093 begin
1094 NetOut.Write(Byte(NET_MSG_PLRDIE));
1095 NetOut.Write(PID);
1096 NetOut.Write(KillType);
1097 NetOut.Write(DeathType);
1098 NetOut.Write(Attacker);
1100 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1101 end;
1103 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
1104 begin
1105 NetOut.Write(Byte(NET_MSG_PLRFIRE));
1106 NetOut.Write(PID);
1107 NetOut.Write(Weapon);
1108 NetOut.Write(X);
1109 NetOut.Write(Y);
1110 NetOut.Write(AX);
1111 NetOut.Write(AY);
1112 NetOut.Write(ShotID);
1114 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1115 end;
1117 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
1118 begin
1119 NetOut.Write(Byte(NET_MSG_PLRDEL));
1120 NetOut.Write(PID);
1122 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1123 end;
1125 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
1126 var
1127 Pl: TPlayer;
1128 begin
1129 Pl := g_Player_Get(PID);
1130 if Pl = nil then Exit;
1132 NetOut.Write(Byte(NET_MSG_PLRSET));
1133 NetOut.Write(PID);
1134 NetOut.Write(Pl.Name);
1135 if Mdl = '' then
1136 NetOut.Write(Pl.Model.Name)
1137 else
1138 NetOut.Write(Mdl);
1139 NetOut.Write(Pl.FColor.R);
1140 NetOut.Write(Pl.FColor.G);
1141 NetOut.Write(Pl.FColor.B);
1142 NetOut.Write(Pl.Team);
1144 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1145 end;
1147 // ITEM (SEND)
1149 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1150 var
1151 it: PItem;
1152 tt: Byte;
1153 begin
1154 it := g_Items_ByIdx(IID);
1156 NetOut.Write(Byte(NET_MSG_ISPAWN));
1157 NetOut.Write(IID);
1158 NetOut.Write(Byte(Quiet));
1159 tt := it.ItemType;
1160 if it.dropped then tt := tt or $80;
1161 NetOut.Write(tt);
1162 NetOut.Write(Byte(it.Fall));
1163 NetOut.Write(Byte(it.Respawnable));
1164 NetOut.Write(it.Obj.X);
1165 NetOut.Write(it.Obj.Y);
1166 NetOut.Write(it.Obj.Vel.X);
1167 NetOut.Write(it.Obj.Vel.Y);
1169 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1170 end;
1172 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1173 begin
1174 NetOut.Write(Byte(NET_MSG_IDEL));
1175 NetOut.Write(IID);
1176 NetOut.Write(Byte(Quiet));
1178 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1179 end;
1181 // PANEL
1183 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
1184 var
1185 TP: TPanel;
1186 begin
1187 TP := g_Map_PanelByGUID(PGUID);
1188 if (TP = nil) then exit;
1190 with TP do
1191 begin
1192 NetOut.Write(Byte(NET_MSG_PTEX));
1193 NetOut.Write(LongWord(PGUID));
1194 NetOut.Write(FCurTexture);
1195 NetOut.Write(FCurFrame);
1196 NetOut.Write(FCurFrameCount);
1197 NetOut.Write(AnimLoop);
1198 end;
1200 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1201 end;
1203 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
1204 var
1205 TP: TPanel;
1206 mpflags: Byte = 0;
1207 begin
1208 TP := g_Map_PanelByGUID(PGUID);
1209 if (TP = nil) then exit;
1211 NetOut.Write(Byte(NET_MSG_PSTATE));
1212 NetOut.Write(LongWord(PGUID));
1213 NetOut.Write(Byte(TP.Enabled));
1214 NetOut.Write(TP.LiftType);
1215 NetOut.Write(TP.X);
1216 NetOut.Write(TP.Y);
1217 NetOut.Write(Word(TP.Width));
1218 NetOut.Write(Word(TP.Height));
1219 // mplats
1220 NetOut.Write(LongInt(TP.movingSpeedX));
1221 NetOut.Write(LongInt(TP.movingSpeedY));
1222 NetOut.Write(LongInt(TP.movingStartX));
1223 NetOut.Write(LongInt(TP.movingStartY));
1224 NetOut.Write(LongInt(TP.movingEndX));
1225 NetOut.Write(LongInt(TP.movingEndY));
1226 NetOut.Write(LongInt(TP.sizeSpeedX));
1227 NetOut.Write(LongInt(TP.sizeSpeedY));
1228 NetOut.Write(LongInt(TP.sizeEndX));
1229 NetOut.Write(LongInt(TP.sizeEndY));
1230 if TP.movingActive then mpflags := mpflags or 1;
1231 if TP.moveOnce then mpflags := mpflags or 2;
1232 NetOut.Write(Byte(mpflags));
1234 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1235 end;
1237 // TRIGGER
1239 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
1240 begin
1241 if gTriggers = nil then Exit;
1242 if T.Sound = nil then Exit;
1244 NetOut.Write(Byte(NET_MSG_TSOUND));
1245 NetOut.Write(T.ClientID);
1246 NetOut.Write(Byte(T.Sound.IsPlaying));
1247 NetOut.Write(LongWord(T.Sound.GetPosition));
1248 NetOut.Write(T.SoundPlayCount);
1250 g_Net_Host_Send(ID, True);
1251 end;
1253 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
1254 begin
1255 NetOut.Write(Byte(NET_MSG_TMUSIC));
1256 NetOut.Write(gMusic.Name);
1257 NetOut.Write(Byte(gMusic.IsPlaying));
1258 NetOut.Write(LongWord(gMusic.GetPosition));
1259 NetOut.Write(Byte(gMusic.SpecPause or gMusic.IsPaused));
1261 g_Net_Host_Send(ID, True);
1262 end;
1264 // MONSTER
1266 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
1267 var
1268 M: TMonster;
1269 begin
1270 M := g_Monsters_ByUID(UID);
1271 if M = nil then
1272 Exit;
1274 with M do
1275 begin
1276 NetOut.Write(Byte(NET_MSG_MSPAWN));
1277 NetOut.Write(UID);
1278 NetOut.Write(MonsterType);
1279 NetOut.Write(MonsterState);
1280 NetOut.Write(MonsterAnim);
1281 NetOut.Write(MonsterTargetUID);
1282 NetOut.Write(MonsterTargetTime);
1283 NetOut.Write(MonsterBehaviour);
1284 NetOut.Write(MonsterSleep);
1285 NetOut.Write(MonsterHealth);
1286 NetOut.Write(MonsterAmmo);
1287 NetOut.Write(GameX);
1288 NetOut.Write(GameY);
1289 NetOut.Write(GameVelX);
1290 NetOut.Write(GameVelY);
1291 NetOut.Write(Byte(GameDirection));
1292 end;
1294 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1295 end;
1297 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
1298 var
1299 M: TMonster;
1300 begin
1301 M := g_Monsters_ByUID(UID);
1302 if M = nil then Exit;
1304 NetOut.Write(Byte(NET_MSG_MPOS));
1305 NetOut.Write(UID);
1307 with M do
1308 begin
1309 NetOut.Write(GameX);
1310 NetOut.Write(GameY);
1311 NetOut.Write(GameVelX);
1312 NetOut.Write(GameVelY);
1313 NetOut.Write(Byte(GameDirection));
1314 end;
1316 g_Net_Host_Send(ID, False, NET_CHAN_MONSTERPOS);
1317 end;
1319 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
1320 var
1321 M: TMonster;
1322 begin
1323 M := g_Monsters_ByUID(UID);
1324 if M = nil then Exit;
1326 NetOut.Write(Byte(NET_MSG_MSTATE));
1327 NetOut.Write(UID);
1329 with M do
1330 begin
1331 NetOut.Write(MonsterState);
1332 NetOut.Write(ForcedAnim);
1333 NetOut.Write(MonsterTargetUID);
1334 NetOut.Write(MonsterTargetTime);
1335 NetOut.Write(MonsterSleep);
1336 NetOut.Write(MonsterHealth);
1337 NetOut.Write(MonsterAmmo);
1338 NetOut.Write(MonsterPain);
1339 NetOut.Write(Byte(AnimIsReverse));
1340 NetOut.Write(FFireTime);
1341 end;
1343 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1344 end;
1346 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
1347 begin
1348 NetOut.Write(Byte(NET_MSG_MSHOT));
1349 NetOut.Write(UID);
1350 NetOut.Write(X);
1351 NetOut.Write(Y);
1352 NetOut.Write(VX);
1353 NetOut.Write(VY);
1355 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1356 end;
1358 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
1359 var
1360 M: TMonster;
1361 begin
1362 M := g_Monsters_ByUID(UID);
1363 if M = nil then Exit;
1365 NetOut.Write(Byte(NET_MSG_MDEL));
1366 NetOut.Write(UID);
1368 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1369 end;
1371 // MISC
1373 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
1374 begin
1375 NetOut.Write(Byte(NET_MSG_TIME_SYNC));
1376 NetOut.Write(Time);
1378 g_Net_Host_Send(ID, False, NET_CHAN_SERVICE);
1379 end;
1381 procedure MH_SEND_VoteEvent(EvType: Byte;
1382 StrArg1: string = 'a'; StrArg2: string = 'b';
1383 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
1384 ID: Integer = NET_EVERYONE);
1385 begin
1386 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
1387 NetOut.Write(EvType);
1388 NetOut.Write(IntArg1);
1389 NetOut.Write(IntArg2);
1390 NetOut.Write(StrArg1);
1391 NetOut.Write(StrArg2);
1393 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1394 end;
1396 // CLIENT MESSAGES //
1398 // GAME
1400 procedure MC_RECV_Chat(var M: TMsg);
1401 var
1402 Txt: string;
1403 Mode: Byte;
1404 begin
1405 Txt := M.ReadString();
1406 Mode := M.ReadByte();
1408 if Mode <> NET_CHAT_SYSTEM then
1409 begin
1410 if Mode = NET_CHAT_PLAYER then
1411 begin
1412 g_Console_Add(Txt, True);
1413 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1414 g_Game_ChatSound(b_Text_Unformat(Txt));
1415 end else
1416 if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then
1417 begin
1418 if gPlayer1.Team = TEAM_RED then
1419 g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True);
1420 if gPlayer1.Team = TEAM_BLUE then
1421 g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True);
1422 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1423 g_Game_ChatSound(b_Text_Unformat(Txt));
1424 end;
1425 end else
1426 g_Console_Add(Txt, True);
1427 end;
1429 procedure MC_RECV_Effect(var M: TMsg);
1430 var
1431 Kind: Byte;
1432 X, Y: Integer;
1433 Ang: SmallInt;
1434 Anim: TAnimation;
1435 ID: LongWord;
1436 begin
1437 if not gGameOn then Exit;
1438 Kind := M.ReadByte();
1439 X := M.ReadLongInt();
1440 Y := M.ReadLongInt();
1441 Ang := M.ReadSmallInt();
1443 case Kind of
1444 NET_GFX_SPARK:
1445 g_GFX_Spark(X, Y, 2 + Random(2), Ang, 0, 0);
1447 NET_GFX_TELE:
1448 begin
1449 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
1450 begin
1451 Anim := TAnimation.Create(ID, False, 3);
1452 g_GFX_OnceAnim(X, Y, Anim);
1453 Anim.Free();
1454 end;
1455 if Ang = 1 then
1456 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
1457 end;
1459 NET_GFX_EXPLODE:
1460 begin
1461 if g_Frames_Get(ID, 'FRAMES_EXPLODE_ROCKET') then
1462 begin
1463 Anim := TAnimation.Create(ID, False, 6);
1464 Anim.Blending := False;
1465 g_GFX_OnceAnim(X-64, Y-64, Anim);
1466 Anim.Free();
1467 end;
1468 if Ang = 1 then
1469 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X, Y);
1470 end;
1472 NET_GFX_BFGEXPL:
1473 begin
1474 if g_Frames_Get(ID, 'FRAMES_EXPLODE_BFG') then
1475 begin
1476 Anim := TAnimation.Create(ID, False, 6);
1477 Anim.Blending := False;
1478 g_GFX_OnceAnim(X-64, Y-64, Anim);
1479 Anim.Free();
1480 end;
1481 if Ang = 1 then
1482 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X, Y);
1483 end;
1485 NET_GFX_BFGHIT:
1486 begin
1487 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1488 begin
1489 Anim := TAnimation.Create(ID, False, 4);
1490 g_GFX_OnceAnim(X-32, Y-32, Anim);
1491 Anim.Free();
1492 end;
1493 end;
1495 NET_GFX_FIRE:
1496 begin
1497 if g_Frames_Get(ID, 'FRAMES_FIRE') then
1498 begin
1499 Anim := TAnimation.Create(ID, False, 4);
1500 g_GFX_OnceAnim(X, Y, Anim);
1501 Anim.Free();
1502 end;
1503 if Ang = 1 then
1504 g_Sound_PlayExAt('SOUND_FIRE', X, Y);
1505 end;
1507 NET_GFX_RESPAWN:
1508 begin
1509 if g_Frames_Get(ID, 'FRAMES_ITEM_RESPAWN') then
1510 begin
1511 Anim := TAnimation.Create(ID, False, 4);
1512 g_GFX_OnceAnim(X, Y, Anim);
1513 Anim.Free();
1514 end;
1515 if Ang = 1 then
1516 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
1517 end;
1519 NET_GFX_SHELL1:
1520 g_Player_CreateShell(X, Y, 0, -2, SHELL_BULLET);
1522 NET_GFX_SHELL2:
1523 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1525 NET_GFX_SHELL3:
1526 begin
1527 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1528 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1529 end;
1530 end;
1531 end;
1533 procedure MC_RECV_Sound(var M: TMsg);
1534 var
1535 Name: string;
1536 X, Y: Integer;
1537 Pos: Boolean;
1538 begin
1539 Name := M.ReadString();
1540 Pos := M.ReadByte() <> 0;
1541 if Pos then
1542 begin
1543 X := M.ReadLongInt();
1544 Y := M.ReadLongInt();
1545 g_Sound_PlayExAt(Name, X, Y);
1546 end
1547 else
1548 g_Sound_PlayEx(Name);
1549 end;
1551 procedure MC_RECV_CreateShot(var M: TMsg);
1552 var
1553 I, X, Y, XV, YV: Integer;
1554 Timeout: LongWord;
1555 Target, Spawner: Word;
1556 ShType: Byte;
1557 begin
1558 I := M.ReadLongInt();
1559 ShType := M.ReadByte();
1560 Target := M.ReadWord();
1561 Spawner := M.ReadWord();
1562 Timeout := M.ReadLongWord();
1563 X := M.ReadLongInt();
1564 Y := M.ReadLongInt();
1565 XV := M.ReadLongInt();
1566 YV := M.ReadLongInt();
1568 I := g_Weapon_CreateShot(I, ShType, Spawner, Target, X, Y, XV, YV);
1569 if (Shots <> nil) and (I <= High(Shots)) then
1570 begin
1571 Shots[I].Timeout := Timeout;
1572 //Shots[I].Target := Target; // TODO: find a use for Target later
1573 end;
1574 end;
1576 procedure MC_RECV_UpdateShot(var M: TMsg);
1577 var
1578 I, TX, TY, TXV, TYV: Integer;
1579 begin
1580 I := M.ReadLongInt();
1581 TX := M.ReadLongInt();
1582 TY := M.ReadLongInt();
1583 TXV := M.ReadLongInt();
1584 TYV := M.ReadLongInt();
1586 if (Shots <> nil) and (I <= High(Shots)) then
1587 with (Shots[i]) do
1588 begin
1589 Obj.X := TX;
1590 Obj.Y := TY;
1591 Obj.Vel.X := TXV;
1592 Obj.Vel.Y := TYV;
1593 end;
1594 end;
1596 procedure MC_RECV_DeleteShot(var M: TMsg);
1597 var
1598 I, X, Y: Integer;
1599 L: Boolean;
1600 begin
1601 if not gGameOn then Exit;
1602 I := M.ReadLongInt();
1603 L := (M.ReadByte() <> 0);
1604 X := M.ReadLongInt();
1605 Y := M.ReadLongInt();
1607 g_Weapon_DestroyShot(I, X, Y, L);
1608 end;
1610 procedure MC_RECV_GameStats(var M: TMsg);
1611 begin
1612 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1613 begin
1614 gTeamStat[TEAM_RED].Goals := M.ReadSmallInt();
1615 gTeamStat[TEAM_BLUE].Goals := M.ReadSmallInt();
1616 end
1617 else
1618 if gGameSettings.GameMode = GM_COOP then
1619 begin
1620 gCoopMonstersKilled := M.ReadWord();
1621 gCoopSecretsFound := M.ReadWord();
1622 end;
1623 end;
1625 procedure MC_RECV_CoopStats(var M: TMsg);
1626 begin
1627 gTotalMonsters := M.ReadLongInt();
1628 gSecretsCount := M.ReadLongInt();
1629 gCoopTotalMonstersKilled := M.ReadWord();
1630 gCoopTotalSecretsFound := M.ReadWord();
1631 gCoopTotalMonsters := M.ReadWord();
1632 gCoopTotalSecrets := M.ReadWord();
1633 end;
1635 procedure MC_RECV_GameEvent(var M: TMsg);
1636 var
1637 EvType: Byte;
1638 EvNum: Integer;
1639 EvStr: string;
1640 EvTime: LongWord;
1641 BHash: Boolean;
1642 EvHash: TMD5Digest;
1643 pl: TPlayer;
1644 i1, i2: TStrings_Locale;
1645 pln: String;
1646 cnt: Byte;
1647 begin
1648 FillChar(EvHash, Sizeof(EvHash), 0);
1649 EvType := M.ReadByte();
1650 EvNum := M.ReadLongInt();
1651 EvStr := M.ReadString();
1652 gLastMap := M.ReadByte() <> 0;
1653 if gLastMap and (gGameSettings.GameMode = GM_COOP) then gStatsOff := True;
1654 gStatsPressed := True;
1655 EvTime := M.ReadLongWord();
1656 BHash := M.ReadByte() <> 0;
1657 if BHash then
1658 EvHash := M.ReadMD5();
1660 gTime := EvTime;
1662 case EvType of
1663 NET_EV_MAPSTART:
1664 begin
1665 gGameOn := False;
1666 g_Game_ClearLoading();
1667 g_Game_StopAllSounds(True);
1669 gSwitchGameMode := Byte(EvNum);
1670 gGameSettings.GameMode := gSwitchGameMode;
1672 gWADHash := EvHash;
1673 if not g_Game_StartMap(EvStr, True) then
1674 begin
1675 if not isWadPath(EvStr) then
1676 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + EvStr]))
1677 else
1678 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [EvStr]));
1679 Exit;
1680 end;
1682 MC_SEND_FullStateRequest;
1683 end;
1685 NET_EV_MAPEND:
1686 begin
1687 gMissionFailed := EvNum <> 0;
1688 gExit := EXIT_ENDLEVELCUSTOM;
1689 end;
1691 NET_EV_RCON:
1692 begin
1693 case EvNum of
1694 NET_RCON_NOAUTH:
1695 g_Console_Add(_lc[I_NET_RCON_NOAUTH], True);
1696 NET_RCON_PWGOOD:
1697 g_Console_Add(_lc[I_NET_RCON_PWD_VALID], True);
1698 NET_RCON_PWBAD:
1699 g_Console_Add(_lc[I_NET_RCON_PWD_INVALID], True);
1700 end;
1701 end;
1703 NET_EV_CHANGE_TEAM:
1704 begin
1705 if EvNum = TEAM_RED then
1706 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True);
1707 if EvNum = TEAM_BLUE then
1708 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True);
1709 end;
1711 NET_EV_PLAYER_KICK:
1712 g_Console_Add(Format(_lc[I_PLAYER_KICK], [EvStr]), True);
1714 NET_EV_PLAYER_BAN:
1715 g_Console_Add(Format(_lc[I_PLAYER_BAN], [EvStr]), True);
1717 NET_EV_LMS_WARMUP:
1718 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [EvNum]), True);
1720 NET_EV_LMS_SURVIVOR:
1721 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True);
1723 NET_EV_BIGTEXT:
1724 g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum));
1726 NET_EV_SCORE:
1727 begin
1728 pl := g_Player_Get(EvNum and $FFFF);
1729 if pl = nil then
1730 pln := '?'
1731 else
1732 pln := pl.Name;
1733 cnt := (EvNum shr 16) and $FF;
1734 if Pos('w', EvStr) = 0 then
1735 begin
1736 // Default score
1737 if Pos('t', EvStr) = 0 then
1738 begin
1739 // Player +/- score
1740 if Pos('-', EvStr) = 0 then
1741 begin
1742 if Pos('e', EvStr) = 0 then
1743 i1 := I_PLAYER_SCORE_ADD_OWN
1744 else
1745 i1 := I_PLAYER_SCORE_ADD_ENEMY;
1746 end else
1747 begin
1748 if Pos('e', EvStr) = 0 then
1749 i1 := I_PLAYER_SCORE_SUB_OWN
1750 else
1751 i1 := I_PLAYER_SCORE_SUB_ENEMY;
1752 end;
1753 // Which team
1754 if Pos('r', EvStr) > 0 then
1755 i2 := I_PLAYER_SCORE_TO_RED
1756 else
1757 i2 := I_PLAYER_SCORE_TO_BLUE;
1758 g_Console_Add(Format(_lc[i1], [pln, cnt, _lc[i2]]), True);
1759 end else
1760 begin
1761 // Team +/- score
1762 if Pos('-', EvStr) = 0 then
1763 i1 := I_PLAYER_SCORE_ADD_TEAM
1764 else
1765 i1 := I_PLAYER_SCORE_SUB_TEAM;
1766 // Which team
1767 if Pos('r', EvStr) > 0 then
1768 i2 := I_PLAYER_SCORE_RED
1769 else
1770 i2 := I_PLAYER_SCORE_BLUE;
1771 g_Console_Add(Format(_lc[i1], [_lc[i2], cnt]), True);
1772 end;
1773 end else
1774 begin
1775 // Game Win
1776 if Pos('e', EvStr) = 0 then
1777 i1 := I_PLAYER_SCORE_WIN_OWN
1778 else
1779 i1 := I_PLAYER_SCORE_WIN_ENEMY;
1780 // Which team
1781 if Pos('r', EvStr) > 0 then
1782 i2 := I_PLAYER_SCORE_TO_RED
1783 else
1784 i2 := I_PLAYER_SCORE_TO_BLUE;
1785 g_Console_Add(Format(_lc[i1], [pln, _lc[i2]]), True);
1786 end;
1787 end;
1789 NET_EV_SCORE_MSG:
1790 begin
1791 if EvNum = TEAM_RED then
1792 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1793 if EvNum = TEAM_BLUE then
1794 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1795 if EvNum = -TEAM_RED then
1796 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1797 if EvNum = -TEAM_BLUE then
1798 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1799 end;
1801 NET_EV_LMS_START:
1802 begin
1803 g_Player_RemoveAllCorpses;
1804 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
1805 end;
1807 NET_EV_LMS_WIN:
1808 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(EvStr)]), 144);
1810 NET_EV_TLMS_WIN:
1811 begin
1812 if EvNum = TEAM_RED then
1813 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
1814 if EvNum = TEAM_BLUE then
1815 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
1816 end;
1818 NET_EV_LMS_LOSE:
1819 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
1821 NET_EV_LMS_DRAW:
1822 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
1824 NET_EV_KILLCOMBO:
1825 g_Game_Announce_KillCombo(EvNum);
1827 NET_EV_PLAYER_TOUCH:
1828 begin
1829 pl := g_Player_Get(EvNum);
1830 if pl <> nil then
1831 pl.Touch();
1832 end;
1834 end;
1835 end;
1837 procedure MC_RECV_FlagEvent(var M: TMsg);
1838 var
1839 PID: Word;
1840 Pl: TPlayer;
1841 EvType: Byte;
1842 Fl, a: Byte;
1843 Quiet: Boolean;
1844 s, ts: string;
1845 begin
1846 EvType := M.ReadByte();
1847 Fl := M.ReadByte();
1849 if Fl = FLAG_NONE then Exit;
1851 Quiet := (M.ReadByte() <> 0);
1852 PID := M.ReadWord();
1854 gFlags[Fl].State := M.ReadByte();
1855 gFlags[Fl].CaptureTime := M.ReadLongWord();
1856 gFlags[Fl].Obj.X := M.ReadLongInt();
1857 gFlags[Fl].Obj.Y := M.ReadLongInt();
1858 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
1859 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
1861 Pl := g_Player_Get(PID);
1862 if (Pl = nil) and
1863 (EvType <> FLAG_STATE_NORMAL) and
1864 (EvType <> FLAG_STATE_DROPPED) and
1865 (EvType <> FLAG_STATE_RETURNED) then
1866 Exit;
1868 case EvType of
1869 FLAG_STATE_NORMAL:
1870 begin
1871 if Quiet or (Pl = nil) then Exit;
1873 if Fl = FLAG_RED then
1874 s := _lc[I_PLAYER_FLAG_RED]
1875 else
1876 s := _lc[I_PLAYER_FLAG_BLUE];
1878 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
1880 if ((Pl = gPlayer1) or (Pl = gPlayer2)
1881 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
1882 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
1883 a := 0
1884 else
1885 a := 1;
1887 if not sound_ret_flag[a].IsPlaying() then
1888 sound_ret_flag[a].Play();
1889 end;
1891 FLAG_STATE_CAPTURED:
1892 begin
1893 if (Pl <> nil) then Pl.SetFlag(Fl);
1895 if Quiet then Exit;
1897 if Fl = FLAG_RED then
1898 s := _lc[I_PLAYER_FLAG_RED]
1899 else
1900 s := _lc[I_PLAYER_FLAG_BLUE];
1902 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [Pl.Name, s]), True);
1903 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
1905 if ((Pl = gPlayer1) or (Pl = gPlayer2)
1906 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
1907 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
1908 a := 0
1909 else
1910 a := 1;
1912 if not sound_get_flag[a].IsPlaying() then
1913 sound_get_flag[a].Play();
1914 end;
1916 FLAG_STATE_DROPPED:
1917 begin
1918 if (Pl <> nil) then Pl.SetFlag(FLAG_NONE);
1920 if Quiet or (Pl = nil) then Exit;
1922 if Fl = FLAG_RED then
1923 s := _lc[I_PLAYER_FLAG_RED]
1924 else
1925 s := _lc[I_PLAYER_FLAG_BLUE];
1927 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [Pl.Name, s]), True);
1928 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
1930 if ((Pl = gPlayer1) or (Pl = gPlayer2)
1931 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
1932 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
1933 a := 0
1934 else
1935 a := 1;
1937 if not sound_lost_flag[a].IsPlaying() then
1938 sound_lost_flag[a].Play();
1939 end;
1941 FLAG_STATE_SCORED:
1942 begin
1943 g_Map_ResetFlag(FLAG_RED);
1944 g_Map_ResetFlag(FLAG_BLUE);
1945 if Quiet or (Pl = nil) then Exit;
1946 Pl.SetFlag(FLAG_NONE);
1948 if Fl = FLAG_RED then
1949 s := _lc[I_PLAYER_FLAG_RED]
1950 else
1951 s := _lc[I_PLAYER_FLAG_BLUE];
1953 ts := Format('%.4d', [gFlags[Fl].CaptureTime]);
1954 Insert('.', ts, Length(ts) + 1 - 3);
1955 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [Pl.Name, s, ts]), True);
1956 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
1958 if ((Pl = gPlayer1) or (Pl = gPlayer2)
1959 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
1960 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
1961 a := 0
1962 else
1963 a := 1;
1965 if not sound_cap_flag[a].IsPlaying() then
1966 sound_cap_flag[a].Play();
1967 end;
1969 FLAG_STATE_RETURNED:
1970 begin
1971 g_Map_ResetFlag(Fl);
1972 if Quiet then Exit;
1974 if Fl = FLAG_RED then
1975 s := _lc[I_PLAYER_FLAG_RED]
1976 else
1977 s := _lc[I_PLAYER_FLAG_BLUE];
1979 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
1981 if ((Pl = gPlayer1) or (Pl = gPlayer2)
1982 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
1983 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
1984 a := 0
1985 else
1986 a := 1;
1988 if not sound_ret_flag[a].IsPlaying() then
1989 sound_ret_flag[a].Play();
1990 end;
1991 end;
1992 end;
1994 procedure MC_RECV_GameSettings(var M: TMsg);
1995 begin
1996 gGameSettings.GameMode := M.ReadByte();
1997 gGameSettings.GoalLimit := M.ReadWord();
1998 gGameSettings.TimeLimit := M.ReadWord();
1999 gGameSettings.MaxLives := M.ReadByte();
2000 gGameSettings.Options := M.ReadLongWord();
2001 end;
2003 // PLAYER
2005 function MC_RECV_PlayerCreate(var M: TMsg): Word;
2006 var
2007 PID, DID: Word;
2008 PName, Model: string;
2009 Color: TRGB;
2010 T: Byte;
2011 Pl: TPlayer;
2012 begin
2013 PID := M.ReadWord();
2014 Pl := g_Player_Get(PID);
2016 PName := M.ReadString();
2017 Model := M.ReadString();
2018 Color.R := M.ReadByte();
2019 Color.G := M.ReadByte();
2020 Color.B := M.ReadByte();
2021 T := M.ReadByte();
2023 Result := 0;
2024 if (PID <> NetPlrUID1) and (PID <> NetPlrUID2) then
2025 begin
2026 if (Pl <> nil) then Exit;
2027 DID := g_Player_Create(Model, Color, T, False);
2028 with g_Player_Get(DID) do
2029 begin
2030 UID := PID;
2031 Name := PName;
2032 Reset(True);
2033 end;
2034 end
2035 else
2036 begin
2037 if (PID = NetPlrUID1) and (gPlayer1 <> nil) then begin
2038 gPlayer1.UID := PID;
2039 gPlayer1.Model.SetColor(Color.R, Color.G, Color.B);
2040 gPlayer1.ChangeTeam(T);
2041 end;
2042 if (PID = NetPlrUID2) and (gPlayer2 <> nil) then begin
2043 gPlayer2.UID := PID;
2044 gPlayer2.Model.SetColor(Color.R, Color.G, Color.B);
2045 gPlayer2.ChangeTeam(T);
2046 end;
2047 end;
2049 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
2050 e_WriteLog('NET: Player ' + PName + ' [' + IntToStr(PID) + '] added.', TMsgType.Notify);
2051 Result := PID;
2052 end;
2054 function MC_RECV_PlayerPos(var M: TMsg): Word;
2055 var
2056 GT: LongWord;
2057 PID: Word;
2058 kByte: Word;
2059 Pl: TPlayer;
2060 Dir: Byte;
2061 TmpX, TmpY: Integer;
2062 begin
2063 Result := 0;
2065 GT := M.ReadLongWord();
2066 if GT < gTime - NET_MAX_DIFFTIME then
2067 begin
2068 gTime := GT;
2069 Exit;
2070 end;
2071 gTime := GT;
2073 PID := M.ReadWord();
2074 Pl := g_Player_Get(PID);
2076 if Pl = nil then Exit;
2078 Result := PID;
2080 with Pl do
2081 begin
2082 FPing := M.ReadWord();
2083 FLoss := M.ReadByte();
2084 kByte := M.ReadWord();
2085 Dir := M.ReadByte();
2087 TmpX := M.ReadLongInt();
2088 TmpY := M.ReadLongInt();
2090 ReleaseKeys;
2092 if (kByte = NET_KEY_CHAT) then
2093 PressKey(KEY_CHAT, 10000)
2094 else
2095 begin
2096 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
2097 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
2098 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
2099 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
2100 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
2101 end;
2103 if ((Pl <> gPlayer1) and (Pl <> gPlayer2)) or LongBool(kByte and NET_KEY_FORCEDIR) then
2104 SetDirection(TDirection(Dir));
2106 GameVelX := M.ReadLongInt();
2107 GameVelY := M.ReadLongInt();
2108 GameAccelX := M.ReadLongInt();
2109 GameAccelY := M.ReadLongInt();
2110 SetLerp(TmpX, TmpY);
2111 if NetForcePlayerUpdate then Update();
2112 end;
2113 end;
2115 function MC_RECV_PlayerStats(var M: TMsg): Word;
2116 var
2117 PID: Word;
2118 Pl: TPlayer;
2119 I: Integer;
2120 OldJet, Flam: Boolean;
2121 NewTeam: Byte;
2122 begin
2123 PID := M.ReadWord();
2124 Pl := g_Player_Get(PID);
2125 Result := 0;
2126 if Pl = nil then
2127 Exit;
2129 with Pl do
2130 begin
2131 alive := (M.ReadByte() <> 0);
2132 GodMode := (M.ReadByte() <> 0);
2133 Health := M.ReadLongInt();
2134 Armor := M.ReadLongInt();
2135 Air := M.ReadLongInt();
2136 JetFuel := M.ReadLongInt();
2137 Lives := M.ReadByte();
2138 NewTeam := M.ReadByte();
2140 for I := WP_FIRST to WP_LAST do
2141 FWeapon[I] := (M.ReadByte() <> 0);
2143 for I := A_BULLETS to A_HIGH do
2144 FAmmo[I] := M.ReadWord();
2146 for I := A_BULLETS to A_HIGH do
2147 FMaxAmmo[I] := M.ReadWord();
2149 for I := MR_SUIT to MR_MAX do
2150 FMegaRulez[I] := M.ReadLongWord();
2152 FRulez := [];
2153 if (M.ReadByte() <> 0) then
2154 FRulez := FRulez + [R_ITEM_BACKPACK];
2155 if (M.ReadByte() <> 0) then
2156 FRulez := FRulez + [R_KEY_RED];
2157 if (M.ReadByte() <> 0) then
2158 FRulez := FRulez + [R_KEY_GREEN];
2159 if (M.ReadByte() <> 0) then
2160 FRulez := FRulez + [R_KEY_BLUE];
2161 if (M.ReadByte() <> 0) then
2162 FRulez := FRulez + [R_BERSERK];
2164 Frags := M.ReadLongInt();
2165 Death := M.ReadLongInt();
2167 SetWeapon(M.ReadByte());
2169 FSpectator := M.ReadByte() <> 0;
2170 if FSpectator then
2171 begin
2172 if Pl = gPlayer1 then
2173 begin
2174 gLMSPID1 := UID;
2175 gPlayer1 := nil;
2176 end;
2177 if Pl = gPlayer2 then
2178 begin
2179 gLMSPID2 := UID;
2180 gPlayer2 := nil;
2181 end;
2182 end
2183 else
2184 begin
2185 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
2186 gPlayer1 := g_Player_Get(gLMSPID1);
2187 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
2188 gPlayer2 := g_Player_Get(gLMSPID2);
2189 end;
2190 FGhost := M.ReadByte() <> 0;
2191 FPhysics := M.ReadByte() <> 0;
2192 FNoRespawn := M.ReadByte() <> 0;
2193 OldJet := FJetpack;
2194 FJetpack := M.ReadByte() <> 0;
2195 FFireTime := M.ReadLongInt();
2196 Flam := M.ReadByte() <> 0;
2197 if OldJet and not FJetpack then
2198 JetpackOff
2199 else if not OldJet and FJetpack then
2200 JetpackOn;
2201 if FFlaming and not Flam then
2202 FlamerOff;
2203 if Team <> NewTeam then
2204 Pl.ChangeTeam(NewTeam);
2205 end;
2207 Result := PID;
2208 end;
2210 function MC_RECV_PlayerDamage(var M: TMsg): Word;
2211 var
2212 PID: Word;
2213 Pl: TPlayer;
2214 Kind: Byte;
2215 Attacker, Value: Word;
2216 VX, VY: Integer;
2217 begin
2218 Result := 0;
2219 if not gGameOn then Exit;
2220 PID := M.ReadWord();
2221 Pl := g_Player_Get(PID);
2222 if Pl = nil then Exit;
2224 Kind := M.ReadByte();
2225 Attacker := M.ReadWord();
2226 Value := M.ReadWord();
2227 VX := M.ReadWord();
2228 VY := M.ReadWord();
2230 with Pl do
2231 Damage(Value, Attacker, VX, VY, Kind);
2233 Result := PID;
2234 end;
2236 function MC_RECV_PlayerDeath(var M: TMsg): Word;
2237 var
2238 PID: Word;
2239 Pl: TPlayer;
2240 KillType, DeathType: Byte;
2241 Attacker: Word;
2242 begin
2243 Result := 0;
2244 if not gGameOn then Exit;
2245 PID := M.ReadWord();
2246 Pl := g_Player_Get(PID);
2247 if Pl = nil then Exit;
2249 KillType := M.ReadByte();
2250 DeathType := M.ReadByte();
2251 Attacker := M.ReadWord();
2253 with Pl do
2254 begin
2255 Kill(KillType, Attacker, DeathType);
2256 SoftReset;
2257 end;
2258 end;
2260 function MC_RECV_PlayerDelete(var M: TMsg): Word;
2261 var
2262 PID: Word;
2263 Pl: TPlayer;
2264 begin
2265 PID := M.ReadWord();
2266 Pl := g_Player_Get(PID);
2267 Result := 0;
2268 if Pl = nil then Exit;
2270 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2271 e_WriteLog('NET: Player ' + Pl.Name + ' [' + IntToStr(PID) + '] removed.', TMsgType.Notify);
2273 g_Player_Remove(PID);
2275 Result := PID;
2276 end;
2278 function MC_RECV_PlayerFire(var M: TMsg): Word;
2279 var
2280 PID: Word;
2281 Weap: Byte;
2282 Pl: TPlayer;
2283 X, Y, AX, AY: Integer;
2284 SHID: Integer;
2285 begin
2286 Result := 0;
2287 if not gGameOn then Exit;
2288 PID := M.ReadWord();
2289 Pl := g_Player_Get(PID);
2290 if Pl = nil then Exit;
2292 Weap := M.ReadByte();
2293 X := M.ReadLongInt();
2294 Y := M.ReadLongInt();
2295 AX := M.ReadLongInt();
2296 AY := M.ReadLongInt();
2297 SHID := M.ReadLongInt();
2299 with Pl do
2300 if alive then NetFire(Weap, X, Y, AX, AY, SHID);
2301 end;
2303 procedure MC_RECV_PlayerSettings(var M: TMsg);
2304 var
2305 TmpName: string;
2306 TmpModel: string;
2307 TmpColor: TRGB;
2308 TmpTeam: Byte;
2309 Pl: TPlayer;
2310 PID: Word;
2311 begin
2312 PID := M.ReadWord();
2313 Pl := g_Player_Get(PID);
2314 if Pl = nil then Exit;
2316 TmpName := M.ReadString();
2317 TmpModel := M.ReadString();
2318 TmpColor.R := M.ReadByte();
2319 TmpColor.G := M.ReadByte();
2320 TmpColor.B := M.ReadByte();
2321 TmpTeam := M.ReadByte();
2323 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
2324 begin
2325 Pl.ChangeTeam(TmpTeam);
2326 if gPlayer1 = Pl then
2327 gPlayer1Settings.Team := TmpTeam;
2328 if gPlayer2 = Pl then
2329 gPlayer2Settings.Team := TmpTeam;
2330 end else
2331 Pl.SetColor(TmpColor);
2333 if Pl.Name <> TmpName then
2334 begin
2335 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
2336 Pl.Name := TmpName;
2337 end;
2339 if TmpModel <> Pl.Model.Name then
2340 Pl.SetModel(TmpModel);
2341 end;
2343 // ITEM
2345 procedure MC_RECV_ItemSpawn(var M: TMsg);
2346 var
2347 ID: Word;
2348 AID: DWord;
2349 X, Y, VX, VY: Integer;
2350 T: Byte;
2351 Quiet, Fall{, Resp}: Boolean;
2352 Anim: TAnimation;
2353 it: PItem;
2354 begin
2355 if not gGameOn then Exit;
2356 ID := M.ReadWord();
2357 Quiet := M.ReadByte() <> 0;
2358 T := M.ReadByte();
2359 Fall := M.ReadByte() <> 0;
2360 {Resp :=} M.ReadByte();
2361 X := M.ReadLongInt();
2362 Y := M.ReadLongInt();
2363 VX := M.ReadLongInt();
2364 VY := M.ReadLongInt();
2366 g_Items_Create(X, Y, T and $7F, Fall, False, False, ID);
2367 if ((T and $80) <> 0) then g_Items_SetDrop(ID);
2369 it := g_Items_ByIdx(ID);
2370 it.Obj.Vel.X := VX;
2371 it.Obj.Vel.Y := VY;
2373 if not Quiet then
2374 begin
2375 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
2376 if g_Frames_Get(AID, 'FRAMES_ITEM_RESPAWN') then
2377 begin
2378 Anim := TAnimation.Create(AID, False, 4);
2379 g_GFX_OnceAnim(X+(it.Obj.Rect.Width div 2)-16, Y+(it.Obj.Rect.Height div 2)-16, Anim);
2380 Anim.Free();
2381 end;
2382 end;
2383 end;
2385 procedure MC_RECV_ItemDestroy(var M: TMsg);
2386 var
2387 ID: Word;
2388 Quiet: Boolean;
2389 begin
2390 if not gGameOn then Exit;
2391 ID := M.ReadWord();
2392 Quiet := M.ReadByte() <> 0;
2394 if not g_Items_ValidId(ID) then exit;
2396 if not Quiet then g_Items_EmitPickupSound(ID);
2398 g_Items_Remove(ID);
2399 end;
2401 // PANEL
2403 procedure MC_RECV_PanelTexture(var M: TMsg);
2404 var
2405 TP: TPanel;
2406 PGUID: Integer;
2407 Tex, Fr: Integer;
2408 Loop, Cnt: Byte;
2409 begin
2410 if not gGameOn then Exit;
2412 PGUID := Integer(M.ReadLongWord());
2413 Tex := M.ReadLongInt();
2414 Fr := M.ReadLongInt();
2415 Cnt := M.ReadByte();
2416 Loop := M.ReadByte();
2418 TP := g_Map_PanelByGUID(PGUID);
2419 if (TP <> nil) then
2420 begin
2421 // switch texture
2422 TP.SetTexture(Tex, Loop);
2423 TP.SetFrame(Fr, Cnt);
2424 end;
2425 end;
2427 procedure MC_RECV_PanelState(var M: TMsg);
2428 var
2429 PGUID: Integer;
2430 E: Boolean;
2431 Lift: Byte;
2432 X, Y, W, H: Integer;
2433 TP: TPanel;
2434 speedX, speedY, startX, startY, endX, endY: Integer;
2435 sizeSpX, sizeSpY, sizeEX, sizeEY: Integer;
2436 mpflags: Byte;
2437 begin
2438 if not gGameOn then Exit;
2440 PGUID := Integer(M.ReadLongWord());
2441 E := (M.ReadByte() <> 0);
2442 Lift := M.ReadByte();
2443 X := M.ReadLongInt();
2444 Y := M.ReadLongInt();
2445 W := M.ReadWord();
2446 H := M.ReadWord();
2447 // mplats
2448 speedX := M.ReadLongInt();
2449 speedY := M.ReadLongInt();
2450 startX := M.ReadLongInt();
2451 startY := M.ReadLongInt();
2452 endX := M.ReadLongInt();
2453 endY := M.ReadLongInt();
2454 sizeSpX := M.ReadLongInt();
2455 sizeSpY := M.ReadLongInt();
2456 sizeEX := M.ReadLongInt();
2457 sizeEY := M.ReadLongInt();
2458 mpflags := M.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2460 TP := g_Map_PanelByGUID(PGUID);
2461 if (TP = nil) then exit;
2463 // update lifts state
2464 if TP.isGLift then g_Map_SetLiftGUID(PGUID, Lift);
2466 // update enabled/disabled state for all panels
2467 if E then g_Map_EnableWallGUID(PGUID) else g_Map_DisableWallGUID(PGUID);
2469 // update panel position, as it can be moved (mplat)
2470 TP.X := X;
2471 TP.Y := Y;
2472 TP.Width := W;
2473 TP.Height := H;
2474 // update mplat state
2475 TP.movingSpeedX := speedX;
2476 TP.movingSpeedY := speedY;
2477 TP.movingStartX := startX;
2478 TP.movingStartY := startY;
2479 TP.movingEndX := endX;
2480 TP.movingEndY := endY;
2481 TP.sizeSpeedX := sizeSpX;
2482 TP.sizeSpeedY := sizeSpY;
2483 TP.sizeEndX := sizeEX;
2484 TP.sizeEndY := sizeEY;
2485 TP.movingActive := ((mpflags and 1) <> 0);
2486 TP.moveOnce := ((mpflags and 2) <> 0);
2487 // notify panel of it's position/size change, so it can fix other internal structures
2488 TP.positionChanged();
2489 end;
2491 // TRIGGERS
2493 procedure MC_RECV_TriggerSound(var M: TMsg);
2494 var
2495 SPlaying: Boolean;
2496 SPos, SID: LongWord;
2497 SCount: LongInt;
2498 I: Integer;
2499 begin
2500 if not gGameOn then Exit;
2501 if gTriggers = nil then Exit;
2503 SID := M.ReadLongWord();
2504 SPlaying := M.ReadByte() <> 0;
2505 SPos := M.ReadLongWord();
2506 SCount := M.ReadLongInt();
2508 for I := Low(gTriggers) to High(gTriggers) do
2509 if gTriggers[I].TriggerType = TRIGGER_SOUND then
2510 if gTriggers[I].ClientID = SID then
2511 with gTriggers[I] do
2512 begin
2513 if Sound <> nil then
2514 begin
2515 if SPlaying then
2516 begin
2517 if tgcLocal then
2518 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), tgcVolume/255.0)
2519 else
2520 Sound.PlayPanVolume((tgcPan-127.0)/128.0, tgcVolume/255.0);
2521 Sound.SetPosition(SPos);
2522 end
2523 else
2524 if Sound.IsPlaying then Sound.Stop;
2525 end;
2527 SoundPlayCount := SCount;
2528 end;
2529 end;
2531 procedure MC_RECV_TriggerMusic(var M: TMsg);
2532 var
2533 MName: string;
2534 MPlaying: Boolean;
2535 MPos: LongWord;
2536 MPaused: Boolean;
2537 begin
2538 if not gGameOn then Exit;
2540 MName := M.ReadString();
2541 MPlaying := M.ReadByte() <> 0;
2542 MPos := M.ReadLongWord();
2543 MPaused := M.ReadByte() <> 0;
2545 if MPlaying then
2546 begin
2547 gMusic.SetByName(MName);
2548 gMusic.Play(True);
2549 gMusic.SetPosition(MPos);
2550 gMusic.SpecPause := MPaused;
2551 end
2552 else
2553 if gMusic.IsPlaying then gMusic.Stop;
2554 end;
2556 // MONSTERS
2558 procedure MC_RECV_MonsterSpawn(var M: TMsg);
2559 var
2560 ID: Word;
2561 MType, MState, MDir, MAnim, MBehav: Byte;
2562 X, Y, VX, VY, MTargTime, MHealth, MAmmo, MSleep: Integer;
2563 MTarg: Word;
2564 Mon: TMonster;
2565 begin
2566 ID := M.ReadWord();
2567 Mon := g_Monsters_ByUID(ID);
2568 if Mon <> nil then
2569 Exit;
2571 MType := M.ReadByte();
2572 MState := M.ReadByte();
2573 MAnim := M.ReadByte();
2574 MTarg := M.ReadWord();
2575 MTargTime := M.ReadLongInt();
2576 MBehav := M.ReadByte();
2577 MSleep := M.ReadLongInt();
2578 MHealth := M.ReadLongInt();
2579 MAmmo := M.ReadLongInt();
2581 X := M.ReadLongInt();
2582 Y := M.ReadLongInt();
2583 VX := M.ReadLongInt();
2584 VY := M.ReadLongInt();
2585 MDir := M.ReadByte();
2587 g_Monsters_Create(MType, X, Y, TDirection(MDir), False, ID);
2588 Mon := g_Monsters_ByUID(ID);
2589 if Mon = nil then
2590 Exit;
2592 with Mon do
2593 begin
2595 MonsterAnim := MAnim;
2596 MonsterTargetUID := MTarg;
2597 MonsterTargetTime := MTargTime;
2598 MonsterBehaviour := MBehav;
2599 MonsterSleep := MSleep;
2600 MonsterAmmo := MAmmo;
2601 SetHealth(MHealth);
2603 SetState(MState);
2605 setPosition(X, Y); // this will call positionChanged();
2606 GameVelX := VX;
2607 GameVelY := VY;
2608 end;
2609 end;
2611 procedure MC_RECV_MonsterPos(var M: TMsg);
2612 var
2613 Mon: TMonster;
2614 ID: Word;
2615 X, Y: Integer;
2616 begin
2617 ID := M.ReadWord();
2618 Mon := g_Monsters_ByUID(ID);
2619 if Mon = nil then
2620 Exit;
2622 with Mon do
2623 begin
2624 X := M.ReadLongInt();
2625 Y := M.ReadLongInt();
2626 Mon.setPosition(X, Y); // this will call `positionChanged()`
2627 GameVelX := M.ReadLongInt();
2628 GameVelY := M.ReadLongInt();
2629 GameDirection := TDirection(M.ReadByte());
2630 end;
2631 end;
2633 procedure MC_RECV_MonsterState(var M: TMsg);
2634 var
2635 ID: Integer;
2636 MState, MFAnm: Byte;
2637 Mon: TMonster;
2638 AnimRevert: Boolean;
2639 begin
2640 ID := M.ReadWord();
2641 Mon := g_Monsters_ByUID(ID);
2642 if Mon = nil then Exit;
2644 MState := M.ReadByte();
2645 MFAnm := M.ReadByte();
2647 with Mon do
2648 begin
2649 MonsterTargetUID := M.ReadWord();
2650 MonsterTargetTime := M.ReadLongInt();
2651 MonsterSleep := M.ReadLongInt();
2652 MonsterHealth := M.ReadLongInt();
2653 MonsterAmmo := M.ReadLongInt();
2654 MonsterPain := M.ReadLongInt();
2655 AnimRevert := M.ReadByte() <> 0;
2656 FFireTime := M.ReadLongInt();
2657 RevertAnim(AnimRevert);
2659 if MonsterState <> MState then
2660 begin
2661 if (MState = MONSTATE_GO) and (MonsterState = MONSTATE_SLEEP) then WakeUpSound();
2662 if (MState = MONSTATE_DIE) then DieSound();
2663 if (MState = MONSTATE_PAIN) then MakeBloodSimple(Min(200, MonsterPain));
2664 if (MState = MONSTATE_ATTACK) then kick(nil);
2665 if (MState = MONSTATE_DEAD) then SetDeadAnim();
2667 SetState(MState, MFAnm);
2668 end;
2669 end;
2670 end;
2672 procedure MC_RECV_MonsterShot(var M: TMsg);
2673 var
2674 ID: Integer;
2675 Mon: TMonster;
2676 X, Y, VX, VY: Integer;
2677 begin
2678 ID := M.ReadWord();
2680 Mon := g_Monsters_ByUID(ID);
2681 if Mon = nil then Exit;
2683 X := M.ReadLongInt();
2684 Y := M.ReadLongInt();
2685 VX := M.ReadLongInt();
2686 VY := M.ReadLongInt();
2688 Mon.ClientAttack(X, Y, VX, VY);
2689 end;
2691 procedure MC_RECV_MonsterDelete(var M: TMsg);
2692 var
2693 ID: Integer;
2694 Mon: TMonster;
2695 begin
2696 ID := M.ReadWord();
2697 Mon := g_Monsters_ByUID(ID);
2698 if Mon = nil then Exit;
2699 Mon.SetState(5);
2700 Mon.MonsterRemoved := True;
2701 end;
2703 procedure MC_RECV_TimeSync(var M: TMsg);
2704 var
2705 Time: LongWord;
2706 begin
2707 Time := M.ReadLongWord();
2709 if gState = STATE_INTERCUSTOM then
2710 gServInterTime := Min(Time, 255);
2711 end;
2713 procedure MC_RECV_VoteEvent(var M: TMsg);
2714 var
2715 EvID: Byte;
2716 Str1, Str2: string;
2717 Int1, Int2: SmallInt;
2718 begin
2719 EvID := M.ReadByte();
2720 Int1 := M.ReadSmallInt();
2721 Int2 := M.ReadSmallInt();
2722 Str1 := M.ReadString();
2723 Str2 := M.ReadString();
2725 case EvID of
2726 NET_VE_STARTED:
2727 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True);
2728 NET_VE_PASSED:
2729 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True);
2730 NET_VE_FAILED:
2731 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
2732 NET_VE_VOTE:
2733 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True);
2734 NET_VE_INPROGRESS:
2735 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True);
2736 end;
2737 end;
2739 // CLIENT SEND
2741 procedure MC_SEND_Info(Password: string);
2742 begin
2743 NetOut.Clear();
2745 NetOut.Write(Byte(NET_MSG_INFO));
2746 NetOut.Write(GAME_VERSION);
2747 NetOut.Write(Password);
2748 NetOut.Write(gPlayer1Settings.Name);
2749 NetOut.Write(gPlayer1Settings.Model);
2750 NetOut.Write(gPlayer1Settings.Color.R);
2751 NetOut.Write(gPlayer1Settings.Color.G);
2752 NetOut.Write(gPlayer1Settings.Color.B);
2753 NetOut.Write(gPlayer1Settings.Team);
2755 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2756 end;
2758 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
2759 begin
2760 NetOut.Write(Byte(NET_MSG_CHAT));
2761 NetOut.Write(Txt);
2762 NetOut.Write(Mode);
2764 g_Net_Client_Send(True, NET_CHAN_CHAT);
2765 end;
2767 function isKeyPressed (key1: Word; key2: Word): Boolean;
2768 begin
2769 if (key1 <> 0) and e_KeyPressed(key1) then begin result := true; exit; end;
2770 if (key2 <> 0) and e_KeyPressed(key2) then begin result := true; exit; end;
2771 result := false;
2772 end;
2774 procedure MC_SEND_PlayerPos();
2775 var
2776 kByte: Word;
2777 Predict: Boolean;
2778 strafeDir: Byte;
2779 WeaponSelect: Word = 0;
2780 I: Integer;
2781 begin
2782 if not gGameOn then Exit;
2783 if gPlayers = nil then Exit;
2784 if gPlayer1 = nil then Exit;
2786 kByte := 0;
2787 Predict := NetPredictSelf; // and (not NetGotKeys);
2789 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2790 begin
2791 strafeDir := P1MoveButton shr 4;
2792 P1MoveButton := P1MoveButton and $0F;
2793 with gGameControls.P1Control do
2794 begin
2795 if isKeyPressed(KeyLeft, KeyLeft2) and (not isKeyPressed(KeyRight, KeyRight2)) then P1MoveButton := 1
2796 else if (not isKeyPressed(KeyLeft, KeyLeft2)) and isKeyPressed(KeyRight, KeyRight2) then P1MoveButton := 2
2797 else if (not isKeyPressed(KeyLeft, KeyLeft2)) and (not isKeyPressed(KeyRight, KeyRight2)) then P1MoveButton := 0;
2799 // strafing
2800 if isKeyPressed(KeyStrafe, KeyStrafe2) then
2801 begin
2802 // new strafe mechanics
2803 if (strafeDir = 0) then strafeDir := P1MoveButton; // start strafing
2804 // now set direction according to strafe (reversed)
2805 if (strafeDir = 2) then gPlayer1.SetDirection(TDirection.D_LEFT)
2806 else if (strafeDir = 1) then gPlayer1.SetDirection(TDirection.D_RIGHT);
2807 end
2808 else
2809 begin
2810 if (P1MoveButton = 2) and isKeyPressed(KeyLeft, KeyLeft2) then gPlayer1.SetDirection(TDirection.D_LEFT)
2811 else if (P1MoveButton = 1) and isKeyPressed(KeyRight, KeyRight2) then gPlayer1.SetDirection(TDirection.D_RIGHT)
2812 else if P1MoveButton <> 0 then gPlayer1.SetDirection(TDirection(P1MoveButton-1));
2813 end;
2815 gPlayer1.ReleaseKeys;
2816 if P1MoveButton = 1 then
2817 begin
2818 kByte := kByte or NET_KEY_LEFT;
2819 if Predict then gPlayer1.PressKey(KEY_LEFT, 10000);
2820 end;
2821 if P1MoveButton = 2 then
2822 begin
2823 kByte := kByte or NET_KEY_RIGHT;
2824 if Predict then gPlayer1.PressKey(KEY_RIGHT, 10000);
2825 end;
2826 if isKeyPressed(KeyUp, KeyUp2) then
2827 begin
2828 kByte := kByte or NET_KEY_UP;
2829 gPlayer1.PressKey(KEY_UP, 10000);
2830 end;
2831 if isKeyPressed(KeyDown, KeyDown2) then
2832 begin
2833 kByte := kByte or NET_KEY_DOWN;
2834 gPlayer1.PressKey(KEY_DOWN, 10000);
2835 end;
2836 if isKeyPressed(KeyJump, KeyJump2) then
2837 begin
2838 kByte := kByte or NET_KEY_JUMP;
2839 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2840 end;
2841 if isKeyPressed(KeyFire, KeyFire2) then kByte := kByte or NET_KEY_FIRE;
2842 if isKeyPressed(KeyOpen, KeyOpen2) then kByte := kByte or NET_KEY_OPEN;
2843 if isKeyPressed(KeyNextWeapon, KeyNextWeapon2) then kByte := kByte or NET_KEY_NW;
2844 if isKeyPressed(KeyPrevWeapon, KeyPrevWeapon2) then kByte := kByte or NET_KEY_PW;
2845 for I := 0 to High(KeyWeapon) do
2846 if isKeyPressed(KeyWeapon[I], KeyWeapon2[I]) then
2847 WeaponSelect := WeaponSelect or Word(1 shl I);
2848 end;
2849 // fix movebutton state
2850 P1MoveButton := P1MoveButton or (strafeDir shl 4);
2851 end
2852 else
2853 kByte := NET_KEY_CHAT;
2855 NetOut.Write(Byte(NET_MSG_PLRPOS));
2856 NetOut.Write(gTime);
2857 NetOut.Write(kByte);
2858 NetOut.Write(Byte(gPlayer1.Direction));
2859 NetOut.Write(WeaponSelect);
2860 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2861 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS);
2863 //kBytePrev := kByte;
2864 //kDirPrev := gPlayer1.Direction;
2865 end;
2867 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
2868 begin
2869 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
2870 NetOut.Write(Byte(Start));
2871 NetOut.Write(Command);
2872 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2873 end;
2875 procedure MC_SEND_PlayerSettings();
2876 begin
2877 NetOut.Write(Byte(NET_MSG_PLRSET));
2878 NetOut.Write(gPlayer1Settings.Name);
2879 NetOut.Write(gPlayer1Settings.Model);
2880 NetOut.Write(gPlayer1Settings.Color.R);
2881 NetOut.Write(gPlayer1Settings.Color.G);
2882 NetOut.Write(gPlayer1Settings.Color.B);
2883 NetOut.Write(gPlayer1Settings.Team);
2885 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2886 end;
2888 procedure MC_SEND_FullStateRequest();
2889 begin
2890 NetOut.Write(Byte(NET_MSG_REQFST));
2892 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2893 end;
2895 procedure MC_SEND_CheatRequest(Kind: Byte);
2896 begin
2897 NetOut.Write(Byte(NET_MSG_CHEAT));
2898 NetOut.Write(Kind);
2900 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2901 end;
2902 procedure MC_SEND_RCONPassword(Password: string);
2903 begin
2904 NetOut.Write(Byte(NET_MSG_RCON_AUTH));
2905 NetOut.Write(Password);
2907 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2908 end;
2909 procedure MC_SEND_RCONCommand(Cmd: string);
2910 begin
2911 NetOut.Write(Byte(NET_MSG_RCON_CMD));
2912 NetOut.Write(Cmd);
2914 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2915 end;
2917 // i have no idea why all this stuff is in here
2919 function ReadFile(const FileName: TFileName): AByte;
2920 var
2921 FileStream : TStream;
2922 fname: string;
2923 begin
2924 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName]), TMsgType.Notify);
2925 fname := findDiskWad(FileName);
2926 if length(fname) = 0 then
2927 begin
2928 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName]), TMsgType.Fatal);
2929 SetLength(Result, 0);
2930 exit;
2931 end;
2932 e_WriteLog(Format('NETWORK: found file "%s"', [fname]), TMsgType.Notify);
2933 Result := nil;
2934 FileStream := openDiskFileRO(fname);
2935 try
2936 if FileStream.Size > 0 then
2937 begin
2938 SetLength(Result, FileStream.Size);
2939 FileStream.Read(Result[0], FileStream.Size);
2940 end;
2941 finally
2942 FileStream.Free;
2943 end;
2944 end;
2946 function CreateMapDataMsg(const FileName: TFileName; ResList: TStringList): TMapDataMsg;
2947 var
2948 i: Integer;
2949 begin
2950 Result.MsgId := NET_MSG_MAP_RESPONSE;
2951 Result.FileData := ReadFile(FileName);
2952 Result.FileSize := Length(Result.FileData);
2954 SetLength(Result.ExternalResources, ResList.Count);
2955 for i:=0 to ResList.Count-1 do
2956 begin
2957 Result.ExternalResources[i].Name := ResList.Strings[i];
2958 Result.ExternalResources[i].md5 := MD5File(GameDir+'/wads/'+ResList.Strings[i]);
2959 end;
2960 end;
2962 procedure ResDataMsgToBytes(var bytes: AByte; const ResData: TResDataMsg);
2963 var
2964 ResultStream: TMemoryStream;
2965 begin
2966 ResultStream := TMemoryStream.Create;
2968 ResultStream.WriteBuffer(ResData.MsgId, SizeOf(ResData.MsgId)); //msgId
2969 ResultStream.WriteBuffer(ResData.FileSize, SizeOf(ResData.FileSize)); //file size
2970 ResultStream.WriteBuffer(ResData.FileData[0], ResData.FileSize); //file data
2972 SetLength(bytes, ResultStream.Size);
2973 ResultStream.Seek(0, soFromBeginning);
2974 ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
2976 ResultStream.Free;
2977 end;
2979 function ResDataFromMsgStream(msgStream: TMemoryStream):TResDataMsg;
2980 begin
2981 msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
2982 msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize));
2983 SetLength(Result.FileData, Result.FileSize);
2984 msgStream.ReadBuffer(Result.FileData[0], Result.FileSize);
2985 end;
2987 procedure MapDataMsgToBytes(var bytes: AByte; const MapDataMsg: TMapDataMsg);
2988 var
2989 ResultStream: TMemoryStream;
2990 resCount: Integer;
2991 begin
2992 resCount := Length(MapDataMsg.ExternalResources);
2994 ResultStream := TMemoryStream.Create;
2996 ResultStream.WriteBuffer(MapDataMsg.MsgId, SizeOf(MapDataMsg.MsgId)); //msgId
2997 ResultStream.WriteBuffer(MapDataMsg.FileSize, SizeOf(MapDataMsg.FileSize)); //file size
2998 ResultStream.WriteBuffer(MapDataMsg.FileData[0], MapDataMsg.FileSize); //file data
3000 ResultStream.WriteBuffer(resCount, SizeOf(resCount)); //res count
3001 ResultStream.WriteBuffer(MapDataMsg.ExternalResources[0], resCount*SizeOf(TExternalResourceInfo)); //res data
3003 SetLength(bytes, ResultStream.Size);
3004 ResultStream.Seek(0, soFromBeginning);
3005 ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
3007 ResultStream.Free;
3008 end;
3010 function MapDataFromMsgStream(msgStream: TMemoryStream):TMapDataMsg;
3011 var
3012 resCount: Integer;
3013 begin
3014 msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
3015 msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize)); //file size
3017 SetLength(Result.FileData, Result.FileSize);
3018 msgStream.ReadBuffer(Result.FileData[0], Result.FileSize); //file data
3020 msgStream.ReadBuffer(resCount, SizeOf(resCount)); //res count
3021 SetLength(Result.ExternalResources, resCount);
3023 msgStream.ReadBuffer(Result.ExternalResources[0], resCount * SizeOf(TExternalResourceInfo)); //res data
3024 end;
3026 function IsValidFileName(const S: String): Boolean;
3027 const
3028 Forbidden: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
3029 var
3030 I: Integer;
3031 begin
3032 Result := S <> '';
3033 for I := 1 to Length(S) do
3034 Result := Result and (not(S[I] in Forbidden));
3035 end;
3037 function IsValidFilePath(const S: String): Boolean;
3038 var
3039 I: Integer;
3040 begin
3041 Result := False;
3042 if not IsValidFileName(S) then exit;
3043 if FileExists(S) then exit;
3044 I := LastDelimiter('\/', S);
3045 if (I > 0) then
3046 if (not DirectoryExists(Copy(S, 1, I-1))) then
3047 exit;
3048 Result := True;
3049 end;
3051 procedure MC_SEND_MapRequest();
3052 begin
3053 NetOut.Write(Byte(NET_MSG_MAP_REQUEST));
3054 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3055 end;
3057 procedure MC_SEND_ResRequest(const resName: AnsiString);
3058 begin
3059 NetOut.Write(Byte(NET_MSG_RES_REQUEST));
3060 NetOut.Write(resName);
3061 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3062 end;
3064 procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
3065 var
3066 payload: AByte;
3067 peer: pENetPeer;
3068 mapDataMsg: TMapDataMsg;
3069 begin
3070 e_WriteLog('NET: Received map request from ' +
3071 DecodeIPV4(C^.Peer.address.host), TMsgType.Notify);
3073 mapDataMsg := CreateMapDataMsg(MapsDir + gGameSettings.WAD, gExternalResources);
3074 peer := NetClients[C^.ID].Peer;
3076 MapDataMsgToBytes(payload, mapDataMsg);
3077 g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
3079 payload := nil;
3080 mapDataMsg.FileData := nil;
3081 mapDataMsg.ExternalResources := nil;
3082 end;
3084 procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
3085 var
3086 payload: AByte;
3087 peer: pENetPeer;
3088 FileName: String;
3089 resDataMsg: TResDataMsg;
3090 begin
3091 FileName := ExtractFileName(M.ReadString());
3092 e_WriteLog('NET: Received res request: ' + FileName +
3093 ' from ' + DecodeIPV4(C^.Peer.address.host), TMsgType.Notify);
3095 if not IsValidFilePath(FileName) then
3096 begin
3097 e_WriteLog('Invalid filename: ' + FileName, TMsgType.Warning);
3098 exit;
3099 end;
3101 peer := NetClients[C^.ID].Peer;
3103 if gExternalResources.IndexOf(FileName) > -1 then
3104 begin
3105 resDataMsg.MsgId := NET_MSG_RES_RESPONSE;
3106 resDataMsg.FileData := ReadFile(GameDir+'/wads/'+FileName);
3107 resDataMsg.FileSize := Length(resDataMsg.FileData);
3109 ResDataMsgToBytes(payload, resDataMsg);
3110 g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
3111 end;
3112 end;
3114 end.