DEADSOFTWARE

migrating from PanelIDs to panel GUIDs; part one
[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; PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
172 procedure MH_SEND_PanelState(PType: Word; 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) + '.', 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; PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
1221 var
1222 TP: TPanel;
1223 begin
1224 TP := g_Map_PanelByGUID(PGUID);
1225 if (TP = nil) then exit;
1227 case PType of
1228 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
1229 TP := gWalls[PID];
1230 PANEL_FORE:
1231 TP := gRenderForegrounds[PID];
1232 PANEL_BACK:
1233 TP := gRenderBackgrounds[PID];
1234 PANEL_WATER:
1235 TP := gWater[PID];
1236 PANEL_ACID1:
1237 TP := gAcid1[PID];
1238 PANEL_ACID2:
1239 TP := gAcid2[PID];
1240 PANEL_STEP:
1241 TP := gSteps[PID];
1242 else
1243 Exit;
1244 end;
1247 with TP do
1248 begin
1249 NetOut.Write(Byte(NET_MSG_PTEX));
1250 NetOut.Write(PType);
1251 NetOut.Write(LongWord(PGUID));
1252 NetOut.Write(FCurTexture);
1253 NetOut.Write(FCurFrame);
1254 NetOut.Write(FCurFrameCount);
1255 NetOut.Write(AnimLoop);
1256 end;
1258 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1259 end;
1261 procedure MH_SEND_PanelState(PType: Word; PGUID: Integer; ID: Integer = NET_EVERYONE);
1262 var
1263 TP: TPanel;
1264 begin
1265 TP := g_Map_PanelByGUID(PGUID);
1266 if (TP = nil) then exit;
1267 case PType of
1269 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR: TP := gWalls[PID];
1270 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT: TP := gLifts[PID];
1272 PANEL_BACK:
1273 begin
1274 //TP := gRenderBackgrounds[PID];
1275 TP.Moved := True;
1276 end;
1277 PANEL_FORE:
1278 begin
1279 //TP := gRenderForegrounds[PID];
1280 TP.Moved := True;
1281 end;
1283 else
1284 Exit;
1286 end;
1288 NetOut.Write(Byte(NET_MSG_PSTATE));
1289 NetOut.Write(PType);
1290 NetOut.Write(LongWord(PGUID));
1291 NetOut.Write(Byte(TP.Enabled));
1292 NetOut.Write(TP.LiftType);
1293 NetOut.Write(TP.X);
1294 NetOut.Write(TP.Y);
1296 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1297 end;
1299 // TRIGGER
1301 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
1302 begin
1303 if gTriggers = nil then Exit;
1304 if T.Sound = nil then Exit;
1306 NetOut.Write(Byte(NET_MSG_TSOUND));
1307 NetOut.Write(T.ClientID);
1308 NetOut.Write(Byte(T.Sound.IsPlaying));
1309 NetOut.Write(LongWord(T.Sound.GetPosition));
1310 NetOut.Write(T.SoundPlayCount);
1312 g_Net_Host_Send(ID, True);
1313 end;
1315 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
1316 begin
1317 NetOut.Write(Byte(NET_MSG_TMUSIC));
1318 NetOut.Write(gMusic.Name);
1319 NetOut.Write(Byte(gMusic.IsPlaying));
1320 NetOut.Write(LongWord(gMusic.GetPosition));
1321 NetOut.Write(Byte(gMusic.SpecPause or gMusic.IsPaused));
1323 g_Net_Host_Send(ID, True);
1324 end;
1326 // MONSTER
1328 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
1329 var
1330 M: TMonster;
1331 begin
1332 M := g_Monsters_ByUID(UID);
1333 if M = nil then
1334 Exit;
1336 with M do
1337 begin
1338 NetOut.Write(Byte(NET_MSG_MSPAWN));
1339 NetOut.Write(UID);
1340 NetOut.Write(MonsterType);
1341 NetOut.Write(MonsterState);
1342 NetOut.Write(MonsterAnim);
1343 NetOut.Write(MonsterTargetUID);
1344 NetOut.Write(MonsterTargetTime);
1345 NetOut.Write(MonsterBehaviour);
1346 NetOut.Write(MonsterSleep);
1347 NetOut.Write(MonsterHealth);
1348 NetOut.Write(MonsterAmmo);
1349 NetOut.Write(GameX);
1350 NetOut.Write(GameY);
1351 NetOut.Write(GameVelX);
1352 NetOut.Write(GameVelY);
1353 NetOut.Write(Byte(GameDirection));
1354 end;
1356 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1357 end;
1359 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
1360 var
1361 M: TMonster;
1362 begin
1363 M := g_Monsters_ByUID(UID);
1364 if M = nil then Exit;
1366 NetOut.Write(Byte(NET_MSG_MPOS));
1367 NetOut.Write(UID);
1369 with M do
1370 begin
1371 NetOut.Write(GameX);
1372 NetOut.Write(GameY);
1373 NetOut.Write(GameVelX);
1374 NetOut.Write(GameVelY);
1375 NetOut.Write(Byte(GameDirection));
1376 end;
1378 g_Net_Host_Send(ID, False, NET_CHAN_MONSTERPOS);
1379 end;
1381 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
1382 var
1383 M: TMonster;
1384 begin
1385 M := g_Monsters_ByUID(UID);
1386 if M = nil then Exit;
1388 NetOut.Write(Byte(NET_MSG_MSTATE));
1389 NetOut.Write(UID);
1391 with M do
1392 begin
1393 NetOut.Write(MonsterState);
1394 NetOut.Write(ForcedAnim);
1395 NetOut.Write(MonsterTargetUID);
1396 NetOut.Write(MonsterTargetTime);
1397 NetOut.Write(MonsterSleep);
1398 NetOut.Write(MonsterHealth);
1399 NetOut.Write(MonsterAmmo);
1400 NetOut.Write(MonsterPain);
1401 NetOut.Write(Byte(AnimIsReverse));
1402 NetOut.Write(FFireTime);
1403 end;
1405 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1406 end;
1408 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
1409 begin
1410 NetOut.Write(Byte(NET_MSG_MSHOT));
1411 NetOut.Write(UID);
1412 NetOut.Write(X);
1413 NetOut.Write(Y);
1414 NetOut.Write(VX);
1415 NetOut.Write(VY);
1417 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1418 end;
1420 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
1421 var
1422 M: TMonster;
1423 begin
1424 M := g_Monsters_ByUID(UID);
1425 if M = nil then Exit;
1427 NetOut.Write(Byte(NET_MSG_MDEL));
1428 NetOut.Write(UID);
1430 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1431 end;
1433 // MISC
1435 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
1436 begin
1437 NetOut.Write(Byte(NET_MSG_TIME_SYNC));
1438 NetOut.Write(Time);
1440 g_Net_Host_Send(ID, False, NET_CHAN_SERVICE);
1441 end;
1443 procedure MH_SEND_VoteEvent(EvType: Byte;
1444 StrArg1: string = 'a'; StrArg2: string = 'b';
1445 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
1446 ID: Integer = NET_EVERYONE);
1447 begin
1448 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
1449 NetOut.Write(EvType);
1450 NetOut.Write(IntArg1);
1451 NetOut.Write(IntArg2);
1452 NetOut.Write(StrArg1);
1453 NetOut.Write(StrArg2);
1455 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1456 end;
1458 // CLIENT MESSAGES //
1460 // GAME
1462 procedure MC_RECV_Chat(var M: TMsg);
1463 var
1464 Txt: string;
1465 Mode: Byte;
1466 begin
1467 Txt := M.ReadString();
1468 Mode := M.ReadByte();
1470 if Mode <> NET_CHAT_SYSTEM then
1471 begin
1472 if Mode = NET_CHAT_PLAYER then
1473 begin
1474 g_Console_Add(Txt, True);
1475 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), MSG_NOTIFY);
1476 g_Sound_PlayEx('SOUND_GAME_RADIO');
1477 end else
1478 if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then
1479 begin
1480 if gPlayer1.Team = TEAM_RED then
1481 g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True);
1482 if gPlayer1.Team = TEAM_BLUE then
1483 g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True);
1484 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), MSG_NOTIFY);
1485 g_Sound_PlayEx('SOUND_GAME_RADIO');
1486 end;
1487 end else
1488 g_Console_Add(Txt, True);
1489 end;
1491 procedure MC_RECV_Effect(var M: TMsg);
1492 var
1493 Kind: Byte;
1494 X, Y: Integer;
1495 Ang: SmallInt;
1496 Anim: TAnimation;
1497 ID: LongWord;
1498 begin
1499 if not gGameOn then Exit;
1500 Kind := M.ReadByte();
1501 X := M.ReadLongInt();
1502 Y := M.ReadLongInt();
1503 Ang := M.ReadSmallInt();
1505 case Kind of
1506 NET_GFX_SPARK:
1507 g_GFX_Spark(X, Y, 2 + Random(2), Ang, 0, 0);
1509 NET_GFX_TELE:
1510 begin
1511 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
1512 begin
1513 Anim := TAnimation.Create(ID, False, 3);
1514 g_GFX_OnceAnim(X, Y, Anim);
1515 Anim.Free();
1516 end;
1517 if Ang = 1 then
1518 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
1519 end;
1521 NET_GFX_EXPLODE:
1522 begin
1523 if g_Frames_Get(ID, 'FRAMES_EXPLODE_ROCKET') then
1524 begin
1525 Anim := TAnimation.Create(ID, False, 6);
1526 Anim.Blending := False;
1527 g_GFX_OnceAnim(X-64, Y-64, Anim);
1528 Anim.Free();
1529 end;
1530 if Ang = 1 then
1531 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X, Y);
1532 end;
1534 NET_GFX_BFGEXPL:
1535 begin
1536 if g_Frames_Get(ID, 'FRAMES_EXPLODE_BFG') then
1537 begin
1538 Anim := TAnimation.Create(ID, False, 6);
1539 Anim.Blending := False;
1540 g_GFX_OnceAnim(X-64, Y-64, Anim);
1541 Anim.Free();
1542 end;
1543 if Ang = 1 then
1544 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X, Y);
1545 end;
1547 NET_GFX_BFGHIT:
1548 begin
1549 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1550 begin
1551 Anim := TAnimation.Create(ID, False, 4);
1552 g_GFX_OnceAnim(X-32, Y-32, Anim);
1553 Anim.Free();
1554 end;
1555 end;
1557 NET_GFX_FIRE:
1558 begin
1559 if g_Frames_Get(ID, 'FRAMES_FIRE') then
1560 begin
1561 Anim := TAnimation.Create(ID, False, 4);
1562 g_GFX_OnceAnim(X, Y, Anim);
1563 Anim.Free();
1564 end;
1565 if Ang = 1 then
1566 g_Sound_PlayExAt('SOUND_FIRE', X, Y);
1567 end;
1569 NET_GFX_RESPAWN:
1570 begin
1571 if g_Frames_Get(ID, 'FRAMES_ITEM_RESPAWN') then
1572 begin
1573 Anim := TAnimation.Create(ID, False, 4);
1574 g_GFX_OnceAnim(X, Y, Anim);
1575 Anim.Free();
1576 end;
1577 if Ang = 1 then
1578 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
1579 end;
1581 NET_GFX_SHELL1:
1582 g_Player_CreateShell(X, Y, 0, -2, SHELL_BULLET);
1584 NET_GFX_SHELL2:
1585 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1587 NET_GFX_SHELL3:
1588 begin
1589 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1590 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1591 end;
1592 end;
1593 end;
1595 procedure MC_RECV_Sound(var M: TMsg);
1596 var
1597 Name: string;
1598 X, Y: Integer;
1599 Pos: Boolean;
1600 begin
1601 Name := M.ReadString();
1602 Pos := M.ReadByte() <> 0;
1603 if Pos then
1604 begin
1605 X := M.ReadLongInt();
1606 Y := M.ReadLongInt();
1607 g_Sound_PlayExAt(Name, X, Y);
1608 end
1609 else
1610 g_Sound_PlayEx(Name);
1611 end;
1613 procedure MC_RECV_CreateShot(var M: TMsg);
1614 var
1615 I, X, Y, XV, YV: Integer;
1616 Timeout: LongWord;
1617 Target, Spawner: Word;
1618 ShType: Byte;
1619 begin
1620 I := M.ReadLongInt();
1621 ShType := M.ReadByte();
1622 Target := M.ReadWord();
1623 Spawner := M.ReadWord();
1624 Timeout := M.ReadLongWord();
1625 X := M.ReadLongInt();
1626 Y := M.ReadLongInt();
1627 XV := M.ReadLongInt();
1628 YV := M.ReadLongInt();
1630 I := g_Weapon_CreateShot(I, ShType, Spawner, Target, X, Y, XV, YV);
1631 if (Shots <> nil) and (I <= High(Shots)) then
1632 begin
1633 Shots[I].Timeout := Timeout;
1634 //Shots[I].Target := Target; // TODO: find a use for Target later
1635 end;
1636 end;
1638 procedure MC_RECV_UpdateShot(var M: TMsg);
1639 var
1640 I, TX, TY, TXV, TYV: Integer;
1641 begin
1642 I := M.ReadLongInt();
1643 TX := M.ReadLongInt();
1644 TY := M.ReadLongInt();
1645 TXV := M.ReadLongInt();
1646 TYV := M.ReadLongInt();
1648 if (Shots <> nil) and (I <= High(Shots)) then
1649 with (Shots[i]) do
1650 begin
1651 Obj.X := TX;
1652 Obj.Y := TY;
1653 Obj.Vel.X := TXV;
1654 Obj.Vel.Y := TYV;
1655 end;
1656 end;
1658 procedure MC_RECV_DeleteShot(var M: TMsg);
1659 var
1660 I, X, Y: Integer;
1661 L: Boolean;
1662 begin
1663 if not gGameOn then Exit;
1664 I := M.ReadLongInt();
1665 L := (M.ReadByte() <> 0);
1666 X := M.ReadLongInt();
1667 Y := M.ReadLongInt();
1669 g_Weapon_DestroyShot(I, X, Y, L);
1670 end;
1672 procedure MC_RECV_GameStats(var M: TMsg);
1673 begin
1674 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1675 begin
1676 gTeamStat[TEAM_RED].Goals := M.ReadSmallInt();
1677 gTeamStat[TEAM_BLUE].Goals := M.ReadSmallInt();
1678 end
1679 else
1680 if gGameSettings.GameMode = GM_COOP then
1681 begin
1682 gCoopMonstersKilled := M.ReadWord();
1683 gCoopSecretsFound := M.ReadWord();
1684 end;
1685 end;
1687 procedure MC_RECV_CoopStats(var M: TMsg);
1688 begin
1689 gTotalMonsters := M.ReadLongInt();
1690 gSecretsCount := M.ReadLongInt();
1691 gCoopTotalMonstersKilled := M.ReadWord();
1692 gCoopTotalSecretsFound := M.ReadWord();
1693 gCoopTotalMonsters := M.ReadWord();
1694 gCoopTotalSecrets := M.ReadWord();
1695 end;
1697 procedure MC_RECV_GameEvent(var M: TMsg);
1698 var
1699 EvType: Byte;
1700 EvNum: Integer;
1701 EvStr: string;
1702 EvTime: LongWord;
1703 BHash: Boolean;
1704 EvHash: TMD5Digest;
1705 pl: TPlayer;
1706 i1, i2: TStrings_Locale;
1707 pln: String;
1708 cnt: Byte;
1709 begin
1710 FillChar(EvHash, Sizeof(EvHash), 0);
1711 EvType := M.ReadByte();
1712 EvNum := M.ReadLongInt();
1713 EvStr := M.ReadString();
1714 gLastMap := M.ReadByte() <> 0;
1715 if gLastMap and (gGameSettings.GameMode = GM_COOP) then gStatsOff := True;
1716 gStatsPressed := True;
1717 EvTime := M.ReadLongWord();
1718 BHash := M.ReadByte() <> 0;
1719 if BHash then
1720 EvHash := M.ReadMD5();
1722 gTime := EvTime;
1724 case EvType of
1725 NET_EV_MAPSTART:
1726 begin
1727 gGameOn := False;
1728 g_Game_ClearLoading();
1729 g_Game_StopAllSounds(True);
1731 gSwitchGameMode := Byte(EvNum);
1732 gGameSettings.GameMode := gSwitchGameMode;
1734 gWADHash := EvHash;
1735 if not g_Game_StartMap(EvStr, True) then
1736 begin
1737 if Pos(':\', EvStr) = 0 then
1738 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + EvStr]))
1739 else
1740 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [EvStr]));
1741 Exit;
1742 end;
1744 MC_SEND_FullStateRequest;
1745 end;
1747 NET_EV_MAPEND:
1748 begin
1749 gMissionFailed := EvNum <> 0;
1750 gExit := EXIT_ENDLEVELCUSTOM;
1751 end;
1753 NET_EV_RCON:
1754 begin
1755 case EvNum of
1756 NET_RCON_NOAUTH:
1757 g_Console_Add(_lc[I_NET_RCON_NOAUTH], True);
1758 NET_RCON_PWGOOD:
1759 g_Console_Add(_lc[I_NET_RCON_PWD_VALID], True);
1760 NET_RCON_PWBAD:
1761 g_Console_Add(_lc[I_NET_RCON_PWD_INVALID], True);
1762 end;
1763 end;
1765 NET_EV_CHANGE_TEAM:
1766 begin
1767 if EvNum = TEAM_RED then
1768 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True);
1769 if EvNum = TEAM_BLUE then
1770 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True);
1771 end;
1773 NET_EV_PLAYER_KICK:
1774 g_Console_Add(Format(_lc[I_PLAYER_KICK], [EvStr]), True);
1776 NET_EV_PLAYER_BAN:
1777 g_Console_Add(Format(_lc[I_PLAYER_BAN], [EvStr]), True);
1779 NET_EV_LMS_WARMUP:
1780 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [EvNum]), True);
1782 NET_EV_LMS_SURVIVOR:
1783 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True);
1785 NET_EV_BIGTEXT:
1786 g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum));
1788 NET_EV_SCORE:
1789 begin
1790 pl := g_Player_Get(EvNum and $FFFF);
1791 if pl = nil then
1792 pln := '?'
1793 else
1794 pln := pl.Name;
1795 cnt := (EvNum shr 16) and $FF;
1796 if Pos('w', EvStr) = 0 then
1797 begin
1798 // Default score
1799 if Pos('t', EvStr) = 0 then
1800 begin
1801 // Player +/- score
1802 if Pos('-', EvStr) = 0 then
1803 begin
1804 if Pos('e', EvStr) = 0 then
1805 i1 := I_PLAYER_SCORE_ADD_OWN
1806 else
1807 i1 := I_PLAYER_SCORE_ADD_ENEMY;
1808 end else
1809 begin
1810 if Pos('e', EvStr) = 0 then
1811 i1 := I_PLAYER_SCORE_SUB_OWN
1812 else
1813 i1 := I_PLAYER_SCORE_SUB_ENEMY;
1814 end;
1815 // Which team
1816 if Pos('r', EvStr) > 0 then
1817 i2 := I_PLAYER_SCORE_TO_RED
1818 else
1819 i2 := I_PLAYER_SCORE_TO_BLUE;
1820 g_Console_Add(Format(_lc[i1], [pln, cnt, _lc[i2]]), True);
1821 end else
1822 begin
1823 // Team +/- score
1824 if Pos('-', EvStr) = 0 then
1825 i1 := I_PLAYER_SCORE_ADD_TEAM
1826 else
1827 i1 := I_PLAYER_SCORE_SUB_TEAM;
1828 // Which team
1829 if Pos('r', EvStr) > 0 then
1830 i2 := I_PLAYER_SCORE_RED
1831 else
1832 i2 := I_PLAYER_SCORE_BLUE;
1833 g_Console_Add(Format(_lc[i1], [_lc[i2], cnt]), True);
1834 end;
1835 end else
1836 begin
1837 // Game Win
1838 if Pos('e', EvStr) = 0 then
1839 i1 := I_PLAYER_SCORE_WIN_OWN
1840 else
1841 i1 := I_PLAYER_SCORE_WIN_ENEMY;
1842 // Which team
1843 if Pos('r', EvStr) > 0 then
1844 i2 := I_PLAYER_SCORE_TO_RED
1845 else
1846 i2 := I_PLAYER_SCORE_TO_BLUE;
1847 g_Console_Add(Format(_lc[i1], [pln, _lc[i2]]), True);
1848 end;
1849 end;
1851 NET_EV_SCORE_MSG:
1852 begin
1853 if EvNum = TEAM_RED then
1854 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1855 if EvNum = TEAM_BLUE then
1856 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1857 if EvNum = -TEAM_RED then
1858 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1859 if EvNum = -TEAM_BLUE then
1860 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1861 end;
1863 NET_EV_LMS_START:
1864 begin
1865 g_Player_RemoveAllCorpses;
1866 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
1867 end;
1869 NET_EV_LMS_WIN:
1870 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(EvStr)]), 144);
1872 NET_EV_TLMS_WIN:
1873 begin
1874 if EvNum = TEAM_RED then
1875 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
1876 if EvNum = TEAM_BLUE then
1877 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
1878 end;
1880 NET_EV_LMS_LOSE:
1881 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
1883 NET_EV_LMS_DRAW:
1884 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
1886 NET_EV_KILLCOMBO:
1887 g_Game_Announce_KillCombo(EvNum);
1889 NET_EV_PLAYER_TOUCH:
1890 begin
1891 pl := g_Player_Get(EvNum);
1892 if pl <> nil then
1893 pl.Touch();
1894 end;
1896 end;
1897 end;
1899 procedure MC_RECV_FlagEvent(var M: TMsg);
1900 var
1901 PID: Word;
1902 Pl: TPlayer;
1903 EvType: Byte;
1904 Fl: Byte;
1905 Quiet: Boolean;
1906 s, ts: string;
1907 begin
1908 EvType := M.ReadByte();
1909 Fl := M.ReadByte();
1911 if Fl = FLAG_NONE then Exit;
1913 Quiet := (M.ReadByte() <> 0);
1914 PID := M.ReadWord();
1916 gFlags[Fl].State := M.ReadByte();
1917 gFlags[Fl].CaptureTime := M.ReadLongWord();
1918 gFlags[Fl].Obj.X := M.ReadLongInt();
1919 gFlags[Fl].Obj.Y := M.ReadLongInt();
1920 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
1921 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
1923 Pl := g_Player_Get(PID);
1924 if (Pl = nil) and
1925 (EvType <> FLAG_STATE_NORMAL) and
1926 (EvType <> FLAG_STATE_DROPPED) and
1927 (EvType <> FLAG_STATE_RETURNED) then
1928 Exit;
1930 case EvType of
1931 FLAG_STATE_NORMAL:
1932 begin
1933 if Quiet or (Pl = nil) then Exit;
1935 if Fl = FLAG_RED then
1936 s := _lc[I_PLAYER_FLAG_RED]
1937 else
1938 s := _lc[I_PLAYER_FLAG_BLUE];
1940 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
1941 end;
1943 FLAG_STATE_CAPTURED:
1944 begin
1945 if (Pl <> nil) then Pl.SetFlag(Fl);
1947 if Quiet then Exit;
1949 if Fl = FLAG_RED then
1950 s := _lc[I_PLAYER_FLAG_RED]
1951 else
1952 s := _lc[I_PLAYER_FLAG_BLUE];
1954 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [Pl.Name, s]), True);
1955 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
1956 end;
1958 FLAG_STATE_DROPPED:
1959 begin
1960 if (Pl <> nil) then Pl.SetFlag(FLAG_NONE);
1962 if Quiet or (Pl = nil) then Exit;
1964 if Fl = FLAG_RED then
1965 s := _lc[I_PLAYER_FLAG_RED]
1966 else
1967 s := _lc[I_PLAYER_FLAG_BLUE];
1969 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [Pl.Name, s]), True);
1970 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
1971 end;
1973 FLAG_STATE_SCORED:
1974 begin
1975 g_Map_ResetFlag(FLAG_RED);
1976 g_Map_ResetFlag(FLAG_BLUE);
1977 if Quiet or (Pl = nil) then Exit;
1978 Pl.SetFlag(FLAG_NONE);
1980 if Fl = FLAG_RED then
1981 s := _lc[I_PLAYER_FLAG_RED]
1982 else
1983 s := _lc[I_PLAYER_FLAG_BLUE];
1985 ts := Format('%.4d', [gFlags[Fl].CaptureTime]);
1986 Insert('.', ts, Length(ts) + 1 - 3);
1987 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [Pl.Name, s, ts]), True);
1988 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
1989 end;
1991 FLAG_STATE_RETURNED:
1992 begin
1993 g_Map_ResetFlag(Fl);
1994 if Quiet then Exit;
1996 if Fl = FLAG_RED then
1997 s := _lc[I_PLAYER_FLAG_RED]
1998 else
1999 s := _lc[I_PLAYER_FLAG_BLUE];
2001 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2002 end;
2003 end;
2004 end;
2006 procedure MC_RECV_GameSettings(var M: TMsg);
2007 begin
2008 gGameSettings.GameMode := M.ReadByte();
2009 gGameSettings.GoalLimit := M.ReadWord();
2010 gGameSettings.TimeLimit := M.ReadWord();
2011 gGameSettings.MaxLives := M.ReadByte();
2012 gGameSettings.Options := M.ReadLongWord();
2013 end;
2015 // PLAYER
2017 function MC_RECV_PlayerCreate(var M: TMsg): Word;
2018 var
2019 PID, DID: Word;
2020 PName, Model: string;
2021 Color: TRGB;
2022 T: Byte;
2023 Pl: TPlayer;
2024 begin
2025 PID := M.ReadWord();
2026 Pl := g_Player_Get(PID);
2028 PName := M.ReadString();
2029 Model := M.ReadString();
2030 Color.R := M.ReadByte();
2031 Color.G := M.ReadByte();
2032 Color.B := M.ReadByte();
2033 T := M.ReadByte();
2035 Result := 0;
2036 if (PID <> NetPlrUID1) and (PID <> NetPlrUID2) then
2037 begin
2038 if (Pl <> nil) then Exit;
2039 DID := g_Player_Create(Model, Color, T, False);
2040 with g_Player_Get(DID) do
2041 begin
2042 UID := PID;
2043 Name := PName;
2044 Reset(True);
2045 end;
2046 end
2047 else
2048 begin
2049 if (PID = NetPlrUID1) and (gPlayer1 <> nil) then begin
2050 gPlayer1.UID := PID;
2051 gPlayer1.Model.SetColor(Color.R, Color.G, Color.B);
2052 gPlayer1.ChangeTeam(T);
2053 end;
2054 if (PID = NetPlrUID2) and (gPlayer2 <> nil) then begin
2055 gPlayer2.UID := PID;
2056 gPlayer2.Model.SetColor(Color.R, Color.G, Color.B);
2057 gPlayer2.ChangeTeam(T);
2058 end;
2059 end;
2061 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
2062 e_WriteLog('NET: Player ' + PName + ' [' + IntToStr(PID) + '] added.', MSG_NOTIFY);
2063 Result := PID;
2064 end;
2066 function MC_RECV_PlayerPos(var M: TMsg): Word;
2067 var
2068 GT: LongWord;
2069 PID: Word;
2070 kByte: Word;
2071 Pl: TPlayer;
2072 Dir: Byte;
2073 TmpX, TmpY: Integer;
2074 begin
2075 Result := 0;
2077 GT := M.ReadLongWord();
2078 if GT < gTime - NET_MAX_DIFFTIME then
2079 begin
2080 gTime := GT;
2081 Exit;
2082 end;
2083 gTime := GT;
2085 PID := M.ReadWord();
2086 Pl := g_Player_Get(PID);
2088 if Pl = nil then Exit;
2090 Result := PID;
2092 with Pl do
2093 begin
2094 FPing := M.ReadWord();
2095 FLoss := M.ReadByte();
2096 kByte := M.ReadWord();
2097 Dir := M.ReadByte();
2099 TmpX := M.ReadLongInt();
2100 TmpY := M.ReadLongInt();
2102 ReleaseKeys;
2104 if (kByte = NET_KEY_CHAT) then
2105 PressKey(KEY_CHAT, 10000)
2106 else
2107 begin
2108 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
2109 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
2110 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
2111 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
2112 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
2113 end;
2115 if ((Pl <> gPlayer1) and (Pl <> gPlayer2)) or LongBool(kByte and NET_KEY_FORCEDIR) then
2116 SetDirection(TDirection(Dir));
2118 GameVelX := M.ReadLongInt();
2119 GameVelY := M.ReadLongInt();
2120 GameAccelX := M.ReadLongInt();
2121 GameAccelY := M.ReadLongInt();
2122 SetLerp(TmpX, TmpY);
2123 if NetForcePlayerUpdate then Update();
2124 end;
2125 end;
2127 function MC_RECV_PlayerStats(var M: TMsg): Word;
2128 var
2129 PID: Word;
2130 Pl: TPlayer;
2131 I: Integer;
2132 OldJet: Boolean;
2133 NewTeam: Byte;
2134 begin
2135 PID := M.ReadWord();
2136 Pl := g_Player_Get(PID);
2137 Result := 0;
2138 if Pl = nil then
2139 Exit;
2141 with Pl do
2142 begin
2143 Live := (M.ReadByte() <> 0);
2144 GodMode := (M.ReadByte() <> 0);
2145 Health := M.ReadLongInt();
2146 Armor := M.ReadLongInt();
2147 Air := M.ReadLongInt();
2148 JetFuel := M.ReadLongInt();
2149 Lives := M.ReadByte();
2150 NewTeam := M.ReadByte();
2152 for I := WP_FIRST to WP_LAST do
2153 FWeapon[I] := (M.ReadByte() <> 0);
2155 for I := A_BULLETS to A_HIGH do
2156 FAmmo[I] := M.ReadWord();
2158 for I := A_BULLETS to A_HIGH do
2159 FMaxAmmo[I] := M.ReadWord();
2161 for I := MR_SUIT to MR_MAX do
2162 FMegaRulez[I] := M.ReadLongWord();
2164 FRulez := [];
2165 if (M.ReadByte() <> 0) then
2166 FRulez := FRulez + [R_ITEM_BACKPACK];
2167 if (M.ReadByte() <> 0) then
2168 FRulez := FRulez + [R_KEY_RED];
2169 if (M.ReadByte() <> 0) then
2170 FRulez := FRulez + [R_KEY_GREEN];
2171 if (M.ReadByte() <> 0) then
2172 FRulez := FRulez + [R_KEY_BLUE];
2173 if (M.ReadByte() <> 0) then
2174 FRulez := FRulez + [R_BERSERK];
2176 Frags := M.ReadLongInt();
2177 Death := M.ReadLongInt();
2179 SetWeapon(M.ReadByte());
2181 FSpectator := M.ReadByte() <> 0;
2182 if FSpectator then
2183 begin
2184 if Pl = gPlayer1 then
2185 begin
2186 gLMSPID1 := UID;
2187 gPlayer1 := nil;
2188 end;
2189 if Pl = gPlayer2 then
2190 begin
2191 gLMSPID2 := UID;
2192 gPlayer2 := nil;
2193 end;
2194 end
2195 else
2196 begin
2197 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
2198 gPlayer1 := g_Player_Get(gLMSPID1);
2199 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
2200 gPlayer2 := g_Player_Get(gLMSPID2);
2201 end;
2202 FGhost := M.ReadByte() <> 0;
2203 FPhysics := M.ReadByte() <> 0;
2204 FNoRespawn := M.ReadByte() <> 0;
2205 OldJet := FJetpack;
2206 FJetpack := M.ReadByte() <> 0;
2207 FFireTime := M.ReadLongInt();
2208 if OldJet and not FJetpack then
2209 JetpackOff
2210 else if not OldJet and FJetpack then
2211 JetpackOn;
2212 if Team <> NewTeam then
2213 Pl.ChangeTeam(NewTeam);
2214 end;
2216 Result := PID;
2217 end;
2219 function MC_RECV_PlayerDamage(var M: TMsg): Word;
2220 var
2221 PID: Word;
2222 Pl: TPlayer;
2223 Kind: Byte;
2224 Attacker, Value: Word;
2225 VX, VY: Integer;
2226 begin
2227 Result := 0;
2228 if not gGameOn then Exit;
2229 PID := M.ReadWord();
2230 Pl := g_Player_Get(PID);
2231 if Pl = nil then Exit;
2233 Kind := M.ReadByte();
2234 Attacker := M.ReadWord();
2235 Value := M.ReadWord();
2236 VX := M.ReadWord();
2237 VY := M.ReadWord();
2239 with Pl do
2240 Damage(Value, Attacker, VX, VY, Kind);
2242 Result := PID;
2243 end;
2245 function MC_RECV_PlayerDeath(var M: TMsg): Word;
2246 var
2247 PID: Word;
2248 Pl: TPlayer;
2249 KillType, DeathType: Byte;
2250 Attacker: Word;
2251 begin
2252 Result := 0;
2253 if not gGameOn then Exit;
2254 PID := M.ReadWord();
2255 Pl := g_Player_Get(PID);
2256 if Pl = nil then Exit;
2258 KillType := M.ReadByte();
2259 DeathType := M.ReadByte();
2260 Attacker := M.ReadWord();
2262 with Pl do
2263 begin
2264 Kill(KillType, Attacker, DeathType);
2265 SoftReset;
2266 end;
2267 end;
2269 function MC_RECV_PlayerDelete(var M: TMsg): Word;
2270 var
2271 PID: Word;
2272 Pl: TPlayer;
2273 begin
2274 PID := M.ReadWord();
2275 Pl := g_Player_Get(PID);
2276 Result := 0;
2277 if Pl = nil then Exit;
2279 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2280 e_WriteLog('NET: Player ' + Pl.Name + ' [' + IntToStr(PID) + '] removed.', MSG_NOTIFY);
2282 g_Player_Remove(PID);
2284 Result := PID;
2285 end;
2287 function MC_RECV_PlayerFire(var M: TMsg): Word;
2288 var
2289 PID: Word;
2290 Weap: Byte;
2291 Pl: TPlayer;
2292 X, Y, AX, AY: Integer;
2293 SHID: Integer;
2294 begin
2295 Result := 0;
2296 if not gGameOn then Exit;
2297 PID := M.ReadWord();
2298 Pl := g_Player_Get(PID);
2299 if Pl = nil then Exit;
2301 Weap := M.ReadByte();
2302 X := M.ReadLongInt();
2303 Y := M.ReadLongInt();
2304 AX := M.ReadLongInt();
2305 AY := M.ReadLongInt();
2306 SHID := M.ReadLongInt();
2308 with Pl do
2309 if Live then NetFire(Weap, X, Y, AX, AY, SHID);
2310 end;
2312 procedure MC_RECV_PlayerSettings(var M: TMsg);
2313 var
2314 TmpName: string;
2315 TmpModel: string;
2316 TmpColor: TRGB;
2317 TmpTeam: Byte;
2318 Pl: TPlayer;
2319 PID: Word;
2320 begin
2321 PID := M.ReadWord();
2322 Pl := g_Player_Get(PID);
2323 if Pl = nil then Exit;
2325 TmpName := M.ReadString();
2326 TmpModel := M.ReadString();
2327 TmpColor.R := M.ReadByte();
2328 TmpColor.G := M.ReadByte();
2329 TmpColor.B := M.ReadByte();
2330 TmpTeam := M.ReadByte();
2332 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
2333 begin
2334 Pl.ChangeTeam(TmpTeam);
2335 if gPlayer1 = Pl then
2336 gPlayer1Settings.Team := TmpTeam;
2337 if gPlayer2 = Pl then
2338 gPlayer2Settings.Team := TmpTeam;
2339 end else
2340 Pl.SetColor(TmpColor);
2342 if Pl.Name <> TmpName then
2343 begin
2344 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
2345 Pl.Name := TmpName;
2346 end;
2348 if TmpModel <> Pl.Model.Name then
2349 Pl.SetModel(TmpModel);
2350 end;
2352 // ITEM
2354 procedure MC_RECV_ItemSpawn(var M: TMsg);
2355 var
2356 ID: Word;
2357 AID: DWord;
2358 X, Y, VX, VY: Integer;
2359 T: Byte;
2360 Quiet, Fall{, Resp}: Boolean;
2361 Anim: TAnimation;
2362 it: PItem;
2363 begin
2364 if not gGameOn then Exit;
2365 ID := M.ReadWord();
2366 Quiet := M.ReadByte() <> 0;
2367 T := M.ReadByte();
2368 Fall := M.ReadByte() <> 0;
2369 {Resp :=} M.ReadByte();
2370 X := M.ReadLongInt();
2371 Y := M.ReadLongInt();
2372 VX := M.ReadLongInt();
2373 VY := M.ReadLongInt();
2375 g_Items_Create(X, Y, T, Fall, False, False, ID);
2377 it := g_Items_ByIdx(ID);
2378 it.Obj.Vel.X := VX;
2379 it.Obj.Vel.Y := VY;
2381 if not Quiet then
2382 begin
2383 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
2384 if g_Frames_Get(AID, 'FRAMES_ITEM_RESPAWN') then
2385 begin
2386 Anim := TAnimation.Create(AID, False, 4);
2387 g_GFX_OnceAnim(X+(it.Obj.Rect.Width div 2)-16, Y+(it.Obj.Rect.Height div 2)-16, Anim);
2388 Anim.Free();
2389 end;
2390 end;
2391 end;
2393 procedure MC_RECV_ItemDestroy(var M: TMsg);
2394 var
2395 ID: Word;
2396 Quiet: Boolean;
2397 begin
2398 if not gGameOn then Exit;
2399 ID := M.ReadWord();
2400 Quiet := M.ReadByte() <> 0;
2402 if not g_Items_ValidId(ID) then exit;
2404 if not Quiet then g_Items_EmitPickupSound(ID);
2406 g_Items_Remove(ID);
2407 end;
2409 // PANEL
2411 procedure MC_RECV_PanelTexture(var M: TMsg);
2412 var
2413 TP: TPanel;
2414 //PType: Word;
2415 PGUID: Integer;
2416 Tex, Fr: Integer;
2417 Loop, Cnt: Byte;
2418 begin
2419 if not gGameOn then Exit;
2420 {PType :=} M.ReadWord();
2421 PGUID := Integer(M.ReadLongWord());
2422 Tex := M.ReadLongInt();
2423 Fr := M.ReadLongInt();
2424 Cnt := M.ReadByte();
2425 Loop := M.ReadByte();
2427 TP := g_Map_PanelByGUID(PGUID);
2430 case PType of
2431 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR: if gWalls <> nil then TP := gWalls[ID];
2432 PANEL_FORE: if gRenderForegrounds <> nil then TP := gRenderForegrounds[ID];
2433 PANEL_BACK: if gRenderBackgrounds <> nil then TP := gRenderBackgrounds[ID];
2434 PANEL_WATER: if gWater <> nil then TP := gWater[ID];
2435 PANEL_ACID1: if gAcid1 <> nil then TP := gAcid1[ID];
2436 PANEL_ACID2: if gAcid2 <> nil then TP := gAcid2[ID];
2437 PANEL_STEP: if gSteps <> nil then TP := gSteps[ID];
2438 else Exit;
2439 end;
2442 if TP <> nil then
2443 begin
2444 if Loop = 0 then
2445 begin
2446 // switch texture
2447 TP.SetTexture(Tex, Loop);
2448 TP.SetFrame(Fr, Cnt);
2449 end
2450 else
2451 begin
2452 // looped or non-looped animation
2453 TP.NextTexture(Loop);
2454 end;
2455 end;
2456 end;
2458 procedure MC_RECV_PanelState(var M: TMsg);
2459 var
2460 PGUID: Integer;
2461 E: Boolean;
2462 Lift: Byte;
2463 PType: Word;
2464 X, Y: Integer;
2465 TP: TPanel;
2466 begin
2467 if not gGameOn then Exit;
2468 PType := M.ReadWord();
2469 PGUID := Integer(M.ReadLongWord());
2470 E := (M.ReadByte() <> 0);
2471 Lift := M.ReadByte();
2472 X := M.ReadLongInt();
2473 Y := M.ReadLongInt();
2475 case PType of
2476 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
2477 if E then g_Map_EnableWallGUID(PGUID) else g_Map_DisableWallGUID(PGUID);
2479 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT:
2480 g_Map_SetLiftGUID(PGUID, Lift);
2482 {PANEL_BACK,
2483 PANEL_FORE:}
2484 else
2485 begin
2486 TP := g_Map_PanelByGUID(PGUID);
2487 if (TP <> nil) then
2488 begin
2489 TP.X := X;
2490 TP.Y := Y;
2491 TP.positionChanged();
2492 end;
2493 //gRenderBackgrounds[ID].X := X;
2494 //gRenderBackgrounds[ID].Y := Y;
2495 end;
2498 PANEL_FORE:
2499 begin
2500 gRenderForegrounds[ID].X := X;
2501 gRenderForegrounds[ID].Y := Y;
2502 end;
2504 end;
2505 end;
2507 // TRIGGERS
2509 procedure MC_RECV_TriggerSound(var M: TMsg);
2510 var
2511 SPlaying: Boolean;
2512 SPos, SID: LongWord;
2513 SCount: LongInt;
2514 I: Integer;
2515 begin
2516 if not gGameOn then Exit;
2517 if gTriggers = nil then Exit;
2519 SID := M.ReadLongWord();
2520 SPlaying := M.ReadByte() <> 0;
2521 SPos := M.ReadLongWord();
2522 SCount := M.ReadLongInt();
2524 for I := Low(gTriggers) to High(gTriggers) do
2525 if gTriggers[I].TriggerType = TRIGGER_SOUND then
2526 if gTriggers[I].ClientID = SID then
2527 with gTriggers[I] do
2528 begin
2529 if SPlaying then
2530 begin
2531 if trigData.trigLocal then
2532 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), trigData.trigVolume/255.0)
2533 else
2534 Sound.PlayPanVolume((trigData.trigPan-127.0)/128.0, trigData.trigVolume/255.0);
2535 Sound.SetPosition(SPos);
2536 end
2537 else
2538 if Sound.IsPlaying then Sound.Stop;
2540 SoundPlayCount := SCount;
2541 end;
2542 end;
2544 procedure MC_RECV_TriggerMusic(var M: TMsg);
2545 var
2546 MName: string;
2547 MPlaying: Boolean;
2548 MPos: LongWord;
2549 MPaused: Boolean;
2550 begin
2551 if not gGameOn then Exit;
2553 MName := M.ReadString();
2554 MPlaying := M.ReadByte() <> 0;
2555 MPos := M.ReadLongWord();
2556 MPaused := M.ReadByte() <> 0;
2558 if MPlaying then
2559 begin
2560 gMusic.SetByName(MName);
2561 gMusic.Play(True);
2562 gMusic.SetPosition(MPos);
2563 gMusic.SpecPause := MPaused;
2564 end
2565 else
2566 if gMusic.IsPlaying then gMusic.Stop;
2567 end;
2569 // MONSTERS
2571 procedure MC_RECV_MonsterSpawn(var M: TMsg);
2572 var
2573 ID: Word;
2574 MType, MState, MDir, MAnim, MBehav: Byte;
2575 X, Y, VX, VY, MTargTime, MHealth, MAmmo, MSleep: Integer;
2576 MTarg: Word;
2577 Mon: TMonster;
2578 begin
2579 ID := M.ReadWord();
2580 Mon := g_Monsters_ByUID(ID);
2581 if Mon <> nil then
2582 Exit;
2584 MType := M.ReadByte();
2585 MState := M.ReadByte();
2586 MAnim := M.ReadByte();
2587 MTarg := M.ReadWord();
2588 MTargTime := M.ReadLongInt();
2589 MBehav := M.ReadByte();
2590 MSleep := M.ReadLongInt();
2591 MHealth := M.ReadLongInt();
2592 MAmmo := M.ReadLongInt();
2594 X := M.ReadLongInt();
2595 Y := M.ReadLongInt();
2596 VX := M.ReadLongInt();
2597 VY := M.ReadLongInt();
2598 MDir := M.ReadByte();
2600 g_Monsters_Create(MType, X, Y, TDirection(MDir), False, ID);
2601 Mon := g_Monsters_ByUID(ID);
2602 if Mon = nil then
2603 Exit;
2605 with Mon do
2606 begin
2607 GameX := X;
2608 GameY := Y;
2609 GameVelX := VX;
2610 GameVelY := VY;
2612 MonsterAnim := MAnim;
2613 MonsterTargetUID := MTarg;
2614 MonsterTargetTime := MTargTime;
2615 MonsterBehaviour := MBehav;
2616 MonsterSleep := MSleep;
2617 MonsterAmmo := MAmmo;
2618 SetHealth(MHealth);
2620 SetState(MState);
2622 positionChanged(); // this updates spatial accelerators
2623 end;
2624 end;
2626 procedure MC_RECV_MonsterPos(var M: TMsg);
2627 var
2628 Mon: TMonster;
2629 ID: Word;
2630 begin
2631 ID := M.ReadWord();
2632 Mon := g_Monsters_ByUID(ID);
2633 if Mon = nil then
2634 Exit;
2636 with Mon do
2637 begin
2638 GameX := M.ReadLongInt();
2639 GameY := M.ReadLongInt();
2640 GameVelX := M.ReadLongInt();
2641 GameVelY := M.ReadLongInt();
2642 GameDirection := TDirection(M.ReadByte());
2643 positionChanged(); // this updates spatial accelerators
2644 end;
2645 end;
2647 procedure MC_RECV_MonsterState(var M: TMsg);
2648 var
2649 ID: Integer;
2650 MState, MFAnm: Byte;
2651 Mon: TMonster;
2652 AnimRevert: Boolean;
2653 begin
2654 ID := M.ReadWord();
2655 Mon := g_Monsters_ByUID(ID);
2656 if Mon = nil then Exit;
2658 MState := M.ReadByte();
2659 MFAnm := M.ReadByte();
2661 with Mon do
2662 begin
2663 MonsterTargetUID := M.ReadWord();
2664 MonsterTargetTime := M.ReadLongInt();
2665 MonsterSleep := M.ReadLongInt();
2666 MonsterHealth := M.ReadLongInt();
2667 MonsterAmmo := M.ReadLongInt();
2668 MonsterPain := M.ReadLongInt();
2669 AnimRevert := M.ReadByte() <> 0;
2670 FFireTime := M.ReadLongInt();
2671 RevertAnim(AnimRevert);
2673 if MonsterState <> MState then
2674 begin
2675 if (MState = MONSTATE_GO) and (MonsterState = MONSTATE_SLEEP) then
2676 WakeUpSound;
2677 if (MState = MONSTATE_DIE) then
2678 DieSound;
2679 if (MState = MONSTATE_PAIN) then
2680 MakeBloodSimple(Min(200, MonsterPain));
2681 if (MState = MONSTATE_ATTACK) then
2682 kick(nil);
2683 if (MState = MONSTATE_DEAD) then
2684 SetDeadAnim;
2686 SetState(MState, MFAnm);
2687 end;
2688 end;
2689 end;
2691 procedure MC_RECV_MonsterShot(var M: TMsg);
2692 var
2693 ID: Integer;
2694 Mon: TMonster;
2695 X, Y, VX, VY: Integer;
2696 begin
2697 ID := M.ReadWord();
2699 Mon := g_Monsters_ByUID(ID);
2700 if Mon = nil then Exit;
2702 X := M.ReadLongInt();
2703 Y := M.ReadLongInt();
2704 VX := M.ReadLongInt();
2705 VY := M.ReadLongInt();
2707 Mon.ClientAttack(X, Y, VX, VY);
2708 end;
2710 procedure MC_RECV_MonsterDelete(var M: TMsg);
2711 var
2712 ID: Integer;
2713 Mon: TMonster;
2714 begin
2715 ID := M.ReadWord();
2716 Mon := g_Monsters_ByUID(ID);
2717 if Mon = nil then Exit;
2718 Mon.SetState(5);
2719 Mon.MonsterRemoved := True;
2720 end;
2722 procedure MC_RECV_TimeSync(var M: TMsg);
2723 var
2724 Time: LongWord;
2725 begin
2726 Time := M.ReadLongWord();
2728 if gState = STATE_INTERCUSTOM then
2729 gServInterTime := Min(Time, 255);
2730 end;
2732 procedure MC_RECV_VoteEvent(var M: TMsg);
2733 var
2734 EvID: Byte;
2735 Str1, Str2: string;
2736 Int1, Int2: SmallInt;
2737 begin
2738 EvID := M.ReadByte();
2739 Int1 := M.ReadSmallInt();
2740 Int2 := M.ReadSmallInt();
2741 Str1 := M.ReadString();
2742 Str2 := M.ReadString();
2744 case EvID of
2745 NET_VE_STARTED:
2746 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True);
2747 NET_VE_PASSED:
2748 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True);
2749 NET_VE_FAILED:
2750 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
2751 NET_VE_VOTE:
2752 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True);
2753 NET_VE_INPROGRESS:
2754 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True);
2755 end;
2756 end;
2758 // CLIENT SEND
2760 procedure MC_SEND_Info(Password: string);
2761 begin
2762 NetOut.Clear();
2764 NetOut.Write(Byte(NET_MSG_INFO));
2765 NetOut.Write(GAME_VERSION);
2766 NetOut.Write(Password);
2767 NetOut.Write(gPlayer1Settings.Name);
2768 NetOut.Write(gPlayer1Settings.Model);
2769 NetOut.Write(gPlayer1Settings.Color.R);
2770 NetOut.Write(gPlayer1Settings.Color.G);
2771 NetOut.Write(gPlayer1Settings.Color.B);
2772 NetOut.Write(gPlayer1Settings.Team);
2774 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2775 end;
2777 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
2778 begin
2779 NetOut.Write(Byte(NET_MSG_CHAT));
2780 NetOut.Write(Txt);
2781 NetOut.Write(Mode);
2783 g_Net_Client_Send(True, NET_CHAN_CHAT);
2784 end;
2786 function isKeyPressed (key1: Word; key2: Word): Boolean;
2787 begin
2788 if (key1 <> 0) and e_KeyPressed(key1) then begin result := true; exit; end;
2789 if (key2 <> 0) and e_KeyPressed(key2) then begin result := true; exit; end;
2790 result := false;
2791 end;
2793 procedure MC_SEND_PlayerPos();
2794 var
2795 kByte: Word;
2796 Predict: Boolean;
2797 strafeDir: Byte;
2798 WeaponSelect: Word = 0;
2799 I: Integer;
2800 begin
2801 if not gGameOn then Exit;
2802 if gPlayers = nil then Exit;
2803 if gPlayer1 = nil then Exit;
2805 kByte := 0;
2806 Predict := NetPredictSelf; // and (not NetGotKeys);
2808 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2809 begin
2810 strafeDir := P1MoveButton shr 4;
2811 P1MoveButton := P1MoveButton and $0F;
2812 with gGameControls.P1Control do
2813 begin
2814 if isKeyPressed(KeyLeft, KeyLeft2) and (not isKeyPressed(KeyRight, KeyRight2)) then P1MoveButton := 1
2815 else if (not isKeyPressed(KeyLeft, KeyLeft2)) and isKeyPressed(KeyRight, KeyRight2) then P1MoveButton := 2
2816 else if (not isKeyPressed(KeyLeft, KeyLeft2)) and (not isKeyPressed(KeyRight, KeyRight2)) then P1MoveButton := 0;
2818 // strafing
2819 if isKeyPressed(KeyStrafe, KeyStrafe2) then
2820 begin
2821 // new strafe mechanics
2822 if (strafeDir = 0) then strafeDir := P1MoveButton; // start strafing
2823 // now set direction according to strafe (reversed)
2824 if (strafeDir = 2) then gPlayer1.SetDirection(D_LEFT)
2825 else if (strafeDir = 1) then gPlayer1.SetDirection(D_RIGHT);
2826 end
2827 else
2828 begin
2829 if (P1MoveButton = 2) and isKeyPressed(KeyLeft, KeyLeft2) then gPlayer1.SetDirection(D_LEFT)
2830 else if (P1MoveButton = 1) and isKeyPressed(KeyRight, KeyRight2) then gPlayer1.SetDirection(D_RIGHT)
2831 else if P1MoveButton <> 0 then gPlayer1.SetDirection(TDirection(P1MoveButton-1));
2832 end;
2834 gPlayer1.ReleaseKeys;
2835 if P1MoveButton = 1 then
2836 begin
2837 kByte := kByte or NET_KEY_LEFT;
2838 if Predict then gPlayer1.PressKey(KEY_LEFT, 10000);
2839 end;
2840 if P1MoveButton = 2 then
2841 begin
2842 kByte := kByte or NET_KEY_RIGHT;
2843 if Predict then gPlayer1.PressKey(KEY_RIGHT, 10000);
2844 end;
2845 if isKeyPressed(KeyUp, KeyUp2) then
2846 begin
2847 kByte := kByte or NET_KEY_UP;
2848 gPlayer1.PressKey(KEY_UP, 10000);
2849 end;
2850 if isKeyPressed(KeyDown, KeyDown2) then
2851 begin
2852 kByte := kByte or NET_KEY_DOWN;
2853 gPlayer1.PressKey(KEY_DOWN, 10000);
2854 end;
2855 if isKeyPressed(KeyJump, KeyJump2) then
2856 begin
2857 kByte := kByte or NET_KEY_JUMP;
2858 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2859 end;
2860 if isKeyPressed(KeyFire, KeyFire2) then kByte := kByte or NET_KEY_FIRE;
2861 if isKeyPressed(KeyOpen, KeyOpen2) then kByte := kByte or NET_KEY_OPEN;
2862 if isKeyPressed(KeyNextWeapon, KeyNextWeapon2) then kByte := kByte or NET_KEY_NW;
2863 if isKeyPressed(KeyPrevWeapon, KeyPrevWeapon2) then kByte := kByte or NET_KEY_PW;
2864 for I := 0 to High(KeyWeapon) do
2865 if isKeyPressed(KeyWeapon[I], KeyWeapon2[I]) then
2866 WeaponSelect := WeaponSelect or Word(1 shl I);
2867 end;
2868 // fix movebutton state
2869 P1MoveButton := P1MoveButton or (strafeDir shl 4);
2870 end
2871 else
2872 kByte := NET_KEY_CHAT;
2874 NetOut.Write(Byte(NET_MSG_PLRPOS));
2875 NetOut.Write(gTime);
2876 NetOut.Write(kByte);
2877 NetOut.Write(Byte(gPlayer1.Direction));
2878 NetOut.Write(WeaponSelect);
2879 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2880 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS);
2882 //kBytePrev := kByte;
2883 //kDirPrev := gPlayer1.Direction;
2884 end;
2886 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
2887 begin
2888 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
2889 NetOut.Write(Byte(Start));
2890 NetOut.Write(Command);
2891 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2892 end;
2894 procedure MC_SEND_PlayerSettings();
2895 begin
2896 NetOut.Write(Byte(NET_MSG_PLRSET));
2897 NetOut.Write(gPlayer1Settings.Name);
2898 NetOut.Write(gPlayer1Settings.Model);
2899 NetOut.Write(gPlayer1Settings.Color.R);
2900 NetOut.Write(gPlayer1Settings.Color.G);
2901 NetOut.Write(gPlayer1Settings.Color.B);
2902 NetOut.Write(gPlayer1Settings.Team);
2904 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2905 end;
2907 procedure MC_SEND_FullStateRequest();
2908 begin
2909 NetOut.Write(Byte(NET_MSG_REQFST));
2911 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2912 end;
2914 procedure MC_SEND_CheatRequest(Kind: Byte);
2915 begin
2916 NetOut.Write(Byte(NET_MSG_CHEAT));
2917 NetOut.Write(Kind);
2919 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2920 end;
2921 procedure MC_SEND_RCONPassword(Password: string);
2922 begin
2923 NetOut.Write(Byte(NET_MSG_RCON_AUTH));
2924 NetOut.Write(Password);
2926 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2927 end;
2928 procedure MC_SEND_RCONCommand(Cmd: string);
2929 begin
2930 NetOut.Write(Byte(NET_MSG_RCON_CMD));
2931 NetOut.Write(Cmd);
2933 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2934 end;
2936 // i have no idea why all this stuff is in here
2938 function ReadFile(const FileName: TFileName): AByte;
2939 var
2940 FileStream : TStream;
2941 fname: string;
2942 begin
2943 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName]), MSG_NOTIFY);
2944 fname := findDiskWad(FileName);
2945 if length(fname) = 0 then
2946 begin
2947 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName]), MSG_FATALERROR);
2948 SetLength(Result, 0);
2949 exit;
2950 end;
2951 e_WriteLog(Format('NETWORK: found file "%s"', [fname]), MSG_NOTIFY);
2952 Result := nil;
2953 FileStream := openDiskFileRO(fname);
2954 try
2955 if FileStream.Size > 0 then
2956 begin
2957 SetLength(Result, FileStream.Size);
2958 FileStream.Read(Result[0], FileStream.Size);
2959 end;
2960 finally
2961 FileStream.Free;
2962 end;
2963 end;
2965 function CreateMapDataMsg(const FileName: TFileName; ResList: TStringList): TMapDataMsg;
2966 var
2967 i: Integer;
2968 begin
2969 Result.MsgId := NET_MSG_MAP_RESPONSE;
2970 Result.FileData := ReadFile(FileName);
2971 Result.FileSize := Length(Result.FileData);
2973 SetLength(Result.ExternalResources, ResList.Count);
2974 for i:=0 to ResList.Count-1 do
2975 begin
2976 Result.ExternalResources[i].Name := ResList.Strings[i];
2977 Result.ExternalResources[i].md5 := MD5File(GameDir+'/wads/'+ResList.Strings[i]);
2978 end;
2979 end;
2981 procedure ResDataMsgToBytes(var bytes: AByte; const ResData: TResDataMsg);
2982 var
2983 ResultStream: TMemoryStream;
2984 begin
2985 ResultStream := TMemoryStream.Create;
2987 ResultStream.WriteBuffer(ResData.MsgId, SizeOf(ResData.MsgId)); //msgId
2988 ResultStream.WriteBuffer(ResData.FileSize, SizeOf(ResData.FileSize)); //file size
2989 ResultStream.WriteBuffer(ResData.FileData[0], ResData.FileSize); //file data
2991 SetLength(bytes, ResultStream.Size);
2992 ResultStream.Seek(0, soFromBeginning);
2993 ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
2995 ResultStream.Free;
2996 end;
2998 function ResDataFromMsgStream(msgStream: TMemoryStream):TResDataMsg;
2999 begin
3000 msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
3001 msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize));
3002 SetLength(Result.FileData, Result.FileSize);
3003 msgStream.ReadBuffer(Result.FileData[0], Result.FileSize);
3004 end;
3006 procedure MapDataMsgToBytes(var bytes: AByte; const MapDataMsg: TMapDataMsg);
3007 var
3008 ResultStream: TMemoryStream;
3009 resCount: Integer;
3010 begin
3011 resCount := Length(MapDataMsg.ExternalResources);
3013 ResultStream := TMemoryStream.Create;
3015 ResultStream.WriteBuffer(MapDataMsg.MsgId, SizeOf(MapDataMsg.MsgId)); //msgId
3016 ResultStream.WriteBuffer(MapDataMsg.FileSize, SizeOf(MapDataMsg.FileSize)); //file size
3017 ResultStream.WriteBuffer(MapDataMsg.FileData[0], MapDataMsg.FileSize); //file data
3019 ResultStream.WriteBuffer(resCount, SizeOf(resCount)); //res count
3020 ResultStream.WriteBuffer(MapDataMsg.ExternalResources[0], resCount*SizeOf(TExternalResourceInfo)); //res data
3022 SetLength(bytes, ResultStream.Size);
3023 ResultStream.Seek(0, soFromBeginning);
3024 ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
3026 ResultStream.Free;
3027 end;
3029 function MapDataFromMsgStream(msgStream: TMemoryStream):TMapDataMsg;
3030 var
3031 resCount: Integer;
3032 begin
3033 msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
3034 msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize)); //file size
3036 SetLength(Result.FileData, Result.FileSize);
3037 msgStream.ReadBuffer(Result.FileData[0], Result.FileSize); //file data
3039 msgStream.ReadBuffer(resCount, SizeOf(resCount)); //res count
3040 SetLength(Result.ExternalResources, resCount);
3042 msgStream.ReadBuffer(Result.ExternalResources[0], resCount * SizeOf(TExternalResourceInfo)); //res data
3043 end;
3045 function IsValidFileName(const S: String): Boolean;
3046 const
3047 Forbidden: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
3048 var
3049 I: Integer;
3050 begin
3051 Result := S <> '';
3052 for I := 1 to Length(S) do
3053 Result := Result and (not(S[I] in Forbidden));
3054 end;
3056 function IsValidFilePath(const S: String): Boolean;
3057 var
3058 I: Integer;
3059 begin
3060 Result := False;
3061 if not IsValidFileName(S) then exit;
3062 if FileExists(S) then exit;
3063 I := LastDelimiter('\/', S);
3064 if (I > 0) then
3065 if (not DirectoryExists(Copy(S, 1, I-1))) then
3066 exit;
3067 Result := True;
3068 end;
3070 procedure MC_SEND_MapRequest();
3071 begin
3072 NetOut.Write(Byte(NET_MSG_MAP_REQUEST));
3073 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3074 end;
3076 procedure MC_SEND_ResRequest(const resName: AnsiString);
3077 begin
3078 NetOut.Write(Byte(NET_MSG_RES_REQUEST));
3079 NetOut.Write(resName);
3080 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3081 end;
3083 procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
3084 var
3085 payload: AByte;
3086 peer: pENetPeer;
3087 mapDataMsg: TMapDataMsg;
3088 begin
3089 e_WriteLog('NET: Received map request from ' +
3090 DecodeIPV4(C.Peer.address.host), MSG_NOTIFY);
3092 mapDataMsg := CreateMapDataMsg(MapsDir + gGameSettings.WAD, gExternalResources);
3093 peer := NetClients[C.ID].Peer;
3095 MapDataMsgToBytes(payload, mapDataMsg);
3096 g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
3098 payload := nil;
3099 mapDataMsg.FileData := nil;
3100 mapDataMsg.ExternalResources := nil;
3101 end;
3103 procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
3104 var
3105 payload: AByte;
3106 peer: pENetPeer;
3107 FileName: String;
3108 resDataMsg: TResDataMsg;
3109 begin
3110 FileName := ExtractFileName(M.ReadString());
3111 e_WriteLog('NET: Received res request: ' + FileName +
3112 ' from ' + DecodeIPV4(C.Peer.address.host), MSG_NOTIFY);
3114 if not IsValidFilePath(FileName) then
3115 begin
3116 e_WriteLog('Invalid filename: ' + FileName, MSG_WARNING);
3117 exit;
3118 end;
3120 peer := NetClients[C.ID].Peer;
3122 if gExternalResources.IndexOf(FileName) > -1 then
3123 begin
3124 resDataMsg.MsgId := NET_MSG_RES_RESPONSE;
3125 resDataMsg.FileData := ReadFile(GameDir+'/wads/'+FileName);
3126 resDataMsg.FileSize := Length(resDataMsg.FileData);
3128 ResDataMsgToBytes(payload, resDataMsg);
3129 g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
3130 end;
3131 end;
3133 end.