DEADSOFTWARE

a7219124df1b26292b2d87aafaa4130125879e4e
[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;
112 NET_EV_SECRET = 19;
114 NET_VE_STARTED = 1;
115 NET_VE_PASSED = 2;
116 NET_VE_FAILED = 3;
117 NET_VE_VOTE = 4;
118 NET_VE_REVOKE = 5;
119 NET_VE_INPROGRESS = 6;
121 NET_FLAG_GET = 1;
122 NET_FLAG_DROP = 2;
123 NET_FLAG_CAP = 3;
124 NET_FLAG_RETURN = 4;
126 NET_CHEAT_SUICIDE = 1;
127 NET_CHEAT_SPECTATE = 2;
129 NET_MAX_DIFFTIME = 5000 div 36;
131 // HOST MESSAGES
133 procedure MH_RECV_Info(C: pTNetClient; var M: TMsg);
134 procedure MH_RECV_Chat(C: pTNetClient; var M: TMsg);
135 procedure MH_RECV_FullStateRequest(C: pTNetClient; var M: TMsg);
136 function MH_RECV_PlayerPos(C: pTNetClient; var M: TMsg): Word;
137 procedure MH_RECV_PlayerSettings(C: pTNetClient; var M: TMsg);
138 procedure MH_RECV_CheatRequest(C: pTNetClient; var M: TMsg);
139 procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
140 procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
141 procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
142 procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
143 procedure MH_RECV_Vote(C: pTNetClient; var M: TMsg);
145 // GAME
146 procedure MH_SEND_Everything(CreatePlayers: Boolean = False; ID: Integer = NET_EVERYONE);
147 procedure MH_SEND_Info(ID: Byte);
148 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
149 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
150 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
151 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
152 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
153 procedure MH_SEND_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
154 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
155 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
156 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
157 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
158 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
159 // PLAYER
160 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
161 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
162 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
163 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
164 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
165 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
166 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
167 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
168 // ITEM
169 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
170 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
171 // PANEL
172 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
173 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
174 // MONSTER
175 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
176 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
177 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
178 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
179 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
180 // TRIGGER
181 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
182 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
183 // MISC
184 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
185 procedure MH_SEND_VoteEvent(EvType: Byte;
186 StrArg1: string = 'a'; StrArg2: string = 'b';
187 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
188 ID: Integer = NET_EVERYONE);
190 // CLIENT MESSAGES //
192 // GAME
193 procedure MC_RECV_Chat(var M: TMsg);
194 procedure MC_RECV_Effect(var M: TMsg);
195 procedure MC_RECV_Sound(var M: TMsg);
196 procedure MC_RECV_GameStats(var M: TMsg);
197 procedure MC_RECV_CoopStats(var M: TMsg);
198 procedure MC_RECV_GameEvent(var M: TMsg);
199 procedure MC_RECV_FlagEvent(var M: TMsg);
200 procedure MC_RECV_GameSettings(var M: TMsg);
201 // PLAYER
202 function MC_RECV_PlayerCreate(var M: TMsg): Word;
203 function MC_RECV_PlayerPos(var M: TMsg): Word;
204 function MC_RECV_PlayerStats(var M: TMsg): Word;
205 function MC_RECV_PlayerDelete(var M: TMsg): Word;
206 function MC_RECV_PlayerDamage(var M: TMsg): Word;
207 function MC_RECV_PlayerDeath(var M: TMsg): Word;
208 function MC_RECV_PlayerFire(var M: TMsg): Word;
209 procedure MC_RECV_PlayerSettings(var M: TMsg);
210 // ITEM
211 procedure MC_RECV_ItemSpawn(var M: TMsg);
212 procedure MC_RECV_ItemDestroy(var M: TMsg);
213 // PANEL
214 procedure MC_RECV_PanelTexture(var M: TMsg);
215 procedure MC_RECV_PanelState(var M: TMsg);
216 // MONSTER
217 procedure MC_RECV_MonsterSpawn(var M: TMsg);
218 procedure MC_RECV_MonsterPos(var M: TMsg);
219 procedure MC_RECV_MonsterState(var M: TMsg);
220 procedure MC_RECV_MonsterShot(var M: TMsg);
221 procedure MC_RECV_MonsterDelete(var M: TMsg);
222 // SHOT
223 procedure MC_RECV_CreateShot(var M: TMsg);
224 procedure MC_RECV_UpdateShot(var M: TMsg);
225 procedure MC_RECV_DeleteShot(var M: TMsg);
226 // TRIGGER
227 procedure MC_RECV_TriggerSound(var M: TMsg);
228 procedure MC_RECV_TriggerMusic(var M: TMsg);
229 // MISC
230 procedure MC_RECV_TimeSync(var M: TMsg);
231 procedure MC_RECV_VoteEvent(var M: TMsg);
232 // SERVICE
233 procedure MC_SEND_Info(Password: string);
234 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
235 procedure MC_SEND_PlayerPos();
236 procedure MC_SEND_FullStateRequest();
237 procedure MC_SEND_PlayerSettings();
238 procedure MC_SEND_CheatRequest(Kind: Byte);
239 procedure MC_SEND_RCONPassword(Password: string);
240 procedure MC_SEND_RCONCommand(Cmd: string);
241 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
242 // DOWNLOAD
243 procedure MC_SEND_MapRequest();
244 procedure MC_SEND_ResRequest(const resName: AnsiString);
246 type
247 TExternalResourceInfo = record
248 Name: string[255];
249 md5: TMD5Digest;
250 end;
252 TResDataMsg = record
253 MsgId: Byte;
254 FileSize: Integer;
255 FileData: AByte;
256 end;
258 TMapDataMsg = record
259 MsgId: Byte;
260 FileSize: Integer;
261 FileData: AByte;
262 ExternalResources: array of TExternalResourceInfo;
263 end;
265 function MapDataFromMsgStream(msgStream: TMemoryStream):TMapDataMsg;
266 function ResDataFromMsgStream(msgStream: TMemoryStream):TResDataMsg;
268 implementation
270 uses
271 Math, ENet, e_input, e_graphics, e_log,
272 g_textures, g_gfx, g_sound, g_console, g_basic, g_options, g_main,
273 g_game, g_player, g_map, g_panel, g_items, g_weapons, g_phys, g_gui,
274 g_language, g_monsters, g_netmaster, utils, wadreader, MAPDEF;
276 const
277 NET_KEY_LEFT = 1;
278 NET_KEY_RIGHT = 2;
279 NET_KEY_UP = 4;
280 NET_KEY_DOWN = 8;
281 NET_KEY_JUMP = 16;
282 NET_KEY_FIRE = 32;
283 NET_KEY_OPEN = 64;
284 NET_KEY_NW = 256;
285 NET_KEY_PW = 512;
286 NET_KEY_CHAT = 2048;
287 NET_KEY_FORCEDIR = 4096;
289 //var
290 //kBytePrev: Word = 0;
291 //kDirPrev: TDirection = D_LEFT;
292 //HostGameTime: Word = 0;
294 // HOST MESSAGES //
297 // GAME
299 procedure MH_RECV_Chat(C: pTNetClient; var M: TMsg);
300 var
301 Txt: string;
302 Mode: Byte;
303 PID: Word;
304 Pl: TPlayer;
305 begin
306 PID := C^.Player;
307 Pl := g_Player_Get(PID);
309 Txt := M.ReadString();
310 Mode := M.ReadByte();
311 if (Mode = NET_CHAT_SYSTEM) then
312 Mode := NET_CHAT_PLAYER; // prevent sending system messages from clients
313 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
314 Mode := NET_CHAT_PLAYER; // revert to player chat in non-team game
316 if Pl = nil then
317 MH_SEND_Chat(Txt, Mode)
318 else
319 MH_SEND_Chat(Pl.Name + ': ' + Txt, Mode, IfThen(Mode = NET_CHAT_TEAM, Pl.Team, NET_EVERYONE));
320 end;
322 procedure MH_RECV_Info(C: pTNetClient; var M: TMsg);
323 var
324 Ver, PName, Model, Pw: string;
325 R, G, B, T: Byte;
326 PID: Word;
327 Color: TRGB;
328 I: Integer;
329 begin
330 Ver := M.ReadString();
331 Pw := M.ReadString();
332 PName := M.ReadString();
333 Model := M.ReadString();
334 R := M.ReadByte();
335 G := M.ReadByte();
336 B := M.ReadByte();
337 T := M.ReadByte();
339 if Ver <> GAME_VERSION then
340 begin
341 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
342 _lc[I_NET_DISC_VERSION]);
343 enet_peer_disconnect(C^.Peer, NET_DISC_VERSION);
344 Exit;
345 end;
347 if g_Net_IsHostBanned(C^.Peer^.address.host) then
348 begin
349 if g_Net_IsHostBanned(C^.Peer^.address.host, True) then
350 begin
351 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
352 _lc[I_NET_DISC_BAN]);
353 enet_peer_disconnect(C^.Peer, NET_DISC_BAN);
354 end
355 else
356 begin
357 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
358 _lc[I_NET_DISC_BAN]);
359 enet_peer_disconnect(C^.Peer, NET_DISC_TEMPBAN);
360 end;
361 Exit;
362 end;
364 if NetPassword <> '' then
365 if AnsiLowerCase(NetPassword) <> AnsiLowerCase(Pw) then
366 begin
367 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
368 _lc[I_NET_DISC_PASSWORD]);
369 enet_peer_disconnect(C^.Peer, NET_DISC_PASSWORD);
370 Exit;
371 end;
373 Color.R := R;
374 Color.B := B;
375 Color.G := G;
377 PID := g_Player_Create(Model, Color, T, False);
378 with g_Player_Get(PID) do
379 begin
380 Name := PName;
381 Reset(True);
382 end;
384 C^.Player := PID;
386 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
387 e_WriteLog('NET: Client ' + PName + ' [' + IntToStr(C^.ID) +
388 '] connected. Assigned player #' + IntToStr(PID) + '.', TMsgType.Notify);
390 MH_SEND_Info(C^.ID);
392 with g_Player_Get(PID) do
393 begin
394 Name := PName;
395 FClientID := C^.ID;
396 // round in progress, don't spawn
397 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
398 begin
399 Lives := 0;
400 FNoRespawn := True;
401 Spectate;
402 FWantsInGame := True; // TODO: look into this later
403 end
404 else
405 Respawn(gGameSettings.GameType = GT_SINGLE);
406 end;
408 for I := Low(NetClients) to High(NetClients) do
409 begin
410 if NetClients[I].ID = C^.ID then Continue;
411 MH_SEND_PlayerCreate(PID, NetClients[I].ID);
412 MH_SEND_PlayerPos(True, PID, NetClients[I].ID);
413 MH_SEND_PlayerStats(PID, NetClients[I].ID);
414 end;
416 if gState in [STATE_INTERCUSTOM, STATE_FOLD] then
417 MH_SEND_GameEvent(NET_EV_MAPEND, 0, 'N', C^.ID);
419 if NetUseMaster then g_Net_Slist_Update;
420 end;
422 procedure MH_RECV_FullStateRequest(C: pTNetClient; var M: TMsg);
423 begin
424 if gGameOn then
425 MH_SEND_Everything((C^.State = NET_STATE_AUTH), C^.ID)
426 else
427 C^.RequestedFullUpdate := True;
428 end;
430 // PLAYER
432 function MH_RECV_PlayerPos(C: pTNetClient; var M: TMsg): Word;
433 var
434 Dir, i: Byte;
435 WeaponSelect: Word;
436 PID: Word;
437 kByte: Word;
438 Pl: TPlayer;
439 GT: LongWord;
440 begin
441 Result := 0;
442 if not gGameOn then Exit;
444 GT := M.ReadLongWord();
445 PID := C^.Player;
446 Pl := g_Player_Get(PID);
447 if Pl = nil then
448 Exit;
450 if (GT > gTime + NET_MAX_DIFFTIME) or (GT < Pl.NetTime) then Exit;
452 with Pl do
453 begin
454 NetTime := GT;
455 kByte := M.ReadWord();
456 Dir := M.ReadByte();
457 WeaponSelect := M.ReadWord();
458 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
459 if Direction <> TDirection(Dir) then
460 JustTeleported := False;
462 SetDirection(TDirection(Dir));
463 ReleaseKeys;
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 for i := 0 to 15 do
482 begin
483 if (WeaponSelect and Word(1 shl i)) <> 0 then
484 begin
485 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
486 QueueWeaponSwitch(i);
487 end;
488 end;
489 end;
491 // MH_SEND_PlayerPos(False, PID, C^.ID);
492 end;
494 procedure MH_RECV_CheatRequest(C: pTNetClient; var M: TMsg);
495 var
496 CheatKind: Byte;
497 Pl: TPlayer;
498 begin
499 Pl := g_Player_Get(C^.Player);
500 if Pl = nil then Exit;
502 CheatKind := M.ReadByte();
504 case CheatKind of
505 NET_CHEAT_SUICIDE:
506 Pl.Damage(SUICIDE_DAMAGE, Pl.UID, 0, 0, HIT_SELF);
507 NET_CHEAT_SPECTATE:
508 begin
509 if Pl.FSpectator then
510 Pl.Respawn(False)
511 else
512 Pl.Spectate;
513 end;
514 end;
515 end;
517 procedure MH_RECV_PlayerSettings(C: pTNetClient; var M: TMsg);
518 var
519 TmpName: string;
520 TmpModel: string;
521 TmpColor: TRGB;
522 TmpTeam: Byte;
523 Pl: TPlayer;
524 begin
525 TmpName := M.ReadString();
526 TmpModel := M.ReadString();
527 TmpColor.R := M.ReadByte();
528 TmpColor.G := M.ReadByte();
529 TmpColor.B := M.ReadByte();
530 TmpTeam := M.ReadByte();
532 Pl := g_Player_Get(C^.Player);
533 if Pl = nil then Exit;
535 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
536 Pl.SwitchTeam
537 else
538 Pl.SetColor(TmpColor);
540 if Pl.Name <> TmpName then
541 begin
542 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
543 Pl.Name := TmpName;
544 end;
546 if TmpModel <> Pl.Model.Name then
547 Pl.SetModel(TmpModel);
549 MH_SEND_PlayerSettings(Pl.UID, TmpModel);
550 end;
552 // RCON
554 procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
555 var
556 Pwd: string;
557 begin
558 Pwd := M.ReadString();
559 if not NetAllowRCON then Exit;
560 if Pwd = NetRCONPassword then
561 begin
562 C^.RCONAuth := True;
563 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWGOOD, 'N', C^.ID);
564 end
565 else
566 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWBAD, 'N', C^.ID);
567 end;
569 procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
570 var
571 Cmd: string;
572 begin
573 Cmd := M.ReadString();
574 if not NetAllowRCON then Exit;
575 if not C^.RCONAuth then
576 begin
577 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_NOAUTH, 'N', C^.ID);
578 Exit;
579 end;
580 g_Console_Process(Cmd);
581 end;
583 // MISC
585 procedure MH_RECV_Vote(C: pTNetClient; var M: TMsg);
586 var
587 Start: Boolean;
588 Name, Command: string;
589 Need: Integer;
590 Pl: TPlayer;
591 begin
592 Start := M.ReadByte() <> 0;
593 Command := M.ReadString();
595 Pl := g_Player_Get(C^.Player);
596 if Pl = nil then Exit;
597 Name := Pl.Name;
599 if Start then
600 begin
601 if not g_Console_CommandBlacklisted(Command) then
602 g_Game_StartVote(Command, Name);
603 end
604 else if gVoteInProgress then
605 begin
606 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
607 Need := Floor((NetClientCount+1)/2.0) + 1
608 else
609 Need := Floor(NetClientCount/2.0) + 1;
610 if C^.Voted then
611 begin
612 Dec(gVoteCount);
613 C^.Voted := False;
614 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [Name, gVoteCount, Need]), True);
615 MH_SEND_VoteEvent(NET_VE_REVOKE, Name, 'a', gVoteCount, Need);
616 end
617 else
618 begin
619 Inc(gVoteCount);
620 C^.Voted := True;
621 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Name, gVoteCount, Need]), True);
622 MH_SEND_VoteEvent(NET_VE_VOTE, Name, 'a', gVoteCount, Need);
623 g_Game_CheckVote;
624 end;
625 end;
626 end;
628 // GAME (SEND)
630 procedure MH_SEND_Everything(CreatePlayers: Boolean = False; ID: Integer = NET_EVERYONE);
632 function sendItemRespawn (it: PItem): Boolean;
633 begin
634 result := false; // don't stop
635 MH_SEND_ItemSpawn(True, it.myid, ID);
636 end;
638 function sendMonSpawn (mon: TMonster): Boolean;
639 begin
640 result := false; // don't stop
641 MH_SEND_MonsterSpawn(mon.UID, ID);
642 end;
644 function sendPanelState (pan: TPanel): Boolean;
645 begin
646 result := false; // don't stop
647 MH_SEND_PanelState(pan.guid, ID); // anyway, to sync mplats
648 if (pan.CanChangeTexture) then MH_SEND_PanelTexture(pan.guid, pan.LastAnimLoop, ID);
649 end;
651 var
652 I: Integer;
653 begin
654 if gPlayers <> nil then
655 begin
656 for I := Low(gPlayers) to High(gPlayers) do
657 begin
658 if gPlayers[I] <> nil then
659 begin
660 if CreatePlayers then MH_SEND_PlayerCreate(gPlayers[I].UID, ID);
661 MH_SEND_PlayerPos(True, gPlayers[I].UID, ID);
662 MH_SEND_PlayerStats(gPlayers[I].UID, ID);
664 if (gPlayers[I].Flag <> FLAG_NONE) and (gGameSettings.GameMode = GM_CTF) then
665 begin
666 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED, gPlayers[I].Flag, gPlayers[I].UID, True, ID);
667 end;
668 end;
669 end;
670 end;
672 g_Items_ForEachAlive(sendItemRespawn, true); // backwards
673 g_Mons_ForEach(sendMonSpawn);
674 g_Map_ForEachPanel(sendPanelState);
676 if gTriggers <> nil then
677 begin
678 for I := Low(gTriggers) to High(gTriggers) do
679 begin
680 if gTriggers[I].TriggerType = TRIGGER_SOUND then
681 begin
682 MH_SEND_TriggerSound(gTriggers[I], ID);
683 end;
684 end;
685 end;
687 if Shots <> nil then
688 begin
689 for I := Low(Shots) to High(Shots) do
690 begin
691 if Shots[i].ShotType in [6, 7, 8] then
692 begin
693 MH_SEND_CreateShot(i, ID);
694 end;
695 end;
696 end;
698 MH_SEND_TriggerMusic(ID);
700 MH_SEND_GameStats(ID);
701 MH_SEND_CoopStats(ID);
703 if gGameSettings.GameMode = GM_CTF then
704 begin
705 if gFlags[FLAG_RED].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_RED].State, FLAG_RED, 0, True, ID);
706 if gFlags[FLAG_BLUE].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_BLUE].State, FLAG_BLUE, 0, True, ID);
707 end;
709 if CreatePlayers and (ID >= 0) then NetClients[ID].State := NET_STATE_GAME;
711 if gLMSRespawn > LMS_RESPAWN_NONE then
712 begin
713 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000, 'N', ID);
714 end;
715 end;
717 procedure MH_SEND_Info(ID: Byte);
718 var
719 Map: string;
720 begin
721 Map := g_ExtractFileName(gMapInfo.Map);
723 NetOut.Clear();
725 NetOut.Write(Byte(NET_MSG_INFO));
726 NetOut.Write(ID);
727 NetOut.Write(NetClients[ID].Player);
728 NetOut.Write(gGameSettings.WAD);
729 NetOut.Write(Map);
730 NetOut.Write(gWADHash);
731 NetOut.Write(gGameSettings.GameMode);
732 NetOut.Write(gGameSettings.GoalLimit);
733 NetOut.Write(gGameSettings.TimeLimit);
734 NetOut.Write(gGameSettings.MaxLives);
735 NetOut.Write(gGameSettings.Options);
736 NetOut.Write(gTime);
738 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
739 end;
741 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
742 var
743 Name: string;
744 i: Integer;
745 Team: Byte;
746 begin
747 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
748 Mode := NET_CHAT_PLAYER;
750 Team := 0;
751 if (Mode = NET_CHAT_TEAM) then
752 begin
753 for i := Low(gPlayers) to High(gPlayers) do
754 if (gPlayers[i] <> nil) and (gPlayers[i].FClientID >= 0) and
755 (gPlayers[i].Team = ID) then
756 begin
757 NetOut.Write(Byte(NET_MSG_CHAT));
758 NetOut.Write(Txt);
759 NetOut.Write(Mode);
760 g_Net_Host_Send(gPlayers[i].FClientID, True, NET_CHAN_CHAT);
761 end;
762 Team := ID;
763 ID := NET_EVERYONE;
764 end
765 else
766 begin
767 NetOut.Write(Byte(NET_MSG_CHAT));
768 NetOut.Write(Txt);
769 NetOut.Write(Mode);
770 g_Net_Host_Send(ID, True, NET_CHAN_CHAT);
771 end;
773 if Mode = NET_CHAT_SYSTEM then
774 Exit;
776 if ID = NET_EVERYONE then
777 begin
778 if Mode = NET_CHAT_PLAYER then
779 begin
780 g_Console_Add(Txt, True);
781 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
782 g_Game_ChatSound(b_Text_Unformat(Txt));
783 end
784 else
785 if Mode = NET_CHAT_TEAM then
786 if gPlayer1 <> nil then
787 begin
788 if (gPlayer1.Team = TEAM_RED) and (Team = TEAM_RED) then
789 begin
790 g_Console_Add(#18'[Team] '#2 + Txt, True);
791 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
792 g_Game_ChatSound(b_Text_Unformat(Txt));
793 end
794 else if (gPlayer1.Team = TEAM_BLUE) and (Team = TEAM_BLUE) then
795 begin
796 g_Console_Add(#20'[Team] '#2 + Txt, True);
797 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
798 g_Game_ChatSound(b_Text_Unformat(Txt));
799 end;
800 end;
801 end
802 else
803 begin
804 Name := g_Net_ClientName_ByID(ID);
805 g_Console_Add('-> ' + Name + ': ' + Txt, True);
806 e_WriteLog('[Tell ' + Name + '] ' + b_Text_Unformat(Txt), TMsgType.Notify);
807 g_Game_ChatSound(b_Text_Unformat(Txt), False);
808 end;
809 end;
811 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
812 begin
813 NetOut.Write(Byte(NET_MSG_GFX));
814 NetOut.Write(Kind);
815 NetOut.Write(X);
816 NetOut.Write(Y);
817 NetOut.Write(Ang);
819 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
820 end;
822 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
823 begin
824 NetOut.Write(Byte(NET_MSG_SND));
825 NetOut.Write(Name);
826 if Pos then
827 begin
828 NetOut.Write(Byte(1));
829 NetOut.Write(X);
830 NetOut.Write(Y);
831 end
832 else
833 NetOut.Write(Byte(0));
835 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
836 end;
838 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
839 begin
840 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
842 NetOut.Write(Byte(NET_MSG_SHADD));
843 NetOut.Write(Proj);
844 NetOut.Write(Shots[Proj].ShotType);
845 NetOut.Write(Shots[Proj].Target);
846 NetOut.Write(Shots[Proj].SpawnerUID);
847 NetOut.Write(Shots[Proj].Timeout);
848 NetOut.Write(Shots[Proj].Obj.X);
849 NetOut.Write(Shots[Proj].Obj.Y);
850 NetOut.Write(Shots[Proj].Obj.Vel.X);
851 NetOut.Write(Shots[Proj].Obj.Vel.Y);
853 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
854 end;
856 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
857 begin
858 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
860 NetOut.Write(Byte(NET_MSG_SHPOS));
861 NetOut.Write(Proj);
862 NetOut.Write(Shots[Proj].Obj.X);
863 NetOut.Write(Shots[Proj].Obj.Y);
864 NetOut.Write(Shots[Proj].Obj.Vel.X);
865 NetOut.Write(Shots[Proj].Obj.Vel.Y);
867 g_Net_Host_Send(ID, False, NET_CHAN_SHOTS);
868 end;
870 procedure MH_Send_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
871 begin
872 NetOut.Write(Byte(NET_MSG_SHDEL));
873 NetOut.Write(Proj);
874 NetOut.Write(Byte(Loud));
875 NetOut.Write(X);
876 NetOut.Write(Y);
878 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
879 end;
881 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
882 begin
883 NetOut.Write(Byte(NET_MSG_SCORE));
884 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
885 begin
886 NetOut.Write(gTeamStat[TEAM_RED].Goals);
887 NetOut.Write(gTeamStat[TEAM_BLUE].Goals);
888 end
889 else
890 if gGameSettings.GameMode = GM_COOP then
891 begin
892 NetOut.Write(gCoopMonstersKilled);
893 NetOut.Write(gCoopSecretsFound);
894 end;
896 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
897 end;
899 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
900 begin
901 NetOut.Write(Byte(NET_MSG_COOP));
902 NetOut.Write(gTotalMonsters);
903 NetOut.Write(gSecretsCount);
904 NetOut.Write(gCoopTotalMonstersKilled);
905 NetOut.Write(gCoopTotalSecretsFound);
906 NetOut.Write(gCoopTotalMonsters);
907 NetOut.Write(gCoopTotalSecrets);
908 end;
910 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
911 begin
912 NetOut.Write(Byte(NET_MSG_GEVENT));
913 NetOut.Write(EvType);
914 NetOut.Write(EvNum);
915 NetOut.Write(EvStr);
916 NetOut.Write(Byte(gLastMap));
917 NetOut.Write(gTime);
918 if (EvType = NET_EV_MAPSTART) and isWadPath(EvStr) then
919 begin
920 NetOut.Write(Byte(1));
921 NetOut.Write(gWADHash);
922 end else
923 NetOut.Write(Byte(0));
925 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
926 end;
928 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
929 begin
930 NetOut.Write(Byte(NET_MSG_FLAG));
931 NetOut.Write(EvType);
932 NetOut.Write(Flag);
933 NetOut.Write(Byte(Quiet));
934 NetOut.Write(PID);
935 NetOut.Write(gFlags[Flag].State);
936 NetOut.Write(gFlags[Flag].CaptureTime);
937 NetOut.Write(gFlags[Flag].Obj.X);
938 NetOut.Write(gFlags[Flag].Obj.Y);
939 NetOut.Write(gFlags[Flag].Obj.Vel.X);
940 NetOut.Write(gFlags[Flag].Obj.Vel.Y);
942 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
943 end;
945 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
946 begin
947 NetOut.Write(Byte(NET_MSG_GSET));
948 NetOut.Write(gGameSettings.GameMode);
949 NetOut.Write(gGameSettings.GoalLimit);
950 NetOut.Write(gGameSettings.TimeLimit);
951 NetOut.Write(gGameSettings.MaxLives);
952 NetOut.Write(gGameSettings.Options);
954 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
955 end;
957 // PLAYER (SEND)
959 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
960 var
961 P: TPlayer;
962 begin
963 P := g_Player_Get(PID);
964 if P = nil then Exit;
966 NetOut.Write(Byte(NET_MSG_PLR));
967 NetOut.Write(PID);
968 NetOut.Write(P.Name);
970 NetOut.Write(P.FActualModelName);
971 NetOut.Write(P.FColor.R);
972 NetOut.Write(P.FColor.G);
973 NetOut.Write(P.FColor.B);
974 NetOut.Write(P.Team);
976 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT)
977 end;
979 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
980 var
981 kByte: Word;
982 Pl: TPlayer;
983 begin
984 Pl := g_Player_Get(PID);
985 if Pl = nil then Exit;
986 if Pl.FDummy then Exit;
988 NetOut.Write(Byte(NET_MSG_PLRPOS));
989 NetOut.Write(gTime);
990 NetOut.Write(PID);
992 kByte := 0;
994 with Pl do
995 begin
996 NetOut.Write(FPing);
997 NetOut.Write(FLoss);
998 if IsKeyPressed(KEY_CHAT) then
999 kByte := NET_KEY_CHAT
1000 else
1001 begin
1002 if IsKeyPressed(KEY_LEFT) then kByte := kByte or NET_KEY_LEFT;
1003 if IsKeyPressed(KEY_RIGHT) then kByte := kByte or NET_KEY_RIGHT;
1004 if IsKeyPressed(KEY_UP) then kByte := kByte or NET_KEY_UP;
1005 if IsKeyPressed(KEY_DOWN) then kByte := kByte or NET_KEY_DOWN;
1006 if IsKeyPressed(KEY_JUMP) then kByte := kByte or NET_KEY_JUMP;
1007 if JustTeleported then kByte := kByte or NET_KEY_FORCEDIR;
1008 end;
1010 NetOut.Write(kByte);
1011 if Direction = TDirection.D_LEFT then NetOut.Write(Byte(0)) else NetOut.Write(Byte(1));
1012 NetOut.Write(GameX);
1013 NetOut.Write(GameY);
1014 NetOut.Write(GameVelX);
1015 NetOut.Write(GameVelY);
1016 NetOut.Write(GameAccelX);
1017 NetOut.Write(GameAccelY);
1018 end;
1020 g_Net_Host_Send(ID, Reliable, NET_CHAN_PLAYERPOS);
1021 end;
1023 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
1024 var
1025 P: TPlayer;
1026 I: Integer;
1027 begin
1028 P := g_Player_Get(PID);
1029 if P = nil then Exit;
1031 NetOut.Write(Byte(NET_MSG_PLRSTA));
1032 NetOut.Write(PID);
1034 with P do
1035 begin
1036 NetOut.Write(Byte(alive));
1037 NetOut.Write(Byte(GodMode));
1038 NetOut.Write(Health);
1039 NetOut.Write(Armor);
1040 NetOut.Write(Air);
1041 NetOut.Write(JetFuel);
1042 NetOut.Write(Lives);
1043 NetOut.Write(Team);
1045 for I := WP_FIRST to WP_LAST do
1046 NetOut.Write(Byte(FWeapon[I]));
1048 for I := A_BULLETS to A_HIGH do
1049 NetOut.Write(FAmmo[I]);
1051 for I := A_BULLETS to A_HIGH do
1052 NetOut.Write(FMaxAmmo[I]);
1054 for I := MR_SUIT to MR_MAX do
1055 NetOut.Write(LongWord(FMegaRulez[I]));
1057 NetOut.Write(Byte(R_ITEM_BACKPACK in FRulez));
1058 NetOut.Write(Byte(R_KEY_RED in FRulez));
1059 NetOut.Write(Byte(R_KEY_GREEN in FRulez));
1060 NetOut.Write(Byte(R_KEY_BLUE in FRulez));
1061 NetOut.Write(Byte(R_BERSERK in FRulez));
1063 NetOut.Write(Frags);
1064 NetOut.Write(Death);
1066 NetOut.Write(CurrWeap);
1068 NetOut.Write(Byte(FSpectator));
1069 NetOut.Write(Byte(FGhost));
1070 NetOut.Write(Byte(FPhysics));
1071 NetOut.Write(Byte(FNoRespawn));
1072 NetOut.Write(Byte(FJetpack));
1073 NetOut.Write(FFireTime);
1074 NetOut.Write(Byte(FFlaming));
1075 end;
1077 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1078 end;
1080 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
1081 begin
1082 NetOut.Write(Byte(NET_MSG_PLRDMG));
1083 NetOut.Write(PID);
1084 NetOut.Write(Kind);
1085 NetOut.Write(Attacker);
1086 NetOut.Write(Value);
1087 NetOut.Write(VX);
1088 NetOut.Write(VY);
1090 g_Net_Host_Send(ID, False, NET_CHAN_PLAYER);
1091 end;
1093 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
1094 begin
1095 NetOut.Write(Byte(NET_MSG_PLRDIE));
1096 NetOut.Write(PID);
1097 NetOut.Write(KillType);
1098 NetOut.Write(DeathType);
1099 NetOut.Write(Attacker);
1101 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1102 end;
1104 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
1105 begin
1106 NetOut.Write(Byte(NET_MSG_PLRFIRE));
1107 NetOut.Write(PID);
1108 NetOut.Write(Weapon);
1109 NetOut.Write(X);
1110 NetOut.Write(Y);
1111 NetOut.Write(AX);
1112 NetOut.Write(AY);
1113 NetOut.Write(ShotID);
1115 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1116 end;
1118 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
1119 begin
1120 NetOut.Write(Byte(NET_MSG_PLRDEL));
1121 NetOut.Write(PID);
1123 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1124 end;
1126 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
1127 var
1128 Pl: TPlayer;
1129 begin
1130 Pl := g_Player_Get(PID);
1131 if Pl = nil then Exit;
1133 NetOut.Write(Byte(NET_MSG_PLRSET));
1134 NetOut.Write(PID);
1135 NetOut.Write(Pl.Name);
1136 if Mdl = '' then
1137 NetOut.Write(Pl.Model.Name)
1138 else
1139 NetOut.Write(Mdl);
1140 NetOut.Write(Pl.FColor.R);
1141 NetOut.Write(Pl.FColor.G);
1142 NetOut.Write(Pl.FColor.B);
1143 NetOut.Write(Pl.Team);
1145 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1146 end;
1148 // ITEM (SEND)
1150 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1151 var
1152 it: PItem;
1153 tt: Byte;
1154 begin
1155 it := g_Items_ByIdx(IID);
1157 NetOut.Write(Byte(NET_MSG_ISPAWN));
1158 NetOut.Write(IID);
1159 NetOut.Write(Byte(Quiet));
1160 tt := it.ItemType;
1161 if it.dropped then tt := tt or $80;
1162 NetOut.Write(tt);
1163 NetOut.Write(Byte(it.Fall));
1164 NetOut.Write(Byte(it.Respawnable));
1165 NetOut.Write(it.Obj.X);
1166 NetOut.Write(it.Obj.Y);
1167 NetOut.Write(it.Obj.Vel.X);
1168 NetOut.Write(it.Obj.Vel.Y);
1170 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1171 end;
1173 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1174 begin
1175 NetOut.Write(Byte(NET_MSG_IDEL));
1176 NetOut.Write(IID);
1177 NetOut.Write(Byte(Quiet));
1179 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1180 end;
1182 // PANEL
1184 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
1185 var
1186 TP: TPanel;
1187 begin
1188 TP := g_Map_PanelByGUID(PGUID);
1189 if (TP = nil) then exit;
1191 with TP do
1192 begin
1193 NetOut.Write(Byte(NET_MSG_PTEX));
1194 NetOut.Write(LongWord(PGUID));
1195 NetOut.Write(FCurTexture);
1196 NetOut.Write(FCurFrame);
1197 NetOut.Write(FCurFrameCount);
1198 NetOut.Write(AnimLoop);
1199 end;
1201 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1202 end;
1204 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
1205 var
1206 TP: TPanel;
1207 mpflags: Byte = 0;
1208 begin
1209 TP := g_Map_PanelByGUID(PGUID);
1210 if (TP = nil) then exit;
1212 NetOut.Write(Byte(NET_MSG_PSTATE));
1213 NetOut.Write(LongWord(PGUID));
1214 NetOut.Write(Byte(TP.Enabled));
1215 NetOut.Write(TP.LiftType);
1216 NetOut.Write(TP.X);
1217 NetOut.Write(TP.Y);
1218 NetOut.Write(Word(TP.Width));
1219 NetOut.Write(Word(TP.Height));
1220 // mplats
1221 NetOut.Write(LongInt(TP.movingSpeedX));
1222 NetOut.Write(LongInt(TP.movingSpeedY));
1223 NetOut.Write(LongInt(TP.movingStartX));
1224 NetOut.Write(LongInt(TP.movingStartY));
1225 NetOut.Write(LongInt(TP.movingEndX));
1226 NetOut.Write(LongInt(TP.movingEndY));
1227 NetOut.Write(LongInt(TP.sizeSpeedX));
1228 NetOut.Write(LongInt(TP.sizeSpeedY));
1229 NetOut.Write(LongInt(TP.sizeEndX));
1230 NetOut.Write(LongInt(TP.sizeEndY));
1231 if TP.movingActive then mpflags := mpflags or 1;
1232 if TP.moveOnce then mpflags := mpflags or 2;
1233 NetOut.Write(Byte(mpflags));
1235 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1236 end;
1238 // TRIGGER
1240 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
1241 begin
1242 if gTriggers = nil then Exit;
1243 if T.Sound = nil then Exit;
1245 NetOut.Write(Byte(NET_MSG_TSOUND));
1246 NetOut.Write(T.ClientID);
1247 NetOut.Write(Byte(T.Sound.IsPlaying));
1248 NetOut.Write(LongWord(T.Sound.GetPosition));
1249 NetOut.Write(T.SoundPlayCount);
1251 g_Net_Host_Send(ID, True);
1252 end;
1254 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
1255 begin
1256 NetOut.Write(Byte(NET_MSG_TMUSIC));
1257 NetOut.Write(gMusic.Name);
1258 NetOut.Write(Byte(gMusic.IsPlaying));
1259 NetOut.Write(LongWord(gMusic.GetPosition));
1260 NetOut.Write(Byte(gMusic.SpecPause or gMusic.IsPaused));
1262 g_Net_Host_Send(ID, True);
1263 end;
1265 // MONSTER
1267 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
1268 var
1269 M: TMonster;
1270 begin
1271 M := g_Monsters_ByUID(UID);
1272 if M = nil then
1273 Exit;
1275 with M do
1276 begin
1277 NetOut.Write(Byte(NET_MSG_MSPAWN));
1278 NetOut.Write(UID);
1279 NetOut.Write(MonsterType);
1280 NetOut.Write(MonsterState);
1281 NetOut.Write(MonsterAnim);
1282 NetOut.Write(MonsterTargetUID);
1283 NetOut.Write(MonsterTargetTime);
1284 NetOut.Write(MonsterBehaviour);
1285 NetOut.Write(MonsterSleep);
1286 NetOut.Write(MonsterHealth);
1287 NetOut.Write(MonsterAmmo);
1288 NetOut.Write(GameX);
1289 NetOut.Write(GameY);
1290 NetOut.Write(GameVelX);
1291 NetOut.Write(GameVelY);
1292 NetOut.Write(Byte(GameDirection));
1293 end;
1295 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1296 end;
1298 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
1299 var
1300 M: TMonster;
1301 begin
1302 M := g_Monsters_ByUID(UID);
1303 if M = nil then Exit;
1305 NetOut.Write(Byte(NET_MSG_MPOS));
1306 NetOut.Write(UID);
1308 with M do
1309 begin
1310 NetOut.Write(GameX);
1311 NetOut.Write(GameY);
1312 NetOut.Write(GameVelX);
1313 NetOut.Write(GameVelY);
1314 NetOut.Write(Byte(GameDirection));
1315 end;
1317 g_Net_Host_Send(ID, False, NET_CHAN_MONSTERPOS);
1318 end;
1320 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
1321 var
1322 M: TMonster;
1323 begin
1324 M := g_Monsters_ByUID(UID);
1325 if M = nil then Exit;
1327 NetOut.Write(Byte(NET_MSG_MSTATE));
1328 NetOut.Write(UID);
1330 with M do
1331 begin
1332 NetOut.Write(MonsterState);
1333 NetOut.Write(ForcedAnim);
1334 NetOut.Write(MonsterTargetUID);
1335 NetOut.Write(MonsterTargetTime);
1336 NetOut.Write(MonsterSleep);
1337 NetOut.Write(MonsterHealth);
1338 NetOut.Write(MonsterAmmo);
1339 NetOut.Write(MonsterPain);
1340 NetOut.Write(Byte(AnimIsReverse));
1341 NetOut.Write(FFireTime);
1342 end;
1344 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1345 end;
1347 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
1348 begin
1349 NetOut.Write(Byte(NET_MSG_MSHOT));
1350 NetOut.Write(UID);
1351 NetOut.Write(X);
1352 NetOut.Write(Y);
1353 NetOut.Write(VX);
1354 NetOut.Write(VY);
1356 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1357 end;
1359 procedure MH_SEND_MonsterDelete(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_MDEL));
1367 NetOut.Write(UID);
1369 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1370 end;
1372 // MISC
1374 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
1375 begin
1376 NetOut.Write(Byte(NET_MSG_TIME_SYNC));
1377 NetOut.Write(Time);
1379 g_Net_Host_Send(ID, False, NET_CHAN_SERVICE);
1380 end;
1382 procedure MH_SEND_VoteEvent(EvType: Byte;
1383 StrArg1: string = 'a'; StrArg2: string = 'b';
1384 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
1385 ID: Integer = NET_EVERYONE);
1386 begin
1387 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
1388 NetOut.Write(EvType);
1389 NetOut.Write(IntArg1);
1390 NetOut.Write(IntArg2);
1391 NetOut.Write(StrArg1);
1392 NetOut.Write(StrArg2);
1394 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1395 end;
1397 // CLIENT MESSAGES //
1399 // GAME
1401 procedure MC_RECV_Chat(var M: TMsg);
1402 var
1403 Txt: string;
1404 Mode: Byte;
1405 begin
1406 Txt := M.ReadString();
1407 Mode := M.ReadByte();
1409 if Mode <> NET_CHAT_SYSTEM then
1410 begin
1411 if Mode = NET_CHAT_PLAYER then
1412 begin
1413 g_Console_Add(Txt, True);
1414 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1415 g_Game_ChatSound(b_Text_Unformat(Txt));
1416 end else
1417 if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then
1418 begin
1419 if gPlayer1.Team = TEAM_RED then
1420 g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True);
1421 if gPlayer1.Team = TEAM_BLUE then
1422 g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True);
1423 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1424 g_Game_ChatSound(b_Text_Unformat(Txt));
1425 end;
1426 end else
1427 g_Console_Add(Txt, True);
1428 end;
1430 procedure MC_RECV_Effect(var M: TMsg);
1431 var
1432 Kind: Byte;
1433 X, Y: Integer;
1434 Ang: SmallInt;
1435 Anim: TAnimation;
1436 ID: LongWord;
1437 begin
1438 if not gGameOn then Exit;
1439 Kind := M.ReadByte();
1440 X := M.ReadLongInt();
1441 Y := M.ReadLongInt();
1442 Ang := M.ReadSmallInt();
1444 case Kind of
1445 NET_GFX_SPARK:
1446 g_GFX_Spark(X, Y, 2 + Random(2), Ang, 0, 0);
1448 NET_GFX_TELE:
1449 begin
1450 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
1451 begin
1452 Anim := TAnimation.Create(ID, False, 3);
1453 g_GFX_OnceAnim(X, Y, Anim);
1454 Anim.Free();
1455 end;
1456 if Ang = 1 then
1457 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
1458 end;
1460 NET_GFX_EXPLODE:
1461 begin
1462 if g_Frames_Get(ID, 'FRAMES_EXPLODE_ROCKET') then
1463 begin
1464 Anim := TAnimation.Create(ID, False, 6);
1465 Anim.Blending := False;
1466 g_GFX_OnceAnim(X-64, Y-64, Anim);
1467 Anim.Free();
1468 end;
1469 if Ang = 1 then
1470 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X, Y);
1471 end;
1473 NET_GFX_BFGEXPL:
1474 begin
1475 if g_Frames_Get(ID, 'FRAMES_EXPLODE_BFG') then
1476 begin
1477 Anim := TAnimation.Create(ID, False, 6);
1478 Anim.Blending := False;
1479 g_GFX_OnceAnim(X-64, Y-64, Anim);
1480 Anim.Free();
1481 end;
1482 if Ang = 1 then
1483 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X, Y);
1484 end;
1486 NET_GFX_BFGHIT:
1487 begin
1488 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1489 begin
1490 Anim := TAnimation.Create(ID, False, 4);
1491 g_GFX_OnceAnim(X-32, Y-32, Anim);
1492 Anim.Free();
1493 end;
1494 end;
1496 NET_GFX_FIRE:
1497 begin
1498 if g_Frames_Get(ID, 'FRAMES_FIRE') then
1499 begin
1500 Anim := TAnimation.Create(ID, False, 4);
1501 g_GFX_OnceAnim(X, Y, Anim);
1502 Anim.Free();
1503 end;
1504 if Ang = 1 then
1505 g_Sound_PlayExAt('SOUND_FIRE', X, Y);
1506 end;
1508 NET_GFX_RESPAWN:
1509 begin
1510 if g_Frames_Get(ID, 'FRAMES_ITEM_RESPAWN') then
1511 begin
1512 Anim := TAnimation.Create(ID, False, 4);
1513 g_GFX_OnceAnim(X, Y, Anim);
1514 Anim.Free();
1515 end;
1516 if Ang = 1 then
1517 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
1518 end;
1520 NET_GFX_SHELL1:
1521 g_Player_CreateShell(X, Y, 0, -2, SHELL_BULLET);
1523 NET_GFX_SHELL2:
1524 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1526 NET_GFX_SHELL3:
1527 begin
1528 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1529 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1530 end;
1531 end;
1532 end;
1534 procedure MC_RECV_Sound(var M: TMsg);
1535 var
1536 Name: string;
1537 X, Y: Integer;
1538 Pos: Boolean;
1539 begin
1540 Name := M.ReadString();
1541 Pos := M.ReadByte() <> 0;
1542 if Pos then
1543 begin
1544 X := M.ReadLongInt();
1545 Y := M.ReadLongInt();
1546 g_Sound_PlayExAt(Name, X, Y);
1547 end
1548 else
1549 g_Sound_PlayEx(Name);
1550 end;
1552 procedure MC_RECV_CreateShot(var M: TMsg);
1553 var
1554 I, X, Y, XV, YV: Integer;
1555 Timeout: LongWord;
1556 Target, Spawner: Word;
1557 ShType: Byte;
1558 begin
1559 I := M.ReadLongInt();
1560 ShType := M.ReadByte();
1561 Target := M.ReadWord();
1562 Spawner := M.ReadWord();
1563 Timeout := M.ReadLongWord();
1564 X := M.ReadLongInt();
1565 Y := M.ReadLongInt();
1566 XV := M.ReadLongInt();
1567 YV := M.ReadLongInt();
1569 I := g_Weapon_CreateShot(I, ShType, Spawner, Target, X, Y, XV, YV);
1570 if (Shots <> nil) and (I <= High(Shots)) then
1571 begin
1572 Shots[I].Timeout := Timeout;
1573 //Shots[I].Target := Target; // TODO: find a use for Target later
1574 end;
1575 end;
1577 procedure MC_RECV_UpdateShot(var M: TMsg);
1578 var
1579 I, TX, TY, TXV, TYV: Integer;
1580 begin
1581 I := M.ReadLongInt();
1582 TX := M.ReadLongInt();
1583 TY := M.ReadLongInt();
1584 TXV := M.ReadLongInt();
1585 TYV := M.ReadLongInt();
1587 if (Shots <> nil) and (I <= High(Shots)) then
1588 with (Shots[i]) do
1589 begin
1590 Obj.X := TX;
1591 Obj.Y := TY;
1592 Obj.Vel.X := TXV;
1593 Obj.Vel.Y := TYV;
1594 end;
1595 end;
1597 procedure MC_RECV_DeleteShot(var M: TMsg);
1598 var
1599 I, X, Y: Integer;
1600 L: Boolean;
1601 begin
1602 if not gGameOn then Exit;
1603 I := M.ReadLongInt();
1604 L := (M.ReadByte() <> 0);
1605 X := M.ReadLongInt();
1606 Y := M.ReadLongInt();
1608 g_Weapon_DestroyShot(I, X, Y, L);
1609 end;
1611 procedure MC_RECV_GameStats(var M: TMsg);
1612 begin
1613 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1614 begin
1615 gTeamStat[TEAM_RED].Goals := M.ReadSmallInt();
1616 gTeamStat[TEAM_BLUE].Goals := M.ReadSmallInt();
1617 end
1618 else
1619 if gGameSettings.GameMode = GM_COOP then
1620 begin
1621 gCoopMonstersKilled := M.ReadWord();
1622 gCoopSecretsFound := M.ReadWord();
1623 end;
1624 end;
1626 procedure MC_RECV_CoopStats(var M: TMsg);
1627 begin
1628 gTotalMonsters := M.ReadLongInt();
1629 gSecretsCount := M.ReadLongInt();
1630 gCoopTotalMonstersKilled := M.ReadWord();
1631 gCoopTotalSecretsFound := M.ReadWord();
1632 gCoopTotalMonsters := M.ReadWord();
1633 gCoopTotalSecrets := M.ReadWord();
1634 end;
1636 procedure MC_RECV_GameEvent(var M: TMsg);
1637 var
1638 EvType: Byte;
1639 EvNum: Integer;
1640 EvStr: string;
1641 EvTime: LongWord;
1642 BHash: Boolean;
1643 EvHash: TMD5Digest;
1644 pl: TPlayer;
1645 i1, i2: TStrings_Locale;
1646 pln: String;
1647 cnt: Byte;
1648 begin
1649 FillChar(EvHash, Sizeof(EvHash), 0);
1650 EvType := M.ReadByte();
1651 EvNum := M.ReadLongInt();
1652 EvStr := M.ReadString();
1653 gLastMap := M.ReadByte() <> 0;
1654 if gLastMap and (gGameSettings.GameMode = GM_COOP) then gStatsOff := True;
1655 gStatsPressed := True;
1656 EvTime := M.ReadLongWord();
1657 BHash := M.ReadByte() <> 0;
1658 if BHash then
1659 EvHash := M.ReadMD5();
1661 gTime := EvTime;
1663 case EvType of
1664 NET_EV_MAPSTART:
1665 begin
1666 gGameOn := False;
1667 g_Game_ClearLoading();
1668 g_Game_StopAllSounds(True);
1670 gSwitchGameMode := Byte(EvNum);
1671 gGameSettings.GameMode := gSwitchGameMode;
1673 gWADHash := EvHash;
1674 if not g_Game_StartMap(EvStr, True) then
1675 begin
1676 if not isWadPath(EvStr) then
1677 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + EvStr]))
1678 else
1679 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [EvStr]));
1680 Exit;
1681 end;
1683 MC_SEND_FullStateRequest;
1684 end;
1686 NET_EV_MAPEND:
1687 begin
1688 gMissionFailed := EvNum <> 0;
1689 gExit := EXIT_ENDLEVELCUSTOM;
1690 end;
1692 NET_EV_RCON:
1693 begin
1694 case EvNum of
1695 NET_RCON_NOAUTH:
1696 g_Console_Add(_lc[I_NET_RCON_NOAUTH], True);
1697 NET_RCON_PWGOOD:
1698 g_Console_Add(_lc[I_NET_RCON_PWD_VALID], True);
1699 NET_RCON_PWBAD:
1700 g_Console_Add(_lc[I_NET_RCON_PWD_INVALID], True);
1701 end;
1702 end;
1704 NET_EV_CHANGE_TEAM:
1705 begin
1706 if EvNum = TEAM_RED then
1707 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True);
1708 if EvNum = TEAM_BLUE then
1709 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True);
1710 end;
1712 NET_EV_PLAYER_KICK:
1713 g_Console_Add(Format(_lc[I_PLAYER_KICK], [EvStr]), True);
1715 NET_EV_PLAYER_BAN:
1716 g_Console_Add(Format(_lc[I_PLAYER_BAN], [EvStr]), True);
1718 NET_EV_LMS_WARMUP:
1719 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [EvNum]), True);
1721 NET_EV_LMS_SURVIVOR:
1722 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True);
1724 NET_EV_BIGTEXT:
1725 g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum));
1727 NET_EV_SCORE:
1728 begin
1729 pl := g_Player_Get(EvNum and $FFFF);
1730 if pl = nil then
1731 pln := '?'
1732 else
1733 pln := pl.Name;
1734 cnt := (EvNum shr 16) and $FF;
1735 if Pos('w', EvStr) = 0 then
1736 begin
1737 // Default score
1738 if Pos('t', EvStr) = 0 then
1739 begin
1740 // Player +/- score
1741 if Pos('-', EvStr) = 0 then
1742 begin
1743 if Pos('e', EvStr) = 0 then
1744 i1 := I_PLAYER_SCORE_ADD_OWN
1745 else
1746 i1 := I_PLAYER_SCORE_ADD_ENEMY;
1747 end else
1748 begin
1749 if Pos('e', EvStr) = 0 then
1750 i1 := I_PLAYER_SCORE_SUB_OWN
1751 else
1752 i1 := I_PLAYER_SCORE_SUB_ENEMY;
1753 end;
1754 // Which team
1755 if Pos('r', EvStr) > 0 then
1756 i2 := I_PLAYER_SCORE_TO_RED
1757 else
1758 i2 := I_PLAYER_SCORE_TO_BLUE;
1759 g_Console_Add(Format(_lc[i1], [pln, cnt, _lc[i2]]), True);
1760 end else
1761 begin
1762 // Team +/- score
1763 if Pos('-', EvStr) = 0 then
1764 i1 := I_PLAYER_SCORE_ADD_TEAM
1765 else
1766 i1 := I_PLAYER_SCORE_SUB_TEAM;
1767 // Which team
1768 if Pos('r', EvStr) > 0 then
1769 i2 := I_PLAYER_SCORE_RED
1770 else
1771 i2 := I_PLAYER_SCORE_BLUE;
1772 g_Console_Add(Format(_lc[i1], [_lc[i2], cnt]), True);
1773 end;
1774 end else
1775 begin
1776 // Game Win
1777 if Pos('e', EvStr) = 0 then
1778 i1 := I_PLAYER_SCORE_WIN_OWN
1779 else
1780 i1 := I_PLAYER_SCORE_WIN_ENEMY;
1781 // Which team
1782 if Pos('r', EvStr) > 0 then
1783 i2 := I_PLAYER_SCORE_TO_RED
1784 else
1785 i2 := I_PLAYER_SCORE_TO_BLUE;
1786 g_Console_Add(Format(_lc[i1], [pln, _lc[i2]]), True);
1787 end;
1788 end;
1790 NET_EV_SCORE_MSG:
1791 begin
1792 if EvNum = TEAM_RED then
1793 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1794 if EvNum = TEAM_BLUE then
1795 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1796 if EvNum = -TEAM_RED then
1797 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1798 if EvNum = -TEAM_BLUE then
1799 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1800 end;
1802 NET_EV_LMS_START:
1803 begin
1804 g_Player_RemoveAllCorpses;
1805 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
1806 end;
1808 NET_EV_LMS_WIN:
1809 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(EvStr)]), 144);
1811 NET_EV_TLMS_WIN:
1812 begin
1813 if EvNum = TEAM_RED then
1814 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
1815 if EvNum = TEAM_BLUE then
1816 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
1817 end;
1819 NET_EV_LMS_LOSE:
1820 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
1822 NET_EV_LMS_DRAW:
1823 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
1825 NET_EV_KILLCOMBO:
1826 g_Game_Announce_KillCombo(EvNum);
1828 NET_EV_PLAYER_TOUCH:
1829 begin
1830 pl := g_Player_Get(EvNum);
1831 if pl <> nil then
1832 pl.Touch();
1833 end;
1835 NET_EV_SECRET:
1836 begin
1837 pl := g_Player_Get(EvNum);
1838 if pl <> nil then
1839 begin
1840 g_Console_Add(Format(_lc[I_PLAYER_SECRET], [pl.Name]), True);
1841 g_Sound_PlayEx('SOUND_GAME_SECRET');
1842 end;
1843 end;
1845 end;
1846 end;
1848 procedure MC_RECV_FlagEvent(var M: TMsg);
1849 var
1850 PID: Word;
1851 Pl: TPlayer;
1852 EvType: Byte;
1853 Fl, a: Byte;
1854 Quiet: Boolean;
1855 s, ts: string;
1856 begin
1857 EvType := M.ReadByte();
1858 Fl := M.ReadByte();
1860 if Fl = FLAG_NONE then Exit;
1862 Quiet := (M.ReadByte() <> 0);
1863 PID := M.ReadWord();
1865 gFlags[Fl].State := M.ReadByte();
1866 gFlags[Fl].CaptureTime := M.ReadLongWord();
1867 gFlags[Fl].Obj.X := M.ReadLongInt();
1868 gFlags[Fl].Obj.Y := M.ReadLongInt();
1869 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
1870 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
1872 Pl := g_Player_Get(PID);
1873 if (Pl = nil) and
1874 (EvType <> FLAG_STATE_NORMAL) and
1875 (EvType <> FLAG_STATE_DROPPED) and
1876 (EvType <> FLAG_STATE_RETURNED) then
1877 Exit;
1879 case EvType of
1880 FLAG_STATE_NORMAL:
1881 begin
1882 if Quiet or (Pl = nil) then Exit;
1884 if Fl = FLAG_RED then
1885 s := _lc[I_PLAYER_FLAG_RED]
1886 else
1887 s := _lc[I_PLAYER_FLAG_BLUE];
1889 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
1891 if ((Pl = gPlayer1) or (Pl = gPlayer2)
1892 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
1893 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
1894 a := 0
1895 else
1896 a := 1;
1898 if not sound_ret_flag[a].IsPlaying() then
1899 sound_ret_flag[a].Play();
1900 end;
1902 FLAG_STATE_CAPTURED:
1903 begin
1904 if (Pl <> nil) then Pl.SetFlag(Fl);
1906 if Quiet then Exit;
1908 if Fl = FLAG_RED then
1909 s := _lc[I_PLAYER_FLAG_RED]
1910 else
1911 s := _lc[I_PLAYER_FLAG_BLUE];
1913 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [Pl.Name, s]), True);
1914 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
1916 if ((Pl = gPlayer1) or (Pl = gPlayer2)
1917 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
1918 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
1919 a := 0
1920 else
1921 a := 1;
1923 if not sound_get_flag[a].IsPlaying() then
1924 sound_get_flag[a].Play();
1925 end;
1927 FLAG_STATE_DROPPED:
1928 begin
1929 if (Pl <> nil) then Pl.SetFlag(FLAG_NONE);
1931 if Quiet or (Pl = nil) then Exit;
1933 if Fl = FLAG_RED then
1934 s := _lc[I_PLAYER_FLAG_RED]
1935 else
1936 s := _lc[I_PLAYER_FLAG_BLUE];
1938 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [Pl.Name, s]), True);
1939 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
1941 if ((Pl = gPlayer1) or (Pl = gPlayer2)
1942 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
1943 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
1944 a := 0
1945 else
1946 a := 1;
1948 if not sound_lost_flag[a].IsPlaying() then
1949 sound_lost_flag[a].Play();
1950 end;
1952 FLAG_STATE_SCORED:
1953 begin
1954 g_Map_ResetFlag(FLAG_RED);
1955 g_Map_ResetFlag(FLAG_BLUE);
1956 if Quiet or (Pl = nil) then Exit;
1957 Pl.SetFlag(FLAG_NONE);
1959 if Fl = FLAG_RED then
1960 s := _lc[I_PLAYER_FLAG_RED]
1961 else
1962 s := _lc[I_PLAYER_FLAG_BLUE];
1964 ts := Format('%.4d', [gFlags[Fl].CaptureTime]);
1965 Insert('.', ts, Length(ts) + 1 - 3);
1966 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [Pl.Name, s, ts]), True);
1967 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
1969 if ((Pl = gPlayer1) or (Pl = gPlayer2)
1970 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
1971 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
1972 a := 0
1973 else
1974 a := 1;
1976 if not sound_cap_flag[a].IsPlaying() then
1977 sound_cap_flag[a].Play();
1978 end;
1980 FLAG_STATE_RETURNED:
1981 begin
1982 g_Map_ResetFlag(Fl);
1983 if Quiet then Exit;
1985 if Fl = FLAG_RED then
1986 s := _lc[I_PLAYER_FLAG_RED]
1987 else
1988 s := _lc[I_PLAYER_FLAG_BLUE];
1990 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
1992 if ((Pl = gPlayer1) or (Pl = gPlayer2)
1993 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
1994 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
1995 a := 0
1996 else
1997 a := 1;
1999 if not sound_ret_flag[a].IsPlaying() then
2000 sound_ret_flag[a].Play();
2001 end;
2002 end;
2003 end;
2005 procedure MC_RECV_GameSettings(var M: TMsg);
2006 begin
2007 gGameSettings.GameMode := M.ReadByte();
2008 gGameSettings.GoalLimit := M.ReadWord();
2009 gGameSettings.TimeLimit := M.ReadWord();
2010 gGameSettings.MaxLives := M.ReadByte();
2011 gGameSettings.Options := M.ReadLongWord();
2012 end;
2014 // PLAYER
2016 function MC_RECV_PlayerCreate(var M: TMsg): Word;
2017 var
2018 PID, DID: Word;
2019 PName, Model: string;
2020 Color: TRGB;
2021 T: Byte;
2022 Pl: TPlayer;
2023 begin
2024 PID := M.ReadWord();
2025 Pl := g_Player_Get(PID);
2027 PName := M.ReadString();
2028 Model := M.ReadString();
2029 Color.R := M.ReadByte();
2030 Color.G := M.ReadByte();
2031 Color.B := M.ReadByte();
2032 T := M.ReadByte();
2034 Result := 0;
2035 if (PID <> NetPlrUID1) and (PID <> NetPlrUID2) then
2036 begin
2037 if (Pl <> nil) then Exit;
2038 DID := g_Player_Create(Model, Color, T, False);
2039 with g_Player_Get(DID) do
2040 begin
2041 UID := PID;
2042 Name := PName;
2043 Reset(True);
2044 end;
2045 end
2046 else
2047 begin
2048 if (PID = NetPlrUID1) and (gPlayer1 <> nil) then begin
2049 gPlayer1.UID := PID;
2050 gPlayer1.Model.SetColor(Color.R, Color.G, Color.B);
2051 gPlayer1.ChangeTeam(T);
2052 end;
2053 if (PID = NetPlrUID2) and (gPlayer2 <> nil) then begin
2054 gPlayer2.UID := PID;
2055 gPlayer2.Model.SetColor(Color.R, Color.G, Color.B);
2056 gPlayer2.ChangeTeam(T);
2057 end;
2058 end;
2060 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
2061 e_WriteLog('NET: Player ' + PName + ' [' + IntToStr(PID) + '] added.', TMsgType.Notify);
2062 Result := PID;
2063 end;
2065 function MC_RECV_PlayerPos(var M: TMsg): Word;
2066 var
2067 GT: LongWord;
2068 PID: Word;
2069 kByte: Word;
2070 Pl: TPlayer;
2071 Dir: Byte;
2072 TmpX, TmpY: Integer;
2073 begin
2074 Result := 0;
2076 GT := M.ReadLongWord();
2077 if GT < gTime - NET_MAX_DIFFTIME then
2078 begin
2079 gTime := GT;
2080 Exit;
2081 end;
2082 gTime := GT;
2084 PID := M.ReadWord();
2085 Pl := g_Player_Get(PID);
2087 if Pl = nil then Exit;
2089 Result := PID;
2091 with Pl do
2092 begin
2093 FPing := M.ReadWord();
2094 FLoss := M.ReadByte();
2095 kByte := M.ReadWord();
2096 Dir := M.ReadByte();
2098 TmpX := M.ReadLongInt();
2099 TmpY := M.ReadLongInt();
2101 ReleaseKeys;
2103 if (kByte = NET_KEY_CHAT) then
2104 PressKey(KEY_CHAT, 10000)
2105 else
2106 begin
2107 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
2108 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
2109 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
2110 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
2111 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
2112 end;
2114 if ((Pl <> gPlayer1) and (Pl <> gPlayer2)) or LongBool(kByte and NET_KEY_FORCEDIR) then
2115 SetDirection(TDirection(Dir));
2117 GameVelX := M.ReadLongInt();
2118 GameVelY := M.ReadLongInt();
2119 GameAccelX := M.ReadLongInt();
2120 GameAccelY := M.ReadLongInt();
2121 SetLerp(TmpX, TmpY);
2122 if NetForcePlayerUpdate then Update();
2123 end;
2124 end;
2126 function MC_RECV_PlayerStats(var M: TMsg): Word;
2127 var
2128 PID: Word;
2129 Pl: TPlayer;
2130 I, OldFire: Integer;
2131 OldJet, Flam: Boolean;
2132 NewTeam: Byte;
2133 begin
2134 PID := M.ReadWord();
2135 Pl := g_Player_Get(PID);
2136 Result := 0;
2137 if Pl = nil then
2138 Exit;
2140 with Pl do
2141 begin
2142 alive := (M.ReadByte() <> 0);
2143 GodMode := (M.ReadByte() <> 0);
2144 Health := M.ReadLongInt();
2145 Armor := M.ReadLongInt();
2146 Air := M.ReadLongInt();
2147 JetFuel := M.ReadLongInt();
2148 Lives := M.ReadByte();
2149 NewTeam := M.ReadByte();
2151 for I := WP_FIRST to WP_LAST do
2152 FWeapon[I] := (M.ReadByte() <> 0);
2154 for I := A_BULLETS to A_HIGH do
2155 FAmmo[I] := M.ReadWord();
2157 for I := A_BULLETS to A_HIGH do
2158 FMaxAmmo[I] := M.ReadWord();
2160 for I := MR_SUIT to MR_MAX do
2161 FMegaRulez[I] := M.ReadLongWord();
2163 FRulez := [];
2164 if (M.ReadByte() <> 0) then
2165 FRulez := FRulez + [R_ITEM_BACKPACK];
2166 if (M.ReadByte() <> 0) then
2167 FRulez := FRulez + [R_KEY_RED];
2168 if (M.ReadByte() <> 0) then
2169 FRulez := FRulez + [R_KEY_GREEN];
2170 if (M.ReadByte() <> 0) then
2171 FRulez := FRulez + [R_KEY_BLUE];
2172 if (M.ReadByte() <> 0) then
2173 FRulez := FRulez + [R_BERSERK];
2175 Frags := M.ReadLongInt();
2176 Death := M.ReadLongInt();
2178 SetWeapon(M.ReadByte());
2180 FSpectator := M.ReadByte() <> 0;
2181 if FSpectator then
2182 begin
2183 if Pl = gPlayer1 then
2184 begin
2185 gLMSPID1 := UID;
2186 gPlayer1 := nil;
2187 end;
2188 if Pl = gPlayer2 then
2189 begin
2190 gLMSPID2 := UID;
2191 gPlayer2 := nil;
2192 end;
2193 end
2194 else
2195 begin
2196 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
2197 gPlayer1 := g_Player_Get(gLMSPID1);
2198 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
2199 gPlayer2 := g_Player_Get(gLMSPID2);
2200 end;
2201 FGhost := M.ReadByte() <> 0;
2202 FPhysics := M.ReadByte() <> 0;
2203 FNoRespawn := M.ReadByte() <> 0;
2204 OldJet := FJetpack;
2205 FJetpack := M.ReadByte() <> 0;
2206 OldFire := FFireTime;
2207 FFireTime := M.ReadLongInt();
2208 if (OldFire <= 0) and (FFireTime > 0) then
2209 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
2210 Flam := M.ReadByte() <> 0;
2211 if OldJet and not FJetpack then
2212 JetpackOff
2213 else if not OldJet and FJetpack then
2214 JetpackOn;
2215 if FFlaming and not Flam then
2216 FlamerOff;
2217 if Team <> NewTeam then
2218 Pl.ChangeTeam(NewTeam);
2219 end;
2221 Result := PID;
2222 end;
2224 function MC_RECV_PlayerDamage(var M: TMsg): Word;
2225 var
2226 PID: Word;
2227 Pl: TPlayer;
2228 Kind: Byte;
2229 Attacker, Value: Word;
2230 VX, VY: Integer;
2231 begin
2232 Result := 0;
2233 if not gGameOn then Exit;
2234 PID := M.ReadWord();
2235 Pl := g_Player_Get(PID);
2236 if Pl = nil then Exit;
2238 Kind := M.ReadByte();
2239 Attacker := M.ReadWord();
2240 Value := M.ReadWord();
2241 VX := M.ReadWord();
2242 VY := M.ReadWord();
2244 with Pl do
2245 Damage(Value, Attacker, VX, VY, Kind);
2247 Result := PID;
2248 end;
2250 function MC_RECV_PlayerDeath(var M: TMsg): Word;
2251 var
2252 PID: Word;
2253 Pl: TPlayer;
2254 KillType, DeathType: Byte;
2255 Attacker: Word;
2256 begin
2257 Result := 0;
2258 if not gGameOn then Exit;
2259 PID := M.ReadWord();
2260 Pl := g_Player_Get(PID);
2261 if Pl = nil then Exit;
2263 KillType := M.ReadByte();
2264 DeathType := M.ReadByte();
2265 Attacker := M.ReadWord();
2267 with Pl do
2268 begin
2269 Kill(KillType, Attacker, DeathType);
2270 SoftReset;
2271 end;
2272 end;
2274 function MC_RECV_PlayerDelete(var M: TMsg): Word;
2275 var
2276 PID: Word;
2277 Pl: TPlayer;
2278 begin
2279 PID := M.ReadWord();
2280 Pl := g_Player_Get(PID);
2281 Result := 0;
2282 if Pl = nil then Exit;
2284 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2285 e_WriteLog('NET: Player ' + Pl.Name + ' [' + IntToStr(PID) + '] removed.', TMsgType.Notify);
2287 g_Player_Remove(PID);
2289 Result := PID;
2290 end;
2292 function MC_RECV_PlayerFire(var M: TMsg): Word;
2293 var
2294 PID: Word;
2295 Weap: Byte;
2296 Pl: TPlayer;
2297 X, Y, AX, AY: Integer;
2298 SHID: Integer;
2299 begin
2300 Result := 0;
2301 if not gGameOn then Exit;
2302 PID := M.ReadWord();
2303 Pl := g_Player_Get(PID);
2304 if Pl = nil then Exit;
2306 Weap := M.ReadByte();
2307 X := M.ReadLongInt();
2308 Y := M.ReadLongInt();
2309 AX := M.ReadLongInt();
2310 AY := M.ReadLongInt();
2311 SHID := M.ReadLongInt();
2313 with Pl do
2314 if alive then NetFire(Weap, X, Y, AX, AY, SHID);
2315 end;
2317 procedure MC_RECV_PlayerSettings(var M: TMsg);
2318 var
2319 TmpName: string;
2320 TmpModel: string;
2321 TmpColor: TRGB;
2322 TmpTeam: Byte;
2323 Pl: TPlayer;
2324 PID: Word;
2325 begin
2326 PID := M.ReadWord();
2327 Pl := g_Player_Get(PID);
2328 if Pl = nil then Exit;
2330 TmpName := M.ReadString();
2331 TmpModel := M.ReadString();
2332 TmpColor.R := M.ReadByte();
2333 TmpColor.G := M.ReadByte();
2334 TmpColor.B := M.ReadByte();
2335 TmpTeam := M.ReadByte();
2337 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
2338 begin
2339 Pl.ChangeTeam(TmpTeam);
2340 if gPlayer1 = Pl then
2341 gPlayer1Settings.Team := TmpTeam;
2342 if gPlayer2 = Pl then
2343 gPlayer2Settings.Team := TmpTeam;
2344 end else
2345 Pl.SetColor(TmpColor);
2347 if Pl.Name <> TmpName then
2348 begin
2349 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
2350 Pl.Name := TmpName;
2351 end;
2353 if TmpModel <> Pl.Model.Name then
2354 Pl.SetModel(TmpModel);
2355 end;
2357 // ITEM
2359 procedure MC_RECV_ItemSpawn(var M: TMsg);
2360 var
2361 ID: Word;
2362 AID: DWord;
2363 X, Y, VX, VY: Integer;
2364 T: Byte;
2365 Quiet, Fall{, Resp}: Boolean;
2366 Anim: TAnimation;
2367 it: PItem;
2368 begin
2369 if not gGameOn then Exit;
2370 ID := M.ReadWord();
2371 Quiet := M.ReadByte() <> 0;
2372 T := M.ReadByte();
2373 Fall := M.ReadByte() <> 0;
2374 {Resp :=} M.ReadByte();
2375 X := M.ReadLongInt();
2376 Y := M.ReadLongInt();
2377 VX := M.ReadLongInt();
2378 VY := M.ReadLongInt();
2380 g_Items_Create(X, Y, T and $7F, Fall, False, False, ID);
2381 if ((T and $80) <> 0) then g_Items_SetDrop(ID);
2383 it := g_Items_ByIdx(ID);
2384 it.Obj.Vel.X := VX;
2385 it.Obj.Vel.Y := VY;
2387 if not Quiet then
2388 begin
2389 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
2390 if g_Frames_Get(AID, 'FRAMES_ITEM_RESPAWN') then
2391 begin
2392 Anim := TAnimation.Create(AID, False, 4);
2393 g_GFX_OnceAnim(X+(it.Obj.Rect.Width div 2)-16, Y+(it.Obj.Rect.Height div 2)-16, Anim);
2394 Anim.Free();
2395 end;
2396 end;
2397 end;
2399 procedure MC_RECV_ItemDestroy(var M: TMsg);
2400 var
2401 ID: Word;
2402 Quiet: Boolean;
2403 begin
2404 if not gGameOn then Exit;
2405 ID := M.ReadWord();
2406 Quiet := M.ReadByte() <> 0;
2408 if not g_Items_ValidId(ID) then exit;
2410 if not Quiet then g_Items_EmitPickupSound(ID);
2412 g_Items_Remove(ID);
2413 end;
2415 // PANEL
2417 procedure MC_RECV_PanelTexture(var M: TMsg);
2418 var
2419 TP: TPanel;
2420 PGUID: Integer;
2421 Tex, Fr: Integer;
2422 Loop, Cnt: Byte;
2423 begin
2424 if not gGameOn then Exit;
2426 PGUID := Integer(M.ReadLongWord());
2427 Tex := M.ReadLongInt();
2428 Fr := M.ReadLongInt();
2429 Cnt := M.ReadByte();
2430 Loop := M.ReadByte();
2432 TP := g_Map_PanelByGUID(PGUID);
2433 if (TP <> nil) then
2434 begin
2435 // switch texture
2436 TP.SetTexture(Tex, Loop);
2437 TP.SetFrame(Fr, Cnt);
2438 end;
2439 end;
2441 procedure MC_RECV_PanelState(var M: TMsg);
2442 var
2443 PGUID: Integer;
2444 E: Boolean;
2445 Lift: Byte;
2446 X, Y, W, H: Integer;
2447 TP: TPanel;
2448 speedX, speedY, startX, startY, endX, endY: Integer;
2449 sizeSpX, sizeSpY, sizeEX, sizeEY: Integer;
2450 mpflags: Byte;
2451 begin
2452 if not gGameOn then Exit;
2454 PGUID := Integer(M.ReadLongWord());
2455 E := (M.ReadByte() <> 0);
2456 Lift := M.ReadByte();
2457 X := M.ReadLongInt();
2458 Y := M.ReadLongInt();
2459 W := M.ReadWord();
2460 H := M.ReadWord();
2461 // mplats
2462 speedX := M.ReadLongInt();
2463 speedY := M.ReadLongInt();
2464 startX := M.ReadLongInt();
2465 startY := M.ReadLongInt();
2466 endX := M.ReadLongInt();
2467 endY := M.ReadLongInt();
2468 sizeSpX := M.ReadLongInt();
2469 sizeSpY := M.ReadLongInt();
2470 sizeEX := M.ReadLongInt();
2471 sizeEY := M.ReadLongInt();
2472 mpflags := M.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2474 TP := g_Map_PanelByGUID(PGUID);
2475 if (TP = nil) then exit;
2477 // update lifts state
2478 if TP.isGLift then g_Map_SetLiftGUID(PGUID, Lift);
2480 // update enabled/disabled state for all panels
2481 if E then g_Map_EnableWallGUID(PGUID) else g_Map_DisableWallGUID(PGUID);
2483 // update panel position, as it can be moved (mplat)
2484 TP.X := X;
2485 TP.Y := Y;
2486 TP.Width := W;
2487 TP.Height := H;
2488 // update mplat state
2489 TP.movingSpeedX := speedX;
2490 TP.movingSpeedY := speedY;
2491 TP.movingStartX := startX;
2492 TP.movingStartY := startY;
2493 TP.movingEndX := endX;
2494 TP.movingEndY := endY;
2495 TP.sizeSpeedX := sizeSpX;
2496 TP.sizeSpeedY := sizeSpY;
2497 TP.sizeEndX := sizeEX;
2498 TP.sizeEndY := sizeEY;
2499 TP.movingActive := ((mpflags and 1) <> 0);
2500 TP.moveOnce := ((mpflags and 2) <> 0);
2501 // notify panel of it's position/size change, so it can fix other internal structures
2502 TP.positionChanged();
2503 end;
2505 // TRIGGERS
2507 procedure MC_RECV_TriggerSound(var M: TMsg);
2508 var
2509 SPlaying: Boolean;
2510 SPos, SID: LongWord;
2511 SCount: LongInt;
2512 I: Integer;
2513 begin
2514 if not gGameOn then Exit;
2515 if gTriggers = nil then Exit;
2517 SID := M.ReadLongWord();
2518 SPlaying := M.ReadByte() <> 0;
2519 SPos := M.ReadLongWord();
2520 SCount := M.ReadLongInt();
2522 for I := Low(gTriggers) to High(gTriggers) do
2523 if gTriggers[I].TriggerType = TRIGGER_SOUND then
2524 if gTriggers[I].ClientID = SID then
2525 with gTriggers[I] do
2526 begin
2527 if Sound <> nil then
2528 begin
2529 if SPlaying then
2530 begin
2531 if tgcLocal then
2532 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), tgcVolume/255.0)
2533 else
2534 Sound.PlayPanVolume((tgcPan-127.0)/128.0, tgcVolume/255.0);
2535 Sound.SetPosition(SPos);
2536 end
2537 else
2538 if Sound.IsPlaying then Sound.Stop;
2539 end;
2541 SoundPlayCount := SCount;
2542 end;
2543 end;
2545 procedure MC_RECV_TriggerMusic(var M: TMsg);
2546 var
2547 MName: string;
2548 MPlaying: Boolean;
2549 MPos: LongWord;
2550 MPaused: Boolean;
2551 begin
2552 if not gGameOn then Exit;
2554 MName := M.ReadString();
2555 MPlaying := M.ReadByte() <> 0;
2556 MPos := M.ReadLongWord();
2557 MPaused := M.ReadByte() <> 0;
2559 if MPlaying then
2560 begin
2561 gMusic.SetByName(MName);
2562 gMusic.Play(True);
2563 gMusic.SetPosition(MPos);
2564 gMusic.SpecPause := MPaused;
2565 end
2566 else
2567 if gMusic.IsPlaying then gMusic.Stop;
2568 end;
2570 // MONSTERS
2572 procedure MC_RECV_MonsterSpawn(var M: TMsg);
2573 var
2574 ID: Word;
2575 MType, MState, MDir, MAnim, MBehav: Byte;
2576 X, Y, VX, VY, MTargTime, MHealth, MAmmo, MSleep: Integer;
2577 MTarg: Word;
2578 Mon: TMonster;
2579 begin
2580 ID := M.ReadWord();
2581 Mon := g_Monsters_ByUID(ID);
2582 if Mon <> nil then
2583 Exit;
2585 MType := M.ReadByte();
2586 MState := M.ReadByte();
2587 MAnim := M.ReadByte();
2588 MTarg := M.ReadWord();
2589 MTargTime := M.ReadLongInt();
2590 MBehav := M.ReadByte();
2591 MSleep := M.ReadLongInt();
2592 MHealth := M.ReadLongInt();
2593 MAmmo := M.ReadLongInt();
2595 X := M.ReadLongInt();
2596 Y := M.ReadLongInt();
2597 VX := M.ReadLongInt();
2598 VY := M.ReadLongInt();
2599 MDir := M.ReadByte();
2601 g_Monsters_Create(MType, X, Y, TDirection(MDir), False, ID);
2602 Mon := g_Monsters_ByUID(ID);
2603 if Mon = nil then
2604 Exit;
2606 with Mon do
2607 begin
2609 MonsterAnim := MAnim;
2610 MonsterTargetUID := MTarg;
2611 MonsterTargetTime := MTargTime;
2612 MonsterBehaviour := MBehav;
2613 MonsterSleep := MSleep;
2614 MonsterAmmo := MAmmo;
2615 SetHealth(MHealth);
2617 SetState(MState);
2619 setPosition(X, Y); // this will call positionChanged();
2620 GameVelX := VX;
2621 GameVelY := VY;
2622 end;
2623 end;
2625 procedure MC_RECV_MonsterPos(var M: TMsg);
2626 var
2627 Mon: TMonster;
2628 ID: Word;
2629 X, Y: Integer;
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 X := M.ReadLongInt();
2639 Y := M.ReadLongInt();
2640 Mon.setPosition(X, Y); // this will call `positionChanged()`
2641 GameVelX := M.ReadLongInt();
2642 GameVelY := M.ReadLongInt();
2643 GameDirection := TDirection(M.ReadByte());
2644 end;
2645 end;
2647 procedure MC_RECV_MonsterState(var M: TMsg);
2648 var
2649 ID, OldFire: 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 OldFire := FFireTime;
2671 FFireTime := M.ReadLongInt();
2672 if (OldFire <= 0) and (FFireTime > 0) then
2673 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
2674 RevertAnim(AnimRevert);
2676 if MonsterState <> MState then
2677 begin
2678 if (MState = MONSTATE_GO) and (MonsterState = MONSTATE_SLEEP) then WakeUpSound();
2679 if (MState = MONSTATE_DIE) then DieSound();
2680 if (MState = MONSTATE_PAIN) then MakeBloodSimple(Min(200, MonsterPain));
2681 if (MState = MONSTATE_ATTACK) then kick(nil);
2682 if (MState = MONSTATE_DEAD) then SetDeadAnim();
2684 SetState(MState, MFAnm);
2685 end;
2686 end;
2687 end;
2689 procedure MC_RECV_MonsterShot(var M: TMsg);
2690 var
2691 ID: Integer;
2692 Mon: TMonster;
2693 X, Y, VX, VY: Integer;
2694 begin
2695 ID := M.ReadWord();
2697 Mon := g_Monsters_ByUID(ID);
2698 if Mon = nil then Exit;
2700 X := M.ReadLongInt();
2701 Y := M.ReadLongInt();
2702 VX := M.ReadLongInt();
2703 VY := M.ReadLongInt();
2705 Mon.ClientAttack(X, Y, VX, VY);
2706 end;
2708 procedure MC_RECV_MonsterDelete(var M: TMsg);
2709 var
2710 ID: Integer;
2711 Mon: TMonster;
2712 begin
2713 ID := M.ReadWord();
2714 Mon := g_Monsters_ByUID(ID);
2715 if Mon = nil then Exit;
2716 Mon.SetState(5);
2717 Mon.MonsterRemoved := True;
2718 end;
2720 procedure MC_RECV_TimeSync(var M: TMsg);
2721 var
2722 Time: LongWord;
2723 begin
2724 Time := M.ReadLongWord();
2726 if gState = STATE_INTERCUSTOM then
2727 gServInterTime := Min(Time, 255);
2728 end;
2730 procedure MC_RECV_VoteEvent(var M: TMsg);
2731 var
2732 EvID: Byte;
2733 Str1, Str2: string;
2734 Int1, Int2: SmallInt;
2735 begin
2736 EvID := M.ReadByte();
2737 Int1 := M.ReadSmallInt();
2738 Int2 := M.ReadSmallInt();
2739 Str1 := M.ReadString();
2740 Str2 := M.ReadString();
2742 case EvID of
2743 NET_VE_STARTED:
2744 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True);
2745 NET_VE_PASSED:
2746 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True);
2747 NET_VE_FAILED:
2748 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
2749 NET_VE_VOTE:
2750 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True);
2751 NET_VE_INPROGRESS:
2752 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True);
2753 end;
2754 end;
2756 // CLIENT SEND
2758 procedure MC_SEND_Info(Password: string);
2759 begin
2760 NetOut.Clear();
2762 NetOut.Write(Byte(NET_MSG_INFO));
2763 NetOut.Write(GAME_VERSION);
2764 NetOut.Write(Password);
2765 NetOut.Write(gPlayer1Settings.Name);
2766 NetOut.Write(gPlayer1Settings.Model);
2767 NetOut.Write(gPlayer1Settings.Color.R);
2768 NetOut.Write(gPlayer1Settings.Color.G);
2769 NetOut.Write(gPlayer1Settings.Color.B);
2770 NetOut.Write(gPlayer1Settings.Team);
2772 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2773 end;
2775 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
2776 begin
2777 NetOut.Write(Byte(NET_MSG_CHAT));
2778 NetOut.Write(Txt);
2779 NetOut.Write(Mode);
2781 g_Net_Client_Send(True, NET_CHAN_CHAT);
2782 end;
2784 function isKeyPressed (key1: Word; key2: Word): Boolean;
2785 begin
2786 if (key1 <> 0) and e_KeyPressed(key1) then begin result := true; exit; end;
2787 if (key2 <> 0) and e_KeyPressed(key2) then begin result := true; exit; end;
2788 result := false;
2789 end;
2791 procedure MC_SEND_PlayerPos();
2792 var
2793 kByte: Word;
2794 Predict: Boolean;
2795 strafeDir: Byte;
2796 WeaponSelect: Word = 0;
2797 I: Integer;
2798 begin
2799 if not gGameOn then Exit;
2800 if gPlayers = nil then Exit;
2801 if gPlayer1 = nil then Exit;
2803 kByte := 0;
2804 Predict := NetPredictSelf; // and (not NetGotKeys);
2806 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2807 begin
2808 strafeDir := P1MoveButton shr 4;
2809 P1MoveButton := P1MoveButton and $0F;
2810 with gGameControls.P1Control do
2811 begin
2812 if isKeyPressed(KeyLeft, KeyLeft2) and (not isKeyPressed(KeyRight, KeyRight2)) then P1MoveButton := 1
2813 else if (not isKeyPressed(KeyLeft, KeyLeft2)) and isKeyPressed(KeyRight, KeyRight2) then P1MoveButton := 2
2814 else if (not isKeyPressed(KeyLeft, KeyLeft2)) and (not isKeyPressed(KeyRight, KeyRight2)) then P1MoveButton := 0;
2816 // strafing
2817 if isKeyPressed(KeyStrafe, KeyStrafe2) then
2818 begin
2819 // new strafe mechanics
2820 if (strafeDir = 0) then strafeDir := P1MoveButton; // start strafing
2821 // now set direction according to strafe (reversed)
2822 if (strafeDir = 2) then gPlayer1.SetDirection(TDirection.D_LEFT)
2823 else if (strafeDir = 1) then gPlayer1.SetDirection(TDirection.D_RIGHT);
2824 end
2825 else
2826 begin
2827 if (P1MoveButton = 2) and isKeyPressed(KeyLeft, KeyLeft2) then gPlayer1.SetDirection(TDirection.D_LEFT)
2828 else if (P1MoveButton = 1) and isKeyPressed(KeyRight, KeyRight2) then gPlayer1.SetDirection(TDirection.D_RIGHT)
2829 else if P1MoveButton <> 0 then gPlayer1.SetDirection(TDirection(P1MoveButton-1));
2830 end;
2832 gPlayer1.ReleaseKeys;
2833 if P1MoveButton = 1 then
2834 begin
2835 kByte := kByte or NET_KEY_LEFT;
2836 if Predict then gPlayer1.PressKey(KEY_LEFT, 10000);
2837 end;
2838 if P1MoveButton = 2 then
2839 begin
2840 kByte := kByte or NET_KEY_RIGHT;
2841 if Predict then gPlayer1.PressKey(KEY_RIGHT, 10000);
2842 end;
2843 if isKeyPressed(KeyUp, KeyUp2) then
2844 begin
2845 kByte := kByte or NET_KEY_UP;
2846 gPlayer1.PressKey(KEY_UP, 10000);
2847 end;
2848 if isKeyPressed(KeyDown, KeyDown2) then
2849 begin
2850 kByte := kByte or NET_KEY_DOWN;
2851 gPlayer1.PressKey(KEY_DOWN, 10000);
2852 end;
2853 if isKeyPressed(KeyJump, KeyJump2) then
2854 begin
2855 kByte := kByte or NET_KEY_JUMP;
2856 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2857 end;
2858 if isKeyPressed(KeyFire, KeyFire2) then kByte := kByte or NET_KEY_FIRE;
2859 if isKeyPressed(KeyOpen, KeyOpen2) then kByte := kByte or NET_KEY_OPEN;
2860 if isKeyPressed(KeyNextWeapon, KeyNextWeapon2) then kByte := kByte or NET_KEY_NW;
2861 if isKeyPressed(KeyPrevWeapon, KeyPrevWeapon2) then kByte := kByte or NET_KEY_PW;
2862 for I := 0 to High(KeyWeapon) do
2863 if isKeyPressed(KeyWeapon[I], KeyWeapon2[I]) then
2864 WeaponSelect := WeaponSelect or Word(1 shl I);
2865 end;
2866 // fix movebutton state
2867 P1MoveButton := P1MoveButton or (strafeDir shl 4);
2868 end
2869 else
2870 kByte := NET_KEY_CHAT;
2872 NetOut.Write(Byte(NET_MSG_PLRPOS));
2873 NetOut.Write(gTime);
2874 NetOut.Write(kByte);
2875 NetOut.Write(Byte(gPlayer1.Direction));
2876 NetOut.Write(WeaponSelect);
2877 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2878 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS);
2880 //kBytePrev := kByte;
2881 //kDirPrev := gPlayer1.Direction;
2882 end;
2884 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
2885 begin
2886 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
2887 NetOut.Write(Byte(Start));
2888 NetOut.Write(Command);
2889 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2890 end;
2892 procedure MC_SEND_PlayerSettings();
2893 begin
2894 NetOut.Write(Byte(NET_MSG_PLRSET));
2895 NetOut.Write(gPlayer1Settings.Name);
2896 NetOut.Write(gPlayer1Settings.Model);
2897 NetOut.Write(gPlayer1Settings.Color.R);
2898 NetOut.Write(gPlayer1Settings.Color.G);
2899 NetOut.Write(gPlayer1Settings.Color.B);
2900 NetOut.Write(gPlayer1Settings.Team);
2902 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2903 end;
2905 procedure MC_SEND_FullStateRequest();
2906 begin
2907 NetOut.Write(Byte(NET_MSG_REQFST));
2909 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2910 end;
2912 procedure MC_SEND_CheatRequest(Kind: Byte);
2913 begin
2914 NetOut.Write(Byte(NET_MSG_CHEAT));
2915 NetOut.Write(Kind);
2917 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2918 end;
2919 procedure MC_SEND_RCONPassword(Password: string);
2920 begin
2921 NetOut.Write(Byte(NET_MSG_RCON_AUTH));
2922 NetOut.Write(Password);
2924 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2925 end;
2926 procedure MC_SEND_RCONCommand(Cmd: string);
2927 begin
2928 NetOut.Write(Byte(NET_MSG_RCON_CMD));
2929 NetOut.Write(Cmd);
2931 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2932 end;
2934 // i have no idea why all this stuff is in here
2936 function ReadFile(const FileName: TFileName): AByte;
2937 var
2938 FileStream : TStream;
2939 fname: string;
2940 begin
2941 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName]), TMsgType.Notify);
2942 fname := findDiskWad(FileName);
2943 if length(fname) = 0 then
2944 begin
2945 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName]), TMsgType.Fatal);
2946 SetLength(Result, 0);
2947 exit;
2948 end;
2949 e_WriteLog(Format('NETWORK: found file "%s"', [fname]), TMsgType.Notify);
2950 Result := nil;
2951 FileStream := openDiskFileRO(fname);
2952 try
2953 if FileStream.Size > 0 then
2954 begin
2955 SetLength(Result, FileStream.Size);
2956 FileStream.Read(Result[0], FileStream.Size);
2957 end;
2958 finally
2959 FileStream.Free;
2960 end;
2961 end;
2963 function CreateMapDataMsg(const FileName: TFileName; ResList: TStringList): TMapDataMsg;
2964 var
2965 i: Integer;
2966 begin
2967 Result.MsgId := NET_MSG_MAP_RESPONSE;
2968 Result.FileData := ReadFile(FileName);
2969 Result.FileSize := Length(Result.FileData);
2971 SetLength(Result.ExternalResources, ResList.Count);
2972 for i:=0 to ResList.Count-1 do
2973 begin
2974 Result.ExternalResources[i].Name := ResList.Strings[i];
2975 Result.ExternalResources[i].md5 := MD5File(GameDir+'/wads/'+ResList.Strings[i]);
2976 end;
2977 end;
2979 procedure ResDataMsgToBytes(var bytes: AByte; const ResData: TResDataMsg);
2980 var
2981 ResultStream: TMemoryStream;
2982 begin
2983 ResultStream := TMemoryStream.Create;
2985 ResultStream.WriteBuffer(ResData.MsgId, SizeOf(ResData.MsgId)); //msgId
2986 ResultStream.WriteBuffer(ResData.FileSize, SizeOf(ResData.FileSize)); //file size
2987 ResultStream.WriteBuffer(ResData.FileData[0], ResData.FileSize); //file data
2989 SetLength(bytes, ResultStream.Size);
2990 ResultStream.Seek(0, soFromBeginning);
2991 ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
2993 ResultStream.Free;
2994 end;
2996 function ResDataFromMsgStream(msgStream: TMemoryStream):TResDataMsg;
2997 begin
2998 msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
2999 msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize));
3000 SetLength(Result.FileData, Result.FileSize);
3001 msgStream.ReadBuffer(Result.FileData[0], Result.FileSize);
3002 end;
3004 procedure MapDataMsgToBytes(var bytes: AByte; const MapDataMsg: TMapDataMsg);
3005 var
3006 ResultStream: TMemoryStream;
3007 resCount: Integer;
3008 begin
3009 resCount := Length(MapDataMsg.ExternalResources);
3011 ResultStream := TMemoryStream.Create;
3013 ResultStream.WriteBuffer(MapDataMsg.MsgId, SizeOf(MapDataMsg.MsgId)); //msgId
3014 ResultStream.WriteBuffer(MapDataMsg.FileSize, SizeOf(MapDataMsg.FileSize)); //file size
3015 ResultStream.WriteBuffer(MapDataMsg.FileData[0], MapDataMsg.FileSize); //file data
3017 ResultStream.WriteBuffer(resCount, SizeOf(resCount)); //res count
3018 ResultStream.WriteBuffer(MapDataMsg.ExternalResources[0], resCount*SizeOf(TExternalResourceInfo)); //res data
3020 SetLength(bytes, ResultStream.Size);
3021 ResultStream.Seek(0, soFromBeginning);
3022 ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
3024 ResultStream.Free;
3025 end;
3027 function MapDataFromMsgStream(msgStream: TMemoryStream):TMapDataMsg;
3028 var
3029 resCount: Integer;
3030 begin
3031 msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
3032 msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize)); //file size
3034 SetLength(Result.FileData, Result.FileSize);
3035 msgStream.ReadBuffer(Result.FileData[0], Result.FileSize); //file data
3037 msgStream.ReadBuffer(resCount, SizeOf(resCount)); //res count
3038 SetLength(Result.ExternalResources, resCount);
3040 msgStream.ReadBuffer(Result.ExternalResources[0], resCount * SizeOf(TExternalResourceInfo)); //res data
3041 end;
3043 function IsValidFileName(const S: String): Boolean;
3044 const
3045 Forbidden: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
3046 var
3047 I: Integer;
3048 begin
3049 Result := S <> '';
3050 for I := 1 to Length(S) do
3051 Result := Result and (not(S[I] in Forbidden));
3052 end;
3054 function IsValidFilePath(const S: String): Boolean;
3055 var
3056 I: Integer;
3057 begin
3058 Result := False;
3059 if not IsValidFileName(S) then exit;
3060 if FileExists(S) then exit;
3061 I := LastDelimiter('\/', S);
3062 if (I > 0) then
3063 if (not DirectoryExists(Copy(S, 1, I-1))) then
3064 exit;
3065 Result := True;
3066 end;
3068 procedure MC_SEND_MapRequest();
3069 begin
3070 NetOut.Write(Byte(NET_MSG_MAP_REQUEST));
3071 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3072 end;
3074 procedure MC_SEND_ResRequest(const resName: AnsiString);
3075 begin
3076 NetOut.Write(Byte(NET_MSG_RES_REQUEST));
3077 NetOut.Write(resName);
3078 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3079 end;
3081 procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
3082 var
3083 payload: AByte;
3084 peer: pENetPeer;
3085 mapDataMsg: TMapDataMsg;
3086 begin
3087 e_WriteLog('NET: Received map request from ' +
3088 DecodeIPV4(C^.Peer.address.host), TMsgType.Notify);
3090 mapDataMsg := CreateMapDataMsg(MapsDir + gGameSettings.WAD, gExternalResources);
3091 peer := NetClients[C^.ID].Peer;
3093 MapDataMsgToBytes(payload, mapDataMsg);
3094 g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
3096 payload := nil;
3097 mapDataMsg.FileData := nil;
3098 mapDataMsg.ExternalResources := nil;
3099 end;
3101 procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
3102 var
3103 payload: AByte;
3104 peer: pENetPeer;
3105 FileName: String;
3106 resDataMsg: TResDataMsg;
3107 begin
3108 FileName := ExtractFileName(M.ReadString());
3109 e_WriteLog('NET: Received res request: ' + FileName +
3110 ' from ' + DecodeIPV4(C^.Peer.address.host), TMsgType.Notify);
3112 if not IsValidFilePath(FileName) then
3113 begin
3114 e_WriteLog('Invalid filename: ' + FileName, TMsgType.Warning);
3115 exit;
3116 end;
3118 peer := NetClients[C^.ID].Peer;
3120 if gExternalResources.IndexOf(FileName) > -1 then
3121 begin
3122 resDataMsg.MsgId := NET_MSG_RES_RESPONSE;
3123 resDataMsg.FileData := ReadFile(GameDir+'/wads/'+FileName);
3124 resDataMsg.FileSize := Length(resDataMsg.FileData);
3126 ResDataMsgToBytes(payload, resDataMsg);
3127 g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
3128 end;
3129 end;
3131 end.