DEADSOFTWARE

Revert "network: do not send weapon switch keys over the network, send actual selecte...
[d2df-sdl.git] / src / game / g_netmsg.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 unit g_netmsg;
19 interface
21 uses e_msg, g_net, g_triggers, Classes, SysUtils, md5;
23 const
24 NET_MSG_INFO = 100;
26 NET_MSG_CHAT = 101;
27 NET_MSG_SND = 102;
28 NET_MSG_GFX = 103;
29 NET_MSG_GEVENT = 104;
30 NET_MSG_SCORE = 105;
31 NET_MSG_COOP = 106;
32 NET_MSG_FLAG = 107;
33 NET_MSG_REQFST = 108;
34 NET_MSG_GSET = 109;
36 NET_MSG_PLR = 111;
37 NET_MSG_PLRPOS = 112;
38 NET_MSG_PLRSTA = 113;
39 NET_MSG_PLRDEL = 114;
40 NET_MSG_PLRDMG = 115;
41 NET_MSG_PLRDIE = 116;
42 NET_MSG_PLRFIRE= 117;
43 NET_MSG_PLRSET = 119;
44 NET_MSG_CHEAT = 120;
46 NET_MSG_ISPAWN = 121;
47 NET_MSG_IDEL = 122;
49 NET_MSG_MSPAWN = 131;
50 NET_MSG_MPOS = 132;
51 NET_MSG_MSTATE = 133;
52 NET_MSG_MSHOT = 134;
53 NET_MSG_MDEL = 135;
55 NET_MSG_PSTATE = 141;
56 NET_MSG_PTEX = 142;
58 NET_MSG_TSOUND = 151;
59 NET_MSG_TMUSIC = 152;
61 NET_MSG_SHDEL = 161;
62 NET_MSG_SHADD = 162;
63 NET_MSG_SHPOS = 163;
65 NET_MSG_RCON_AUTH = 191;
66 NET_MSG_RCON_CMD = 192;
67 NET_MSG_TIME_SYNC = 194;
68 NET_MSG_VOTE_EVENT = 195;
70 NET_MSG_MAP_REQUEST = 201;
71 NET_MSG_MAP_RESPONSE = 202;
72 NET_MSG_RES_REQUEST = 203;
73 NET_MSG_RES_RESPONSE = 204;
75 NET_CHAT_SYSTEM = 0;
76 NET_CHAT_PLAYER = 1;
77 NET_CHAT_TEAM = 2;
79 NET_RCON_NOAUTH = 0;
80 NET_RCON_PWGOOD = 1;
81 NET_RCON_PWBAD = 2;
83 NET_GFX_SPARK = 1;
84 NET_GFX_TELE = 2;
85 NET_GFX_RESPAWN = 3;
86 NET_GFX_FIRE = 4;
87 NET_GFX_EXPLODE = 5;
88 NET_GFX_BFGEXPL = 6;
89 NET_GFX_BFGHIT = 7;
90 NET_GFX_SHELL1 = 8;
91 NET_GFX_SHELL2 = 9;
92 NET_GFX_SHELL3 = 10;
94 NET_EV_MAPSTART = 1;
95 NET_EV_MAPEND = 2;
96 NET_EV_CHANGE_TEAM = 3;
97 NET_EV_PLAYER_KICK = 4;
98 NET_EV_PLAYER_BAN = 5;
99 NET_EV_LMS_WARMUP = 6;
100 NET_EV_LMS_SURVIVOR = 7;
101 NET_EV_RCON = 8;
102 NET_EV_BIGTEXT = 9;
103 NET_EV_SCORE = 10;
104 NET_EV_SCORE_MSG = 11;
105 NET_EV_LMS_START = 12;
106 NET_EV_LMS_WIN = 13;
107 NET_EV_TLMS_WIN = 14;
108 NET_EV_LMS_LOSE = 15;
109 NET_EV_LMS_DRAW = 16;
110 NET_EV_KILLCOMBO = 17;
111 NET_EV_PLAYER_TOUCH = 18;
113 NET_VE_STARTED = 1;
114 NET_VE_PASSED = 2;
115 NET_VE_FAILED = 3;
116 NET_VE_VOTE = 4;
117 NET_VE_REVOKE = 5;
118 NET_VE_INPROGRESS = 6;
120 NET_FLAG_GET = 1;
121 NET_FLAG_DROP = 2;
122 NET_FLAG_CAP = 3;
123 NET_FLAG_RETURN = 4;
125 NET_CHEAT_SUICIDE = 1;
126 NET_CHEAT_SPECTATE = 2;
128 NET_MAX_DIFFTIME = 5000 div 36;
130 // HOST MESSAGES
132 procedure MH_RECV_Info(C: pTNetClient; var M: TMsg);
133 procedure MH_RECV_Chat(C: pTNetClient; var M: TMsg);
134 procedure MH_RECV_FullStateRequest(C: pTNetClient; var M: TMsg);
135 function MH_RECV_PlayerPos(C: pTNetClient; var M: TMsg): Word;
136 procedure MH_RECV_PlayerSettings(C: pTNetClient; var M: TMsg);
137 procedure MH_RECV_CheatRequest(C: pTNetClient; var M: TMsg);
138 procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
139 procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
140 procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
141 procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
142 procedure MH_RECV_Vote(C: pTNetClient; var M: TMsg);
144 // GAME
145 procedure MH_SEND_Everything(CreatePlayers: Boolean = False; ID: Integer = NET_EVERYONE);
146 procedure MH_SEND_Info(ID: Byte);
147 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
148 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
149 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
150 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
151 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
152 procedure MH_SEND_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
153 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
154 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
155 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
156 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
157 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
158 // PLAYER
159 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
160 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
161 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
162 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
163 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
164 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
165 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
166 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
167 // ITEM
168 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
169 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
170 // PANEL
171 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
172 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
173 // MONSTER
174 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
175 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
176 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
177 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
178 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
179 // TRIGGER
180 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
181 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
182 // MISC
183 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
184 procedure MH_SEND_VoteEvent(EvType: Byte;
185 StrArg1: string = 'a'; StrArg2: string = 'b';
186 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
187 ID: Integer = NET_EVERYONE);
189 // CLIENT MESSAGES //
191 // GAME
192 procedure MC_RECV_Chat(var M: TMsg);
193 procedure MC_RECV_Effect(var M: TMsg);
194 procedure MC_RECV_Sound(var M: TMsg);
195 procedure MC_RECV_GameStats(var M: TMsg);
196 procedure MC_RECV_CoopStats(var M: TMsg);
197 procedure MC_RECV_GameEvent(var M: TMsg);
198 procedure MC_RECV_FlagEvent(var M: TMsg);
199 procedure MC_RECV_GameSettings(var M: TMsg);
200 // PLAYER
201 function MC_RECV_PlayerCreate(var M: TMsg): Word;
202 function MC_RECV_PlayerPos(var M: TMsg): Word;
203 function MC_RECV_PlayerStats(var M: TMsg): Word;
204 function MC_RECV_PlayerDelete(var M: TMsg): Word;
205 function MC_RECV_PlayerDamage(var M: TMsg): Word;
206 function MC_RECV_PlayerDeath(var M: TMsg): Word;
207 function MC_RECV_PlayerFire(var M: TMsg): Word;
208 procedure MC_RECV_PlayerSettings(var M: TMsg);
209 // ITEM
210 procedure MC_RECV_ItemSpawn(var M: TMsg);
211 procedure MC_RECV_ItemDestroy(var M: TMsg);
212 // PANEL
213 procedure MC_RECV_PanelTexture(var M: TMsg);
214 procedure MC_RECV_PanelState(var M: TMsg);
215 // MONSTER
216 procedure MC_RECV_MonsterSpawn(var M: TMsg);
217 procedure MC_RECV_MonsterPos(var M: TMsg);
218 procedure MC_RECV_MonsterState(var M: TMsg);
219 procedure MC_RECV_MonsterShot(var M: TMsg);
220 procedure MC_RECV_MonsterDelete(var M: TMsg);
221 // SHOT
222 procedure MC_RECV_CreateShot(var M: TMsg);
223 procedure MC_RECV_UpdateShot(var M: TMsg);
224 procedure MC_RECV_DeleteShot(var M: TMsg);
225 // TRIGGER
226 procedure MC_RECV_TriggerSound(var M: TMsg);
227 procedure MC_RECV_TriggerMusic(var M: TMsg);
228 // MISC
229 procedure MC_RECV_TimeSync(var M: TMsg);
230 procedure MC_RECV_VoteEvent(var M: TMsg);
231 // SERVICE
232 procedure MC_SEND_Info(Password: string);
233 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
234 procedure MC_SEND_PlayerPos();
235 procedure MC_SEND_FullStateRequest();
236 procedure MC_SEND_PlayerSettings();
237 procedure MC_SEND_CheatRequest(Kind: Byte);
238 procedure MC_SEND_RCONPassword(Password: string);
239 procedure MC_SEND_RCONCommand(Cmd: string);
240 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
241 // DOWNLOAD
242 procedure MC_SEND_MapRequest();
243 procedure MC_SEND_ResRequest(const resName: AnsiString);
245 type
246 TExternalResourceInfo = record
247 Name: string[255];
248 md5: TMD5Digest;
249 end;
251 TResDataMsg = record
252 MsgId: Byte;
253 FileSize: Integer;
254 FileData: AByte;
255 end;
257 TMapDataMsg = record
258 MsgId: Byte;
259 FileSize: Integer;
260 FileData: AByte;
261 ExternalResources: array of TExternalResourceInfo;
262 end;
264 function MapDataFromMsgStream(msgStream: TMemoryStream):TMapDataMsg;
265 function ResDataFromMsgStream(msgStream: TMemoryStream):TResDataMsg;
267 implementation
269 uses
270 Math, ENet, e_input, e_graphics, e_log,
271 g_textures, g_gfx, g_sound, g_console, g_basic, g_options, g_main,
272 g_game, g_player, g_map, g_panel, g_items, g_weapons, g_phys, g_gui,
273 g_language, g_monsters, g_netmaster, utils, wadreader, MAPDEF;
275 const
276 NET_KEY_LEFT = 1;
277 NET_KEY_RIGHT = 2;
278 NET_KEY_UP = 4;
279 NET_KEY_DOWN = 8;
280 NET_KEY_JUMP = 16;
281 NET_KEY_FIRE = 32;
282 NET_KEY_OPEN = 64;
283 NET_KEY_NW = 256;
284 NET_KEY_PW = 512;
285 NET_KEY_CHAT = 2048;
286 NET_KEY_FORCEDIR = 4096;
288 //var
289 //kBytePrev: Word = 0;
290 //kDirPrev: TDirection = D_LEFT;
291 //HostGameTime: Word = 0;
293 // HOST MESSAGES //
296 // GAME
298 procedure MH_RECV_Chat(C: pTNetClient; var M: TMsg);
299 var
300 Txt: string;
301 Mode: Byte;
302 PID: Word;
303 Pl: TPlayer;
304 begin
305 PID := C^.Player;
306 Pl := g_Player_Get(PID);
308 Txt := M.ReadString();
309 Mode := M.ReadByte();
310 if (Mode = NET_CHAT_SYSTEM) then
311 Mode := NET_CHAT_PLAYER; // prevent sending system messages from clients
312 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
313 Mode := NET_CHAT_PLAYER; // revert to player chat in non-team game
315 if Pl = nil then
316 MH_SEND_Chat(Txt, Mode)
317 else
318 MH_SEND_Chat(Pl.Name + ': ' + Txt, Mode, IfThen(Mode = NET_CHAT_TEAM, Pl.Team, NET_EVERYONE));
319 end;
321 procedure MH_RECV_Info(C: pTNetClient; var M: TMsg);
322 var
323 Ver, PName, Model, Pw: string;
324 R, G, B, T: Byte;
325 PID: Word;
326 Color: TRGB;
327 I: Integer;
328 begin
329 Ver := M.ReadString();
330 Pw := M.ReadString();
331 PName := M.ReadString();
332 Model := M.ReadString();
333 R := M.ReadByte();
334 G := M.ReadByte();
335 B := M.ReadByte();
336 T := M.ReadByte();
338 if Ver <> GAME_VERSION then
339 begin
340 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
341 _lc[I_NET_DISC_VERSION]);
342 enet_peer_disconnect(C^.Peer, NET_DISC_VERSION);
343 Exit;
344 end;
346 if g_Net_IsHostBanned(C^.Peer^.address.host) then
347 begin
348 if g_Net_IsHostBanned(C^.Peer^.address.host, True) then
349 begin
350 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
351 _lc[I_NET_DISC_BAN]);
352 enet_peer_disconnect(C^.Peer, NET_DISC_BAN);
353 end
354 else
355 begin
356 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
357 _lc[I_NET_DISC_BAN]);
358 enet_peer_disconnect(C^.Peer, NET_DISC_TEMPBAN);
359 end;
360 Exit;
361 end;
363 if NetPassword <> '' then
364 if AnsiLowerCase(NetPassword) <> AnsiLowerCase(Pw) then
365 begin
366 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
367 _lc[I_NET_DISC_PASSWORD]);
368 enet_peer_disconnect(C^.Peer, NET_DISC_PASSWORD);
369 Exit;
370 end;
372 Color.R := R;
373 Color.B := B;
374 Color.G := G;
376 PID := g_Player_Create(Model, Color, T, False);
377 with g_Player_Get(PID) do
378 begin
379 Name := PName;
380 Reset(True);
381 end;
383 C^.Player := PID;
385 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
386 e_WriteLog('NET: Client ' + PName + ' [' + IntToStr(C^.ID) +
387 '] connected. Assigned player #' + IntToStr(PID) + '.', TMsgType.Notify);
389 MH_SEND_Info(C^.ID);
391 with g_Player_Get(PID) do
392 begin
393 Name := PName;
394 FClientID := C^.ID;
395 // round in progress, don't spawn
396 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
397 begin
398 Lives := 0;
399 FNoRespawn := True;
400 Spectate;
401 FWantsInGame := True; // TODO: look into this later
402 end
403 else
404 Respawn(gGameSettings.GameType = GT_SINGLE);
405 end;
407 for I := Low(NetClients) to High(NetClients) do
408 begin
409 if NetClients[I].ID = C^.ID then Continue;
410 MH_SEND_PlayerCreate(PID, NetClients[I].ID);
411 MH_SEND_PlayerPos(True, PID, NetClients[I].ID);
412 MH_SEND_PlayerStats(PID, NetClients[I].ID);
413 end;
415 if gState in [STATE_INTERCUSTOM, STATE_FOLD] then
416 MH_SEND_GameEvent(NET_EV_MAPEND, 0, 'N', C^.ID);
418 if NetUseMaster then g_Net_Slist_Update;
419 end;
421 procedure MH_RECV_FullStateRequest(C: pTNetClient; var M: TMsg);
422 begin
423 if gGameOn then
424 MH_SEND_Everything((C^.State = NET_STATE_AUTH), C^.ID)
425 else
426 C^.RequestedFullUpdate := True;
427 end;
429 // PLAYER
431 function MH_RECV_PlayerPos(C: pTNetClient; var M: TMsg): Word;
432 var
433 Dir, i: Byte;
434 WeaponSelect: Word;
435 PID: Word;
436 kByte: Word;
437 Pl: TPlayer;
438 GT: LongWord;
439 begin
440 Result := 0;
441 if not gGameOn then Exit;
443 GT := M.ReadLongWord();
444 PID := C^.Player;
445 Pl := g_Player_Get(PID);
446 if Pl = nil then
447 Exit;
449 if (GT > gTime + NET_MAX_DIFFTIME) or (GT < Pl.NetTime) then Exit;
451 with Pl do
452 begin
453 NetTime := GT;
454 kByte := M.ReadWord();
455 Dir := M.ReadByte();
456 WeaponSelect := M.ReadWord();
457 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
458 if Direction <> TDirection(Dir) then
459 JustTeleported := False;
461 SetDirection(TDirection(Dir));
462 ReleaseKeys;
464 if kByte = NET_KEY_CHAT then
465 begin
466 PressKey(KEY_CHAT, 10000);
467 Exit;
468 end;
470 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
471 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
472 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
473 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
474 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
475 if LongBool(kByte and NET_KEY_FIRE) then PressKey(KEY_FIRE, 10000);
476 if LongBool(kByte and NET_KEY_OPEN) then PressKey(KEY_OPEN, 10000);
477 if LongBool(kByte and NET_KEY_NW) then PressKey(KEY_NEXTWEAPON, 10000);
478 if LongBool(kByte and NET_KEY_PW) then PressKey(KEY_PREVWEAPON, 10000);
480 for i := 0 to 15 do
481 begin
482 if (WeaponSelect and Word(1 shl i)) <> 0 then
483 begin
484 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
485 QueueWeaponSwitch(i);
486 end;
487 end;
488 end;
490 // MH_SEND_PlayerPos(False, PID, C^.ID);
491 end;
493 procedure MH_RECV_CheatRequest(C: pTNetClient; var M: TMsg);
494 var
495 CheatKind: Byte;
496 Pl: TPlayer;
497 begin
498 Pl := g_Player_Get(C^.Player);
499 if Pl = nil then Exit;
501 CheatKind := M.ReadByte();
503 case CheatKind of
504 NET_CHEAT_SUICIDE:
505 Pl.Damage(SUICIDE_DAMAGE, Pl.UID, 0, 0, HIT_SELF);
506 NET_CHEAT_SPECTATE:
507 begin
508 if Pl.FSpectator then
509 Pl.Respawn(False)
510 else
511 Pl.Spectate;
512 end;
513 end;
514 end;
516 procedure MH_RECV_PlayerSettings(C: pTNetClient; var M: TMsg);
517 var
518 TmpName: string;
519 TmpModel: string;
520 TmpColor: TRGB;
521 TmpTeam: Byte;
522 Pl: TPlayer;
523 begin
524 TmpName := M.ReadString();
525 TmpModel := M.ReadString();
526 TmpColor.R := M.ReadByte();
527 TmpColor.G := M.ReadByte();
528 TmpColor.B := M.ReadByte();
529 TmpTeam := M.ReadByte();
531 Pl := g_Player_Get(C^.Player);
532 if Pl = nil then Exit;
534 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
535 Pl.SwitchTeam
536 else
537 Pl.SetColor(TmpColor);
539 if Pl.Name <> TmpName then
540 begin
541 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
542 Pl.Name := TmpName;
543 end;
545 if TmpModel <> Pl.Model.Name then
546 Pl.SetModel(TmpModel);
548 MH_SEND_PlayerSettings(Pl.UID, TmpModel);
549 end;
551 // RCON
553 procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
554 var
555 Pwd: string;
556 begin
557 Pwd := M.ReadString();
558 if not NetAllowRCON then Exit;
559 if Pwd = NetRCONPassword then
560 begin
561 C^.RCONAuth := True;
562 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWGOOD, 'N', C^.ID);
563 end
564 else
565 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWBAD, 'N', C^.ID);
566 end;
568 procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
569 var
570 Cmd: string;
571 begin
572 Cmd := M.ReadString();
573 if not NetAllowRCON then Exit;
574 if not C^.RCONAuth then
575 begin
576 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_NOAUTH, 'N', C^.ID);
577 Exit;
578 end;
579 g_Console_Process(Cmd);
580 end;
582 // MISC
584 procedure MH_RECV_Vote(C: pTNetClient; var M: TMsg);
585 var
586 Start: Boolean;
587 Name, Command: string;
588 Need: Integer;
589 Pl: TPlayer;
590 begin
591 Start := M.ReadByte() <> 0;
592 Command := M.ReadString();
594 Pl := g_Player_Get(C^.Player);
595 if Pl = nil then Exit;
596 Name := Pl.Name;
598 if Start then
599 begin
600 if not g_Console_CommandBlacklisted(Command) then
601 g_Game_StartVote(Command, Name);
602 end
603 else if gVoteInProgress then
604 begin
605 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
606 Need := Floor((NetClientCount+1)/2.0) + 1
607 else
608 Need := Floor(NetClientCount/2.0) + 1;
609 if C^.Voted then
610 begin
611 Dec(gVoteCount);
612 C^.Voted := False;
613 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [Name, gVoteCount, Need]), True);
614 MH_SEND_VoteEvent(NET_VE_REVOKE, Name, 'a', gVoteCount, Need);
615 end
616 else
617 begin
618 Inc(gVoteCount);
619 C^.Voted := True;
620 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Name, gVoteCount, Need]), True);
621 MH_SEND_VoteEvent(NET_VE_VOTE, Name, 'a', gVoteCount, Need);
622 g_Game_CheckVote;
623 end;
624 end;
625 end;
627 // GAME (SEND)
629 procedure MH_SEND_Everything(CreatePlayers: Boolean = False; ID: Integer = NET_EVERYONE);
631 function sendItemRespawn (it: PItem): Boolean;
632 begin
633 result := false; // don't stop
634 MH_SEND_ItemSpawn(True, it.myid, ID);
635 end;
637 function sendMonSpawn (mon: TMonster): Boolean;
638 begin
639 result := false; // don't stop
640 MH_SEND_MonsterSpawn(mon.UID, ID);
641 end;
643 function sendPanelState (pan: TPanel): Boolean;
644 begin
645 result := false; // don't stop
646 MH_SEND_PanelState(pan.guid, ID); // anyway, to sync mplats
647 if (pan.CanChangeTexture) then MH_SEND_PanelTexture(pan.guid, pan.LastAnimLoop, ID);
648 end;
650 var
651 I: Integer;
652 begin
653 if gPlayers <> nil then
654 begin
655 for I := Low(gPlayers) to High(gPlayers) do
656 begin
657 if gPlayers[I] <> nil then
658 begin
659 if CreatePlayers then MH_SEND_PlayerCreate(gPlayers[I].UID, ID);
660 MH_SEND_PlayerPos(True, gPlayers[I].UID, ID);
661 MH_SEND_PlayerStats(gPlayers[I].UID, ID);
663 if (gPlayers[I].Flag <> FLAG_NONE) and (gGameSettings.GameMode = GM_CTF) then
664 begin
665 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED, gPlayers[I].Flag, gPlayers[I].UID, True, ID);
666 end;
667 end;
668 end;
669 end;
671 g_Items_ForEachAlive(sendItemRespawn, true); // backwards
672 g_Mons_ForEach(sendMonSpawn);
673 g_Map_ForEachPanel(sendPanelState);
675 if gTriggers <> nil then
676 begin
677 for I := Low(gTriggers) to High(gTriggers) do
678 begin
679 if gTriggers[I].TriggerType = TRIGGER_SOUND then
680 begin
681 MH_SEND_TriggerSound(gTriggers[I], ID);
682 end;
683 end;
684 end;
686 if Shots <> nil then
687 begin
688 for I := Low(Shots) to High(Shots) do
689 begin
690 if Shots[i].ShotType in [6, 7, 8] then
691 begin
692 MH_SEND_CreateShot(i, ID);
693 end;
694 end;
695 end;
697 MH_SEND_TriggerMusic(ID);
699 MH_SEND_GameStats(ID);
700 MH_SEND_CoopStats(ID);
702 if gGameSettings.GameMode = GM_CTF then
703 begin
704 if gFlags[FLAG_RED].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_RED].State, FLAG_RED, 0, True, ID);
705 if gFlags[FLAG_BLUE].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_BLUE].State, FLAG_BLUE, 0, True, ID);
706 end;
708 if CreatePlayers and (ID >= 0) then NetClients[ID].State := NET_STATE_GAME;
710 if gLMSRespawn > LMS_RESPAWN_NONE then
711 begin
712 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000, 'N', ID);
713 end;
714 end;
716 procedure MH_SEND_Info(ID: Byte);
717 var
718 Map: string;
719 begin
720 Map := g_ExtractFileName(gMapInfo.Map);
722 NetOut.Clear();
724 NetOut.Write(Byte(NET_MSG_INFO));
725 NetOut.Write(ID);
726 NetOut.Write(NetClients[ID].Player);
727 NetOut.Write(gGameSettings.WAD);
728 NetOut.Write(Map);
729 NetOut.Write(gWADHash);
730 NetOut.Write(gGameSettings.GameMode);
731 NetOut.Write(gGameSettings.GoalLimit);
732 NetOut.Write(gGameSettings.TimeLimit);
733 NetOut.Write(gGameSettings.MaxLives);
734 NetOut.Write(gGameSettings.Options);
735 NetOut.Write(gTime);
737 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
738 end;
740 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
741 var
742 Name: string;
743 i: Integer;
744 Team: Byte;
745 begin
746 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
747 Mode := NET_CHAT_PLAYER;
749 Team := 0;
750 if (Mode = NET_CHAT_TEAM) then
751 begin
752 for i := Low(gPlayers) to High(gPlayers) do
753 if (gPlayers[i] <> nil) and (gPlayers[i].FClientID >= 0) and
754 (gPlayers[i].Team = ID) then
755 begin
756 NetOut.Write(Byte(NET_MSG_CHAT));
757 NetOut.Write(Txt);
758 NetOut.Write(Mode);
759 g_Net_Host_Send(gPlayers[i].FClientID, True, NET_CHAN_CHAT);
760 end;
761 Team := ID;
762 ID := NET_EVERYONE;
763 end
764 else
765 begin
766 NetOut.Write(Byte(NET_MSG_CHAT));
767 NetOut.Write(Txt);
768 NetOut.Write(Mode);
769 g_Net_Host_Send(ID, True, NET_CHAN_CHAT);
770 end;
772 if Mode = NET_CHAT_SYSTEM then
773 Exit;
775 if ID = NET_EVERYONE then
776 begin
777 if Mode = NET_CHAT_PLAYER then
778 begin
779 g_Console_Add(Txt, True);
780 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
781 g_Game_ChatSound(b_Text_Unformat(Txt));
782 end
783 else
784 if Mode = NET_CHAT_TEAM then
785 if gPlayer1 <> nil then
786 begin
787 if (gPlayer1.Team = TEAM_RED) and (Team = TEAM_RED) then
788 begin
789 g_Console_Add(#18'[Team] '#2 + Txt, True);
790 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
791 g_Game_ChatSound(b_Text_Unformat(Txt));
792 end
793 else if (gPlayer1.Team = TEAM_BLUE) and (Team = TEAM_BLUE) then
794 begin
795 g_Console_Add(#20'[Team] '#2 + Txt, True);
796 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
797 g_Game_ChatSound(b_Text_Unformat(Txt));
798 end;
799 end;
800 end
801 else
802 begin
803 Name := g_Net_ClientName_ByID(ID);
804 g_Console_Add('-> ' + Name + ': ' + Txt, True);
805 e_WriteLog('[Tell ' + Name + '] ' + b_Text_Unformat(Txt), TMsgType.Notify);
806 g_Game_ChatSound(b_Text_Unformat(Txt), False);
807 end;
808 end;
810 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
811 begin
812 NetOut.Write(Byte(NET_MSG_GFX));
813 NetOut.Write(Kind);
814 NetOut.Write(X);
815 NetOut.Write(Y);
816 NetOut.Write(Ang);
818 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
819 end;
821 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
822 begin
823 NetOut.Write(Byte(NET_MSG_SND));
824 NetOut.Write(Name);
825 if Pos then
826 begin
827 NetOut.Write(Byte(1));
828 NetOut.Write(X);
829 NetOut.Write(Y);
830 end
831 else
832 NetOut.Write(Byte(0));
834 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
835 end;
837 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
838 begin
839 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
841 NetOut.Write(Byte(NET_MSG_SHADD));
842 NetOut.Write(Proj);
843 NetOut.Write(Shots[Proj].ShotType);
844 NetOut.Write(Shots[Proj].Target);
845 NetOut.Write(Shots[Proj].SpawnerUID);
846 NetOut.Write(Shots[Proj].Timeout);
847 NetOut.Write(Shots[Proj].Obj.X);
848 NetOut.Write(Shots[Proj].Obj.Y);
849 NetOut.Write(Shots[Proj].Obj.Vel.X);
850 NetOut.Write(Shots[Proj].Obj.Vel.Y);
852 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
853 end;
855 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
856 begin
857 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
859 NetOut.Write(Byte(NET_MSG_SHPOS));
860 NetOut.Write(Proj);
861 NetOut.Write(Shots[Proj].Obj.X);
862 NetOut.Write(Shots[Proj].Obj.Y);
863 NetOut.Write(Shots[Proj].Obj.Vel.X);
864 NetOut.Write(Shots[Proj].Obj.Vel.Y);
866 g_Net_Host_Send(ID, False, NET_CHAN_SHOTS);
867 end;
869 procedure MH_Send_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
870 begin
871 NetOut.Write(Byte(NET_MSG_SHDEL));
872 NetOut.Write(Proj);
873 NetOut.Write(Byte(Loud));
874 NetOut.Write(X);
875 NetOut.Write(Y);
877 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
878 end;
880 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
881 begin
882 NetOut.Write(Byte(NET_MSG_SCORE));
883 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
884 begin
885 NetOut.Write(gTeamStat[TEAM_RED].Goals);
886 NetOut.Write(gTeamStat[TEAM_BLUE].Goals);
887 end
888 else
889 if gGameSettings.GameMode = GM_COOP then
890 begin
891 NetOut.Write(gCoopMonstersKilled);
892 NetOut.Write(gCoopSecretsFound);
893 end;
895 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
896 end;
898 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
899 begin
900 NetOut.Write(Byte(NET_MSG_COOP));
901 NetOut.Write(gTotalMonsters);
902 NetOut.Write(gSecretsCount);
903 NetOut.Write(gCoopTotalMonstersKilled);
904 NetOut.Write(gCoopTotalSecretsFound);
905 NetOut.Write(gCoopTotalMonsters);
906 NetOut.Write(gCoopTotalSecrets);
907 end;
909 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
910 begin
911 NetOut.Write(Byte(NET_MSG_GEVENT));
912 NetOut.Write(EvType);
913 NetOut.Write(EvNum);
914 NetOut.Write(EvStr);
915 NetOut.Write(Byte(gLastMap));
916 NetOut.Write(gTime);
917 if (EvType = NET_EV_MAPSTART) and isWadPath(EvStr) then
918 begin
919 NetOut.Write(Byte(1));
920 NetOut.Write(gWADHash);
921 end else
922 NetOut.Write(Byte(0));
924 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
925 end;
927 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
928 begin
929 NetOut.Write(Byte(NET_MSG_FLAG));
930 NetOut.Write(EvType);
931 NetOut.Write(Flag);
932 NetOut.Write(Byte(Quiet));
933 NetOut.Write(PID);
934 NetOut.Write(gFlags[Flag].State);
935 NetOut.Write(gFlags[Flag].CaptureTime);
936 NetOut.Write(gFlags[Flag].Obj.X);
937 NetOut.Write(gFlags[Flag].Obj.Y);
938 NetOut.Write(gFlags[Flag].Obj.Vel.X);
939 NetOut.Write(gFlags[Flag].Obj.Vel.Y);
941 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
942 end;
944 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
945 begin
946 NetOut.Write(Byte(NET_MSG_GSET));
947 NetOut.Write(gGameSettings.GameMode);
948 NetOut.Write(gGameSettings.GoalLimit);
949 NetOut.Write(gGameSettings.TimeLimit);
950 NetOut.Write(gGameSettings.MaxLives);
951 NetOut.Write(gGameSettings.Options);
953 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
954 end;
956 // PLAYER (SEND)
958 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
959 var
960 P: TPlayer;
961 begin
962 P := g_Player_Get(PID);
963 if P = nil then Exit;
965 NetOut.Write(Byte(NET_MSG_PLR));
966 NetOut.Write(PID);
967 NetOut.Write(P.Name);
969 NetOut.Write(P.FActualModelName);
970 NetOut.Write(P.FColor.R);
971 NetOut.Write(P.FColor.G);
972 NetOut.Write(P.FColor.B);
973 NetOut.Write(P.Team);
975 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT)
976 end;
978 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
979 var
980 kByte: Word;
981 Pl: TPlayer;
982 begin
983 Pl := g_Player_Get(PID);
984 if Pl = nil then Exit;
985 if Pl.FDummy then Exit;
987 NetOut.Write(Byte(NET_MSG_PLRPOS));
988 NetOut.Write(gTime);
989 NetOut.Write(PID);
991 kByte := 0;
993 with Pl do
994 begin
995 NetOut.Write(FPing);
996 NetOut.Write(FLoss);
997 if IsKeyPressed(KEY_CHAT) then
998 kByte := NET_KEY_CHAT
999 else
1000 begin
1001 if IsKeyPressed(KEY_LEFT) then kByte := kByte or NET_KEY_LEFT;
1002 if IsKeyPressed(KEY_RIGHT) then kByte := kByte or NET_KEY_RIGHT;
1003 if IsKeyPressed(KEY_UP) then kByte := kByte or NET_KEY_UP;
1004 if IsKeyPressed(KEY_DOWN) then kByte := kByte or NET_KEY_DOWN;
1005 if IsKeyPressed(KEY_JUMP) then kByte := kByte or NET_KEY_JUMP;
1006 if JustTeleported then kByte := kByte or NET_KEY_FORCEDIR;
1007 end;
1009 NetOut.Write(kByte);
1010 if Direction = TDirection.D_LEFT then NetOut.Write(Byte(0)) else NetOut.Write(Byte(1));
1011 NetOut.Write(GameX);
1012 NetOut.Write(GameY);
1013 NetOut.Write(GameVelX);
1014 NetOut.Write(GameVelY);
1015 NetOut.Write(GameAccelX);
1016 NetOut.Write(GameAccelY);
1017 end;
1019 g_Net_Host_Send(ID, Reliable, NET_CHAN_PLAYERPOS);
1020 end;
1022 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
1023 var
1024 P: TPlayer;
1025 I: Integer;
1026 ww: Word;
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 // collect all weapons in one word
1046 ww := 0;
1047 for I := WP_FIRST to WP_LAST do if (FWeapon[I]) then ww := ww or (1 shl (i-WP_FIRST));
1048 NetOut.Write(Word(ww));
1050 for I := A_BULLETS to A_HIGH do
1051 NetOut.Write(FAmmo[I]);
1053 for I := A_BULLETS to A_HIGH do
1054 NetOut.Write(FMaxAmmo[I]);
1056 for I := MR_SUIT to MR_MAX do
1057 NetOut.Write(LongWord(FMegaRulez[I]));
1059 // collect all special flags in one byte
1060 ww := 0;
1061 if (R_ITEM_BACKPACK in FRulez) then ww := ww or $01;
1062 if (R_KEY_RED in FRulez) then ww := ww or $02;
1063 if (R_KEY_GREEN in FRulez) then ww := ww or $04;
1064 if (R_KEY_BLUE in FRulez) then ww := ww or $08;
1065 if (R_BERSERK in FRulez) then ww := ww or $10;
1066 NetOut.Write(Byte(ww));
1068 NetOut.Write(Frags);
1069 NetOut.Write(Death);
1071 NetOut.Write(CurrWeap);
1073 // other flags
1074 ww := 0;
1075 if (FSpectator) then ww := ww or $01;
1076 if (FGhost) then ww := ww or $02;
1077 if (FPhysics) then ww := ww or $04;
1078 if (FNoRespawn) then ww := ww or $08;
1079 if (FJetpack) then ww := ww or $10;
1080 NetOut.Write(Byte(ww));
1082 NetOut.Write(FFireTime);
1083 end;
1085 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1086 end;
1088 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
1089 begin
1090 NetOut.Write(Byte(NET_MSG_PLRDMG));
1091 NetOut.Write(PID);
1092 NetOut.Write(Kind);
1093 NetOut.Write(Attacker);
1094 NetOut.Write(Value);
1095 NetOut.Write(VX);
1096 NetOut.Write(VY);
1098 g_Net_Host_Send(ID, False, NET_CHAN_PLAYER);
1099 end;
1101 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
1102 begin
1103 NetOut.Write(Byte(NET_MSG_PLRDIE));
1104 NetOut.Write(PID);
1105 NetOut.Write(KillType);
1106 NetOut.Write(DeathType);
1107 NetOut.Write(Attacker);
1109 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1110 end;
1112 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
1113 begin
1114 NetOut.Write(Byte(NET_MSG_PLRFIRE));
1115 NetOut.Write(PID);
1116 NetOut.Write(Weapon);
1117 NetOut.Write(X);
1118 NetOut.Write(Y);
1119 NetOut.Write(AX);
1120 NetOut.Write(AY);
1121 NetOut.Write(ShotID);
1123 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1124 end;
1126 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
1127 begin
1128 NetOut.Write(Byte(NET_MSG_PLRDEL));
1129 NetOut.Write(PID);
1131 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1132 end;
1134 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
1135 var
1136 Pl: TPlayer;
1137 begin
1138 Pl := g_Player_Get(PID);
1139 if Pl = nil then Exit;
1141 NetOut.Write(Byte(NET_MSG_PLRSET));
1142 NetOut.Write(PID);
1143 NetOut.Write(Pl.Name);
1144 if Mdl = '' then
1145 NetOut.Write(Pl.Model.Name)
1146 else
1147 NetOut.Write(Mdl);
1148 NetOut.Write(Pl.FColor.R);
1149 NetOut.Write(Pl.FColor.G);
1150 NetOut.Write(Pl.FColor.B);
1151 NetOut.Write(Pl.Team);
1153 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1154 end;
1156 // ITEM (SEND)
1158 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1159 var
1160 it: PItem;
1161 tt: Byte;
1162 begin
1163 it := g_Items_ByIdx(IID);
1165 NetOut.Write(Byte(NET_MSG_ISPAWN));
1166 NetOut.Write(IID);
1167 NetOut.Write(Byte(Quiet));
1168 tt := it.ItemType;
1169 if it.dropped then tt := tt or $80;
1170 NetOut.Write(tt);
1171 NetOut.Write(Byte(it.Fall));
1172 NetOut.Write(Byte(it.Respawnable));
1173 NetOut.Write(it.Obj.X);
1174 NetOut.Write(it.Obj.Y);
1175 NetOut.Write(it.Obj.Vel.X);
1176 NetOut.Write(it.Obj.Vel.Y);
1178 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1179 end;
1181 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1182 begin
1183 NetOut.Write(Byte(NET_MSG_IDEL));
1184 NetOut.Write(IID);
1185 NetOut.Write(Byte(Quiet));
1187 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1188 end;
1190 // PANEL
1192 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
1193 var
1194 TP: TPanel;
1195 begin
1196 TP := g_Map_PanelByGUID(PGUID);
1197 if (TP = nil) then exit;
1199 with TP do
1200 begin
1201 NetOut.Write(Byte(NET_MSG_PTEX));
1202 NetOut.Write(LongWord(PGUID));
1203 NetOut.Write(FCurTexture);
1204 NetOut.Write(FCurFrame);
1205 NetOut.Write(FCurFrameCount);
1206 NetOut.Write(AnimLoop);
1207 end;
1209 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1210 end;
1212 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
1213 var
1214 TP: TPanel;
1215 mpflags: Byte = 0;
1216 begin
1217 TP := g_Map_PanelByGUID(PGUID);
1218 if (TP = nil) then exit;
1220 NetOut.Write(Byte(NET_MSG_PSTATE));
1221 NetOut.Write(LongWord(PGUID));
1222 NetOut.Write(Byte(TP.Enabled));
1223 NetOut.Write(TP.LiftType);
1224 NetOut.Write(TP.X);
1225 NetOut.Write(TP.Y);
1226 NetOut.Write(Word(TP.Width));
1227 NetOut.Write(Word(TP.Height));
1228 // mplats
1229 NetOut.Write(LongInt(TP.movingSpeedX));
1230 NetOut.Write(LongInt(TP.movingSpeedY));
1231 NetOut.Write(LongInt(TP.movingStartX));
1232 NetOut.Write(LongInt(TP.movingStartY));
1233 NetOut.Write(LongInt(TP.movingEndX));
1234 NetOut.Write(LongInt(TP.movingEndY));
1235 NetOut.Write(LongInt(TP.sizeSpeedX));
1236 NetOut.Write(LongInt(TP.sizeSpeedY));
1237 NetOut.Write(LongInt(TP.sizeEndX));
1238 NetOut.Write(LongInt(TP.sizeEndY));
1239 if TP.movingActive then mpflags := mpflags or 1;
1240 if TP.moveOnce then mpflags := mpflags or 2;
1241 NetOut.Write(Byte(mpflags));
1243 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1244 end;
1246 // TRIGGER
1248 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
1249 begin
1250 if gTriggers = nil then Exit;
1251 if T.Sound = nil then Exit;
1253 NetOut.Write(Byte(NET_MSG_TSOUND));
1254 NetOut.Write(T.ClientID);
1255 NetOut.Write(Byte(T.Sound.IsPlaying));
1256 NetOut.Write(LongWord(T.Sound.GetPosition));
1257 NetOut.Write(T.SoundPlayCount);
1259 g_Net_Host_Send(ID, True);
1260 end;
1262 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
1263 begin
1264 NetOut.Write(Byte(NET_MSG_TMUSIC));
1265 NetOut.Write(gMusic.Name);
1266 NetOut.Write(Byte(gMusic.IsPlaying));
1267 NetOut.Write(LongWord(gMusic.GetPosition));
1268 NetOut.Write(Byte(gMusic.SpecPause or gMusic.IsPaused));
1270 g_Net_Host_Send(ID, True);
1271 end;
1273 // MONSTER
1275 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
1276 var
1277 M: TMonster;
1278 begin
1279 M := g_Monsters_ByUID(UID);
1280 if M = nil then
1281 Exit;
1283 with M do
1284 begin
1285 NetOut.Write(Byte(NET_MSG_MSPAWN));
1286 NetOut.Write(UID);
1287 NetOut.Write(MonsterType);
1288 NetOut.Write(MonsterState);
1289 NetOut.Write(MonsterAnim);
1290 NetOut.Write(MonsterTargetUID);
1291 NetOut.Write(MonsterTargetTime);
1292 NetOut.Write(MonsterBehaviour);
1293 NetOut.Write(MonsterSleep);
1294 NetOut.Write(MonsterHealth);
1295 NetOut.Write(MonsterAmmo);
1296 NetOut.Write(GameX);
1297 NetOut.Write(GameY);
1298 NetOut.Write(GameVelX);
1299 NetOut.Write(GameVelY);
1300 NetOut.Write(Byte(GameDirection));
1301 end;
1303 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1304 end;
1306 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
1307 var
1308 M: TMonster;
1309 begin
1310 M := g_Monsters_ByUID(UID);
1311 if M = nil then Exit;
1313 NetOut.Write(Byte(NET_MSG_MPOS));
1314 NetOut.Write(UID);
1316 with M do
1317 begin
1318 NetOut.Write(GameX);
1319 NetOut.Write(GameY);
1320 NetOut.Write(GameVelX);
1321 NetOut.Write(GameVelY);
1322 NetOut.Write(Byte(GameDirection));
1323 end;
1325 g_Net_Host_Send(ID, False, NET_CHAN_MONSTERPOS);
1326 end;
1328 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
1329 var
1330 M: TMonster;
1331 begin
1332 M := g_Monsters_ByUID(UID);
1333 if M = nil then Exit;
1335 NetOut.Write(Byte(NET_MSG_MSTATE));
1336 NetOut.Write(UID);
1338 with M do
1339 begin
1340 NetOut.Write(MonsterState);
1341 NetOut.Write(ForcedAnim);
1342 NetOut.Write(MonsterTargetUID);
1343 NetOut.Write(MonsterTargetTime);
1344 NetOut.Write(MonsterSleep);
1345 NetOut.Write(MonsterHealth);
1346 NetOut.Write(MonsterAmmo);
1347 NetOut.Write(MonsterPain);
1348 NetOut.Write(Byte(AnimIsReverse));
1349 NetOut.Write(FFireTime);
1350 end;
1352 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1353 end;
1355 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
1356 begin
1357 NetOut.Write(Byte(NET_MSG_MSHOT));
1358 NetOut.Write(UID);
1359 NetOut.Write(X);
1360 NetOut.Write(Y);
1361 NetOut.Write(VX);
1362 NetOut.Write(VY);
1364 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1365 end;
1367 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
1368 var
1369 M: TMonster;
1370 begin
1371 M := g_Monsters_ByUID(UID);
1372 if M = nil then Exit;
1374 NetOut.Write(Byte(NET_MSG_MDEL));
1375 NetOut.Write(UID);
1377 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1378 end;
1380 // MISC
1382 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
1383 begin
1384 NetOut.Write(Byte(NET_MSG_TIME_SYNC));
1385 NetOut.Write(Time);
1387 g_Net_Host_Send(ID, False, NET_CHAN_SERVICE);
1388 end;
1390 procedure MH_SEND_VoteEvent(EvType: Byte;
1391 StrArg1: string = 'a'; StrArg2: string = 'b';
1392 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
1393 ID: Integer = NET_EVERYONE);
1394 begin
1395 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
1396 NetOut.Write(EvType);
1397 NetOut.Write(IntArg1);
1398 NetOut.Write(IntArg2);
1399 NetOut.Write(StrArg1);
1400 NetOut.Write(StrArg2);
1402 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1403 end;
1405 // CLIENT MESSAGES //
1407 // GAME
1409 procedure MC_RECV_Chat(var M: TMsg);
1410 var
1411 Txt: string;
1412 Mode: Byte;
1413 begin
1414 Txt := M.ReadString();
1415 Mode := M.ReadByte();
1417 if Mode <> NET_CHAT_SYSTEM then
1418 begin
1419 if Mode = NET_CHAT_PLAYER then
1420 begin
1421 g_Console_Add(Txt, True);
1422 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1423 g_Game_ChatSound(b_Text_Unformat(Txt));
1424 end else
1425 if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then
1426 begin
1427 if gPlayer1.Team = TEAM_RED then
1428 g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True);
1429 if gPlayer1.Team = TEAM_BLUE then
1430 g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True);
1431 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1432 g_Game_ChatSound(b_Text_Unformat(Txt));
1433 end;
1434 end else
1435 g_Console_Add(Txt, True);
1436 end;
1438 procedure MC_RECV_Effect(var M: TMsg);
1439 var
1440 Kind: Byte;
1441 X, Y: Integer;
1442 Ang: SmallInt;
1443 Anim: TAnimation;
1444 ID: LongWord;
1445 begin
1446 if not gGameOn then Exit;
1447 Kind := M.ReadByte();
1448 X := M.ReadLongInt();
1449 Y := M.ReadLongInt();
1450 Ang := M.ReadSmallInt();
1452 case Kind of
1453 NET_GFX_SPARK:
1454 g_GFX_Spark(X, Y, 2 + Random(2), Ang, 0, 0);
1456 NET_GFX_TELE:
1457 begin
1458 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
1459 begin
1460 Anim := TAnimation.Create(ID, False, 3);
1461 g_GFX_OnceAnim(X, Y, Anim);
1462 Anim.Free();
1463 end;
1464 if Ang = 1 then
1465 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
1466 end;
1468 NET_GFX_EXPLODE:
1469 begin
1470 if g_Frames_Get(ID, 'FRAMES_EXPLODE_ROCKET') then
1471 begin
1472 Anim := TAnimation.Create(ID, False, 6);
1473 Anim.Blending := False;
1474 g_GFX_OnceAnim(X-64, Y-64, Anim);
1475 Anim.Free();
1476 end;
1477 if Ang = 1 then
1478 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X, Y);
1479 end;
1481 NET_GFX_BFGEXPL:
1482 begin
1483 if g_Frames_Get(ID, 'FRAMES_EXPLODE_BFG') then
1484 begin
1485 Anim := TAnimation.Create(ID, False, 6);
1486 Anim.Blending := False;
1487 g_GFX_OnceAnim(X-64, Y-64, Anim);
1488 Anim.Free();
1489 end;
1490 if Ang = 1 then
1491 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X, Y);
1492 end;
1494 NET_GFX_BFGHIT:
1495 begin
1496 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1497 begin
1498 Anim := TAnimation.Create(ID, False, 4);
1499 g_GFX_OnceAnim(X-32, Y-32, Anim);
1500 Anim.Free();
1501 end;
1502 end;
1504 NET_GFX_FIRE:
1505 begin
1506 if g_Frames_Get(ID, 'FRAMES_FIRE') then
1507 begin
1508 Anim := TAnimation.Create(ID, False, 4);
1509 g_GFX_OnceAnim(X, Y, Anim);
1510 Anim.Free();
1511 end;
1512 if Ang = 1 then
1513 g_Sound_PlayExAt('SOUND_FIRE', X, Y);
1514 end;
1516 NET_GFX_RESPAWN:
1517 begin
1518 if g_Frames_Get(ID, 'FRAMES_ITEM_RESPAWN') then
1519 begin
1520 Anim := TAnimation.Create(ID, False, 4);
1521 g_GFX_OnceAnim(X, Y, Anim);
1522 Anim.Free();
1523 end;
1524 if Ang = 1 then
1525 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
1526 end;
1528 NET_GFX_SHELL1:
1529 g_Player_CreateShell(X, Y, 0, -2, SHELL_BULLET);
1531 NET_GFX_SHELL2:
1532 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1534 NET_GFX_SHELL3:
1535 begin
1536 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1537 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1538 end;
1539 end;
1540 end;
1542 procedure MC_RECV_Sound(var M: TMsg);
1543 var
1544 Name: string;
1545 X, Y: Integer;
1546 Pos: Boolean;
1547 begin
1548 Name := M.ReadString();
1549 Pos := M.ReadByte() <> 0;
1550 if Pos then
1551 begin
1552 X := M.ReadLongInt();
1553 Y := M.ReadLongInt();
1554 g_Sound_PlayExAt(Name, X, Y);
1555 end
1556 else
1557 g_Sound_PlayEx(Name);
1558 end;
1560 procedure MC_RECV_CreateShot(var M: TMsg);
1561 var
1562 I, X, Y, XV, YV: Integer;
1563 Timeout: LongWord;
1564 Target, Spawner: Word;
1565 ShType: Byte;
1566 begin
1567 I := M.ReadLongInt();
1568 ShType := M.ReadByte();
1569 Target := M.ReadWord();
1570 Spawner := M.ReadWord();
1571 Timeout := M.ReadLongWord();
1572 X := M.ReadLongInt();
1573 Y := M.ReadLongInt();
1574 XV := M.ReadLongInt();
1575 YV := M.ReadLongInt();
1577 I := g_Weapon_CreateShot(I, ShType, Spawner, Target, X, Y, XV, YV);
1578 if (Shots <> nil) and (I <= High(Shots)) then
1579 begin
1580 Shots[I].Timeout := Timeout;
1581 //Shots[I].Target := Target; // TODO: find a use for Target later
1582 end;
1583 end;
1585 procedure MC_RECV_UpdateShot(var M: TMsg);
1586 var
1587 I, TX, TY, TXV, TYV: Integer;
1588 begin
1589 I := M.ReadLongInt();
1590 TX := M.ReadLongInt();
1591 TY := M.ReadLongInt();
1592 TXV := M.ReadLongInt();
1593 TYV := M.ReadLongInt();
1595 if (Shots <> nil) and (I <= High(Shots)) then
1596 with (Shots[i]) do
1597 begin
1598 Obj.X := TX;
1599 Obj.Y := TY;
1600 Obj.Vel.X := TXV;
1601 Obj.Vel.Y := TYV;
1602 end;
1603 end;
1605 procedure MC_RECV_DeleteShot(var M: TMsg);
1606 var
1607 I, X, Y: Integer;
1608 L: Boolean;
1609 begin
1610 if not gGameOn then Exit;
1611 I := M.ReadLongInt();
1612 L := (M.ReadByte() <> 0);
1613 X := M.ReadLongInt();
1614 Y := M.ReadLongInt();
1616 g_Weapon_DestroyShot(I, X, Y, L);
1617 end;
1619 procedure MC_RECV_GameStats(var M: TMsg);
1620 begin
1621 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1622 begin
1623 gTeamStat[TEAM_RED].Goals := M.ReadSmallInt();
1624 gTeamStat[TEAM_BLUE].Goals := M.ReadSmallInt();
1625 end
1626 else
1627 if gGameSettings.GameMode = GM_COOP then
1628 begin
1629 gCoopMonstersKilled := M.ReadWord();
1630 gCoopSecretsFound := M.ReadWord();
1631 end;
1632 end;
1634 procedure MC_RECV_CoopStats(var M: TMsg);
1635 begin
1636 gTotalMonsters := M.ReadLongInt();
1637 gSecretsCount := M.ReadLongInt();
1638 gCoopTotalMonstersKilled := M.ReadWord();
1639 gCoopTotalSecretsFound := M.ReadWord();
1640 gCoopTotalMonsters := M.ReadWord();
1641 gCoopTotalSecrets := M.ReadWord();
1642 end;
1644 procedure MC_RECV_GameEvent(var M: TMsg);
1645 var
1646 EvType: Byte;
1647 EvNum: Integer;
1648 EvStr: string;
1649 EvTime: LongWord;
1650 BHash: Boolean;
1651 EvHash: TMD5Digest;
1652 pl: TPlayer;
1653 i1, i2: TStrings_Locale;
1654 pln: String;
1655 cnt: Byte;
1656 begin
1657 FillChar(EvHash, Sizeof(EvHash), 0);
1658 EvType := M.ReadByte();
1659 EvNum := M.ReadLongInt();
1660 EvStr := M.ReadString();
1661 gLastMap := M.ReadByte() <> 0;
1662 if gLastMap and (gGameSettings.GameMode = GM_COOP) then gStatsOff := True;
1663 gStatsPressed := True;
1664 EvTime := M.ReadLongWord();
1665 BHash := M.ReadByte() <> 0;
1666 if BHash then
1667 EvHash := M.ReadMD5();
1669 gTime := EvTime;
1671 case EvType of
1672 NET_EV_MAPSTART:
1673 begin
1674 gGameOn := False;
1675 g_Game_ClearLoading();
1676 g_Game_StopAllSounds(True);
1678 gSwitchGameMode := Byte(EvNum);
1679 gGameSettings.GameMode := gSwitchGameMode;
1681 gWADHash := EvHash;
1682 if not g_Game_StartMap(EvStr, True) then
1683 begin
1684 if not isWadPath(EvStr) then
1685 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + EvStr]))
1686 else
1687 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [EvStr]));
1688 Exit;
1689 end;
1691 MC_SEND_FullStateRequest;
1692 end;
1694 NET_EV_MAPEND:
1695 begin
1696 gMissionFailed := EvNum <> 0;
1697 gExit := EXIT_ENDLEVELCUSTOM;
1698 end;
1700 NET_EV_RCON:
1701 begin
1702 case EvNum of
1703 NET_RCON_NOAUTH:
1704 g_Console_Add(_lc[I_NET_RCON_NOAUTH], True);
1705 NET_RCON_PWGOOD:
1706 g_Console_Add(_lc[I_NET_RCON_PWD_VALID], True);
1707 NET_RCON_PWBAD:
1708 g_Console_Add(_lc[I_NET_RCON_PWD_INVALID], True);
1709 end;
1710 end;
1712 NET_EV_CHANGE_TEAM:
1713 begin
1714 if EvNum = TEAM_RED then
1715 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True);
1716 if EvNum = TEAM_BLUE then
1717 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True);
1718 end;
1720 NET_EV_PLAYER_KICK:
1721 g_Console_Add(Format(_lc[I_PLAYER_KICK], [EvStr]), True);
1723 NET_EV_PLAYER_BAN:
1724 g_Console_Add(Format(_lc[I_PLAYER_BAN], [EvStr]), True);
1726 NET_EV_LMS_WARMUP:
1727 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [EvNum]), True);
1729 NET_EV_LMS_SURVIVOR:
1730 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True);
1732 NET_EV_BIGTEXT:
1733 g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum));
1735 NET_EV_SCORE:
1736 begin
1737 pl := g_Player_Get(EvNum and $FFFF);
1738 if pl = nil then
1739 pln := '?'
1740 else
1741 pln := pl.Name;
1742 cnt := (EvNum shr 16) and $FF;
1743 if Pos('w', EvStr) = 0 then
1744 begin
1745 // Default score
1746 if Pos('t', EvStr) = 0 then
1747 begin
1748 // Player +/- score
1749 if Pos('-', EvStr) = 0 then
1750 begin
1751 if Pos('e', EvStr) = 0 then
1752 i1 := I_PLAYER_SCORE_ADD_OWN
1753 else
1754 i1 := I_PLAYER_SCORE_ADD_ENEMY;
1755 end else
1756 begin
1757 if Pos('e', EvStr) = 0 then
1758 i1 := I_PLAYER_SCORE_SUB_OWN
1759 else
1760 i1 := I_PLAYER_SCORE_SUB_ENEMY;
1761 end;
1762 // Which team
1763 if Pos('r', EvStr) > 0 then
1764 i2 := I_PLAYER_SCORE_TO_RED
1765 else
1766 i2 := I_PLAYER_SCORE_TO_BLUE;
1767 g_Console_Add(Format(_lc[i1], [pln, cnt, _lc[i2]]), True);
1768 end else
1769 begin
1770 // Team +/- score
1771 if Pos('-', EvStr) = 0 then
1772 i1 := I_PLAYER_SCORE_ADD_TEAM
1773 else
1774 i1 := I_PLAYER_SCORE_SUB_TEAM;
1775 // Which team
1776 if Pos('r', EvStr) > 0 then
1777 i2 := I_PLAYER_SCORE_RED
1778 else
1779 i2 := I_PLAYER_SCORE_BLUE;
1780 g_Console_Add(Format(_lc[i1], [_lc[i2], cnt]), True);
1781 end;
1782 end else
1783 begin
1784 // Game Win
1785 if Pos('e', EvStr) = 0 then
1786 i1 := I_PLAYER_SCORE_WIN_OWN
1787 else
1788 i1 := I_PLAYER_SCORE_WIN_ENEMY;
1789 // Which team
1790 if Pos('r', EvStr) > 0 then
1791 i2 := I_PLAYER_SCORE_TO_RED
1792 else
1793 i2 := I_PLAYER_SCORE_TO_BLUE;
1794 g_Console_Add(Format(_lc[i1], [pln, _lc[i2]]), True);
1795 end;
1796 end;
1798 NET_EV_SCORE_MSG:
1799 begin
1800 if EvNum = TEAM_RED then
1801 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1802 if EvNum = TEAM_BLUE then
1803 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1804 if EvNum = -TEAM_RED then
1805 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1806 if EvNum = -TEAM_BLUE then
1807 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1808 end;
1810 NET_EV_LMS_START:
1811 begin
1812 g_Player_RemoveAllCorpses;
1813 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
1814 end;
1816 NET_EV_LMS_WIN:
1817 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(EvStr)]), 144);
1819 NET_EV_TLMS_WIN:
1820 begin
1821 if EvNum = TEAM_RED then
1822 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
1823 if EvNum = TEAM_BLUE then
1824 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
1825 end;
1827 NET_EV_LMS_LOSE:
1828 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
1830 NET_EV_LMS_DRAW:
1831 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
1833 NET_EV_KILLCOMBO:
1834 g_Game_Announce_KillCombo(EvNum);
1836 NET_EV_PLAYER_TOUCH:
1837 begin
1838 pl := g_Player_Get(EvNum);
1839 if pl <> nil then
1840 pl.Touch();
1841 end;
1843 end;
1844 end;
1846 procedure MC_RECV_FlagEvent(var M: TMsg);
1847 var
1848 PID: Word;
1849 Pl: TPlayer;
1850 EvType: Byte;
1851 Fl: Byte;
1852 Quiet: Boolean;
1853 s, ts: string;
1854 begin
1855 EvType := M.ReadByte();
1856 Fl := M.ReadByte();
1858 if Fl = FLAG_NONE then Exit;
1860 Quiet := (M.ReadByte() <> 0);
1861 PID := M.ReadWord();
1863 gFlags[Fl].State := M.ReadByte();
1864 gFlags[Fl].CaptureTime := M.ReadLongWord();
1865 gFlags[Fl].Obj.X := M.ReadLongInt();
1866 gFlags[Fl].Obj.Y := M.ReadLongInt();
1867 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
1868 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
1870 Pl := g_Player_Get(PID);
1871 if (Pl = nil) and
1872 (EvType <> FLAG_STATE_NORMAL) and
1873 (EvType <> FLAG_STATE_DROPPED) and
1874 (EvType <> FLAG_STATE_RETURNED) then
1875 Exit;
1877 case EvType of
1878 FLAG_STATE_NORMAL:
1879 begin
1880 if Quiet or (Pl = nil) then Exit;
1882 if Fl = FLAG_RED then
1883 s := _lc[I_PLAYER_FLAG_RED]
1884 else
1885 s := _lc[I_PLAYER_FLAG_BLUE];
1887 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
1888 end;
1890 FLAG_STATE_CAPTURED:
1891 begin
1892 if (Pl <> nil) then Pl.SetFlag(Fl);
1894 if Quiet then Exit;
1896 if Fl = FLAG_RED then
1897 s := _lc[I_PLAYER_FLAG_RED]
1898 else
1899 s := _lc[I_PLAYER_FLAG_BLUE];
1901 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [Pl.Name, s]), True);
1902 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
1903 end;
1905 FLAG_STATE_DROPPED:
1906 begin
1907 if (Pl <> nil) then Pl.SetFlag(FLAG_NONE);
1909 if Quiet or (Pl = nil) then Exit;
1911 if Fl = FLAG_RED then
1912 s := _lc[I_PLAYER_FLAG_RED]
1913 else
1914 s := _lc[I_PLAYER_FLAG_BLUE];
1916 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [Pl.Name, s]), True);
1917 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
1918 end;
1920 FLAG_STATE_SCORED:
1921 begin
1922 g_Map_ResetFlag(FLAG_RED);
1923 g_Map_ResetFlag(FLAG_BLUE);
1924 if Quiet or (Pl = nil) then Exit;
1925 Pl.SetFlag(FLAG_NONE);
1927 if Fl = FLAG_RED then
1928 s := _lc[I_PLAYER_FLAG_RED]
1929 else
1930 s := _lc[I_PLAYER_FLAG_BLUE];
1932 ts := Format('%.4d', [gFlags[Fl].CaptureTime]);
1933 Insert('.', ts, Length(ts) + 1 - 3);
1934 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [Pl.Name, s, ts]), True);
1935 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
1936 end;
1938 FLAG_STATE_RETURNED:
1939 begin
1940 g_Map_ResetFlag(Fl);
1941 if Quiet then Exit;
1943 if Fl = FLAG_RED then
1944 s := _lc[I_PLAYER_FLAG_RED]
1945 else
1946 s := _lc[I_PLAYER_FLAG_BLUE];
1948 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
1949 end;
1950 end;
1951 end;
1953 procedure MC_RECV_GameSettings(var M: TMsg);
1954 begin
1955 gGameSettings.GameMode := M.ReadByte();
1956 gGameSettings.GoalLimit := M.ReadWord();
1957 gGameSettings.TimeLimit := M.ReadWord();
1958 gGameSettings.MaxLives := M.ReadByte();
1959 gGameSettings.Options := M.ReadLongWord();
1960 end;
1962 // PLAYER
1964 function MC_RECV_PlayerCreate(var M: TMsg): Word;
1965 var
1966 PID, DID: Word;
1967 PName, Model: string;
1968 Color: TRGB;
1969 T: Byte;
1970 Pl: TPlayer;
1971 begin
1972 PID := M.ReadWord();
1973 Pl := g_Player_Get(PID);
1975 PName := M.ReadString();
1976 Model := M.ReadString();
1977 Color.R := M.ReadByte();
1978 Color.G := M.ReadByte();
1979 Color.B := M.ReadByte();
1980 T := M.ReadByte();
1982 Result := 0;
1983 if (PID <> NetPlrUID1) and (PID <> NetPlrUID2) then
1984 begin
1985 if (Pl <> nil) then Exit;
1986 DID := g_Player_Create(Model, Color, T, False);
1987 with g_Player_Get(DID) do
1988 begin
1989 UID := PID;
1990 Name := PName;
1991 Reset(True);
1992 end;
1993 end
1994 else
1995 begin
1996 if (PID = NetPlrUID1) and (gPlayer1 <> nil) then begin
1997 gPlayer1.UID := PID;
1998 gPlayer1.Model.SetColor(Color.R, Color.G, Color.B);
1999 gPlayer1.ChangeTeam(T);
2000 end;
2001 if (PID = NetPlrUID2) and (gPlayer2 <> nil) then begin
2002 gPlayer2.UID := PID;
2003 gPlayer2.Model.SetColor(Color.R, Color.G, Color.B);
2004 gPlayer2.ChangeTeam(T);
2005 end;
2006 end;
2008 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
2009 e_WriteLog('NET: Player ' + PName + ' [' + IntToStr(PID) + '] added.', TMsgType.Notify);
2010 Result := PID;
2011 end;
2013 function MC_RECV_PlayerPos(var M: TMsg): Word;
2014 var
2015 GT: LongWord;
2016 PID: Word;
2017 kByte: Word;
2018 Pl: TPlayer;
2019 Dir: Byte;
2020 TmpX, TmpY: Integer;
2021 begin
2022 Result := 0;
2024 GT := M.ReadLongWord();
2025 if GT < gTime - NET_MAX_DIFFTIME then
2026 begin
2027 gTime := GT;
2028 Exit;
2029 end;
2030 gTime := GT;
2032 PID := M.ReadWord();
2033 Pl := g_Player_Get(PID);
2035 if Pl = nil then Exit;
2037 Result := PID;
2039 with Pl do
2040 begin
2041 FPing := M.ReadWord();
2042 FLoss := M.ReadByte();
2043 kByte := M.ReadWord();
2044 Dir := M.ReadByte();
2046 TmpX := M.ReadLongInt();
2047 TmpY := M.ReadLongInt();
2049 ReleaseKeys;
2051 if (kByte = NET_KEY_CHAT) then
2052 PressKey(KEY_CHAT, 10000)
2053 else
2054 begin
2055 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
2056 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
2057 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
2058 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
2059 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
2060 end;
2062 if ((Pl <> gPlayer1) and (Pl <> gPlayer2)) or LongBool(kByte and NET_KEY_FORCEDIR) then
2063 SetDirection(TDirection(Dir));
2065 GameVelX := M.ReadLongInt();
2066 GameVelY := M.ReadLongInt();
2067 GameAccelX := M.ReadLongInt();
2068 GameAccelY := M.ReadLongInt();
2069 SetLerp(TmpX, TmpY);
2070 if NetForcePlayerUpdate then Update();
2071 end;
2072 end;
2074 function MC_RECV_PlayerStats(var M: TMsg): Word;
2075 var
2076 PID: Word;
2077 Pl: TPlayer;
2078 I: Integer;
2079 OldJet: Boolean;
2080 NewTeam: Byte;
2081 ww: Word;
2082 begin
2083 PID := M.ReadWord();
2084 Pl := g_Player_Get(PID);
2085 Result := 0;
2086 if Pl = nil then
2087 Exit;
2089 with Pl do
2090 begin
2091 alive := (M.ReadByte() <> 0);
2092 GodMode := (M.ReadByte() <> 0);
2093 Health := M.ReadLongInt();
2094 Armor := M.ReadLongInt();
2095 Air := M.ReadLongInt();
2096 JetFuel := M.ReadLongInt();
2097 Lives := M.ReadByte();
2098 NewTeam := M.ReadByte();
2100 ww := M.ReadWord();
2101 for I := WP_FIRST to WP_LAST do
2102 begin
2103 FWeapon[I] := ((ww and $01) <> 0);
2104 ww := ww shr 1;
2105 end;
2107 for I := A_BULLETS to A_HIGH do
2108 FAmmo[I] := M.ReadWord();
2110 for I := A_BULLETS to A_HIGH do
2111 FMaxAmmo[I] := M.ReadWord();
2113 for I := MR_SUIT to MR_MAX do
2114 FMegaRulez[I] := M.ReadLongWord();
2116 FRulez := [];
2117 // unpack special flags
2118 ww := M.ReadByte();
2119 if ((ww and $01) <> 0) then FRulez := FRulez+[R_ITEM_BACKPACK];
2120 if ((ww and $02) <> 0) then FRulez := FRulez+[R_KEY_RED];
2121 if ((ww and $04) <> 0) then FRulez := FRulez+[R_KEY_GREEN];
2122 if ((ww and $08) <> 0) then FRulez := FRulez+[R_KEY_BLUE];
2123 if ((ww and $10) <> 0) then FRulez := FRulez+[R_BERSERK];
2125 Frags := M.ReadLongInt();
2126 Death := M.ReadLongInt();
2128 SetWeapon(M.ReadByte());
2130 // other flags
2131 ww := M.ReadByte();
2133 FSpectator := ((ww and $01) <> 0);
2134 if FSpectator then
2135 begin
2136 if Pl = gPlayer1 then
2137 begin
2138 gLMSPID1 := UID;
2139 gPlayer1 := nil;
2140 end;
2141 if Pl = gPlayer2 then
2142 begin
2143 gLMSPID2 := UID;
2144 gPlayer2 := nil;
2145 end;
2146 end
2147 else
2148 begin
2149 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
2150 gPlayer1 := g_Player_Get(gLMSPID1);
2151 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
2152 gPlayer2 := g_Player_Get(gLMSPID2);
2153 end;
2155 FGhost := ((ww and $02) <> 0);
2156 FPhysics := ((ww and $04) <> 0);
2157 FNoRespawn := ((ww and $08) <> 0);
2158 OldJet := FJetpack;
2159 FJetpack := ((ww and $10) <> 0);
2160 FFireTime := M.ReadLongInt();
2161 if OldJet and not FJetpack then
2162 JetpackOff
2163 else if not OldJet and FJetpack then
2164 JetpackOn;
2165 if Team <> NewTeam then
2166 Pl.ChangeTeam(NewTeam);
2167 end;
2169 Result := PID;
2170 end;
2172 function MC_RECV_PlayerDamage(var M: TMsg): Word;
2173 var
2174 PID: Word;
2175 Pl: TPlayer;
2176 Kind: Byte;
2177 Attacker, Value: Word;
2178 VX, VY: Integer;
2179 begin
2180 Result := 0;
2181 if not gGameOn then Exit;
2182 PID := M.ReadWord();
2183 Pl := g_Player_Get(PID);
2184 if Pl = nil then Exit;
2186 Kind := M.ReadByte();
2187 Attacker := M.ReadWord();
2188 Value := M.ReadWord();
2189 VX := M.ReadWord();
2190 VY := M.ReadWord();
2192 with Pl do
2193 Damage(Value, Attacker, VX, VY, Kind);
2195 Result := PID;
2196 end;
2198 function MC_RECV_PlayerDeath(var M: TMsg): Word;
2199 var
2200 PID: Word;
2201 Pl: TPlayer;
2202 KillType, DeathType: Byte;
2203 Attacker: Word;
2204 begin
2205 Result := 0;
2206 if not gGameOn then Exit;
2207 PID := M.ReadWord();
2208 Pl := g_Player_Get(PID);
2209 if Pl = nil then Exit;
2211 KillType := M.ReadByte();
2212 DeathType := M.ReadByte();
2213 Attacker := M.ReadWord();
2215 with Pl do
2216 begin
2217 Kill(KillType, Attacker, DeathType);
2218 SoftReset;
2219 end;
2220 end;
2222 function MC_RECV_PlayerDelete(var M: TMsg): Word;
2223 var
2224 PID: Word;
2225 Pl: TPlayer;
2226 begin
2227 PID := M.ReadWord();
2228 Pl := g_Player_Get(PID);
2229 Result := 0;
2230 if Pl = nil then Exit;
2232 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2233 e_WriteLog('NET: Player ' + Pl.Name + ' [' + IntToStr(PID) + '] removed.', TMsgType.Notify);
2235 g_Player_Remove(PID);
2237 Result := PID;
2238 end;
2240 function MC_RECV_PlayerFire(var M: TMsg): Word;
2241 var
2242 PID: Word;
2243 Weap: Byte;
2244 Pl: TPlayer;
2245 X, Y, AX, AY: Integer;
2246 SHID: Integer;
2247 begin
2248 Result := 0;
2249 if not gGameOn then Exit;
2250 PID := M.ReadWord();
2251 Pl := g_Player_Get(PID);
2252 if Pl = nil then Exit;
2254 Weap := M.ReadByte();
2255 X := M.ReadLongInt();
2256 Y := M.ReadLongInt();
2257 AX := M.ReadLongInt();
2258 AY := M.ReadLongInt();
2259 SHID := M.ReadLongInt();
2261 with Pl do
2262 if alive then NetFire(Weap, X, Y, AX, AY, SHID);
2263 end;
2265 procedure MC_RECV_PlayerSettings(var M: TMsg);
2266 var
2267 TmpName: string;
2268 TmpModel: string;
2269 TmpColor: TRGB;
2270 TmpTeam: Byte;
2271 Pl: TPlayer;
2272 PID: Word;
2273 begin
2274 PID := M.ReadWord();
2275 Pl := g_Player_Get(PID);
2276 if Pl = nil then Exit;
2278 TmpName := M.ReadString();
2279 TmpModel := M.ReadString();
2280 TmpColor.R := M.ReadByte();
2281 TmpColor.G := M.ReadByte();
2282 TmpColor.B := M.ReadByte();
2283 TmpTeam := M.ReadByte();
2285 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
2286 begin
2287 Pl.ChangeTeam(TmpTeam);
2288 if gPlayer1 = Pl then
2289 gPlayer1Settings.Team := TmpTeam;
2290 if gPlayer2 = Pl then
2291 gPlayer2Settings.Team := TmpTeam;
2292 end else
2293 Pl.SetColor(TmpColor);
2295 if Pl.Name <> TmpName then
2296 begin
2297 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
2298 Pl.Name := TmpName;
2299 end;
2301 if TmpModel <> Pl.Model.Name then
2302 Pl.SetModel(TmpModel);
2303 end;
2305 // ITEM
2307 procedure MC_RECV_ItemSpawn(var M: TMsg);
2308 var
2309 ID: Word;
2310 AID: DWord;
2311 X, Y, VX, VY: Integer;
2312 T: Byte;
2313 Quiet, Fall{, Resp}: Boolean;
2314 Anim: TAnimation;
2315 it: PItem;
2316 begin
2317 if not gGameOn then Exit;
2318 ID := M.ReadWord();
2319 Quiet := M.ReadByte() <> 0;
2320 T := M.ReadByte();
2321 Fall := M.ReadByte() <> 0;
2322 {Resp :=} M.ReadByte();
2323 X := M.ReadLongInt();
2324 Y := M.ReadLongInt();
2325 VX := M.ReadLongInt();
2326 VY := M.ReadLongInt();
2328 g_Items_Create(X, Y, T and $7F, Fall, False, False, ID);
2329 if ((T and $80) <> 0) then g_Items_SetDrop(ID);
2331 it := g_Items_ByIdx(ID);
2332 it.Obj.Vel.X := VX;
2333 it.Obj.Vel.Y := VY;
2335 if not Quiet then
2336 begin
2337 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
2338 if g_Frames_Get(AID, 'FRAMES_ITEM_RESPAWN') then
2339 begin
2340 Anim := TAnimation.Create(AID, False, 4);
2341 g_GFX_OnceAnim(X+(it.Obj.Rect.Width div 2)-16, Y+(it.Obj.Rect.Height div 2)-16, Anim);
2342 Anim.Free();
2343 end;
2344 end;
2345 end;
2347 procedure MC_RECV_ItemDestroy(var M: TMsg);
2348 var
2349 ID: Word;
2350 Quiet: Boolean;
2351 begin
2352 if not gGameOn then Exit;
2353 ID := M.ReadWord();
2354 Quiet := M.ReadByte() <> 0;
2356 if not g_Items_ValidId(ID) then exit;
2358 if not Quiet then g_Items_EmitPickupSound(ID);
2360 g_Items_Remove(ID);
2361 end;
2363 // PANEL
2365 procedure MC_RECV_PanelTexture(var M: TMsg);
2366 var
2367 TP: TPanel;
2368 PGUID: Integer;
2369 Tex, Fr: Integer;
2370 Loop, Cnt: Byte;
2371 begin
2372 if not gGameOn then Exit;
2374 PGUID := Integer(M.ReadLongWord());
2375 Tex := M.ReadLongInt();
2376 Fr := M.ReadLongInt();
2377 Cnt := M.ReadByte();
2378 Loop := M.ReadByte();
2380 TP := g_Map_PanelByGUID(PGUID);
2381 if (TP <> nil) then
2382 begin
2383 // switch texture
2384 TP.SetTexture(Tex, Loop);
2385 TP.SetFrame(Fr, Cnt);
2386 end;
2387 end;
2389 procedure MC_RECV_PanelState(var M: TMsg);
2390 var
2391 PGUID: Integer;
2392 E: Boolean;
2393 Lift: Byte;
2394 X, Y, W, H: Integer;
2395 TP: TPanel;
2396 speedX, speedY, startX, startY, endX, endY: Integer;
2397 sizeSpX, sizeSpY, sizeEX, sizeEY: Integer;
2398 mpflags: Byte;
2399 begin
2400 if not gGameOn then Exit;
2402 PGUID := Integer(M.ReadLongWord());
2403 E := (M.ReadByte() <> 0);
2404 Lift := M.ReadByte();
2405 X := M.ReadLongInt();
2406 Y := M.ReadLongInt();
2407 W := M.ReadWord();
2408 H := M.ReadWord();
2409 // mplats
2410 speedX := M.ReadLongInt();
2411 speedY := M.ReadLongInt();
2412 startX := M.ReadLongInt();
2413 startY := M.ReadLongInt();
2414 endX := M.ReadLongInt();
2415 endY := M.ReadLongInt();
2416 sizeSpX := M.ReadLongInt();
2417 sizeSpY := M.ReadLongInt();
2418 sizeEX := M.ReadLongInt();
2419 sizeEY := M.ReadLongInt();
2420 mpflags := M.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2422 TP := g_Map_PanelByGUID(PGUID);
2423 if (TP = nil) then exit;
2425 // update lifts state
2426 if TP.isGLift then g_Map_SetLiftGUID(PGUID, Lift);
2428 // update enabled/disabled state for all panels
2429 if E then g_Map_EnableWallGUID(PGUID) else g_Map_DisableWallGUID(PGUID);
2431 // update panel position, as it can be moved (mplat)
2432 TP.X := X;
2433 TP.Y := Y;
2434 TP.Width := W;
2435 TP.Height := H;
2436 // update mplat state
2437 TP.movingSpeedX := speedX;
2438 TP.movingSpeedY := speedY;
2439 TP.movingStartX := startX;
2440 TP.movingStartY := startY;
2441 TP.movingEndX := endX;
2442 TP.movingEndY := endY;
2443 TP.sizeSpeedX := sizeSpX;
2444 TP.sizeSpeedY := sizeSpY;
2445 TP.sizeEndX := sizeEX;
2446 TP.sizeEndY := sizeEY;
2447 TP.movingActive := ((mpflags and 1) <> 0);
2448 TP.moveOnce := ((mpflags and 2) <> 0);
2449 // notify panel of it's position/size change, so it can fix other internal structures
2450 TP.positionChanged();
2451 end;
2453 // TRIGGERS
2455 procedure MC_RECV_TriggerSound(var M: TMsg);
2456 var
2457 SPlaying: Boolean;
2458 SPos, SID: LongWord;
2459 SCount: LongInt;
2460 I: Integer;
2461 begin
2462 if not gGameOn then Exit;
2463 if gTriggers = nil then Exit;
2465 SID := M.ReadLongWord();
2466 SPlaying := M.ReadByte() <> 0;
2467 SPos := M.ReadLongWord();
2468 SCount := M.ReadLongInt();
2470 for I := Low(gTriggers) to High(gTriggers) do
2471 if gTriggers[I].TriggerType = TRIGGER_SOUND then
2472 if gTriggers[I].ClientID = SID then
2473 with gTriggers[I] do
2474 begin
2475 if Sound <> nil then
2476 begin
2477 if SPlaying then
2478 begin
2479 if tgcLocal then
2480 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), tgcVolume/255.0)
2481 else
2482 Sound.PlayPanVolume((tgcPan-127.0)/128.0, tgcVolume/255.0);
2483 Sound.SetPosition(SPos);
2484 end
2485 else
2486 if Sound.IsPlaying then Sound.Stop;
2487 end;
2489 SoundPlayCount := SCount;
2490 end;
2491 end;
2493 procedure MC_RECV_TriggerMusic(var M: TMsg);
2494 var
2495 MName: string;
2496 MPlaying: Boolean;
2497 MPos: LongWord;
2498 MPaused: Boolean;
2499 begin
2500 if not gGameOn then Exit;
2502 MName := M.ReadString();
2503 MPlaying := M.ReadByte() <> 0;
2504 MPos := M.ReadLongWord();
2505 MPaused := M.ReadByte() <> 0;
2507 if MPlaying then
2508 begin
2509 gMusic.SetByName(MName);
2510 gMusic.Play(True);
2511 gMusic.SetPosition(MPos);
2512 gMusic.SpecPause := MPaused;
2513 end
2514 else
2515 if gMusic.IsPlaying then gMusic.Stop;
2516 end;
2518 // MONSTERS
2520 procedure MC_RECV_MonsterSpawn(var M: TMsg);
2521 var
2522 ID: Word;
2523 MType, MState, MDir, MAnim, MBehav: Byte;
2524 X, Y, VX, VY, MTargTime, MHealth, MAmmo, MSleep: Integer;
2525 MTarg: Word;
2526 Mon: TMonster;
2527 begin
2528 ID := M.ReadWord();
2529 Mon := g_Monsters_ByUID(ID);
2530 if Mon <> nil then
2531 Exit;
2533 MType := M.ReadByte();
2534 MState := M.ReadByte();
2535 MAnim := M.ReadByte();
2536 MTarg := M.ReadWord();
2537 MTargTime := M.ReadLongInt();
2538 MBehav := M.ReadByte();
2539 MSleep := M.ReadLongInt();
2540 MHealth := M.ReadLongInt();
2541 MAmmo := M.ReadLongInt();
2543 X := M.ReadLongInt();
2544 Y := M.ReadLongInt();
2545 VX := M.ReadLongInt();
2546 VY := M.ReadLongInt();
2547 MDir := M.ReadByte();
2549 g_Monsters_Create(MType, X, Y, TDirection(MDir), False, ID);
2550 Mon := g_Monsters_ByUID(ID);
2551 if Mon = nil then
2552 Exit;
2554 with Mon do
2555 begin
2557 MonsterAnim := MAnim;
2558 MonsterTargetUID := MTarg;
2559 MonsterTargetTime := MTargTime;
2560 MonsterBehaviour := MBehav;
2561 MonsterSleep := MSleep;
2562 MonsterAmmo := MAmmo;
2563 SetHealth(MHealth);
2565 SetState(MState);
2567 setPosition(X, Y); // this will call positionChanged();
2568 GameVelX := VX;
2569 GameVelY := VY;
2570 end;
2571 end;
2573 procedure MC_RECV_MonsterPos(var M: TMsg);
2574 var
2575 Mon: TMonster;
2576 ID: Word;
2577 X, Y: Integer;
2578 begin
2579 ID := M.ReadWord();
2580 Mon := g_Monsters_ByUID(ID);
2581 if Mon = nil then
2582 Exit;
2584 with Mon do
2585 begin
2586 X := M.ReadLongInt();
2587 Y := M.ReadLongInt();
2588 Mon.setPosition(X, Y); // this will call `positionChanged()`
2589 GameVelX := M.ReadLongInt();
2590 GameVelY := M.ReadLongInt();
2591 GameDirection := TDirection(M.ReadByte());
2592 end;
2593 end;
2595 procedure MC_RECV_MonsterState(var M: TMsg);
2596 var
2597 ID: Integer;
2598 MState, MFAnm: Byte;
2599 Mon: TMonster;
2600 AnimRevert: Boolean;
2601 begin
2602 ID := M.ReadWord();
2603 Mon := g_Monsters_ByUID(ID);
2604 if Mon = nil then Exit;
2606 MState := M.ReadByte();
2607 MFAnm := M.ReadByte();
2609 with Mon do
2610 begin
2611 MonsterTargetUID := M.ReadWord();
2612 MonsterTargetTime := M.ReadLongInt();
2613 MonsterSleep := M.ReadLongInt();
2614 MonsterHealth := M.ReadLongInt();
2615 MonsterAmmo := M.ReadLongInt();
2616 MonsterPain := M.ReadLongInt();
2617 AnimRevert := M.ReadByte() <> 0;
2618 FFireTime := M.ReadLongInt();
2619 RevertAnim(AnimRevert);
2621 if MonsterState <> MState then
2622 begin
2623 if (MState = MONSTATE_GO) and (MonsterState = MONSTATE_SLEEP) then WakeUpSound();
2624 if (MState = MONSTATE_DIE) then DieSound();
2625 if (MState = MONSTATE_PAIN) then MakeBloodSimple(Min(200, MonsterPain));
2626 if (MState = MONSTATE_ATTACK) then kick(nil);
2627 if (MState = MONSTATE_DEAD) then SetDeadAnim();
2629 SetState(MState, MFAnm);
2630 end;
2631 end;
2632 end;
2634 procedure MC_RECV_MonsterShot(var M: TMsg);
2635 var
2636 ID: Integer;
2637 Mon: TMonster;
2638 X, Y, VX, VY: Integer;
2639 begin
2640 ID := M.ReadWord();
2642 Mon := g_Monsters_ByUID(ID);
2643 if Mon = nil then Exit;
2645 X := M.ReadLongInt();
2646 Y := M.ReadLongInt();
2647 VX := M.ReadLongInt();
2648 VY := M.ReadLongInt();
2650 Mon.ClientAttack(X, Y, VX, VY);
2651 end;
2653 procedure MC_RECV_MonsterDelete(var M: TMsg);
2654 var
2655 ID: Integer;
2656 Mon: TMonster;
2657 begin
2658 ID := M.ReadWord();
2659 Mon := g_Monsters_ByUID(ID);
2660 if Mon = nil then Exit;
2661 Mon.SetState(5);
2662 Mon.MonsterRemoved := True;
2663 end;
2665 procedure MC_RECV_TimeSync(var M: TMsg);
2666 var
2667 Time: LongWord;
2668 begin
2669 Time := M.ReadLongWord();
2671 if gState = STATE_INTERCUSTOM then
2672 gServInterTime := Min(Time, 255);
2673 end;
2675 procedure MC_RECV_VoteEvent(var M: TMsg);
2676 var
2677 EvID: Byte;
2678 Str1, Str2: string;
2679 Int1, Int2: SmallInt;
2680 begin
2681 EvID := M.ReadByte();
2682 Int1 := M.ReadSmallInt();
2683 Int2 := M.ReadSmallInt();
2684 Str1 := M.ReadString();
2685 Str2 := M.ReadString();
2687 case EvID of
2688 NET_VE_STARTED:
2689 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True);
2690 NET_VE_PASSED:
2691 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True);
2692 NET_VE_FAILED:
2693 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
2694 NET_VE_VOTE:
2695 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True);
2696 NET_VE_INPROGRESS:
2697 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True);
2698 end;
2699 end;
2701 // CLIENT SEND
2703 procedure MC_SEND_Info(Password: string);
2704 begin
2705 NetOut.Clear();
2707 NetOut.Write(Byte(NET_MSG_INFO));
2708 NetOut.Write(GAME_VERSION);
2709 NetOut.Write(Password);
2710 NetOut.Write(gPlayer1Settings.Name);
2711 NetOut.Write(gPlayer1Settings.Model);
2712 NetOut.Write(gPlayer1Settings.Color.R);
2713 NetOut.Write(gPlayer1Settings.Color.G);
2714 NetOut.Write(gPlayer1Settings.Color.B);
2715 NetOut.Write(gPlayer1Settings.Team);
2717 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2718 end;
2720 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
2721 begin
2722 NetOut.Write(Byte(NET_MSG_CHAT));
2723 NetOut.Write(Txt);
2724 NetOut.Write(Mode);
2726 g_Net_Client_Send(True, NET_CHAN_CHAT);
2727 end;
2729 function isKeyPressed (key1: Word; key2: Word): Boolean;
2730 begin
2731 if (key1 <> 0) and e_KeyPressed(key1) then begin result := true; exit; end;
2732 if (key2 <> 0) and e_KeyPressed(key2) then begin result := true; exit; end;
2733 result := false;
2734 end;
2736 procedure MC_SEND_PlayerPos();
2737 var
2738 kByte: Word;
2739 Predict: Boolean;
2740 strafeDir: Byte;
2741 WeaponSelect: Word = 0;
2742 I: Integer;
2743 begin
2744 if not gGameOn then Exit;
2745 if gPlayers = nil then Exit;
2746 if gPlayer1 = nil then Exit;
2748 kByte := 0;
2749 Predict := NetPredictSelf; // and (not NetGotKeys);
2751 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2752 begin
2753 strafeDir := P1MoveButton shr 4;
2754 P1MoveButton := P1MoveButton and $0F;
2755 with gGameControls.P1Control do
2756 begin
2757 if isKeyPressed(KeyLeft, KeyLeft2) and (not isKeyPressed(KeyRight, KeyRight2)) then P1MoveButton := 1
2758 else if (not isKeyPressed(KeyLeft, KeyLeft2)) and isKeyPressed(KeyRight, KeyRight2) then P1MoveButton := 2
2759 else if (not isKeyPressed(KeyLeft, KeyLeft2)) and (not isKeyPressed(KeyRight, KeyRight2)) then P1MoveButton := 0;
2761 // strafing
2762 if isKeyPressed(KeyStrafe, KeyStrafe2) then
2763 begin
2764 // new strafe mechanics
2765 if (strafeDir = 0) then strafeDir := P1MoveButton; // start strafing
2766 // now set direction according to strafe (reversed)
2767 if (strafeDir = 2) then gPlayer1.SetDirection(TDirection.D_LEFT)
2768 else if (strafeDir = 1) then gPlayer1.SetDirection(TDirection.D_RIGHT);
2769 end
2770 else
2771 begin
2772 if (P1MoveButton = 2) and isKeyPressed(KeyLeft, KeyLeft2) then gPlayer1.SetDirection(TDirection.D_LEFT)
2773 else if (P1MoveButton = 1) and isKeyPressed(KeyRight, KeyRight2) then gPlayer1.SetDirection(TDirection.D_RIGHT)
2774 else if P1MoveButton <> 0 then gPlayer1.SetDirection(TDirection(P1MoveButton-1));
2775 end;
2777 gPlayer1.ReleaseKeys;
2778 gPlayer1.weaponSwitchKeysStateChange(-1, isKeyPressed(KeyNextWeapon, KeyNextWeapon2));
2779 gPlayer1.weaponSwitchKeysStateChange(-2, isKeyPressed(KeyPrevWeapon, KeyPrevWeapon2));
2781 if P1MoveButton = 1 then
2782 begin
2783 kByte := kByte or NET_KEY_LEFT;
2784 if Predict then gPlayer1.PressKey(KEY_LEFT, 10000);
2785 end;
2786 if P1MoveButton = 2 then
2787 begin
2788 kByte := kByte or NET_KEY_RIGHT;
2789 if Predict then gPlayer1.PressKey(KEY_RIGHT, 10000);
2790 end;
2791 if isKeyPressed(KeyUp, KeyUp2) then
2792 begin
2793 kByte := kByte or NET_KEY_UP;
2794 gPlayer1.PressKey(KEY_UP, 10000);
2795 end;
2796 if isKeyPressed(KeyDown, KeyDown2) then
2797 begin
2798 kByte := kByte or NET_KEY_DOWN;
2799 gPlayer1.PressKey(KEY_DOWN, 10000);
2800 end;
2801 if isKeyPressed(KeyJump, KeyJump2) then
2802 begin
2803 kByte := kByte or NET_KEY_JUMP;
2804 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2805 end;
2806 if isKeyPressed(KeyFire, KeyFire2) then kByte := kByte or NET_KEY_FIRE;
2807 if isKeyPressed(KeyOpen, KeyOpen2) then kByte := kByte or NET_KEY_OPEN;
2808 if isKeyPressed(KeyNextWeapon, KeyNextWeapon2) and gPlayer1.isWeaponSwitchKeyReleased(-1) then kByte := kByte or NET_KEY_NW;
2809 if isKeyPressed(KeyPrevWeapon, KeyPrevWeapon2) and gPlayer1.isWeaponSwitchKeyReleased(-2) then kByte := kByte or NET_KEY_PW;
2810 for I := 0 to High(KeyWeapon) do
2811 begin
2812 if isKeyPressed(KeyWeapon[I], KeyWeapon2[I]) then
2813 begin
2814 gPlayer1.weaponSwitchKeysStateChange(i, true);
2815 if gPlayer1.isWeaponSwitchKeyReleased(i) then WeaponSelect := WeaponSelect or Word(1 shl I);
2816 end
2817 else
2818 begin
2819 gPlayer1.weaponSwitchKeysStateChange(i, false);
2820 end;
2821 end;
2822 end;
2823 // fix movebutton state
2824 P1MoveButton := P1MoveButton or (strafeDir shl 4);
2825 end
2826 else
2827 kByte := NET_KEY_CHAT;
2829 gPlayer1.weaponSwitchKeysShiftNewStates();
2831 NetOut.Write(Byte(NET_MSG_PLRPOS));
2832 NetOut.Write(gTime);
2833 NetOut.Write(kByte);
2834 NetOut.Write(Byte(gPlayer1.Direction));
2835 NetOut.Write(WeaponSelect);
2836 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2837 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS);
2839 //kBytePrev := kByte;
2840 //kDirPrev := gPlayer1.Direction;
2841 end;
2843 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
2844 begin
2845 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
2846 NetOut.Write(Byte(Start));
2847 NetOut.Write(Command);
2848 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2849 end;
2851 procedure MC_SEND_PlayerSettings();
2852 begin
2853 NetOut.Write(Byte(NET_MSG_PLRSET));
2854 NetOut.Write(gPlayer1Settings.Name);
2855 NetOut.Write(gPlayer1Settings.Model);
2856 NetOut.Write(gPlayer1Settings.Color.R);
2857 NetOut.Write(gPlayer1Settings.Color.G);
2858 NetOut.Write(gPlayer1Settings.Color.B);
2859 NetOut.Write(gPlayer1Settings.Team);
2861 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2862 end;
2864 procedure MC_SEND_FullStateRequest();
2865 begin
2866 NetOut.Write(Byte(NET_MSG_REQFST));
2868 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2869 end;
2871 procedure MC_SEND_CheatRequest(Kind: Byte);
2872 begin
2873 NetOut.Write(Byte(NET_MSG_CHEAT));
2874 NetOut.Write(Kind);
2876 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2877 end;
2878 procedure MC_SEND_RCONPassword(Password: string);
2879 begin
2880 NetOut.Write(Byte(NET_MSG_RCON_AUTH));
2881 NetOut.Write(Password);
2883 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2884 end;
2885 procedure MC_SEND_RCONCommand(Cmd: string);
2886 begin
2887 NetOut.Write(Byte(NET_MSG_RCON_CMD));
2888 NetOut.Write(Cmd);
2890 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2891 end;
2893 // i have no idea why all this stuff is in here
2895 function ReadFile(const FileName: TFileName): AByte;
2896 var
2897 FileStream : TStream;
2898 fname: string;
2899 begin
2900 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName]), TMsgType.Notify);
2901 fname := findDiskWad(FileName);
2902 if length(fname) = 0 then
2903 begin
2904 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName]), TMsgType.Fatal);
2905 SetLength(Result, 0);
2906 exit;
2907 end;
2908 e_WriteLog(Format('NETWORK: found file "%s"', [fname]), TMsgType.Notify);
2909 Result := nil;
2910 FileStream := openDiskFileRO(fname);
2911 try
2912 if FileStream.Size > 0 then
2913 begin
2914 SetLength(Result, FileStream.Size);
2915 FileStream.Read(Result[0], FileStream.Size);
2916 end;
2917 finally
2918 FileStream.Free;
2919 end;
2920 end;
2922 function CreateMapDataMsg(const FileName: TFileName; ResList: TStringList): TMapDataMsg;
2923 var
2924 i: Integer;
2925 begin
2926 Result.MsgId := NET_MSG_MAP_RESPONSE;
2927 Result.FileData := ReadFile(FileName);
2928 Result.FileSize := Length(Result.FileData);
2930 SetLength(Result.ExternalResources, ResList.Count);
2931 for i:=0 to ResList.Count-1 do
2932 begin
2933 Result.ExternalResources[i].Name := ResList.Strings[i];
2934 Result.ExternalResources[i].md5 := MD5File(GameDir+'/wads/'+ResList.Strings[i]);
2935 end;
2936 end;
2938 procedure ResDataMsgToBytes(var bytes: AByte; const ResData: TResDataMsg);
2939 var
2940 ResultStream: TMemoryStream;
2941 begin
2942 ResultStream := TMemoryStream.Create;
2944 ResultStream.WriteBuffer(ResData.MsgId, SizeOf(ResData.MsgId)); //msgId
2945 ResultStream.WriteBuffer(ResData.FileSize, SizeOf(ResData.FileSize)); //file size
2946 ResultStream.WriteBuffer(ResData.FileData[0], ResData.FileSize); //file data
2948 SetLength(bytes, ResultStream.Size);
2949 ResultStream.Seek(0, soFromBeginning);
2950 ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
2952 ResultStream.Free;
2953 end;
2955 function ResDataFromMsgStream(msgStream: TMemoryStream):TResDataMsg;
2956 begin
2957 msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
2958 msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize));
2959 SetLength(Result.FileData, Result.FileSize);
2960 msgStream.ReadBuffer(Result.FileData[0], Result.FileSize);
2961 end;
2963 procedure MapDataMsgToBytes(var bytes: AByte; const MapDataMsg: TMapDataMsg);
2964 var
2965 ResultStream: TMemoryStream;
2966 resCount: Integer;
2967 begin
2968 resCount := Length(MapDataMsg.ExternalResources);
2970 ResultStream := TMemoryStream.Create;
2972 ResultStream.WriteBuffer(MapDataMsg.MsgId, SizeOf(MapDataMsg.MsgId)); //msgId
2973 ResultStream.WriteBuffer(MapDataMsg.FileSize, SizeOf(MapDataMsg.FileSize)); //file size
2974 ResultStream.WriteBuffer(MapDataMsg.FileData[0], MapDataMsg.FileSize); //file data
2976 ResultStream.WriteBuffer(resCount, SizeOf(resCount)); //res count
2977 ResultStream.WriteBuffer(MapDataMsg.ExternalResources[0], resCount*SizeOf(TExternalResourceInfo)); //res data
2979 SetLength(bytes, ResultStream.Size);
2980 ResultStream.Seek(0, soFromBeginning);
2981 ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
2983 ResultStream.Free;
2984 end;
2986 function MapDataFromMsgStream(msgStream: TMemoryStream):TMapDataMsg;
2987 var
2988 resCount: Integer;
2989 begin
2990 msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
2991 msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize)); //file size
2993 SetLength(Result.FileData, Result.FileSize);
2994 msgStream.ReadBuffer(Result.FileData[0], Result.FileSize); //file data
2996 msgStream.ReadBuffer(resCount, SizeOf(resCount)); //res count
2997 SetLength(Result.ExternalResources, resCount);
2999 msgStream.ReadBuffer(Result.ExternalResources[0], resCount * SizeOf(TExternalResourceInfo)); //res data
3000 end;
3002 function IsValidFileName(const S: String): Boolean;
3003 const
3004 Forbidden: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
3005 var
3006 I: Integer;
3007 begin
3008 Result := S <> '';
3009 for I := 1 to Length(S) do
3010 Result := Result and (not(S[I] in Forbidden));
3011 end;
3013 function IsValidFilePath(const S: String): Boolean;
3014 var
3015 I: Integer;
3016 begin
3017 Result := False;
3018 if not IsValidFileName(S) then exit;
3019 if FileExists(S) then exit;
3020 I := LastDelimiter('\/', S);
3021 if (I > 0) then
3022 if (not DirectoryExists(Copy(S, 1, I-1))) then
3023 exit;
3024 Result := True;
3025 end;
3027 procedure MC_SEND_MapRequest();
3028 begin
3029 NetOut.Write(Byte(NET_MSG_MAP_REQUEST));
3030 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3031 end;
3033 procedure MC_SEND_ResRequest(const resName: AnsiString);
3034 begin
3035 NetOut.Write(Byte(NET_MSG_RES_REQUEST));
3036 NetOut.Write(resName);
3037 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3038 end;
3040 procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
3041 var
3042 payload: AByte;
3043 peer: pENetPeer;
3044 mapDataMsg: TMapDataMsg;
3045 begin
3046 e_WriteLog('NET: Received map request from ' +
3047 DecodeIPV4(C^.Peer.address.host), TMsgType.Notify);
3049 mapDataMsg := CreateMapDataMsg(MapsDir + gGameSettings.WAD, gExternalResources);
3050 peer := NetClients[C^.ID].Peer;
3052 MapDataMsgToBytes(payload, mapDataMsg);
3053 g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
3055 payload := nil;
3056 mapDataMsg.FileData := nil;
3057 mapDataMsg.ExternalResources := nil;
3058 end;
3060 procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
3061 var
3062 payload: AByte;
3063 peer: pENetPeer;
3064 FileName: String;
3065 resDataMsg: TResDataMsg;
3066 begin
3067 FileName := ExtractFileName(M.ReadString());
3068 e_WriteLog('NET: Received res request: ' + FileName +
3069 ' from ' + DecodeIPV4(C^.Peer.address.host), TMsgType.Notify);
3071 if not IsValidFilePath(FileName) then
3072 begin
3073 e_WriteLog('Invalid filename: ' + FileName, TMsgType.Warning);
3074 exit;
3075 end;
3077 peer := NetClients[C^.ID].Peer;
3079 if gExternalResources.IndexOf(FileName) > -1 then
3080 begin
3081 resDataMsg.MsgId := NET_MSG_RES_RESPONSE;
3082 resDataMsg.FileData := ReadFile(GameDir+'/wads/'+FileName);
3083 resDataMsg.FileSize := Length(resDataMsg.FileData);
3085 ResDataMsgToBytes(payload, resDataMsg);
3086 g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
3087 end;
3088 end;
3090 end.