DEADSOFTWARE

fixed processing of alternate keyset in network games
[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 {$MODE DELPHI}
17 unit g_netmsg;
19 interface
21 uses 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; P: Pointer);
133 procedure MH_RECV_Chat(C: pTNetClient; P: Pointer);
134 procedure MH_RECV_FullStateRequest(C: pTNetClient; P: Pointer);
135 function MH_RECV_PlayerPos(C: pTNetClient; P: Pointer): Word;
136 procedure MH_RECV_PlayerSettings(C: pTNetClient; P: Pointer);
137 procedure MH_RECV_CheatRequest(C: pTNetClient; P: Pointer);
138 procedure MH_RECV_RCONPassword(C: pTNetClient; P: Pointer);
139 procedure MH_RECV_RCONCommand(C: pTNetClient; P: Pointer);
140 procedure MH_RECV_MapRequest(C: pTNetClient; P: Pointer);
141 procedure MH_RECV_ResRequest(C: pTNetClient; P: Pointer);
142 procedure MH_RECV_Vote(C: pTNetClient; P: Pointer);
144 // GAME
145 procedure MH_SEND_Everything(CreatePlayers: Boolean = False; ID: Integer = NET_EVERYONE);
146 procedure MH_SEND_Info(ID: Byte);
147 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
148 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
149 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
150 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
151 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
152 procedure MH_SEND_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
153 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
154 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
155 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
156 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
157 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
158 // PLAYER
159 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
160 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
161 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
162 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
163 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
164 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
165 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
166 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
167 // ITEM
168 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
169 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
170 // PANEL
171 procedure MH_SEND_PanelTexture(PType: Word; PID: LongWord; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
172 procedure MH_SEND_PanelState(PType: Word; PID: LongWord; 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(P: Pointer);
193 procedure MC_RECV_Effect(P: Pointer);
194 procedure MC_RECV_Sound(P: Pointer);
195 procedure MC_RECV_GameStats(P: Pointer);
196 procedure MC_RECV_CoopStats(P: Pointer);
197 procedure MC_RECV_GameEvent(P: Pointer);
198 procedure MC_RECV_FlagEvent(P: Pointer);
199 procedure MC_RECV_GameSettings(P: Pointer);
200 // PLAYER
201 function MC_RECV_PlayerCreate(P: Pointer): Word;
202 function MC_RECV_PlayerPos(P: Pointer): Word;
203 function MC_RECV_PlayerStats(P: Pointer): Word;
204 function MC_RECV_PlayerDelete(P: Pointer): Word;
205 function MC_RECV_PlayerDamage(P: Pointer): Word;
206 function MC_RECV_PlayerDeath(P: Pointer): Word;
207 function MC_RECV_PlayerFire(P: Pointer): Word;
208 procedure MC_RECV_PlayerSettings(P: Pointer);
209 // ITEM
210 procedure MC_RECV_ItemSpawn(P: Pointer);
211 procedure MC_RECV_ItemDestroy(P: Pointer);
212 // PANEL
213 procedure MC_RECV_PanelTexture(P: Pointer);
214 procedure MC_RECV_PanelState(P: Pointer);
215 // MONSTER
216 procedure MC_RECV_MonsterSpawn(P: Pointer);
217 procedure MC_RECV_MonsterPos(P: Pointer);
218 procedure MC_RECV_MonsterState(P: Pointer);
219 procedure MC_RECV_MonsterShot(P: Pointer);
220 procedure MC_RECV_MonsterDelete(P: Pointer);
221 // SHOT
222 procedure MC_RECV_CreateShot(P: Pointer);
223 procedure MC_RECV_UpdateShot(P: Pointer);
224 procedure MC_RECV_DeleteShot(P: Pointer);
225 // TRIGGER
226 procedure MC_RECV_TriggerSound(P: Pointer);
227 procedure MC_RECV_TriggerMusic(P: Pointer);
228 // MISC
229 procedure MC_RECV_TimeSync(P: Pointer);
230 procedure MC_RECV_VoteEvent(P: Pointer);
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_fixedbuffer, 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; P: Pointer);
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 := e_Raw_Read_String(P);
309 Mode := e_Raw_Read_Byte(P);
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; P: Pointer);
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 := e_Raw_Read_String(P);
330 Pw := e_Raw_Read_String(P);
331 PName := e_Raw_Read_String(P);
332 Model := e_Raw_Read_String(P);
333 R := e_Raw_Read_Byte(P);
334 G := e_Raw_Read_Byte(P);
335 B := e_Raw_Read_Byte(P);
336 T := e_Raw_Read_Byte(P);
338 if Ver <> GAME_VERSION then
339 begin
340 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
341 _lc[I_NET_DISC_VERSION]);
342 enet_peer_disconnect(C^.Peer, NET_DISC_VERSION);
343 Exit;
344 end;
346 if g_Net_IsHostBanned(C^.Peer^.address.host) then
347 begin
348 if g_Net_IsHostBanned(C^.Peer^.address.host, True) then
349 begin
350 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
351 _lc[I_NET_DISC_BAN]);
352 enet_peer_disconnect(C^.Peer, NET_DISC_BAN);
353 end
354 else
355 begin
356 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
357 _lc[I_NET_DISC_BAN]);
358 enet_peer_disconnect(C^.Peer, NET_DISC_TEMPBAN);
359 end;
360 Exit;
361 end;
363 if NetPassword <> '' then
364 if AnsiLowerCase(NetPassword) <> AnsiLowerCase(Pw) then
365 begin
366 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
367 _lc[I_NET_DISC_PASSWORD]);
368 enet_peer_disconnect(C^.Peer, NET_DISC_PASSWORD);
369 Exit;
370 end;
372 Color.R := R;
373 Color.B := B;
374 Color.G := G;
376 PID := g_Player_Create(Model, Color, T, False);
377 with g_Player_Get(PID) do
378 begin
379 Name := PName;
380 Reset(True);
381 end;
383 C^.Player := PID;
385 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
386 e_WriteLog('NET: Client ' + PName + ' [' + IntToStr(C^.ID) +
387 '] connected. Assigned player #' + IntToStr(PID) + '.', MSG_NOTIFY);
389 MH_SEND_Info(C^.ID);
391 with g_Player_Get(PID) do
392 begin
393 Name := PName;
394 FClientID := C^.ID;
395 // round in progress, don't spawn
396 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
397 begin
398 Lives := 0;
399 FNoRespawn := True;
400 Spectate;
401 FWantsInGame := True; // TODO: look into this later
402 end
403 else
404 Respawn(gGameSettings.GameType = GT_SINGLE);
405 end;
407 for I := Low(NetClients) to High(NetClients) do
408 begin
409 if NetClients[I].ID = C^.ID then Continue;
410 MH_SEND_PlayerCreate(PID, NetClients[I].ID);
411 MH_SEND_PlayerPos(True, PID, NetClients[I].ID);
412 MH_SEND_PlayerStats(PID, NetClients[I].ID);
413 end;
415 if gState in [STATE_INTERCUSTOM, STATE_FOLD] then
416 MH_SEND_GameEvent(NET_EV_MAPEND, 0, 'N', C^.ID);
418 if NetUseMaster then g_Net_Slist_Update;
419 end;
421 procedure MH_RECV_FullStateRequest(C: pTNetClient; P: Pointer);
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; P: Pointer): Word;
432 var
433 Dir: Byte;
434 PID: Word;
435 kByte: Word;
436 Pl: TPlayer;
437 GT: LongWord;
438 begin
439 Result := 0;
440 if not gGameOn then Exit;
442 GT := e_Raw_Read_LongWord(P);
443 PID := C^.Player;
444 Pl := g_Player_Get(PID);
445 if Pl = nil then
446 Exit;
448 if (GT > gTime + NET_MAX_DIFFTIME) or (GT < Pl.NetTime) then Exit;
450 with Pl do
451 begin
452 NetTime := GT;
453 kByte := e_Raw_Read_Word(P);
454 Dir := e_Raw_Read_Byte(P);
455 if Direction <> TDirection(Dir) then
456 JustTeleported := False;
457 SetDirection(TDirection(Dir));
458 ReleaseKeys;
460 if kByte = NET_KEY_CHAT then
461 begin
462 PressKey(KEY_CHAT, 10000);
463 Exit;
464 end;
466 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
467 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
468 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
469 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
470 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
471 if LongBool(kByte and NET_KEY_FIRE) then PressKey(KEY_FIRE, 10000);
472 if LongBool(kByte and NET_KEY_OPEN) then PressKey(KEY_OPEN, 10000);
473 if LongBool(kByte and NET_KEY_NW) then PressKey(KEY_NEXTWEAPON, 10000);
474 if LongBool(kByte and NET_KEY_PW) then PressKey(KEY_PREVWEAPON, 10000);
475 end;
477 // MH_SEND_PlayerPos(False, PID, C^.ID);
478 end;
480 procedure MH_RECV_CheatRequest(C: pTNetClient; P: Pointer);
481 var
482 CheatKind: Byte;
483 Pl: TPlayer;
484 begin
485 Pl := g_Player_Get(C^.Player);
486 if Pl = nil then Exit;
488 CheatKind := e_Raw_Read_Byte(P);
490 case CheatKind of
491 NET_CHEAT_SUICIDE:
492 Pl.Damage(SUICIDE_DAMAGE, Pl.UID, 0, 0, HIT_SELF);
493 NET_CHEAT_SPECTATE:
494 begin
495 if Pl.FSpectator then
496 Pl.Respawn(False)
497 else
498 Pl.Spectate;
499 end;
500 end;
501 end;
503 procedure MH_RECV_PlayerSettings(C: pTNetClient; P: Pointer);
504 var
505 TmpName: string;
506 TmpModel: string;
507 TmpColor: TRGB;
508 TmpTeam: Byte;
509 Pl: TPlayer;
510 begin
511 TmpName := e_Raw_Read_String(P);
512 TmpModel := e_Raw_Read_String(P);
513 TmpColor.R := e_Raw_Read_Byte(P);
514 TmpColor.G := e_Raw_Read_Byte(P);
515 TmpColor.B := e_Raw_Read_Byte(P);
516 TmpTeam := e_Raw_Read_Byte(P);
518 Pl := g_Player_Get(C^.Player);
519 if Pl = nil then Exit;
521 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
522 Pl.SwitchTeam
523 else
524 Pl.SetColor(TmpColor);
526 if Pl.Name <> TmpName then
527 begin
528 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
529 Pl.Name := TmpName;
530 end;
532 if TmpModel <> Pl.Model.Name then
533 Pl.SetModel(TmpModel);
535 MH_SEND_PlayerSettings(Pl.UID, TmpModel);
536 end;
538 // RCON
540 procedure MH_RECV_RCONPassword(C: pTNetClient; P: Pointer);
541 var
542 Pwd: string;
543 begin
544 Pwd := e_Raw_Read_String(P);
545 if not NetAllowRCON then Exit;
546 if Pwd = NetRCONPassword then
547 begin
548 C^.RCONAuth := True;
549 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWGOOD, 'N', C^.ID);
550 end
551 else
552 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWBAD, 'N', C^.ID);
553 end;
555 procedure MH_RECV_RCONCommand(C: pTNetClient; P: Pointer);
556 var
557 Cmd: string;
558 begin
559 Cmd := e_Raw_Read_String(P);
560 if not NetAllowRCON then Exit;
561 if not C^.RCONAuth then
562 begin
563 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_NOAUTH, 'N', C^.ID);
564 Exit;
565 end;
566 g_Console_Process(Cmd);
567 end;
569 // MISC
571 procedure MH_RECV_Vote(C: pTNetClient; P: Pointer);
572 var
573 Start: Boolean;
574 Name, Command: string;
575 Need: Integer;
576 Pl: TPlayer;
577 begin
578 Start := e_Raw_Read_Byte(P) <> 0;
579 Command := e_Raw_Read_String(P);
581 Pl := g_Player_Get(C^.Player);
582 if Pl = nil then Exit;
583 Name := Pl.Name;
585 if Start then
586 begin
587 if not g_Console_CommandBlacklisted(Command) then
588 g_Game_StartVote(Command, Name);
589 end
590 else if gVoteInProgress then
591 begin
592 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
593 Need := Floor((NetClientCount+1)/2.0) + 1
594 else
595 Need := Floor(NetClientCount/2.0) + 1;
596 if C^.Voted then
597 begin
598 Dec(gVoteCount);
599 C^.Voted := False;
600 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [Name, gVoteCount, Need]), True);
601 MH_SEND_VoteEvent(NET_VE_REVOKE, Name, 'a', gVoteCount, Need);
602 end
603 else
604 begin
605 Inc(gVoteCount);
606 C^.Voted := True;
607 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Name, gVoteCount, Need]), True);
608 MH_SEND_VoteEvent(NET_VE_VOTE, Name, 'a', gVoteCount, Need);
609 g_Game_CheckVote;
610 end;
611 end;
612 end;
614 // GAME (SEND)
616 procedure MH_SEND_Everything(CreatePlayers: Boolean = False; ID: Integer = NET_EVERYONE);
617 var
618 I: Integer;
619 begin
620 if gPlayers <> nil then
621 for I := Low(gPlayers) to High(gPlayers) do
622 if gPlayers[I] <> nil then
623 begin
624 if CreatePlayers then MH_SEND_PlayerCreate(gPlayers[I].UID, ID);
625 MH_SEND_PlayerPos(True, gPlayers[I].UID, ID);
626 MH_SEND_PlayerStats(gPlayers[I].UID, ID);
628 if (gPlayers[I].Flag <> FLAG_NONE) and (gGameSettings.GameMode = GM_CTF) then
629 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED, gPlayers[I].Flag, gPlayers[I].UID, True, ID);
630 end;
632 if gItems <> nil then
633 begin
634 for I := High(gItems) downto Low(gItems) do
635 if gItems[I].Live then
636 MH_SEND_ItemSpawn(True, I, ID);
637 end;
639 if gMonsters <> nil then
640 for I := 0 to High(gMonsters) do
641 if gMonsters[I] <> nil then
642 MH_SEND_MonsterSpawn(gMonsters[I].UID, ID);
644 if gWalls <> nil then
645 for I := Low(gWalls) to High(gWalls) do
646 if gWalls[I] <> nil then
647 with gWalls[I] do
648 begin
649 if Door then
650 MH_SEND_PanelState(PanelType, I, ID);
652 if GetTextureCount > 1 then
653 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
654 end;
656 if gLifts <> nil then
657 for I := Low(gLifts) to High(gLifts) do
658 if gLifts[I] <> nil then
659 with gLifts[I] do
660 MH_SEND_PanelState(PanelType, I, ID);
662 if gRenderForegrounds <> nil then
663 for I := Low(gRenderForegrounds) to High(gRenderForegrounds) do
664 if gRenderForegrounds[I] <> nil then
665 with gRenderForegrounds[I] do
666 begin
667 if (GetTextureCount > 1) then
668 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
669 if Moved then
670 MH_SEND_PanelState(PanelType, I, ID);
671 end;
672 if gRenderBackgrounds <> nil then
673 for I := Low(gRenderBackgrounds) to High(gRenderBackgrounds) do
674 if gRenderBackgrounds[I] <> nil then
675 with gRenderBackgrounds[I] do
676 begin
677 if (GetTextureCount > 1) then
678 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
679 if Moved then
680 MH_SEND_PanelState(PanelType, I, ID);
681 end;
682 if gWater <> nil then
683 for I := Low(gWater) to High(gWater) do
684 if gWater[I] <> nil then
685 with gWater[I] do
686 if GetTextureCount > 1 then
687 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
688 if gAcid1 <> nil then
689 for I := Low(gAcid1) to High(gAcid1) do
690 if gAcid1[I] <> nil then
691 with gAcid1[I] do
692 if GetTextureCount > 1 then
693 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
694 if gAcid2 <> nil then
695 for I := Low(gAcid2) to High(gAcid2) do
696 if gAcid2[I] <> nil then
697 with gAcid2[I] do
698 if GetTextureCount > 1 then
699 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
700 if gSteps <> nil then
701 for I := Low(gSteps) to High(gSteps) do
702 if gSteps[I] <> nil then
703 with gSteps[I] do
704 if GetTextureCount > 1 then
705 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
707 if gTriggers <> nil then
708 for I := Low(gTriggers) to High(gTriggers) do
709 if gTriggers[I].TriggerType = TRIGGER_SOUND then
710 MH_SEND_TriggerSound(gTriggers[I], ID);
712 if Shots <> nil then
713 for I := Low(Shots) to High(Shots) do
714 if Shots[i].ShotType in [6, 7, 8] then
715 MH_SEND_CreateShot(i, ID);
717 MH_SEND_TriggerMusic(ID);
719 MH_SEND_GameStats(ID);
720 MH_SEND_CoopStats(ID);
722 if gGameSettings.GameMode = GM_CTF then
723 begin
724 if gFlags[FLAG_RED].State <> FLAG_STATE_CAPTURED then
725 MH_SEND_FlagEvent(gFlags[FLAG_RED].State, FLAG_RED, 0, True, ID);
726 if gFlags[FLAG_BLUE].State <> FLAG_STATE_CAPTURED then
727 MH_SEND_FlagEvent(gFlags[FLAG_BLUE].State, FLAG_BLUE, 0, True, ID);
728 end;
730 if CreatePlayers and (ID >= 0) then NetClients[ID].State := NET_STATE_GAME;
732 if gLMSRespawn > LMS_RESPAWN_NONE then
733 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000, 'N', ID);
734 end;
736 procedure MH_SEND_Info(ID: Byte);
737 var
738 Map: string;
739 begin
740 Map := g_ExtractFileName(gMapInfo.Map);
742 e_Buffer_Clear(@NetOut);
744 e_Buffer_Write(@NetOut, Byte(NET_MSG_INFO));
745 e_Buffer_Write(@NetOut, ID);
746 e_Buffer_Write(@NetOut, NetClients[ID].Player);
747 e_Buffer_Write(@NetOut, gGameSettings.WAD);
748 e_Buffer_Write(@NetOut, Map);
749 e_Buffer_Write(@NetOut, gWADHash);
750 e_Buffer_Write(@NetOut, gGameSettings.GameMode);
751 e_Buffer_Write(@NetOut, gGameSettings.GoalLimit);
752 e_Buffer_Write(@NetOut, gGameSettings.TimeLimit);
753 e_Buffer_Write(@NetOut, gGameSettings.MaxLives);
754 e_Buffer_Write(@NetOut, gGameSettings.Options);
755 e_Buffer_Write(@NetOut, gTime);
757 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
758 end;
760 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
761 var
762 Name: string;
763 i: Integer;
764 Team: Byte;
765 begin
766 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
767 Mode := NET_CHAT_PLAYER;
769 Team := 0;
770 if (Mode = NET_CHAT_TEAM) then
771 begin
772 for i := Low(gPlayers) to High(gPlayers) do
773 if (gPlayers[i] <> nil) and (gPlayers[i].FClientID >= 0) and
774 (gPlayers[i].Team = ID) then
775 begin
776 e_Buffer_Write(@NetOut, Byte(NET_MSG_CHAT));
777 e_Buffer_Write(@NetOut, Txt);
778 e_Buffer_Write(@NetOut, Mode);
779 g_Net_Host_Send(gPlayers[i].FClientID, True, NET_CHAN_CHAT);
780 end;
781 Team := ID;
782 ID := NET_EVERYONE;
783 end
784 else
785 begin
786 e_Buffer_Write(@NetOut, Byte(NET_MSG_CHAT));
787 e_Buffer_Write(@NetOut, Txt);
788 e_Buffer_Write(@NetOut, Mode);
789 g_Net_Host_Send(ID, True, NET_CHAN_CHAT);
790 end;
792 if Mode = NET_CHAT_SYSTEM then
793 Exit;
795 if ID = NET_EVERYONE then
796 begin
797 if Mode = NET_CHAT_PLAYER then
798 begin
799 g_Console_Add(Txt, True);
800 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), MSG_NOTIFY);
801 g_Sound_PlayEx('SOUND_GAME_RADIO');
802 end
803 else
804 if Mode = NET_CHAT_TEAM then
805 if gPlayer1 <> nil then
806 begin
807 if (gPlayer1.Team = TEAM_RED) and (Team = TEAM_RED) then
808 begin
809 g_Console_Add(#18'[Team] '#2 + Txt, True);
810 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), MSG_NOTIFY);
811 g_Sound_PlayEx('SOUND_GAME_RADIO');
812 end
813 else if (gPlayer1.Team = TEAM_BLUE) and (Team = TEAM_BLUE) then
814 begin
815 g_Console_Add(#20'[Team] '#2 + Txt, True);
816 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), MSG_NOTIFY);
817 g_Sound_PlayEx('SOUND_GAME_RADIO');
818 end;
819 end;
820 end
821 else
822 begin
823 Name := g_Net_ClientName_ByID(ID);
824 g_Console_Add('-> ' + Name + ': ' + Txt, True);
825 e_WriteLog('[Tell ' + Name + '] ' + b_Text_Unformat(Txt), MSG_NOTIFY);
826 g_Sound_PlayEx('SOUND_GAME_RADIO');
827 end;
828 end;
830 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
831 begin
832 e_Buffer_Write(@NetOut, Byte(NET_MSG_GFX));
833 e_Buffer_Write(@NetOut, Kind);
834 e_Buffer_Write(@NetOut, X);
835 e_Buffer_Write(@NetOut, Y);
836 e_Buffer_Write(@NetOut, Ang);
838 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
839 end;
841 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
842 begin
843 e_Buffer_Write(@NetOut, Byte(NET_MSG_SND));
844 e_Buffer_Write(@NetOut, Name);
845 if Pos then
846 begin
847 e_Buffer_Write(@NetOut, Byte(1));
848 e_Buffer_Write(@NetOut, X);
849 e_Buffer_Write(@NetOut, Y);
850 end
851 else
852 e_Buffer_Write(@NetOut, Byte(0));
854 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
855 end;
857 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
858 begin
859 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
861 e_Buffer_Write(@NetOut, Byte(NET_MSG_SHADD));
862 e_Buffer_Write(@NetOut, Proj);
863 e_Buffer_Write(@NetOut, Shots[Proj].ShotType);
864 e_Buffer_Write(@NetOut, Shots[Proj].Target);
865 e_Buffer_Write(@NetOut, Shots[Proj].SpawnerUID);
866 e_Buffer_Write(@NetOut, Shots[Proj].Timeout);
867 e_Buffer_Write(@NetOut, Shots[Proj].Obj.X);
868 e_Buffer_Write(@NetOut, Shots[Proj].Obj.Y);
869 e_Buffer_Write(@NetOut, Shots[Proj].Obj.Vel.X);
870 e_Buffer_Write(@NetOut, Shots[Proj].Obj.Vel.Y);
872 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
873 end;
875 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
876 begin
877 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
879 e_Buffer_Write(@NetOut, Byte(NET_MSG_SHPOS));
880 e_Buffer_Write(@NetOut, Proj);
881 e_Buffer_Write(@NetOut, Shots[Proj].Obj.X);
882 e_Buffer_Write(@NetOut, Shots[Proj].Obj.Y);
883 e_Buffer_Write(@NetOut, Shots[Proj].Obj.Vel.X);
884 e_Buffer_Write(@NetOut, Shots[Proj].Obj.Vel.Y);
886 g_Net_Host_Send(ID, False, NET_CHAN_SHOTS);
887 end;
889 procedure MH_Send_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
890 begin
891 e_Buffer_Write(@NetOut, Byte(NET_MSG_SHDEL));
892 e_Buffer_Write(@NetOut, Proj);
893 e_Buffer_Write(@NetOut, Byte(Loud));
894 e_Buffer_Write(@NetOut, X);
895 e_Buffer_Write(@NetOut, Y);
897 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
898 end;
900 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
901 begin
902 e_Buffer_Write(@NetOut, Byte(NET_MSG_SCORE));
903 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
904 begin
905 e_Buffer_Write(@NetOut, gTeamStat[TEAM_RED].Goals);
906 e_Buffer_Write(@NetOut, gTeamStat[TEAM_BLUE].Goals);
907 end
908 else
909 if gGameSettings.GameMode = GM_COOP then
910 begin
911 e_Buffer_Write(@NetOut, gCoopMonstersKilled);
912 e_Buffer_Write(@NetOut, gCoopSecretsFound);
913 end;
915 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
916 end;
918 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
919 begin
920 e_Buffer_Write(@NetOut, Byte(NET_MSG_COOP));
921 e_Buffer_Write(@NetOut, gTotalMonsters);
922 e_Buffer_Write(@NetOut, gSecretsCount);
923 e_Buffer_Write(@NetOut, gCoopTotalMonstersKilled);
924 e_Buffer_Write(@NetOut, gCoopTotalSecretsFound);
925 e_Buffer_Write(@NetOut, gCoopTotalMonsters);
926 e_Buffer_Write(@NetOut, gCoopTotalSecrets);
927 end;
929 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
930 begin
931 e_Buffer_Write(@NetOut, Byte(NET_MSG_GEVENT));
932 e_Buffer_Write(@NetOut, EvType);
933 e_Buffer_Write(@NetOut, EvNum);
934 e_Buffer_Write(@NetOut, EvStr);
935 e_Buffer_Write(@NetOut, Byte(gLastMap));
936 e_Buffer_Write(@NetOut, gTime);
937 if (EvType = NET_EV_MAPSTART) and (Pos(':\', EvStr) > 0) then
938 begin
939 e_Buffer_Write(@NetOut, Byte(1));
940 e_Buffer_Write(@NetOut, gWADHash);
941 end else
942 e_Buffer_Write(@NetOut, Byte(0));
944 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
945 end;
947 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
948 begin
949 e_Buffer_Write(@NetOut, Byte(NET_MSG_FLAG));
950 e_Buffer_Write(@NetOut, EvType);
951 e_Buffer_Write(@NetOut, Flag);
952 e_Buffer_Write(@NetOut, Byte(Quiet));
953 e_Buffer_Write(@NetOut, PID);
954 e_Buffer_Write(@NetOut, gFlags[Flag].State);
955 e_Buffer_Write(@NetOut, gFlags[Flag].CaptureTime);
956 e_Buffer_Write(@NetOut, gFlags[Flag].Obj.X);
957 e_Buffer_Write(@NetOut, gFlags[Flag].Obj.Y);
958 e_Buffer_Write(@NetOut, gFlags[Flag].Obj.Vel.X);
959 e_Buffer_Write(@NetOut, gFlags[Flag].Obj.Vel.Y);
961 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
962 end;
964 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
965 begin
966 e_Buffer_Write(@NetOut, Byte(NET_MSG_GSET));
967 e_Buffer_Write(@NetOut, gGameSettings.GameMode);
968 e_Buffer_Write(@NetOut, gGameSettings.GoalLimit);
969 e_Buffer_Write(@NetOut, gGameSettings.TimeLimit);
970 e_Buffer_Write(@NetOut, gGameSettings.MaxLives);
971 e_Buffer_Write(@NetOut, gGameSettings.Options);
973 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
974 end;
976 // PLAYER (SEND)
978 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
979 var
980 P: TPlayer;
981 begin
982 P := g_Player_Get(PID);
983 if P = nil then Exit;
985 e_Buffer_Write(@NetOut, Byte(NET_MSG_PLR));
986 e_Buffer_Write(@NetOut, PID);
987 e_Buffer_Write(@NetOut, P.Name);
989 e_Buffer_Write(@NetOut, P.FActualModelName);
990 e_Buffer_Write(@NetOut, P.FColor.R);
991 e_Buffer_Write(@NetOut, P.FColor.G);
992 e_Buffer_Write(@NetOut, P.FColor.B);
993 e_Buffer_Write(@NetOut, P.Team);
995 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT)
996 end;
998 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
999 var
1000 kByte: Word;
1001 Pl: TPlayer;
1002 begin
1003 Pl := g_Player_Get(PID);
1004 if Pl = nil then Exit;
1005 if Pl.FDummy then Exit;
1007 e_Buffer_Write(@NetOut, Byte(NET_MSG_PLRPOS));
1008 e_Buffer_Write(@NetOut, gTime);
1009 e_Buffer_Write(@NetOut, PID);
1011 kByte := 0;
1013 with Pl do
1014 begin
1015 e_Buffer_Write(@NetOut, FPing);
1016 e_Buffer_Write(@NetOut, FLoss);
1017 if IsKeyPressed(KEY_CHAT) then
1018 kByte := NET_KEY_CHAT
1019 else
1020 begin
1021 if IsKeyPressed(KEY_LEFT) then kByte := kByte or NET_KEY_LEFT;
1022 if IsKeyPressed(KEY_RIGHT) then kByte := kByte or NET_KEY_RIGHT;
1023 if IsKeyPressed(KEY_UP) then kByte := kByte or NET_KEY_UP;
1024 if IsKeyPressed(KEY_DOWN) then kByte := kByte or NET_KEY_DOWN;
1025 if IsKeyPressed(KEY_JUMP) then kByte := kByte or NET_KEY_JUMP;
1026 if JustTeleported then kByte := kByte or NET_KEY_FORCEDIR;
1027 end;
1029 e_Buffer_Write(@NetOut, kByte);
1030 if Direction = D_LEFT then e_Buffer_Write(@NetOut, Byte(0)) else e_Buffer_Write(@NetOut, Byte(1));
1031 e_Buffer_Write(@NetOut, GameX);
1032 e_Buffer_Write(@NetOut, GameY);
1033 e_Buffer_Write(@NetOut, GameVelX);
1034 e_Buffer_Write(@NetOut, GameVelY);
1035 e_Buffer_Write(@NetOut, GameAccelX);
1036 e_Buffer_Write(@NetOut, GameAccelY);
1037 end;
1039 g_Net_Host_Send(ID, Reliable, NET_CHAN_PLAYERPOS);
1040 end;
1042 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
1043 var
1044 P: TPlayer;
1045 I: Integer;
1046 begin
1047 P := g_Player_Get(PID);
1048 if P = nil then Exit;
1050 e_Buffer_Write(@NetOut, Byte(NET_MSG_PLRSTA));
1051 e_Buffer_Write(@NetOut, PID);
1053 with P do
1054 begin
1055 e_Buffer_Write(@NetOut, Byte(Live));
1056 e_Buffer_Write(@NetOut, Byte(GodMode));
1057 e_Buffer_Write(@NetOut, Health);
1058 e_Buffer_Write(@NetOut, Armor);
1059 e_Buffer_Write(@NetOut, Air);
1060 e_Buffer_Write(@NetOut, JetFuel);
1061 e_Buffer_Write(@NetOut, Lives);
1062 e_Buffer_Write(@NetOut, Team);
1064 for I := WEAPON_KASTET to WEAPON_SUPERPULEMET do
1065 e_Buffer_Write(@NetOut, Byte(FWeapon[I]));
1067 for I := A_BULLETS to A_CELLS do
1068 e_Buffer_Write(@NetOut, FAmmo[I]);
1070 for I := A_BULLETS to A_CELLS do
1071 e_Buffer_Write(@NetOut, FMaxAmmo[I]);
1073 for I := MR_SUIT to MR_MAX do
1074 e_Buffer_Write(@NetOut, LongWord(FMegaRulez[I]));
1076 e_Buffer_Write(@NetOut, Byte(R_ITEM_BACKPACK in FRulez));
1077 e_Buffer_Write(@NetOut, Byte(R_KEY_RED in FRulez));
1078 e_Buffer_Write(@NetOut, Byte(R_KEY_GREEN in FRulez));
1079 e_Buffer_Write(@NetOut, Byte(R_KEY_BLUE in FRulez));
1080 e_Buffer_Write(@NetOut, Byte(R_BERSERK in FRulez));
1082 e_Buffer_Write(@NetOut, Frags);
1083 e_Buffer_Write(@NetOut, Death);
1085 e_Buffer_Write(@NetOut, CurrWeap);
1087 e_Buffer_Write(@NetOut, Byte(FSpectator));
1088 e_Buffer_Write(@NetOut, Byte(FGhost));
1089 e_Buffer_Write(@NetOut, Byte(FPhysics));
1090 e_Buffer_Write(@NetOut, Byte(FNoRespawn));
1091 e_Buffer_Write(@NetOut, Byte(FJetpack));
1092 end;
1094 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1095 end;
1097 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
1098 begin
1099 e_Buffer_Write(@NetOut, Byte(NET_MSG_PLRDMG));
1100 e_Buffer_Write(@NetOut, PID);
1101 e_Buffer_Write(@NetOut, Kind);
1102 e_Buffer_Write(@NetOut, Attacker);
1103 e_Buffer_Write(@NetOut, Value);
1104 e_Buffer_Write(@NetOut, VX);
1105 e_Buffer_Write(@NetOut, VY);
1107 g_Net_Host_Send(ID, False, NET_CHAN_PLAYER);
1108 end;
1110 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
1111 begin
1112 e_Buffer_Write(@NetOut, Byte(NET_MSG_PLRDIE));
1113 e_Buffer_Write(@NetOut, PID);
1114 e_Buffer_Write(@NetOut, KillType);
1115 e_Buffer_Write(@NetOut, DeathType);
1116 e_Buffer_Write(@NetOut, Attacker);
1118 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1119 end;
1121 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
1122 begin
1123 e_Buffer_Write(@NetOut, Byte(NET_MSG_PLRFIRE));
1124 e_Buffer_Write(@NetOut, PID);
1125 e_Buffer_Write(@NetOut, Weapon);
1126 e_Buffer_Write(@NetOut, X);
1127 e_Buffer_Write(@NetOut, Y);
1128 e_Buffer_Write(@NetOut, AX);
1129 e_Buffer_Write(@NetOut, AY);
1130 e_Buffer_Write(@NetOut, ShotID);
1132 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1133 end;
1135 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
1136 begin
1137 e_Buffer_Write(@NetOut, Byte(NET_MSG_PLRDEL));
1138 e_Buffer_Write(@NetOut, PID);
1140 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1141 end;
1143 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
1144 var
1145 Pl: TPlayer;
1146 begin
1147 Pl := g_Player_Get(PID);
1148 if Pl = nil then Exit;
1150 e_Buffer_Write(@NetOut, Byte(NET_MSG_PLRSET));
1151 e_Buffer_Write(@NetOut, PID);
1152 e_Buffer_Write(@NetOut, Pl.Name);
1153 if Mdl = '' then
1154 e_Buffer_Write(@NetOut, Pl.Model.Name)
1155 else
1156 e_Buffer_Write(@NetOut, Mdl);
1157 e_Buffer_Write(@NetOut, Pl.FColor.R);
1158 e_Buffer_Write(@NetOut, Pl.FColor.G);
1159 e_Buffer_Write(@NetOut, Pl.FColor.B);
1160 e_Buffer_Write(@NetOut, Pl.Team);
1162 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1163 end;
1165 // ITEM (SEND)
1167 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1168 begin
1169 e_Buffer_Write(@NetOut, Byte(NET_MSG_ISPAWN));
1170 e_Buffer_Write(@NetOut, IID);
1171 e_Buffer_Write(@NetOut, Byte(Quiet));
1172 e_Buffer_Write(@NetOut, gItems[IID].ItemType);
1173 e_Buffer_Write(@NetOut, Byte(gItems[IID].Fall));
1174 e_Buffer_Write(@NetOut, Byte(gItems[IID].Respawnable));
1175 e_Buffer_Write(@NetOut, gItems[IID].Obj.X);
1176 e_Buffer_Write(@NetOut, gItems[IID].Obj.Y);
1177 e_Buffer_Write(@NetOut, gItems[IID].Obj.Vel.X);
1178 e_Buffer_Write(@NetOut, gItems[IID].Obj.Vel.Y);
1180 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1181 end;
1183 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1184 begin
1185 e_Buffer_Write(@NetOut, Byte(NET_MSG_IDEL));
1186 e_Buffer_Write(@NetOut, IID);
1187 e_Buffer_Write(@NetOut, Byte(Quiet));
1189 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1190 end;
1192 // PANEL
1194 procedure MH_SEND_PanelTexture(PType: Word; PID: LongWord; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
1195 var
1196 TP: TPanel;
1197 begin
1198 case PType of
1199 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
1200 TP := gWalls[PID];
1201 PANEL_FORE:
1202 TP := gRenderForegrounds[PID];
1203 PANEL_BACK:
1204 TP := gRenderBackgrounds[PID];
1205 PANEL_WATER:
1206 TP := gWater[PID];
1207 PANEL_ACID1:
1208 TP := gAcid1[PID];
1209 PANEL_ACID2:
1210 TP := gAcid2[PID];
1211 PANEL_STEP:
1212 TP := gSteps[PID];
1213 else
1214 Exit;
1215 end;
1217 with TP do
1218 begin
1219 e_Buffer_Write(@NetOut, Byte(NET_MSG_PTEX));
1220 e_Buffer_Write(@NetOut, PType);
1221 e_Buffer_Write(@NetOut, PID);
1222 e_Buffer_Write(@NetOut, FCurTexture);
1223 e_Buffer_Write(@NetOut, FCurFrame);
1224 e_Buffer_Write(@NetOut, FCurFrameCount);
1225 e_Buffer_Write(@NetOut, AnimLoop);
1226 end;
1228 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1229 end;
1231 procedure MH_SEND_PanelState(PType: Word; PID: LongWord; ID: Integer = NET_EVERYONE);
1232 var
1233 TP: TPanel;
1234 begin
1235 case PType of
1236 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
1237 TP := gWalls[PID];
1238 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT:
1239 TP := gLifts[PID];
1240 PANEL_BACK:
1241 begin
1242 TP := gRenderBackgrounds[PID];
1243 TP.Moved := True;
1244 end;
1245 PANEL_FORE:
1246 begin
1247 TP := gRenderForegrounds[PID];
1248 TP.Moved := True;
1249 end;
1250 else
1251 Exit;
1252 end;
1254 e_Buffer_Write(@NetOut, Byte(NET_MSG_PSTATE));
1255 e_Buffer_Write(@NetOut, PType);
1256 e_Buffer_Write(@NetOut, PID);
1257 e_Buffer_Write(@NetOut, Byte(TP.Enabled));
1258 e_Buffer_Write(@NetOut, TP.LiftType);
1259 e_Buffer_Write(@NetOut, TP.X);
1260 e_Buffer_Write(@NetOut, TP.Y);
1262 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1263 end;
1265 // TRIGGER
1267 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
1268 begin
1269 if gTriggers = nil then Exit;
1270 if T.Sound = nil then Exit;
1272 e_Buffer_Write(@NetOut, Byte(NET_MSG_TSOUND));
1273 e_Buffer_Write(@NetOut, T.ClientID);
1274 e_Buffer_Write(@NetOut, Byte(T.Sound.IsPlaying));
1275 e_Buffer_Write(@NetOut, LongWord(T.Sound.GetPosition));
1276 e_Buffer_Write(@NetOut, T.SoundPlayCount);
1278 g_Net_Host_Send(ID, True);
1279 end;
1281 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
1282 begin
1283 e_Buffer_Write(@NetOut, Byte(NET_MSG_TMUSIC));
1284 e_Buffer_Write(@NetOut, gMusic.Name);
1285 e_Buffer_Write(@NetOut, Byte(gMusic.IsPlaying));
1286 e_Buffer_Write(@NetOut, LongWord(gMusic.GetPosition));
1287 e_Buffer_Write(@NetOut, Byte(gMusic.SpecPause or gMusic.IsPaused));
1289 g_Net_Host_Send(ID, True);
1290 end;
1292 // MONSTER
1294 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
1295 var
1296 M: TMonster;
1297 begin
1298 M := g_Monsters_Get(UID);
1299 if M = nil then
1300 Exit;
1302 with M do
1303 begin
1304 e_Buffer_Write(@NetOut, Byte(NET_MSG_MSPAWN));
1305 e_Buffer_Write(@NetOut, UID);
1306 e_Buffer_Write(@NetOut, MonsterType);
1307 e_Buffer_Write(@NetOut, MonsterState);
1308 e_Buffer_Write(@NetOut, MonsterAnim);
1309 e_Buffer_Write(@NetOut, MonsterTargetUID);
1310 e_Buffer_Write(@NetOut, MonsterTargetTime);
1311 e_Buffer_Write(@NetOut, MonsterBehaviour);
1312 e_Buffer_Write(@NetOut, MonsterSleep);
1313 e_Buffer_Write(@NetOut, MonsterHealth);
1314 e_Buffer_Write(@NetOut, MonsterAmmo);
1315 e_Buffer_Write(@NetOut, GameX);
1316 e_Buffer_Write(@NetOut, GameY);
1317 e_Buffer_Write(@NetOut, GameVelX);
1318 e_Buffer_Write(@NetOut, GameVelY);
1319 e_Buffer_Write(@NetOut, Byte(GameDirection));
1320 end;
1322 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1323 end;
1325 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
1326 var
1327 M: TMonster;
1328 begin
1329 M := g_Monsters_Get(UID);
1330 if M = nil then Exit;
1332 e_Buffer_Write(@NetOut, Byte(NET_MSG_MPOS));
1333 e_Buffer_Write(@NetOut, UID);
1335 with M do
1336 begin
1337 e_Buffer_Write(@NetOut, GameX);
1338 e_Buffer_Write(@NetOut, GameY);
1339 e_Buffer_Write(@NetOut, GameVelX);
1340 e_Buffer_Write(@NetOut, GameVelY);
1341 e_Buffer_Write(@NetOut, Byte(GameDirection));
1342 end;
1344 g_Net_Host_Send(ID, False, NET_CHAN_MONSTERPOS);
1345 end;
1347 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
1348 var
1349 M: TMonster;
1350 begin
1351 M := g_Monsters_Get(UID);
1352 if M = nil then Exit;
1354 e_Buffer_Write(@NetOut, Byte(NET_MSG_MSTATE));
1355 e_Buffer_Write(@NetOut, UID);
1357 with M do
1358 begin
1359 e_Buffer_Write(@NetOut, MonsterState);
1360 e_Buffer_Write(@NetOut, ForcedAnim);
1361 e_Buffer_Write(@NetOut, MonsterTargetUID);
1362 e_Buffer_Write(@NetOut, MonsterTargetTime);
1363 e_Buffer_Write(@NetOut, MonsterSleep);
1364 e_Buffer_Write(@NetOut, MonsterHealth);
1365 e_Buffer_Write(@NetOut, MonsterAmmo);
1366 e_Buffer_Write(@NetOut, MonsterPain);
1367 e_Buffer_Write(@NetOut, Byte(AnimIsReverse));
1368 end;
1370 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1371 end;
1373 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
1374 begin
1375 e_Buffer_Write(@NetOut, Byte(NET_MSG_MSHOT));
1376 e_Buffer_Write(@NetOut, UID);
1377 e_Buffer_Write(@NetOut, X);
1378 e_Buffer_Write(@NetOut, Y);
1379 e_Buffer_Write(@NetOut, VX);
1380 e_Buffer_Write(@NetOut, VY);
1382 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1383 end;
1385 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
1386 var
1387 M: TMonster;
1388 begin
1389 M := g_Monsters_Get(UID);
1390 if M = nil then Exit;
1392 e_Buffer_Write(@NetOut, Byte(NET_MSG_MDEL));
1393 e_Buffer_Write(@NetOut, UID);
1395 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1396 end;
1398 // MISC
1400 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
1401 begin
1402 e_Buffer_Write(@NetOut, Byte(NET_MSG_TIME_SYNC));
1403 e_Buffer_Write(@NetOut, Time);
1405 g_Net_Host_Send(ID, False, NET_CHAN_SERVICE);
1406 end;
1408 procedure MH_SEND_VoteEvent(EvType: Byte;
1409 StrArg1: string = 'a'; StrArg2: string = 'b';
1410 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
1411 ID: Integer = NET_EVERYONE);
1412 begin
1413 e_Buffer_Write(@NetOut, Byte(NET_MSG_VOTE_EVENT));
1414 e_Buffer_Write(@NetOut, EvType);
1415 e_Buffer_Write(@NetOut, IntArg1);
1416 e_Buffer_Write(@NetOut, IntArg2);
1417 e_Buffer_Write(@NetOut, StrArg1);
1418 e_Buffer_Write(@NetOut, StrArg2);
1420 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1421 end;
1423 // CLIENT MESSAGES //
1425 // GAME
1427 procedure MC_RECV_Chat(P: Pointer);
1428 var
1429 Txt: string;
1430 Mode: Byte;
1431 begin
1432 Txt := e_Raw_Read_String(P);
1433 Mode := e_Raw_Read_Byte(P);
1435 if Mode <> NET_CHAT_SYSTEM then
1436 begin
1437 if Mode = NET_CHAT_PLAYER then
1438 begin
1439 g_Console_Add(Txt, True);
1440 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), MSG_NOTIFY);
1441 g_Sound_PlayEx('SOUND_GAME_RADIO');
1442 end else
1443 if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then
1444 begin
1445 if gPlayer1.Team = TEAM_RED then
1446 g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True);
1447 if gPlayer1.Team = TEAM_BLUE then
1448 g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True);
1449 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), MSG_NOTIFY);
1450 g_Sound_PlayEx('SOUND_GAME_RADIO');
1451 end;
1452 end else
1453 g_Console_Add(Txt, True);
1454 end;
1456 procedure MC_RECV_Effect(P: Pointer);
1457 var
1458 Kind: Byte;
1459 X, Y: Integer;
1460 Ang: SmallInt;
1461 Anim: TAnimation;
1462 ID: LongWord;
1463 begin
1464 if not gGameOn then Exit;
1465 Kind := e_Raw_Read_Byte(P);
1466 X := e_Raw_Read_LongInt(P);
1467 Y := e_Raw_Read_LongInt(P);
1468 Ang := e_Raw_Read_SmallInt(P);
1470 case Kind of
1471 NET_GFX_SPARK:
1472 g_GFX_Spark(X, Y, 2 + Random(2), Ang, 0, 0);
1474 NET_GFX_TELE:
1475 begin
1476 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
1477 begin
1478 Anim := TAnimation.Create(ID, False, 3);
1479 g_GFX_OnceAnim(X, Y, Anim);
1480 Anim.Free();
1481 end;
1482 if Ang = 1 then
1483 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
1484 end;
1486 NET_GFX_EXPLODE:
1487 begin
1488 if g_Frames_Get(ID, 'FRAMES_EXPLODE_ROCKET') then
1489 begin
1490 Anim := TAnimation.Create(ID, False, 6);
1491 Anim.Blending := False;
1492 g_GFX_OnceAnim(X-64, Y-64, Anim);
1493 Anim.Free();
1494 end;
1495 if Ang = 1 then
1496 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X, Y);
1497 end;
1499 NET_GFX_BFGEXPL:
1500 begin
1501 if g_Frames_Get(ID, 'FRAMES_EXPLODE_BFG') then
1502 begin
1503 Anim := TAnimation.Create(ID, False, 6);
1504 Anim.Blending := False;
1505 g_GFX_OnceAnim(X-64, Y-64, Anim);
1506 Anim.Free();
1507 end;
1508 if Ang = 1 then
1509 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X, Y);
1510 end;
1512 NET_GFX_BFGHIT:
1513 begin
1514 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1515 begin
1516 Anim := TAnimation.Create(ID, False, 4);
1517 g_GFX_OnceAnim(X-32, Y-32, Anim);
1518 Anim.Free();
1519 end;
1520 end;
1522 NET_GFX_FIRE:
1523 begin
1524 if g_Frames_Get(ID, 'FRAMES_FIRE') then
1525 begin
1526 Anim := TAnimation.Create(ID, False, 4);
1527 g_GFX_OnceAnim(X, Y, Anim);
1528 Anim.Free();
1529 end;
1530 if Ang = 1 then
1531 g_Sound_PlayExAt('SOUND_FIRE', X, Y);
1532 end;
1534 NET_GFX_RESPAWN:
1535 begin
1536 if g_Frames_Get(ID, 'FRAMES_ITEM_RESPAWN') then
1537 begin
1538 Anim := TAnimation.Create(ID, False, 4);
1539 g_GFX_OnceAnim(X, Y, Anim);
1540 Anim.Free();
1541 end;
1542 if Ang = 1 then
1543 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
1544 end;
1546 NET_GFX_SHELL1:
1547 g_Player_CreateShell(X, Y, 0, -2, SHELL_BULLET);
1549 NET_GFX_SHELL2:
1550 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1552 NET_GFX_SHELL3:
1553 begin
1554 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1555 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1556 end;
1557 end;
1558 end;
1560 procedure MC_RECV_Sound(P: Pointer);
1561 var
1562 Name: string;
1563 X, Y: Integer;
1564 Pos: Boolean;
1565 begin
1566 Name := e_Raw_Read_String(P);
1567 Pos := e_Raw_Read_Byte(P) <> 0;
1568 if Pos then
1569 begin
1570 X := e_Raw_Read_LongInt(P);
1571 Y := e_Raw_Read_LongInt(P);
1572 g_Sound_PlayExAt(Name, X, Y);
1573 end
1574 else
1575 g_Sound_PlayEx(Name);
1576 end;
1578 procedure MC_RECV_CreateShot(P: Pointer);
1579 var
1580 I, X, Y, XV, YV: Integer;
1581 Timeout: LongWord;
1582 Target, Spawner: Word;
1583 ShType: Byte;
1584 begin
1585 I := e_Raw_Read_LongInt(P);
1586 ShType := e_Raw_Read_Byte(P);
1587 Target := e_Raw_Read_Word(P);
1588 Spawner := e_Raw_Read_Word(P);
1589 Timeout := e_Raw_Read_LongWord(P);
1590 X := e_Raw_Read_LongInt(P);
1591 Y := e_Raw_Read_LongInt(P);
1592 XV := e_Raw_Read_LongInt(P);
1593 YV := e_Raw_Read_LongInt(P);
1595 I := g_Weapon_CreateShot(I, ShType, Spawner, Target, X, Y, XV, YV);
1596 if (Shots <> nil) and (I <= High(Shots)) then
1597 begin
1598 Shots[I].Timeout := Timeout;
1599 //Shots[I].Target := Target; // TODO: find a use for Target later
1600 end;
1601 end;
1603 procedure MC_RECV_UpdateShot(P: Pointer);
1604 var
1605 I, TX, TY, TXV, TYV: Integer;
1606 begin
1607 I := e_Raw_Read_LongInt(P);
1608 TX := e_Raw_Read_LongInt(P);
1609 TY := e_Raw_Read_LongInt(P);
1610 TXV := e_Raw_Read_LongInt(P);
1611 TYV := e_Raw_Read_LongInt(P);
1613 if (Shots <> nil) and (I <= High(Shots)) then
1614 with (Shots[i]) do
1615 begin
1616 Obj.X := TX;
1617 Obj.Y := TY;
1618 Obj.Vel.X := TXV;
1619 Obj.Vel.Y := TYV;
1620 end;
1621 end;
1623 procedure MC_RECV_DeleteShot(P: Pointer);
1624 var
1625 I, X, Y: Integer;
1626 L: Boolean;
1627 begin
1628 if not gGameOn then Exit;
1629 I := e_Raw_Read_LongInt(P);
1630 L := (e_Raw_Read_Byte(P) <> 0);
1631 X := e_Raw_Read_LongInt(P);
1632 Y := e_Raw_Read_LongInt(P);
1634 g_Weapon_DestroyShot(I, X, Y, L);
1635 end;
1637 procedure MC_RECV_GameStats(P: Pointer);
1638 begin
1639 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1640 begin
1641 gTeamStat[TEAM_RED].Goals := e_Raw_Read_SmallInt(P);
1642 gTeamStat[TEAM_BLUE].Goals := e_Raw_Read_SmallInt(P);
1643 end
1644 else
1645 if gGameSettings.GameMode = GM_COOP then
1646 begin
1647 gCoopMonstersKilled := e_Raw_Read_Word(P);
1648 gCoopSecretsFound := e_Raw_Read_Word(P);
1649 end;
1650 end;
1652 procedure MC_RECV_CoopStats(P: Pointer);
1653 begin
1654 gTotalMonsters := e_Raw_Read_LongInt(P);
1655 gSecretsCount := e_Raw_Read_LongInt(P);
1656 gCoopTotalMonstersKilled := e_Raw_Read_Word(P);
1657 gCoopTotalSecretsFound := e_Raw_Read_Word(P);
1658 gCoopTotalMonsters := e_Raw_Read_Word(P);
1659 gCoopTotalSecrets := e_Raw_Read_Word(P);
1660 end;
1662 procedure MC_RECV_GameEvent(P: Pointer);
1663 var
1664 EvType: Byte;
1665 EvNum: Integer;
1666 EvStr: string;
1667 EvTime: LongWord;
1668 BHash: Boolean;
1669 EvHash: TMD5Digest;
1670 pl: TPlayer;
1671 i1, i2: TStrings_Locale;
1672 pln: String;
1673 cnt: Byte;
1674 begin
1675 FillChar(EvHash, Sizeof(EvHash), 0);
1676 EvType := e_Raw_Read_Byte(P);
1677 EvNum := e_Raw_Read_LongInt(P);
1678 EvStr := e_Raw_Read_String(P);
1679 gLastMap := e_Raw_Read_Byte(P) <> 0;
1680 if gLastMap and (gGameSettings.GameMode = GM_COOP) then gStatsOff := True;
1681 gStatsPressed := True;
1682 EvTime := e_Raw_Read_LongWord(P);
1683 BHash := e_Raw_Read_Byte(P) <> 0;
1684 if BHash then
1685 EvHash := e_Raw_Read_MD5(P);
1687 gTime := EvTime;
1689 case EvType of
1690 NET_EV_MAPSTART:
1691 begin
1692 gGameOn := False;
1693 g_Game_ClearLoading();
1694 g_Game_StopAllSounds(True);
1696 gSwitchGameMode := Byte(EvNum);
1697 gGameSettings.GameMode := gSwitchGameMode;
1699 gWADHash := EvHash;
1700 if not g_Game_StartMap(EvStr, True) then
1701 begin
1702 if Pos(':\', EvStr) = 0 then
1703 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + EvStr]))
1704 else
1705 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [EvStr]));
1706 Exit;
1707 end;
1709 MC_SEND_FullStateRequest;
1710 end;
1712 NET_EV_MAPEND:
1713 begin
1714 gMissionFailed := EvNum <> 0;
1715 gExit := EXIT_ENDLEVELCUSTOM;
1716 end;
1718 NET_EV_RCON:
1719 begin
1720 case EvNum of
1721 NET_RCON_NOAUTH:
1722 g_Console_Add(_lc[I_NET_RCON_NOAUTH], True);
1723 NET_RCON_PWGOOD:
1724 g_Console_Add(_lc[I_NET_RCON_PWD_VALID], True);
1725 NET_RCON_PWBAD:
1726 g_Console_Add(_lc[I_NET_RCON_PWD_INVALID], True);
1727 end;
1728 end;
1730 NET_EV_CHANGE_TEAM:
1731 begin
1732 if EvNum = TEAM_RED then
1733 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True);
1734 if EvNum = TEAM_BLUE then
1735 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True);
1736 end;
1738 NET_EV_PLAYER_KICK:
1739 g_Console_Add(Format(_lc[I_PLAYER_KICK], [EvStr]), True);
1741 NET_EV_PLAYER_BAN:
1742 g_Console_Add(Format(_lc[I_PLAYER_BAN], [EvStr]), True);
1744 NET_EV_LMS_WARMUP:
1745 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [EvNum]), True);
1747 NET_EV_LMS_SURVIVOR:
1748 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True);
1750 NET_EV_BIGTEXT:
1751 g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum));
1753 NET_EV_SCORE:
1754 begin
1755 pl := g_Player_Get(EvNum and $FFFF);
1756 if pl = nil then
1757 pln := '?'
1758 else
1759 pln := pl.Name;
1760 cnt := (EvNum shr 16) and $FF;
1761 if Pos('w', EvStr) = 0 then
1762 begin
1763 // Default score
1764 if Pos('t', EvStr) = 0 then
1765 begin
1766 // Player +/- score
1767 if Pos('-', EvStr) = 0 then
1768 begin
1769 if Pos('e', EvStr) = 0 then
1770 i1 := I_PLAYER_SCORE_ADD_OWN
1771 else
1772 i1 := I_PLAYER_SCORE_ADD_ENEMY;
1773 end else
1774 begin
1775 if Pos('e', EvStr) = 0 then
1776 i1 := I_PLAYER_SCORE_SUB_OWN
1777 else
1778 i1 := I_PLAYER_SCORE_SUB_ENEMY;
1779 end;
1780 // Which team
1781 if Pos('r', EvStr) > 0 then
1782 i2 := I_PLAYER_SCORE_TO_RED
1783 else
1784 i2 := I_PLAYER_SCORE_TO_BLUE;
1785 g_Console_Add(Format(_lc[i1], [pln, cnt, _lc[i2]]), True);
1786 end else
1787 begin
1788 // Team +/- score
1789 if Pos('-', EvStr) = 0 then
1790 i1 := I_PLAYER_SCORE_ADD_TEAM
1791 else
1792 i1 := I_PLAYER_SCORE_SUB_TEAM;
1793 // Which team
1794 if Pos('r', EvStr) > 0 then
1795 i2 := I_PLAYER_SCORE_RED
1796 else
1797 i2 := I_PLAYER_SCORE_BLUE;
1798 g_Console_Add(Format(_lc[i1], [_lc[i2], cnt]), True);
1799 end;
1800 end else
1801 begin
1802 // Game Win
1803 if Pos('e', EvStr) = 0 then
1804 i1 := I_PLAYER_SCORE_WIN_OWN
1805 else
1806 i1 := I_PLAYER_SCORE_WIN_ENEMY;
1807 // Which team
1808 if Pos('r', EvStr) > 0 then
1809 i2 := I_PLAYER_SCORE_TO_RED
1810 else
1811 i2 := I_PLAYER_SCORE_TO_BLUE;
1812 g_Console_Add(Format(_lc[i1], [pln, _lc[i2]]), True);
1813 end;
1814 end;
1816 NET_EV_SCORE_MSG:
1817 begin
1818 if EvNum = TEAM_RED then
1819 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1820 if EvNum = TEAM_BLUE then
1821 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1822 if EvNum = -TEAM_RED then
1823 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1824 if EvNum = -TEAM_BLUE then
1825 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1826 end;
1828 NET_EV_LMS_START:
1829 begin
1830 g_Player_RemoveAllCorpses;
1831 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
1832 end;
1834 NET_EV_LMS_WIN:
1835 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(EvStr)]), 144);
1837 NET_EV_TLMS_WIN:
1838 begin
1839 if EvNum = TEAM_RED then
1840 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
1841 if EvNum = TEAM_BLUE then
1842 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
1843 end;
1845 NET_EV_LMS_LOSE:
1846 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
1848 NET_EV_LMS_DRAW:
1849 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
1851 NET_EV_KILLCOMBO:
1852 g_Game_Announce_KillCombo(EvNum);
1854 NET_EV_PLAYER_TOUCH:
1855 begin
1856 pl := g_Player_Get(EvNum);
1857 if pl <> nil then
1858 pl.Touch();
1859 end;
1861 end;
1862 end;
1864 procedure MC_RECV_FlagEvent(P: Pointer);
1865 var
1866 PID: Word;
1867 Pl: TPlayer;
1868 EvType: Byte;
1869 Fl: Byte;
1870 Quiet: Boolean;
1871 s, ts: string;
1872 begin
1873 EvType := e_Raw_Read_Byte(P);
1874 Fl := e_Raw_Read_Byte(P);
1876 if Fl = FLAG_NONE then Exit;
1878 Quiet := (e_Raw_Read_Byte(P) <> 0);
1879 PID := e_Raw_Read_Word(P);
1881 gFlags[Fl].State := e_Raw_Read_Byte(P);
1882 gFlags[Fl].CaptureTime := e_Raw_Read_LongWord(P);
1883 gFlags[Fl].Obj.X := e_Raw_Read_LongInt(P);
1884 gFlags[Fl].Obj.Y := e_Raw_Read_LongInt(P);
1885 gFlags[Fl].Obj.Vel.X := e_Raw_Read_LongInt(P);
1886 gFlags[Fl].Obj.Vel.Y := e_Raw_Read_LongInt(P);
1888 Pl := g_Player_Get(PID);
1889 if (Pl = nil) and
1890 (EvType <> FLAG_STATE_NORMAL) and
1891 (EvType <> FLAG_STATE_DROPPED) and
1892 (EvType <> FLAG_STATE_RETURNED) then
1893 Exit;
1895 case EvType of
1896 FLAG_STATE_NORMAL:
1897 begin
1898 if Quiet or (Pl = nil) then Exit;
1900 if Fl = FLAG_RED then
1901 s := _lc[I_PLAYER_FLAG_RED]
1902 else
1903 s := _lc[I_PLAYER_FLAG_BLUE];
1905 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
1906 end;
1908 FLAG_STATE_CAPTURED:
1909 begin
1910 if (Pl <> nil) then Pl.SetFlag(Fl);
1912 if Quiet then Exit;
1914 if Fl = FLAG_RED then
1915 s := _lc[I_PLAYER_FLAG_RED]
1916 else
1917 s := _lc[I_PLAYER_FLAG_BLUE];
1919 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [Pl.Name, s]), True);
1920 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
1921 end;
1923 FLAG_STATE_DROPPED:
1924 begin
1925 if (Pl <> nil) then Pl.SetFlag(FLAG_NONE);
1927 if Quiet or (Pl = nil) then Exit;
1929 if Fl = FLAG_RED then
1930 s := _lc[I_PLAYER_FLAG_RED]
1931 else
1932 s := _lc[I_PLAYER_FLAG_BLUE];
1934 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [Pl.Name, s]), True);
1935 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
1936 end;
1938 FLAG_STATE_SCORED:
1939 begin
1940 g_Map_ResetFlag(FLAG_RED);
1941 g_Map_ResetFlag(FLAG_BLUE);
1942 if Quiet or (Pl = nil) then Exit;
1943 Pl.SetFlag(FLAG_NONE);
1945 if Fl = FLAG_RED then
1946 s := _lc[I_PLAYER_FLAG_RED]
1947 else
1948 s := _lc[I_PLAYER_FLAG_BLUE];
1950 ts := Format('%.4d', [gFlags[Fl].CaptureTime]);
1951 Insert('.', ts, Length(ts) + 1 - 3);
1952 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [Pl.Name, s, ts]), True);
1953 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
1954 end;
1956 FLAG_STATE_RETURNED:
1957 begin
1958 g_Map_ResetFlag(Fl);
1959 if Quiet then Exit;
1961 if Fl = FLAG_RED then
1962 s := _lc[I_PLAYER_FLAG_RED]
1963 else
1964 s := _lc[I_PLAYER_FLAG_BLUE];
1966 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
1967 end;
1968 end;
1969 end;
1971 procedure MC_RECV_GameSettings(P: Pointer);
1972 begin
1973 gGameSettings.GameMode := e_Raw_Read_Byte(P);
1974 gGameSettings.GoalLimit := e_Raw_Read_Word(P);
1975 gGameSettings.TimeLimit := e_Raw_Read_Word(P);
1976 gGameSettings.MaxLives := e_Raw_Read_Byte(P);
1977 gGameSettings.Options := e_Raw_Read_LongWord(P);
1978 end;
1980 // PLAYER
1982 function MC_RECV_PlayerCreate(P: Pointer): Word;
1983 var
1984 PID, DID: Word;
1985 PName, Model: string;
1986 Color: TRGB;
1987 T: Byte;
1988 Pl: TPlayer;
1989 begin
1990 PID := e_Raw_Read_Word(P);
1991 Pl := g_Player_Get(PID);
1993 PName := e_Raw_Read_String(P);
1994 Model := e_Raw_Read_String(P);
1995 Color.R := e_Raw_Read_Byte(P);
1996 Color.G := e_Raw_Read_Byte(P);
1997 Color.B := e_Raw_Read_Byte(P);
1998 T := e_Raw_Read_Byte(P);
2000 Result := 0;
2001 if (PID <> NetPlrUID1) and (PID <> NetPlrUID2) then
2002 begin
2003 if (Pl <> nil) then Exit;
2004 DID := g_Player_Create(Model, Color, T, False);
2005 with g_Player_Get(DID) do
2006 begin
2007 UID := PID;
2008 Name := PName;
2009 Reset(True);
2010 end;
2011 end
2012 else
2013 begin
2014 if (PID = NetPlrUID1) and (gPlayer1 <> nil) then begin
2015 gPlayer1.UID := PID;
2016 gPlayer1.Model.SetColor(Color.R, Color.G, Color.B);
2017 gPlayer1.ChangeTeam(T);
2018 end;
2019 if (PID = NetPlrUID2) and (gPlayer2 <> nil) then begin
2020 gPlayer2.UID := PID;
2021 gPlayer2.Model.SetColor(Color.R, Color.G, Color.B);
2022 gPlayer2.ChangeTeam(T);
2023 end;
2024 end;
2026 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
2027 e_WriteLog('NET: Player ' + PName + ' [' + IntToStr(PID) + '] added.', MSG_NOTIFY);
2028 Result := PID;
2029 end;
2031 function MC_RECV_PlayerPos(P: Pointer): Word;
2032 var
2033 GT: LongWord;
2034 PID: Word;
2035 kByte: Word;
2036 Pl: TPlayer;
2037 Dir: Byte;
2038 TmpX, TmpY: Integer;
2039 begin
2040 Result := 0;
2042 GT := e_Raw_Read_LongWord(P);
2043 if GT < gTime - NET_MAX_DIFFTIME then
2044 begin
2045 gTime := GT;
2046 Exit;
2047 end;
2048 gTime := GT;
2050 PID := e_Raw_Read_Word(P);
2051 Pl := g_Player_Get(PID);
2053 if Pl = nil then Exit;
2055 Result := PID;
2057 with Pl do
2058 begin
2059 FPing := e_Raw_Read_Word(P);
2060 FLoss := e_Raw_Read_Byte(P);
2061 kByte := e_Raw_Read_Word(P);
2062 Dir := e_Raw_Read_Byte(P);
2064 TmpX := e_Raw_Read_LongInt(P);
2065 TmpY := e_Raw_Read_LongInt(P);
2067 ReleaseKeys;
2069 if (kByte = NET_KEY_CHAT) then
2070 PressKey(KEY_CHAT, 10000)
2071 else
2072 begin
2073 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
2074 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
2075 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
2076 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
2077 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
2078 end;
2080 if ((Pl <> gPlayer1) and (Pl <> gPlayer2)) or LongBool(kByte and NET_KEY_FORCEDIR) then
2081 SetDirection(TDirection(Dir));
2083 GameVelX := e_Raw_Read_LongInt(P);
2084 GameVelY := e_Raw_Read_LongInt(P);
2085 GameAccelX := e_Raw_Read_LongInt(P);
2086 GameAccelY := e_Raw_Read_LongInt(P);
2087 SetLerp(TmpX, TmpY);
2088 if NetForcePlayerUpdate then Update();
2089 end;
2090 end;
2092 function MC_RECV_PlayerStats(P: Pointer): Word;
2093 var
2094 PID: Word;
2095 Pl: TPlayer;
2096 I: Integer;
2097 OldJet: Boolean;
2098 NewTeam: Byte;
2099 begin
2100 PID := e_Raw_Read_Word(P);
2101 Pl := g_Player_Get(PID);
2102 Result := 0;
2103 if Pl = nil then
2104 Exit;
2106 with Pl do
2107 begin
2108 Live := (e_Raw_Read_Byte(P) <> 0);
2109 GodMode := (e_Raw_Read_Byte(P) <> 0);
2110 Health := e_Raw_Read_LongInt(P);
2111 Armor := e_Raw_Read_LongInt(P);
2112 Air := e_Raw_Read_LongInt(P);
2113 JetFuel := e_Raw_Read_LongInt(P);
2114 Lives := e_Raw_Read_Byte(P);
2115 NewTeam := e_Raw_Read_Byte(P);
2117 for I := WEAPON_KASTET to WEAPON_SUPERPULEMET do
2118 FWeapon[I] := (e_Raw_Read_Byte(P) <> 0);
2120 for I := A_BULLETS to A_CELLS do
2121 FAmmo[I] := e_Raw_Read_Word(P);
2123 for I := A_BULLETS to A_CELLS do
2124 FMaxAmmo[I] := e_Raw_Read_Word(P);
2126 for I := MR_SUIT to MR_MAX do
2127 FMegaRulez[I] := e_Raw_Read_LongWord(P);
2129 FRulez := [];
2130 if (e_Raw_Read_Byte(P) <> 0) then
2131 FRulez := FRulez + [R_ITEM_BACKPACK];
2132 if (e_Raw_Read_Byte(P) <> 0) then
2133 FRulez := FRulez + [R_KEY_RED];
2134 if (e_Raw_Read_Byte(P) <> 0) then
2135 FRulez := FRulez + [R_KEY_GREEN];
2136 if (e_Raw_Read_Byte(P) <> 0) then
2137 FRulez := FRulez + [R_KEY_BLUE];
2138 if (e_Raw_Read_Byte(P) <> 0) then
2139 FRulez := FRulez + [R_BERSERK];
2141 Frags := e_Raw_Read_LongInt(P);
2142 Death := e_Raw_Read_LongInt(P);
2144 SetWeapon(e_Raw_Read_Byte(P));
2146 FSpectator := e_Raw_Read_Byte(P) <> 0;
2147 if FSpectator then
2148 begin
2149 if Pl = gPlayer1 then
2150 begin
2151 gLMSPID1 := UID;
2152 gPlayer1 := nil;
2153 end;
2154 if Pl = gPlayer2 then
2155 begin
2156 gLMSPID2 := UID;
2157 gPlayer2 := nil;
2158 end;
2159 end
2160 else
2161 begin
2162 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
2163 gPlayer1 := g_Player_Get(gLMSPID1);
2164 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
2165 gPlayer2 := g_Player_Get(gLMSPID2);
2166 end;
2167 FGhost := e_Raw_Read_Byte(P) <> 0;
2168 FPhysics := e_Raw_Read_Byte(P) <> 0;
2169 FNoRespawn := e_Raw_Read_Byte(P) <> 0;
2170 OldJet := FJetpack;
2171 FJetpack := e_Raw_Read_Byte(P) <> 0;
2172 if OldJet and not FJetpack then
2173 JetpackOff
2174 else if not OldJet and FJetpack then
2175 JetpackOn;
2176 if Team <> NewTeam then
2177 Pl.ChangeTeam(NewTeam);
2178 end;
2180 Result := PID;
2181 end;
2183 function MC_RECV_PlayerDamage(P: Pointer): Word;
2184 var
2185 PID: Word;
2186 Pl: TPlayer;
2187 Kind: Byte;
2188 Attacker, Value: Word;
2189 VX, VY: Integer;
2190 begin
2191 Result := 0;
2192 if not gGameOn then Exit;
2193 PID := e_Raw_Read_Word(P);
2194 Pl := g_Player_Get(PID);
2195 if Pl = nil then Exit;
2197 Kind := e_Raw_Read_Byte(P);
2198 Attacker := e_Raw_Read_Word(P);
2199 Value := e_Raw_Read_Word(P);
2200 VX := e_Raw_Read_Word(P);
2201 VY := e_Raw_Read_Word(P);
2203 with Pl do
2204 Damage(Value, Attacker, VX, VY, Kind);
2206 Result := PID;
2207 end;
2209 function MC_RECV_PlayerDeath(P: Pointer): Word;
2210 var
2211 PID: Word;
2212 Pl: TPlayer;
2213 KillType, DeathType: Byte;
2214 Attacker: Word;
2215 begin
2216 Result := 0;
2217 if not gGameOn then Exit;
2218 PID := e_Raw_Read_Word(P);
2219 Pl := g_Player_Get(PID);
2220 if Pl = nil then Exit;
2222 KillType := e_Raw_Read_Byte(P);
2223 DeathType := e_Raw_Read_Byte(P);
2224 Attacker := e_Raw_Read_Word(P);
2226 with Pl do
2227 begin
2228 Kill(KillType, Attacker, DeathType);
2229 SoftReset;
2230 end;
2231 end;
2233 function MC_RECV_PlayerDelete(P: Pointer): Word;
2234 var
2235 PID: Word;
2236 Pl: TPlayer;
2237 begin
2238 PID := e_Raw_Read_Word(P);
2239 Pl := g_Player_Get(PID);
2240 Result := 0;
2241 if Pl = nil then Exit;
2243 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2244 e_WriteLog('NET: Player ' + Pl.Name + ' [' + IntToStr(PID) + '] removed.', MSG_NOTIFY);
2246 g_Player_Remove(PID);
2248 Result := PID;
2249 end;
2251 function MC_RECV_PlayerFire(P: Pointer): Word;
2252 var
2253 PID: Word;
2254 Weap: Byte;
2255 Pl: TPlayer;
2256 X, Y, AX, AY: Integer;
2257 SHID: Integer;
2258 begin
2259 Result := 0;
2260 if not gGameOn then Exit;
2261 PID := e_Raw_Read_Word(P);
2262 Pl := g_Player_Get(PID);
2263 if Pl = nil then Exit;
2265 Weap := e_Raw_Read_Byte(P);
2266 X := e_Raw_Read_LongInt(P);
2267 Y := e_Raw_Read_LongInt(P);
2268 AX := e_Raw_Read_LongInt(P);
2269 AY := e_Raw_Read_LongInt(P);
2270 SHID := e_Raw_Read_LongInt(P);
2272 with Pl do
2273 if Live then NetFire(Weap, X, Y, AX, AY, SHID);
2274 end;
2276 procedure MC_RECV_PlayerSettings(P: Pointer);
2277 var
2278 TmpName: string;
2279 TmpModel: string;
2280 TmpColor: TRGB;
2281 TmpTeam: Byte;
2282 Pl: TPlayer;
2283 PID: Word;
2284 begin
2285 PID := e_Raw_Read_Word(P);
2286 Pl := g_Player_Get(PID);
2287 if Pl = nil then Exit;
2289 TmpName := e_Raw_Read_String(P);
2290 TmpModel := e_Raw_Read_String(P);
2291 TmpColor.R := e_Raw_Read_Byte(P);
2292 TmpColor.G := e_Raw_Read_Byte(P);
2293 TmpColor.B := e_Raw_Read_Byte(P);
2294 TmpTeam := e_Raw_Read_Byte(P);
2296 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
2297 begin
2298 Pl.ChangeTeam(TmpTeam);
2299 if gPlayer1 = Pl then
2300 gPlayer1Settings.Team := TmpTeam;
2301 if gPlayer2 = Pl then
2302 gPlayer2Settings.Team := TmpTeam;
2303 end else
2304 Pl.SetColor(TmpColor);
2306 if Pl.Name <> TmpName then
2307 begin
2308 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
2309 Pl.Name := TmpName;
2310 end;
2312 if TmpModel <> Pl.Model.Name then
2313 Pl.SetModel(TmpModel);
2314 end;
2316 // ITEM
2318 procedure MC_RECV_ItemSpawn(P: Pointer);
2319 var
2320 ID: Word;
2321 AID: DWord;
2322 X, Y, VX, VY: Integer;
2323 T: Byte;
2324 Quiet, Fall{, Resp}: Boolean;
2325 Anim: TAnimation;
2326 begin
2327 if not gGameOn then Exit;
2328 ID := e_Raw_Read_Word(P);
2329 Quiet := e_Raw_Read_Byte(P) <> 0;
2330 T := e_Raw_Read_Byte(P);
2331 Fall := e_Raw_Read_Byte(P) <> 0;
2332 {Resp :=} e_Raw_Read_Byte(P);
2333 X := e_Raw_Read_LongInt(P);
2334 Y := e_Raw_Read_LongInt(P);
2335 VX := e_Raw_Read_LongInt(P);
2336 VY := e_Raw_Read_LongInt(P);
2338 g_Items_Create(X, Y, T, Fall, False, False, ID);
2339 gItems[ID].Obj.Vel.X := VX;
2340 gItems[ID].Obj.Vel.Y := VY;
2342 if not Quiet then
2343 begin
2344 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
2345 if g_Frames_Get(AID, 'FRAMES_ITEM_RESPAWN') then
2346 begin
2347 Anim := TAnimation.Create(AID, False, 4);
2348 g_GFX_OnceAnim(X+(gItems[ID].Obj.Rect.Width div 2)-16, Y+(gItems[ID].Obj.Rect.Height div 2)-16, Anim);
2349 Anim.Free();
2350 end;
2351 end;
2352 end;
2354 procedure MC_RECV_ItemDestroy(P: Pointer);
2355 var
2356 ID: Word;
2357 Quiet: Boolean;
2358 begin
2359 if not gGameOn then Exit;
2360 ID := e_Raw_Read_Word(P);
2361 Quiet := e_Raw_Read_Byte(P) <> 0;
2362 if gItems = nil then Exit;
2363 if (ID > High(gItems)) then Exit;
2365 if not Quiet then
2366 if gSoundEffectsDF then
2367 begin
2368 if gItems[ID].ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL,
2369 ITEM_INVIS, ITEM_MEDKIT_BLACK, ITEM_JETPACK] then
2370 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ',
2371 gItems[ID].Obj.X, gItems[ID].Obj.Y)
2372 else
2373 if gItems[ID].ItemType in [ITEM_WEAPON_SAW, ITEM_WEAPON_PISTOL, ITEM_WEAPON_SHOTGUN1, ITEM_WEAPON_SHOTGUN2,
2374 ITEM_WEAPON_CHAINGUN, ITEM_WEAPON_ROCKETLAUNCHER, ITEM_WEAPON_PLASMA,
2375 ITEM_WEAPON_BFG, ITEM_WEAPON_SUPERPULEMET, ITEM_AMMO_BACKPACK] then
2376 g_Sound_PlayExAt('SOUND_ITEM_GETWEAPON',
2377 gItems[ID].Obj.X, gItems[ID].Obj.Y)
2378 else
2379 g_Sound_PlayExAt('SOUND_ITEM_GETITEM',
2380 gItems[ID].Obj.X, gItems[ID].Obj.Y);
2381 end
2382 else
2383 begin
2384 if gItems[ID].ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_SUIT,
2385 ITEM_MEDKIT_BLACK, ITEM_INVUL, ITEM_INVIS, ITEM_JETPACK] then
2386 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ',
2387 gItems[ID].Obj.X, gItems[ID].Obj.Y)
2388 else
2389 if gItems[ID].ItemType in [ITEM_WEAPON_SAW, ITEM_WEAPON_PISTOL, ITEM_WEAPON_SHOTGUN1, ITEM_WEAPON_SHOTGUN2,
2390 ITEM_WEAPON_CHAINGUN, ITEM_WEAPON_ROCKETLAUNCHER, ITEM_WEAPON_PLASMA,
2391 ITEM_WEAPON_BFG, ITEM_WEAPON_SUPERPULEMET] then
2392 g_Sound_PlayExAt('SOUND_ITEM_GETWEAPON',
2393 gItems[ID].Obj.X, gItems[ID].Obj.Y)
2394 else
2395 g_Sound_PlayExAt('SOUND_ITEM_GETITEM',
2396 gItems[ID].Obj.X, gItems[ID].Obj.Y);
2397 end;
2399 g_Items_Remove(ID);
2400 end;
2402 // PANEL
2404 procedure MC_RECV_PanelTexture(P: Pointer);
2405 var
2406 TP: TPanel;
2407 PType: Word;
2408 ID: LongWord;
2409 Tex, Fr: Integer;
2410 Loop, Cnt: Byte;
2411 begin
2412 if not gGameOn then Exit;
2413 PType := e_Raw_Read_Word(P);
2414 ID := e_Raw_Read_LongWord(P);
2415 Tex := e_Raw_Read_LongInt(P);
2416 Fr := e_Raw_Read_LongInt(P);
2417 Cnt := e_Raw_Read_Byte(P);
2418 Loop := e_Raw_Read_Byte(P);
2420 TP := nil;
2422 case PType of
2423 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
2424 if gWalls <> nil then
2425 TP := gWalls[ID];
2426 PANEL_FORE:
2427 if gRenderForegrounds <> nil then
2428 TP := gRenderForegrounds[ID];
2429 PANEL_BACK:
2430 if gRenderBackgrounds <> nil then
2431 TP := gRenderBackgrounds[ID];
2432 PANEL_WATER:
2433 if gWater <> nil then
2434 TP := gWater[ID];
2435 PANEL_ACID1:
2436 if gAcid1 <> nil then
2437 TP := gAcid1[ID];
2438 PANEL_ACID2:
2439 if gAcid2 <> nil then
2440 TP := gAcid2[ID];
2441 PANEL_STEP:
2442 if gSteps <> nil then
2443 TP := gSteps[ID];
2444 else
2445 Exit;
2446 end;
2448 if TP <> nil then
2449 if Loop = 0 then
2450 begin // switch texture
2451 TP.SetTexture(Tex, Loop);
2452 TP.SetFrame(Fr, Cnt);
2453 end else // looped or non-looped animation
2454 TP.NextTexture(Loop);
2455 end;
2457 procedure MC_RECV_PanelState(P: Pointer);
2458 var
2459 ID: LongWord;
2460 E: Boolean;
2461 Lift: Byte;
2462 PType: Word;
2463 X, Y: Integer;
2464 begin
2465 if not gGameOn then Exit;
2466 PType := e_Raw_Read_Word(P);
2467 ID := e_Raw_Read_LongWord(P);
2468 E := (e_Raw_Read_Byte(P) <> 0);
2469 Lift := e_Raw_Read_Byte(P);
2470 X := e_Raw_Read_LongInt(P);
2471 Y := e_Raw_Read_LongInt(P);
2473 case PType of
2474 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
2475 if E then
2476 g_Map_EnableWall(ID)
2477 else
2478 g_Map_DisableWall(ID);
2480 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT:
2481 g_Map_SetLift(ID, Lift);
2483 PANEL_BACK:
2484 begin
2485 gRenderBackgrounds[ID].X := X;
2486 gRenderBackgrounds[ID].Y := Y;
2487 end;
2489 PANEL_FORE:
2490 begin
2491 gRenderForegrounds[ID].X := X;
2492 gRenderForegrounds[ID].Y := Y;
2493 end;
2494 end;
2495 end;
2497 // TRIGGERS
2499 procedure MC_RECV_TriggerSound(P: Pointer);
2500 var
2501 SPlaying: Boolean;
2502 SPos, SID: LongWord;
2503 SCount: LongInt;
2504 I: Integer;
2505 begin
2506 if not gGameOn then Exit;
2507 if gTriggers = nil then Exit;
2509 SID := e_Raw_Read_LongWord(P);
2510 SPlaying := e_Raw_Read_Byte(P) <> 0;
2511 SPos := e_Raw_Read_LongWord(P);
2512 SCount := e_Raw_Read_LongInt(P);
2514 for I := Low(gTriggers) to High(gTriggers) do
2515 if gTriggers[I].TriggerType = TRIGGER_SOUND then
2516 if gTriggers[I].ClientID = SID then
2517 with gTriggers[I] do
2518 begin
2519 if SPlaying then
2520 begin
2521 if Data.Local then
2522 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), Data.Volume/255.0)
2523 else
2524 Sound.PlayPanVolume((Data.Pan-127.0)/128.0, Data.Volume/255.0);
2525 Sound.SetPosition(SPos);
2526 end
2527 else
2528 if Sound.IsPlaying then Sound.Stop;
2530 SoundPlayCount := SCount;
2531 end;
2532 end;
2534 procedure MC_RECV_TriggerMusic(P: Pointer);
2535 var
2536 MName: string;
2537 MPlaying: Boolean;
2538 MPos: LongWord;
2539 MPaused: Boolean;
2540 begin
2541 if not gGameOn then Exit;
2543 MName := e_Raw_Read_String(P);
2544 MPlaying := e_Raw_Read_Byte(P) <> 0;
2545 MPos := e_Raw_Read_LongWord(P);
2546 MPaused := e_Raw_Read_Byte(P) <> 0;
2548 if MPlaying then
2549 begin
2550 gMusic.SetByName(MName);
2551 gMusic.Play(True);
2552 gMusic.SetPosition(MPos);
2553 gMusic.SpecPause := MPaused;
2554 end
2555 else
2556 if gMusic.IsPlaying then gMusic.Stop;
2557 end;
2559 // MONSTERS
2561 procedure MC_RECV_MonsterSpawn(P: Pointer);
2562 var
2563 ID: Word;
2564 MType, MState, MDir, MAnim, MBehav: Byte;
2565 X, Y, VX, VY, MTargTime, MHealth, MAmmo, MSleep: Integer;
2566 MTarg: Word;
2567 M: TMonster;
2568 begin
2569 ID := e_Raw_Read_Word(P);
2570 M := g_Monsters_Get(ID);
2571 if M <> nil then
2572 Exit;
2574 MType := e_Raw_Read_Byte(P);
2575 MState := e_Raw_Read_Byte(P);
2576 MAnim := e_Raw_Read_Byte(P);
2577 MTarg := e_Raw_Read_Word(P);
2578 MTargTime := e_Raw_Read_LongInt(P);
2579 MBehav := e_Raw_Read_Byte(P);
2580 MSleep := e_Raw_Read_LongInt(P);
2581 MHealth := e_Raw_Read_LongInt(P);
2582 MAmmo := e_Raw_Read_LongInt(P);
2584 X := e_Raw_Read_LongInt(P);
2585 Y := e_Raw_Read_LongInt(P);
2586 VX := e_Raw_Read_LongInt(P);
2587 VY := e_Raw_Read_LongInt(P);
2588 MDir := e_Raw_Read_Byte(P);
2590 g_Monsters_Create(MType, X, Y, TDirection(MDir), False, ID);
2591 M := g_Monsters_Get(ID);
2592 if M = nil then
2593 Exit;
2595 with M do
2596 begin
2597 GameX := X;
2598 GameY := Y;
2599 GameVelX := VX;
2600 GameVelY := VY;
2602 MonsterAnim := MAnim;
2603 MonsterTargetUID := MTarg;
2604 MonsterTargetTime := MTargTime;
2605 MonsterBehaviour := MBehav;
2606 MonsterSleep := MSleep;
2607 MonsterAmmo := MAmmo;
2608 SetHealth(MHealth);
2610 SetState(MState);
2611 end;
2612 end;
2614 procedure MC_RECV_MonsterPos(P: Pointer);
2615 var
2616 M: TMonster;
2617 ID: Word;
2618 begin
2619 ID := e_Raw_Read_Word(P);
2620 M := g_Monsters_Get(ID);
2621 if M = nil then
2622 Exit;
2624 with M do
2625 begin
2626 GameX := e_Raw_Read_LongInt(P);
2627 GameY := e_Raw_Read_LongInt(P);
2628 GameVelX := e_Raw_Read_LongInt(P);
2629 GameVelY := e_Raw_Read_LongInt(P);
2630 GameDirection := TDirection(e_Raw_Read_Byte(P));
2631 end;
2632 end;
2634 procedure MC_RECV_MonsterState(P: Pointer);
2635 var
2636 ID: Integer;
2637 MState, MFAnm: Byte;
2638 M: TMonster;
2639 AnimRevert: Boolean;
2640 begin
2641 ID := e_Raw_Read_Word(P);
2642 M := g_Monsters_Get(ID);
2643 if M = nil then Exit;
2645 MState := e_Raw_Read_Byte(P);
2646 MFAnm := e_Raw_Read_Byte(P);
2648 with M do
2649 begin
2650 MonsterTargetUID := e_Raw_Read_Word(P);
2651 MonsterTargetTime := e_Raw_Read_LongInt(P);
2652 MonsterSleep := e_Raw_Read_LongInt(P);
2653 MonsterHealth := e_Raw_Read_LongInt(P);
2654 MonsterAmmo := e_Raw_Read_LongInt(P);
2655 MonsterPain := e_Raw_Read_LongInt(P);
2656 AnimRevert := e_Raw_Read_Byte(P) <> 0;
2657 RevertAnim(AnimRevert);
2659 if MonsterState <> MState then
2660 begin
2661 if (MState = MONSTATE_GO) and (MonsterState = MONSTATE_SLEEP) then
2662 WakeUpSound;
2663 if (MState = MONSTATE_DIE) then
2664 DieSound;
2665 if (MState = MONSTATE_PAIN) then
2666 MakeBloodSimple(Min(200, MonsterPain));
2667 if (MState = MONSTATE_ATTACK) then
2668 kick(nil);
2669 if (MState = MONSTATE_DEAD) then
2670 SetDeadAnim;
2672 SetState(MState, MFAnm);
2673 end;
2674 end;
2675 end;
2677 procedure MC_RECV_MonsterShot(P: Pointer);
2678 var
2679 ID: Integer;
2680 M: TMonster;
2681 X, Y, VX, VY: Integer;
2682 begin
2683 ID := e_Raw_Read_Word(P);
2685 M := g_Monsters_Get(ID);
2686 if M = nil then Exit;
2688 X := e_Raw_Read_LongInt(P);
2689 Y := e_Raw_Read_LongInt(P);
2690 VX := e_Raw_Read_LongInt(P);
2691 VY := e_Raw_Read_LongInt(P);
2693 M.ClientAttack(X, Y, VX, VY);
2694 end;
2696 procedure MC_RECV_MonsterDelete(P: Pointer);
2697 var
2698 ID: Integer;
2699 M: TMonster;
2700 begin
2701 ID := e_Raw_Read_Word(P);
2702 M := g_Monsters_Get(ID);
2703 if M = nil then Exit;
2705 gMonsters[ID].SetState(5);
2706 gMonsters[ID].MonsterRemoved := True;
2707 end;
2709 procedure MC_RECV_TimeSync(P: Pointer);
2710 var
2711 Time: LongWord;
2712 begin
2713 Time := e_Raw_Read_LongWord(P);
2715 if gState = STATE_INTERCUSTOM then
2716 gServInterTime := Min(Time, 255);
2717 end;
2719 procedure MC_RECV_VoteEvent(P: Pointer);
2720 var
2721 EvID: Byte;
2722 Str1, Str2: string;
2723 Int1, Int2: SmallInt;
2724 begin
2725 EvID := e_Raw_Read_Byte(P);
2726 Int1 := e_Raw_Read_SmallInt(P);
2727 Int2 := e_Raw_Read_SmallInt(P);
2728 Str1 := e_Raw_Read_String(P);
2729 Str2 := e_Raw_Read_String(P);
2731 case EvID of
2732 NET_VE_STARTED:
2733 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True);
2734 NET_VE_PASSED:
2735 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True);
2736 NET_VE_FAILED:
2737 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
2738 NET_VE_VOTE:
2739 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True);
2740 NET_VE_INPROGRESS:
2741 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True);
2742 end;
2743 end;
2745 // CLIENT SEND
2747 procedure MC_SEND_Info(Password: string);
2748 begin
2749 e_Buffer_Clear(@NetOut);
2751 e_Buffer_Write(@NetOut, Byte(NET_MSG_INFO));
2752 e_Buffer_Write(@NetOut, GAME_VERSION);
2753 e_Buffer_Write(@NetOut, Password);
2754 e_Buffer_Write(@NetOut, gPlayer1Settings.Name);
2755 e_Buffer_Write(@NetOut, gPlayer1Settings.Model);
2756 e_Buffer_Write(@NetOut, gPlayer1Settings.Color.R);
2757 e_Buffer_Write(@NetOut, gPlayer1Settings.Color.G);
2758 e_Buffer_Write(@NetOut, gPlayer1Settings.Color.B);
2759 e_Buffer_Write(@NetOut, gPlayer1Settings.Team);
2761 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2762 end;
2764 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
2765 begin
2766 e_Buffer_Write(@NetOut, Byte(NET_MSG_CHAT));
2767 e_Buffer_Write(@NetOut, Txt);
2768 e_Buffer_Write(@NetOut, Mode);
2770 g_Net_Client_Send(True, NET_CHAN_CHAT);
2771 end;
2773 function isKeyPressed (key1: Word; key2: Word): Boolean;
2774 begin
2775 if (key1 <> 0) and e_KeyPressed(key1) then begin result := true; exit; end;
2776 if (key2 <> 0) and e_KeyPressed(key2) then begin result := true; exit; end;
2777 result := false;
2778 end;
2780 procedure MC_SEND_PlayerPos();
2781 var
2782 kByte: Word;
2783 Predict: Boolean;
2784 begin
2785 if not gGameOn then Exit;
2786 if gPlayers = nil then Exit;
2787 if gPlayer1 = nil then Exit;
2789 kByte := 0;
2790 Predict := NetPredictSelf; // and (not NetGotKeys);
2792 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2793 with gGameControls.P1Control do
2794 begin
2795 if isKeyPressed(KeyLeft, KeyLeft2) and (not isKeyPressed(KeyRight, KeyRight2)) then P1MoveButton := 1
2796 else if (not isKeyPressed(KeyLeft, KeyLeft2)) and isKeyPressed(KeyRight, KeyRight2) then P1MoveButton := 2
2797 else if (not isKeyPressed(KeyLeft, KeyLeft2)) and (not isKeyPressed(KeyRight, KeyRight2)) then P1MoveButton := 0;
2799 if (P1MoveButton = 2) and isKeyPressed(KeyLeft, KeyLeft2) then gPlayer1.SetDirection(D_LEFT)
2800 else if (P1MoveButton = 1) and isKeyPressed(KeyRight, KeyRight2) then gPlayer1.SetDirection(D_RIGHT)
2801 else if P1MoveButton <> 0 then gPlayer1.SetDirection(TDirection(P1MoveButton-1));
2803 gPlayer1.ReleaseKeys;
2804 if P1MoveButton = 1 then
2805 begin
2806 kByte := kByte or NET_KEY_LEFT;
2807 if Predict then gPlayer1.PressKey(KEY_LEFT, 10000);
2808 end;
2809 if P1MoveButton = 2 then
2810 begin
2811 kByte := kByte or NET_KEY_RIGHT;
2812 if Predict then gPlayer1.PressKey(KEY_RIGHT, 10000);
2813 end;
2814 if isKeyPressed(KeyUp, KeyUp2) then
2815 begin
2816 kByte := kByte or NET_KEY_UP;
2817 gPlayer1.PressKey(KEY_UP, 10000);
2818 end;
2819 if isKeyPressed(KeyDown, KeyDown2) then
2820 begin
2821 kByte := kByte or NET_KEY_DOWN;
2822 gPlayer1.PressKey(KEY_DOWN, 10000);
2823 end;
2824 if isKeyPressed(KeyJump, KeyJump2) then
2825 begin
2826 kByte := kByte or NET_KEY_JUMP;
2827 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2828 end;
2829 if isKeyPressed(KeyFire, KeyFire2) then kByte := kByte or NET_KEY_FIRE;
2830 if isKeyPressed(KeyOpen, KeyOpen2) then kByte := kByte or NET_KEY_OPEN;
2831 if isKeyPressed(KeyNextWeapon, KeyNextWeapon2) then kByte := kByte or NET_KEY_NW;
2832 if isKeyPressed(KeyPrevWeapon, KeyPrevWeapon2) then kByte := kByte or NET_KEY_PW;
2833 end
2834 else
2835 kByte := NET_KEY_CHAT;
2837 e_Buffer_Write(@NetOut, Byte(NET_MSG_PLRPOS));
2838 e_Buffer_Write(@NetOut, gTime);
2839 e_Buffer_Write(@NetOut, kByte);
2840 e_Buffer_Write(@NetOut, Byte(gPlayer1.Direction));
2841 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS);
2843 //kBytePrev := kByte;
2844 //kDirPrev := gPlayer1.Direction;
2845 end;
2847 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
2848 begin
2849 e_Buffer_Write(@NetOut, Byte(NET_MSG_VOTE_EVENT));
2850 e_Buffer_Write(@NetOut, Byte(Start));
2851 e_Buffer_Write(@NetOut, Command);
2852 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2853 end;
2855 procedure MC_SEND_PlayerSettings();
2856 begin
2857 e_Buffer_Write(@NetOut, Byte(NET_MSG_PLRSET));
2858 e_Buffer_Write(@NetOut, gPlayer1Settings.Name);
2859 e_Buffer_Write(@NetOut, gPlayer1Settings.Model);
2860 e_Buffer_Write(@NetOut, gPlayer1Settings.Color.R);
2861 e_Buffer_Write(@NetOut, gPlayer1Settings.Color.G);
2862 e_Buffer_Write(@NetOut, gPlayer1Settings.Color.B);
2863 e_Buffer_Write(@NetOut, gPlayer1Settings.Team);
2865 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2866 end;
2868 procedure MC_SEND_FullStateRequest();
2869 begin
2870 e_Buffer_Write(@NetOut, Byte(NET_MSG_REQFST));
2872 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2873 end;
2875 procedure MC_SEND_CheatRequest(Kind: Byte);
2876 begin
2877 e_Buffer_Write(@NetOut, Byte(NET_MSG_CHEAT));
2878 e_Buffer_Write(@NetOut, Kind);
2880 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2881 end;
2882 procedure MC_SEND_RCONPassword(Password: string);
2883 begin
2884 e_Buffer_Write(@NetOut, Byte(NET_MSG_RCON_AUTH));
2885 e_Buffer_Write(@NetOut, Password);
2887 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2888 end;
2889 procedure MC_SEND_RCONCommand(Cmd: string);
2890 begin
2891 e_Buffer_Write(@NetOut, Byte(NET_MSG_RCON_CMD));
2892 e_Buffer_Write(@NetOut, Cmd);
2894 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2895 end;
2897 // i have no idea why all this stuff is in here
2899 function ReadFile(const FileName: TFileName): AByte;
2900 var
2901 FileStream : TStream;
2902 fname: string;
2903 begin
2904 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName]), MSG_NOTIFY);
2905 fname := findDiskWad(FileName);
2906 if length(fname) = 0 then
2907 begin
2908 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName]), MSG_FATALERROR);
2909 SetLength(Result, 0);
2910 exit;
2911 end;
2912 e_WriteLog(Format('NETWORK: found file "%s"', [fname]), MSG_NOTIFY);
2913 Result := nil;
2914 FileStream := openDiskFileRO(fname);
2915 try
2916 if FileStream.Size > 0 then
2917 begin
2918 SetLength(Result, FileStream.Size);
2919 FileStream.Read(Result[0], FileStream.Size);
2920 end;
2921 finally
2922 FileStream.Free;
2923 end;
2924 end;
2926 function CreateMapDataMsg(const FileName: TFileName; ResList: TStringList): TMapDataMsg;
2927 var
2928 i: Integer;
2929 begin
2930 Result.MsgId := NET_MSG_MAP_RESPONSE;
2931 Result.FileData := ReadFile(FileName);
2932 Result.FileSize := Length(Result.FileData);
2934 SetLength(Result.ExternalResources, ResList.Count);
2935 for i:=0 to ResList.Count-1 do
2936 begin
2937 Result.ExternalResources[i].Name := ResList.Strings[i];
2938 Result.ExternalResources[i].md5 := MD5File(GameDir+'/wads/'+ResList.Strings[i]);
2939 end;
2940 end;
2942 procedure ResDataMsgToBytes(var bytes: AByte; const ResData: TResDataMsg);
2943 var
2944 ResultStream: TMemoryStream;
2945 begin
2946 ResultStream := TMemoryStream.Create;
2948 ResultStream.WriteBuffer(ResData.MsgId, SizeOf(ResData.MsgId)); //msgId
2949 ResultStream.WriteBuffer(ResData.FileSize, SizeOf(ResData.FileSize)); //file size
2950 ResultStream.WriteBuffer(ResData.FileData[0], ResData.FileSize); //file data
2952 SetLength(bytes, ResultStream.Size);
2953 ResultStream.Seek(0, soFromBeginning);
2954 ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
2956 ResultStream.Free;
2957 end;
2959 function ResDataFromMsgStream(msgStream: TMemoryStream):TResDataMsg;
2960 begin
2961 msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
2962 msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize));
2963 SetLength(Result.FileData, Result.FileSize);
2964 msgStream.ReadBuffer(Result.FileData[0], Result.FileSize);
2965 end;
2967 procedure MapDataMsgToBytes(var bytes: AByte; const MapDataMsg: TMapDataMsg);
2968 var
2969 ResultStream: TMemoryStream;
2970 resCount: Integer;
2971 begin
2972 resCount := Length(MapDataMsg.ExternalResources);
2974 ResultStream := TMemoryStream.Create;
2976 ResultStream.WriteBuffer(MapDataMsg.MsgId, SizeOf(MapDataMsg.MsgId)); //msgId
2977 ResultStream.WriteBuffer(MapDataMsg.FileSize, SizeOf(MapDataMsg.FileSize)); //file size
2978 ResultStream.WriteBuffer(MapDataMsg.FileData[0], MapDataMsg.FileSize); //file data
2980 ResultStream.WriteBuffer(resCount, SizeOf(resCount)); //res count
2981 ResultStream.WriteBuffer(MapDataMsg.ExternalResources[0], resCount*SizeOf(TExternalResourceInfo)); //res data
2983 SetLength(bytes, ResultStream.Size);
2984 ResultStream.Seek(0, soFromBeginning);
2985 ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
2987 ResultStream.Free;
2988 end;
2990 function MapDataFromMsgStream(msgStream: TMemoryStream):TMapDataMsg;
2991 var
2992 resCount: Integer;
2993 begin
2994 msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
2995 msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize)); //file size
2997 SetLength(Result.FileData, Result.FileSize);
2998 msgStream.ReadBuffer(Result.FileData[0], Result.FileSize); //file data
3000 msgStream.ReadBuffer(resCount, SizeOf(resCount)); //res count
3001 SetLength(Result.ExternalResources, resCount);
3003 msgStream.ReadBuffer(Result.ExternalResources[0], resCount * SizeOf(TExternalResourceInfo)); //res data
3004 end;
3006 function IsValidFileName(const S: String): Boolean;
3007 const
3008 Forbidden: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
3009 var
3010 I: Integer;
3011 begin
3012 Result := S <> '';
3013 for I := 1 to Length(S) do
3014 Result := Result and (not(S[I] in Forbidden));
3015 end;
3017 function IsValidFilePath(const S: String): Boolean;
3018 var
3019 I: Integer;
3020 begin
3021 Result := False;
3022 if not IsValidFileName(S) then exit;
3023 if FileExists(S) then exit;
3024 I := LastDelimiter('\/', S);
3025 if (I > 0) then
3026 if (not DirectoryExists(Copy(S, 1, I-1))) then
3027 exit;
3028 Result := True;
3029 end;
3031 procedure MC_SEND_MapRequest();
3032 begin
3033 e_Buffer_Write(@NetOut, Byte(NET_MSG_MAP_REQUEST));
3034 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3035 end;
3037 procedure MC_SEND_ResRequest(const resName: AnsiString);
3038 begin
3039 e_Buffer_Write(@NetOut, Byte(NET_MSG_RES_REQUEST));
3040 e_Buffer_Write(@NetOut, resName);
3041 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3042 end;
3044 procedure MH_RECV_MapRequest(C: pTNetClient; P: Pointer);
3045 var
3046 payload: AByte;
3047 peer: pENetPeer;
3048 mapDataMsg: TMapDataMsg;
3049 begin
3050 e_WriteLog('NET: Received map request from ' +
3051 DecodeIPV4(C.Peer.address.host), MSG_NOTIFY);
3053 mapDataMsg := CreateMapDataMsg(MapsDir + gGameSettings.WAD, gExternalResources);
3054 peer := NetClients[C.ID].Peer;
3056 MapDataMsgToBytes(payload, mapDataMsg);
3057 g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
3059 payload := nil;
3060 mapDataMsg.FileData := nil;
3061 mapDataMsg.ExternalResources := nil;
3062 end;
3064 procedure MH_RECV_ResRequest(C: pTNetClient; P: Pointer);
3065 var
3066 payload: AByte;
3067 peer: pENetPeer;
3068 FileName: String;
3069 resDataMsg: TResDataMsg;
3070 begin
3071 FileName := ExtractFileName(e_Raw_Read_String(P));
3072 e_WriteLog('NET: Received res request: ' + FileName +
3073 ' from ' + DecodeIPV4(C.Peer.address.host), MSG_NOTIFY);
3075 if not IsValidFilePath(FileName) then
3076 begin
3077 e_WriteLog('Invalid filename: ' + FileName, MSG_WARNING);
3078 exit;
3079 end;
3081 peer := NetClients[C.ID].Peer;
3083 if gExternalResources.IndexOf(FileName) > -1 then
3084 begin
3085 resDataMsg.MsgId := NET_MSG_RES_RESPONSE;
3086 resDataMsg.FileData := ReadFile(GameDir+'/wads/'+FileName);
3087 resDataMsg.FileSize := Length(resDataMsg.FileData);
3089 ResDataMsgToBytes(payload, resDataMsg);
3090 g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
3091 end;
3092 end;
3094 end.