Refactor: Constants for first and last weapon
[d2df-sdl.git] / src / game / g_netmsg.pas
blobe838a9b7fff87f34eaceee923c3dc387feb14fe1
1 (* Copyright (C) DooM 2D:Forever Developers
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.
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.
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/>.
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);
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);
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);
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
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;
433 Dir, i: Byte;
434 WeaponSelect: Word;
435 PID: Word;
436 kByte: Word;
437 Pl: TPlayer;
438 GT: LongWord;
439 begin
440 Result := 0;
441 if not gGameOn then Exit;
443 GT := e_Raw_Read_LongWord(P);
444 PID := C^.Player;
445 Pl := g_Player_Get(PID);
446 if Pl = nil then
447 Exit;
449 if (GT > gTime + NET_MAX_DIFFTIME) or (GT < Pl.NetTime) then Exit;
451 with Pl do
452 begin
453 NetTime := GT;
454 kByte := e_Raw_Read_Word(P);
455 Dir := e_Raw_Read_Byte(P);
456 WeaponSelect := e_Raw_Read_Word(P);
457 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
458 if Direction <> TDirection(Dir) then
459 JustTeleported := False;
461 SetDirection(TDirection(Dir));
462 ReleaseKeys;
464 if kByte = NET_KEY_CHAT then
465 begin
466 PressKey(KEY_CHAT, 10000);
467 Exit;
468 end;
470 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
471 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
472 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
473 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
474 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
475 if LongBool(kByte and NET_KEY_FIRE) then PressKey(KEY_FIRE, 10000);
476 if LongBool(kByte and NET_KEY_OPEN) then PressKey(KEY_OPEN, 10000);
477 if LongBool(kByte and NET_KEY_NW) then PressKey(KEY_NEXTWEAPON, 10000);
478 if LongBool(kByte and NET_KEY_PW) then PressKey(KEY_PREVWEAPON, 10000);
480 for i := 0 to 15 do
481 begin
482 if (WeaponSelect and Word(1 shl i)) <> 0 then
483 begin
484 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
485 QueueWeaponSwitch(i);
486 end;
487 end;
488 end;
490 // MH_SEND_PlayerPos(False, PID, C^.ID);
491 end;
493 procedure MH_RECV_CheatRequest(C: pTNetClient; P: Pointer);
495 CheatKind: Byte;
496 Pl: TPlayer;
497 begin
498 Pl := g_Player_Get(C^.Player);
499 if Pl = nil then Exit;
501 CheatKind := e_Raw_Read_Byte(P);
503 case CheatKind of
504 NET_CHEAT_SUICIDE:
505 Pl.Damage(SUICIDE_DAMAGE, Pl.UID, 0, 0, HIT_SELF);
506 NET_CHEAT_SPECTATE:
507 begin
508 if Pl.FSpectator then
509 Pl.Respawn(False)
510 else
511 Pl.Spectate;
512 end;
513 end;
514 end;
516 procedure MH_RECV_PlayerSettings(C: pTNetClient; P: Pointer);
518 TmpName: string;
519 TmpModel: string;
520 TmpColor: TRGB;
521 TmpTeam: Byte;
522 Pl: TPlayer;
523 begin
524 TmpName := e_Raw_Read_String(P);
525 TmpModel := e_Raw_Read_String(P);
526 TmpColor.R := e_Raw_Read_Byte(P);
527 TmpColor.G := e_Raw_Read_Byte(P);
528 TmpColor.B := e_Raw_Read_Byte(P);
529 TmpTeam := e_Raw_Read_Byte(P);
531 Pl := g_Player_Get(C^.Player);
532 if Pl = nil then Exit;
534 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
535 Pl.SwitchTeam
536 else
537 Pl.SetColor(TmpColor);
539 if Pl.Name <> TmpName then
540 begin
541 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
542 Pl.Name := TmpName;
543 end;
545 if TmpModel <> Pl.Model.Name then
546 Pl.SetModel(TmpModel);
548 MH_SEND_PlayerSettings(Pl.UID, TmpModel);
549 end;
551 // RCON
553 procedure MH_RECV_RCONPassword(C: pTNetClient; P: Pointer);
555 Pwd: string;
556 begin
557 Pwd := e_Raw_Read_String(P);
558 if not NetAllowRCON then Exit;
559 if Pwd = NetRCONPassword then
560 begin
561 C^.RCONAuth := True;
562 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWGOOD, 'N', C^.ID);
564 else
565 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWBAD, 'N', C^.ID);
566 end;
568 procedure MH_RECV_RCONCommand(C: pTNetClient; P: Pointer);
570 Cmd: string;
571 begin
572 Cmd := e_Raw_Read_String(P);
573 if not NetAllowRCON then Exit;
574 if not C^.RCONAuth then
575 begin
576 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_NOAUTH, 'N', C^.ID);
577 Exit;
578 end;
579 g_Console_Process(Cmd);
580 end;
582 // MISC
584 procedure MH_RECV_Vote(C: pTNetClient; P: Pointer);
586 Start: Boolean;
587 Name, Command: string;
588 Need: Integer;
589 Pl: TPlayer;
590 begin
591 Start := e_Raw_Read_Byte(P) <> 0;
592 Command := e_Raw_Read_String(P);
594 Pl := g_Player_Get(C^.Player);
595 if Pl = nil then Exit;
596 Name := Pl.Name;
598 if Start then
599 begin
600 if not g_Console_CommandBlacklisted(Command) then
601 g_Game_StartVote(Command, Name);
603 else if gVoteInProgress then
604 begin
605 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
606 Need := Floor((NetClientCount+1)/2.0) + 1
607 else
608 Need := Floor(NetClientCount/2.0) + 1;
609 if C^.Voted then
610 begin
611 Dec(gVoteCount);
612 C^.Voted := False;
613 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [Name, gVoteCount, Need]), True);
614 MH_SEND_VoteEvent(NET_VE_REVOKE, Name, 'a', gVoteCount, Need);
616 else
617 begin
618 Inc(gVoteCount);
619 C^.Voted := True;
620 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Name, gVoteCount, Need]), True);
621 MH_SEND_VoteEvent(NET_VE_VOTE, Name, 'a', gVoteCount, Need);
622 g_Game_CheckVote;
623 end;
624 end;
625 end;
627 // GAME (SEND)
629 procedure MH_SEND_Everything(CreatePlayers: Boolean = False; ID: Integer = NET_EVERYONE);
631 I: Integer;
632 begin
633 if gPlayers <> nil then
634 for I := Low(gPlayers) to High(gPlayers) do
635 if gPlayers[I] <> nil then
636 begin
637 if CreatePlayers then MH_SEND_PlayerCreate(gPlayers[I].UID, ID);
638 MH_SEND_PlayerPos(True, gPlayers[I].UID, ID);
639 MH_SEND_PlayerStats(gPlayers[I].UID, ID);
641 if (gPlayers[I].Flag <> FLAG_NONE) and (gGameSettings.GameMode = GM_CTF) then
642 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED, gPlayers[I].Flag, gPlayers[I].UID, True, ID);
643 end;
645 if gItems <> nil then
646 begin
647 for I := High(gItems) downto Low(gItems) do
648 if gItems[I].Live then
649 MH_SEND_ItemSpawn(True, I, ID);
650 end;
652 if gMonsters <> nil then
653 for I := 0 to High(gMonsters) do
654 if gMonsters[I] <> nil then
655 MH_SEND_MonsterSpawn(gMonsters[I].UID, ID);
657 if gWalls <> nil then
658 for I := Low(gWalls) to High(gWalls) do
659 if gWalls[I] <> nil then
660 with gWalls[I] do
661 begin
662 if Door then
663 MH_SEND_PanelState(PanelType, I, ID);
665 if GetTextureCount > 1 then
666 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
667 end;
669 if gLifts <> nil then
670 for I := Low(gLifts) to High(gLifts) do
671 if gLifts[I] <> nil then
672 with gLifts[I] do
673 MH_SEND_PanelState(PanelType, I, ID);
675 if gRenderForegrounds <> nil then
676 for I := Low(gRenderForegrounds) to High(gRenderForegrounds) do
677 if gRenderForegrounds[I] <> nil then
678 with gRenderForegrounds[I] do
679 begin
680 if (GetTextureCount > 1) then
681 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
682 if Moved then
683 MH_SEND_PanelState(PanelType, I, ID);
684 end;
685 if gRenderBackgrounds <> nil then
686 for I := Low(gRenderBackgrounds) to High(gRenderBackgrounds) do
687 if gRenderBackgrounds[I] <> nil then
688 with gRenderBackgrounds[I] do
689 begin
690 if (GetTextureCount > 1) then
691 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
692 if Moved then
693 MH_SEND_PanelState(PanelType, I, ID);
694 end;
695 if gWater <> nil then
696 for I := Low(gWater) to High(gWater) do
697 if gWater[I] <> nil then
698 with gWater[I] do
699 if GetTextureCount > 1 then
700 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
701 if gAcid1 <> nil then
702 for I := Low(gAcid1) to High(gAcid1) do
703 if gAcid1[I] <> nil then
704 with gAcid1[I] do
705 if GetTextureCount > 1 then
706 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
707 if gAcid2 <> nil then
708 for I := Low(gAcid2) to High(gAcid2) do
709 if gAcid2[I] <> nil then
710 with gAcid2[I] do
711 if GetTextureCount > 1 then
712 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
713 if gSteps <> nil then
714 for I := Low(gSteps) to High(gSteps) do
715 if gSteps[I] <> nil then
716 with gSteps[I] do
717 if GetTextureCount > 1 then
718 MH_SEND_PanelTexture(PanelType, I, LastAnimLoop, ID);
720 if gTriggers <> nil then
721 for I := Low(gTriggers) to High(gTriggers) do
722 if gTriggers[I].TriggerType = TRIGGER_SOUND then
723 MH_SEND_TriggerSound(gTriggers[I], ID);
725 if Shots <> nil then
726 for I := Low(Shots) to High(Shots) do
727 if Shots[i].ShotType in [6, 7, 8] then
728 MH_SEND_CreateShot(i, ID);
730 MH_SEND_TriggerMusic(ID);
732 MH_SEND_GameStats(ID);
733 MH_SEND_CoopStats(ID);
735 if gGameSettings.GameMode = GM_CTF then
736 begin
737 if gFlags[FLAG_RED].State <> FLAG_STATE_CAPTURED then
738 MH_SEND_FlagEvent(gFlags[FLAG_RED].State, FLAG_RED, 0, True, ID);
739 if gFlags[FLAG_BLUE].State <> FLAG_STATE_CAPTURED then
740 MH_SEND_FlagEvent(gFlags[FLAG_BLUE].State, FLAG_BLUE, 0, True, ID);
741 end;
743 if CreatePlayers and (ID >= 0) then NetClients[ID].State := NET_STATE_GAME;
745 if gLMSRespawn > LMS_RESPAWN_NONE then
746 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000, 'N', ID);
747 end;
749 procedure MH_SEND_Info(ID: Byte);
751 Map: string;
752 begin
753 Map := g_ExtractFileName(gMapInfo.Map);
755 e_Buffer_Clear(@NetOut);
757 e_Buffer_Write(@NetOut, Byte(NET_MSG_INFO));
758 e_Buffer_Write(@NetOut, ID);
759 e_Buffer_Write(@NetOut, NetClients[ID].Player);
760 e_Buffer_Write(@NetOut, gGameSettings.WAD);
761 e_Buffer_Write(@NetOut, Map);
762 e_Buffer_Write(@NetOut, gWADHash);
763 e_Buffer_Write(@NetOut, gGameSettings.GameMode);
764 e_Buffer_Write(@NetOut, gGameSettings.GoalLimit);
765 e_Buffer_Write(@NetOut, gGameSettings.TimeLimit);
766 e_Buffer_Write(@NetOut, gGameSettings.MaxLives);
767 e_Buffer_Write(@NetOut, gGameSettings.Options);
768 e_Buffer_Write(@NetOut, gTime);
770 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
771 end;
773 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
775 Name: string;
776 i: Integer;
777 Team: Byte;
778 begin
779 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
780 Mode := NET_CHAT_PLAYER;
782 Team := 0;
783 if (Mode = NET_CHAT_TEAM) then
784 begin
785 for i := Low(gPlayers) to High(gPlayers) do
786 if (gPlayers[i] <> nil) and (gPlayers[i].FClientID >= 0) and
787 (gPlayers[i].Team = ID) then
788 begin
789 e_Buffer_Write(@NetOut, Byte(NET_MSG_CHAT));
790 e_Buffer_Write(@NetOut, Txt);
791 e_Buffer_Write(@NetOut, Mode);
792 g_Net_Host_Send(gPlayers[i].FClientID, True, NET_CHAN_CHAT);
793 end;
794 Team := ID;
795 ID := NET_EVERYONE;
797 else
798 begin
799 e_Buffer_Write(@NetOut, Byte(NET_MSG_CHAT));
800 e_Buffer_Write(@NetOut, Txt);
801 e_Buffer_Write(@NetOut, Mode);
802 g_Net_Host_Send(ID, True, NET_CHAN_CHAT);
803 end;
805 if Mode = NET_CHAT_SYSTEM then
806 Exit;
808 if ID = NET_EVERYONE then
809 begin
810 if Mode = NET_CHAT_PLAYER then
811 begin
812 g_Console_Add(Txt, True);
813 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), MSG_NOTIFY);
814 g_Sound_PlayEx('SOUND_GAME_RADIO');
816 else
817 if Mode = NET_CHAT_TEAM then
818 if gPlayer1 <> nil then
819 begin
820 if (gPlayer1.Team = TEAM_RED) and (Team = TEAM_RED) then
821 begin
822 g_Console_Add(#18'[Team] '#2 + Txt, True);
823 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), MSG_NOTIFY);
824 g_Sound_PlayEx('SOUND_GAME_RADIO');
826 else if (gPlayer1.Team = TEAM_BLUE) and (Team = TEAM_BLUE) then
827 begin
828 g_Console_Add(#20'[Team] '#2 + Txt, True);
829 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), MSG_NOTIFY);
830 g_Sound_PlayEx('SOUND_GAME_RADIO');
831 end;
832 end;
834 else
835 begin
836 Name := g_Net_ClientName_ByID(ID);
837 g_Console_Add('-> ' + Name + ': ' + Txt, True);
838 e_WriteLog('[Tell ' + Name + '] ' + b_Text_Unformat(Txt), MSG_NOTIFY);
839 g_Sound_PlayEx('SOUND_GAME_RADIO');
840 end;
841 end;
843 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
844 begin
845 e_Buffer_Write(@NetOut, Byte(NET_MSG_GFX));
846 e_Buffer_Write(@NetOut, Kind);
847 e_Buffer_Write(@NetOut, X);
848 e_Buffer_Write(@NetOut, Y);
849 e_Buffer_Write(@NetOut, Ang);
851 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
852 end;
854 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
855 begin
856 e_Buffer_Write(@NetOut, Byte(NET_MSG_SND));
857 e_Buffer_Write(@NetOut, Name);
858 if Pos then
859 begin
860 e_Buffer_Write(@NetOut, Byte(1));
861 e_Buffer_Write(@NetOut, X);
862 e_Buffer_Write(@NetOut, Y);
864 else
865 e_Buffer_Write(@NetOut, Byte(0));
867 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
868 end;
870 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
871 begin
872 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
874 e_Buffer_Write(@NetOut, Byte(NET_MSG_SHADD));
875 e_Buffer_Write(@NetOut, Proj);
876 e_Buffer_Write(@NetOut, Shots[Proj].ShotType);
877 e_Buffer_Write(@NetOut, Shots[Proj].Target);
878 e_Buffer_Write(@NetOut, Shots[Proj].SpawnerUID);
879 e_Buffer_Write(@NetOut, Shots[Proj].Timeout);
880 e_Buffer_Write(@NetOut, Shots[Proj].Obj.X);
881 e_Buffer_Write(@NetOut, Shots[Proj].Obj.Y);
882 e_Buffer_Write(@NetOut, Shots[Proj].Obj.Vel.X);
883 e_Buffer_Write(@NetOut, Shots[Proj].Obj.Vel.Y);
885 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
886 end;
888 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
889 begin
890 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
892 e_Buffer_Write(@NetOut, Byte(NET_MSG_SHPOS));
893 e_Buffer_Write(@NetOut, Proj);
894 e_Buffer_Write(@NetOut, Shots[Proj].Obj.X);
895 e_Buffer_Write(@NetOut, Shots[Proj].Obj.Y);
896 e_Buffer_Write(@NetOut, Shots[Proj].Obj.Vel.X);
897 e_Buffer_Write(@NetOut, Shots[Proj].Obj.Vel.Y);
899 g_Net_Host_Send(ID, False, NET_CHAN_SHOTS);
900 end;
902 procedure MH_Send_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
903 begin
904 e_Buffer_Write(@NetOut, Byte(NET_MSG_SHDEL));
905 e_Buffer_Write(@NetOut, Proj);
906 e_Buffer_Write(@NetOut, Byte(Loud));
907 e_Buffer_Write(@NetOut, X);
908 e_Buffer_Write(@NetOut, Y);
910 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
911 end;
913 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
914 begin
915 e_Buffer_Write(@NetOut, Byte(NET_MSG_SCORE));
916 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
917 begin
918 e_Buffer_Write(@NetOut, gTeamStat[TEAM_RED].Goals);
919 e_Buffer_Write(@NetOut, gTeamStat[TEAM_BLUE].Goals);
921 else
922 if gGameSettings.GameMode = GM_COOP then
923 begin
924 e_Buffer_Write(@NetOut, gCoopMonstersKilled);
925 e_Buffer_Write(@NetOut, gCoopSecretsFound);
926 end;
928 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
929 end;
931 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
932 begin
933 e_Buffer_Write(@NetOut, Byte(NET_MSG_COOP));
934 e_Buffer_Write(@NetOut, gTotalMonsters);
935 e_Buffer_Write(@NetOut, gSecretsCount);
936 e_Buffer_Write(@NetOut, gCoopTotalMonstersKilled);
937 e_Buffer_Write(@NetOut, gCoopTotalSecretsFound);
938 e_Buffer_Write(@NetOut, gCoopTotalMonsters);
939 e_Buffer_Write(@NetOut, gCoopTotalSecrets);
940 end;
942 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
943 begin
944 e_Buffer_Write(@NetOut, Byte(NET_MSG_GEVENT));
945 e_Buffer_Write(@NetOut, EvType);
946 e_Buffer_Write(@NetOut, EvNum);
947 e_Buffer_Write(@NetOut, EvStr);
948 e_Buffer_Write(@NetOut, Byte(gLastMap));
949 e_Buffer_Write(@NetOut, gTime);
950 if (EvType = NET_EV_MAPSTART) and (Pos(':\', EvStr) > 0) then
951 begin
952 e_Buffer_Write(@NetOut, Byte(1));
953 e_Buffer_Write(@NetOut, gWADHash);
954 end else
955 e_Buffer_Write(@NetOut, Byte(0));
957 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
958 end;
960 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
961 begin
962 e_Buffer_Write(@NetOut, Byte(NET_MSG_FLAG));
963 e_Buffer_Write(@NetOut, EvType);
964 e_Buffer_Write(@NetOut, Flag);
965 e_Buffer_Write(@NetOut, Byte(Quiet));
966 e_Buffer_Write(@NetOut, PID);
967 e_Buffer_Write(@NetOut, gFlags[Flag].State);
968 e_Buffer_Write(@NetOut, gFlags[Flag].CaptureTime);
969 e_Buffer_Write(@NetOut, gFlags[Flag].Obj.X);
970 e_Buffer_Write(@NetOut, gFlags[Flag].Obj.Y);
971 e_Buffer_Write(@NetOut, gFlags[Flag].Obj.Vel.X);
972 e_Buffer_Write(@NetOut, gFlags[Flag].Obj.Vel.Y);
974 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
975 end;
977 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
978 begin
979 e_Buffer_Write(@NetOut, Byte(NET_MSG_GSET));
980 e_Buffer_Write(@NetOut, gGameSettings.GameMode);
981 e_Buffer_Write(@NetOut, gGameSettings.GoalLimit);
982 e_Buffer_Write(@NetOut, gGameSettings.TimeLimit);
983 e_Buffer_Write(@NetOut, gGameSettings.MaxLives);
984 e_Buffer_Write(@NetOut, gGameSettings.Options);
986 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
987 end;
989 // PLAYER (SEND)
991 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
993 P: TPlayer;
994 begin
995 P := g_Player_Get(PID);
996 if P = nil then Exit;
998 e_Buffer_Write(@NetOut, Byte(NET_MSG_PLR));
999 e_Buffer_Write(@NetOut, PID);
1000 e_Buffer_Write(@NetOut, P.Name);
1002 e_Buffer_Write(@NetOut, P.FActualModelName);
1003 e_Buffer_Write(@NetOut, P.FColor.R);
1004 e_Buffer_Write(@NetOut, P.FColor.G);
1005 e_Buffer_Write(@NetOut, P.FColor.B);
1006 e_Buffer_Write(@NetOut, P.Team);
1008 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT)
1009 end;
1011 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
1013 kByte: Word;
1014 Pl: TPlayer;
1015 begin
1016 Pl := g_Player_Get(PID);
1017 if Pl = nil then Exit;
1018 if Pl.FDummy then Exit;
1020 e_Buffer_Write(@NetOut, Byte(NET_MSG_PLRPOS));
1021 e_Buffer_Write(@NetOut, gTime);
1022 e_Buffer_Write(@NetOut, PID);
1024 kByte := 0;
1026 with Pl do
1027 begin
1028 e_Buffer_Write(@NetOut, FPing);
1029 e_Buffer_Write(@NetOut, FLoss);
1030 if IsKeyPressed(KEY_CHAT) then
1031 kByte := NET_KEY_CHAT
1032 else
1033 begin
1034 if IsKeyPressed(KEY_LEFT) then kByte := kByte or NET_KEY_LEFT;
1035 if IsKeyPressed(KEY_RIGHT) then kByte := kByte or NET_KEY_RIGHT;
1036 if IsKeyPressed(KEY_UP) then kByte := kByte or NET_KEY_UP;
1037 if IsKeyPressed(KEY_DOWN) then kByte := kByte or NET_KEY_DOWN;
1038 if IsKeyPressed(KEY_JUMP) then kByte := kByte or NET_KEY_JUMP;
1039 if JustTeleported then kByte := kByte or NET_KEY_FORCEDIR;
1040 end;
1042 e_Buffer_Write(@NetOut, kByte);
1043 if Direction = D_LEFT then e_Buffer_Write(@NetOut, Byte(0)) else e_Buffer_Write(@NetOut, Byte(1));
1044 e_Buffer_Write(@NetOut, GameX);
1045 e_Buffer_Write(@NetOut, GameY);
1046 e_Buffer_Write(@NetOut, GameVelX);
1047 e_Buffer_Write(@NetOut, GameVelY);
1048 e_Buffer_Write(@NetOut, GameAccelX);
1049 e_Buffer_Write(@NetOut, GameAccelY);
1050 end;
1052 g_Net_Host_Send(ID, Reliable, NET_CHAN_PLAYERPOS);
1053 end;
1055 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
1057 P: TPlayer;
1058 I: Integer;
1059 begin
1060 P := g_Player_Get(PID);
1061 if P = nil then Exit;
1063 e_Buffer_Write(@NetOut, Byte(NET_MSG_PLRSTA));
1064 e_Buffer_Write(@NetOut, PID);
1066 with P do
1067 begin
1068 e_Buffer_Write(@NetOut, Byte(Live));
1069 e_Buffer_Write(@NetOut, Byte(GodMode));
1070 e_Buffer_Write(@NetOut, Health);
1071 e_Buffer_Write(@NetOut, Armor);
1072 e_Buffer_Write(@NetOut, Air);
1073 e_Buffer_Write(@NetOut, JetFuel);
1074 e_Buffer_Write(@NetOut, Lives);
1075 e_Buffer_Write(@NetOut, Team);
1077 for I := WP_FIRST to WP_LAST do
1078 e_Buffer_Write(@NetOut, Byte(FWeapon[I]));
1080 for I := A_BULLETS to A_CELLS do
1081 e_Buffer_Write(@NetOut, FAmmo[I]);
1083 for I := A_BULLETS to A_CELLS do
1084 e_Buffer_Write(@NetOut, FMaxAmmo[I]);
1086 for I := MR_SUIT to MR_MAX do
1087 e_Buffer_Write(@NetOut, LongWord(FMegaRulez[I]));
1089 e_Buffer_Write(@NetOut, Byte(R_ITEM_BACKPACK in FRulez));
1090 e_Buffer_Write(@NetOut, Byte(R_KEY_RED in FRulez));
1091 e_Buffer_Write(@NetOut, Byte(R_KEY_GREEN in FRulez));
1092 e_Buffer_Write(@NetOut, Byte(R_KEY_BLUE in FRulez));
1093 e_Buffer_Write(@NetOut, Byte(R_BERSERK in FRulez));
1095 e_Buffer_Write(@NetOut, Frags);
1096 e_Buffer_Write(@NetOut, Death);
1098 e_Buffer_Write(@NetOut, CurrWeap);
1100 e_Buffer_Write(@NetOut, Byte(FSpectator));
1101 e_Buffer_Write(@NetOut, Byte(FGhost));
1102 e_Buffer_Write(@NetOut, Byte(FPhysics));
1103 e_Buffer_Write(@NetOut, Byte(FNoRespawn));
1104 e_Buffer_Write(@NetOut, Byte(FJetpack));
1105 end;
1107 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1108 end;
1110 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
1111 begin
1112 e_Buffer_Write(@NetOut, Byte(NET_MSG_PLRDMG));
1113 e_Buffer_Write(@NetOut, PID);
1114 e_Buffer_Write(@NetOut, Kind);
1115 e_Buffer_Write(@NetOut, Attacker);
1116 e_Buffer_Write(@NetOut, Value);
1117 e_Buffer_Write(@NetOut, VX);
1118 e_Buffer_Write(@NetOut, VY);
1120 g_Net_Host_Send(ID, False, NET_CHAN_PLAYER);
1121 end;
1123 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
1124 begin
1125 e_Buffer_Write(@NetOut, Byte(NET_MSG_PLRDIE));
1126 e_Buffer_Write(@NetOut, PID);
1127 e_Buffer_Write(@NetOut, KillType);
1128 e_Buffer_Write(@NetOut, DeathType);
1129 e_Buffer_Write(@NetOut, Attacker);
1131 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1132 end;
1134 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
1135 begin
1136 e_Buffer_Write(@NetOut, Byte(NET_MSG_PLRFIRE));
1137 e_Buffer_Write(@NetOut, PID);
1138 e_Buffer_Write(@NetOut, Weapon);
1139 e_Buffer_Write(@NetOut, X);
1140 e_Buffer_Write(@NetOut, Y);
1141 e_Buffer_Write(@NetOut, AX);
1142 e_Buffer_Write(@NetOut, AY);
1143 e_Buffer_Write(@NetOut, ShotID);
1145 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1146 end;
1148 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
1149 begin
1150 e_Buffer_Write(@NetOut, Byte(NET_MSG_PLRDEL));
1151 e_Buffer_Write(@NetOut, PID);
1153 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1154 end;
1156 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
1158 Pl: TPlayer;
1159 begin
1160 Pl := g_Player_Get(PID);
1161 if Pl = nil then Exit;
1163 e_Buffer_Write(@NetOut, Byte(NET_MSG_PLRSET));
1164 e_Buffer_Write(@NetOut, PID);
1165 e_Buffer_Write(@NetOut, Pl.Name);
1166 if Mdl = '' then
1167 e_Buffer_Write(@NetOut, Pl.Model.Name)
1168 else
1169 e_Buffer_Write(@NetOut, Mdl);
1170 e_Buffer_Write(@NetOut, Pl.FColor.R);
1171 e_Buffer_Write(@NetOut, Pl.FColor.G);
1172 e_Buffer_Write(@NetOut, Pl.FColor.B);
1173 e_Buffer_Write(@NetOut, Pl.Team);
1175 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1176 end;
1178 // ITEM (SEND)
1180 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1181 begin
1182 e_Buffer_Write(@NetOut, Byte(NET_MSG_ISPAWN));
1183 e_Buffer_Write(@NetOut, IID);
1184 e_Buffer_Write(@NetOut, Byte(Quiet));
1185 e_Buffer_Write(@NetOut, gItems[IID].ItemType);
1186 e_Buffer_Write(@NetOut, Byte(gItems[IID].Fall));
1187 e_Buffer_Write(@NetOut, Byte(gItems[IID].Respawnable));
1188 e_Buffer_Write(@NetOut, gItems[IID].Obj.X);
1189 e_Buffer_Write(@NetOut, gItems[IID].Obj.Y);
1190 e_Buffer_Write(@NetOut, gItems[IID].Obj.Vel.X);
1191 e_Buffer_Write(@NetOut, gItems[IID].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 e_Buffer_Write(@NetOut, Byte(NET_MSG_IDEL));
1199 e_Buffer_Write(@NetOut, IID);
1200 e_Buffer_Write(@NetOut, Byte(Quiet));
1202 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1203 end;
1205 // PANEL
1207 procedure MH_SEND_PanelTexture(PType: Word; PID: LongWord; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
1209 TP: TPanel;
1210 begin
1211 case PType of
1212 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
1213 TP := gWalls[PID];
1214 PANEL_FORE:
1215 TP := gRenderForegrounds[PID];
1216 PANEL_BACK:
1217 TP := gRenderBackgrounds[PID];
1218 PANEL_WATER:
1219 TP := gWater[PID];
1220 PANEL_ACID1:
1221 TP := gAcid1[PID];
1222 PANEL_ACID2:
1223 TP := gAcid2[PID];
1224 PANEL_STEP:
1225 TP := gSteps[PID];
1226 else
1227 Exit;
1228 end;
1230 with TP do
1231 begin
1232 e_Buffer_Write(@NetOut, Byte(NET_MSG_PTEX));
1233 e_Buffer_Write(@NetOut, PType);
1234 e_Buffer_Write(@NetOut, PID);
1235 e_Buffer_Write(@NetOut, FCurTexture);
1236 e_Buffer_Write(@NetOut, FCurFrame);
1237 e_Buffer_Write(@NetOut, FCurFrameCount);
1238 e_Buffer_Write(@NetOut, AnimLoop);
1239 end;
1241 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1242 end;
1244 procedure MH_SEND_PanelState(PType: Word; PID: LongWord; ID: Integer = NET_EVERYONE);
1246 TP: TPanel;
1247 begin
1248 case PType of
1249 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
1250 TP := gWalls[PID];
1251 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT:
1252 TP := gLifts[PID];
1253 PANEL_BACK:
1254 begin
1255 TP := gRenderBackgrounds[PID];
1256 TP.Moved := True;
1257 end;
1258 PANEL_FORE:
1259 begin
1260 TP := gRenderForegrounds[PID];
1261 TP.Moved := True;
1262 end;
1263 else
1264 Exit;
1265 end;
1267 e_Buffer_Write(@NetOut, Byte(NET_MSG_PSTATE));
1268 e_Buffer_Write(@NetOut, PType);
1269 e_Buffer_Write(@NetOut, PID);
1270 e_Buffer_Write(@NetOut, Byte(TP.Enabled));
1271 e_Buffer_Write(@NetOut, TP.LiftType);
1272 e_Buffer_Write(@NetOut, TP.X);
1273 e_Buffer_Write(@NetOut, TP.Y);
1275 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1276 end;
1278 // TRIGGER
1280 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
1281 begin
1282 if gTriggers = nil then Exit;
1283 if T.Sound = nil then Exit;
1285 e_Buffer_Write(@NetOut, Byte(NET_MSG_TSOUND));
1286 e_Buffer_Write(@NetOut, T.ClientID);
1287 e_Buffer_Write(@NetOut, Byte(T.Sound.IsPlaying));
1288 e_Buffer_Write(@NetOut, LongWord(T.Sound.GetPosition));
1289 e_Buffer_Write(@NetOut, T.SoundPlayCount);
1291 g_Net_Host_Send(ID, True);
1292 end;
1294 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
1295 begin
1296 e_Buffer_Write(@NetOut, Byte(NET_MSG_TMUSIC));
1297 e_Buffer_Write(@NetOut, gMusic.Name);
1298 e_Buffer_Write(@NetOut, Byte(gMusic.IsPlaying));
1299 e_Buffer_Write(@NetOut, LongWord(gMusic.GetPosition));
1300 e_Buffer_Write(@NetOut, Byte(gMusic.SpecPause or gMusic.IsPaused));
1302 g_Net_Host_Send(ID, True);
1303 end;
1305 // MONSTER
1307 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
1309 M: TMonster;
1310 begin
1311 M := g_Monsters_Get(UID);
1312 if M = nil then
1313 Exit;
1315 with M do
1316 begin
1317 e_Buffer_Write(@NetOut, Byte(NET_MSG_MSPAWN));
1318 e_Buffer_Write(@NetOut, UID);
1319 e_Buffer_Write(@NetOut, MonsterType);
1320 e_Buffer_Write(@NetOut, MonsterState);
1321 e_Buffer_Write(@NetOut, MonsterAnim);
1322 e_Buffer_Write(@NetOut, MonsterTargetUID);
1323 e_Buffer_Write(@NetOut, MonsterTargetTime);
1324 e_Buffer_Write(@NetOut, MonsterBehaviour);
1325 e_Buffer_Write(@NetOut, MonsterSleep);
1326 e_Buffer_Write(@NetOut, MonsterHealth);
1327 e_Buffer_Write(@NetOut, MonsterAmmo);
1328 e_Buffer_Write(@NetOut, GameX);
1329 e_Buffer_Write(@NetOut, GameY);
1330 e_Buffer_Write(@NetOut, GameVelX);
1331 e_Buffer_Write(@NetOut, GameVelY);
1332 e_Buffer_Write(@NetOut, Byte(GameDirection));
1333 end;
1335 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1336 end;
1338 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
1340 M: TMonster;
1341 begin
1342 M := g_Monsters_Get(UID);
1343 if M = nil then Exit;
1345 e_Buffer_Write(@NetOut, Byte(NET_MSG_MPOS));
1346 e_Buffer_Write(@NetOut, UID);
1348 with M do
1349 begin
1350 e_Buffer_Write(@NetOut, GameX);
1351 e_Buffer_Write(@NetOut, GameY);
1352 e_Buffer_Write(@NetOut, GameVelX);
1353 e_Buffer_Write(@NetOut, GameVelY);
1354 e_Buffer_Write(@NetOut, Byte(GameDirection));
1355 end;
1357 g_Net_Host_Send(ID, False, NET_CHAN_MONSTERPOS);
1358 end;
1360 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
1362 M: TMonster;
1363 begin
1364 M := g_Monsters_Get(UID);
1365 if M = nil then Exit;
1367 e_Buffer_Write(@NetOut, Byte(NET_MSG_MSTATE));
1368 e_Buffer_Write(@NetOut, UID);
1370 with M do
1371 begin
1372 e_Buffer_Write(@NetOut, MonsterState);
1373 e_Buffer_Write(@NetOut, ForcedAnim);
1374 e_Buffer_Write(@NetOut, MonsterTargetUID);
1375 e_Buffer_Write(@NetOut, MonsterTargetTime);
1376 e_Buffer_Write(@NetOut, MonsterSleep);
1377 e_Buffer_Write(@NetOut, MonsterHealth);
1378 e_Buffer_Write(@NetOut, MonsterAmmo);
1379 e_Buffer_Write(@NetOut, MonsterPain);
1380 e_Buffer_Write(@NetOut, Byte(AnimIsReverse));
1381 end;
1383 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1384 end;
1386 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
1387 begin
1388 e_Buffer_Write(@NetOut, Byte(NET_MSG_MSHOT));
1389 e_Buffer_Write(@NetOut, UID);
1390 e_Buffer_Write(@NetOut, X);
1391 e_Buffer_Write(@NetOut, Y);
1392 e_Buffer_Write(@NetOut, VX);
1393 e_Buffer_Write(@NetOut, VY);
1395 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1396 end;
1398 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
1400 M: TMonster;
1401 begin
1402 M := g_Monsters_Get(UID);
1403 if M = nil then Exit;
1405 e_Buffer_Write(@NetOut, Byte(NET_MSG_MDEL));
1406 e_Buffer_Write(@NetOut, UID);
1408 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1409 end;
1411 // MISC
1413 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
1414 begin
1415 e_Buffer_Write(@NetOut, Byte(NET_MSG_TIME_SYNC));
1416 e_Buffer_Write(@NetOut, Time);
1418 g_Net_Host_Send(ID, False, NET_CHAN_SERVICE);
1419 end;
1421 procedure MH_SEND_VoteEvent(EvType: Byte;
1422 StrArg1: string = 'a'; StrArg2: string = 'b';
1423 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
1424 ID: Integer = NET_EVERYONE);
1425 begin
1426 e_Buffer_Write(@NetOut, Byte(NET_MSG_VOTE_EVENT));
1427 e_Buffer_Write(@NetOut, EvType);
1428 e_Buffer_Write(@NetOut, IntArg1);
1429 e_Buffer_Write(@NetOut, IntArg2);
1430 e_Buffer_Write(@NetOut, StrArg1);
1431 e_Buffer_Write(@NetOut, StrArg2);
1433 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1434 end;
1436 // CLIENT MESSAGES //
1438 // GAME
1440 procedure MC_RECV_Chat(P: Pointer);
1442 Txt: string;
1443 Mode: Byte;
1444 begin
1445 Txt := e_Raw_Read_String(P);
1446 Mode := e_Raw_Read_Byte(P);
1448 if Mode <> NET_CHAT_SYSTEM then
1449 begin
1450 if Mode = NET_CHAT_PLAYER then
1451 begin
1452 g_Console_Add(Txt, True);
1453 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), MSG_NOTIFY);
1454 g_Sound_PlayEx('SOUND_GAME_RADIO');
1455 end else
1456 if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then
1457 begin
1458 if gPlayer1.Team = TEAM_RED then
1459 g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True);
1460 if gPlayer1.Team = TEAM_BLUE then
1461 g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True);
1462 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), MSG_NOTIFY);
1463 g_Sound_PlayEx('SOUND_GAME_RADIO');
1464 end;
1465 end else
1466 g_Console_Add(Txt, True);
1467 end;
1469 procedure MC_RECV_Effect(P: Pointer);
1471 Kind: Byte;
1472 X, Y: Integer;
1473 Ang: SmallInt;
1474 Anim: TAnimation;
1475 ID: LongWord;
1476 begin
1477 if not gGameOn then Exit;
1478 Kind := e_Raw_Read_Byte(P);
1479 X := e_Raw_Read_LongInt(P);
1480 Y := e_Raw_Read_LongInt(P);
1481 Ang := e_Raw_Read_SmallInt(P);
1483 case Kind of
1484 NET_GFX_SPARK:
1485 g_GFX_Spark(X, Y, 2 + Random(2), Ang, 0, 0);
1487 NET_GFX_TELE:
1488 begin
1489 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
1490 begin
1491 Anim := TAnimation.Create(ID, False, 3);
1492 g_GFX_OnceAnim(X, Y, Anim);
1493 Anim.Free();
1494 end;
1495 if Ang = 1 then
1496 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
1497 end;
1499 NET_GFX_EXPLODE:
1500 begin
1501 if g_Frames_Get(ID, 'FRAMES_EXPLODE_ROCKET') 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_EXPLODEROCKET', X, Y);
1510 end;
1512 NET_GFX_BFGEXPL:
1513 begin
1514 if g_Frames_Get(ID, 'FRAMES_EXPLODE_BFG') then
1515 begin
1516 Anim := TAnimation.Create(ID, False, 6);
1517 Anim.Blending := False;
1518 g_GFX_OnceAnim(X-64, Y-64, Anim);
1519 Anim.Free();
1520 end;
1521 if Ang = 1 then
1522 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X, Y);
1523 end;
1525 NET_GFX_BFGHIT:
1526 begin
1527 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1528 begin
1529 Anim := TAnimation.Create(ID, False, 4);
1530 g_GFX_OnceAnim(X-32, Y-32, Anim);
1531 Anim.Free();
1532 end;
1533 end;
1535 NET_GFX_FIRE:
1536 begin
1537 if g_Frames_Get(ID, 'FRAMES_FIRE') then
1538 begin
1539 Anim := TAnimation.Create(ID, False, 4);
1540 g_GFX_OnceAnim(X, Y, Anim);
1541 Anim.Free();
1542 end;
1543 if Ang = 1 then
1544 g_Sound_PlayExAt('SOUND_FIRE', X, Y);
1545 end;
1547 NET_GFX_RESPAWN:
1548 begin
1549 if g_Frames_Get(ID, 'FRAMES_ITEM_RESPAWN') then
1550 begin
1551 Anim := TAnimation.Create(ID, False, 4);
1552 g_GFX_OnceAnim(X, Y, Anim);
1553 Anim.Free();
1554 end;
1555 if Ang = 1 then
1556 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
1557 end;
1559 NET_GFX_SHELL1:
1560 g_Player_CreateShell(X, Y, 0, -2, SHELL_BULLET);
1562 NET_GFX_SHELL2:
1563 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1565 NET_GFX_SHELL3:
1566 begin
1567 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1568 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1569 end;
1570 end;
1571 end;
1573 procedure MC_RECV_Sound(P: Pointer);
1575 Name: string;
1576 X, Y: Integer;
1577 Pos: Boolean;
1578 begin
1579 Name := e_Raw_Read_String(P);
1580 Pos := e_Raw_Read_Byte(P) <> 0;
1581 if Pos then
1582 begin
1583 X := e_Raw_Read_LongInt(P);
1584 Y := e_Raw_Read_LongInt(P);
1585 g_Sound_PlayExAt(Name, X, Y);
1587 else
1588 g_Sound_PlayEx(Name);
1589 end;
1591 procedure MC_RECV_CreateShot(P: Pointer);
1593 I, X, Y, XV, YV: Integer;
1594 Timeout: LongWord;
1595 Target, Spawner: Word;
1596 ShType: Byte;
1597 begin
1598 I := e_Raw_Read_LongInt(P);
1599 ShType := e_Raw_Read_Byte(P);
1600 Target := e_Raw_Read_Word(P);
1601 Spawner := e_Raw_Read_Word(P);
1602 Timeout := e_Raw_Read_LongWord(P);
1603 X := e_Raw_Read_LongInt(P);
1604 Y := e_Raw_Read_LongInt(P);
1605 XV := e_Raw_Read_LongInt(P);
1606 YV := e_Raw_Read_LongInt(P);
1608 I := g_Weapon_CreateShot(I, ShType, Spawner, Target, X, Y, XV, YV);
1609 if (Shots <> nil) and (I <= High(Shots)) then
1610 begin
1611 Shots[I].Timeout := Timeout;
1612 //Shots[I].Target := Target; // TODO: find a use for Target later
1613 end;
1614 end;
1616 procedure MC_RECV_UpdateShot(P: Pointer);
1618 I, TX, TY, TXV, TYV: Integer;
1619 begin
1620 I := e_Raw_Read_LongInt(P);
1621 TX := e_Raw_Read_LongInt(P);
1622 TY := e_Raw_Read_LongInt(P);
1623 TXV := e_Raw_Read_LongInt(P);
1624 TYV := e_Raw_Read_LongInt(P);
1626 if (Shots <> nil) and (I <= High(Shots)) then
1627 with (Shots[i]) do
1628 begin
1629 Obj.X := TX;
1630 Obj.Y := TY;
1631 Obj.Vel.X := TXV;
1632 Obj.Vel.Y := TYV;
1633 end;
1634 end;
1636 procedure MC_RECV_DeleteShot(P: Pointer);
1638 I, X, Y: Integer;
1639 L: Boolean;
1640 begin
1641 if not gGameOn then Exit;
1642 I := e_Raw_Read_LongInt(P);
1643 L := (e_Raw_Read_Byte(P) <> 0);
1644 X := e_Raw_Read_LongInt(P);
1645 Y := e_Raw_Read_LongInt(P);
1647 g_Weapon_DestroyShot(I, X, Y, L);
1648 end;
1650 procedure MC_RECV_GameStats(P: Pointer);
1651 begin
1652 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1653 begin
1654 gTeamStat[TEAM_RED].Goals := e_Raw_Read_SmallInt(P);
1655 gTeamStat[TEAM_BLUE].Goals := e_Raw_Read_SmallInt(P);
1657 else
1658 if gGameSettings.GameMode = GM_COOP then
1659 begin
1660 gCoopMonstersKilled := e_Raw_Read_Word(P);
1661 gCoopSecretsFound := e_Raw_Read_Word(P);
1662 end;
1663 end;
1665 procedure MC_RECV_CoopStats(P: Pointer);
1666 begin
1667 gTotalMonsters := e_Raw_Read_LongInt(P);
1668 gSecretsCount := e_Raw_Read_LongInt(P);
1669 gCoopTotalMonstersKilled := e_Raw_Read_Word(P);
1670 gCoopTotalSecretsFound := e_Raw_Read_Word(P);
1671 gCoopTotalMonsters := e_Raw_Read_Word(P);
1672 gCoopTotalSecrets := e_Raw_Read_Word(P);
1673 end;
1675 procedure MC_RECV_GameEvent(P: Pointer);
1677 EvType: Byte;
1678 EvNum: Integer;
1679 EvStr: string;
1680 EvTime: LongWord;
1681 BHash: Boolean;
1682 EvHash: TMD5Digest;
1683 pl: TPlayer;
1684 i1, i2: TStrings_Locale;
1685 pln: String;
1686 cnt: Byte;
1687 begin
1688 FillChar(EvHash, Sizeof(EvHash), 0);
1689 EvType := e_Raw_Read_Byte(P);
1690 EvNum := e_Raw_Read_LongInt(P);
1691 EvStr := e_Raw_Read_String(P);
1692 gLastMap := e_Raw_Read_Byte(P) <> 0;
1693 if gLastMap and (gGameSettings.GameMode = GM_COOP) then gStatsOff := True;
1694 gStatsPressed := True;
1695 EvTime := e_Raw_Read_LongWord(P);
1696 BHash := e_Raw_Read_Byte(P) <> 0;
1697 if BHash then
1698 EvHash := e_Raw_Read_MD5(P);
1700 gTime := EvTime;
1702 case EvType of
1703 NET_EV_MAPSTART:
1704 begin
1705 gGameOn := False;
1706 g_Game_ClearLoading();
1707 g_Game_StopAllSounds(True);
1709 gSwitchGameMode := Byte(EvNum);
1710 gGameSettings.GameMode := gSwitchGameMode;
1712 gWADHash := EvHash;
1713 if not g_Game_StartMap(EvStr, True) then
1714 begin
1715 if Pos(':\', EvStr) = 0 then
1716 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + EvStr]))
1717 else
1718 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [EvStr]));
1719 Exit;
1720 end;
1722 MC_SEND_FullStateRequest;
1723 end;
1725 NET_EV_MAPEND:
1726 begin
1727 gMissionFailed := EvNum <> 0;
1728 gExit := EXIT_ENDLEVELCUSTOM;
1729 end;
1731 NET_EV_RCON:
1732 begin
1733 case EvNum of
1734 NET_RCON_NOAUTH:
1735 g_Console_Add(_lc[I_NET_RCON_NOAUTH], True);
1736 NET_RCON_PWGOOD:
1737 g_Console_Add(_lc[I_NET_RCON_PWD_VALID], True);
1738 NET_RCON_PWBAD:
1739 g_Console_Add(_lc[I_NET_RCON_PWD_INVALID], True);
1740 end;
1741 end;
1743 NET_EV_CHANGE_TEAM:
1744 begin
1745 if EvNum = TEAM_RED then
1746 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True);
1747 if EvNum = TEAM_BLUE then
1748 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True);
1749 end;
1751 NET_EV_PLAYER_KICK:
1752 g_Console_Add(Format(_lc[I_PLAYER_KICK], [EvStr]), True);
1754 NET_EV_PLAYER_BAN:
1755 g_Console_Add(Format(_lc[I_PLAYER_BAN], [EvStr]), True);
1757 NET_EV_LMS_WARMUP:
1758 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [EvNum]), True);
1760 NET_EV_LMS_SURVIVOR:
1761 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True);
1763 NET_EV_BIGTEXT:
1764 g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum));
1766 NET_EV_SCORE:
1767 begin
1768 pl := g_Player_Get(EvNum and $FFFF);
1769 if pl = nil then
1770 pln := '?'
1771 else
1772 pln := pl.Name;
1773 cnt := (EvNum shr 16) and $FF;
1774 if Pos('w', EvStr) = 0 then
1775 begin
1776 // Default score
1777 if Pos('t', EvStr) = 0 then
1778 begin
1779 // Player +/- score
1780 if Pos('-', EvStr) = 0 then
1781 begin
1782 if Pos('e', EvStr) = 0 then
1783 i1 := I_PLAYER_SCORE_ADD_OWN
1784 else
1785 i1 := I_PLAYER_SCORE_ADD_ENEMY;
1786 end else
1787 begin
1788 if Pos('e', EvStr) = 0 then
1789 i1 := I_PLAYER_SCORE_SUB_OWN
1790 else
1791 i1 := I_PLAYER_SCORE_SUB_ENEMY;
1792 end;
1793 // Which team
1794 if Pos('r', EvStr) > 0 then
1795 i2 := I_PLAYER_SCORE_TO_RED
1796 else
1797 i2 := I_PLAYER_SCORE_TO_BLUE;
1798 g_Console_Add(Format(_lc[i1], [pln, cnt, _lc[i2]]), True);
1799 end else
1800 begin
1801 // Team +/- score
1802 if Pos('-', EvStr) = 0 then
1803 i1 := I_PLAYER_SCORE_ADD_TEAM
1804 else
1805 i1 := I_PLAYER_SCORE_SUB_TEAM;
1806 // Which team
1807 if Pos('r', EvStr) > 0 then
1808 i2 := I_PLAYER_SCORE_RED
1809 else
1810 i2 := I_PLAYER_SCORE_BLUE;
1811 g_Console_Add(Format(_lc[i1], [_lc[i2], cnt]), True);
1812 end;
1813 end else
1814 begin
1815 // Game Win
1816 if Pos('e', EvStr) = 0 then
1817 i1 := I_PLAYER_SCORE_WIN_OWN
1818 else
1819 i1 := I_PLAYER_SCORE_WIN_ENEMY;
1820 // Which team
1821 if Pos('r', EvStr) > 0 then
1822 i2 := I_PLAYER_SCORE_TO_RED
1823 else
1824 i2 := I_PLAYER_SCORE_TO_BLUE;
1825 g_Console_Add(Format(_lc[i1], [pln, _lc[i2]]), True);
1826 end;
1827 end;
1829 NET_EV_SCORE_MSG:
1830 begin
1831 if EvNum = TEAM_RED then
1832 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1833 if EvNum = TEAM_BLUE then
1834 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1835 if EvNum = -TEAM_RED then
1836 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1837 if EvNum = -TEAM_BLUE then
1838 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1839 end;
1841 NET_EV_LMS_START:
1842 begin
1843 g_Player_RemoveAllCorpses;
1844 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
1845 end;
1847 NET_EV_LMS_WIN:
1848 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(EvStr)]), 144);
1850 NET_EV_TLMS_WIN:
1851 begin
1852 if EvNum = TEAM_RED then
1853 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
1854 if EvNum = TEAM_BLUE then
1855 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
1856 end;
1858 NET_EV_LMS_LOSE:
1859 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
1861 NET_EV_LMS_DRAW:
1862 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
1864 NET_EV_KILLCOMBO:
1865 g_Game_Announce_KillCombo(EvNum);
1867 NET_EV_PLAYER_TOUCH:
1868 begin
1869 pl := g_Player_Get(EvNum);
1870 if pl <> nil then
1871 pl.Touch();
1872 end;
1874 end;
1875 end;
1877 procedure MC_RECV_FlagEvent(P: Pointer);
1879 PID: Word;
1880 Pl: TPlayer;
1881 EvType: Byte;
1882 Fl: Byte;
1883 Quiet: Boolean;
1884 s, ts: string;
1885 begin
1886 EvType := e_Raw_Read_Byte(P);
1887 Fl := e_Raw_Read_Byte(P);
1889 if Fl = FLAG_NONE then Exit;
1891 Quiet := (e_Raw_Read_Byte(P) <> 0);
1892 PID := e_Raw_Read_Word(P);
1894 gFlags[Fl].State := e_Raw_Read_Byte(P);
1895 gFlags[Fl].CaptureTime := e_Raw_Read_LongWord(P);
1896 gFlags[Fl].Obj.X := e_Raw_Read_LongInt(P);
1897 gFlags[Fl].Obj.Y := e_Raw_Read_LongInt(P);
1898 gFlags[Fl].Obj.Vel.X := e_Raw_Read_LongInt(P);
1899 gFlags[Fl].Obj.Vel.Y := e_Raw_Read_LongInt(P);
1901 Pl := g_Player_Get(PID);
1902 if (Pl = nil) and
1903 (EvType <> FLAG_STATE_NORMAL) and
1904 (EvType <> FLAG_STATE_DROPPED) and
1905 (EvType <> FLAG_STATE_RETURNED) then
1906 Exit;
1908 case EvType of
1909 FLAG_STATE_NORMAL:
1910 begin
1911 if Quiet or (Pl = nil) then Exit;
1913 if Fl = FLAG_RED then
1914 s := _lc[I_PLAYER_FLAG_RED]
1915 else
1916 s := _lc[I_PLAYER_FLAG_BLUE];
1918 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
1919 end;
1921 FLAG_STATE_CAPTURED:
1922 begin
1923 if (Pl <> nil) then Pl.SetFlag(Fl);
1925 if Quiet then Exit;
1927 if Fl = FLAG_RED then
1928 s := _lc[I_PLAYER_FLAG_RED]
1929 else
1930 s := _lc[I_PLAYER_FLAG_BLUE];
1932 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [Pl.Name, s]), True);
1933 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
1934 end;
1936 FLAG_STATE_DROPPED:
1937 begin
1938 if (Pl <> nil) then Pl.SetFlag(FLAG_NONE);
1940 if Quiet or (Pl = nil) then Exit;
1942 if Fl = FLAG_RED then
1943 s := _lc[I_PLAYER_FLAG_RED]
1944 else
1945 s := _lc[I_PLAYER_FLAG_BLUE];
1947 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [Pl.Name, s]), True);
1948 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
1949 end;
1951 FLAG_STATE_SCORED:
1952 begin
1953 g_Map_ResetFlag(FLAG_RED);
1954 g_Map_ResetFlag(FLAG_BLUE);
1955 if Quiet or (Pl = nil) then Exit;
1956 Pl.SetFlag(FLAG_NONE);
1958 if Fl = FLAG_RED then
1959 s := _lc[I_PLAYER_FLAG_RED]
1960 else
1961 s := _lc[I_PLAYER_FLAG_BLUE];
1963 ts := Format('%.4d', [gFlags[Fl].CaptureTime]);
1964 Insert('.', ts, Length(ts) + 1 - 3);
1965 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [Pl.Name, s, ts]), True);
1966 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
1967 end;
1969 FLAG_STATE_RETURNED:
1970 begin
1971 g_Map_ResetFlag(Fl);
1972 if Quiet then Exit;
1974 if Fl = FLAG_RED then
1975 s := _lc[I_PLAYER_FLAG_RED]
1976 else
1977 s := _lc[I_PLAYER_FLAG_BLUE];
1979 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
1980 end;
1981 end;
1982 end;
1984 procedure MC_RECV_GameSettings(P: Pointer);
1985 begin
1986 gGameSettings.GameMode := e_Raw_Read_Byte(P);
1987 gGameSettings.GoalLimit := e_Raw_Read_Word(P);
1988 gGameSettings.TimeLimit := e_Raw_Read_Word(P);
1989 gGameSettings.MaxLives := e_Raw_Read_Byte(P);
1990 gGameSettings.Options := e_Raw_Read_LongWord(P);
1991 end;
1993 // PLAYER
1995 function MC_RECV_PlayerCreate(P: Pointer): Word;
1997 PID, DID: Word;
1998 PName, Model: string;
1999 Color: TRGB;
2000 T: Byte;
2001 Pl: TPlayer;
2002 begin
2003 PID := e_Raw_Read_Word(P);
2004 Pl := g_Player_Get(PID);
2006 PName := e_Raw_Read_String(P);
2007 Model := e_Raw_Read_String(P);
2008 Color.R := e_Raw_Read_Byte(P);
2009 Color.G := e_Raw_Read_Byte(P);
2010 Color.B := e_Raw_Read_Byte(P);
2011 T := e_Raw_Read_Byte(P);
2013 Result := 0;
2014 if (PID <> NetPlrUID1) and (PID <> NetPlrUID2) then
2015 begin
2016 if (Pl <> nil) then Exit;
2017 DID := g_Player_Create(Model, Color, T, False);
2018 with g_Player_Get(DID) do
2019 begin
2020 UID := PID;
2021 Name := PName;
2022 Reset(True);
2023 end;
2025 else
2026 begin
2027 if (PID = NetPlrUID1) and (gPlayer1 <> nil) then begin
2028 gPlayer1.UID := PID;
2029 gPlayer1.Model.SetColor(Color.R, Color.G, Color.B);
2030 gPlayer1.ChangeTeam(T);
2031 end;
2032 if (PID = NetPlrUID2) and (gPlayer2 <> nil) then begin
2033 gPlayer2.UID := PID;
2034 gPlayer2.Model.SetColor(Color.R, Color.G, Color.B);
2035 gPlayer2.ChangeTeam(T);
2036 end;
2037 end;
2039 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
2040 e_WriteLog('NET: Player ' + PName + ' [' + IntToStr(PID) + '] added.', MSG_NOTIFY);
2041 Result := PID;
2042 end;
2044 function MC_RECV_PlayerPos(P: Pointer): Word;
2046 GT: LongWord;
2047 PID: Word;
2048 kByte: Word;
2049 Pl: TPlayer;
2050 Dir: Byte;
2051 TmpX, TmpY: Integer;
2052 begin
2053 Result := 0;
2055 GT := e_Raw_Read_LongWord(P);
2056 if GT < gTime - NET_MAX_DIFFTIME then
2057 begin
2058 gTime := GT;
2059 Exit;
2060 end;
2061 gTime := GT;
2063 PID := e_Raw_Read_Word(P);
2064 Pl := g_Player_Get(PID);
2066 if Pl = nil then Exit;
2068 Result := PID;
2070 with Pl do
2071 begin
2072 FPing := e_Raw_Read_Word(P);
2073 FLoss := e_Raw_Read_Byte(P);
2074 kByte := e_Raw_Read_Word(P);
2075 Dir := e_Raw_Read_Byte(P);
2077 TmpX := e_Raw_Read_LongInt(P);
2078 TmpY := e_Raw_Read_LongInt(P);
2080 ReleaseKeys;
2082 if (kByte = NET_KEY_CHAT) then
2083 PressKey(KEY_CHAT, 10000)
2084 else
2085 begin
2086 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
2087 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
2088 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
2089 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
2090 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
2091 end;
2093 if ((Pl <> gPlayer1) and (Pl <> gPlayer2)) or LongBool(kByte and NET_KEY_FORCEDIR) then
2094 SetDirection(TDirection(Dir));
2096 GameVelX := e_Raw_Read_LongInt(P);
2097 GameVelY := e_Raw_Read_LongInt(P);
2098 GameAccelX := e_Raw_Read_LongInt(P);
2099 GameAccelY := e_Raw_Read_LongInt(P);
2100 SetLerp(TmpX, TmpY);
2101 if NetForcePlayerUpdate then Update();
2102 end;
2103 end;
2105 function MC_RECV_PlayerStats(P: Pointer): Word;
2107 PID: Word;
2108 Pl: TPlayer;
2109 I: Integer;
2110 OldJet: Boolean;
2111 NewTeam: Byte;
2112 begin
2113 PID := e_Raw_Read_Word(P);
2114 Pl := g_Player_Get(PID);
2115 Result := 0;
2116 if Pl = nil then
2117 Exit;
2119 with Pl do
2120 begin
2121 Live := (e_Raw_Read_Byte(P) <> 0);
2122 GodMode := (e_Raw_Read_Byte(P) <> 0);
2123 Health := e_Raw_Read_LongInt(P);
2124 Armor := e_Raw_Read_LongInt(P);
2125 Air := e_Raw_Read_LongInt(P);
2126 JetFuel := e_Raw_Read_LongInt(P);
2127 Lives := e_Raw_Read_Byte(P);
2128 NewTeam := e_Raw_Read_Byte(P);
2130 for I := WP_FIRST to WP_LAST do
2131 FWeapon[I] := (e_Raw_Read_Byte(P) <> 0);
2133 for I := A_BULLETS to A_CELLS do
2134 FAmmo[I] := e_Raw_Read_Word(P);
2136 for I := A_BULLETS to A_CELLS do
2137 FMaxAmmo[I] := e_Raw_Read_Word(P);
2139 for I := MR_SUIT to MR_MAX do
2140 FMegaRulez[I] := e_Raw_Read_LongWord(P);
2142 FRulez := [];
2143 if (e_Raw_Read_Byte(P) <> 0) then
2144 FRulez := FRulez + [R_ITEM_BACKPACK];
2145 if (e_Raw_Read_Byte(P) <> 0) then
2146 FRulez := FRulez + [R_KEY_RED];
2147 if (e_Raw_Read_Byte(P) <> 0) then
2148 FRulez := FRulez + [R_KEY_GREEN];
2149 if (e_Raw_Read_Byte(P) <> 0) then
2150 FRulez := FRulez + [R_KEY_BLUE];
2151 if (e_Raw_Read_Byte(P) <> 0) then
2152 FRulez := FRulez + [R_BERSERK];
2154 Frags := e_Raw_Read_LongInt(P);
2155 Death := e_Raw_Read_LongInt(P);
2157 SetWeapon(e_Raw_Read_Byte(P));
2159 FSpectator := e_Raw_Read_Byte(P) <> 0;
2160 if FSpectator then
2161 begin
2162 if Pl = gPlayer1 then
2163 begin
2164 gLMSPID1 := UID;
2165 gPlayer1 := nil;
2166 end;
2167 if Pl = gPlayer2 then
2168 begin
2169 gLMSPID2 := UID;
2170 gPlayer2 := nil;
2171 end;
2173 else
2174 begin
2175 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
2176 gPlayer1 := g_Player_Get(gLMSPID1);
2177 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
2178 gPlayer2 := g_Player_Get(gLMSPID2);
2179 end;
2180 FGhost := e_Raw_Read_Byte(P) <> 0;
2181 FPhysics := e_Raw_Read_Byte(P) <> 0;
2182 FNoRespawn := e_Raw_Read_Byte(P) <> 0;
2183 OldJet := FJetpack;
2184 FJetpack := e_Raw_Read_Byte(P) <> 0;
2185 if OldJet and not FJetpack then
2186 JetpackOff
2187 else if not OldJet and FJetpack then
2188 JetpackOn;
2189 if Team <> NewTeam then
2190 Pl.ChangeTeam(NewTeam);
2191 end;
2193 Result := PID;
2194 end;
2196 function MC_RECV_PlayerDamage(P: Pointer): Word;
2198 PID: Word;
2199 Pl: TPlayer;
2200 Kind: Byte;
2201 Attacker, Value: Word;
2202 VX, VY: Integer;
2203 begin
2204 Result := 0;
2205 if not gGameOn then Exit;
2206 PID := e_Raw_Read_Word(P);
2207 Pl := g_Player_Get(PID);
2208 if Pl = nil then Exit;
2210 Kind := e_Raw_Read_Byte(P);
2211 Attacker := e_Raw_Read_Word(P);
2212 Value := e_Raw_Read_Word(P);
2213 VX := e_Raw_Read_Word(P);
2214 VY := e_Raw_Read_Word(P);
2216 with Pl do
2217 Damage(Value, Attacker, VX, VY, Kind);
2219 Result := PID;
2220 end;
2222 function MC_RECV_PlayerDeath(P: Pointer): Word;
2224 PID: Word;
2225 Pl: TPlayer;
2226 KillType, DeathType: Byte;
2227 Attacker: Word;
2228 begin
2229 Result := 0;
2230 if not gGameOn then Exit;
2231 PID := e_Raw_Read_Word(P);
2232 Pl := g_Player_Get(PID);
2233 if Pl = nil then Exit;
2235 KillType := e_Raw_Read_Byte(P);
2236 DeathType := e_Raw_Read_Byte(P);
2237 Attacker := e_Raw_Read_Word(P);
2239 with Pl do
2240 begin
2241 Kill(KillType, Attacker, DeathType);
2242 SoftReset;
2243 end;
2244 end;
2246 function MC_RECV_PlayerDelete(P: Pointer): Word;
2248 PID: Word;
2249 Pl: TPlayer;
2250 begin
2251 PID := e_Raw_Read_Word(P);
2252 Pl := g_Player_Get(PID);
2253 Result := 0;
2254 if Pl = nil then Exit;
2256 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2257 e_WriteLog('NET: Player ' + Pl.Name + ' [' + IntToStr(PID) + '] removed.', MSG_NOTIFY);
2259 g_Player_Remove(PID);
2261 Result := PID;
2262 end;
2264 function MC_RECV_PlayerFire(P: Pointer): Word;
2266 PID: Word;
2267 Weap: Byte;
2268 Pl: TPlayer;
2269 X, Y, AX, AY: Integer;
2270 SHID: Integer;
2271 begin
2272 Result := 0;
2273 if not gGameOn then Exit;
2274 PID := e_Raw_Read_Word(P);
2275 Pl := g_Player_Get(PID);
2276 if Pl = nil then Exit;
2278 Weap := e_Raw_Read_Byte(P);
2279 X := e_Raw_Read_LongInt(P);
2280 Y := e_Raw_Read_LongInt(P);
2281 AX := e_Raw_Read_LongInt(P);
2282 AY := e_Raw_Read_LongInt(P);
2283 SHID := e_Raw_Read_LongInt(P);
2285 with Pl do
2286 if Live then NetFire(Weap, X, Y, AX, AY, SHID);
2287 end;
2289 procedure MC_RECV_PlayerSettings(P: Pointer);
2291 TmpName: string;
2292 TmpModel: string;
2293 TmpColor: TRGB;
2294 TmpTeam: Byte;
2295 Pl: TPlayer;
2296 PID: Word;
2297 begin
2298 PID := e_Raw_Read_Word(P);
2299 Pl := g_Player_Get(PID);
2300 if Pl = nil then Exit;
2302 TmpName := e_Raw_Read_String(P);
2303 TmpModel := e_Raw_Read_String(P);
2304 TmpColor.R := e_Raw_Read_Byte(P);
2305 TmpColor.G := e_Raw_Read_Byte(P);
2306 TmpColor.B := e_Raw_Read_Byte(P);
2307 TmpTeam := e_Raw_Read_Byte(P);
2309 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
2310 begin
2311 Pl.ChangeTeam(TmpTeam);
2312 if gPlayer1 = Pl then
2313 gPlayer1Settings.Team := TmpTeam;
2314 if gPlayer2 = Pl then
2315 gPlayer2Settings.Team := TmpTeam;
2316 end else
2317 Pl.SetColor(TmpColor);
2319 if Pl.Name <> TmpName then
2320 begin
2321 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
2322 Pl.Name := TmpName;
2323 end;
2325 if TmpModel <> Pl.Model.Name then
2326 Pl.SetModel(TmpModel);
2327 end;
2329 // ITEM
2331 procedure MC_RECV_ItemSpawn(P: Pointer);
2333 ID: Word;
2334 AID: DWord;
2335 X, Y, VX, VY: Integer;
2336 T: Byte;
2337 Quiet, Fall{, Resp}: Boolean;
2338 Anim: TAnimation;
2339 begin
2340 if not gGameOn then Exit;
2341 ID := e_Raw_Read_Word(P);
2342 Quiet := e_Raw_Read_Byte(P) <> 0;
2343 T := e_Raw_Read_Byte(P);
2344 Fall := e_Raw_Read_Byte(P) <> 0;
2345 {Resp :=} e_Raw_Read_Byte(P);
2346 X := e_Raw_Read_LongInt(P);
2347 Y := e_Raw_Read_LongInt(P);
2348 VX := e_Raw_Read_LongInt(P);
2349 VY := e_Raw_Read_LongInt(P);
2351 g_Items_Create(X, Y, T, Fall, False, False, ID);
2352 gItems[ID].Obj.Vel.X := VX;
2353 gItems[ID].Obj.Vel.Y := VY;
2355 if not Quiet then
2356 begin
2357 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
2358 if g_Frames_Get(AID, 'FRAMES_ITEM_RESPAWN') then
2359 begin
2360 Anim := TAnimation.Create(AID, False, 4);
2361 g_GFX_OnceAnim(X+(gItems[ID].Obj.Rect.Width div 2)-16, Y+(gItems[ID].Obj.Rect.Height div 2)-16, Anim);
2362 Anim.Free();
2363 end;
2364 end;
2365 end;
2367 procedure MC_RECV_ItemDestroy(P: Pointer);
2369 ID: Word;
2370 Quiet: Boolean;
2371 begin
2372 if not gGameOn then Exit;
2373 ID := e_Raw_Read_Word(P);
2374 Quiet := e_Raw_Read_Byte(P) <> 0;
2375 if gItems = nil then Exit;
2376 if (ID > High(gItems)) then Exit;
2378 if not Quiet then
2379 if gSoundEffectsDF then
2380 begin
2381 if gItems[ID].ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL,
2382 ITEM_INVIS, ITEM_MEDKIT_BLACK, ITEM_JETPACK] then
2383 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ',
2384 gItems[ID].Obj.X, gItems[ID].Obj.Y)
2385 else
2386 if gItems[ID].ItemType in [ITEM_WEAPON_SAW, ITEM_WEAPON_PISTOL, ITEM_WEAPON_SHOTGUN1, ITEM_WEAPON_SHOTGUN2,
2387 ITEM_WEAPON_CHAINGUN, ITEM_WEAPON_ROCKETLAUNCHER, ITEM_WEAPON_PLASMA,
2388 ITEM_WEAPON_BFG, ITEM_WEAPON_SUPERPULEMET, ITEM_AMMO_BACKPACK] then
2389 g_Sound_PlayExAt('SOUND_ITEM_GETWEAPON',
2390 gItems[ID].Obj.X, gItems[ID].Obj.Y)
2391 else
2392 g_Sound_PlayExAt('SOUND_ITEM_GETITEM',
2393 gItems[ID].Obj.X, gItems[ID].Obj.Y);
2395 else
2396 begin
2397 if gItems[ID].ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_SUIT,
2398 ITEM_MEDKIT_BLACK, ITEM_INVUL, ITEM_INVIS, ITEM_JETPACK] then
2399 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ',
2400 gItems[ID].Obj.X, gItems[ID].Obj.Y)
2401 else
2402 if gItems[ID].ItemType in [ITEM_WEAPON_SAW, ITEM_WEAPON_PISTOL, ITEM_WEAPON_SHOTGUN1, ITEM_WEAPON_SHOTGUN2,
2403 ITEM_WEAPON_CHAINGUN, ITEM_WEAPON_ROCKETLAUNCHER, ITEM_WEAPON_PLASMA,
2404 ITEM_WEAPON_BFG, ITEM_WEAPON_SUPERPULEMET] then
2405 g_Sound_PlayExAt('SOUND_ITEM_GETWEAPON',
2406 gItems[ID].Obj.X, gItems[ID].Obj.Y)
2407 else
2408 g_Sound_PlayExAt('SOUND_ITEM_GETITEM',
2409 gItems[ID].Obj.X, gItems[ID].Obj.Y);
2410 end;
2412 g_Items_Remove(ID);
2413 end;
2415 // PANEL
2417 procedure MC_RECV_PanelTexture(P: Pointer);
2419 TP: TPanel;
2420 PType: Word;
2421 ID: LongWord;
2422 Tex, Fr: Integer;
2423 Loop, Cnt: Byte;
2424 begin
2425 if not gGameOn then Exit;
2426 PType := e_Raw_Read_Word(P);
2427 ID := e_Raw_Read_LongWord(P);
2428 Tex := e_Raw_Read_LongInt(P);
2429 Fr := e_Raw_Read_LongInt(P);
2430 Cnt := e_Raw_Read_Byte(P);
2431 Loop := e_Raw_Read_Byte(P);
2433 TP := nil;
2435 case PType of
2436 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
2437 if gWalls <> nil then
2438 TP := gWalls[ID];
2439 PANEL_FORE:
2440 if gRenderForegrounds <> nil then
2441 TP := gRenderForegrounds[ID];
2442 PANEL_BACK:
2443 if gRenderBackgrounds <> nil then
2444 TP := gRenderBackgrounds[ID];
2445 PANEL_WATER:
2446 if gWater <> nil then
2447 TP := gWater[ID];
2448 PANEL_ACID1:
2449 if gAcid1 <> nil then
2450 TP := gAcid1[ID];
2451 PANEL_ACID2:
2452 if gAcid2 <> nil then
2453 TP := gAcid2[ID];
2454 PANEL_STEP:
2455 if gSteps <> nil then
2456 TP := gSteps[ID];
2457 else
2458 Exit;
2459 end;
2461 if TP <> nil then
2462 if Loop = 0 then
2463 begin // switch texture
2464 TP.SetTexture(Tex, Loop);
2465 TP.SetFrame(Fr, Cnt);
2466 end else // looped or non-looped animation
2467 TP.NextTexture(Loop);
2468 end;
2470 procedure MC_RECV_PanelState(P: Pointer);
2472 ID: LongWord;
2473 E: Boolean;
2474 Lift: Byte;
2475 PType: Word;
2476 X, Y: Integer;
2477 begin
2478 if not gGameOn then Exit;
2479 PType := e_Raw_Read_Word(P);
2480 ID := e_Raw_Read_LongWord(P);
2481 E := (e_Raw_Read_Byte(P) <> 0);
2482 Lift := e_Raw_Read_Byte(P);
2483 X := e_Raw_Read_LongInt(P);
2484 Y := e_Raw_Read_LongInt(P);
2486 case PType of
2487 PANEL_WALL, PANEL_OPENDOOR, PANEL_CLOSEDOOR:
2488 if E then
2489 g_Map_EnableWall(ID)
2490 else
2491 g_Map_DisableWall(ID);
2493 PANEL_LIFTUP, PANEL_LIFTDOWN, PANEL_LIFTLEFT, PANEL_LIFTRIGHT:
2494 g_Map_SetLift(ID, Lift);
2496 PANEL_BACK:
2497 begin
2498 gRenderBackgrounds[ID].X := X;
2499 gRenderBackgrounds[ID].Y := Y;
2500 end;
2502 PANEL_FORE:
2503 begin
2504 gRenderForegrounds[ID].X := X;
2505 gRenderForegrounds[ID].Y := Y;
2506 end;
2507 end;
2508 end;
2510 // TRIGGERS
2512 procedure MC_RECV_TriggerSound(P: Pointer);
2514 SPlaying: Boolean;
2515 SPos, SID: LongWord;
2516 SCount: LongInt;
2517 I: Integer;
2518 begin
2519 if not gGameOn then Exit;
2520 if gTriggers = nil then Exit;
2522 SID := e_Raw_Read_LongWord(P);
2523 SPlaying := e_Raw_Read_Byte(P) <> 0;
2524 SPos := e_Raw_Read_LongWord(P);
2525 SCount := e_Raw_Read_LongInt(P);
2527 for I := Low(gTriggers) to High(gTriggers) do
2528 if gTriggers[I].TriggerType = TRIGGER_SOUND then
2529 if gTriggers[I].ClientID = SID then
2530 with gTriggers[I] do
2531 begin
2532 if SPlaying then
2533 begin
2534 if Data.Local then
2535 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), Data.Volume/255.0)
2536 else
2537 Sound.PlayPanVolume((Data.Pan-127.0)/128.0, Data.Volume/255.0);
2538 Sound.SetPosition(SPos);
2540 else
2541 if Sound.IsPlaying then Sound.Stop;
2543 SoundPlayCount := SCount;
2544 end;
2545 end;
2547 procedure MC_RECV_TriggerMusic(P: Pointer);
2549 MName: string;
2550 MPlaying: Boolean;
2551 MPos: LongWord;
2552 MPaused: Boolean;
2553 begin
2554 if not gGameOn then Exit;
2556 MName := e_Raw_Read_String(P);
2557 MPlaying := e_Raw_Read_Byte(P) <> 0;
2558 MPos := e_Raw_Read_LongWord(P);
2559 MPaused := e_Raw_Read_Byte(P) <> 0;
2561 if MPlaying then
2562 begin
2563 gMusic.SetByName(MName);
2564 gMusic.Play(True);
2565 gMusic.SetPosition(MPos);
2566 gMusic.SpecPause := MPaused;
2568 else
2569 if gMusic.IsPlaying then gMusic.Stop;
2570 end;
2572 // MONSTERS
2574 procedure MC_RECV_MonsterSpawn(P: Pointer);
2576 ID: Word;
2577 MType, MState, MDir, MAnim, MBehav: Byte;
2578 X, Y, VX, VY, MTargTime, MHealth, MAmmo, MSleep: Integer;
2579 MTarg: Word;
2580 M: TMonster;
2581 begin
2582 ID := e_Raw_Read_Word(P);
2583 M := g_Monsters_Get(ID);
2584 if M <> nil then
2585 Exit;
2587 MType := e_Raw_Read_Byte(P);
2588 MState := e_Raw_Read_Byte(P);
2589 MAnim := e_Raw_Read_Byte(P);
2590 MTarg := e_Raw_Read_Word(P);
2591 MTargTime := e_Raw_Read_LongInt(P);
2592 MBehav := e_Raw_Read_Byte(P);
2593 MSleep := e_Raw_Read_LongInt(P);
2594 MHealth := e_Raw_Read_LongInt(P);
2595 MAmmo := e_Raw_Read_LongInt(P);
2597 X := e_Raw_Read_LongInt(P);
2598 Y := e_Raw_Read_LongInt(P);
2599 VX := e_Raw_Read_LongInt(P);
2600 VY := e_Raw_Read_LongInt(P);
2601 MDir := e_Raw_Read_Byte(P);
2603 g_Monsters_Create(MType, X, Y, TDirection(MDir), False, ID);
2604 M := g_Monsters_Get(ID);
2605 if M = nil then
2606 Exit;
2608 with M do
2609 begin
2610 GameX := X;
2611 GameY := Y;
2612 GameVelX := VX;
2613 GameVelY := VY;
2615 MonsterAnim := MAnim;
2616 MonsterTargetUID := MTarg;
2617 MonsterTargetTime := MTargTime;
2618 MonsterBehaviour := MBehav;
2619 MonsterSleep := MSleep;
2620 MonsterAmmo := MAmmo;
2621 SetHealth(MHealth);
2623 SetState(MState);
2624 end;
2625 end;
2627 procedure MC_RECV_MonsterPos(P: Pointer);
2629 M: TMonster;
2630 ID: Word;
2631 begin
2632 ID := e_Raw_Read_Word(P);
2633 M := g_Monsters_Get(ID);
2634 if M = nil then
2635 Exit;
2637 with M do
2638 begin
2639 GameX := e_Raw_Read_LongInt(P);
2640 GameY := e_Raw_Read_LongInt(P);
2641 GameVelX := e_Raw_Read_LongInt(P);
2642 GameVelY := e_Raw_Read_LongInt(P);
2643 GameDirection := TDirection(e_Raw_Read_Byte(P));
2644 end;
2645 end;
2647 procedure MC_RECV_MonsterState(P: Pointer);
2649 ID: Integer;
2650 MState, MFAnm: Byte;
2651 M: TMonster;
2652 AnimRevert: Boolean;
2653 begin
2654 ID := e_Raw_Read_Word(P);
2655 M := g_Monsters_Get(ID);
2656 if M = nil then Exit;
2658 MState := e_Raw_Read_Byte(P);
2659 MFAnm := e_Raw_Read_Byte(P);
2661 with M do
2662 begin
2663 MonsterTargetUID := e_Raw_Read_Word(P);
2664 MonsterTargetTime := e_Raw_Read_LongInt(P);
2665 MonsterSleep := e_Raw_Read_LongInt(P);
2666 MonsterHealth := e_Raw_Read_LongInt(P);
2667 MonsterAmmo := e_Raw_Read_LongInt(P);
2668 MonsterPain := e_Raw_Read_LongInt(P);
2669 AnimRevert := e_Raw_Read_Byte(P) <> 0;
2670 RevertAnim(AnimRevert);
2672 if MonsterState <> MState then
2673 begin
2674 if (MState = MONSTATE_GO) and (MonsterState = MONSTATE_SLEEP) then
2675 WakeUpSound;
2676 if (MState = MONSTATE_DIE) then
2677 DieSound;
2678 if (MState = MONSTATE_PAIN) then
2679 MakeBloodSimple(Min(200, MonsterPain));
2680 if (MState = MONSTATE_ATTACK) then
2681 kick(nil);
2682 if (MState = MONSTATE_DEAD) then
2683 SetDeadAnim;
2685 SetState(MState, MFAnm);
2686 end;
2687 end;
2688 end;
2690 procedure MC_RECV_MonsterShot(P: Pointer);
2692 ID: Integer;
2693 M: TMonster;
2694 X, Y, VX, VY: Integer;
2695 begin
2696 ID := e_Raw_Read_Word(P);
2698 M := g_Monsters_Get(ID);
2699 if M = nil then Exit;
2701 X := e_Raw_Read_LongInt(P);
2702 Y := e_Raw_Read_LongInt(P);
2703 VX := e_Raw_Read_LongInt(P);
2704 VY := e_Raw_Read_LongInt(P);
2706 M.ClientAttack(X, Y, VX, VY);
2707 end;
2709 procedure MC_RECV_MonsterDelete(P: Pointer);
2711 ID: Integer;
2712 M: TMonster;
2713 begin
2714 ID := e_Raw_Read_Word(P);
2715 M := g_Monsters_Get(ID);
2716 if M = nil then Exit;
2718 gMonsters[ID].SetState(5);
2719 gMonsters[ID].MonsterRemoved := True;
2720 end;
2722 procedure MC_RECV_TimeSync(P: Pointer);
2724 Time: LongWord;
2725 begin
2726 Time := e_Raw_Read_LongWord(P);
2728 if gState = STATE_INTERCUSTOM then
2729 gServInterTime := Min(Time, 255);
2730 end;
2732 procedure MC_RECV_VoteEvent(P: Pointer);
2734 EvID: Byte;
2735 Str1, Str2: string;
2736 Int1, Int2: SmallInt;
2737 begin
2738 EvID := e_Raw_Read_Byte(P);
2739 Int1 := e_Raw_Read_SmallInt(P);
2740 Int2 := e_Raw_Read_SmallInt(P);
2741 Str1 := e_Raw_Read_String(P);
2742 Str2 := e_Raw_Read_String(P);
2744 case EvID of
2745 NET_VE_STARTED:
2746 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True);
2747 NET_VE_PASSED:
2748 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True);
2749 NET_VE_FAILED:
2750 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
2751 NET_VE_VOTE:
2752 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True);
2753 NET_VE_INPROGRESS:
2754 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True);
2755 end;
2756 end;
2758 // CLIENT SEND
2760 procedure MC_SEND_Info(Password: string);
2761 begin
2762 e_Buffer_Clear(@NetOut);
2764 e_Buffer_Write(@NetOut, Byte(NET_MSG_INFO));
2765 e_Buffer_Write(@NetOut, GAME_VERSION);
2766 e_Buffer_Write(@NetOut, Password);
2767 e_Buffer_Write(@NetOut, gPlayer1Settings.Name);
2768 e_Buffer_Write(@NetOut, gPlayer1Settings.Model);
2769 e_Buffer_Write(@NetOut, gPlayer1Settings.Color.R);
2770 e_Buffer_Write(@NetOut, gPlayer1Settings.Color.G);
2771 e_Buffer_Write(@NetOut, gPlayer1Settings.Color.B);
2772 e_Buffer_Write(@NetOut, gPlayer1Settings.Team);
2774 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2775 end;
2777 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
2778 begin
2779 e_Buffer_Write(@NetOut, Byte(NET_MSG_CHAT));
2780 e_Buffer_Write(@NetOut, Txt);
2781 e_Buffer_Write(@NetOut, Mode);
2783 g_Net_Client_Send(True, NET_CHAN_CHAT);
2784 end;
2786 function isKeyPressed (key1: Word; key2: Word): Boolean;
2787 begin
2788 if (key1 <> 0) and e_KeyPressed(key1) then begin result := true; exit; end;
2789 if (key2 <> 0) and e_KeyPressed(key2) then begin result := true; exit; end;
2790 result := false;
2791 end;
2793 procedure MC_SEND_PlayerPos();
2795 kByte: Word;
2796 Predict: Boolean;
2797 strafeDir: Byte;
2798 WeaponSelect: Word = 0;
2799 I: Integer;
2800 begin
2801 if not gGameOn then Exit;
2802 if gPlayers = nil then Exit;
2803 if gPlayer1 = nil then Exit;
2805 kByte := 0;
2806 Predict := NetPredictSelf; // and (not NetGotKeys);
2808 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2809 begin
2810 strafeDir := P1MoveButton shr 4;
2811 P1MoveButton := P1MoveButton and $0F;
2812 with gGameControls.P1Control do
2813 begin
2814 if isKeyPressed(KeyLeft, KeyLeft2) and (not isKeyPressed(KeyRight, KeyRight2)) then P1MoveButton := 1
2815 else if (not isKeyPressed(KeyLeft, KeyLeft2)) and isKeyPressed(KeyRight, KeyRight2) then P1MoveButton := 2
2816 else if (not isKeyPressed(KeyLeft, KeyLeft2)) and (not isKeyPressed(KeyRight, KeyRight2)) then P1MoveButton := 0;
2818 // strafing
2819 if isKeyPressed(KeyStrafe, KeyStrafe2) then
2820 begin
2821 // new strafe mechanics
2822 if (strafeDir = 0) then strafeDir := P1MoveButton; // start strafing
2823 // now set direction according to strafe (reversed)
2824 if (strafeDir = 2) then gPlayer1.SetDirection(D_LEFT)
2825 else if (strafeDir = 1) then gPlayer1.SetDirection(D_RIGHT);
2827 else
2828 begin
2829 if (P1MoveButton = 2) and isKeyPressed(KeyLeft, KeyLeft2) then gPlayer1.SetDirection(D_LEFT)
2830 else if (P1MoveButton = 1) and isKeyPressed(KeyRight, KeyRight2) then gPlayer1.SetDirection(D_RIGHT)
2831 else if P1MoveButton <> 0 then gPlayer1.SetDirection(TDirection(P1MoveButton-1));
2832 end;
2834 gPlayer1.ReleaseKeys;
2835 if P1MoveButton = 1 then
2836 begin
2837 kByte := kByte or NET_KEY_LEFT;
2838 if Predict then gPlayer1.PressKey(KEY_LEFT, 10000);
2839 end;
2840 if P1MoveButton = 2 then
2841 begin
2842 kByte := kByte or NET_KEY_RIGHT;
2843 if Predict then gPlayer1.PressKey(KEY_RIGHT, 10000);
2844 end;
2845 if isKeyPressed(KeyUp, KeyUp2) then
2846 begin
2847 kByte := kByte or NET_KEY_UP;
2848 gPlayer1.PressKey(KEY_UP, 10000);
2849 end;
2850 if isKeyPressed(KeyDown, KeyDown2) then
2851 begin
2852 kByte := kByte or NET_KEY_DOWN;
2853 gPlayer1.PressKey(KEY_DOWN, 10000);
2854 end;
2855 if isKeyPressed(KeyJump, KeyJump2) then
2856 begin
2857 kByte := kByte or NET_KEY_JUMP;
2858 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
2859 end;
2860 if isKeyPressed(KeyFire, KeyFire2) then kByte := kByte or NET_KEY_FIRE;
2861 if isKeyPressed(KeyOpen, KeyOpen2) then kByte := kByte or NET_KEY_OPEN;
2862 if isKeyPressed(KeyNextWeapon, KeyNextWeapon2) then kByte := kByte or NET_KEY_NW;
2863 if isKeyPressed(KeyPrevWeapon, KeyPrevWeapon2) then kByte := kByte or NET_KEY_PW;
2864 for I := 0 to High(KeyWeapon) do
2865 if isKeyPressed(KeyWeapon[I], KeyWeapon2[I]) then
2866 WeaponSelect := WeaponSelect or Word(1 shl I);
2867 end;
2868 // fix movebutton state
2869 P1MoveButton := P1MoveButton or (strafeDir shl 4);
2871 else
2872 kByte := NET_KEY_CHAT;
2874 e_Buffer_Write(@NetOut, Byte(NET_MSG_PLRPOS));
2875 e_Buffer_Write(@NetOut, gTime);
2876 e_Buffer_Write(@NetOut, kByte);
2877 e_Buffer_Write(@NetOut, Byte(gPlayer1.Direction));
2878 e_Buffer_Write(@NetOut, WeaponSelect);
2879 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
2880 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS);
2882 //kBytePrev := kByte;
2883 //kDirPrev := gPlayer1.Direction;
2884 end;
2886 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
2887 begin
2888 e_Buffer_Write(@NetOut, Byte(NET_MSG_VOTE_EVENT));
2889 e_Buffer_Write(@NetOut, Byte(Start));
2890 e_Buffer_Write(@NetOut, Command);
2891 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2892 end;
2894 procedure MC_SEND_PlayerSettings();
2895 begin
2896 e_Buffer_Write(@NetOut, Byte(NET_MSG_PLRSET));
2897 e_Buffer_Write(@NetOut, gPlayer1Settings.Name);
2898 e_Buffer_Write(@NetOut, gPlayer1Settings.Model);
2899 e_Buffer_Write(@NetOut, gPlayer1Settings.Color.R);
2900 e_Buffer_Write(@NetOut, gPlayer1Settings.Color.G);
2901 e_Buffer_Write(@NetOut, gPlayer1Settings.Color.B);
2902 e_Buffer_Write(@NetOut, gPlayer1Settings.Team);
2904 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2905 end;
2907 procedure MC_SEND_FullStateRequest();
2908 begin
2909 e_Buffer_Write(@NetOut, Byte(NET_MSG_REQFST));
2911 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2912 end;
2914 procedure MC_SEND_CheatRequest(Kind: Byte);
2915 begin
2916 e_Buffer_Write(@NetOut, Byte(NET_MSG_CHEAT));
2917 e_Buffer_Write(@NetOut, Kind);
2919 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
2920 end;
2921 procedure MC_SEND_RCONPassword(Password: string);
2922 begin
2923 e_Buffer_Write(@NetOut, Byte(NET_MSG_RCON_AUTH));
2924 e_Buffer_Write(@NetOut, Password);
2926 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2927 end;
2928 procedure MC_SEND_RCONCommand(Cmd: string);
2929 begin
2930 e_Buffer_Write(@NetOut, Byte(NET_MSG_RCON_CMD));
2931 e_Buffer_Write(@NetOut, Cmd);
2933 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2934 end;
2936 // i have no idea why all this stuff is in here
2938 function ReadFile(const FileName: TFileName): AByte;
2940 FileStream : TStream;
2941 fname: string;
2942 begin
2943 e_WriteLog(Format('NETWORK: looking for file "%s"', [FileName]), MSG_NOTIFY);
2944 fname := findDiskWad(FileName);
2945 if length(fname) = 0 then
2946 begin
2947 e_WriteLog(Format('NETWORK: file "%s" not found!', [FileName]), MSG_FATALERROR);
2948 SetLength(Result, 0);
2949 exit;
2950 end;
2951 e_WriteLog(Format('NETWORK: found file "%s"', [fname]), MSG_NOTIFY);
2952 Result := nil;
2953 FileStream := openDiskFileRO(fname);
2955 if FileStream.Size > 0 then
2956 begin
2957 SetLength(Result, FileStream.Size);
2958 FileStream.Read(Result[0], FileStream.Size);
2959 end;
2960 finally
2961 FileStream.Free;
2962 end;
2963 end;
2965 function CreateMapDataMsg(const FileName: TFileName; ResList: TStringList): TMapDataMsg;
2967 i: Integer;
2968 begin
2969 Result.MsgId := NET_MSG_MAP_RESPONSE;
2970 Result.FileData := ReadFile(FileName);
2971 Result.FileSize := Length(Result.FileData);
2973 SetLength(Result.ExternalResources, ResList.Count);
2974 for i:=0 to ResList.Count-1 do
2975 begin
2976 Result.ExternalResources[i].Name := ResList.Strings[i];
2977 Result.ExternalResources[i].md5 := MD5File(GameDir+'/wads/'+ResList.Strings[i]);
2978 end;
2979 end;
2981 procedure ResDataMsgToBytes(var bytes: AByte; const ResData: TResDataMsg);
2983 ResultStream: TMemoryStream;
2984 begin
2985 ResultStream := TMemoryStream.Create;
2987 ResultStream.WriteBuffer(ResData.MsgId, SizeOf(ResData.MsgId)); //msgId
2988 ResultStream.WriteBuffer(ResData.FileSize, SizeOf(ResData.FileSize)); //file size
2989 ResultStream.WriteBuffer(ResData.FileData[0], ResData.FileSize); //file data
2991 SetLength(bytes, ResultStream.Size);
2992 ResultStream.Seek(0, soFromBeginning);
2993 ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
2995 ResultStream.Free;
2996 end;
2998 function ResDataFromMsgStream(msgStream: TMemoryStream):TResDataMsg;
2999 begin
3000 msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
3001 msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize));
3002 SetLength(Result.FileData, Result.FileSize);
3003 msgStream.ReadBuffer(Result.FileData[0], Result.FileSize);
3004 end;
3006 procedure MapDataMsgToBytes(var bytes: AByte; const MapDataMsg: TMapDataMsg);
3008 ResultStream: TMemoryStream;
3009 resCount: Integer;
3010 begin
3011 resCount := Length(MapDataMsg.ExternalResources);
3013 ResultStream := TMemoryStream.Create;
3015 ResultStream.WriteBuffer(MapDataMsg.MsgId, SizeOf(MapDataMsg.MsgId)); //msgId
3016 ResultStream.WriteBuffer(MapDataMsg.FileSize, SizeOf(MapDataMsg.FileSize)); //file size
3017 ResultStream.WriteBuffer(MapDataMsg.FileData[0], MapDataMsg.FileSize); //file data
3019 ResultStream.WriteBuffer(resCount, SizeOf(resCount)); //res count
3020 ResultStream.WriteBuffer(MapDataMsg.ExternalResources[0], resCount*SizeOf(TExternalResourceInfo)); //res data
3022 SetLength(bytes, ResultStream.Size);
3023 ResultStream.Seek(0, soFromBeginning);
3024 ResultStream.ReadBuffer(bytes[0], ResultStream.Size);
3026 ResultStream.Free;
3027 end;
3029 function MapDataFromMsgStream(msgStream: TMemoryStream):TMapDataMsg;
3031 resCount: Integer;
3032 begin
3033 msgStream.ReadBuffer(Result.MsgId, SizeOf(Result.MsgId));
3034 msgStream.ReadBuffer(Result.FileSize, SizeOf(Result.FileSize)); //file size
3036 SetLength(Result.FileData, Result.FileSize);
3037 msgStream.ReadBuffer(Result.FileData[0], Result.FileSize); //file data
3039 msgStream.ReadBuffer(resCount, SizeOf(resCount)); //res count
3040 SetLength(Result.ExternalResources, resCount);
3042 msgStream.ReadBuffer(Result.ExternalResources[0], resCount * SizeOf(TExternalResourceInfo)); //res data
3043 end;
3045 function IsValidFileName(const S: String): Boolean;
3046 const
3047 Forbidden: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
3049 I: Integer;
3050 begin
3051 Result := S <> '';
3052 for I := 1 to Length(S) do
3053 Result := Result and (not(S[I] in Forbidden));
3054 end;
3056 function IsValidFilePath(const S: String): Boolean;
3058 I: Integer;
3059 begin
3060 Result := False;
3061 if not IsValidFileName(S) then exit;
3062 if FileExists(S) then exit;
3063 I := LastDelimiter('\/', S);
3064 if (I > 0) then
3065 if (not DirectoryExists(Copy(S, 1, I-1))) then
3066 exit;
3067 Result := True;
3068 end;
3070 procedure MC_SEND_MapRequest();
3071 begin
3072 e_Buffer_Write(@NetOut, Byte(NET_MSG_MAP_REQUEST));
3073 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3074 end;
3076 procedure MC_SEND_ResRequest(const resName: AnsiString);
3077 begin
3078 e_Buffer_Write(@NetOut, Byte(NET_MSG_RES_REQUEST));
3079 e_Buffer_Write(@NetOut, resName);
3080 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3081 end;
3083 procedure MH_RECV_MapRequest(C: pTNetClient; P: Pointer);
3085 payload: AByte;
3086 peer: pENetPeer;
3087 mapDataMsg: TMapDataMsg;
3088 begin
3089 e_WriteLog('NET: Received map request from ' +
3090 DecodeIPV4(C.Peer.address.host), MSG_NOTIFY);
3092 mapDataMsg := CreateMapDataMsg(MapsDir + gGameSettings.WAD, gExternalResources);
3093 peer := NetClients[C.ID].Peer;
3095 MapDataMsgToBytes(payload, mapDataMsg);
3096 g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
3098 payload := nil;
3099 mapDataMsg.FileData := nil;
3100 mapDataMsg.ExternalResources := nil;
3101 end;
3103 procedure MH_RECV_ResRequest(C: pTNetClient; P: Pointer);
3105 payload: AByte;
3106 peer: pENetPeer;
3107 FileName: String;
3108 resDataMsg: TResDataMsg;
3109 begin
3110 FileName := ExtractFileName(e_Raw_Read_String(P));
3111 e_WriteLog('NET: Received res request: ' + FileName +
3112 ' from ' + DecodeIPV4(C.Peer.address.host), MSG_NOTIFY);
3114 if not IsValidFilePath(FileName) then
3115 begin
3116 e_WriteLog('Invalid filename: ' + FileName, MSG_WARNING);
3117 exit;
3118 end;
3120 peer := NetClients[C.ID].Peer;
3122 if gExternalResources.IndexOf(FileName) > -1 then
3123 begin
3124 resDataMsg.MsgId := NET_MSG_RES_RESPONSE;
3125 resDataMsg.FileData := ReadFile(GameDir+'/wads/'+FileName);
3126 resDataMsg.FileSize := Length(resDataMsg.FileData);
3128 ResDataMsgToBytes(payload, resDataMsg);
3129 g_Net_SendData(payload, peer, True, NET_CHAN_DOWNLOAD);
3130 end;
3131 end;
3133 end.