DEADSOFTWARE

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