DEADSOFTWARE

6d1f430e5509196b9212f1535b1baedf3658e8af
[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 SetWeapon(M.ReadByte());
458 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
459 if Direction <> TDirection(Dir) then
460 JustTeleported := False;
462 SetDirection(TDirection(Dir));
463 ReleaseKeysNoWeapon();
465 if kByte = NET_KEY_CHAT then
466 begin
467 PressKey(KEY_CHAT, 10000);
468 Exit;
469 end;
471 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
472 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
473 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
474 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
475 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
476 if LongBool(kByte and NET_KEY_FIRE) then PressKey(KEY_FIRE, 10000);
477 if LongBool(kByte and NET_KEY_OPEN) then PressKey(KEY_OPEN, 10000);
478 //if LongBool(kByte and NET_KEY_NW) then PressKey(KEY_NEXTWEAPON, 10000);
479 //if LongBool(kByte and NET_KEY_PW) then PressKey(KEY_PREVWEAPON, 10000);
481 (*
482 for i := 0 to 15 do
483 begin
484 if (WeaponSelect and Word(1 shl i)) <> 0 then
485 begin
486 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
487 QueueWeaponSwitch(i);
488 end;
489 end;
490 *)
491 end;
493 // MH_SEND_PlayerPos(False, PID, C^.ID);
494 end;
496 procedure MH_RECV_CheatRequest(C: pTNetClient; var M: TMsg);
497 var
498 CheatKind: Byte;
499 Pl: TPlayer;
500 begin
501 Pl := g_Player_Get(C^.Player);
502 if Pl = nil then Exit;
504 CheatKind := M.ReadByte();
506 case CheatKind of
507 NET_CHEAT_SUICIDE:
508 Pl.Damage(SUICIDE_DAMAGE, Pl.UID, 0, 0, HIT_SELF);
509 NET_CHEAT_SPECTATE:
510 begin
511 if Pl.FSpectator then
512 Pl.Respawn(False)
513 else
514 Pl.Spectate;
515 end;
516 end;
517 end;
519 procedure MH_RECV_PlayerSettings(C: pTNetClient; var M: TMsg);
520 var
521 TmpName: string;
522 TmpModel: string;
523 TmpColor: TRGB;
524 TmpTeam: Byte;
525 Pl: TPlayer;
526 begin
527 TmpName := M.ReadString();
528 TmpModel := M.ReadString();
529 TmpColor.R := M.ReadByte();
530 TmpColor.G := M.ReadByte();
531 TmpColor.B := M.ReadByte();
532 TmpTeam := M.ReadByte();
534 Pl := g_Player_Get(C^.Player);
535 if Pl = nil then Exit;
537 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
538 Pl.SwitchTeam
539 else
540 Pl.SetColor(TmpColor);
542 if Pl.Name <> TmpName then
543 begin
544 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
545 Pl.Name := TmpName;
546 end;
548 if TmpModel <> Pl.Model.Name then
549 Pl.SetModel(TmpModel);
551 MH_SEND_PlayerSettings(Pl.UID, TmpModel);
552 end;
554 // RCON
556 procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
557 var
558 Pwd: string;
559 begin
560 Pwd := M.ReadString();
561 if not NetAllowRCON then Exit;
562 if Pwd = NetRCONPassword then
563 begin
564 C^.RCONAuth := True;
565 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWGOOD, 'N', C^.ID);
566 end
567 else
568 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWBAD, 'N', C^.ID);
569 end;
571 procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
572 var
573 Cmd: string;
574 begin
575 Cmd := M.ReadString();
576 if not NetAllowRCON then Exit;
577 if not C^.RCONAuth then
578 begin
579 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_NOAUTH, 'N', C^.ID);
580 Exit;
581 end;
582 g_Console_Process(Cmd);
583 end;
585 // MISC
587 procedure MH_RECV_Vote(C: pTNetClient; var M: TMsg);
588 var
589 Start: Boolean;
590 Name, Command: string;
591 Need: Integer;
592 Pl: TPlayer;
593 begin
594 Start := M.ReadByte() <> 0;
595 Command := M.ReadString();
597 Pl := g_Player_Get(C^.Player);
598 if Pl = nil then Exit;
599 Name := Pl.Name;
601 if Start then
602 begin
603 if not g_Console_CommandBlacklisted(Command) then
604 g_Game_StartVote(Command, Name);
605 end
606 else if gVoteInProgress then
607 begin
608 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
609 Need := Floor((NetClientCount+1)/2.0) + 1
610 else
611 Need := Floor(NetClientCount/2.0) + 1;
612 if C^.Voted then
613 begin
614 Dec(gVoteCount);
615 C^.Voted := False;
616 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [Name, gVoteCount, Need]), True);
617 MH_SEND_VoteEvent(NET_VE_REVOKE, Name, 'a', gVoteCount, Need);
618 end
619 else
620 begin
621 Inc(gVoteCount);
622 C^.Voted := True;
623 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Name, gVoteCount, Need]), True);
624 MH_SEND_VoteEvent(NET_VE_VOTE, Name, 'a', gVoteCount, Need);
625 g_Game_CheckVote;
626 end;
627 end;
628 end;
630 // GAME (SEND)
632 procedure MH_SEND_Everything(CreatePlayers: Boolean = False; ID: Integer = NET_EVERYONE);
634 function sendItemRespawn (it: PItem): Boolean;
635 begin
636 result := false; // don't stop
637 MH_SEND_ItemSpawn(True, it.myid, ID);
638 end;
640 function sendMonSpawn (mon: TMonster): Boolean;
641 begin
642 result := false; // don't stop
643 MH_SEND_MonsterSpawn(mon.UID, ID);
644 end;
646 function sendPanelState (pan: TPanel): Boolean;
647 begin
648 result := false; // don't stop
649 MH_SEND_PanelState(pan.guid, ID); // anyway, to sync mplats
650 if (pan.CanChangeTexture) then MH_SEND_PanelTexture(pan.guid, pan.LastAnimLoop, ID);
651 end;
653 var
654 I: Integer;
655 begin
656 if gPlayers <> nil then
657 begin
658 for I := Low(gPlayers) to High(gPlayers) do
659 begin
660 if gPlayers[I] <> nil then
661 begin
662 if CreatePlayers then MH_SEND_PlayerCreate(gPlayers[I].UID, ID);
663 MH_SEND_PlayerPos(True, gPlayers[I].UID, ID);
664 MH_SEND_PlayerStats(gPlayers[I].UID, ID);
666 if (gPlayers[I].Flag <> FLAG_NONE) and (gGameSettings.GameMode = GM_CTF) then
667 begin
668 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED, gPlayers[I].Flag, gPlayers[I].UID, True, ID);
669 end;
670 end;
671 end;
672 end;
674 g_Items_ForEachAlive(sendItemRespawn, true); // backwards
675 g_Mons_ForEach(sendMonSpawn);
676 g_Map_ForEachPanel(sendPanelState);
678 if gTriggers <> nil then
679 begin
680 for I := Low(gTriggers) to High(gTriggers) do
681 begin
682 if gTriggers[I].TriggerType = TRIGGER_SOUND then
683 begin
684 MH_SEND_TriggerSound(gTriggers[I], ID);
685 end;
686 end;
687 end;
689 if Shots <> nil then
690 begin
691 for I := Low(Shots) to High(Shots) do
692 begin
693 if Shots[i].ShotType in [6, 7, 8] then
694 begin
695 MH_SEND_CreateShot(i, ID);
696 end;
697 end;
698 end;
700 MH_SEND_TriggerMusic(ID);
702 MH_SEND_GameStats(ID);
703 MH_SEND_CoopStats(ID);
705 if gGameSettings.GameMode = GM_CTF then
706 begin
707 if gFlags[FLAG_RED].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_RED].State, FLAG_RED, 0, True, ID);
708 if gFlags[FLAG_BLUE].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_BLUE].State, FLAG_BLUE, 0, True, ID);
709 end;
711 if CreatePlayers and (ID >= 0) then NetClients[ID].State := NET_STATE_GAME;
713 if gLMSRespawn > LMS_RESPAWN_NONE then
714 begin
715 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000, 'N', ID);
716 end;
717 end;
719 procedure MH_SEND_Info(ID: Byte);
720 var
721 Map: string;
722 begin
723 Map := g_ExtractFileName(gMapInfo.Map);
725 NetOut.Clear();
727 NetOut.Write(Byte(NET_MSG_INFO));
728 NetOut.Write(ID);
729 NetOut.Write(NetClients[ID].Player);
730 NetOut.Write(gGameSettings.WAD);
731 NetOut.Write(Map);
732 NetOut.Write(gWADHash);
733 NetOut.Write(gGameSettings.GameMode);
734 NetOut.Write(gGameSettings.GoalLimit);
735 NetOut.Write(gGameSettings.TimeLimit);
736 NetOut.Write(gGameSettings.MaxLives);
737 NetOut.Write(gGameSettings.Options);
738 NetOut.Write(gTime);
740 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
741 end;
743 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
744 var
745 Name: string;
746 i: Integer;
747 Team: Byte;
748 begin
749 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
750 Mode := NET_CHAT_PLAYER;
752 Team := 0;
753 if (Mode = NET_CHAT_TEAM) then
754 begin
755 for i := Low(gPlayers) to High(gPlayers) do
756 if (gPlayers[i] <> nil) and (gPlayers[i].FClientID >= 0) and
757 (gPlayers[i].Team = ID) then
758 begin
759 NetOut.Write(Byte(NET_MSG_CHAT));
760 NetOut.Write(Txt);
761 NetOut.Write(Mode);
762 g_Net_Host_Send(gPlayers[i].FClientID, True, NET_CHAN_CHAT);
763 end;
764 Team := ID;
765 ID := NET_EVERYONE;
766 end
767 else
768 begin
769 NetOut.Write(Byte(NET_MSG_CHAT));
770 NetOut.Write(Txt);
771 NetOut.Write(Mode);
772 g_Net_Host_Send(ID, True, NET_CHAN_CHAT);
773 end;
775 if Mode = NET_CHAT_SYSTEM then
776 Exit;
778 if ID = NET_EVERYONE then
779 begin
780 if Mode = NET_CHAT_PLAYER then
781 begin
782 g_Console_Add(Txt, True);
783 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
784 g_Game_ChatSound(b_Text_Unformat(Txt));
785 end
786 else
787 if Mode = NET_CHAT_TEAM then
788 if gPlayer1 <> nil then
789 begin
790 if (gPlayer1.Team = TEAM_RED) and (Team = TEAM_RED) then
791 begin
792 g_Console_Add(#18'[Team] '#2 + Txt, True);
793 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
794 g_Game_ChatSound(b_Text_Unformat(Txt));
795 end
796 else if (gPlayer1.Team = TEAM_BLUE) and (Team = TEAM_BLUE) then
797 begin
798 g_Console_Add(#20'[Team] '#2 + Txt, True);
799 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
800 g_Game_ChatSound(b_Text_Unformat(Txt));
801 end;
802 end;
803 end
804 else
805 begin
806 Name := g_Net_ClientName_ByID(ID);
807 g_Console_Add('-> ' + Name + ': ' + Txt, True);
808 e_WriteLog('[Tell ' + Name + '] ' + b_Text_Unformat(Txt), TMsgType.Notify);
809 g_Game_ChatSound(b_Text_Unformat(Txt), False);
810 end;
811 end;
813 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
814 begin
815 NetOut.Write(Byte(NET_MSG_GFX));
816 NetOut.Write(Kind);
817 NetOut.Write(X);
818 NetOut.Write(Y);
819 NetOut.Write(Ang);
821 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
822 end;
824 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
825 begin
826 NetOut.Write(Byte(NET_MSG_SND));
827 NetOut.Write(Name);
828 if Pos then
829 begin
830 NetOut.Write(Byte(1));
831 NetOut.Write(X);
832 NetOut.Write(Y);
833 end
834 else
835 NetOut.Write(Byte(0));
837 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
838 end;
840 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
841 begin
842 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
844 NetOut.Write(Byte(NET_MSG_SHADD));
845 NetOut.Write(Proj);
846 NetOut.Write(Shots[Proj].ShotType);
847 NetOut.Write(Shots[Proj].Target);
848 NetOut.Write(Shots[Proj].SpawnerUID);
849 NetOut.Write(Shots[Proj].Timeout);
850 NetOut.Write(Shots[Proj].Obj.X);
851 NetOut.Write(Shots[Proj].Obj.Y);
852 NetOut.Write(Shots[Proj].Obj.Vel.X);
853 NetOut.Write(Shots[Proj].Obj.Vel.Y);
855 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
856 end;
858 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
859 begin
860 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
862 NetOut.Write(Byte(NET_MSG_SHPOS));
863 NetOut.Write(Proj);
864 NetOut.Write(Shots[Proj].Obj.X);
865 NetOut.Write(Shots[Proj].Obj.Y);
866 NetOut.Write(Shots[Proj].Obj.Vel.X);
867 NetOut.Write(Shots[Proj].Obj.Vel.Y);
869 g_Net_Host_Send(ID, False, NET_CHAN_SHOTS);
870 end;
872 procedure MH_Send_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
873 begin
874 NetOut.Write(Byte(NET_MSG_SHDEL));
875 NetOut.Write(Proj);
876 NetOut.Write(Byte(Loud));
877 NetOut.Write(X);
878 NetOut.Write(Y);
880 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
881 end;
883 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
884 begin
885 NetOut.Write(Byte(NET_MSG_SCORE));
886 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
887 begin
888 NetOut.Write(gTeamStat[TEAM_RED].Goals);
889 NetOut.Write(gTeamStat[TEAM_BLUE].Goals);
890 end
891 else
892 if gGameSettings.GameMode = GM_COOP then
893 begin
894 NetOut.Write(gCoopMonstersKilled);
895 NetOut.Write(gCoopSecretsFound);
896 end;
898 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
899 end;
901 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
902 begin
903 NetOut.Write(Byte(NET_MSG_COOP));
904 NetOut.Write(gTotalMonsters);
905 NetOut.Write(gSecretsCount);
906 NetOut.Write(gCoopTotalMonstersKilled);
907 NetOut.Write(gCoopTotalSecretsFound);
908 NetOut.Write(gCoopTotalMonsters);
909 NetOut.Write(gCoopTotalSecrets);
910 end;
912 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
913 begin
914 NetOut.Write(Byte(NET_MSG_GEVENT));
915 NetOut.Write(EvType);
916 NetOut.Write(EvNum);
917 NetOut.Write(EvStr);
918 NetOut.Write(Byte(gLastMap));
919 NetOut.Write(gTime);
920 if (EvType = NET_EV_MAPSTART) and isWadPath(EvStr) then
921 begin
922 NetOut.Write(Byte(1));
923 NetOut.Write(gWADHash);
924 end else
925 NetOut.Write(Byte(0));
927 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
928 end;
930 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
931 begin
932 NetOut.Write(Byte(NET_MSG_FLAG));
933 NetOut.Write(EvType);
934 NetOut.Write(Flag);
935 NetOut.Write(Byte(Quiet));
936 NetOut.Write(PID);
937 NetOut.Write(gFlags[Flag].State);
938 NetOut.Write(gFlags[Flag].CaptureTime);
939 NetOut.Write(gFlags[Flag].Obj.X);
940 NetOut.Write(gFlags[Flag].Obj.Y);
941 NetOut.Write(gFlags[Flag].Obj.Vel.X);
942 NetOut.Write(gFlags[Flag].Obj.Vel.Y);
944 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
945 end;
947 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
948 begin
949 NetOut.Write(Byte(NET_MSG_GSET));
950 NetOut.Write(gGameSettings.GameMode);
951 NetOut.Write(gGameSettings.GoalLimit);
952 NetOut.Write(gGameSettings.TimeLimit);
953 NetOut.Write(gGameSettings.MaxLives);
954 NetOut.Write(gGameSettings.Options);
956 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
957 end;
959 // PLAYER (SEND)
961 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
962 var
963 P: TPlayer;
964 begin
965 P := g_Player_Get(PID);
966 if P = nil then Exit;
968 NetOut.Write(Byte(NET_MSG_PLR));
969 NetOut.Write(PID);
970 NetOut.Write(P.Name);
972 NetOut.Write(P.FActualModelName);
973 NetOut.Write(P.FColor.R);
974 NetOut.Write(P.FColor.G);
975 NetOut.Write(P.FColor.B);
976 NetOut.Write(P.Team);
978 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT)
979 end;
981 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
982 var
983 kByte: Word;
984 Pl: TPlayer;
985 begin
986 Pl := g_Player_Get(PID);
987 if Pl = nil then Exit;
988 if Pl.FDummy then Exit;
990 NetOut.Write(Byte(NET_MSG_PLRPOS));
991 NetOut.Write(gTime);
992 NetOut.Write(PID);
994 kByte := 0;
996 with Pl do
997 begin
998 NetOut.Write(FPing);
999 NetOut.Write(FLoss);
1000 if IsKeyPressed(KEY_CHAT) then
1001 kByte := NET_KEY_CHAT
1002 else
1003 begin
1004 if IsKeyPressed(KEY_LEFT) then kByte := kByte or NET_KEY_LEFT;
1005 if IsKeyPressed(KEY_RIGHT) then kByte := kByte or NET_KEY_RIGHT;
1006 if IsKeyPressed(KEY_UP) then kByte := kByte or NET_KEY_UP;
1007 if IsKeyPressed(KEY_DOWN) then kByte := kByte or NET_KEY_DOWN;
1008 if IsKeyPressed(KEY_JUMP) then kByte := kByte or NET_KEY_JUMP;
1009 if JustTeleported then kByte := kByte or NET_KEY_FORCEDIR;
1010 end;
1012 NetOut.Write(kByte);
1013 if Direction = TDirection.D_LEFT then NetOut.Write(Byte(0)) else NetOut.Write(Byte(1));
1014 NetOut.Write(GameX);
1015 NetOut.Write(GameY);
1016 NetOut.Write(GameVelX);
1017 NetOut.Write(GameVelY);
1018 NetOut.Write(GameAccelX);
1019 NetOut.Write(GameAccelY);
1020 end;
1022 g_Net_Host_Send(ID, Reliable, NET_CHAN_PLAYERPOS);
1023 end;
1025 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
1026 var
1027 P: TPlayer;
1028 I: Integer;
1029 ww: Word;
1030 begin
1031 P := g_Player_Get(PID);
1032 if P = nil then Exit;
1034 NetOut.Write(Byte(NET_MSG_PLRSTA));
1035 NetOut.Write(PID);
1037 with P do
1038 begin
1039 NetOut.Write(Byte(alive));
1040 NetOut.Write(Byte(GodMode));
1041 NetOut.Write(Health);
1042 NetOut.Write(Armor);
1043 NetOut.Write(Air);
1044 NetOut.Write(JetFuel);
1045 NetOut.Write(Lives);
1046 NetOut.Write(Team);
1048 // collect all weapons in one word
1049 ww := 0;
1050 for I := WP_FIRST to WP_LAST do if (FWeapon[I]) then ww := ww or (1 shl (i-WP_FIRST));
1051 NetOut.Write(Word(ww));
1053 for I := A_BULLETS to A_HIGH do
1054 NetOut.Write(FAmmo[I]);
1056 for I := A_BULLETS to A_HIGH do
1057 NetOut.Write(FMaxAmmo[I]);
1059 for I := MR_SUIT to MR_MAX do
1060 NetOut.Write(LongWord(FMegaRulez[I]));
1062 // collect all special flags in one byte
1063 ww := 0;
1064 if (R_ITEM_BACKPACK in FRulez) then ww := ww or $01;
1065 if (R_KEY_RED in FRulez) then ww := ww or $02;
1066 if (R_KEY_GREEN in FRulez) then ww := ww or $04;
1067 if (R_KEY_BLUE in FRulez) then ww := ww or $08;
1068 if (R_BERSERK in FRulez) then ww := ww or $10;
1069 NetOut.Write(Byte(ww));
1071 NetOut.Write(Frags);
1072 NetOut.Write(Death);
1074 NetOut.Write(CurrWeap);
1076 // other flags
1077 ww := 0;
1078 if (FSpectator) then ww := ww or $01;
1079 if (FGhost) then ww := ww or $02;
1080 if (FPhysics) then ww := ww or $04;
1081 if (FNoRespawn) then ww := ww or $08;
1082 if (FJetpack) then ww := ww or $10;
1083 NetOut.Write(Byte(ww));
1085 NetOut.Write(FFireTime);
1086 end;
1088 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1089 end;
1091 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
1092 begin
1093 NetOut.Write(Byte(NET_MSG_PLRDMG));
1094 NetOut.Write(PID);
1095 NetOut.Write(Kind);
1096 NetOut.Write(Attacker);
1097 NetOut.Write(Value);
1098 NetOut.Write(VX);
1099 NetOut.Write(VY);
1101 g_Net_Host_Send(ID, False, NET_CHAN_PLAYER);
1102 end;
1104 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
1105 begin
1106 NetOut.Write(Byte(NET_MSG_PLRDIE));
1107 NetOut.Write(PID);
1108 NetOut.Write(KillType);
1109 NetOut.Write(DeathType);
1110 NetOut.Write(Attacker);
1112 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1113 end;
1115 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
1116 begin
1117 NetOut.Write(Byte(NET_MSG_PLRFIRE));
1118 NetOut.Write(PID);
1119 NetOut.Write(Weapon);
1120 NetOut.Write(X);
1121 NetOut.Write(Y);
1122 NetOut.Write(AX);
1123 NetOut.Write(AY);
1124 NetOut.Write(ShotID);
1126 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1127 end;
1129 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
1130 begin
1131 NetOut.Write(Byte(NET_MSG_PLRDEL));
1132 NetOut.Write(PID);
1134 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1135 end;
1137 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
1138 var
1139 Pl: TPlayer;
1140 begin
1141 Pl := g_Player_Get(PID);
1142 if Pl = nil then Exit;
1144 NetOut.Write(Byte(NET_MSG_PLRSET));
1145 NetOut.Write(PID);
1146 NetOut.Write(Pl.Name);
1147 if Mdl = '' then
1148 NetOut.Write(Pl.Model.Name)
1149 else
1150 NetOut.Write(Mdl);
1151 NetOut.Write(Pl.FColor.R);
1152 NetOut.Write(Pl.FColor.G);
1153 NetOut.Write(Pl.FColor.B);
1154 NetOut.Write(Pl.Team);
1156 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1157 end;
1159 // ITEM (SEND)
1161 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1162 var
1163 it: PItem;
1164 tt: Byte;
1165 begin
1166 it := g_Items_ByIdx(IID);
1168 NetOut.Write(Byte(NET_MSG_ISPAWN));
1169 NetOut.Write(IID);
1170 NetOut.Write(Byte(Quiet));
1171 tt := it.ItemType;
1172 if it.dropped then tt := tt or $80;
1173 NetOut.Write(tt);
1174 NetOut.Write(Byte(it.Fall));
1175 NetOut.Write(Byte(it.Respawnable));
1176 NetOut.Write(it.Obj.X);
1177 NetOut.Write(it.Obj.Y);
1178 NetOut.Write(it.Obj.Vel.X);
1179 NetOut.Write(it.Obj.Vel.Y);
1181 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1182 end;
1184 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1185 begin
1186 NetOut.Write(Byte(NET_MSG_IDEL));
1187 NetOut.Write(IID);
1188 NetOut.Write(Byte(Quiet));
1190 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1191 end;
1193 // PANEL
1195 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
1196 var
1197 TP: TPanel;
1198 begin
1199 TP := g_Map_PanelByGUID(PGUID);
1200 if (TP = nil) then exit;
1202 with TP do
1203 begin
1204 NetOut.Write(Byte(NET_MSG_PTEX));
1205 NetOut.Write(LongWord(PGUID));
1206 NetOut.Write(FCurTexture);
1207 NetOut.Write(FCurFrame);
1208 NetOut.Write(FCurFrameCount);
1209 NetOut.Write(AnimLoop);
1210 end;
1212 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1213 end;
1215 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
1216 var
1217 TP: TPanel;
1218 mpflags: Byte = 0;
1219 begin
1220 TP := g_Map_PanelByGUID(PGUID);
1221 if (TP = nil) then exit;
1223 NetOut.Write(Byte(NET_MSG_PSTATE));
1224 NetOut.Write(LongWord(PGUID));
1225 NetOut.Write(Byte(TP.Enabled));
1226 NetOut.Write(TP.LiftType);
1227 NetOut.Write(TP.X);
1228 NetOut.Write(TP.Y);
1229 NetOut.Write(Word(TP.Width));
1230 NetOut.Write(Word(TP.Height));
1231 // mplats
1232 NetOut.Write(LongInt(TP.movingSpeedX));
1233 NetOut.Write(LongInt(TP.movingSpeedY));
1234 NetOut.Write(LongInt(TP.movingStartX));
1235 NetOut.Write(LongInt(TP.movingStartY));
1236 NetOut.Write(LongInt(TP.movingEndX));
1237 NetOut.Write(LongInt(TP.movingEndY));
1238 NetOut.Write(LongInt(TP.sizeSpeedX));
1239 NetOut.Write(LongInt(TP.sizeSpeedY));
1240 NetOut.Write(LongInt(TP.sizeEndX));
1241 NetOut.Write(LongInt(TP.sizeEndY));
1242 if TP.movingActive then mpflags := mpflags or 1;
1243 if TP.moveOnce then mpflags := mpflags or 2;
1244 NetOut.Write(Byte(mpflags));
1246 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1247 end;
1249 // TRIGGER
1251 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
1252 begin
1253 if gTriggers = nil then Exit;
1254 if T.Sound = nil then Exit;
1256 NetOut.Write(Byte(NET_MSG_TSOUND));
1257 NetOut.Write(T.ClientID);
1258 NetOut.Write(Byte(T.Sound.IsPlaying));
1259 NetOut.Write(LongWord(T.Sound.GetPosition));
1260 NetOut.Write(T.SoundPlayCount);
1262 g_Net_Host_Send(ID, True);
1263 end;
1265 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
1266 begin
1267 NetOut.Write(Byte(NET_MSG_TMUSIC));
1268 NetOut.Write(gMusic.Name);
1269 NetOut.Write(Byte(gMusic.IsPlaying));
1270 NetOut.Write(LongWord(gMusic.GetPosition));
1271 NetOut.Write(Byte(gMusic.SpecPause or gMusic.IsPaused));
1273 g_Net_Host_Send(ID, True);
1274 end;
1276 // MONSTER
1278 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
1279 var
1280 M: TMonster;
1281 begin
1282 M := g_Monsters_ByUID(UID);
1283 if M = nil then
1284 Exit;
1286 with M do
1287 begin
1288 NetOut.Write(Byte(NET_MSG_MSPAWN));
1289 NetOut.Write(UID);
1290 NetOut.Write(MonsterType);
1291 NetOut.Write(MonsterState);
1292 NetOut.Write(MonsterAnim);
1293 NetOut.Write(MonsterTargetUID);
1294 NetOut.Write(MonsterTargetTime);
1295 NetOut.Write(MonsterBehaviour);
1296 NetOut.Write(MonsterSleep);
1297 NetOut.Write(MonsterHealth);
1298 NetOut.Write(MonsterAmmo);
1299 NetOut.Write(GameX);
1300 NetOut.Write(GameY);
1301 NetOut.Write(GameVelX);
1302 NetOut.Write(GameVelY);
1303 NetOut.Write(Byte(GameDirection));
1304 end;
1306 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1307 end;
1309 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
1310 var
1311 M: TMonster;
1312 begin
1313 M := g_Monsters_ByUID(UID);
1314 if M = nil then Exit;
1316 NetOut.Write(Byte(NET_MSG_MPOS));
1317 NetOut.Write(UID);
1319 with M do
1320 begin
1321 NetOut.Write(GameX);
1322 NetOut.Write(GameY);
1323 NetOut.Write(GameVelX);
1324 NetOut.Write(GameVelY);
1325 NetOut.Write(Byte(GameDirection));
1326 end;
1328 g_Net_Host_Send(ID, False, NET_CHAN_MONSTERPOS);
1329 end;
1331 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
1332 var
1333 M: TMonster;
1334 begin
1335 M := g_Monsters_ByUID(UID);
1336 if M = nil then Exit;
1338 NetOut.Write(Byte(NET_MSG_MSTATE));
1339 NetOut.Write(UID);
1341 with M do
1342 begin
1343 NetOut.Write(MonsterState);
1344 NetOut.Write(ForcedAnim);
1345 NetOut.Write(MonsterTargetUID);
1346 NetOut.Write(MonsterTargetTime);
1347 NetOut.Write(MonsterSleep);
1348 NetOut.Write(MonsterHealth);
1349 NetOut.Write(MonsterAmmo);
1350 NetOut.Write(MonsterPain);
1351 NetOut.Write(Byte(AnimIsReverse));
1352 NetOut.Write(FFireTime);
1353 end;
1355 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1356 end;
1358 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
1359 begin
1360 NetOut.Write(Byte(NET_MSG_MSHOT));
1361 NetOut.Write(UID);
1362 NetOut.Write(X);
1363 NetOut.Write(Y);
1364 NetOut.Write(VX);
1365 NetOut.Write(VY);
1367 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1368 end;
1370 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
1371 var
1372 M: TMonster;
1373 begin
1374 M := g_Monsters_ByUID(UID);
1375 if M = nil then Exit;
1377 NetOut.Write(Byte(NET_MSG_MDEL));
1378 NetOut.Write(UID);
1380 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1381 end;
1383 // MISC
1385 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
1386 begin
1387 NetOut.Write(Byte(NET_MSG_TIME_SYNC));
1388 NetOut.Write(Time);
1390 g_Net_Host_Send(ID, False, NET_CHAN_SERVICE);
1391 end;
1393 procedure MH_SEND_VoteEvent(EvType: Byte;
1394 StrArg1: string = 'a'; StrArg2: string = 'b';
1395 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
1396 ID: Integer = NET_EVERYONE);
1397 begin
1398 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
1399 NetOut.Write(EvType);
1400 NetOut.Write(IntArg1);
1401 NetOut.Write(IntArg2);
1402 NetOut.Write(StrArg1);
1403 NetOut.Write(StrArg2);
1405 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1406 end;
1408 // CLIENT MESSAGES //
1410 // GAME
1412 procedure MC_RECV_Chat(var M: TMsg);
1413 var
1414 Txt: string;
1415 Mode: Byte;
1416 begin
1417 Txt := M.ReadString();
1418 Mode := M.ReadByte();
1420 if Mode <> NET_CHAT_SYSTEM then
1421 begin
1422 if Mode = NET_CHAT_PLAYER then
1423 begin
1424 g_Console_Add(Txt, True);
1425 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1426 g_Game_ChatSound(b_Text_Unformat(Txt));
1427 end else
1428 if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then
1429 begin
1430 if gPlayer1.Team = TEAM_RED then
1431 g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True);
1432 if gPlayer1.Team = TEAM_BLUE then
1433 g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True);
1434 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1435 g_Game_ChatSound(b_Text_Unformat(Txt));
1436 end;
1437 end else
1438 g_Console_Add(Txt, True);
1439 end;
1441 procedure MC_RECV_Effect(var M: TMsg);
1442 var
1443 Kind: Byte;
1444 X, Y: Integer;
1445 Ang: SmallInt;
1446 Anim: TAnimation;
1447 ID: LongWord;
1448 begin
1449 if not gGameOn then Exit;
1450 Kind := M.ReadByte();
1451 X := M.ReadLongInt();
1452 Y := M.ReadLongInt();
1453 Ang := M.ReadSmallInt();
1455 case Kind of
1456 NET_GFX_SPARK:
1457 g_GFX_Spark(X, Y, 2 + Random(2), Ang, 0, 0);
1459 NET_GFX_TELE:
1460 begin
1461 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
1462 begin
1463 Anim := TAnimation.Create(ID, False, 3);
1464 g_GFX_OnceAnim(X, Y, Anim);
1465 Anim.Free();
1466 end;
1467 if Ang = 1 then
1468 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
1469 end;
1471 NET_GFX_EXPLODE:
1472 begin
1473 if g_Frames_Get(ID, 'FRAMES_EXPLODE_ROCKET') then
1474 begin
1475 Anim := TAnimation.Create(ID, False, 6);
1476 Anim.Blending := False;
1477 g_GFX_OnceAnim(X-64, Y-64, Anim);
1478 Anim.Free();
1479 end;
1480 if Ang = 1 then
1481 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X, Y);
1482 end;
1484 NET_GFX_BFGEXPL:
1485 begin
1486 if g_Frames_Get(ID, 'FRAMES_EXPLODE_BFG') then
1487 begin
1488 Anim := TAnimation.Create(ID, False, 6);
1489 Anim.Blending := False;
1490 g_GFX_OnceAnim(X-64, Y-64, Anim);
1491 Anim.Free();
1492 end;
1493 if Ang = 1 then
1494 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X, Y);
1495 end;
1497 NET_GFX_BFGHIT:
1498 begin
1499 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1500 begin
1501 Anim := TAnimation.Create(ID, False, 4);
1502 g_GFX_OnceAnim(X-32, Y-32, Anim);
1503 Anim.Free();
1504 end;
1505 end;
1507 NET_GFX_FIRE:
1508 begin
1509 if g_Frames_Get(ID, 'FRAMES_FIRE') 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_FIRE', X, Y);
1517 end;
1519 NET_GFX_RESPAWN:
1520 begin
1521 if g_Frames_Get(ID, 'FRAMES_ITEM_RESPAWN') then
1522 begin
1523 Anim := TAnimation.Create(ID, False, 4);
1524 g_GFX_OnceAnim(X, Y, Anim);
1525 Anim.Free();
1526 end;
1527 if Ang = 1 then
1528 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
1529 end;
1531 NET_GFX_SHELL1:
1532 g_Player_CreateShell(X, Y, 0, -2, SHELL_BULLET);
1534 NET_GFX_SHELL2:
1535 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1537 NET_GFX_SHELL3:
1538 begin
1539 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1540 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1541 end;
1542 end;
1543 end;
1545 procedure MC_RECV_Sound(var M: TMsg);
1546 var
1547 Name: string;
1548 X, Y: Integer;
1549 Pos: Boolean;
1550 begin
1551 Name := M.ReadString();
1552 Pos := M.ReadByte() <> 0;
1553 if Pos then
1554 begin
1555 X := M.ReadLongInt();
1556 Y := M.ReadLongInt();
1557 g_Sound_PlayExAt(Name, X, Y);
1558 end
1559 else
1560 g_Sound_PlayEx(Name);
1561 end;
1563 procedure MC_RECV_CreateShot(var M: TMsg);
1564 var
1565 I, X, Y, XV, YV: Integer;
1566 Timeout: LongWord;
1567 Target, Spawner: Word;
1568 ShType: Byte;
1569 begin
1570 I := M.ReadLongInt();
1571 ShType := M.ReadByte();
1572 Target := M.ReadWord();
1573 Spawner := M.ReadWord();
1574 Timeout := M.ReadLongWord();
1575 X := M.ReadLongInt();
1576 Y := M.ReadLongInt();
1577 XV := M.ReadLongInt();
1578 YV := M.ReadLongInt();
1580 I := g_Weapon_CreateShot(I, ShType, Spawner, Target, X, Y, XV, YV);
1581 if (Shots <> nil) and (I <= High(Shots)) then
1582 begin
1583 Shots[I].Timeout := Timeout;
1584 //Shots[I].Target := Target; // TODO: find a use for Target later
1585 end;
1586 end;
1588 procedure MC_RECV_UpdateShot(var M: TMsg);
1589 var
1590 I, TX, TY, TXV, TYV: Integer;
1591 begin
1592 I := M.ReadLongInt();
1593 TX := M.ReadLongInt();
1594 TY := M.ReadLongInt();
1595 TXV := M.ReadLongInt();
1596 TYV := M.ReadLongInt();
1598 if (Shots <> nil) and (I <= High(Shots)) then
1599 with (Shots[i]) do
1600 begin
1601 Obj.X := TX;
1602 Obj.Y := TY;
1603 Obj.Vel.X := TXV;
1604 Obj.Vel.Y := TYV;
1605 end;
1606 end;
1608 procedure MC_RECV_DeleteShot(var M: TMsg);
1609 var
1610 I, X, Y: Integer;
1611 L: Boolean;
1612 begin
1613 if not gGameOn then Exit;
1614 I := M.ReadLongInt();
1615 L := (M.ReadByte() <> 0);
1616 X := M.ReadLongInt();
1617 Y := M.ReadLongInt();
1619 g_Weapon_DestroyShot(I, X, Y, L);
1620 end;
1622 procedure MC_RECV_GameStats(var M: TMsg);
1623 begin
1624 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1625 begin
1626 gTeamStat[TEAM_RED].Goals := M.ReadSmallInt();
1627 gTeamStat[TEAM_BLUE].Goals := M.ReadSmallInt();
1628 end
1629 else
1630 if gGameSettings.GameMode = GM_COOP then
1631 begin
1632 gCoopMonstersKilled := M.ReadWord();
1633 gCoopSecretsFound := M.ReadWord();
1634 end;
1635 end;
1637 procedure MC_RECV_CoopStats(var M: TMsg);
1638 begin
1639 gTotalMonsters := M.ReadLongInt();
1640 gSecretsCount := M.ReadLongInt();
1641 gCoopTotalMonstersKilled := M.ReadWord();
1642 gCoopTotalSecretsFound := M.ReadWord();
1643 gCoopTotalMonsters := M.ReadWord();
1644 gCoopTotalSecrets := M.ReadWord();
1645 end;
1647 procedure MC_RECV_GameEvent(var M: TMsg);
1648 var
1649 EvType: Byte;
1650 EvNum: Integer;
1651 EvStr: string;
1652 EvTime: LongWord;
1653 BHash: Boolean;
1654 EvHash: TMD5Digest;
1655 pl: TPlayer;
1656 i1, i2: TStrings_Locale;
1657 pln: String;
1658 cnt: Byte;
1659 begin
1660 FillChar(EvHash, Sizeof(EvHash), 0);
1661 EvType := M.ReadByte();
1662 EvNum := M.ReadLongInt();
1663 EvStr := M.ReadString();
1664 gLastMap := M.ReadByte() <> 0;
1665 if gLastMap and (gGameSettings.GameMode = GM_COOP) then gStatsOff := True;
1666 gStatsPressed := True;
1667 EvTime := M.ReadLongWord();
1668 BHash := M.ReadByte() <> 0;
1669 if BHash then
1670 EvHash := M.ReadMD5();
1672 gTime := EvTime;
1674 case EvType of
1675 NET_EV_MAPSTART:
1676 begin
1677 gGameOn := False;
1678 g_Game_ClearLoading();
1679 g_Game_StopAllSounds(True);
1681 gSwitchGameMode := Byte(EvNum);
1682 gGameSettings.GameMode := gSwitchGameMode;
1684 gWADHash := EvHash;
1685 if not g_Game_StartMap(EvStr, True) then
1686 begin
1687 if not isWadPath(EvStr) then
1688 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + EvStr]))
1689 else
1690 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [EvStr]));
1691 Exit;
1692 end;
1694 MC_SEND_FullStateRequest;
1695 end;
1697 NET_EV_MAPEND:
1698 begin
1699 gMissionFailed := EvNum <> 0;
1700 gExit := EXIT_ENDLEVELCUSTOM;
1701 end;
1703 NET_EV_RCON:
1704 begin
1705 case EvNum of
1706 NET_RCON_NOAUTH:
1707 g_Console_Add(_lc[I_NET_RCON_NOAUTH], True);
1708 NET_RCON_PWGOOD:
1709 g_Console_Add(_lc[I_NET_RCON_PWD_VALID], True);
1710 NET_RCON_PWBAD:
1711 g_Console_Add(_lc[I_NET_RCON_PWD_INVALID], True);
1712 end;
1713 end;
1715 NET_EV_CHANGE_TEAM:
1716 begin
1717 if EvNum = TEAM_RED then
1718 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True);
1719 if EvNum = TEAM_BLUE then
1720 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True);
1721 end;
1723 NET_EV_PLAYER_KICK:
1724 g_Console_Add(Format(_lc[I_PLAYER_KICK], [EvStr]), True);
1726 NET_EV_PLAYER_BAN:
1727 g_Console_Add(Format(_lc[I_PLAYER_BAN], [EvStr]), True);
1729 NET_EV_LMS_WARMUP:
1730 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [EvNum]), True);
1732 NET_EV_LMS_SURVIVOR:
1733 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True);
1735 NET_EV_BIGTEXT:
1736 g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum));
1738 NET_EV_SCORE:
1739 begin
1740 pl := g_Player_Get(EvNum and $FFFF);
1741 if pl = nil then
1742 pln := '?'
1743 else
1744 pln := pl.Name;
1745 cnt := (EvNum shr 16) and $FF;
1746 if Pos('w', EvStr) = 0 then
1747 begin
1748 // Default score
1749 if Pos('t', EvStr) = 0 then
1750 begin
1751 // Player +/- score
1752 if Pos('-', EvStr) = 0 then
1753 begin
1754 if Pos('e', EvStr) = 0 then
1755 i1 := I_PLAYER_SCORE_ADD_OWN
1756 else
1757 i1 := I_PLAYER_SCORE_ADD_ENEMY;
1758 end else
1759 begin
1760 if Pos('e', EvStr) = 0 then
1761 i1 := I_PLAYER_SCORE_SUB_OWN
1762 else
1763 i1 := I_PLAYER_SCORE_SUB_ENEMY;
1764 end;
1765 // Which team
1766 if Pos('r', EvStr) > 0 then
1767 i2 := I_PLAYER_SCORE_TO_RED
1768 else
1769 i2 := I_PLAYER_SCORE_TO_BLUE;
1770 g_Console_Add(Format(_lc[i1], [pln, cnt, _lc[i2]]), True);
1771 end else
1772 begin
1773 // Team +/- score
1774 if Pos('-', EvStr) = 0 then
1775 i1 := I_PLAYER_SCORE_ADD_TEAM
1776 else
1777 i1 := I_PLAYER_SCORE_SUB_TEAM;
1778 // Which team
1779 if Pos('r', EvStr) > 0 then
1780 i2 := I_PLAYER_SCORE_RED
1781 else
1782 i2 := I_PLAYER_SCORE_BLUE;
1783 g_Console_Add(Format(_lc[i1], [_lc[i2], cnt]), True);
1784 end;
1785 end else
1786 begin
1787 // Game Win
1788 if Pos('e', EvStr) = 0 then
1789 i1 := I_PLAYER_SCORE_WIN_OWN
1790 else
1791 i1 := I_PLAYER_SCORE_WIN_ENEMY;
1792 // Which team
1793 if Pos('r', EvStr) > 0 then
1794 i2 := I_PLAYER_SCORE_TO_RED
1795 else
1796 i2 := I_PLAYER_SCORE_TO_BLUE;
1797 g_Console_Add(Format(_lc[i1], [pln, _lc[i2]]), True);
1798 end;
1799 end;
1801 NET_EV_SCORE_MSG:
1802 begin
1803 if EvNum = TEAM_RED then
1804 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1805 if EvNum = TEAM_BLUE then
1806 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1807 if EvNum = -TEAM_RED then
1808 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1809 if EvNum = -TEAM_BLUE then
1810 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1811 end;
1813 NET_EV_LMS_START:
1814 begin
1815 g_Player_RemoveAllCorpses;
1816 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
1817 end;
1819 NET_EV_LMS_WIN:
1820 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(EvStr)]), 144);
1822 NET_EV_TLMS_WIN:
1823 begin
1824 if EvNum = TEAM_RED then
1825 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
1826 if EvNum = TEAM_BLUE then
1827 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
1828 end;
1830 NET_EV_LMS_LOSE:
1831 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
1833 NET_EV_LMS_DRAW:
1834 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
1836 NET_EV_KILLCOMBO:
1837 g_Game_Announce_KillCombo(EvNum);
1839 NET_EV_PLAYER_TOUCH:
1840 begin
1841 pl := g_Player_Get(EvNum);
1842 if pl <> nil then
1843 pl.Touch();
1844 end;
1846 end;
1847 end;
1849 procedure MC_RECV_FlagEvent(var M: TMsg);
1850 var
1851 PID: Word;
1852 Pl: TPlayer;
1853 EvType: Byte;
1854 Fl: Byte;
1855 Quiet: Boolean;
1856 s, ts: string;
1857 begin
1858 EvType := M.ReadByte();
1859 Fl := M.ReadByte();
1861 if Fl = FLAG_NONE then Exit;
1863 Quiet := (M.ReadByte() <> 0);
1864 PID := M.ReadWord();
1866 gFlags[Fl].State := M.ReadByte();
1867 gFlags[Fl].CaptureTime := M.ReadLongWord();
1868 gFlags[Fl].Obj.X := M.ReadLongInt();
1869 gFlags[Fl].Obj.Y := M.ReadLongInt();
1870 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
1871 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
1873 Pl := g_Player_Get(PID);
1874 if (Pl = nil) and
1875 (EvType <> FLAG_STATE_NORMAL) and
1876 (EvType <> FLAG_STATE_DROPPED) and
1877 (EvType <> FLAG_STATE_RETURNED) then
1878 Exit;
1880 case EvType of
1881 FLAG_STATE_NORMAL:
1882 begin
1883 if Quiet or (Pl = nil) then Exit;
1885 if Fl = FLAG_RED then
1886 s := _lc[I_PLAYER_FLAG_RED]
1887 else
1888 s := _lc[I_PLAYER_FLAG_BLUE];
1890 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
1891 end;
1893 FLAG_STATE_CAPTURED:
1894 begin
1895 if (Pl <> nil) then Pl.SetFlag(Fl);
1897 if Quiet then Exit;
1899 if Fl = FLAG_RED then
1900 s := _lc[I_PLAYER_FLAG_RED]
1901 else
1902 s := _lc[I_PLAYER_FLAG_BLUE];
1904 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [Pl.Name, s]), True);
1905 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
1906 end;
1908 FLAG_STATE_DROPPED:
1909 begin
1910 if (Pl <> nil) then Pl.SetFlag(FLAG_NONE);
1912 if Quiet or (Pl = nil) then Exit;
1914 if Fl = FLAG_RED then
1915 s := _lc[I_PLAYER_FLAG_RED]
1916 else
1917 s := _lc[I_PLAYER_FLAG_BLUE];
1919 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [Pl.Name, s]), True);
1920 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
1921 end;
1923 FLAG_STATE_SCORED:
1924 begin
1925 g_Map_ResetFlag(FLAG_RED);
1926 g_Map_ResetFlag(FLAG_BLUE);
1927 if Quiet or (Pl = nil) then Exit;
1928 Pl.SetFlag(FLAG_NONE);
1930 if Fl = FLAG_RED then
1931 s := _lc[I_PLAYER_FLAG_RED]
1932 else
1933 s := _lc[I_PLAYER_FLAG_BLUE];
1935 ts := Format('%.4d', [gFlags[Fl].CaptureTime]);
1936 Insert('.', ts, Length(ts) + 1 - 3);
1937 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [Pl.Name, s, ts]), True);
1938 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
1939 end;
1941 FLAG_STATE_RETURNED:
1942 begin
1943 g_Map_ResetFlag(Fl);
1944 if Quiet then Exit;
1946 if Fl = FLAG_RED then
1947 s := _lc[I_PLAYER_FLAG_RED]
1948 else
1949 s := _lc[I_PLAYER_FLAG_BLUE];
1951 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
1952 end;
1953 end;
1954 end;
1956 procedure MC_RECV_GameSettings(var M: TMsg);
1957 begin
1958 gGameSettings.GameMode := M.ReadByte();
1959 gGameSettings.GoalLimit := M.ReadWord();
1960 gGameSettings.TimeLimit := M.ReadWord();
1961 gGameSettings.MaxLives := M.ReadByte();
1962 gGameSettings.Options := M.ReadLongWord();
1963 end;
1965 // PLAYER
1967 function MC_RECV_PlayerCreate(var M: TMsg): Word;
1968 var
1969 PID, DID: Word;
1970 PName, Model: string;
1971 Color: TRGB;
1972 T: Byte;
1973 Pl: TPlayer;
1974 begin
1975 PID := M.ReadWord();
1976 Pl := g_Player_Get(PID);
1978 PName := M.ReadString();
1979 Model := M.ReadString();
1980 Color.R := M.ReadByte();
1981 Color.G := M.ReadByte();
1982 Color.B := M.ReadByte();
1983 T := M.ReadByte();
1985 Result := 0;
1986 if (PID <> NetPlrUID1) and (PID <> NetPlrUID2) then
1987 begin
1988 if (Pl <> nil) then Exit;
1989 DID := g_Player_Create(Model, Color, T, False);
1990 with g_Player_Get(DID) do
1991 begin
1992 UID := PID;
1993 Name := PName;
1994 Reset(True);
1995 end;
1996 end
1997 else
1998 begin
1999 if (PID = NetPlrUID1) and (gPlayer1 <> nil) then begin
2000 gPlayer1.UID := PID;
2001 gPlayer1.Model.SetColor(Color.R, Color.G, Color.B);
2002 gPlayer1.ChangeTeam(T);
2003 end;
2004 if (PID = NetPlrUID2) and (gPlayer2 <> nil) then begin
2005 gPlayer2.UID := PID;
2006 gPlayer2.Model.SetColor(Color.R, Color.G, Color.B);
2007 gPlayer2.ChangeTeam(T);
2008 end;
2009 end;
2011 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
2012 e_WriteLog('NET: Player ' + PName + ' [' + IntToStr(PID) + '] added.', TMsgType.Notify);
2013 Result := PID;
2014 end;
2016 function MC_RECV_PlayerPos(var M: TMsg): Word;
2017 var
2018 GT: LongWord;
2019 PID: Word;
2020 kByte: Word;
2021 Pl: TPlayer;
2022 Dir: Byte;
2023 TmpX, TmpY: Integer;
2024 begin
2025 Result := 0;
2027 GT := M.ReadLongWord();
2028 if GT < gTime - NET_MAX_DIFFTIME then
2029 begin
2030 gTime := GT;
2031 Exit;
2032 end;
2033 gTime := GT;
2035 PID := M.ReadWord();
2036 Pl := g_Player_Get(PID);
2038 if Pl = nil then Exit;
2040 Result := PID;
2042 with Pl do
2043 begin
2044 FPing := M.ReadWord();
2045 FLoss := M.ReadByte();
2046 kByte := M.ReadWord();
2047 Dir := M.ReadByte();
2049 TmpX := M.ReadLongInt();
2050 TmpY := M.ReadLongInt();
2052 ReleaseKeysNoWeapon;
2054 if (kByte = NET_KEY_CHAT) then
2055 PressKey(KEY_CHAT, 10000)
2056 else
2057 begin
2058 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
2059 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
2060 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
2061 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
2062 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
2063 end;
2065 if ((Pl <> gPlayer1) and (Pl <> gPlayer2)) or LongBool(kByte and NET_KEY_FORCEDIR) then
2066 SetDirection(TDirection(Dir));
2068 GameVelX := M.ReadLongInt();
2069 GameVelY := M.ReadLongInt();
2070 GameAccelX := M.ReadLongInt();
2071 GameAccelY := M.ReadLongInt();
2072 SetLerp(TmpX, TmpY);
2073 if NetForcePlayerUpdate then Update();
2074 end;
2075 end;
2077 function MC_RECV_PlayerStats(var M: TMsg): Word;
2078 var
2079 PID: Word;
2080 Pl: TPlayer;
2081 I: Integer;
2082 OldJet: Boolean;
2083 NewTeam: Byte;
2084 ww: Word;
2085 begin
2086 PID := M.ReadWord();
2087 Pl := g_Player_Get(PID);
2088 Result := 0;
2089 if Pl = nil then
2090 Exit;
2092 with Pl do
2093 begin
2094 alive := (M.ReadByte() <> 0);
2095 GodMode := (M.ReadByte() <> 0);
2096 Health := M.ReadLongInt();
2097 Armor := M.ReadLongInt();
2098 Air := M.ReadLongInt();
2099 JetFuel := M.ReadLongInt();
2100 Lives := M.ReadByte();
2101 NewTeam := M.ReadByte();
2103 ww := M.ReadWord();
2104 for I := WP_FIRST to WP_LAST do
2105 begin
2106 FWeapon[I] := ((ww and $01) <> 0);
2107 ww := ww shr 1;
2108 end;
2110 for I := A_BULLETS to A_HIGH do
2111 FAmmo[I] := M.ReadWord();
2113 for I := A_BULLETS to A_HIGH do
2114 FMaxAmmo[I] := M.ReadWord();
2116 for I := MR_SUIT to MR_MAX do
2117 FMegaRulez[I] := M.ReadLongWord();
2119 FRulez := [];
2120 // unpack special flags
2121 ww := M.ReadByte();
2122 if ((ww and $01) <> 0) then FRulez := FRulez+[R_ITEM_BACKPACK];
2123 if ((ww and $02) <> 0) then FRulez := FRulez+[R_KEY_RED];
2124 if ((ww and $04) <> 0) then FRulez := FRulez+[R_KEY_GREEN];
2125 if ((ww and $08) <> 0) then FRulez := FRulez+[R_KEY_BLUE];
2126 if ((ww and $10) <> 0) then FRulez := FRulez+[R_BERSERK];
2128 Frags := M.ReadLongInt();
2129 Death := M.ReadLongInt();
2131 SetWeapon(M.ReadByte());
2133 // other flags
2134 ww := M.ReadByte();
2136 FSpectator := ((ww and $01) <> 0);
2137 if FSpectator then
2138 begin
2139 if Pl = gPlayer1 then
2140 begin
2141 gLMSPID1 := UID;
2142 gPlayer1 := nil;
2143 end;
2144 if Pl = gPlayer2 then
2145 begin
2146 gLMSPID2 := UID;
2147 gPlayer2 := nil;
2148 end;
2149 end
2150 else
2151 begin
2152 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
2153 gPlayer1 := g_Player_Get(gLMSPID1);
2154 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
2155 gPlayer2 := g_Player_Get(gLMSPID2);
2156 end;
2158 FGhost := ((ww and $02) <> 0);
2159 FPhysics := ((ww and $04) <> 0);
2160 FNoRespawn := ((ww and $08) <> 0);
2161 OldJet := FJetpack;
2162 FJetpack := ((ww and $10) <> 0);
2163 FFireTime := M.ReadLongInt();
2164 if OldJet and not FJetpack then
2165 JetpackOff
2166 else if not OldJet and FJetpack then
2167 JetpackOn;
2168 if Team <> NewTeam then
2169 Pl.ChangeTeam(NewTeam);
2170 end;
2172 Result := PID;
2173 end;
2175 function MC_RECV_PlayerDamage(var M: TMsg): Word;
2176 var
2177 PID: Word;
2178 Pl: TPlayer;
2179 Kind: Byte;
2180 Attacker, Value: Word;
2181 VX, VY: Integer;
2182 begin
2183 Result := 0;
2184 if not gGameOn then Exit;
2185 PID := M.ReadWord();
2186 Pl := g_Player_Get(PID);
2187 if Pl = nil then Exit;
2189 Kind := M.ReadByte();
2190 Attacker := M.ReadWord();
2191 Value := M.ReadWord();
2192 VX := M.ReadWord();
2193 VY := M.ReadWord();
2195 with Pl do
2196 Damage(Value, Attacker, VX, VY, Kind);
2198 Result := PID;
2199 end;
2201 function MC_RECV_PlayerDeath(var M: TMsg): Word;
2202 var
2203 PID: Word;
2204 Pl: TPlayer;
2205 KillType, DeathType: Byte;
2206 Attacker: Word;
2207 begin
2208 Result := 0;
2209 if not gGameOn then Exit;
2210 PID := M.ReadWord();
2211 Pl := g_Player_Get(PID);
2212 if Pl = nil then Exit;
2214 KillType := M.ReadByte();
2215 DeathType := M.ReadByte();
2216 Attacker := M.ReadWord();
2218 with Pl do
2219 begin
2220 Kill(KillType, Attacker, DeathType);
2221 SoftReset;
2222 end;
2223 end;
2225 function MC_RECV_PlayerDelete(var M: TMsg): Word;
2226 var
2227 PID: Word;
2228 Pl: TPlayer;
2229 begin
2230 PID := M.ReadWord();
2231 Pl := g_Player_Get(PID);
2232 Result := 0;
2233 if Pl = nil then Exit;
2235 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2236 e_WriteLog('NET: Player ' + Pl.Name + ' [' + IntToStr(PID) + '] removed.', TMsgType.Notify);
2238 g_Player_Remove(PID);
2240 Result := PID;
2241 end;
2243 function MC_RECV_PlayerFire(var M: TMsg): Word;
2244 var
2245 PID: Word;
2246 Weap: Byte;
2247 Pl: TPlayer;
2248 X, Y, AX, AY: Integer;
2249 SHID: Integer;
2250 begin
2251 Result := 0;
2252 if not gGameOn then Exit;
2253 PID := M.ReadWord();
2254 Pl := g_Player_Get(PID);
2255 if Pl = nil then Exit;
2257 Weap := M.ReadByte();
2258 X := M.ReadLongInt();
2259 Y := M.ReadLongInt();
2260 AX := M.ReadLongInt();
2261 AY := M.ReadLongInt();
2262 SHID := M.ReadLongInt();
2264 with Pl do
2265 if alive then NetFire(Weap, X, Y, AX, AY, SHID);
2266 end;
2268 procedure MC_RECV_PlayerSettings(var M: TMsg);
2269 var
2270 TmpName: string;
2271 TmpModel: string;
2272 TmpColor: TRGB;
2273 TmpTeam: Byte;
2274 Pl: TPlayer;
2275 PID: Word;
2276 begin
2277 PID := M.ReadWord();
2278 Pl := g_Player_Get(PID);
2279 if Pl = nil then Exit;
2281 TmpName := M.ReadString();
2282 TmpModel := M.ReadString();
2283 TmpColor.R := M.ReadByte();
2284 TmpColor.G := M.ReadByte();
2285 TmpColor.B := M.ReadByte();
2286 TmpTeam := M.ReadByte();
2288 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
2289 begin
2290 Pl.ChangeTeam(TmpTeam);
2291 if gPlayer1 = Pl then
2292 gPlayer1Settings.Team := TmpTeam;
2293 if gPlayer2 = Pl then
2294 gPlayer2Settings.Team := TmpTeam;
2295 end else
2296 Pl.SetColor(TmpColor);
2298 if Pl.Name <> TmpName then
2299 begin
2300 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
2301 Pl.Name := TmpName;
2302 end;
2304 if TmpModel <> Pl.Model.Name then
2305 Pl.SetModel(TmpModel);
2306 end;
2308 // ITEM
2310 procedure MC_RECV_ItemSpawn(var M: TMsg);
2311 var
2312 ID: Word;
2313 AID: DWord;
2314 X, Y, VX, VY: Integer;
2315 T: Byte;
2316 Quiet, Fall{, Resp}: Boolean;
2317 Anim: TAnimation;
2318 it: PItem;
2319 begin
2320 if not gGameOn then Exit;
2321 ID := M.ReadWord();
2322 Quiet := M.ReadByte() <> 0;
2323 T := M.ReadByte();
2324 Fall := M.ReadByte() <> 0;
2325 {Resp :=} M.ReadByte();
2326 X := M.ReadLongInt();
2327 Y := M.ReadLongInt();
2328 VX := M.ReadLongInt();
2329 VY := M.ReadLongInt();
2331 g_Items_Create(X, Y, T and $7F, Fall, False, False, ID);
2332 if ((T and $80) <> 0) then g_Items_SetDrop(ID);
2334 it := g_Items_ByIdx(ID);
2335 it.Obj.Vel.X := VX;
2336 it.Obj.Vel.Y := VY;
2338 if not Quiet then
2339 begin
2340 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
2341 if g_Frames_Get(AID, 'FRAMES_ITEM_RESPAWN') then
2342 begin
2343 Anim := TAnimation.Create(AID, False, 4);
2344 g_GFX_OnceAnim(X+(it.Obj.Rect.Width div 2)-16, Y+(it.Obj.Rect.Height div 2)-16, Anim);
2345 Anim.Free();
2346 end;
2347 end;
2348 end;
2350 procedure MC_RECV_ItemDestroy(var M: TMsg);
2351 var
2352 ID: Word;
2353 Quiet: Boolean;
2354 begin
2355 if not gGameOn then Exit;
2356 ID := M.ReadWord();
2357 Quiet := M.ReadByte() <> 0;
2359 if not g_Items_ValidId(ID) then exit;
2361 if not Quiet then g_Items_EmitPickupSound(ID);
2363 g_Items_Remove(ID);
2364 end;
2366 // PANEL
2368 procedure MC_RECV_PanelTexture(var M: TMsg);
2369 var
2370 TP: TPanel;
2371 PGUID: Integer;
2372 Tex, Fr: Integer;
2373 Loop, Cnt: Byte;
2374 begin
2375 if not gGameOn then Exit;
2377 PGUID := Integer(M.ReadLongWord());
2378 Tex := M.ReadLongInt();
2379 Fr := M.ReadLongInt();
2380 Cnt := M.ReadByte();
2381 Loop := M.ReadByte();
2383 TP := g_Map_PanelByGUID(PGUID);
2384 if (TP <> nil) then
2385 begin
2386 // switch texture
2387 TP.SetTexture(Tex, Loop);
2388 TP.SetFrame(Fr, Cnt);
2389 end;
2390 end;
2392 procedure MC_RECV_PanelState(var M: TMsg);
2393 var
2394 PGUID: Integer;
2395 E: Boolean;
2396 Lift: Byte;
2397 X, Y, W, H: Integer;
2398 TP: TPanel;
2399 speedX, speedY, startX, startY, endX, endY: Integer;
2400 sizeSpX, sizeSpY, sizeEX, sizeEY: Integer;
2401 mpflags: Byte;
2402 begin
2403 if not gGameOn then Exit;
2405 PGUID := Integer(M.ReadLongWord());
2406 E := (M.ReadByte() <> 0);
2407 Lift := M.ReadByte();
2408 X := M.ReadLongInt();
2409 Y := M.ReadLongInt();
2410 W := M.ReadWord();
2411 H := M.ReadWord();
2412 // mplats
2413 speedX := M.ReadLongInt();
2414 speedY := M.ReadLongInt();
2415 startX := M.ReadLongInt();
2416 startY := M.ReadLongInt();
2417 endX := M.ReadLongInt();
2418 endY := M.ReadLongInt();
2419 sizeSpX := M.ReadLongInt();
2420 sizeSpY := M.ReadLongInt();
2421 sizeEX := M.ReadLongInt();
2422 sizeEY := M.ReadLongInt();
2423 mpflags := M.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2425 TP := g_Map_PanelByGUID(PGUID);
2426 if (TP = nil) then exit;
2428 // update lifts state
2429 if TP.isGLift then g_Map_SetLiftGUID(PGUID, Lift);
2431 // update enabled/disabled state for all panels
2432 if E then g_Map_EnableWallGUID(PGUID) else g_Map_DisableWallGUID(PGUID);
2434 // update panel position, as it can be moved (mplat)
2435 TP.X := X;
2436 TP.Y := Y;
2437 TP.Width := W;
2438 TP.Height := H;
2439 // update mplat state
2440 TP.movingSpeedX := speedX;
2441 TP.movingSpeedY := speedY;
2442 TP.movingStartX := startX;
2443 TP.movingStartY := startY;
2444 TP.movingEndX := endX;
2445 TP.movingEndY := endY;
2446 TP.sizeSpeedX := sizeSpX;
2447 TP.sizeSpeedY := sizeSpY;
2448 TP.sizeEndX := sizeEX;
2449 TP.sizeEndY := sizeEY;
2450 TP.movingActive := ((mpflags and 1) <> 0);
2451 TP.moveOnce := ((mpflags and 2) <> 0);
2452 // notify panel of it's position/size change, so it can fix other internal structures
2453 TP.positionChanged();
2454 end;
2456 // TRIGGERS
2458 procedure MC_RECV_TriggerSound(var M: TMsg);
2459 var
2460 SPlaying: Boolean;
2461 SPos, SID: LongWord;
2462 SCount: LongInt;
2463 I: Integer;
2464 begin
2465 if not gGameOn then Exit;
2466 if gTriggers = nil then Exit;
2468 SID := M.ReadLongWord();
2469 SPlaying := M.ReadByte() <> 0;
2470 SPos := M.ReadLongWord();
2471 SCount := M.ReadLongInt();
2473 for I := Low(gTriggers) to High(gTriggers) do
2474 if gTriggers[I].TriggerType = TRIGGER_SOUND then
2475 if gTriggers[I].ClientID = SID then
2476 with gTriggers[I] do
2477 begin
2478 if Sound <> nil then
2479 begin
2480 if SPlaying then
2481 begin
2482 if tgcLocal then
2483 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), tgcVolume/255.0)
2484 else
2485 Sound.PlayPanVolume((tgcPan-127.0)/128.0, tgcVolume/255.0);
2486 Sound.SetPosition(SPos);
2487 end
2488 else
2489 if Sound.IsPlaying then Sound.Stop;
2490 end;
2492 SoundPlayCount := SCount;
2493 end;
2494 end;
2496 procedure MC_RECV_TriggerMusic(var M: TMsg);
2497 var
2498 MName: string;
2499 MPlaying: Boolean;
2500 MPos: LongWord;
2501 MPaused: Boolean;
2502 begin
2503 if not gGameOn then Exit;
2505 MName := M.ReadString();
2506 MPlaying := M.ReadByte() <> 0;
2507 MPos := M.ReadLongWord();
2508 MPaused := M.ReadByte() <> 0;
2510 if MPlaying then
2511 begin
2512 gMusic.SetByName(MName);
2513 gMusic.Play(True);
2514 gMusic.SetPosition(MPos);
2515 gMusic.SpecPause := MPaused;
2516 end
2517 else
2518 if gMusic.IsPlaying then gMusic.Stop;
2519 end;
2521 // MONSTERS
2523 procedure MC_RECV_MonsterSpawn(var M: TMsg);
2524 var
2525 ID: Word;
2526 MType, MState, MDir, MAnim, MBehav: Byte;
2527 X, Y, VX, VY, MTargTime, MHealth, MAmmo, MSleep: Integer;
2528 MTarg: Word;
2529 Mon: TMonster;
2530 begin
2531 ID := M.ReadWord();
2532 Mon := g_Monsters_ByUID(ID);
2533 if Mon <> nil then
2534 Exit;
2536 MType := M.ReadByte();
2537 MState := M.ReadByte();
2538 MAnim := M.ReadByte();
2539 MTarg := M.ReadWord();
2540 MTargTime := M.ReadLongInt();
2541 MBehav := M.ReadByte();
2542 MSleep := M.ReadLongInt();
2543 MHealth := M.ReadLongInt();
2544 MAmmo := M.ReadLongInt();
2546 X := M.ReadLongInt();
2547 Y := M.ReadLongInt();
2548 VX := M.ReadLongInt();
2549 VY := M.ReadLongInt();
2550 MDir := M.ReadByte();
2552 g_Monsters_Create(MType, X, Y, TDirection(MDir), False, ID);
2553 Mon := g_Monsters_ByUID(ID);
2554 if Mon = nil then
2555 Exit;
2557 with Mon do
2558 begin
2560 MonsterAnim := MAnim;
2561 MonsterTargetUID := MTarg;
2562 MonsterTargetTime := MTargTime;
2563 MonsterBehaviour := MBehav;
2564 MonsterSleep := MSleep;
2565 MonsterAmmo := MAmmo;
2566 SetHealth(MHealth);
2568 SetState(MState);
2570 setPosition(X, Y); // this will call positionChanged();
2571 GameVelX := VX;
2572 GameVelY := VY;
2573 end;
2574 end;
2576 procedure MC_RECV_MonsterPos(var M: TMsg);
2577 var
2578 Mon: TMonster;
2579 ID: Word;
2580 X, Y: Integer;
2581 begin
2582 ID := M.ReadWord();
2583 Mon := g_Monsters_ByUID(ID);
2584 if Mon = nil then
2585 Exit;
2587 with Mon do
2588 begin
2589 X := M.ReadLongInt();
2590 Y := M.ReadLongInt();
2591 Mon.setPosition(X, Y); // this will call `positionChanged()`
2592 GameVelX := M.ReadLongInt();
2593 GameVelY := M.ReadLongInt();
2594 GameDirection := TDirection(M.ReadByte());
2595 end;
2596 end;
2598 procedure MC_RECV_MonsterState(var M: TMsg);
2599 var
2600 ID: Integer;
2601 MState, MFAnm: Byte;
2602 Mon: TMonster;
2603 AnimRevert: Boolean;
2604 begin
2605 ID := M.ReadWord();
2606 Mon := g_Monsters_ByUID(ID);
2607 if Mon = nil then Exit;
2609 MState := M.ReadByte();
2610 MFAnm := M.ReadByte();
2612 with Mon do
2613 begin
2614 MonsterTargetUID := M.ReadWord();
2615 MonsterTargetTime := M.ReadLongInt();
2616 MonsterSleep := M.ReadLongInt();
2617 MonsterHealth := M.ReadLongInt();
2618 MonsterAmmo := M.ReadLongInt();
2619 MonsterPain := M.ReadLongInt();
2620 AnimRevert := M.ReadByte() <> 0;
2621 FFireTime := M.ReadLongInt();
2622 RevertAnim(AnimRevert);
2624 if MonsterState <> MState then
2625 begin
2626 if (MState = MONSTATE_GO) and (MonsterState = MONSTATE_SLEEP) then WakeUpSound();
2627 if (MState = MONSTATE_DIE) then DieSound();
2628 if (MState = MONSTATE_PAIN) then MakeBloodSimple(Min(200, MonsterPain));
2629 if (MState = MONSTATE_ATTACK) then kick(nil);
2630 if (MState = MONSTATE_DEAD) then SetDeadAnim();
2632 SetState(MState, MFAnm);
2633 end;
2634 end;
2635 end;
2637 procedure MC_RECV_MonsterShot(var M: TMsg);
2638 var
2639 ID: Integer;
2640 Mon: TMonster;
2641 X, Y, VX, VY: Integer;
2642 begin
2643 ID := M.ReadWord();
2645 Mon := g_Monsters_ByUID(ID);
2646 if Mon = nil then Exit;
2648 X := M.ReadLongInt();
2649 Y := M.ReadLongInt();
2650 VX := M.ReadLongInt();
2651 VY := M.ReadLongInt();
2653 Mon.ClientAttack(X, Y, VX, VY);
2654 end;
2656 procedure MC_RECV_MonsterDelete(var M: TMsg);
2657 var
2658 ID: Integer;
2659 Mon: TMonster;
2660 begin
2661 ID := M.ReadWord();
2662 Mon := g_Monsters_ByUID(ID);
2663 if Mon = nil then Exit;
2664 Mon.SetState(5);
2665 Mon.MonsterRemoved := True;
2666 end;
2668 procedure MC_RECV_TimeSync(var M: TMsg);
2669 var
2670 Time: LongWord;
2671 begin
2672 Time := M.ReadLongWord();
2674 if gState = STATE_INTERCUSTOM then
2675 gServInterTime := Min(Time, 255);
2676 end;
2678 procedure MC_RECV_VoteEvent(var M: TMsg);
2679 var
2680 EvID: Byte;
2681 Str1, Str2: string;
2682 Int1, Int2: SmallInt;
2683 begin
2684 EvID := M.ReadByte();
2685 Int1 := M.ReadSmallInt();
2686 Int2 := M.ReadSmallInt();
2687 Str1 := M.ReadString();
2688 Str2 := M.ReadString();
2690 case EvID of
2691 NET_VE_STARTED:
2692 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True);
2693 NET_VE_PASSED:
2694 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True);
2695 NET_VE_FAILED:
2696 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
2697 NET_VE_VOTE:
2698 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True);
2699 NET_VE_INPROGRESS:
2700 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True);
2701 end;
2702 end;
2704 // CLIENT SEND
2706 procedure MC_SEND_Info(Password: string);
2707 begin
2708 NetOut.Clear();
2710 NetOut.Write(Byte(NET_MSG_INFO));
2711 NetOut.Write(GAME_VERSION);
2712 NetOut.Write(Password);
2713 NetOut.Write(gPlayer1Settings.Name);
2714 NetOut.Write(gPlayer1Settings.Model);
2715 NetOut.Write(gPlayer1Settings.Color.R);
2716 NetOut.Write(gPlayer1Settings.Color.G);
2717 NetOut.Write(gPlayer1Settings.Color.B);
2718 NetOut.Write(gPlayer1Settings.Team);
2720 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2721 end;
2723 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
2724 begin
2725 NetOut.Write(Byte(NET_MSG_CHAT));
2726 NetOut.Write(Txt);
2727 NetOut.Write(Mode);
2729 g_Net_Client_Send(True, NET_CHAN_CHAT);
2730 end;
2732 function isKeyPressed (key1: Word; key2: Word): Boolean;
2733 begin
2734 if (key1 <> 0) and e_KeyPressed(key1) then begin result := true; exit; end;
2735 if (key2 <> 0) and e_KeyPressed(key2) then begin result := true; exit; end;
2736 result := false;
2737 end;
2739 procedure MC_SEND_PlayerPos();
2740 var
2741 kByte: Word;
2742 Predict: Boolean;
2743 strafeDir: Byte;
2744 //WeaponSelect: Word = 0;
2745 I: Integer;
2746 begin
2747 if not gGameOn then Exit;
2748 if gPlayers = nil then Exit;
2749 if gPlayer1 = nil then Exit;
2751 kByte := 0;
2752 Predict := NetPredictSelf; // and (not NetGotKeys);
2754 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2755 begin
2756 strafeDir := P1MoveButton shr 4;
2757 P1MoveButton := P1MoveButton and $0F;
2758 with gGameControls.P1Control do
2759 begin
2760 if isKeyPressed(KeyLeft, KeyLeft2) and (not isKeyPressed(KeyRight, KeyRight2)) then P1MoveButton := 1
2761 else if (not isKeyPressed(KeyLeft, KeyLeft2)) and isKeyPressed(KeyRight, KeyRight2) then P1MoveButton := 2
2762 else if (not isKeyPressed(KeyLeft, KeyLeft2)) and (not isKeyPressed(KeyRight, KeyRight2)) then P1MoveButton := 0;
2764 // strafing
2765 if isKeyPressed(KeyStrafe, KeyStrafe2) then
2766 begin
2767 // new strafe mechanics
2768 if (strafeDir = 0) then strafeDir := P1MoveButton; // start strafing
2769 // now set direction according to strafe (reversed)
2770 if (strafeDir = 2) then gPlayer1.SetDirection(TDirection.D_LEFT)
2771 else if (strafeDir = 1) then gPlayer1.SetDirection(TDirection.D_RIGHT);
2772 end
2773 else
2774 begin
2775 if (P1MoveButton = 2) and isKeyPressed(KeyLeft, KeyLeft2) then gPlayer1.SetDirection(TDirection.D_LEFT)
2776 else if (P1MoveButton = 1) and isKeyPressed(KeyRight, KeyRight2) then gPlayer1.SetDirection(TDirection.D_RIGHT)
2777 else if P1MoveButton <> 0 then gPlayer1.SetDirection(TDirection(P1MoveButton-1));
2778 end;
2780 gPlayer1.ReleaseKeys;
2781 gPlayer1.weaponSwitchKeysStateChange(-1, isKeyPressed(KeyNextWeapon, KeyNextWeapon2));
2782 gPlayer1.weaponSwitchKeysStateChange(-2, isKeyPressed(KeyPrevWeapon, KeyPrevWeapon2));
2784 if P1MoveButton = 1 then
2785 begin
2786 kByte := kByte or NET_KEY_LEFT;
2787 if Predict then gPlayer1.PressKey(KEY_LEFT, 10000);
2788 end;
2789 if P1MoveButton = 2 then
2790 begin
2791 kByte := kByte or NET_KEY_RIGHT;
2792 if Predict then gPlayer1.PressKey(KEY_RIGHT, 10000);
2793 end;
2794 if isKeyPressed(KeyUp, KeyUp2) then
2795 begin
2796 kByte := kByte or NET_KEY_UP;
2797 gPlayer1.PressKey(KEY_UP, 10000);
2798 end;
2799 if isKeyPressed(KeyDown, KeyDown2) then
2800 begin
2801 kByte := kByte or NET_KEY_DOWN;
2802 gPlayer1.PressKey(KEY_DOWN, 10000);
2803 end;
2804 if isKeyPressed(KeyJump, KeyJump2) then
2805 begin
2806 kByte := kByte or NET_KEY_JUMP;
2807 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2808 end;
2809 if isKeyPressed(KeyFire, KeyFire2) then kByte := kByte or NET_KEY_FIRE;
2810 if isKeyPressed(KeyOpen, KeyOpen2) then kByte := kByte or NET_KEY_OPEN;
2811 // do not send weapon switch keys, `MH_SEND_PlayerStats()` will send changed weapon anyway
2812 if isKeyPressed(KeyNextWeapon, KeyNextWeapon2) and gPlayer1.isWeaponSwitchKeyReleased(-1) then gPlayer1.PressKey(KEY_NEXTWEAPON); //kByte := kByte or NET_KEY_NW;
2813 if isKeyPressed(KeyPrevWeapon, KeyPrevWeapon2) and gPlayer1.isWeaponSwitchKeyReleased(-2) then gPlayer1.PressKey(KEY_PREVWEAPON); //kByte := kByte or NET_KEY_PW;
2814 for I := 0 to High(KeyWeapon) do
2815 begin
2816 if isKeyPressed(KeyWeapon[I], KeyWeapon2[I]) then
2817 begin
2818 gPlayer1.weaponSwitchKeysStateChange(i, true);
2819 if gPlayer1.isWeaponSwitchKeyReleased(i) then
2820 begin
2821 gPlayer1.QueueWeaponSwitch(i); // all choices are passed there, and god will take the best
2822 //WeaponSelect := WeaponSelect or Word(1 shl I);
2823 end;
2824 end
2825 else
2826 begin
2827 gPlayer1.weaponSwitchKeysStateChange(i, false);
2828 end;
2829 end;
2830 end;
2831 // fix movebutton state
2832 P1MoveButton := P1MoveButton or (strafeDir shl 4);
2833 end
2834 else
2835 kByte := NET_KEY_CHAT;
2837 gPlayer1.weaponSwitchKeysShiftNewStates();
2839 NetOut.Write(Byte(NET_MSG_PLRPOS));
2840 NetOut.Write(gTime);
2841 NetOut.Write(kByte);
2842 NetOut.Write(Byte(gPlayer1.Direction));
2843 NetOut.Write(Byte(gPlayer1.CurrWeap));
2844 //NetOut.Write(WeaponSelect);
2845 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2846 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS);
2848 //kBytePrev := kByte;
2849 //kDirPrev := gPlayer1.Direction;
2850 end;
2852 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
2853 begin
2854 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
2855 NetOut.Write(Byte(Start));
2856 NetOut.Write(Command);
2857 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2858 end;
2860 procedure MC_SEND_PlayerSettings();
2861 begin
2862 NetOut.Write(Byte(NET_MSG_PLRSET));
2863 NetOut.Write(gPlayer1Settings.Name);
2864 NetOut.Write(gPlayer1Settings.Model);
2865 NetOut.Write(gPlayer1Settings.Color.R);
2866 NetOut.Write(gPlayer1Settings.Color.G);
2867 NetOut.Write(gPlayer1Settings.Color.B);
2868 NetOut.Write(gPlayer1Settings.Team);
2870 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2871 end;
2873 procedure MC_SEND_FullStateRequest();
2874 begin
2875 NetOut.Write(Byte(NET_MSG_REQFST));
2877 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2878 end;
2880 procedure MC_SEND_CheatRequest(Kind: Byte);
2881 begin
2882 NetOut.Write(Byte(NET_MSG_CHEAT));
2883 NetOut.Write(Kind);
2885 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2886 end;
2887 procedure MC_SEND_RCONPassword(Password: string);
2888 begin
2889 NetOut.Write(Byte(NET_MSG_RCON_AUTH));
2890 NetOut.Write(Password);
2892 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2893 end;
2894 procedure MC_SEND_RCONCommand(Cmd: string);
2895 begin
2896 NetOut.Write(Byte(NET_MSG_RCON_CMD));
2897 NetOut.Write(Cmd);
2899 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2900 end;
2902 // i have no idea why all this stuff is in here
2904 function ReadFile(const FileName: TFileName): AByte;
2905 var
2906 FileStream : TStream;
2907 fname: string;
2908 begin
2909 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName]), TMsgType.Notify);
2910 fname := findDiskWad(FileName);
2911 if length(fname) = 0 then
2912 begin
2913 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName]), TMsgType.Fatal);
2914 SetLength(Result, 0);
2915 exit;
2916 end;
2917 e_WriteLog(Format('NETWORK: found file "%s"', [fname]), TMsgType.Notify);
2918 Result := nil;
2919 FileStream := openDiskFileRO(fname);
2920 try
2921 if FileStream.Size > 0 then
2922 begin
2923 SetLength(Result, FileStream.Size);
2924 FileStream.Read(Result[0], FileStream.Size);
2925 end;
2926 finally
2927 FileStream.Free;
2928 end;
2929 end;
2931 function CreateMapDataMsg(const FileName: TFileName; ResList: TStringList): TMapDataMsg;
2932 var
2933 i: Integer;
2934 begin
2935 Result.MsgId := NET_MSG_MAP_RESPONSE;
2936 Result.FileData := ReadFile(FileName);
2937 Result.FileSize := Length(Result.FileData);
2939 SetLength(Result.ExternalResources, ResList.Count);
2940 for i:=0 to ResList.Count-1 do
2941 begin
2942 Result.ExternalResources[i].Name := ResList.Strings[i];
2943 Result.ExternalResources[i].md5 := MD5File(GameDir+'/wads/'+ResList.Strings[i]);
2944 end;
2945 end;
2947 procedure ResDataMsgToBytes(var bytes: AByte; const ResData: TResDataMsg);
2948 var
2949 ResultStream: TMemoryStream;
2950 begin
2951 ResultStream := TMemoryStream.Create;
2953 ResultStream.WriteBuffer(ResData.MsgId, SizeOf(ResData.MsgId)); //msgId
2954 ResultStream.WriteBuffer(ResData.FileSize, SizeOf(ResData.FileSize)); //file size
2955 ResultStream.WriteBuffer(ResData.FileData[0], ResData.FileSize); //file data
2957 SetLength(bytes, ResultStream.Size);
2958 ResultStream.Seek(0, soFromBeginning);
2959 ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
2961 ResultStream.Free;
2962 end;
2964 function ResDataFromMsgStream(msgStream: TMemoryStream):TResDataMsg;
2965 begin
2966 msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
2967 msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize));
2968 SetLength(Result.FileData, Result.FileSize);
2969 msgStream.ReadBuffer(Result.FileData[0], Result.FileSize);
2970 end;
2972 procedure MapDataMsgToBytes(var bytes: AByte; const MapDataMsg: TMapDataMsg);
2973 var
2974 ResultStream: TMemoryStream;
2975 resCount: Integer;
2976 begin
2977 resCount := Length(MapDataMsg.ExternalResources);
2979 ResultStream := TMemoryStream.Create;
2981 ResultStream.WriteBuffer(MapDataMsg.MsgId, SizeOf(MapDataMsg.MsgId)); //msgId
2982 ResultStream.WriteBuffer(MapDataMsg.FileSize, SizeOf(MapDataMsg.FileSize)); //file size
2983 ResultStream.WriteBuffer(MapDataMsg.FileData[0], MapDataMsg.FileSize); //file data
2985 ResultStream.WriteBuffer(resCount, SizeOf(resCount)); //res count
2986 ResultStream.WriteBuffer(MapDataMsg.ExternalResources[0], resCount*SizeOf(TExternalResourceInfo)); //res data
2988 SetLength(bytes, ResultStream.Size);
2989 ResultStream.Seek(0, soFromBeginning);
2990 ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
2992 ResultStream.Free;
2993 end;
2995 function MapDataFromMsgStream(msgStream: TMemoryStream):TMapDataMsg;
2996 var
2997 resCount: Integer;
2998 begin
2999 msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
3000 msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize)); //file size
3002 SetLength(Result.FileData, Result.FileSize);
3003 msgStream.ReadBuffer(Result.FileData[0], Result.FileSize); //file data
3005 msgStream.ReadBuffer(resCount, SizeOf(resCount)); //res count
3006 SetLength(Result.ExternalResources, resCount);
3008 msgStream.ReadBuffer(Result.ExternalResources[0], resCount * SizeOf(TExternalResourceInfo)); //res data
3009 end;
3011 function IsValidFileName(const S: String): Boolean;
3012 const
3013 Forbidden: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
3014 var
3015 I: Integer;
3016 begin
3017 Result := S <> '';
3018 for I := 1 to Length(S) do
3019 Result := Result and (not(S[I] in Forbidden));
3020 end;
3022 function IsValidFilePath(const S: String): Boolean;
3023 var
3024 I: Integer;
3025 begin
3026 Result := False;
3027 if not IsValidFileName(S) then exit;
3028 if FileExists(S) then exit;
3029 I := LastDelimiter('\/', S);
3030 if (I > 0) then
3031 if (not DirectoryExists(Copy(S, 1, I-1))) then
3032 exit;
3033 Result := True;
3034 end;
3036 procedure MC_SEND_MapRequest();
3037 begin
3038 NetOut.Write(Byte(NET_MSG_MAP_REQUEST));
3039 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3040 end;
3042 procedure MC_SEND_ResRequest(const resName: AnsiString);
3043 begin
3044 NetOut.Write(Byte(NET_MSG_RES_REQUEST));
3045 NetOut.Write(resName);
3046 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3047 end;
3049 procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
3050 var
3051 payload: AByte;
3052 peer: pENetPeer;
3053 mapDataMsg: TMapDataMsg;
3054 begin
3055 e_WriteLog('NET: Received map request from ' +
3056 DecodeIPV4(C^.Peer.address.host), TMsgType.Notify);
3058 mapDataMsg := CreateMapDataMsg(MapsDir + gGameSettings.WAD, gExternalResources);
3059 peer := NetClients[C^.ID].Peer;
3061 MapDataMsgToBytes(payload, mapDataMsg);
3062 g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
3064 payload := nil;
3065 mapDataMsg.FileData := nil;
3066 mapDataMsg.ExternalResources := nil;
3067 end;
3069 procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
3070 var
3071 payload: AByte;
3072 peer: pENetPeer;
3073 FileName: String;
3074 resDataMsg: TResDataMsg;
3075 begin
3076 FileName := ExtractFileName(M.ReadString());
3077 e_WriteLog('NET: Received res request: ' + FileName +
3078 ' from ' + DecodeIPV4(C^.Peer.address.host), TMsgType.Notify);
3080 if not IsValidFilePath(FileName) then
3081 begin
3082 e_WriteLog('Invalid filename: ' + FileName, TMsgType.Warning);
3083 exit;
3084 end;
3086 peer := NetClients[C^.ID].Peer;
3088 if gExternalResources.IndexOf(FileName) > -1 then
3089 begin
3090 resDataMsg.MsgId := NET_MSG_RES_RESPONSE;
3091 resDataMsg.FileData := ReadFile(GameDir+'/wads/'+FileName);
3092 resDataMsg.FileSize := Length(resDataMsg.FileData);
3094 ResDataMsgToBytes(payload, resDataMsg);
3095 g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
3096 end;
3097 end;
3099 end.