DEADSOFTWARE

removed "monidx" argument from monster spatial query callback (each monster has UIDs...
[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(PType: Word; PID: LongWord; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
172 procedure MH_SEND_PanelState(PType: Word; PID: LongWord; 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) + '.', MSG_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 var
644 I: Integer;
645 begin
646 if gPlayers <> nil then
647 begin
648 for I := Low(gPlayers) to High(gPlayers) do
649 begin
650 if gPlayers[I] <> nil then
651 begin
652 if CreatePlayers then MH_SEND_PlayerCreate(gPlayers[I].UID, ID);
653 MH_SEND_PlayerPos(True, gPlayers[I].UID, ID);
654 MH_SEND_PlayerStats(gPlayers[I].UID, ID);
656 if (gPlayers[I].Flag <> FLAG_NONE) and (gGameSettings.GameMode = GM_CTF) then
657 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED, gPlayers[I].Flag, gPlayers[I].UID, True, ID);
658 end;
659 end;
660 end;
662 g_Items_ForEachAlive(sendItemRespawn, true); // backwards
663 g_Mons_ForEach(sendMonSpawn);
665 if gWalls <> nil then
666 for I := Low(gWalls) to High(gWalls) do
667 if gWalls[I] <> nil then
668 with gWalls[I] do
669 begin
670 if Door then
671 MH_SEND_PanelState(PanelType, I, ID);
673 if GetTextureCount > 1 then
674 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
675 end;
677 if gLifts <> nil then
678 for I := Low(gLifts) to High(gLifts) do
679 if gLifts[I] <> nil then
680 with gLifts[I] do
681 MH_SEND_PanelState(PanelType, I, ID);
683 if gRenderForegrounds <> nil then
684 for I := Low(gRenderForegrounds) to High(gRenderForegrounds) do
685 if gRenderForegrounds[I] <> nil then
686 with gRenderForegrounds[I] do
687 begin
688 if (GetTextureCount > 1) then
689 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
690 if Moved then
691 MH_SEND_PanelState(PanelType, I, ID);
692 end;
693 if gRenderBackgrounds <> nil then
694 for I := Low(gRenderBackgrounds) to High(gRenderBackgrounds) do
695 if gRenderBackgrounds[I] <> nil then
696 with gRenderBackgrounds[I] do
697 begin
698 if (GetTextureCount > 1) then
699 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
700 if Moved then
701 MH_SEND_PanelState(PanelType, I, ID);
702 end;
703 if gWater <> nil then
704 for I := Low(gWater) to High(gWater) do
705 if gWater[I] <> nil then
706 with gWater[I] do
707 if GetTextureCount > 1 then
708 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
709 if gAcid1 <> nil then
710 for I := Low(gAcid1) to High(gAcid1) do
711 if gAcid1[I] <> nil then
712 with gAcid1[I] do
713 if GetTextureCount > 1 then
714 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
715 if gAcid2 <> nil then
716 for I := Low(gAcid2) to High(gAcid2) do
717 if gAcid2[I] <> nil then
718 with gAcid2[I] do
719 if GetTextureCount > 1 then
720 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
721 if gSteps <> nil then
722 for I := Low(gSteps) to High(gSteps) do
723 if gSteps[I] <> nil then
724 with gSteps[I] do
725 if GetTextureCount > 1 then
726 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
728 if gTriggers <> nil then
729 for I := Low(gTriggers) to High(gTriggers) do
730 if gTriggers[I].TriggerType = TRIGGER_SOUND then
731 MH_SEND_TriggerSound(gTriggers[I], ID);
733 if Shots <> nil then
734 for I := Low(Shots) to High(Shots) do
735 if Shots[i].ShotType in [6, 7, 8] then
736 MH_SEND_CreateShot(i, ID);
738 MH_SEND_TriggerMusic(ID);
740 MH_SEND_GameStats(ID);
741 MH_SEND_CoopStats(ID);
743 if gGameSettings.GameMode = GM_CTF then
744 begin
745 if gFlags[FLAG_RED].State <> FLAG_STATE_CAPTURED then
746 MH_SEND_FlagEvent(gFlags[FLAG_RED].State, FLAG_RED, 0, True, ID);
747 if gFlags[FLAG_BLUE].State <> FLAG_STATE_CAPTURED then
748 MH_SEND_FlagEvent(gFlags[FLAG_BLUE].State, FLAG_BLUE, 0, True, ID);
749 end;
751 if CreatePlayers and (ID >= 0) then NetClients[ID].State := NET_STATE_GAME;
753 if gLMSRespawn > LMS_RESPAWN_NONE then
754 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000, 'N', ID);
755 end;
757 procedure MH_SEND_Info(ID: Byte);
758 var
759 Map: string;
760 begin
761 Map := g_ExtractFileName(gMapInfo.Map);
763 NetOut.Clear();
765 NetOut.Write(Byte(NET_MSG_INFO));
766 NetOut.Write(ID);
767 NetOut.Write(NetClients[ID].Player);
768 NetOut.Write(gGameSettings.WAD);
769 NetOut.Write(Map);
770 NetOut.Write(gWADHash);
771 NetOut.Write(gGameSettings.GameMode);
772 NetOut.Write(gGameSettings.GoalLimit);
773 NetOut.Write(gGameSettings.TimeLimit);
774 NetOut.Write(gGameSettings.MaxLives);
775 NetOut.Write(gGameSettings.Options);
776 NetOut.Write(gTime);
778 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
779 end;
781 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
782 var
783 Name: string;
784 i: Integer;
785 Team: Byte;
786 begin
787 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
788 Mode := NET_CHAT_PLAYER;
790 Team := 0;
791 if (Mode = NET_CHAT_TEAM) then
792 begin
793 for i := Low(gPlayers) to High(gPlayers) do
794 if (gPlayers[i] <> nil) and (gPlayers[i].FClientID >= 0) and
795 (gPlayers[i].Team = ID) then
796 begin
797 NetOut.Write(Byte(NET_MSG_CHAT));
798 NetOut.Write(Txt);
799 NetOut.Write(Mode);
800 g_Net_Host_Send(gPlayers[i].FClientID, True, NET_CHAN_CHAT);
801 end;
802 Team := ID;
803 ID := NET_EVERYONE;
804 end
805 else
806 begin
807 NetOut.Write(Byte(NET_MSG_CHAT));
808 NetOut.Write(Txt);
809 NetOut.Write(Mode);
810 g_Net_Host_Send(ID, True, NET_CHAN_CHAT);
811 end;
813 if Mode = NET_CHAT_SYSTEM then
814 Exit;
816 if ID = NET_EVERYONE then
817 begin
818 if Mode = NET_CHAT_PLAYER then
819 begin
820 g_Console_Add(Txt, True);
821 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), MSG_NOTIFY);
822 g_Sound_PlayEx('SOUND_GAME_RADIO');
823 end
824 else
825 if Mode = NET_CHAT_TEAM then
826 if gPlayer1 <> nil then
827 begin
828 if (gPlayer1.Team = TEAM_RED) and (Team = TEAM_RED) then
829 begin
830 g_Console_Add(#18'[Team] '#2 + Txt, True);
831 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), MSG_NOTIFY);
832 g_Sound_PlayEx('SOUND_GAME_RADIO');
833 end
834 else if (gPlayer1.Team = TEAM_BLUE) and (Team = TEAM_BLUE) then
835 begin
836 g_Console_Add(#20'[Team] '#2 + Txt, True);
837 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), MSG_NOTIFY);
838 g_Sound_PlayEx('SOUND_GAME_RADIO');
839 end;
840 end;
841 end
842 else
843 begin
844 Name := g_Net_ClientName_ByID(ID);
845 g_Console_Add('-> ' + Name + ': ' + Txt, True);
846 e_WriteLog('[Tell ' + Name + '] ' + b_Text_Unformat(Txt), MSG_NOTIFY);
847 g_Sound_PlayEx('SOUND_GAME_RADIO');
848 end;
849 end;
851 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
852 begin
853 NetOut.Write(Byte(NET_MSG_GFX));
854 NetOut.Write(Kind);
855 NetOut.Write(X);
856 NetOut.Write(Y);
857 NetOut.Write(Ang);
859 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
860 end;
862 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
863 begin
864 NetOut.Write(Byte(NET_MSG_SND));
865 NetOut.Write(Name);
866 if Pos then
867 begin
868 NetOut.Write(Byte(1));
869 NetOut.Write(X);
870 NetOut.Write(Y);
871 end
872 else
873 NetOut.Write(Byte(0));
875 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
876 end;
878 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
879 begin
880 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
882 NetOut.Write(Byte(NET_MSG_SHADD));
883 NetOut.Write(Proj);
884 NetOut.Write(Shots[Proj].ShotType);
885 NetOut.Write(Shots[Proj].Target);
886 NetOut.Write(Shots[Proj].SpawnerUID);
887 NetOut.Write(Shots[Proj].Timeout);
888 NetOut.Write(Shots[Proj].Obj.X);
889 NetOut.Write(Shots[Proj].Obj.Y);
890 NetOut.Write(Shots[Proj].Obj.Vel.X);
891 NetOut.Write(Shots[Proj].Obj.Vel.Y);
893 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
894 end;
896 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
897 begin
898 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
900 NetOut.Write(Byte(NET_MSG_SHPOS));
901 NetOut.Write(Proj);
902 NetOut.Write(Shots[Proj].Obj.X);
903 NetOut.Write(Shots[Proj].Obj.Y);
904 NetOut.Write(Shots[Proj].Obj.Vel.X);
905 NetOut.Write(Shots[Proj].Obj.Vel.Y);
907 g_Net_Host_Send(ID, False, NET_CHAN_SHOTS);
908 end;
910 procedure MH_Send_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
911 begin
912 NetOut.Write(Byte(NET_MSG_SHDEL));
913 NetOut.Write(Proj);
914 NetOut.Write(Byte(Loud));
915 NetOut.Write(X);
916 NetOut.Write(Y);
918 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
919 end;
921 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
922 begin
923 NetOut.Write(Byte(NET_MSG_SCORE));
924 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
925 begin
926 NetOut.Write(gTeamStat[TEAM_RED].Goals);
927 NetOut.Write(gTeamStat[TEAM_BLUE].Goals);
928 end
929 else
930 if gGameSettings.GameMode = GM_COOP then
931 begin
932 NetOut.Write(gCoopMonstersKilled);
933 NetOut.Write(gCoopSecretsFound);
934 end;
936 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
937 end;
939 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
940 begin
941 NetOut.Write(Byte(NET_MSG_COOP));
942 NetOut.Write(gTotalMonsters);
943 NetOut.Write(gSecretsCount);
944 NetOut.Write(gCoopTotalMonstersKilled);
945 NetOut.Write(gCoopTotalSecretsFound);
946 NetOut.Write(gCoopTotalMonsters);
947 NetOut.Write(gCoopTotalSecrets);
948 end;
950 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
951 begin
952 NetOut.Write(Byte(NET_MSG_GEVENT));
953 NetOut.Write(EvType);
954 NetOut.Write(EvNum);
955 NetOut.Write(EvStr);
956 NetOut.Write(Byte(gLastMap));
957 NetOut.Write(gTime);
958 if (EvType = NET_EV_MAPSTART) and (Pos(':\', EvStr) > 0) then
959 begin
960 NetOut.Write(Byte(1));
961 NetOut.Write(gWADHash);
962 end else
963 NetOut.Write(Byte(0));
965 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
966 end;
968 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
969 begin
970 NetOut.Write(Byte(NET_MSG_FLAG));
971 NetOut.Write(EvType);
972 NetOut.Write(Flag);
973 NetOut.Write(Byte(Quiet));
974 NetOut.Write(PID);
975 NetOut.Write(gFlags[Flag].State);
976 NetOut.Write(gFlags[Flag].CaptureTime);
977 NetOut.Write(gFlags[Flag].Obj.X);
978 NetOut.Write(gFlags[Flag].Obj.Y);
979 NetOut.Write(gFlags[Flag].Obj.Vel.X);
980 NetOut.Write(gFlags[Flag].Obj.Vel.Y);
982 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
983 end;
985 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
986 begin
987 NetOut.Write(Byte(NET_MSG_GSET));
988 NetOut.Write(gGameSettings.GameMode);
989 NetOut.Write(gGameSettings.GoalLimit);
990 NetOut.Write(gGameSettings.TimeLimit);
991 NetOut.Write(gGameSettings.MaxLives);
992 NetOut.Write(gGameSettings.Options);
994 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
995 end;
997 // PLAYER (SEND)
999 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
1000 var
1001 P: TPlayer;
1002 begin
1003 P := g_Player_Get(PID);
1004 if P = nil then Exit;
1006 NetOut.Write(Byte(NET_MSG_PLR));
1007 NetOut.Write(PID);
1008 NetOut.Write(P.Name);
1010 NetOut.Write(P.FActualModelName);
1011 NetOut.Write(P.FColor.R);
1012 NetOut.Write(P.FColor.G);
1013 NetOut.Write(P.FColor.B);
1014 NetOut.Write(P.Team);
1016 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT)
1017 end;
1019 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
1020 var
1021 kByte: Word;
1022 Pl: TPlayer;
1023 begin
1024 Pl := g_Player_Get(PID);
1025 if Pl = nil then Exit;
1026 if Pl.FDummy then Exit;
1028 NetOut.Write(Byte(NET_MSG_PLRPOS));
1029 NetOut.Write(gTime);
1030 NetOut.Write(PID);
1032 kByte := 0;
1034 with Pl do
1035 begin
1036 NetOut.Write(FPing);
1037 NetOut.Write(FLoss);
1038 if IsKeyPressed(KEY_CHAT) then
1039 kByte := NET_KEY_CHAT
1040 else
1041 begin
1042 if IsKeyPressed(KEY_LEFT) then kByte := kByte or NET_KEY_LEFT;
1043 if IsKeyPressed(KEY_RIGHT) then kByte := kByte or NET_KEY_RIGHT;
1044 if IsKeyPressed(KEY_UP) then kByte := kByte or NET_KEY_UP;
1045 if IsKeyPressed(KEY_DOWN) then kByte := kByte or NET_KEY_DOWN;
1046 if IsKeyPressed(KEY_JUMP) then kByte := kByte or NET_KEY_JUMP;
1047 if JustTeleported then kByte := kByte or NET_KEY_FORCEDIR;
1048 end;
1050 NetOut.Write(kByte);
1051 if Direction = D_LEFT then NetOut.Write(Byte(0)) else NetOut.Write(Byte(1));
1052 NetOut.Write(GameX);
1053 NetOut.Write(GameY);
1054 NetOut.Write(GameVelX);
1055 NetOut.Write(GameVelY);
1056 NetOut.Write(GameAccelX);
1057 NetOut.Write(GameAccelY);
1058 end;
1060 g_Net_Host_Send(ID, Reliable, NET_CHAN_PLAYERPOS);
1061 end;
1063 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
1064 var
1065 P: TPlayer;
1066 I: Integer;
1067 begin
1068 P := g_Player_Get(PID);
1069 if P = nil then Exit;
1071 NetOut.Write(Byte(NET_MSG_PLRSTA));
1072 NetOut.Write(PID);
1074 with P do
1075 begin
1076 NetOut.Write(Byte(Live));
1077 NetOut.Write(Byte(GodMode));
1078 NetOut.Write(Health);
1079 NetOut.Write(Armor);
1080 NetOut.Write(Air);
1081 NetOut.Write(JetFuel);
1082 NetOut.Write(Lives);
1083 NetOut.Write(Team);
1085 for I := WP_FIRST to WP_LAST do
1086 NetOut.Write(Byte(FWeapon[I]));
1088 for I := A_BULLETS to A_HIGH do
1089 NetOut.Write(FAmmo[I]);
1091 for I := A_BULLETS to A_HIGH do
1092 NetOut.Write(FMaxAmmo[I]);
1094 for I := MR_SUIT to MR_MAX do
1095 NetOut.Write(LongWord(FMegaRulez[I]));
1097 NetOut.Write(Byte(R_ITEM_BACKPACK in FRulez));
1098 NetOut.Write(Byte(R_KEY_RED in FRulez));
1099 NetOut.Write(Byte(R_KEY_GREEN in FRulez));
1100 NetOut.Write(Byte(R_KEY_BLUE in FRulez));
1101 NetOut.Write(Byte(R_BERSERK in FRulez));
1103 NetOut.Write(Frags);
1104 NetOut.Write(Death);
1106 NetOut.Write(CurrWeap);
1108 NetOut.Write(Byte(FSpectator));
1109 NetOut.Write(Byte(FGhost));
1110 NetOut.Write(Byte(FPhysics));
1111 NetOut.Write(Byte(FNoRespawn));
1112 NetOut.Write(Byte(FJetpack));
1113 NetOut.Write(FFireTime);
1114 end;
1116 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1117 end;
1119 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
1120 begin
1121 NetOut.Write(Byte(NET_MSG_PLRDMG));
1122 NetOut.Write(PID);
1123 NetOut.Write(Kind);
1124 NetOut.Write(Attacker);
1125 NetOut.Write(Value);
1126 NetOut.Write(VX);
1127 NetOut.Write(VY);
1129 g_Net_Host_Send(ID, False, NET_CHAN_PLAYER);
1130 end;
1132 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
1133 begin
1134 NetOut.Write(Byte(NET_MSG_PLRDIE));
1135 NetOut.Write(PID);
1136 NetOut.Write(KillType);
1137 NetOut.Write(DeathType);
1138 NetOut.Write(Attacker);
1140 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1141 end;
1143 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
1144 begin
1145 NetOut.Write(Byte(NET_MSG_PLRFIRE));
1146 NetOut.Write(PID);
1147 NetOut.Write(Weapon);
1148 NetOut.Write(X);
1149 NetOut.Write(Y);
1150 NetOut.Write(AX);
1151 NetOut.Write(AY);
1152 NetOut.Write(ShotID);
1154 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1155 end;
1157 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
1158 begin
1159 NetOut.Write(Byte(NET_MSG_PLRDEL));
1160 NetOut.Write(PID);
1162 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1163 end;
1165 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
1166 var
1167 Pl: TPlayer;
1168 begin
1169 Pl := g_Player_Get(PID);
1170 if Pl = nil then Exit;
1172 NetOut.Write(Byte(NET_MSG_PLRSET));
1173 NetOut.Write(PID);
1174 NetOut.Write(Pl.Name);
1175 if Mdl = '' then
1176 NetOut.Write(Pl.Model.Name)
1177 else
1178 NetOut.Write(Mdl);
1179 NetOut.Write(Pl.FColor.R);
1180 NetOut.Write(Pl.FColor.G);
1181 NetOut.Write(Pl.FColor.B);
1182 NetOut.Write(Pl.Team);
1184 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1185 end;
1187 // ITEM (SEND)
1189 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1190 var
1191 it: PItem;
1192 begin
1193 it := g_Items_ByIdx(IID);
1195 NetOut.Write(Byte(NET_MSG_ISPAWN));
1196 NetOut.Write(IID);
1197 NetOut.Write(Byte(Quiet));
1198 NetOut.Write(it.ItemType);
1199 NetOut.Write(Byte(it.Fall));
1200 NetOut.Write(Byte(it.Respawnable));
1201 NetOut.Write(it.Obj.X);
1202 NetOut.Write(it.Obj.Y);
1203 NetOut.Write(it.Obj.Vel.X);
1204 NetOut.Write(it.Obj.Vel.Y);
1206 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1207 end;
1209 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1210 begin
1211 NetOut.Write(Byte(NET_MSG_IDEL));
1212 NetOut.Write(IID);
1213 NetOut.Write(Byte(Quiet));
1215 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1216 end;
1218 // PANEL
1220 procedure MH_SEND_PanelTexture(PType: Word; PID: LongWord; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
1221 var
1222 TP: TPanel;
1223 begin
1224 case PType of
1225 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
1226 TP := gWalls[PID];
1227 PANEL_FORE:
1228 TP := gRenderForegrounds[PID];
1229 PANEL_BACK:
1230 TP := gRenderBackgrounds[PID];
1231 PANEL_WATER:
1232 TP := gWater[PID];
1233 PANEL_ACID1:
1234 TP := gAcid1[PID];
1235 PANEL_ACID2:
1236 TP := gAcid2[PID];
1237 PANEL_STEP:
1238 TP := gSteps[PID];
1239 else
1240 Exit;
1241 end;
1243 with TP do
1244 begin
1245 NetOut.Write(Byte(NET_MSG_PTEX));
1246 NetOut.Write(PType);
1247 NetOut.Write(PID);
1248 NetOut.Write(FCurTexture);
1249 NetOut.Write(FCurFrame);
1250 NetOut.Write(FCurFrameCount);
1251 NetOut.Write(AnimLoop);
1252 end;
1254 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1255 end;
1257 procedure MH_SEND_PanelState(PType: Word; PID: LongWord; ID: Integer = NET_EVERYONE);
1258 var
1259 TP: TPanel;
1260 begin
1261 case PType of
1262 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
1263 TP := gWalls[PID];
1264 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT:
1265 TP := gLifts[PID];
1266 PANEL_BACK:
1267 begin
1268 TP := gRenderBackgrounds[PID];
1269 TP.Moved := True;
1270 end;
1271 PANEL_FORE:
1272 begin
1273 TP := gRenderForegrounds[PID];
1274 TP.Moved := True;
1275 end;
1276 else
1277 Exit;
1278 end;
1280 NetOut.Write(Byte(NET_MSG_PSTATE));
1281 NetOut.Write(PType);
1282 NetOut.Write(PID);
1283 NetOut.Write(Byte(TP.Enabled));
1284 NetOut.Write(TP.LiftType);
1285 NetOut.Write(TP.X);
1286 NetOut.Write(TP.Y);
1288 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1289 end;
1291 // TRIGGER
1293 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
1294 begin
1295 if gTriggers = nil then Exit;
1296 if T.Sound = nil then Exit;
1298 NetOut.Write(Byte(NET_MSG_TSOUND));
1299 NetOut.Write(T.ClientID);
1300 NetOut.Write(Byte(T.Sound.IsPlaying));
1301 NetOut.Write(LongWord(T.Sound.GetPosition));
1302 NetOut.Write(T.SoundPlayCount);
1304 g_Net_Host_Send(ID, True);
1305 end;
1307 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
1308 begin
1309 NetOut.Write(Byte(NET_MSG_TMUSIC));
1310 NetOut.Write(gMusic.Name);
1311 NetOut.Write(Byte(gMusic.IsPlaying));
1312 NetOut.Write(LongWord(gMusic.GetPosition));
1313 NetOut.Write(Byte(gMusic.SpecPause or gMusic.IsPaused));
1315 g_Net_Host_Send(ID, True);
1316 end;
1318 // MONSTER
1320 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
1321 var
1322 M: TMonster;
1323 begin
1324 M := g_Monsters_ByUID(UID);
1325 if M = nil then
1326 Exit;
1328 with M do
1329 begin
1330 NetOut.Write(Byte(NET_MSG_MSPAWN));
1331 NetOut.Write(UID);
1332 NetOut.Write(MonsterType);
1333 NetOut.Write(MonsterState);
1334 NetOut.Write(MonsterAnim);
1335 NetOut.Write(MonsterTargetUID);
1336 NetOut.Write(MonsterTargetTime);
1337 NetOut.Write(MonsterBehaviour);
1338 NetOut.Write(MonsterSleep);
1339 NetOut.Write(MonsterHealth);
1340 NetOut.Write(MonsterAmmo);
1341 NetOut.Write(GameX);
1342 NetOut.Write(GameY);
1343 NetOut.Write(GameVelX);
1344 NetOut.Write(GameVelY);
1345 NetOut.Write(Byte(GameDirection));
1346 end;
1348 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1349 end;
1351 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
1352 var
1353 M: TMonster;
1354 begin
1355 M := g_Monsters_ByUID(UID);
1356 if M = nil then Exit;
1358 NetOut.Write(Byte(NET_MSG_MPOS));
1359 NetOut.Write(UID);
1361 with M do
1362 begin
1363 NetOut.Write(GameX);
1364 NetOut.Write(GameY);
1365 NetOut.Write(GameVelX);
1366 NetOut.Write(GameVelY);
1367 NetOut.Write(Byte(GameDirection));
1368 end;
1370 g_Net_Host_Send(ID, False, NET_CHAN_MONSTERPOS);
1371 end;
1373 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
1374 var
1375 M: TMonster;
1376 begin
1377 M := g_Monsters_ByUID(UID);
1378 if M = nil then Exit;
1380 NetOut.Write(Byte(NET_MSG_MSTATE));
1381 NetOut.Write(UID);
1383 with M do
1384 begin
1385 NetOut.Write(MonsterState);
1386 NetOut.Write(ForcedAnim);
1387 NetOut.Write(MonsterTargetUID);
1388 NetOut.Write(MonsterTargetTime);
1389 NetOut.Write(MonsterSleep);
1390 NetOut.Write(MonsterHealth);
1391 NetOut.Write(MonsterAmmo);
1392 NetOut.Write(MonsterPain);
1393 NetOut.Write(Byte(AnimIsReverse));
1394 NetOut.Write(FFireTime);
1395 end;
1397 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1398 end;
1400 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
1401 begin
1402 NetOut.Write(Byte(NET_MSG_MSHOT));
1403 NetOut.Write(UID);
1404 NetOut.Write(X);
1405 NetOut.Write(Y);
1406 NetOut.Write(VX);
1407 NetOut.Write(VY);
1409 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1410 end;
1412 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
1413 var
1414 M: TMonster;
1415 begin
1416 M := g_Monsters_ByUID(UID);
1417 if M = nil then Exit;
1419 NetOut.Write(Byte(NET_MSG_MDEL));
1420 NetOut.Write(UID);
1422 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1423 end;
1425 // MISC
1427 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
1428 begin
1429 NetOut.Write(Byte(NET_MSG_TIME_SYNC));
1430 NetOut.Write(Time);
1432 g_Net_Host_Send(ID, False, NET_CHAN_SERVICE);
1433 end;
1435 procedure MH_SEND_VoteEvent(EvType: Byte;
1436 StrArg1: string = 'a'; StrArg2: string = 'b';
1437 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
1438 ID: Integer = NET_EVERYONE);
1439 begin
1440 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
1441 NetOut.Write(EvType);
1442 NetOut.Write(IntArg1);
1443 NetOut.Write(IntArg2);
1444 NetOut.Write(StrArg1);
1445 NetOut.Write(StrArg2);
1447 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1448 end;
1450 // CLIENT MESSAGES //
1452 // GAME
1454 procedure MC_RECV_Chat(var M: TMsg);
1455 var
1456 Txt: string;
1457 Mode: Byte;
1458 begin
1459 Txt := M.ReadString();
1460 Mode := M.ReadByte();
1462 if Mode <> NET_CHAT_SYSTEM then
1463 begin
1464 if Mode = NET_CHAT_PLAYER then
1465 begin
1466 g_Console_Add(Txt, True);
1467 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), MSG_NOTIFY);
1468 g_Sound_PlayEx('SOUND_GAME_RADIO');
1469 end else
1470 if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then
1471 begin
1472 if gPlayer1.Team = TEAM_RED then
1473 g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True);
1474 if gPlayer1.Team = TEAM_BLUE then
1475 g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True);
1476 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), MSG_NOTIFY);
1477 g_Sound_PlayEx('SOUND_GAME_RADIO');
1478 end;
1479 end else
1480 g_Console_Add(Txt, True);
1481 end;
1483 procedure MC_RECV_Effect(var M: TMsg);
1484 var
1485 Kind: Byte;
1486 X, Y: Integer;
1487 Ang: SmallInt;
1488 Anim: TAnimation;
1489 ID: LongWord;
1490 begin
1491 if not gGameOn then Exit;
1492 Kind := M.ReadByte();
1493 X := M.ReadLongInt();
1494 Y := M.ReadLongInt();
1495 Ang := M.ReadSmallInt();
1497 case Kind of
1498 NET_GFX_SPARK:
1499 g_GFX_Spark(X, Y, 2 + Random(2), Ang, 0, 0);
1501 NET_GFX_TELE:
1502 begin
1503 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
1504 begin
1505 Anim := TAnimation.Create(ID, False, 3);
1506 g_GFX_OnceAnim(X, Y, Anim);
1507 Anim.Free();
1508 end;
1509 if Ang = 1 then
1510 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
1511 end;
1513 NET_GFX_EXPLODE:
1514 begin
1515 if g_Frames_Get(ID, 'FRAMES_EXPLODE_ROCKET') then
1516 begin
1517 Anim := TAnimation.Create(ID, False, 6);
1518 Anim.Blending := False;
1519 g_GFX_OnceAnim(X-64, Y-64, Anim);
1520 Anim.Free();
1521 end;
1522 if Ang = 1 then
1523 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X, Y);
1524 end;
1526 NET_GFX_BFGEXPL:
1527 begin
1528 if g_Frames_Get(ID, 'FRAMES_EXPLODE_BFG') then
1529 begin
1530 Anim := TAnimation.Create(ID, False, 6);
1531 Anim.Blending := False;
1532 g_GFX_OnceAnim(X-64, Y-64, Anim);
1533 Anim.Free();
1534 end;
1535 if Ang = 1 then
1536 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X, Y);
1537 end;
1539 NET_GFX_BFGHIT:
1540 begin
1541 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1542 begin
1543 Anim := TAnimation.Create(ID, False, 4);
1544 g_GFX_OnceAnim(X-32, Y-32, Anim);
1545 Anim.Free();
1546 end;
1547 end;
1549 NET_GFX_FIRE:
1550 begin
1551 if g_Frames_Get(ID, 'FRAMES_FIRE') then
1552 begin
1553 Anim := TAnimation.Create(ID, False, 4);
1554 g_GFX_OnceAnim(X, Y, Anim);
1555 Anim.Free();
1556 end;
1557 if Ang = 1 then
1558 g_Sound_PlayExAt('SOUND_FIRE', X, Y);
1559 end;
1561 NET_GFX_RESPAWN:
1562 begin
1563 if g_Frames_Get(ID, 'FRAMES_ITEM_RESPAWN') then
1564 begin
1565 Anim := TAnimation.Create(ID, False, 4);
1566 g_GFX_OnceAnim(X, Y, Anim);
1567 Anim.Free();
1568 end;
1569 if Ang = 1 then
1570 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
1571 end;
1573 NET_GFX_SHELL1:
1574 g_Player_CreateShell(X, Y, 0, -2, SHELL_BULLET);
1576 NET_GFX_SHELL2:
1577 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1579 NET_GFX_SHELL3:
1580 begin
1581 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1582 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1583 end;
1584 end;
1585 end;
1587 procedure MC_RECV_Sound(var M: TMsg);
1588 var
1589 Name: string;
1590 X, Y: Integer;
1591 Pos: Boolean;
1592 begin
1593 Name := M.ReadString();
1594 Pos := M.ReadByte() <> 0;
1595 if Pos then
1596 begin
1597 X := M.ReadLongInt();
1598 Y := M.ReadLongInt();
1599 g_Sound_PlayExAt(Name, X, Y);
1600 end
1601 else
1602 g_Sound_PlayEx(Name);
1603 end;
1605 procedure MC_RECV_CreateShot(var M: TMsg);
1606 var
1607 I, X, Y, XV, YV: Integer;
1608 Timeout: LongWord;
1609 Target, Spawner: Word;
1610 ShType: Byte;
1611 begin
1612 I := M.ReadLongInt();
1613 ShType := M.ReadByte();
1614 Target := M.ReadWord();
1615 Spawner := M.ReadWord();
1616 Timeout := M.ReadLongWord();
1617 X := M.ReadLongInt();
1618 Y := M.ReadLongInt();
1619 XV := M.ReadLongInt();
1620 YV := M.ReadLongInt();
1622 I := g_Weapon_CreateShot(I, ShType, Spawner, Target, X, Y, XV, YV);
1623 if (Shots <> nil) and (I <= High(Shots)) then
1624 begin
1625 Shots[I].Timeout := Timeout;
1626 //Shots[I].Target := Target; // TODO: find a use for Target later
1627 end;
1628 end;
1630 procedure MC_RECV_UpdateShot(var M: TMsg);
1631 var
1632 I, TX, TY, TXV, TYV: Integer;
1633 begin
1634 I := M.ReadLongInt();
1635 TX := M.ReadLongInt();
1636 TY := M.ReadLongInt();
1637 TXV := M.ReadLongInt();
1638 TYV := M.ReadLongInt();
1640 if (Shots <> nil) and (I <= High(Shots)) then
1641 with (Shots[i]) do
1642 begin
1643 Obj.X := TX;
1644 Obj.Y := TY;
1645 Obj.Vel.X := TXV;
1646 Obj.Vel.Y := TYV;
1647 end;
1648 end;
1650 procedure MC_RECV_DeleteShot(var M: TMsg);
1651 var
1652 I, X, Y: Integer;
1653 L: Boolean;
1654 begin
1655 if not gGameOn then Exit;
1656 I := M.ReadLongInt();
1657 L := (M.ReadByte() <> 0);
1658 X := M.ReadLongInt();
1659 Y := M.ReadLongInt();
1661 g_Weapon_DestroyShot(I, X, Y, L);
1662 end;
1664 procedure MC_RECV_GameStats(var M: TMsg);
1665 begin
1666 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1667 begin
1668 gTeamStat[TEAM_RED].Goals := M.ReadSmallInt();
1669 gTeamStat[TEAM_BLUE].Goals := M.ReadSmallInt();
1670 end
1671 else
1672 if gGameSettings.GameMode = GM_COOP then
1673 begin
1674 gCoopMonstersKilled := M.ReadWord();
1675 gCoopSecretsFound := M.ReadWord();
1676 end;
1677 end;
1679 procedure MC_RECV_CoopStats(var M: TMsg);
1680 begin
1681 gTotalMonsters := M.ReadLongInt();
1682 gSecretsCount := M.ReadLongInt();
1683 gCoopTotalMonstersKilled := M.ReadWord();
1684 gCoopTotalSecretsFound := M.ReadWord();
1685 gCoopTotalMonsters := M.ReadWord();
1686 gCoopTotalSecrets := M.ReadWord();
1687 end;
1689 procedure MC_RECV_GameEvent(var M: TMsg);
1690 var
1691 EvType: Byte;
1692 EvNum: Integer;
1693 EvStr: string;
1694 EvTime: LongWord;
1695 BHash: Boolean;
1696 EvHash: TMD5Digest;
1697 pl: TPlayer;
1698 i1, i2: TStrings_Locale;
1699 pln: String;
1700 cnt: Byte;
1701 begin
1702 FillChar(EvHash, Sizeof(EvHash), 0);
1703 EvType := M.ReadByte();
1704 EvNum := M.ReadLongInt();
1705 EvStr := M.ReadString();
1706 gLastMap := M.ReadByte() <> 0;
1707 if gLastMap and (gGameSettings.GameMode = GM_COOP) then gStatsOff := True;
1708 gStatsPressed := True;
1709 EvTime := M.ReadLongWord();
1710 BHash := M.ReadByte() <> 0;
1711 if BHash then
1712 EvHash := M.ReadMD5();
1714 gTime := EvTime;
1716 case EvType of
1717 NET_EV_MAPSTART:
1718 begin
1719 gGameOn := False;
1720 g_Game_ClearLoading();
1721 g_Game_StopAllSounds(True);
1723 gSwitchGameMode := Byte(EvNum);
1724 gGameSettings.GameMode := gSwitchGameMode;
1726 gWADHash := EvHash;
1727 if not g_Game_StartMap(EvStr, True) then
1728 begin
1729 if Pos(':\', EvStr) = 0 then
1730 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + EvStr]))
1731 else
1732 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [EvStr]));
1733 Exit;
1734 end;
1736 MC_SEND_FullStateRequest;
1737 end;
1739 NET_EV_MAPEND:
1740 begin
1741 gMissionFailed := EvNum <> 0;
1742 gExit := EXIT_ENDLEVELCUSTOM;
1743 end;
1745 NET_EV_RCON:
1746 begin
1747 case EvNum of
1748 NET_RCON_NOAUTH:
1749 g_Console_Add(_lc[I_NET_RCON_NOAUTH], True);
1750 NET_RCON_PWGOOD:
1751 g_Console_Add(_lc[I_NET_RCON_PWD_VALID], True);
1752 NET_RCON_PWBAD:
1753 g_Console_Add(_lc[I_NET_RCON_PWD_INVALID], True);
1754 end;
1755 end;
1757 NET_EV_CHANGE_TEAM:
1758 begin
1759 if EvNum = TEAM_RED then
1760 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True);
1761 if EvNum = TEAM_BLUE then
1762 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True);
1763 end;
1765 NET_EV_PLAYER_KICK:
1766 g_Console_Add(Format(_lc[I_PLAYER_KICK], [EvStr]), True);
1768 NET_EV_PLAYER_BAN:
1769 g_Console_Add(Format(_lc[I_PLAYER_BAN], [EvStr]), True);
1771 NET_EV_LMS_WARMUP:
1772 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [EvNum]), True);
1774 NET_EV_LMS_SURVIVOR:
1775 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True);
1777 NET_EV_BIGTEXT:
1778 g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum));
1780 NET_EV_SCORE:
1781 begin
1782 pl := g_Player_Get(EvNum and $FFFF);
1783 if pl = nil then
1784 pln := '?'
1785 else
1786 pln := pl.Name;
1787 cnt := (EvNum shr 16) and $FF;
1788 if Pos('w', EvStr) = 0 then
1789 begin
1790 // Default score
1791 if Pos('t', EvStr) = 0 then
1792 begin
1793 // Player +/- score
1794 if Pos('-', EvStr) = 0 then
1795 begin
1796 if Pos('e', EvStr) = 0 then
1797 i1 := I_PLAYER_SCORE_ADD_OWN
1798 else
1799 i1 := I_PLAYER_SCORE_ADD_ENEMY;
1800 end else
1801 begin
1802 if Pos('e', EvStr) = 0 then
1803 i1 := I_PLAYER_SCORE_SUB_OWN
1804 else
1805 i1 := I_PLAYER_SCORE_SUB_ENEMY;
1806 end;
1807 // Which team
1808 if Pos('r', EvStr) > 0 then
1809 i2 := I_PLAYER_SCORE_TO_RED
1810 else
1811 i2 := I_PLAYER_SCORE_TO_BLUE;
1812 g_Console_Add(Format(_lc[i1], [pln, cnt, _lc[i2]]), True);
1813 end else
1814 begin
1815 // Team +/- score
1816 if Pos('-', EvStr) = 0 then
1817 i1 := I_PLAYER_SCORE_ADD_TEAM
1818 else
1819 i1 := I_PLAYER_SCORE_SUB_TEAM;
1820 // Which team
1821 if Pos('r', EvStr) > 0 then
1822 i2 := I_PLAYER_SCORE_RED
1823 else
1824 i2 := I_PLAYER_SCORE_BLUE;
1825 g_Console_Add(Format(_lc[i1], [_lc[i2], cnt]), True);
1826 end;
1827 end else
1828 begin
1829 // Game Win
1830 if Pos('e', EvStr) = 0 then
1831 i1 := I_PLAYER_SCORE_WIN_OWN
1832 else
1833 i1 := I_PLAYER_SCORE_WIN_ENEMY;
1834 // Which team
1835 if Pos('r', EvStr) > 0 then
1836 i2 := I_PLAYER_SCORE_TO_RED
1837 else
1838 i2 := I_PLAYER_SCORE_TO_BLUE;
1839 g_Console_Add(Format(_lc[i1], [pln, _lc[i2]]), True);
1840 end;
1841 end;
1843 NET_EV_SCORE_MSG:
1844 begin
1845 if EvNum = TEAM_RED then
1846 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1847 if EvNum = TEAM_BLUE then
1848 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1849 if EvNum = -TEAM_RED then
1850 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1851 if EvNum = -TEAM_BLUE then
1852 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1853 end;
1855 NET_EV_LMS_START:
1856 begin
1857 g_Player_RemoveAllCorpses;
1858 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
1859 end;
1861 NET_EV_LMS_WIN:
1862 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(EvStr)]), 144);
1864 NET_EV_TLMS_WIN:
1865 begin
1866 if EvNum = TEAM_RED then
1867 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
1868 if EvNum = TEAM_BLUE then
1869 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
1870 end;
1872 NET_EV_LMS_LOSE:
1873 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
1875 NET_EV_LMS_DRAW:
1876 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
1878 NET_EV_KILLCOMBO:
1879 g_Game_Announce_KillCombo(EvNum);
1881 NET_EV_PLAYER_TOUCH:
1882 begin
1883 pl := g_Player_Get(EvNum);
1884 if pl <> nil then
1885 pl.Touch();
1886 end;
1888 end;
1889 end;
1891 procedure MC_RECV_FlagEvent(var M: TMsg);
1892 var
1893 PID: Word;
1894 Pl: TPlayer;
1895 EvType: Byte;
1896 Fl: Byte;
1897 Quiet: Boolean;
1898 s, ts: string;
1899 begin
1900 EvType := M.ReadByte();
1901 Fl := M.ReadByte();
1903 if Fl = FLAG_NONE then Exit;
1905 Quiet := (M.ReadByte() <> 0);
1906 PID := M.ReadWord();
1908 gFlags[Fl].State := M.ReadByte();
1909 gFlags[Fl].CaptureTime := M.ReadLongWord();
1910 gFlags[Fl].Obj.X := M.ReadLongInt();
1911 gFlags[Fl].Obj.Y := M.ReadLongInt();
1912 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
1913 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
1915 Pl := g_Player_Get(PID);
1916 if (Pl = nil) and
1917 (EvType <> FLAG_STATE_NORMAL) and
1918 (EvType <> FLAG_STATE_DROPPED) and
1919 (EvType <> FLAG_STATE_RETURNED) then
1920 Exit;
1922 case EvType of
1923 FLAG_STATE_NORMAL:
1924 begin
1925 if Quiet or (Pl = nil) then Exit;
1927 if Fl = FLAG_RED then
1928 s := _lc[I_PLAYER_FLAG_RED]
1929 else
1930 s := _lc[I_PLAYER_FLAG_BLUE];
1932 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
1933 end;
1935 FLAG_STATE_CAPTURED:
1936 begin
1937 if (Pl <> nil) then Pl.SetFlag(Fl);
1939 if Quiet then Exit;
1941 if Fl = FLAG_RED then
1942 s := _lc[I_PLAYER_FLAG_RED]
1943 else
1944 s := _lc[I_PLAYER_FLAG_BLUE];
1946 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [Pl.Name, s]), True);
1947 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
1948 end;
1950 FLAG_STATE_DROPPED:
1951 begin
1952 if (Pl <> nil) then Pl.SetFlag(FLAG_NONE);
1954 if Quiet or (Pl = nil) then Exit;
1956 if Fl = FLAG_RED then
1957 s := _lc[I_PLAYER_FLAG_RED]
1958 else
1959 s := _lc[I_PLAYER_FLAG_BLUE];
1961 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [Pl.Name, s]), True);
1962 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
1963 end;
1965 FLAG_STATE_SCORED:
1966 begin
1967 g_Map_ResetFlag(FLAG_RED);
1968 g_Map_ResetFlag(FLAG_BLUE);
1969 if Quiet or (Pl = nil) then Exit;
1970 Pl.SetFlag(FLAG_NONE);
1972 if Fl = FLAG_RED then
1973 s := _lc[I_PLAYER_FLAG_RED]
1974 else
1975 s := _lc[I_PLAYER_FLAG_BLUE];
1977 ts := Format('%.4d', [gFlags[Fl].CaptureTime]);
1978 Insert('.', ts, Length(ts) + 1 - 3);
1979 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [Pl.Name, s, ts]), True);
1980 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
1981 end;
1983 FLAG_STATE_RETURNED:
1984 begin
1985 g_Map_ResetFlag(Fl);
1986 if Quiet then Exit;
1988 if Fl = FLAG_RED then
1989 s := _lc[I_PLAYER_FLAG_RED]
1990 else
1991 s := _lc[I_PLAYER_FLAG_BLUE];
1993 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
1994 end;
1995 end;
1996 end;
1998 procedure MC_RECV_GameSettings(var M: TMsg);
1999 begin
2000 gGameSettings.GameMode := M.ReadByte();
2001 gGameSettings.GoalLimit := M.ReadWord();
2002 gGameSettings.TimeLimit := M.ReadWord();
2003 gGameSettings.MaxLives := M.ReadByte();
2004 gGameSettings.Options := M.ReadLongWord();
2005 end;
2007 // PLAYER
2009 function MC_RECV_PlayerCreate(var M: TMsg): Word;
2010 var
2011 PID, DID: Word;
2012 PName, Model: string;
2013 Color: TRGB;
2014 T: Byte;
2015 Pl: TPlayer;
2016 begin
2017 PID := M.ReadWord();
2018 Pl := g_Player_Get(PID);
2020 PName := M.ReadString();
2021 Model := M.ReadString();
2022 Color.R := M.ReadByte();
2023 Color.G := M.ReadByte();
2024 Color.B := M.ReadByte();
2025 T := M.ReadByte();
2027 Result := 0;
2028 if (PID <> NetPlrUID1) and (PID <> NetPlrUID2) then
2029 begin
2030 if (Pl <> nil) then Exit;
2031 DID := g_Player_Create(Model, Color, T, False);
2032 with g_Player_Get(DID) do
2033 begin
2034 UID := PID;
2035 Name := PName;
2036 Reset(True);
2037 end;
2038 end
2039 else
2040 begin
2041 if (PID = NetPlrUID1) and (gPlayer1 <> nil) then begin
2042 gPlayer1.UID := PID;
2043 gPlayer1.Model.SetColor(Color.R, Color.G, Color.B);
2044 gPlayer1.ChangeTeam(T);
2045 end;
2046 if (PID = NetPlrUID2) and (gPlayer2 <> nil) then begin
2047 gPlayer2.UID := PID;
2048 gPlayer2.Model.SetColor(Color.R, Color.G, Color.B);
2049 gPlayer2.ChangeTeam(T);
2050 end;
2051 end;
2053 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
2054 e_WriteLog('NET: Player ' + PName + ' [' + IntToStr(PID) + '] added.', MSG_NOTIFY);
2055 Result := PID;
2056 end;
2058 function MC_RECV_PlayerPos(var M: TMsg): Word;
2059 var
2060 GT: LongWord;
2061 PID: Word;
2062 kByte: Word;
2063 Pl: TPlayer;
2064 Dir: Byte;
2065 TmpX, TmpY: Integer;
2066 begin
2067 Result := 0;
2069 GT := M.ReadLongWord();
2070 if GT < gTime - NET_MAX_DIFFTIME then
2071 begin
2072 gTime := GT;
2073 Exit;
2074 end;
2075 gTime := GT;
2077 PID := M.ReadWord();
2078 Pl := g_Player_Get(PID);
2080 if Pl = nil then Exit;
2082 Result := PID;
2084 with Pl do
2085 begin
2086 FPing := M.ReadWord();
2087 FLoss := M.ReadByte();
2088 kByte := M.ReadWord();
2089 Dir := M.ReadByte();
2091 TmpX := M.ReadLongInt();
2092 TmpY := M.ReadLongInt();
2094 ReleaseKeys;
2096 if (kByte = NET_KEY_CHAT) then
2097 PressKey(KEY_CHAT, 10000)
2098 else
2099 begin
2100 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
2101 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
2102 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
2103 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
2104 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
2105 end;
2107 if ((Pl <> gPlayer1) and (Pl <> gPlayer2)) or LongBool(kByte and NET_KEY_FORCEDIR) then
2108 SetDirection(TDirection(Dir));
2110 GameVelX := M.ReadLongInt();
2111 GameVelY := M.ReadLongInt();
2112 GameAccelX := M.ReadLongInt();
2113 GameAccelY := M.ReadLongInt();
2114 SetLerp(TmpX, TmpY);
2115 if NetForcePlayerUpdate then Update();
2116 end;
2117 end;
2119 function MC_RECV_PlayerStats(var M: TMsg): Word;
2120 var
2121 PID: Word;
2122 Pl: TPlayer;
2123 I: Integer;
2124 OldJet: Boolean;
2125 NewTeam: Byte;
2126 begin
2127 PID := M.ReadWord();
2128 Pl := g_Player_Get(PID);
2129 Result := 0;
2130 if Pl = nil then
2131 Exit;
2133 with Pl do
2134 begin
2135 Live := (M.ReadByte() <> 0);
2136 GodMode := (M.ReadByte() <> 0);
2137 Health := M.ReadLongInt();
2138 Armor := M.ReadLongInt();
2139 Air := M.ReadLongInt();
2140 JetFuel := M.ReadLongInt();
2141 Lives := M.ReadByte();
2142 NewTeam := M.ReadByte();
2144 for I := WP_FIRST to WP_LAST do
2145 FWeapon[I] := (M.ReadByte() <> 0);
2147 for I := A_BULLETS to A_HIGH do
2148 FAmmo[I] := M.ReadWord();
2150 for I := A_BULLETS to A_HIGH do
2151 FMaxAmmo[I] := M.ReadWord();
2153 for I := MR_SUIT to MR_MAX do
2154 FMegaRulez[I] := M.ReadLongWord();
2156 FRulez := [];
2157 if (M.ReadByte() <> 0) then
2158 FRulez := FRulez + [R_ITEM_BACKPACK];
2159 if (M.ReadByte() <> 0) then
2160 FRulez := FRulez + [R_KEY_RED];
2161 if (M.ReadByte() <> 0) then
2162 FRulez := FRulez + [R_KEY_GREEN];
2163 if (M.ReadByte() <> 0) then
2164 FRulez := FRulez + [R_KEY_BLUE];
2165 if (M.ReadByte() <> 0) then
2166 FRulez := FRulez + [R_BERSERK];
2168 Frags := M.ReadLongInt();
2169 Death := M.ReadLongInt();
2171 SetWeapon(M.ReadByte());
2173 FSpectator := M.ReadByte() <> 0;
2174 if FSpectator then
2175 begin
2176 if Pl = gPlayer1 then
2177 begin
2178 gLMSPID1 := UID;
2179 gPlayer1 := nil;
2180 end;
2181 if Pl = gPlayer2 then
2182 begin
2183 gLMSPID2 := UID;
2184 gPlayer2 := nil;
2185 end;
2186 end
2187 else
2188 begin
2189 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
2190 gPlayer1 := g_Player_Get(gLMSPID1);
2191 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
2192 gPlayer2 := g_Player_Get(gLMSPID2);
2193 end;
2194 FGhost := M.ReadByte() <> 0;
2195 FPhysics := M.ReadByte() <> 0;
2196 FNoRespawn := M.ReadByte() <> 0;
2197 OldJet := FJetpack;
2198 FJetpack := M.ReadByte() <> 0;
2199 FFireTime := M.ReadLongInt();
2200 if OldJet and not FJetpack then
2201 JetpackOff
2202 else if not OldJet and FJetpack then
2203 JetpackOn;
2204 if Team <> NewTeam then
2205 Pl.ChangeTeam(NewTeam);
2206 end;
2208 Result := PID;
2209 end;
2211 function MC_RECV_PlayerDamage(var M: TMsg): Word;
2212 var
2213 PID: Word;
2214 Pl: TPlayer;
2215 Kind: Byte;
2216 Attacker, Value: Word;
2217 VX, VY: Integer;
2218 begin
2219 Result := 0;
2220 if not gGameOn then Exit;
2221 PID := M.ReadWord();
2222 Pl := g_Player_Get(PID);
2223 if Pl = nil then Exit;
2225 Kind := M.ReadByte();
2226 Attacker := M.ReadWord();
2227 Value := M.ReadWord();
2228 VX := M.ReadWord();
2229 VY := M.ReadWord();
2231 with Pl do
2232 Damage(Value, Attacker, VX, VY, Kind);
2234 Result := PID;
2235 end;
2237 function MC_RECV_PlayerDeath(var M: TMsg): Word;
2238 var
2239 PID: Word;
2240 Pl: TPlayer;
2241 KillType, DeathType: Byte;
2242 Attacker: Word;
2243 begin
2244 Result := 0;
2245 if not gGameOn then Exit;
2246 PID := M.ReadWord();
2247 Pl := g_Player_Get(PID);
2248 if Pl = nil then Exit;
2250 KillType := M.ReadByte();
2251 DeathType := M.ReadByte();
2252 Attacker := M.ReadWord();
2254 with Pl do
2255 begin
2256 Kill(KillType, Attacker, DeathType);
2257 SoftReset;
2258 end;
2259 end;
2261 function MC_RECV_PlayerDelete(var M: TMsg): Word;
2262 var
2263 PID: Word;
2264 Pl: TPlayer;
2265 begin
2266 PID := M.ReadWord();
2267 Pl := g_Player_Get(PID);
2268 Result := 0;
2269 if Pl = nil then Exit;
2271 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2272 e_WriteLog('NET: Player ' + Pl.Name + ' [' + IntToStr(PID) + '] removed.', MSG_NOTIFY);
2274 g_Player_Remove(PID);
2276 Result := PID;
2277 end;
2279 function MC_RECV_PlayerFire(var M: TMsg): Word;
2280 var
2281 PID: Word;
2282 Weap: Byte;
2283 Pl: TPlayer;
2284 X, Y, AX, AY: Integer;
2285 SHID: Integer;
2286 begin
2287 Result := 0;
2288 if not gGameOn then Exit;
2289 PID := M.ReadWord();
2290 Pl := g_Player_Get(PID);
2291 if Pl = nil then Exit;
2293 Weap := M.ReadByte();
2294 X := M.ReadLongInt();
2295 Y := M.ReadLongInt();
2296 AX := M.ReadLongInt();
2297 AY := M.ReadLongInt();
2298 SHID := M.ReadLongInt();
2300 with Pl do
2301 if Live then NetFire(Weap, X, Y, AX, AY, SHID);
2302 end;
2304 procedure MC_RECV_PlayerSettings(var M: TMsg);
2305 var
2306 TmpName: string;
2307 TmpModel: string;
2308 TmpColor: TRGB;
2309 TmpTeam: Byte;
2310 Pl: TPlayer;
2311 PID: Word;
2312 begin
2313 PID := M.ReadWord();
2314 Pl := g_Player_Get(PID);
2315 if Pl = nil then Exit;
2317 TmpName := M.ReadString();
2318 TmpModel := M.ReadString();
2319 TmpColor.R := M.ReadByte();
2320 TmpColor.G := M.ReadByte();
2321 TmpColor.B := M.ReadByte();
2322 TmpTeam := M.ReadByte();
2324 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
2325 begin
2326 Pl.ChangeTeam(TmpTeam);
2327 if gPlayer1 = Pl then
2328 gPlayer1Settings.Team := TmpTeam;
2329 if gPlayer2 = Pl then
2330 gPlayer2Settings.Team := TmpTeam;
2331 end else
2332 Pl.SetColor(TmpColor);
2334 if Pl.Name <> TmpName then
2335 begin
2336 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
2337 Pl.Name := TmpName;
2338 end;
2340 if TmpModel <> Pl.Model.Name then
2341 Pl.SetModel(TmpModel);
2342 end;
2344 // ITEM
2346 procedure MC_RECV_ItemSpawn(var M: TMsg);
2347 var
2348 ID: Word;
2349 AID: DWord;
2350 X, Y, VX, VY: Integer;
2351 T: Byte;
2352 Quiet, Fall{, Resp}: Boolean;
2353 Anim: TAnimation;
2354 it: PItem;
2355 begin
2356 if not gGameOn then Exit;
2357 ID := M.ReadWord();
2358 Quiet := M.ReadByte() <> 0;
2359 T := M.ReadByte();
2360 Fall := M.ReadByte() <> 0;
2361 {Resp :=} M.ReadByte();
2362 X := M.ReadLongInt();
2363 Y := M.ReadLongInt();
2364 VX := M.ReadLongInt();
2365 VY := M.ReadLongInt();
2367 g_Items_Create(X, Y, T, Fall, False, False, 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 PType: Word;
2407 ID: LongWord;
2408 Tex, Fr: Integer;
2409 Loop, Cnt: Byte;
2410 begin
2411 if not gGameOn then Exit;
2412 PType := M.ReadWord();
2413 ID := M.ReadLongWord();
2414 Tex := M.ReadLongInt();
2415 Fr := M.ReadLongInt();
2416 Cnt := M.ReadByte();
2417 Loop := M.ReadByte();
2419 TP := nil;
2421 case PType of
2422 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
2423 if gWalls <> nil then
2424 TP := gWalls[ID];
2425 PANEL_FORE:
2426 if gRenderForegrounds <> nil then
2427 TP := gRenderForegrounds[ID];
2428 PANEL_BACK:
2429 if gRenderBackgrounds <> nil then
2430 TP := gRenderBackgrounds[ID];
2431 PANEL_WATER:
2432 if gWater <> nil then
2433 TP := gWater[ID];
2434 PANEL_ACID1:
2435 if gAcid1 <> nil then
2436 TP := gAcid1[ID];
2437 PANEL_ACID2:
2438 if gAcid2 <> nil then
2439 TP := gAcid2[ID];
2440 PANEL_STEP:
2441 if gSteps <> nil then
2442 TP := gSteps[ID];
2443 else
2444 Exit;
2445 end;
2447 if TP <> nil then
2448 if Loop = 0 then
2449 begin // switch texture
2450 TP.SetTexture(Tex, Loop);
2451 TP.SetFrame(Fr, Cnt);
2452 end else // looped or non-looped animation
2453 TP.NextTexture(Loop);
2454 end;
2456 procedure MC_RECV_PanelState(var M: TMsg);
2457 var
2458 ID: LongWord;
2459 E: Boolean;
2460 Lift: Byte;
2461 PType: Word;
2462 X, Y: Integer;
2463 begin
2464 if not gGameOn then Exit;
2465 PType := M.ReadWord();
2466 ID := M.ReadLongWord();
2467 E := (M.ReadByte() <> 0);
2468 Lift := M.ReadByte();
2469 X := M.ReadLongInt();
2470 Y := M.ReadLongInt();
2472 case PType of
2473 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
2474 if E then
2475 g_Map_EnableWall(ID)
2476 else
2477 g_Map_DisableWall(ID);
2479 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT:
2480 g_Map_SetLift(ID, Lift);
2482 PANEL_BACK:
2483 begin
2484 gRenderBackgrounds[ID].X := X;
2485 gRenderBackgrounds[ID].Y := Y;
2486 end;
2488 PANEL_FORE:
2489 begin
2490 gRenderForegrounds[ID].X := X;
2491 gRenderForegrounds[ID].Y := Y;
2492 end;
2493 end;
2494 end;
2496 // TRIGGERS
2498 procedure MC_RECV_TriggerSound(var M: TMsg);
2499 var
2500 SPlaying: Boolean;
2501 SPos, SID: LongWord;
2502 SCount: LongInt;
2503 I: Integer;
2504 begin
2505 if not gGameOn then Exit;
2506 if gTriggers = nil then Exit;
2508 SID := M.ReadLongWord();
2509 SPlaying := M.ReadByte() <> 0;
2510 SPos := M.ReadLongWord();
2511 SCount := M.ReadLongInt();
2513 for I := Low(gTriggers) to High(gTriggers) do
2514 if gTriggers[I].TriggerType = TRIGGER_SOUND then
2515 if gTriggers[I].ClientID = SID then
2516 with gTriggers[I] do
2517 begin
2518 if SPlaying then
2519 begin
2520 if Data.Local then
2521 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), Data.Volume/255.0)
2522 else
2523 Sound.PlayPanVolume((Data.Pan-127.0)/128.0, Data.Volume/255.0);
2524 Sound.SetPosition(SPos);
2525 end
2526 else
2527 if Sound.IsPlaying then Sound.Stop;
2529 SoundPlayCount := SCount;
2530 end;
2531 end;
2533 procedure MC_RECV_TriggerMusic(var M: TMsg);
2534 var
2535 MName: string;
2536 MPlaying: Boolean;
2537 MPos: LongWord;
2538 MPaused: Boolean;
2539 begin
2540 if not gGameOn then Exit;
2542 MName := M.ReadString();
2543 MPlaying := M.ReadByte() <> 0;
2544 MPos := M.ReadLongWord();
2545 MPaused := M.ReadByte() <> 0;
2547 if MPlaying then
2548 begin
2549 gMusic.SetByName(MName);
2550 gMusic.Play(True);
2551 gMusic.SetPosition(MPos);
2552 gMusic.SpecPause := MPaused;
2553 end
2554 else
2555 if gMusic.IsPlaying then gMusic.Stop;
2556 end;
2558 // MONSTERS
2560 procedure MC_RECV_MonsterSpawn(var M: TMsg);
2561 var
2562 ID: Word;
2563 MType, MState, MDir, MAnim, MBehav: Byte;
2564 X, Y, VX, VY, MTargTime, MHealth, MAmmo, MSleep: Integer;
2565 MTarg: Word;
2566 Mon: TMonster;
2567 begin
2568 ID := M.ReadWord();
2569 Mon := g_Monsters_ByUID(ID);
2570 if Mon <> nil then
2571 Exit;
2573 MType := M.ReadByte();
2574 MState := M.ReadByte();
2575 MAnim := M.ReadByte();
2576 MTarg := M.ReadWord();
2577 MTargTime := M.ReadLongInt();
2578 MBehav := M.ReadByte();
2579 MSleep := M.ReadLongInt();
2580 MHealth := M.ReadLongInt();
2581 MAmmo := M.ReadLongInt();
2583 X := M.ReadLongInt();
2584 Y := M.ReadLongInt();
2585 VX := M.ReadLongInt();
2586 VY := M.ReadLongInt();
2587 MDir := M.ReadByte();
2589 g_Monsters_Create(MType, X, Y, TDirection(MDir), False, ID);
2590 Mon := g_Monsters_ByUID(ID);
2591 if Mon = nil then
2592 Exit;
2594 with Mon do
2595 begin
2596 GameX := X;
2597 GameY := Y;
2598 GameVelX := VX;
2599 GameVelY := VY;
2601 MonsterAnim := MAnim;
2602 MonsterTargetUID := MTarg;
2603 MonsterTargetTime := MTargTime;
2604 MonsterBehaviour := MBehav;
2605 MonsterSleep := MSleep;
2606 MonsterAmmo := MAmmo;
2607 SetHealth(MHealth);
2609 SetState(MState);
2611 positionChanged(); // this updates spatial accelerators
2612 end;
2613 end;
2615 procedure MC_RECV_MonsterPos(var M: TMsg);
2616 var
2617 Mon: TMonster;
2618 ID: Word;
2619 begin
2620 ID := M.ReadWord();
2621 Mon := g_Monsters_ByUID(ID);
2622 if Mon = nil then
2623 Exit;
2625 with Mon do
2626 begin
2627 GameX := M.ReadLongInt();
2628 GameY := M.ReadLongInt();
2629 GameVelX := M.ReadLongInt();
2630 GameVelY := M.ReadLongInt();
2631 GameDirection := TDirection(M.ReadByte());
2632 positionChanged(); // this updates spatial accelerators
2633 end;
2634 end;
2636 procedure MC_RECV_MonsterState(var M: TMsg);
2637 var
2638 ID: Integer;
2639 MState, MFAnm: Byte;
2640 Mon: TMonster;
2641 AnimRevert: Boolean;
2642 begin
2643 ID := M.ReadWord();
2644 Mon := g_Monsters_ByUID(ID);
2645 if Mon = nil then Exit;
2647 MState := M.ReadByte();
2648 MFAnm := M.ReadByte();
2650 with Mon do
2651 begin
2652 MonsterTargetUID := M.ReadWord();
2653 MonsterTargetTime := M.ReadLongInt();
2654 MonsterSleep := M.ReadLongInt();
2655 MonsterHealth := M.ReadLongInt();
2656 MonsterAmmo := M.ReadLongInt();
2657 MonsterPain := M.ReadLongInt();
2658 AnimRevert := M.ReadByte() <> 0;
2659 FFireTime := M.ReadLongInt();
2660 RevertAnim(AnimRevert);
2662 if MonsterState <> MState then
2663 begin
2664 if (MState = MONSTATE_GO) and (MonsterState = MONSTATE_SLEEP) then
2665 WakeUpSound;
2666 if (MState = MONSTATE_DIE) then
2667 DieSound;
2668 if (MState = MONSTATE_PAIN) then
2669 MakeBloodSimple(Min(200, MonsterPain));
2670 if (MState = MONSTATE_ATTACK) then
2671 kick(nil);
2672 if (MState = MONSTATE_DEAD) then
2673 SetDeadAnim;
2675 SetState(MState, MFAnm);
2676 end;
2677 end;
2678 end;
2680 procedure MC_RECV_MonsterShot(var M: TMsg);
2681 var
2682 ID: Integer;
2683 Mon: TMonster;
2684 X, Y, VX, VY: Integer;
2685 begin
2686 ID := M.ReadWord();
2688 Mon := g_Monsters_ByUID(ID);
2689 if Mon = nil then Exit;
2691 X := M.ReadLongInt();
2692 Y := M.ReadLongInt();
2693 VX := M.ReadLongInt();
2694 VY := M.ReadLongInt();
2696 Mon.ClientAttack(X, Y, VX, VY);
2697 end;
2699 procedure MC_RECV_MonsterDelete(var M: TMsg);
2700 var
2701 ID: Integer;
2702 Mon: TMonster;
2703 begin
2704 ID := M.ReadWord();
2705 Mon := g_Monsters_ByUID(ID);
2706 if Mon = nil then Exit;
2707 Mon.SetState(5);
2708 Mon.MonsterRemoved := True;
2709 end;
2711 procedure MC_RECV_TimeSync(var M: TMsg);
2712 var
2713 Time: LongWord;
2714 begin
2715 Time := M.ReadLongWord();
2717 if gState = STATE_INTERCUSTOM then
2718 gServInterTime := Min(Time, 255);
2719 end;
2721 procedure MC_RECV_VoteEvent(var M: TMsg);
2722 var
2723 EvID: Byte;
2724 Str1, Str2: string;
2725 Int1, Int2: SmallInt;
2726 begin
2727 EvID := M.ReadByte();
2728 Int1 := M.ReadSmallInt();
2729 Int2 := M.ReadSmallInt();
2730 Str1 := M.ReadString();
2731 Str2 := M.ReadString();
2733 case EvID of
2734 NET_VE_STARTED:
2735 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True);
2736 NET_VE_PASSED:
2737 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True);
2738 NET_VE_FAILED:
2739 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
2740 NET_VE_VOTE:
2741 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True);
2742 NET_VE_INPROGRESS:
2743 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True);
2744 end;
2745 end;
2747 // CLIENT SEND
2749 procedure MC_SEND_Info(Password: string);
2750 begin
2751 NetOut.Clear();
2753 NetOut.Write(Byte(NET_MSG_INFO));
2754 NetOut.Write(GAME_VERSION);
2755 NetOut.Write(Password);
2756 NetOut.Write(gPlayer1Settings.Name);
2757 NetOut.Write(gPlayer1Settings.Model);
2758 NetOut.Write(gPlayer1Settings.Color.R);
2759 NetOut.Write(gPlayer1Settings.Color.G);
2760 NetOut.Write(gPlayer1Settings.Color.B);
2761 NetOut.Write(gPlayer1Settings.Team);
2763 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2764 end;
2766 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
2767 begin
2768 NetOut.Write(Byte(NET_MSG_CHAT));
2769 NetOut.Write(Txt);
2770 NetOut.Write(Mode);
2772 g_Net_Client_Send(True, NET_CHAN_CHAT);
2773 end;
2775 function isKeyPressed (key1: Word; key2: Word): Boolean;
2776 begin
2777 if (key1 <> 0) and e_KeyPressed(key1) then begin result := true; exit; end;
2778 if (key2 <> 0) and e_KeyPressed(key2) then begin result := true; exit; end;
2779 result := false;
2780 end;
2782 procedure MC_SEND_PlayerPos();
2783 var
2784 kByte: Word;
2785 Predict: Boolean;
2786 strafeDir: Byte;
2787 WeaponSelect: Word = 0;
2788 I: Integer;
2789 begin
2790 if not gGameOn then Exit;
2791 if gPlayers = nil then Exit;
2792 if gPlayer1 = nil then Exit;
2794 kByte := 0;
2795 Predict := NetPredictSelf; // and (not NetGotKeys);
2797 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2798 begin
2799 strafeDir := P1MoveButton shr 4;
2800 P1MoveButton := P1MoveButton and $0F;
2801 with gGameControls.P1Control do
2802 begin
2803 if isKeyPressed(KeyLeft, KeyLeft2) and (not isKeyPressed(KeyRight, KeyRight2)) then P1MoveButton := 1
2804 else if (not isKeyPressed(KeyLeft, KeyLeft2)) and isKeyPressed(KeyRight, KeyRight2) then P1MoveButton := 2
2805 else if (not isKeyPressed(KeyLeft, KeyLeft2)) and (not isKeyPressed(KeyRight, KeyRight2)) then P1MoveButton := 0;
2807 // strafing
2808 if isKeyPressed(KeyStrafe, KeyStrafe2) then
2809 begin
2810 // new strafe mechanics
2811 if (strafeDir = 0) then strafeDir := P1MoveButton; // start strafing
2812 // now set direction according to strafe (reversed)
2813 if (strafeDir = 2) then gPlayer1.SetDirection(D_LEFT)
2814 else if (strafeDir = 1) then gPlayer1.SetDirection(D_RIGHT);
2815 end
2816 else
2817 begin
2818 if (P1MoveButton = 2) and isKeyPressed(KeyLeft, KeyLeft2) then gPlayer1.SetDirection(D_LEFT)
2819 else if (P1MoveButton = 1) and isKeyPressed(KeyRight, KeyRight2) then gPlayer1.SetDirection(D_RIGHT)
2820 else if P1MoveButton <> 0 then gPlayer1.SetDirection(TDirection(P1MoveButton-1));
2821 end;
2823 gPlayer1.ReleaseKeys;
2824 if P1MoveButton = 1 then
2825 begin
2826 kByte := kByte or NET_KEY_LEFT;
2827 if Predict then gPlayer1.PressKey(KEY_LEFT, 10000);
2828 end;
2829 if P1MoveButton = 2 then
2830 begin
2831 kByte := kByte or NET_KEY_RIGHT;
2832 if Predict then gPlayer1.PressKey(KEY_RIGHT, 10000);
2833 end;
2834 if isKeyPressed(KeyUp, KeyUp2) then
2835 begin
2836 kByte := kByte or NET_KEY_UP;
2837 gPlayer1.PressKey(KEY_UP, 10000);
2838 end;
2839 if isKeyPressed(KeyDown, KeyDown2) then
2840 begin
2841 kByte := kByte or NET_KEY_DOWN;
2842 gPlayer1.PressKey(KEY_DOWN, 10000);
2843 end;
2844 if isKeyPressed(KeyJump, KeyJump2) then
2845 begin
2846 kByte := kByte or NET_KEY_JUMP;
2847 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2848 end;
2849 if isKeyPressed(KeyFire, KeyFire2) then kByte := kByte or NET_KEY_FIRE;
2850 if isKeyPressed(KeyOpen, KeyOpen2) then kByte := kByte or NET_KEY_OPEN;
2851 if isKeyPressed(KeyNextWeapon, KeyNextWeapon2) then kByte := kByte or NET_KEY_NW;
2852 if isKeyPressed(KeyPrevWeapon, KeyPrevWeapon2) then kByte := kByte or NET_KEY_PW;
2853 for I := 0 to High(KeyWeapon) do
2854 if isKeyPressed(KeyWeapon[I], KeyWeapon2[I]) then
2855 WeaponSelect := WeaponSelect or Word(1 shl I);
2856 end;
2857 // fix movebutton state
2858 P1MoveButton := P1MoveButton or (strafeDir shl 4);
2859 end
2860 else
2861 kByte := NET_KEY_CHAT;
2863 NetOut.Write(Byte(NET_MSG_PLRPOS));
2864 NetOut.Write(gTime);
2865 NetOut.Write(kByte);
2866 NetOut.Write(Byte(gPlayer1.Direction));
2867 NetOut.Write(WeaponSelect);
2868 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2869 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS);
2871 //kBytePrev := kByte;
2872 //kDirPrev := gPlayer1.Direction;
2873 end;
2875 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
2876 begin
2877 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
2878 NetOut.Write(Byte(Start));
2879 NetOut.Write(Command);
2880 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2881 end;
2883 procedure MC_SEND_PlayerSettings();
2884 begin
2885 NetOut.Write(Byte(NET_MSG_PLRSET));
2886 NetOut.Write(gPlayer1Settings.Name);
2887 NetOut.Write(gPlayer1Settings.Model);
2888 NetOut.Write(gPlayer1Settings.Color.R);
2889 NetOut.Write(gPlayer1Settings.Color.G);
2890 NetOut.Write(gPlayer1Settings.Color.B);
2891 NetOut.Write(gPlayer1Settings.Team);
2893 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2894 end;
2896 procedure MC_SEND_FullStateRequest();
2897 begin
2898 NetOut.Write(Byte(NET_MSG_REQFST));
2900 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2901 end;
2903 procedure MC_SEND_CheatRequest(Kind: Byte);
2904 begin
2905 NetOut.Write(Byte(NET_MSG_CHEAT));
2906 NetOut.Write(Kind);
2908 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2909 end;
2910 procedure MC_SEND_RCONPassword(Password: string);
2911 begin
2912 NetOut.Write(Byte(NET_MSG_RCON_AUTH));
2913 NetOut.Write(Password);
2915 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2916 end;
2917 procedure MC_SEND_RCONCommand(Cmd: string);
2918 begin
2919 NetOut.Write(Byte(NET_MSG_RCON_CMD));
2920 NetOut.Write(Cmd);
2922 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2923 end;
2925 // i have no idea why all this stuff is in here
2927 function ReadFile(const FileName: TFileName): AByte;
2928 var
2929 FileStream : TStream;
2930 fname: string;
2931 begin
2932 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName]), MSG_NOTIFY);
2933 fname := findDiskWad(FileName);
2934 if length(fname) = 0 then
2935 begin
2936 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName]), MSG_FATALERROR);
2937 SetLength(Result, 0);
2938 exit;
2939 end;
2940 e_WriteLog(Format('NETWORK: found file "%s"', [fname]), MSG_NOTIFY);
2941 Result := nil;
2942 FileStream := openDiskFileRO(fname);
2943 try
2944 if FileStream.Size > 0 then
2945 begin
2946 SetLength(Result, FileStream.Size);
2947 FileStream.Read(Result[0], FileStream.Size);
2948 end;
2949 finally
2950 FileStream.Free;
2951 end;
2952 end;
2954 function CreateMapDataMsg(const FileName: TFileName; ResList: TStringList): TMapDataMsg;
2955 var
2956 i: Integer;
2957 begin
2958 Result.MsgId := NET_MSG_MAP_RESPONSE;
2959 Result.FileData := ReadFile(FileName);
2960 Result.FileSize := Length(Result.FileData);
2962 SetLength(Result.ExternalResources, ResList.Count);
2963 for i:=0 to ResList.Count-1 do
2964 begin
2965 Result.ExternalResources[i].Name := ResList.Strings[i];
2966 Result.ExternalResources[i].md5 := MD5File(GameDir+'/wads/'+ResList.Strings[i]);
2967 end;
2968 end;
2970 procedure ResDataMsgToBytes(var bytes: AByte; const ResData: TResDataMsg);
2971 var
2972 ResultStream: TMemoryStream;
2973 begin
2974 ResultStream := TMemoryStream.Create;
2976 ResultStream.WriteBuffer(ResData.MsgId, SizeOf(ResData.MsgId)); //msgId
2977 ResultStream.WriteBuffer(ResData.FileSize, SizeOf(ResData.FileSize)); //file size
2978 ResultStream.WriteBuffer(ResData.FileData[0], ResData.FileSize); //file data
2980 SetLength(bytes, ResultStream.Size);
2981 ResultStream.Seek(0, soFromBeginning);
2982 ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
2984 ResultStream.Free;
2985 end;
2987 function ResDataFromMsgStream(msgStream: TMemoryStream):TResDataMsg;
2988 begin
2989 msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
2990 msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize));
2991 SetLength(Result.FileData, Result.FileSize);
2992 msgStream.ReadBuffer(Result.FileData[0], Result.FileSize);
2993 end;
2995 procedure MapDataMsgToBytes(var bytes: AByte; const MapDataMsg: TMapDataMsg);
2996 var
2997 ResultStream: TMemoryStream;
2998 resCount: Integer;
2999 begin
3000 resCount := Length(MapDataMsg.ExternalResources);
3002 ResultStream := TMemoryStream.Create;
3004 ResultStream.WriteBuffer(MapDataMsg.MsgId, SizeOf(MapDataMsg.MsgId)); //msgId
3005 ResultStream.WriteBuffer(MapDataMsg.FileSize, SizeOf(MapDataMsg.FileSize)); //file size
3006 ResultStream.WriteBuffer(MapDataMsg.FileData[0], MapDataMsg.FileSize); //file data
3008 ResultStream.WriteBuffer(resCount, SizeOf(resCount)); //res count
3009 ResultStream.WriteBuffer(MapDataMsg.ExternalResources[0], resCount*SizeOf(TExternalResourceInfo)); //res data
3011 SetLength(bytes, ResultStream.Size);
3012 ResultStream.Seek(0, soFromBeginning);
3013 ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
3015 ResultStream.Free;
3016 end;
3018 function MapDataFromMsgStream(msgStream: TMemoryStream):TMapDataMsg;
3019 var
3020 resCount: Integer;
3021 begin
3022 msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
3023 msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize)); //file size
3025 SetLength(Result.FileData, Result.FileSize);
3026 msgStream.ReadBuffer(Result.FileData[0], Result.FileSize); //file data
3028 msgStream.ReadBuffer(resCount, SizeOf(resCount)); //res count
3029 SetLength(Result.ExternalResources, resCount);
3031 msgStream.ReadBuffer(Result.ExternalResources[0], resCount * SizeOf(TExternalResourceInfo)); //res data
3032 end;
3034 function IsValidFileName(const S: String): Boolean;
3035 const
3036 Forbidden: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
3037 var
3038 I: Integer;
3039 begin
3040 Result := S <> '';
3041 for I := 1 to Length(S) do
3042 Result := Result and (not(S[I] in Forbidden));
3043 end;
3045 function IsValidFilePath(const S: String): Boolean;
3046 var
3047 I: Integer;
3048 begin
3049 Result := False;
3050 if not IsValidFileName(S) then exit;
3051 if FileExists(S) then exit;
3052 I := LastDelimiter('\/', S);
3053 if (I > 0) then
3054 if (not DirectoryExists(Copy(S, 1, I-1))) then
3055 exit;
3056 Result := True;
3057 end;
3059 procedure MC_SEND_MapRequest();
3060 begin
3061 NetOut.Write(Byte(NET_MSG_MAP_REQUEST));
3062 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3063 end;
3065 procedure MC_SEND_ResRequest(const resName: AnsiString);
3066 begin
3067 NetOut.Write(Byte(NET_MSG_RES_REQUEST));
3068 NetOut.Write(resName);
3069 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3070 end;
3072 procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
3073 var
3074 payload: AByte;
3075 peer: pENetPeer;
3076 mapDataMsg: TMapDataMsg;
3077 begin
3078 e_WriteLog('NET: Received map request from ' +
3079 DecodeIPV4(C.Peer.address.host), MSG_NOTIFY);
3081 mapDataMsg := CreateMapDataMsg(MapsDir + gGameSettings.WAD, gExternalResources);
3082 peer := NetClients[C.ID].Peer;
3084 MapDataMsgToBytes(payload, mapDataMsg);
3085 g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
3087 payload := nil;
3088 mapDataMsg.FileData := nil;
3089 mapDataMsg.ExternalResources := nil;
3090 end;
3092 procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
3093 var
3094 payload: AByte;
3095 peer: pENetPeer;
3096 FileName: String;
3097 resDataMsg: TResDataMsg;
3098 begin
3099 FileName := ExtractFileName(M.ReadString());
3100 e_WriteLog('NET: Received res request: ' + FileName +
3101 ' from ' + DecodeIPV4(C.Peer.address.host), MSG_NOTIFY);
3103 if not IsValidFilePath(FileName) then
3104 begin
3105 e_WriteLog('Invalid filename: ' + FileName, MSG_WARNING);
3106 exit;
3107 end;
3109 peer := NetClients[C.ID].Peer;
3111 if gExternalResources.IndexOf(FileName) > -1 then
3112 begin
3113 resDataMsg.MsgId := NET_MSG_RES_RESPONSE;
3114 resDataMsg.FileData := ReadFile(GameDir+'/wads/'+FileName);
3115 resDataMsg.FileSize := Length(resDataMsg.FileData);
3117 ResDataMsgToBytes(payload, resDataMsg);
3118 g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
3119 end;
3120 end;
3122 end.