DEADSOFTWARE

1c44acacf18cd4b437c528ac620b1c3c4c168f2d
[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, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 unit g_netmsg;
18 interface
20 uses e_msg, g_net, g_triggers, Classes, SysUtils, md5;
22 const
23 NET_MSG_INFO = 100;
25 NET_MSG_CHAT = 101;
26 NET_MSG_SND = 102;
27 NET_MSG_GFX = 103;
28 NET_MSG_GEVENT = 104;
29 NET_MSG_SCORE = 105;
30 NET_MSG_COOP = 106;
31 NET_MSG_FLAG = 107;
32 NET_MSG_REQFST = 108;
33 NET_MSG_GSET = 109;
35 NET_MSG_PLR = 111;
36 NET_MSG_PLRPOS = 112;
37 NET_MSG_PLRSTA = 113;
38 NET_MSG_PLRDEL = 114;
39 NET_MSG_PLRDMG = 115;
40 NET_MSG_PLRDIE = 116;
41 NET_MSG_PLRFIRE= 117;
42 NET_MSG_PLRSET = 119;
43 NET_MSG_CHEAT = 120;
45 NET_MSG_ISPAWN = 121;
46 NET_MSG_IDEL = 122;
48 NET_MSG_MSPAWN = 131;
49 NET_MSG_MPOS = 132;
50 NET_MSG_MSTATE = 133;
51 NET_MSG_MSHOT = 134;
52 NET_MSG_MDEL = 135;
54 NET_MSG_PSTATE = 141;
55 NET_MSG_PTEX = 142;
57 NET_MSG_TSOUND = 151;
58 NET_MSG_TMUSIC = 152;
60 NET_MSG_SHDEL = 161;
61 NET_MSG_SHADD = 162;
62 NET_MSG_SHPOS = 163;
64 NET_MSG_RCON_AUTH = 191;
65 NET_MSG_RCON_CMD = 192;
66 NET_MSG_TIME_SYNC = 194;
67 NET_MSG_VOTE_EVENT = 195;
69 {
70 NET_MSG_MAP_REQUEST = 201;
71 NET_MSG_MAP_RESPONSE = 202;
72 NET_MSG_RES_REQUEST = 203;
73 NET_MSG_RES_RESPONSE = 204;
74 }
76 NET_CHAT_SYSTEM = 0;
77 NET_CHAT_PLAYER = 1;
78 NET_CHAT_TEAM = 2;
80 NET_RCON_NOAUTH = 0;
81 NET_RCON_PWGOOD = 1;
82 NET_RCON_PWBAD = 2;
84 NET_GFX_SPARK = 1;
85 NET_GFX_TELE = 2;
86 NET_GFX_RESPAWN = 3;
87 NET_GFX_FIRE = 4;
88 NET_GFX_EXPLODE = 5;
89 NET_GFX_BFGEXPL = 6;
90 NET_GFX_BFGHIT = 7;
91 NET_GFX_SHELL1 = 8;
92 NET_GFX_SHELL2 = 9;
93 NET_GFX_SHELL3 = 10;
95 NET_EV_MAPSTART = 1;
96 NET_EV_MAPEND = 2;
97 NET_EV_CHANGE_TEAM = 3;
98 NET_EV_PLAYER_KICK = 4;
99 NET_EV_PLAYER_BAN = 5;
100 NET_EV_LMS_WARMUP = 6;
101 NET_EV_LMS_SURVIVOR = 7;
102 NET_EV_RCON = 8;
103 NET_EV_BIGTEXT = 9;
104 NET_EV_SCORE = 10;
105 NET_EV_SCORE_MSG = 11;
106 NET_EV_LMS_START = 12;
107 NET_EV_LMS_WIN = 13;
108 NET_EV_TLMS_WIN = 14;
109 NET_EV_LMS_LOSE = 15;
110 NET_EV_LMS_DRAW = 16;
111 NET_EV_KILLCOMBO = 17;
112 NET_EV_PLAYER_TOUCH = 18;
113 NET_EV_SECRET = 19;
114 NET_EV_INTER_READY = 20;
116 NET_VE_STARTED = 1;
117 NET_VE_PASSED = 2;
118 NET_VE_FAILED = 3;
119 NET_VE_VOTE = 4;
120 NET_VE_REVOKE = 5;
121 NET_VE_INPROGRESS = 6;
123 NET_FLAG_GET = 1;
124 NET_FLAG_DROP = 2;
125 NET_FLAG_CAP = 3;
126 NET_FLAG_RETURN = 4;
128 NET_CHEAT_SUICIDE = 1;
129 NET_CHEAT_SPECTATE = 2;
130 NET_CHEAT_READY = 3;
132 NET_MAX_DIFFTIME = 5000 div 36;
134 // HOST MESSAGES
136 procedure MH_ProcessFirstSpawn (C: pTNetClient);
138 procedure MH_RECV_Info(C: pTNetClient; var M: TMsg);
139 procedure MH_RECV_Chat(C: pTNetClient; var M: TMsg);
140 procedure MH_RECV_FullStateRequest(C: pTNetClient; var M: TMsg);
141 function MH_RECV_PlayerPos(C: pTNetClient; var M: TMsg): Word;
142 procedure MH_RECV_PlayerSettings(C: pTNetClient; var M: TMsg);
143 procedure MH_RECV_CheatRequest(C: pTNetClient; var M: TMsg);
144 procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
145 procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
146 //procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
147 //procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
148 procedure MH_RECV_Vote(C: pTNetClient; var M: TMsg);
150 // GAME
151 procedure MH_SEND_Everything(CreatePlayers: Boolean {= False}; ID: Integer {= NET_EVERYONE});
152 procedure MH_SEND_Info(ID: Byte);
153 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
154 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
155 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
156 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
157 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
158 procedure MH_SEND_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
159 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
160 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
161 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
162 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
163 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
164 // PLAYER
165 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
166 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
167 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
168 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
169 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
170 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
171 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
172 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
173 // ITEM
174 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
175 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
176 // PANEL
177 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
178 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
179 // MONSTER
180 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
181 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
182 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
183 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
184 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
185 // TRIGGER
186 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
187 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
188 // MISC
189 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
190 procedure MH_SEND_VoteEvent(EvType: Byte;
191 StrArg1: string = 'a'; StrArg2: string = 'b';
192 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
193 ID: Integer = NET_EVERYONE);
195 // CLIENT MESSAGES //
197 // GAME
198 procedure MC_RECV_Chat(var M: TMsg);
199 procedure MC_RECV_Effect(var M: TMsg);
200 procedure MC_RECV_Sound(var M: TMsg);
201 procedure MC_RECV_GameStats(var M: TMsg);
202 procedure MC_RECV_CoopStats(var M: TMsg);
203 procedure MC_RECV_GameEvent(var M: TMsg);
204 procedure MC_RECV_FlagEvent(var M: TMsg);
205 procedure MC_RECV_GameSettings(var M: TMsg);
206 // PLAYER
207 function MC_RECV_PlayerCreate(var M: TMsg): Word;
208 function MC_RECV_PlayerPos(var M: TMsg): Word;
209 function MC_RECV_PlayerStats(var M: TMsg): Word;
210 function MC_RECV_PlayerDelete(var M: TMsg): Word;
211 function MC_RECV_PlayerDamage(var M: TMsg): Word;
212 function MC_RECV_PlayerDeath(var M: TMsg): Word;
213 function MC_RECV_PlayerFire(var M: TMsg): Word;
214 procedure MC_RECV_PlayerSettings(var M: TMsg);
215 // ITEM
216 procedure MC_RECV_ItemSpawn(var M: TMsg);
217 procedure MC_RECV_ItemDestroy(var M: TMsg);
218 // PANEL
219 procedure MC_RECV_PanelTexture(var M: TMsg);
220 procedure MC_RECV_PanelState(var M: TMsg);
221 // MONSTER
222 procedure MC_RECV_MonsterSpawn(var M: TMsg);
223 procedure MC_RECV_MonsterPos(var M: TMsg);
224 procedure MC_RECV_MonsterState(var M: TMsg);
225 procedure MC_RECV_MonsterShot(var M: TMsg);
226 procedure MC_RECV_MonsterDelete(var M: TMsg);
227 // SHOT
228 procedure MC_RECV_CreateShot(var M: TMsg);
229 procedure MC_RECV_UpdateShot(var M: TMsg);
230 procedure MC_RECV_DeleteShot(var M: TMsg);
231 // TRIGGER
232 procedure MC_RECV_TriggerSound(var M: TMsg);
233 procedure MC_RECV_TriggerMusic(var M: TMsg);
234 // MISC
235 procedure MC_RECV_TimeSync(var M: TMsg);
236 procedure MC_RECV_VoteEvent(var M: TMsg);
237 // SERVICE
238 procedure MC_SEND_Info(Password: string);
239 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
240 procedure MC_SEND_PlayerPos();
241 procedure MC_SEND_FullStateRequest();
242 procedure MC_SEND_PlayerSettings();
243 procedure MC_SEND_CheatRequest(Kind: Byte);
244 procedure MC_SEND_RCONPassword(Password: string);
245 procedure MC_SEND_RCONCommand(Cmd: string);
246 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
247 // DOWNLOAD
248 //procedure MC_SEND_MapRequest();
249 //procedure MC_SEND_ResRequest(const resName: AnsiString);
252 type
253 TExternalResourceInfo = record
254 Name: string[255];
255 md5: TMD5Digest;
256 end;
258 TResDataMsg = record
259 MsgId: Byte;
260 FileSize: Integer;
261 FileData: AByte;
262 end;
264 TMapDataMsg = record
265 MsgId: Byte;
266 FileSize: Integer;
267 FileData: AByte;
268 ExternalResources: array of TExternalResourceInfo;
269 end;
271 function IsValidFileName(const S: String): Boolean;
272 function IsValidFilePath(const S: String): Boolean;
275 implementation
277 uses
278 Math, ENet, e_input, e_graphics, e_log,
279 g_textures, g_gfx, g_sound, g_console, g_basic, g_options, g_main,
280 g_game, g_player, g_map, g_panel, g_items, g_weapons, g_phys, g_gui,
281 g_language, g_monsters, g_netmaster, utils, wadreader, MAPDEF;
283 const
284 NET_KEY_LEFT = 1;
285 NET_KEY_RIGHT = 2;
286 NET_KEY_UP = 4;
287 NET_KEY_DOWN = 8;
288 NET_KEY_JUMP = 16;
289 NET_KEY_FIRE = 32;
290 NET_KEY_OPEN = 64;
291 NET_KEY_NW = 256;
292 NET_KEY_PW = 512;
293 NET_KEY_CHAT = 2048;
294 NET_KEY_FORCEDIR = 4096;
296 //var
297 //kBytePrev: Word = 0;
298 //kDirPrev: TDirection = D_LEFT;
299 //HostGameTime: Word = 0;
302 function IsValidFileName(const S: String): Boolean;
303 const
304 Forbidden: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
305 var
306 I: Integer;
307 begin
308 Result := S <> '';
309 for I := 1 to Length(S) do
310 Result := Result and (not(S[I] in Forbidden));
311 end;
313 function IsValidFilePath(const S: String): Boolean;
314 var
315 I: Integer;
316 begin
317 Result := False;
318 if not IsValidFileName(S) then exit;
319 if FileExists(S) then exit;
320 I := LastDelimiter('\/', S);
321 if (I > 0) then
322 if (not DirectoryExists(Copy(S, 1, I-1))) then
323 exit;
324 Result := True;
325 end;
328 // HOST MESSAGES //
331 // GAME
333 procedure MH_RECV_Chat(C: pTNetClient; var M: TMsg);
334 var
335 Txt: string;
336 Mode: Byte;
337 PID: Word;
338 Pl: TPlayer;
339 begin
340 PID := C^.Player;
341 Pl := g_Player_Get(PID);
343 Txt := M.ReadString();
344 Mode := M.ReadByte();
345 if (Mode = NET_CHAT_SYSTEM) then
346 Mode := NET_CHAT_PLAYER; // prevent sending system messages from clients
347 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
348 Mode := NET_CHAT_PLAYER; // revert to player chat in non-team game
350 if Pl = nil then
351 MH_SEND_Chat(Txt, Mode)
352 else
353 MH_SEND_Chat(Pl.Name + ': ' + Txt, Mode, IfThen(Mode = NET_CHAT_TEAM, Pl.Team, NET_EVERYONE));
354 end;
356 procedure MH_RECV_Info(C: pTNetClient; var M: TMsg);
357 var
358 Ver, PName, Model, Pw: string;
359 R, G, B, T: Byte;
360 PID: Word;
361 Color: TRGB;
362 I: Integer;
363 begin
364 Ver := M.ReadString();
365 Pw := M.ReadString();
366 PName := M.ReadString();
367 Model := M.ReadString();
368 R := M.ReadByte();
369 G := M.ReadByte();
370 B := M.ReadByte();
371 T := M.ReadByte();
373 if Ver <> GAME_VERSION then
374 begin
375 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
376 _lc[I_NET_DISC_VERSION]);
377 enet_peer_disconnect(C^.Peer, NET_DISC_VERSION);
378 Exit;
379 end;
381 if g_Net_IsHostBanned(C^.Peer^.address.host) then
382 begin
383 if g_Net_IsHostBanned(C^.Peer^.address.host, True) then
384 begin
385 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
386 _lc[I_NET_DISC_BAN]);
387 enet_peer_disconnect(C^.Peer, NET_DISC_BAN);
388 end
389 else
390 begin
391 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
392 _lc[I_NET_DISC_BAN]);
393 enet_peer_disconnect(C^.Peer, NET_DISC_TEMPBAN);
394 end;
395 Exit;
396 end;
398 if NetPassword <> '' then
399 if AnsiLowerCase(NetPassword) <> AnsiLowerCase(Pw) then
400 begin
401 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
402 _lc[I_NET_DISC_PASSWORD]);
403 enet_peer_disconnect(C^.Peer, NET_DISC_PASSWORD);
404 Exit;
405 end;
407 Color.R := R;
408 Color.B := B;
409 Color.G := G;
411 PID := g_Player_Create(Model, Color, T, False);
412 with g_Player_Get(PID) do
413 begin
414 Name := PName;
415 Reset(True);
416 end;
418 C^.Player := PID;
419 C^.WaitForFirstSpawn := false;
421 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
422 e_WriteLog('NET: Client ' + PName + ' [' + IntToStr(C^.ID) +
423 '] connected. Assigned player #' + IntToStr(PID) + '.', TMsgType.Notify);
425 MH_SEND_Info(C^.ID);
427 with g_Player_Get(PID) do
428 begin
429 Name := PName;
430 FClientID := C^.ID;
431 // round in progress, don't spawn
432 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
433 begin
434 Lives := 0;
435 FNoRespawn := True;
436 Spectate;
437 FWantsInGame := True; // TODO: look into this later
438 C^.WaitForFirstSpawn := true;
439 end
440 else
441 begin
442 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C.ID, C.Player]);
443 //e_LogWritefln('spawning player with pid #%u...', [PID]);
444 //Respawn(gGameSettings.GameType = GT_SINGLE);
445 //k8: no, do not spawn a player yet, wait for "request full state" packet
446 Lives := 0;
447 Spectate;
448 FNoRespawn := True;
449 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
450 // that is, if we'll set it to `true`, the player can be spawned after
451 // warmup time ran out, for example, regardless of the real player state.
452 // also, this seems to work only for the initial connection. further
453 // map changes could initiate resource downloading, but the player will
454 // be spawned immediately.
455 // the proper solution will require another player state, "ephemeral".
456 // the player should start any map in "ephemeral" state, and turned into
457 // real mobj only when they sent a special "i am ready" packet. this packet
458 // must be sent after receiving the full state, so the player will get a full
459 // map view before going into game.
460 FWantsInGame := false;
461 C^.WaitForFirstSpawn := true;
462 end;
463 end;
465 //if not C^.WaitForFirstSpawn then
466 begin
467 for I := Low(NetClients) to High(NetClients) do
468 begin
469 if NetClients[I].ID = C^.ID then Continue;
470 MH_SEND_PlayerCreate(PID, NetClients[I].ID);
471 MH_SEND_PlayerPos(True, PID, NetClients[I].ID);
472 MH_SEND_PlayerStats(PID, NetClients[I].ID);
473 end;
474 end;
476 if gState in [STATE_INTERCUSTOM, STATE_FOLD] then
477 MH_SEND_GameEvent(NET_EV_MAPEND, 0, 'N', C^.ID);
479 if NetUseMaster then g_Net_Slist_Update;
480 end;
483 procedure MH_ProcessFirstSpawn (C: pTNetClient);
484 var
485 plr: TPlayer;
486 begin
487 if not C.WaitForFirstSpawn then exit;
488 plr := g_Player_Get(C^.Player);
489 if not assigned(plr) then exit;
490 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C.ID, C.Player]);
491 C.WaitForFirstSpawn := false;
492 plr.FNoRespawn := false;
493 plr.FWantsInGame := true; // TODO: look into this later
494 plr.Respawn(False);
495 end;
498 procedure MH_RECV_FullStateRequest(C: pTNetClient; var M: TMsg);
499 begin
500 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
501 if gGameOn then
502 begin
503 MH_SEND_Everything((C^.State = NET_STATE_AUTH), C^.ID)
504 end
505 else
506 begin
507 C^.RequestedFullUpdate := True;
508 end;
509 end;
511 // PLAYER
513 function MH_RECV_PlayerPos(C: pTNetClient; var M: TMsg): Word;
514 var
515 Dir, i: Byte;
516 WeaponSelect: Word;
517 PID: Word;
518 kByte: Word;
519 Pl: TPlayer;
520 GT: LongWord;
521 begin
522 Result := 0;
523 if not gGameOn then Exit;
525 GT := M.ReadLongWord();
526 PID := C^.Player;
527 Pl := g_Player_Get(PID);
528 if Pl = nil then
529 Exit;
531 if (GT > gTime + NET_MAX_DIFFTIME) or (GT < Pl.NetTime) then Exit;
533 with Pl do
534 begin
535 NetTime := GT;
536 kByte := M.ReadWord();
537 Dir := M.ReadByte();
538 WeaponSelect := M.ReadWord();
539 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
540 if Direction <> TDirection(Dir) then
541 JustTeleported := False;
543 SetDirection(TDirection(Dir));
544 ReleaseKeys;
546 if kByte = NET_KEY_CHAT then
547 begin
548 PressKey(KEY_CHAT, 10000);
549 Exit;
550 end;
552 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
553 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
554 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
555 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
556 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
557 if LongBool(kByte and NET_KEY_FIRE) then PressKey(KEY_FIRE, 10000);
558 if LongBool(kByte and NET_KEY_OPEN) then PressKey(KEY_OPEN, 10000);
559 if LongBool(kByte and NET_KEY_NW) then PressKey(KEY_NEXTWEAPON, 10000);
560 if LongBool(kByte and NET_KEY_PW) then PressKey(KEY_PREVWEAPON, 10000);
562 for i := 0 to 15 do
563 begin
564 if (WeaponSelect and Word(1 shl i)) <> 0 then
565 begin
566 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
567 QueueWeaponSwitch(i);
568 end;
569 end;
570 end;
572 // MH_SEND_PlayerPos(False, PID, C^.ID);
573 end;
575 procedure MH_RECV_CheatRequest(C: pTNetClient; var M: TMsg);
576 var
577 CheatKind: Byte;
578 Pl: TPlayer;
579 begin
580 Pl := g_Player_Get(C^.Player);
581 if Pl = nil then Exit;
583 CheatKind := M.ReadByte();
585 case CheatKind of
586 NET_CHEAT_SUICIDE:
587 Pl.Damage(SUICIDE_DAMAGE, Pl.UID, 0, 0, HIT_SELF);
588 NET_CHEAT_SPECTATE:
589 begin
590 if Pl.FSpectator then
591 Pl.Respawn(False)
592 else
593 Pl.Spectate;
594 end;
595 NET_CHEAT_READY:
596 begin
597 if gState <> STATE_INTERCUSTOM then Exit;
598 Pl.FReady := not Pl.FReady;
599 if Pl.FReady then
600 begin
601 MH_SEND_GameEvent(NET_EV_INTER_READY, Pl.UID, 'Y');
602 Inc(gInterReadyCount);
603 end
604 else
605 begin
606 MH_SEND_GameEvent(NET_EV_INTER_READY, Pl.UID, 'N');
607 Dec(gInterReadyCount);
608 end;
609 end;
610 end;
611 end;
613 procedure MH_RECV_PlayerSettings(C: pTNetClient; var M: TMsg);
614 var
615 TmpName: string;
616 TmpModel: string;
617 TmpColor: TRGB;
618 TmpTeam: Byte;
619 Pl: TPlayer;
620 begin
621 TmpName := M.ReadString();
622 TmpModel := M.ReadString();
623 TmpColor.R := M.ReadByte();
624 TmpColor.G := M.ReadByte();
625 TmpColor.B := M.ReadByte();
626 TmpTeam := M.ReadByte();
628 Pl := g_Player_Get(C^.Player);
629 if Pl = nil then Exit;
631 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
632 Pl.SwitchTeam
633 else
634 Pl.SetColor(TmpColor);
636 if Pl.Name <> TmpName then
637 begin
638 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
639 Pl.Name := TmpName;
640 end;
642 if TmpModel <> Pl.Model.Name then
643 Pl.SetModel(TmpModel);
645 MH_SEND_PlayerSettings(Pl.UID, TmpModel);
646 end;
648 // RCON
650 procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
651 var
652 Pwd: string;
653 begin
654 Pwd := M.ReadString();
655 if not NetAllowRCON then Exit;
656 if Pwd = NetRCONPassword then
657 begin
658 C^.RCONAuth := True;
659 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWGOOD, 'N', C^.ID);
660 end
661 else
662 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWBAD, 'N', C^.ID);
663 end;
665 procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
666 var
667 Cmd: string;
668 begin
669 Cmd := M.ReadString();
670 if not NetAllowRCON then Exit;
671 if not C^.RCONAuth then
672 begin
673 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_NOAUTH, 'N', C^.ID);
674 Exit;
675 end;
676 g_Console_Process(Cmd);
677 end;
679 // MISC
681 procedure MH_RECV_Vote(C: pTNetClient; var M: TMsg);
682 var
683 Start: Boolean;
684 Name, Command: string;
685 Need: Integer;
686 Pl: TPlayer;
687 begin
688 Start := M.ReadByte() <> 0;
689 Command := M.ReadString();
691 Pl := g_Player_Get(C^.Player);
692 if Pl = nil then Exit;
693 Name := Pl.Name;
695 if Start then
696 begin
697 if not g_Console_CommandBlacklisted(Command) then
698 g_Game_StartVote(Command, Name);
699 end
700 else if gVoteInProgress then
701 begin
702 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
703 Need := Floor((NetClientCount+1)/2.0) + 1
704 else
705 Need := Floor(NetClientCount/2.0) + 1;
706 if C^.Voted then
707 begin
708 Dec(gVoteCount);
709 C^.Voted := False;
710 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [Name, gVoteCount, Need]), True);
711 MH_SEND_VoteEvent(NET_VE_REVOKE, Name, 'a', gVoteCount, Need);
712 end
713 else
714 begin
715 Inc(gVoteCount);
716 C^.Voted := True;
717 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Name, gVoteCount, Need]), True);
718 MH_SEND_VoteEvent(NET_VE_VOTE, Name, 'a', gVoteCount, Need);
719 g_Game_CheckVote;
720 end;
721 end;
722 end;
724 // GAME (SEND)
726 procedure MH_SEND_Everything(CreatePlayers: Boolean {= False}; ID: Integer {= NET_EVERYONE});
728 function sendItemRespawn (it: PItem): Boolean;
729 begin
730 result := false; // don't stop
731 MH_SEND_ItemSpawn(True, it.myid, ID);
732 end;
734 function sendMonSpawn (mon: TMonster): Boolean;
735 begin
736 result := false; // don't stop
737 MH_SEND_MonsterSpawn(mon.UID, ID);
738 end;
740 function sendPanelState (pan: TPanel): Boolean;
741 begin
742 result := false; // don't stop
743 MH_SEND_PanelState(pan.guid, ID); // anyway, to sync mplats
744 if (pan.CanChangeTexture) then MH_SEND_PanelTexture(pan.guid, pan.LastAnimLoop, ID);
745 end;
747 var
748 I: Integer;
749 begin
750 if (ID >= 0) and (ID < length(NetClients)) then
751 begin
752 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID, NetClients[ID].Player]);
753 MH_ProcessFirstSpawn(@NetClients[ID]);
754 end;
756 if gPlayers <> nil then
757 begin
758 for I := Low(gPlayers) to High(gPlayers) do
759 begin
760 if gPlayers[I] <> nil then
761 begin
762 if CreatePlayers then MH_SEND_PlayerCreate(gPlayers[I].UID, ID);
763 MH_SEND_PlayerPos(True, gPlayers[I].UID, ID);
764 MH_SEND_PlayerStats(gPlayers[I].UID, ID);
766 if (gPlayers[I].Flag <> FLAG_NONE) and (gGameSettings.GameMode = GM_CTF) then
767 begin
768 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED, gPlayers[I].Flag, gPlayers[I].UID, True, ID);
769 end;
770 end;
771 end;
772 end;
774 g_Items_ForEachAlive(sendItemRespawn, true); // backwards
775 g_Mons_ForEach(sendMonSpawn);
776 g_Map_ForEachPanel(sendPanelState);
778 if gTriggers <> nil then
779 begin
780 for I := Low(gTriggers) to High(gTriggers) do
781 begin
782 if gTriggers[I].TriggerType = TRIGGER_SOUND then
783 begin
784 MH_SEND_TriggerSound(gTriggers[I], ID);
785 end;
786 end;
787 end;
789 if Shots <> nil then
790 begin
791 for I := Low(Shots) to High(Shots) do
792 begin
793 if Shots[i].ShotType in [6, 7, 8] then
794 begin
795 MH_SEND_CreateShot(i, ID);
796 end;
797 end;
798 end;
800 MH_SEND_TriggerMusic(ID);
802 MH_SEND_GameStats(ID);
803 MH_SEND_CoopStats(ID);
805 if gGameSettings.GameMode = GM_CTF then
806 begin
807 if gFlags[FLAG_RED].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_RED].State, FLAG_RED, 0, True, ID);
808 if gFlags[FLAG_BLUE].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_BLUE].State, FLAG_BLUE, 0, True, ID);
809 end;
811 if CreatePlayers and (ID >= 0) then NetClients[ID].State := NET_STATE_GAME;
813 if gLMSRespawn > LMS_RESPAWN_NONE then
814 begin
815 e_LogWritefln('*** client #%u (cid #%u) WARMUP', [ID, NetClients[ID].Player]);
816 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000, 'N', ID);
817 end;
819 g_Net_Flush();
820 end;
822 procedure MH_SEND_Info(ID: Byte);
823 var
824 Map: string;
825 begin
826 Map := g_ExtractFileName(gMapInfo.Map);
828 NetOut.Clear();
830 NetOut.Write(Byte(NET_MSG_INFO));
831 NetOut.Write(ID);
832 NetOut.Write(NetClients[ID].Player);
833 NetOut.Write(gGameSettings.WAD);
834 NetOut.Write(Map);
835 NetOut.Write(gWADHash);
836 NetOut.Write(gGameSettings.GameMode);
837 NetOut.Write(gGameSettings.GoalLimit);
838 NetOut.Write(gGameSettings.TimeLimit);
839 NetOut.Write(gGameSettings.MaxLives);
840 NetOut.Write(gGameSettings.Options);
841 NetOut.Write(gTime);
843 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
844 end;
846 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
847 var
848 Name: string;
849 i: Integer;
850 Team: Byte;
851 begin
852 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
853 Mode := NET_CHAT_PLAYER;
855 Team := 0;
856 if (Mode = NET_CHAT_TEAM) then
857 begin
858 for i := Low(gPlayers) to High(gPlayers) do
859 if (gPlayers[i] <> nil) and (gPlayers[i].FClientID >= 0) and
860 (gPlayers[i].Team = ID) then
861 begin
862 NetOut.Write(Byte(NET_MSG_CHAT));
863 NetOut.Write(Txt);
864 NetOut.Write(Mode);
865 g_Net_Host_Send(gPlayers[i].FClientID, True, NET_CHAN_CHAT);
866 end;
867 Team := ID;
868 ID := NET_EVERYONE;
869 end
870 else
871 begin
872 NetOut.Write(Byte(NET_MSG_CHAT));
873 NetOut.Write(Txt);
874 NetOut.Write(Mode);
875 g_Net_Host_Send(ID, True, NET_CHAN_CHAT);
876 end;
878 if Mode = NET_CHAT_SYSTEM then
879 Exit;
881 if ID = NET_EVERYONE then
882 begin
883 if Mode = NET_CHAT_PLAYER then
884 begin
885 g_Console_Add(Txt, True);
886 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
887 g_Game_ChatSound(b_Text_Unformat(Txt));
888 end
889 else
890 if Mode = NET_CHAT_TEAM then
891 if gPlayer1 <> nil then
892 begin
893 if (gPlayer1.Team = TEAM_RED) and (Team = TEAM_RED) then
894 begin
895 g_Console_Add(#18'[Team] '#2 + Txt, True);
896 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
897 g_Game_ChatSound(b_Text_Unformat(Txt));
898 end
899 else if (gPlayer1.Team = TEAM_BLUE) and (Team = TEAM_BLUE) then
900 begin
901 g_Console_Add(#20'[Team] '#2 + Txt, True);
902 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
903 g_Game_ChatSound(b_Text_Unformat(Txt));
904 end;
905 end;
906 end
907 else
908 begin
909 Name := g_Net_ClientName_ByID(ID);
910 g_Console_Add('-> ' + Name + ': ' + Txt, True);
911 e_WriteLog('[Tell ' + Name + '] ' + b_Text_Unformat(Txt), TMsgType.Notify);
912 g_Game_ChatSound(b_Text_Unformat(Txt), False);
913 end;
914 end;
916 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
917 begin
918 NetOut.Write(Byte(NET_MSG_GFX));
919 NetOut.Write(Kind);
920 NetOut.Write(X);
921 NetOut.Write(Y);
922 NetOut.Write(Ang);
924 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
925 end;
927 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
928 begin
929 NetOut.Write(Byte(NET_MSG_SND));
930 NetOut.Write(Name);
931 if Pos then
932 begin
933 NetOut.Write(Byte(1));
934 NetOut.Write(X);
935 NetOut.Write(Y);
936 end
937 else
938 NetOut.Write(Byte(0));
940 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
941 end;
943 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
944 begin
945 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
947 NetOut.Write(Byte(NET_MSG_SHADD));
948 NetOut.Write(Proj);
949 NetOut.Write(Shots[Proj].ShotType);
950 NetOut.Write(Shots[Proj].Target);
951 NetOut.Write(Shots[Proj].SpawnerUID);
952 NetOut.Write(Shots[Proj].Timeout);
953 NetOut.Write(Shots[Proj].Obj.X);
954 NetOut.Write(Shots[Proj].Obj.Y);
955 NetOut.Write(Shots[Proj].Obj.Vel.X);
956 NetOut.Write(Shots[Proj].Obj.Vel.Y);
958 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
959 end;
961 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
962 begin
963 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
965 NetOut.Write(Byte(NET_MSG_SHPOS));
966 NetOut.Write(Proj);
967 NetOut.Write(Shots[Proj].Obj.X);
968 NetOut.Write(Shots[Proj].Obj.Y);
969 NetOut.Write(Shots[Proj].Obj.Vel.X);
970 NetOut.Write(Shots[Proj].Obj.Vel.Y);
972 g_Net_Host_Send(ID, False, NET_CHAN_SHOTS);
973 end;
975 procedure MH_Send_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
976 begin
977 NetOut.Write(Byte(NET_MSG_SHDEL));
978 NetOut.Write(Proj);
979 NetOut.Write(Byte(Loud));
980 NetOut.Write(X);
981 NetOut.Write(Y);
983 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
984 end;
986 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
987 begin
988 NetOut.Write(Byte(NET_MSG_SCORE));
989 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
990 begin
991 NetOut.Write(gTeamStat[TEAM_RED].Goals);
992 NetOut.Write(gTeamStat[TEAM_BLUE].Goals);
993 end
994 else
995 if gGameSettings.GameMode = GM_COOP then
996 begin
997 NetOut.Write(gCoopMonstersKilled);
998 NetOut.Write(gCoopSecretsFound);
999 end;
1001 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1002 end;
1004 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
1005 begin
1006 NetOut.Write(Byte(NET_MSG_COOP));
1007 NetOut.Write(gTotalMonsters);
1008 NetOut.Write(gSecretsCount);
1009 NetOut.Write(gCoopTotalMonstersKilled);
1010 NetOut.Write(gCoopTotalSecretsFound);
1011 NetOut.Write(gCoopTotalMonsters);
1012 NetOut.Write(gCoopTotalSecrets);
1013 end;
1015 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
1016 begin
1017 NetOut.Write(Byte(NET_MSG_GEVENT));
1018 NetOut.Write(EvType);
1019 NetOut.Write(EvNum);
1020 NetOut.Write(EvStr);
1021 NetOut.Write(Byte(gLastMap));
1022 NetOut.Write(gTime);
1023 if (EvType = NET_EV_MAPSTART) and isWadPath(EvStr) then
1024 begin
1025 NetOut.Write(Byte(1));
1026 NetOut.Write(gWADHash);
1027 end else
1028 NetOut.Write(Byte(0));
1030 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
1031 end;
1033 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
1034 begin
1035 NetOut.Write(Byte(NET_MSG_FLAG));
1036 NetOut.Write(EvType);
1037 NetOut.Write(Flag);
1038 NetOut.Write(Byte(Quiet));
1039 NetOut.Write(PID);
1040 NetOut.Write(gFlags[Flag].State);
1041 NetOut.Write(gFlags[Flag].CaptureTime);
1042 NetOut.Write(gFlags[Flag].Obj.X);
1043 NetOut.Write(gFlags[Flag].Obj.Y);
1044 NetOut.Write(gFlags[Flag].Obj.Vel.X);
1045 NetOut.Write(gFlags[Flag].Obj.Vel.Y);
1047 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1048 end;
1050 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
1051 begin
1052 NetOut.Write(Byte(NET_MSG_GSET));
1053 NetOut.Write(gGameSettings.GameMode);
1054 NetOut.Write(gGameSettings.GoalLimit);
1055 NetOut.Write(gGameSettings.TimeLimit);
1056 NetOut.Write(gGameSettings.MaxLives);
1057 NetOut.Write(gGameSettings.Options);
1059 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1060 end;
1062 // PLAYER (SEND)
1064 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
1065 var
1066 P: TPlayer;
1067 begin
1068 P := g_Player_Get(PID);
1069 if P = nil then Exit;
1071 NetOut.Write(Byte(NET_MSG_PLR));
1072 NetOut.Write(PID);
1073 NetOut.Write(P.Name);
1075 NetOut.Write(P.FActualModelName);
1076 NetOut.Write(P.FColor.R);
1077 NetOut.Write(P.FColor.G);
1078 NetOut.Write(P.FColor.B);
1079 NetOut.Write(P.Team);
1081 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT)
1082 end;
1084 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
1085 var
1086 kByte: Word;
1087 Pl: TPlayer;
1088 begin
1089 Pl := g_Player_Get(PID);
1090 if Pl = nil then Exit;
1091 if Pl.FDummy then Exit;
1093 NetOut.Write(Byte(NET_MSG_PLRPOS));
1094 NetOut.Write(gTime);
1095 NetOut.Write(PID);
1097 kByte := 0;
1099 with Pl do
1100 begin
1101 NetOut.Write(FPing);
1102 NetOut.Write(FLoss);
1103 if IsKeyPressed(KEY_CHAT) then
1104 kByte := NET_KEY_CHAT
1105 else
1106 begin
1107 if IsKeyPressed(KEY_LEFT) then kByte := kByte or NET_KEY_LEFT;
1108 if IsKeyPressed(KEY_RIGHT) then kByte := kByte or NET_KEY_RIGHT;
1109 if IsKeyPressed(KEY_UP) then kByte := kByte or NET_KEY_UP;
1110 if IsKeyPressed(KEY_DOWN) then kByte := kByte or NET_KEY_DOWN;
1111 if IsKeyPressed(KEY_JUMP) then kByte := kByte or NET_KEY_JUMP;
1112 if JustTeleported then kByte := kByte or NET_KEY_FORCEDIR;
1113 end;
1115 NetOut.Write(kByte);
1116 if Direction = TDirection.D_LEFT then NetOut.Write(Byte(0)) else NetOut.Write(Byte(1));
1117 NetOut.Write(GameX);
1118 NetOut.Write(GameY);
1119 NetOut.Write(GameVelX);
1120 NetOut.Write(GameVelY);
1121 NetOut.Write(GameAccelX);
1122 NetOut.Write(GameAccelY);
1123 end;
1125 g_Net_Host_Send(ID, Reliable, NET_CHAN_PLAYERPOS);
1126 end;
1128 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
1129 var
1130 P: TPlayer;
1131 I: Integer;
1132 begin
1133 P := g_Player_Get(PID);
1134 if P = nil then Exit;
1136 NetOut.Write(Byte(NET_MSG_PLRSTA));
1137 NetOut.Write(PID);
1139 with P do
1140 begin
1141 NetOut.Write(Byte(alive));
1142 NetOut.Write(Byte(GodMode));
1143 NetOut.Write(Health);
1144 NetOut.Write(Armor);
1145 NetOut.Write(Air);
1146 NetOut.Write(JetFuel);
1147 NetOut.Write(Lives);
1148 NetOut.Write(Team);
1150 for I := WP_FIRST to WP_LAST do
1151 NetOut.Write(Byte(FWeapon[I]));
1153 for I := A_BULLETS to A_HIGH do
1154 NetOut.Write(FAmmo[I]);
1156 for I := A_BULLETS to A_HIGH do
1157 NetOut.Write(FMaxAmmo[I]);
1159 for I := MR_SUIT to MR_MAX do
1160 NetOut.Write(LongWord(FMegaRulez[I]));
1162 NetOut.Write(Byte(R_ITEM_BACKPACK in FRulez));
1163 NetOut.Write(Byte(R_KEY_RED in FRulez));
1164 NetOut.Write(Byte(R_KEY_GREEN in FRulez));
1165 NetOut.Write(Byte(R_KEY_BLUE in FRulez));
1166 NetOut.Write(Byte(R_BERSERK in FRulez));
1168 NetOut.Write(Frags);
1169 NetOut.Write(Death);
1171 NetOut.Write(CurrWeap);
1173 NetOut.Write(Byte(FSpectator));
1174 NetOut.Write(Byte(FGhost));
1175 NetOut.Write(Byte(FPhysics));
1176 NetOut.Write(Byte(FNoRespawn));
1177 NetOut.Write(Byte(FJetpack));
1178 NetOut.Write(FFireTime);
1179 NetOut.Write(Byte(FFlaming));
1180 end;
1182 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1183 end;
1185 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
1186 begin
1187 NetOut.Write(Byte(NET_MSG_PLRDMG));
1188 NetOut.Write(PID);
1189 NetOut.Write(Kind);
1190 NetOut.Write(Attacker);
1191 NetOut.Write(Value);
1192 NetOut.Write(VX);
1193 NetOut.Write(VY);
1195 g_Net_Host_Send(ID, False, NET_CHAN_PLAYER);
1196 end;
1198 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
1199 begin
1200 NetOut.Write(Byte(NET_MSG_PLRDIE));
1201 NetOut.Write(PID);
1202 NetOut.Write(KillType);
1203 NetOut.Write(DeathType);
1204 NetOut.Write(Attacker);
1206 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1207 end;
1209 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
1210 begin
1211 NetOut.Write(Byte(NET_MSG_PLRFIRE));
1212 NetOut.Write(PID);
1213 NetOut.Write(Weapon);
1214 NetOut.Write(X);
1215 NetOut.Write(Y);
1216 NetOut.Write(AX);
1217 NetOut.Write(AY);
1218 NetOut.Write(ShotID);
1220 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1221 end;
1223 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
1224 begin
1225 NetOut.Write(Byte(NET_MSG_PLRDEL));
1226 NetOut.Write(PID);
1228 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1229 end;
1231 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
1232 var
1233 Pl: TPlayer;
1234 begin
1235 Pl := g_Player_Get(PID);
1236 if Pl = nil then Exit;
1238 NetOut.Write(Byte(NET_MSG_PLRSET));
1239 NetOut.Write(PID);
1240 NetOut.Write(Pl.Name);
1241 if Mdl = '' then
1242 NetOut.Write(Pl.Model.Name)
1243 else
1244 NetOut.Write(Mdl);
1245 NetOut.Write(Pl.FColor.R);
1246 NetOut.Write(Pl.FColor.G);
1247 NetOut.Write(Pl.FColor.B);
1248 NetOut.Write(Pl.Team);
1250 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1251 end;
1253 // ITEM (SEND)
1255 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1256 var
1257 it: PItem;
1258 tt: Byte;
1259 begin
1260 it := g_Items_ByIdx(IID);
1262 NetOut.Write(Byte(NET_MSG_ISPAWN));
1263 NetOut.Write(IID);
1264 NetOut.Write(Byte(Quiet));
1265 tt := it.ItemType;
1266 if it.dropped then tt := tt or $80;
1267 NetOut.Write(tt);
1268 NetOut.Write(Byte(it.Fall));
1269 NetOut.Write(Byte(it.Respawnable));
1270 NetOut.Write(it.Obj.X);
1271 NetOut.Write(it.Obj.Y);
1272 NetOut.Write(it.Obj.Vel.X);
1273 NetOut.Write(it.Obj.Vel.Y);
1275 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1276 end;
1278 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1279 begin
1280 NetOut.Write(Byte(NET_MSG_IDEL));
1281 NetOut.Write(IID);
1282 NetOut.Write(Byte(Quiet));
1284 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1285 end;
1287 // PANEL
1289 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
1290 var
1291 TP: TPanel;
1292 begin
1293 TP := g_Map_PanelByGUID(PGUID);
1294 if (TP = nil) then exit;
1296 with TP do
1297 begin
1298 NetOut.Write(Byte(NET_MSG_PTEX));
1299 NetOut.Write(LongWord(PGUID));
1300 NetOut.Write(FCurTexture);
1301 NetOut.Write(FCurFrame);
1302 NetOut.Write(FCurFrameCount);
1303 NetOut.Write(AnimLoop);
1304 end;
1306 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1307 end;
1309 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
1310 var
1311 TP: TPanel;
1312 mpflags: Byte = 0;
1313 begin
1314 TP := g_Map_PanelByGUID(PGUID);
1315 if (TP = nil) then exit;
1317 NetOut.Write(Byte(NET_MSG_PSTATE));
1318 NetOut.Write(LongWord(PGUID));
1319 NetOut.Write(Byte(TP.Enabled));
1320 NetOut.Write(TP.LiftType);
1321 NetOut.Write(TP.X);
1322 NetOut.Write(TP.Y);
1323 NetOut.Write(Word(TP.Width));
1324 NetOut.Write(Word(TP.Height));
1325 // mplats
1326 NetOut.Write(LongInt(TP.movingSpeedX));
1327 NetOut.Write(LongInt(TP.movingSpeedY));
1328 NetOut.Write(LongInt(TP.movingStartX));
1329 NetOut.Write(LongInt(TP.movingStartY));
1330 NetOut.Write(LongInt(TP.movingEndX));
1331 NetOut.Write(LongInt(TP.movingEndY));
1332 NetOut.Write(LongInt(TP.sizeSpeedX));
1333 NetOut.Write(LongInt(TP.sizeSpeedY));
1334 NetOut.Write(LongInt(TP.sizeEndX));
1335 NetOut.Write(LongInt(TP.sizeEndY));
1336 if TP.movingActive then mpflags := mpflags or 1;
1337 if TP.moveOnce then mpflags := mpflags or 2;
1338 NetOut.Write(Byte(mpflags));
1340 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1341 end;
1343 // TRIGGER
1345 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
1346 begin
1347 if gTriggers = nil then Exit;
1348 if T.Sound = nil then Exit;
1350 NetOut.Write(Byte(NET_MSG_TSOUND));
1351 NetOut.Write(T.ClientID);
1352 NetOut.Write(Byte(T.Sound.IsPlaying));
1353 NetOut.Write(LongWord(T.Sound.GetPosition));
1354 NetOut.Write(T.SoundPlayCount);
1356 g_Net_Host_Send(ID, True);
1357 end;
1359 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
1360 begin
1361 NetOut.Write(Byte(NET_MSG_TMUSIC));
1362 NetOut.Write(gMusic.Name);
1363 NetOut.Write(Byte(gMusic.IsPlaying));
1364 NetOut.Write(LongWord(gMusic.GetPosition));
1365 NetOut.Write(Byte(gMusic.SpecPause or gMusic.IsPaused));
1367 g_Net_Host_Send(ID, True);
1368 end;
1370 // MONSTER
1372 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
1373 var
1374 M: TMonster;
1375 begin
1376 M := g_Monsters_ByUID(UID);
1377 if M = nil then
1378 Exit;
1380 with M do
1381 begin
1382 NetOut.Write(Byte(NET_MSG_MSPAWN));
1383 NetOut.Write(UID);
1384 NetOut.Write(MonsterType);
1385 NetOut.Write(MonsterState);
1386 NetOut.Write(MonsterAnim);
1387 NetOut.Write(MonsterTargetUID);
1388 NetOut.Write(MonsterTargetTime);
1389 NetOut.Write(MonsterBehaviour);
1390 NetOut.Write(MonsterSleep);
1391 NetOut.Write(MonsterHealth);
1392 NetOut.Write(MonsterAmmo);
1393 NetOut.Write(GameX);
1394 NetOut.Write(GameY);
1395 NetOut.Write(GameVelX);
1396 NetOut.Write(GameVelY);
1397 NetOut.Write(Byte(GameDirection));
1398 end;
1400 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1401 end;
1403 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
1404 var
1405 M: TMonster;
1406 begin
1407 M := g_Monsters_ByUID(UID);
1408 if M = nil then Exit;
1410 NetOut.Write(Byte(NET_MSG_MPOS));
1411 NetOut.Write(UID);
1413 with M do
1414 begin
1415 NetOut.Write(GameX);
1416 NetOut.Write(GameY);
1417 NetOut.Write(GameVelX);
1418 NetOut.Write(GameVelY);
1419 NetOut.Write(Byte(GameDirection));
1420 end;
1422 g_Net_Host_Send(ID, False, NET_CHAN_MONSTERPOS);
1423 end;
1425 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
1426 var
1427 M: TMonster;
1428 begin
1429 M := g_Monsters_ByUID(UID);
1430 if M = nil then Exit;
1432 NetOut.Write(Byte(NET_MSG_MSTATE));
1433 NetOut.Write(UID);
1435 with M do
1436 begin
1437 NetOut.Write(MonsterState);
1438 NetOut.Write(ForcedAnim);
1439 NetOut.Write(MonsterTargetUID);
1440 NetOut.Write(MonsterTargetTime);
1441 NetOut.Write(MonsterSleep);
1442 NetOut.Write(MonsterHealth);
1443 NetOut.Write(MonsterAmmo);
1444 NetOut.Write(MonsterPain);
1445 NetOut.Write(Byte(AnimIsReverse));
1446 NetOut.Write(FFireTime);
1447 end;
1449 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1450 end;
1452 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
1453 begin
1454 NetOut.Write(Byte(NET_MSG_MSHOT));
1455 NetOut.Write(UID);
1456 NetOut.Write(X);
1457 NetOut.Write(Y);
1458 NetOut.Write(VX);
1459 NetOut.Write(VY);
1461 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1462 end;
1464 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
1465 var
1466 M: TMonster;
1467 begin
1468 M := g_Monsters_ByUID(UID);
1469 if M = nil then Exit;
1471 NetOut.Write(Byte(NET_MSG_MDEL));
1472 NetOut.Write(UID);
1474 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1475 end;
1477 // MISC
1479 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
1480 begin
1481 NetOut.Write(Byte(NET_MSG_TIME_SYNC));
1482 NetOut.Write(Time);
1484 g_Net_Host_Send(ID, False, NET_CHAN_SERVICE);
1485 end;
1487 procedure MH_SEND_VoteEvent(EvType: Byte;
1488 StrArg1: string = 'a'; StrArg2: string = 'b';
1489 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
1490 ID: Integer = NET_EVERYONE);
1491 begin
1492 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
1493 NetOut.Write(EvType);
1494 NetOut.Write(IntArg1);
1495 NetOut.Write(IntArg2);
1496 NetOut.Write(StrArg1);
1497 NetOut.Write(StrArg2);
1499 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1500 end;
1502 // CLIENT MESSAGES //
1504 // GAME
1506 procedure MC_RECV_Chat(var M: TMsg);
1507 var
1508 Txt: string;
1509 Mode: Byte;
1510 begin
1511 Txt := M.ReadString();
1512 Mode := M.ReadByte();
1514 if Mode <> NET_CHAT_SYSTEM then
1515 begin
1516 if Mode = NET_CHAT_PLAYER then
1517 begin
1518 g_Console_Add(Txt, True);
1519 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1520 g_Game_ChatSound(b_Text_Unformat(Txt));
1521 end else
1522 if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then
1523 begin
1524 if gPlayer1.Team = TEAM_RED then
1525 g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True);
1526 if gPlayer1.Team = TEAM_BLUE then
1527 g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True);
1528 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1529 g_Game_ChatSound(b_Text_Unformat(Txt));
1530 end;
1531 end else
1532 g_Console_Add(Txt, True);
1533 end;
1535 procedure MC_RECV_Effect(var M: TMsg);
1536 var
1537 Kind: Byte;
1538 X, Y: Integer;
1539 Ang: SmallInt;
1540 Anim: TAnimation;
1541 ID: LongWord;
1542 begin
1543 if not gGameOn then Exit;
1544 Kind := M.ReadByte();
1545 X := M.ReadLongInt();
1546 Y := M.ReadLongInt();
1547 Ang := M.ReadSmallInt();
1549 case Kind of
1550 NET_GFX_SPARK:
1551 g_GFX_Spark(X, Y, 2 + Random(2), Ang, 0, 0);
1553 NET_GFX_TELE:
1554 begin
1555 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
1556 begin
1557 Anim := TAnimation.Create(ID, False, 3);
1558 g_GFX_OnceAnim(X, Y, Anim);
1559 Anim.Free();
1560 end;
1561 if Ang = 1 then
1562 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
1563 end;
1565 NET_GFX_EXPLODE:
1566 begin
1567 if g_Frames_Get(ID, 'FRAMES_EXPLODE_ROCKET') then
1568 begin
1569 Anim := TAnimation.Create(ID, False, 6);
1570 Anim.Blending := False;
1571 g_GFX_OnceAnim(X-64, Y-64, Anim);
1572 Anim.Free();
1573 end;
1574 if Ang = 1 then
1575 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X, Y);
1576 end;
1578 NET_GFX_BFGEXPL:
1579 begin
1580 if g_Frames_Get(ID, 'FRAMES_EXPLODE_BFG') then
1581 begin
1582 Anim := TAnimation.Create(ID, False, 6);
1583 Anim.Blending := False;
1584 g_GFX_OnceAnim(X-64, Y-64, Anim);
1585 Anim.Free();
1586 end;
1587 if Ang = 1 then
1588 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X, Y);
1589 end;
1591 NET_GFX_BFGHIT:
1592 begin
1593 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1594 begin
1595 Anim := TAnimation.Create(ID, False, 4);
1596 g_GFX_OnceAnim(X-32, Y-32, Anim);
1597 Anim.Free();
1598 end;
1599 end;
1601 NET_GFX_FIRE:
1602 begin
1603 if g_Frames_Get(ID, 'FRAMES_FIRE') then
1604 begin
1605 Anim := TAnimation.Create(ID, False, 4);
1606 g_GFX_OnceAnim(X, Y, Anim);
1607 Anim.Free();
1608 end;
1609 if Ang = 1 then
1610 g_Sound_PlayExAt('SOUND_FIRE', X, Y);
1611 end;
1613 NET_GFX_RESPAWN:
1614 begin
1615 if g_Frames_Get(ID, 'FRAMES_ITEM_RESPAWN') then
1616 begin
1617 Anim := TAnimation.Create(ID, False, 4);
1618 g_GFX_OnceAnim(X, Y, Anim);
1619 Anim.Free();
1620 end;
1621 if Ang = 1 then
1622 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
1623 end;
1625 NET_GFX_SHELL1:
1626 g_Player_CreateShell(X, Y, 0, -2, SHELL_BULLET);
1628 NET_GFX_SHELL2:
1629 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1631 NET_GFX_SHELL3:
1632 begin
1633 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1634 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1635 end;
1636 end;
1637 end;
1639 procedure MC_RECV_Sound(var M: TMsg);
1640 var
1641 Name: string;
1642 X, Y: Integer;
1643 Pos: Boolean;
1644 begin
1645 Name := M.ReadString();
1646 Pos := M.ReadByte() <> 0;
1647 if Pos then
1648 begin
1649 X := M.ReadLongInt();
1650 Y := M.ReadLongInt();
1651 g_Sound_PlayExAt(Name, X, Y);
1652 end
1653 else
1654 g_Sound_PlayEx(Name);
1655 end;
1657 procedure MC_RECV_CreateShot(var M: TMsg);
1658 var
1659 I, X, Y, XV, YV: Integer;
1660 Timeout: LongWord;
1661 Target, Spawner: Word;
1662 ShType: Byte;
1663 begin
1664 I := M.ReadLongInt();
1665 ShType := M.ReadByte();
1666 Target := M.ReadWord();
1667 Spawner := M.ReadWord();
1668 Timeout := M.ReadLongWord();
1669 X := M.ReadLongInt();
1670 Y := M.ReadLongInt();
1671 XV := M.ReadLongInt();
1672 YV := M.ReadLongInt();
1674 I := g_Weapon_CreateShot(I, ShType, Spawner, Target, X, Y, XV, YV);
1675 if (Shots <> nil) and (I <= High(Shots)) then
1676 begin
1677 Shots[I].Timeout := Timeout;
1678 //Shots[I].Target := Target; // TODO: find a use for Target later
1679 end;
1680 end;
1682 procedure MC_RECV_UpdateShot(var M: TMsg);
1683 var
1684 I, TX, TY, TXV, TYV: Integer;
1685 begin
1686 I := M.ReadLongInt();
1687 TX := M.ReadLongInt();
1688 TY := M.ReadLongInt();
1689 TXV := M.ReadLongInt();
1690 TYV := M.ReadLongInt();
1692 if (Shots <> nil) and (I <= High(Shots)) then
1693 with (Shots[i]) do
1694 begin
1695 Obj.X := TX;
1696 Obj.Y := TY;
1697 Obj.Vel.X := TXV;
1698 Obj.Vel.Y := TYV;
1699 end;
1700 end;
1702 procedure MC_RECV_DeleteShot(var M: TMsg);
1703 var
1704 I, X, Y: Integer;
1705 L: Boolean;
1706 begin
1707 if not gGameOn then Exit;
1708 I := M.ReadLongInt();
1709 L := (M.ReadByte() <> 0);
1710 X := M.ReadLongInt();
1711 Y := M.ReadLongInt();
1713 g_Weapon_DestroyShot(I, X, Y, L);
1714 end;
1716 procedure MC_RECV_GameStats(var M: TMsg);
1717 begin
1718 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1719 begin
1720 gTeamStat[TEAM_RED].Goals := M.ReadSmallInt();
1721 gTeamStat[TEAM_BLUE].Goals := M.ReadSmallInt();
1722 end
1723 else
1724 if gGameSettings.GameMode = GM_COOP then
1725 begin
1726 gCoopMonstersKilled := M.ReadWord();
1727 gCoopSecretsFound := M.ReadWord();
1728 end;
1729 end;
1731 procedure MC_RECV_CoopStats(var M: TMsg);
1732 begin
1733 gTotalMonsters := M.ReadLongInt();
1734 gSecretsCount := M.ReadLongInt();
1735 gCoopTotalMonstersKilled := M.ReadWord();
1736 gCoopTotalSecretsFound := M.ReadWord();
1737 gCoopTotalMonsters := M.ReadWord();
1738 gCoopTotalSecrets := M.ReadWord();
1739 end;
1741 procedure MC_RECV_GameEvent(var M: TMsg);
1742 var
1743 EvType: Byte;
1744 EvNum: Integer;
1745 EvStr: string;
1746 EvTime: LongWord;
1747 BHash: Boolean;
1748 EvHash: TMD5Digest;
1749 pl: TPlayer;
1750 i1, i2: TStrings_Locale;
1751 pln: String;
1752 cnt: Byte;
1753 goodCmd: Boolean = true;
1754 begin
1755 FillChar(EvHash, Sizeof(EvHash), 0);
1756 EvType := M.ReadByte();
1757 EvNum := M.ReadLongInt();
1758 EvStr := M.ReadString();
1759 gLastMap := M.ReadByte() <> 0;
1760 if gLastMap and (gGameSettings.GameMode = GM_COOP) then gStatsOff := True;
1761 gStatsPressed := True;
1762 EvTime := M.ReadLongWord();
1763 BHash := M.ReadByte() <> 0;
1764 if BHash then
1765 EvHash := M.ReadMD5();
1767 gTime := EvTime;
1769 if (g_Res_received_map_start <> 0) then
1770 begin
1771 if (g_Res_received_map_start < 0) then exit;
1772 goodCmd := false;
1773 case EvType of
1774 NET_EV_MAPSTART: goodCmd := true;
1775 NET_EV_MAPEND: goodCmd := true;
1776 NET_EV_PLAYER_KICK: goodCmd := true;
1777 NET_EV_PLAYER_BAN: goodCmd := true;
1778 end;
1779 if not goodCmd then exit;
1780 end;
1782 case EvType of
1783 NET_EV_MAPSTART:
1784 begin
1785 if (g_Res_received_map_start <> 0) then
1786 begin
1787 g_Res_received_map_start := -1;
1788 end
1789 else
1790 begin
1791 gGameOn := False;
1792 g_Game_ClearLoading();
1793 g_Game_StopAllSounds(True);
1795 gSwitchGameMode := Byte(EvNum);
1796 gGameSettings.GameMode := gSwitchGameMode;
1798 gWADHash := EvHash;
1799 if not g_Game_StartMap(EvStr, True) then
1800 begin
1801 if not isWadPath(EvStr) then
1802 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + EvStr]))
1803 else
1804 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [EvStr]));
1805 Exit;
1806 end;
1808 MC_SEND_FullStateRequest;
1809 end;
1810 end;
1812 NET_EV_MAPEND:
1813 begin
1814 if (g_Res_received_map_start <> 0) then
1815 begin
1816 g_Res_received_map_start := -1;
1817 end
1818 else
1819 begin
1820 gMissionFailed := EvNum <> 0;
1821 gExit := EXIT_ENDLEVELCUSTOM;
1822 end;
1823 end;
1825 NET_EV_RCON:
1826 begin
1827 case EvNum of
1828 NET_RCON_NOAUTH:
1829 g_Console_Add(_lc[I_NET_RCON_NOAUTH], True);
1830 NET_RCON_PWGOOD:
1831 g_Console_Add(_lc[I_NET_RCON_PWD_VALID], True);
1832 NET_RCON_PWBAD:
1833 g_Console_Add(_lc[I_NET_RCON_PWD_INVALID], True);
1834 end;
1835 end;
1837 NET_EV_CHANGE_TEAM:
1838 begin
1839 if EvNum = TEAM_RED then
1840 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True);
1841 if EvNum = TEAM_BLUE then
1842 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True);
1843 end;
1845 NET_EV_PLAYER_KICK:
1846 begin
1847 g_Console_Add(Format(_lc[I_PLAYER_KICK], [EvStr]), True);
1848 if (g_Res_received_map_start <> 0) then g_Res_received_map_start := -1;
1849 end;
1851 NET_EV_PLAYER_BAN:
1852 begin
1853 g_Console_Add(Format(_lc[I_PLAYER_BAN], [EvStr]), True);
1854 if (g_Res_received_map_start <> 0) then g_Res_received_map_start := -1;
1855 end;
1857 NET_EV_LMS_WARMUP:
1858 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [EvNum]), True);
1860 NET_EV_LMS_SURVIVOR:
1861 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True);
1863 NET_EV_BIGTEXT:
1864 g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum));
1866 NET_EV_SCORE:
1867 begin
1868 pl := g_Player_Get(EvNum and $FFFF);
1869 if pl = nil then
1870 pln := '?'
1871 else
1872 pln := pl.Name;
1873 cnt := (EvNum shr 16) and $FF;
1874 if Pos('w', EvStr) = 0 then
1875 begin
1876 // Default score
1877 if Pos('t', EvStr) = 0 then
1878 begin
1879 // Player +/- score
1880 if Pos('-', EvStr) = 0 then
1881 begin
1882 if Pos('e', EvStr) = 0 then
1883 i1 := I_PLAYER_SCORE_ADD_OWN
1884 else
1885 i1 := I_PLAYER_SCORE_ADD_ENEMY;
1886 end else
1887 begin
1888 if Pos('e', EvStr) = 0 then
1889 i1 := I_PLAYER_SCORE_SUB_OWN
1890 else
1891 i1 := I_PLAYER_SCORE_SUB_ENEMY;
1892 end;
1893 // Which team
1894 if Pos('r', EvStr) > 0 then
1895 i2 := I_PLAYER_SCORE_TO_RED
1896 else
1897 i2 := I_PLAYER_SCORE_TO_BLUE;
1898 g_Console_Add(Format(_lc[i1], [pln, cnt, _lc[i2]]), True);
1899 end else
1900 begin
1901 // Team +/- score
1902 if Pos('-', EvStr) = 0 then
1903 i1 := I_PLAYER_SCORE_ADD_TEAM
1904 else
1905 i1 := I_PLAYER_SCORE_SUB_TEAM;
1906 // Which team
1907 if Pos('r', EvStr) > 0 then
1908 i2 := I_PLAYER_SCORE_RED
1909 else
1910 i2 := I_PLAYER_SCORE_BLUE;
1911 g_Console_Add(Format(_lc[i1], [_lc[i2], cnt]), True);
1912 end;
1913 end else
1914 begin
1915 // Game Win
1916 if Pos('e', EvStr) = 0 then
1917 i1 := I_PLAYER_SCORE_WIN_OWN
1918 else
1919 i1 := I_PLAYER_SCORE_WIN_ENEMY;
1920 // Which team
1921 if Pos('r', EvStr) > 0 then
1922 i2 := I_PLAYER_SCORE_TO_RED
1923 else
1924 i2 := I_PLAYER_SCORE_TO_BLUE;
1925 g_Console_Add(Format(_lc[i1], [pln, _lc[i2]]), True);
1926 end;
1927 end;
1929 NET_EV_SCORE_MSG:
1930 begin
1931 if EvNum = TEAM_RED then
1932 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1933 if EvNum = TEAM_BLUE then
1934 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1935 if EvNum = -TEAM_RED then
1936 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
1937 if EvNum = -TEAM_BLUE then
1938 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
1939 end;
1941 NET_EV_LMS_START:
1942 begin
1943 g_Player_RemoveAllCorpses;
1944 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
1945 end;
1947 NET_EV_LMS_WIN:
1948 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(EvStr)]), 144);
1950 NET_EV_TLMS_WIN:
1951 begin
1952 if EvNum = TEAM_RED then
1953 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
1954 if EvNum = TEAM_BLUE then
1955 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
1956 end;
1958 NET_EV_LMS_LOSE:
1959 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
1961 NET_EV_LMS_DRAW:
1962 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
1964 NET_EV_KILLCOMBO:
1965 g_Game_Announce_KillCombo(EvNum);
1967 NET_EV_PLAYER_TOUCH:
1968 begin
1969 pl := g_Player_Get(EvNum);
1970 if pl <> nil then
1971 pl.Touch();
1972 end;
1974 NET_EV_SECRET:
1975 begin
1976 pl := g_Player_Get(EvNum);
1977 if pl <> nil then
1978 begin
1979 g_Console_Add(Format(_lc[I_PLAYER_SECRET], [pl.Name]), True);
1980 g_Sound_PlayEx('SOUND_GAME_SECRET');
1981 end;
1982 end;
1984 NET_EV_INTER_READY:
1985 begin
1986 pl := g_Player_Get(EvNum);
1987 if pl <> nil then pl.FReady := (EvStr = 'Y');
1988 end;
1989 end;
1990 end;
1992 procedure MC_RECV_FlagEvent(var M: TMsg);
1993 var
1994 PID: Word;
1995 Pl: TPlayer;
1996 EvType: Byte;
1997 Fl, a: Byte;
1998 Quiet: Boolean;
1999 s, ts: string;
2000 begin
2001 EvType := M.ReadByte();
2002 Fl := M.ReadByte();
2004 if Fl = FLAG_NONE then Exit;
2006 Quiet := (M.ReadByte() <> 0);
2007 PID := M.ReadWord();
2009 gFlags[Fl].State := M.ReadByte();
2010 gFlags[Fl].CaptureTime := M.ReadLongWord();
2011 gFlags[Fl].Obj.X := M.ReadLongInt();
2012 gFlags[Fl].Obj.Y := M.ReadLongInt();
2013 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
2014 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
2016 Pl := g_Player_Get(PID);
2017 if (Pl = nil) and
2018 (EvType <> FLAG_STATE_NORMAL) and
2019 (EvType <> FLAG_STATE_DROPPED) and
2020 (EvType <> FLAG_STATE_RETURNED) then
2021 Exit;
2023 case EvType of
2024 FLAG_STATE_NORMAL:
2025 begin
2026 if Quiet or (Pl = nil) then Exit;
2028 if Fl = FLAG_RED then
2029 s := _lc[I_PLAYER_FLAG_RED]
2030 else
2031 s := _lc[I_PLAYER_FLAG_BLUE];
2033 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2035 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2036 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2037 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2038 a := 0
2039 else
2040 a := 1;
2042 if not sound_ret_flag[a].IsPlaying() then
2043 sound_ret_flag[a].Play();
2044 end;
2046 FLAG_STATE_CAPTURED:
2047 begin
2048 if (Pl <> nil) then Pl.SetFlag(Fl);
2050 if Quiet then Exit;
2052 if Fl = FLAG_RED then
2053 s := _lc[I_PLAYER_FLAG_RED]
2054 else
2055 s := _lc[I_PLAYER_FLAG_BLUE];
2057 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [Pl.Name, s]), True);
2058 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
2060 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2061 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2062 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2063 a := 0
2064 else
2065 a := 1;
2067 if not sound_get_flag[a].IsPlaying() then
2068 sound_get_flag[a].Play();
2069 end;
2071 FLAG_STATE_DROPPED:
2072 begin
2073 if (Pl <> nil) then Pl.SetFlag(FLAG_NONE);
2075 if Quiet or (Pl = nil) then Exit;
2077 if Fl = FLAG_RED then
2078 s := _lc[I_PLAYER_FLAG_RED]
2079 else
2080 s := _lc[I_PLAYER_FLAG_BLUE];
2082 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [Pl.Name, s]), True);
2083 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
2085 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2086 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2087 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2088 a := 0
2089 else
2090 a := 1;
2092 if not sound_lost_flag[a].IsPlaying() then
2093 sound_lost_flag[a].Play();
2094 end;
2096 FLAG_STATE_SCORED:
2097 begin
2098 g_Map_ResetFlag(FLAG_RED);
2099 g_Map_ResetFlag(FLAG_BLUE);
2100 if Quiet or (Pl = nil) then Exit;
2101 Pl.SetFlag(FLAG_NONE);
2103 if Fl = FLAG_RED then
2104 s := _lc[I_PLAYER_FLAG_RED]
2105 else
2106 s := _lc[I_PLAYER_FLAG_BLUE];
2108 ts := Format('%.4d', [gFlags[Fl].CaptureTime]);
2109 Insert('.', ts, Length(ts) + 1 - 3);
2110 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [Pl.Name, s, ts]), True);
2111 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
2113 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2114 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2115 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2116 a := 0
2117 else
2118 a := 1;
2120 if not sound_cap_flag[a].IsPlaying() then
2121 sound_cap_flag[a].Play();
2122 end;
2124 FLAG_STATE_RETURNED:
2125 begin
2126 g_Map_ResetFlag(Fl);
2127 if Quiet then Exit;
2129 if Fl = FLAG_RED then
2130 s := _lc[I_PLAYER_FLAG_RED]
2131 else
2132 s := _lc[I_PLAYER_FLAG_BLUE];
2134 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2136 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2137 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2138 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2139 a := 0
2140 else
2141 a := 1;
2143 if not sound_ret_flag[a].IsPlaying() then
2144 sound_ret_flag[a].Play();
2145 end;
2146 end;
2147 end;
2149 procedure MC_RECV_GameSettings(var M: TMsg);
2150 begin
2151 gGameSettings.GameMode := M.ReadByte();
2152 gGameSettings.GoalLimit := M.ReadWord();
2153 gGameSettings.TimeLimit := M.ReadWord();
2154 gGameSettings.MaxLives := M.ReadByte();
2155 gGameSettings.Options := M.ReadLongWord();
2156 end;
2158 // PLAYER
2160 function MC_RECV_PlayerCreate(var M: TMsg): Word;
2161 var
2162 PID, DID: Word;
2163 PName, Model: string;
2164 Color: TRGB;
2165 T: Byte;
2166 Pl: TPlayer;
2167 begin
2168 PID := M.ReadWord();
2169 Pl := g_Player_Get(PID);
2171 PName := M.ReadString();
2172 Model := M.ReadString();
2173 Color.R := M.ReadByte();
2174 Color.G := M.ReadByte();
2175 Color.B := M.ReadByte();
2176 T := M.ReadByte();
2178 Result := 0;
2179 if (PID <> NetPlrUID1) and (PID <> NetPlrUID2) then
2180 begin
2181 if (Pl <> nil) then Exit;
2182 DID := g_Player_Create(Model, Color, T, False);
2183 with g_Player_Get(DID) do
2184 begin
2185 UID := PID;
2186 Name := PName;
2187 Reset(True);
2188 end;
2189 end
2190 else
2191 begin
2192 if (PID = NetPlrUID1) and (gPlayer1 <> nil) then begin
2193 gPlayer1.UID := PID;
2194 gPlayer1.Model.SetColor(Color.R, Color.G, Color.B);
2195 gPlayer1.ChangeTeam(T);
2196 end;
2197 if (PID = NetPlrUID2) and (gPlayer2 <> nil) then begin
2198 gPlayer2.UID := PID;
2199 gPlayer2.Model.SetColor(Color.R, Color.G, Color.B);
2200 gPlayer2.ChangeTeam(T);
2201 end;
2202 end;
2204 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
2205 e_WriteLog('NET: Player ' + PName + ' [' + IntToStr(PID) + '] added.', TMsgType.Notify);
2206 Result := PID;
2207 end;
2209 function MC_RECV_PlayerPos(var M: TMsg): Word;
2210 var
2211 GT: LongWord;
2212 PID: Word;
2213 kByte: Word;
2214 Pl: TPlayer;
2215 Dir: Byte;
2216 TmpX, TmpY: Integer;
2217 begin
2218 Result := 0;
2220 GT := M.ReadLongWord();
2221 if GT < gTime - NET_MAX_DIFFTIME then
2222 begin
2223 gTime := GT;
2224 Exit;
2225 end;
2226 gTime := GT;
2228 PID := M.ReadWord();
2229 Pl := g_Player_Get(PID);
2231 if Pl = nil then Exit;
2233 Result := PID;
2235 with Pl do
2236 begin
2237 FPing := M.ReadWord();
2238 FLoss := M.ReadByte();
2239 kByte := M.ReadWord();
2240 Dir := M.ReadByte();
2242 TmpX := M.ReadLongInt();
2243 TmpY := M.ReadLongInt();
2245 ReleaseKeys;
2247 if (kByte = NET_KEY_CHAT) then
2248 PressKey(KEY_CHAT, 10000)
2249 else
2250 begin
2251 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
2252 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
2253 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
2254 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
2255 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
2256 end;
2258 if ((Pl <> gPlayer1) and (Pl <> gPlayer2)) or LongBool(kByte and NET_KEY_FORCEDIR) then
2259 SetDirection(TDirection(Dir));
2261 GameVelX := M.ReadLongInt();
2262 GameVelY := M.ReadLongInt();
2263 GameAccelX := M.ReadLongInt();
2264 GameAccelY := M.ReadLongInt();
2265 SetLerp(TmpX, TmpY);
2266 if NetForcePlayerUpdate then Update();
2267 end;
2268 end;
2270 function MC_RECV_PlayerStats(var M: TMsg): Word;
2271 var
2272 PID: Word;
2273 Pl: TPlayer;
2274 I, OldFire: Integer;
2275 OldJet, Flam: Boolean;
2276 NewTeam: Byte;
2277 begin
2278 PID := M.ReadWord();
2279 Pl := g_Player_Get(PID);
2280 Result := 0;
2281 if Pl = nil then
2282 Exit;
2284 with Pl do
2285 begin
2286 alive := (M.ReadByte() <> 0);
2287 GodMode := (M.ReadByte() <> 0);
2288 Health := M.ReadLongInt();
2289 Armor := M.ReadLongInt();
2290 Air := M.ReadLongInt();
2291 JetFuel := M.ReadLongInt();
2292 Lives := M.ReadByte();
2293 NewTeam := M.ReadByte();
2295 for I := WP_FIRST to WP_LAST do
2296 FWeapon[I] := (M.ReadByte() <> 0);
2298 for I := A_BULLETS to A_HIGH do
2299 FAmmo[I] := M.ReadWord();
2301 for I := A_BULLETS to A_HIGH do
2302 FMaxAmmo[I] := M.ReadWord();
2304 for I := MR_SUIT to MR_MAX do
2305 FMegaRulez[I] := M.ReadLongWord();
2307 FRulez := [];
2308 if (M.ReadByte() <> 0) then
2309 FRulez := FRulez + [R_ITEM_BACKPACK];
2310 if (M.ReadByte() <> 0) then
2311 FRulez := FRulez + [R_KEY_RED];
2312 if (M.ReadByte() <> 0) then
2313 FRulez := FRulez + [R_KEY_GREEN];
2314 if (M.ReadByte() <> 0) then
2315 FRulez := FRulez + [R_KEY_BLUE];
2316 if (M.ReadByte() <> 0) then
2317 FRulez := FRulez + [R_BERSERK];
2319 Frags := M.ReadLongInt();
2320 Death := M.ReadLongInt();
2322 SetWeapon(M.ReadByte());
2324 FSpectator := M.ReadByte() <> 0;
2325 if FSpectator then
2326 begin
2327 if Pl = gPlayer1 then
2328 begin
2329 gLMSPID1 := UID;
2330 gPlayer1 := nil;
2331 end;
2332 if Pl = gPlayer2 then
2333 begin
2334 gLMSPID2 := UID;
2335 gPlayer2 := nil;
2336 end;
2337 end
2338 else
2339 begin
2340 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
2341 gPlayer1 := g_Player_Get(gLMSPID1);
2342 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
2343 gPlayer2 := g_Player_Get(gLMSPID2);
2344 end;
2345 FGhost := M.ReadByte() <> 0;
2346 FPhysics := M.ReadByte() <> 0;
2347 FNoRespawn := M.ReadByte() <> 0;
2348 OldJet := FJetpack;
2349 FJetpack := M.ReadByte() <> 0;
2350 OldFire := FFireTime;
2351 FFireTime := M.ReadLongInt();
2352 if (OldFire <= 0) and (FFireTime > 0) then
2353 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
2354 Flam := M.ReadByte() <> 0;
2355 if OldJet and not FJetpack then
2356 JetpackOff
2357 else if not OldJet and FJetpack then
2358 JetpackOn;
2359 if FFlaming and not Flam then
2360 FlamerOff;
2361 if Team <> NewTeam then
2362 Pl.ChangeTeam(NewTeam);
2363 end;
2365 Result := PID;
2366 end;
2368 function MC_RECV_PlayerDamage(var M: TMsg): Word;
2369 var
2370 PID: Word;
2371 Pl: TPlayer;
2372 Kind: Byte;
2373 Attacker, Value: Word;
2374 VX, VY: Integer;
2375 begin
2376 Result := 0;
2377 if not gGameOn then Exit;
2378 PID := M.ReadWord();
2379 Pl := g_Player_Get(PID);
2380 if Pl = nil then Exit;
2382 Kind := M.ReadByte();
2383 Attacker := M.ReadWord();
2384 Value := M.ReadWord();
2385 VX := M.ReadWord();
2386 VY := M.ReadWord();
2388 with Pl do
2389 Damage(Value, Attacker, VX, VY, Kind);
2391 Result := PID;
2392 end;
2394 function MC_RECV_PlayerDeath(var M: TMsg): Word;
2395 var
2396 PID: Word;
2397 Pl: TPlayer;
2398 KillType, DeathType: Byte;
2399 Attacker: Word;
2400 begin
2401 Result := 0;
2402 if not gGameOn then Exit;
2403 PID := M.ReadWord();
2404 Pl := g_Player_Get(PID);
2405 if Pl = nil then Exit;
2407 KillType := M.ReadByte();
2408 DeathType := M.ReadByte();
2409 Attacker := M.ReadWord();
2411 with Pl do
2412 begin
2413 Kill(KillType, Attacker, DeathType);
2414 SoftReset;
2415 end;
2416 end;
2418 function MC_RECV_PlayerDelete(var M: TMsg): Word;
2419 var
2420 PID: Word;
2421 Pl: TPlayer;
2422 begin
2423 PID := M.ReadWord();
2424 Pl := g_Player_Get(PID);
2425 Result := 0;
2426 if Pl = nil then Exit;
2428 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2429 e_WriteLog('NET: Player ' + Pl.Name + ' [' + IntToStr(PID) + '] removed.', TMsgType.Notify);
2431 g_Player_Remove(PID);
2433 Result := PID;
2434 end;
2436 function MC_RECV_PlayerFire(var M: TMsg): Word;
2437 var
2438 PID: Word;
2439 Weap: Byte;
2440 Pl: TPlayer;
2441 X, Y, AX, AY: Integer;
2442 SHID: Integer;
2443 begin
2444 Result := 0;
2445 if not gGameOn then Exit;
2446 PID := M.ReadWord();
2447 Pl := g_Player_Get(PID);
2448 if Pl = nil then Exit;
2450 Weap := M.ReadByte();
2451 X := M.ReadLongInt();
2452 Y := M.ReadLongInt();
2453 AX := M.ReadLongInt();
2454 AY := M.ReadLongInt();
2455 SHID := M.ReadLongInt();
2457 with Pl do
2458 if alive then NetFire(Weap, X, Y, AX, AY, SHID);
2459 end;
2461 procedure MC_RECV_PlayerSettings(var M: TMsg);
2462 var
2463 TmpName: string;
2464 TmpModel: string;
2465 TmpColor: TRGB;
2466 TmpTeam: Byte;
2467 Pl: TPlayer;
2468 PID: Word;
2469 begin
2470 PID := M.ReadWord();
2471 Pl := g_Player_Get(PID);
2472 if Pl = nil then Exit;
2474 TmpName := M.ReadString();
2475 TmpModel := M.ReadString();
2476 TmpColor.R := M.ReadByte();
2477 TmpColor.G := M.ReadByte();
2478 TmpColor.B := M.ReadByte();
2479 TmpTeam := M.ReadByte();
2481 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
2482 begin
2483 Pl.ChangeTeam(TmpTeam);
2484 if gPlayer1 = Pl then
2485 gPlayer1Settings.Team := TmpTeam;
2486 if gPlayer2 = Pl then
2487 gPlayer2Settings.Team := TmpTeam;
2488 end else
2489 Pl.SetColor(TmpColor);
2491 if Pl.Name <> TmpName then
2492 begin
2493 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
2494 Pl.Name := TmpName;
2495 end;
2497 if TmpModel <> Pl.Model.Name then
2498 Pl.SetModel(TmpModel);
2499 end;
2501 // ITEM
2503 procedure MC_RECV_ItemSpawn(var M: TMsg);
2504 var
2505 ID: Word;
2506 AID: DWord;
2507 X, Y, VX, VY: Integer;
2508 T: Byte;
2509 Quiet, Fall{, Resp}: Boolean;
2510 Anim: TAnimation;
2511 it: PItem;
2512 begin
2513 if not gGameOn then Exit;
2514 ID := M.ReadWord();
2515 Quiet := M.ReadByte() <> 0;
2516 T := M.ReadByte();
2517 Fall := M.ReadByte() <> 0;
2518 {Resp :=} M.ReadByte();
2519 X := M.ReadLongInt();
2520 Y := M.ReadLongInt();
2521 VX := M.ReadLongInt();
2522 VY := M.ReadLongInt();
2524 g_Items_Create(X, Y, T and $7F, Fall, False, False, ID);
2525 if ((T and $80) <> 0) then g_Items_SetDrop(ID);
2527 it := g_Items_ByIdx(ID);
2528 it.Obj.Vel.X := VX;
2529 it.Obj.Vel.Y := VY;
2531 if not Quiet then
2532 begin
2533 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
2534 if g_Frames_Get(AID, 'FRAMES_ITEM_RESPAWN') then
2535 begin
2536 Anim := TAnimation.Create(AID, False, 4);
2537 g_GFX_OnceAnim(X+(it.Obj.Rect.Width div 2)-16, Y+(it.Obj.Rect.Height div 2)-16, Anim);
2538 Anim.Free();
2539 end;
2540 end;
2541 end;
2543 procedure MC_RECV_ItemDestroy(var M: TMsg);
2544 var
2545 ID: Word;
2546 Quiet: Boolean;
2547 begin
2548 if not gGameOn then Exit;
2549 ID := M.ReadWord();
2550 Quiet := M.ReadByte() <> 0;
2552 if not g_Items_ValidId(ID) then exit;
2554 if not Quiet then g_Items_EmitPickupSound(ID);
2556 g_Items_Remove(ID);
2557 end;
2559 // PANEL
2561 procedure MC_RECV_PanelTexture(var M: TMsg);
2562 var
2563 TP: TPanel;
2564 PGUID: Integer;
2565 Tex, Fr: Integer;
2566 Loop, Cnt: Byte;
2567 begin
2568 if not gGameOn then Exit;
2570 PGUID := Integer(M.ReadLongWord());
2571 Tex := M.ReadLongInt();
2572 Fr := M.ReadLongInt();
2573 Cnt := M.ReadByte();
2574 Loop := M.ReadByte();
2576 TP := g_Map_PanelByGUID(PGUID);
2577 if (TP <> nil) then
2578 begin
2579 // switch texture
2580 TP.SetTexture(Tex, Loop);
2581 TP.SetFrame(Fr, Cnt);
2582 end;
2583 end;
2585 procedure MC_RECV_PanelState(var M: TMsg);
2586 var
2587 PGUID: Integer;
2588 E: Boolean;
2589 Lift: Byte;
2590 X, Y, W, H: Integer;
2591 TP: TPanel;
2592 speedX, speedY, startX, startY, endX, endY: Integer;
2593 sizeSpX, sizeSpY, sizeEX, sizeEY: Integer;
2594 mpflags: Byte;
2595 begin
2596 if not gGameOn then Exit;
2598 PGUID := Integer(M.ReadLongWord());
2599 E := (M.ReadByte() <> 0);
2600 Lift := M.ReadByte();
2601 X := M.ReadLongInt();
2602 Y := M.ReadLongInt();
2603 W := M.ReadWord();
2604 H := M.ReadWord();
2605 // mplats
2606 speedX := M.ReadLongInt();
2607 speedY := M.ReadLongInt();
2608 startX := M.ReadLongInt();
2609 startY := M.ReadLongInt();
2610 endX := M.ReadLongInt();
2611 endY := M.ReadLongInt();
2612 sizeSpX := M.ReadLongInt();
2613 sizeSpY := M.ReadLongInt();
2614 sizeEX := M.ReadLongInt();
2615 sizeEY := M.ReadLongInt();
2616 mpflags := M.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2618 TP := g_Map_PanelByGUID(PGUID);
2619 if (TP = nil) then exit;
2621 // update lifts state
2622 if TP.isGLift then g_Map_SetLiftGUID(PGUID, Lift);
2624 // update enabled/disabled state for all panels
2625 if E then g_Map_EnableWallGUID(PGUID) else g_Map_DisableWallGUID(PGUID);
2627 // update panel position, as it can be moved (mplat)
2628 TP.X := X;
2629 TP.Y := Y;
2630 TP.Width := W;
2631 TP.Height := H;
2632 // update mplat state
2633 TP.movingSpeedX := speedX;
2634 TP.movingSpeedY := speedY;
2635 TP.movingStartX := startX;
2636 TP.movingStartY := startY;
2637 TP.movingEndX := endX;
2638 TP.movingEndY := endY;
2639 TP.sizeSpeedX := sizeSpX;
2640 TP.sizeSpeedY := sizeSpY;
2641 TP.sizeEndX := sizeEX;
2642 TP.sizeEndY := sizeEY;
2643 TP.movingActive := ((mpflags and 1) <> 0);
2644 TP.moveOnce := ((mpflags and 2) <> 0);
2645 // notify panel of it's position/size change, so it can fix other internal structures
2646 TP.positionChanged();
2647 end;
2649 // TRIGGERS
2651 procedure MC_RECV_TriggerSound(var M: TMsg);
2652 var
2653 SPlaying: Boolean;
2654 SPos, SID: LongWord;
2655 SCount: LongInt;
2656 I: Integer;
2657 begin
2658 if not gGameOn then Exit;
2659 if gTriggers = nil then Exit;
2661 SID := M.ReadLongWord();
2662 SPlaying := M.ReadByte() <> 0;
2663 SPos := M.ReadLongWord();
2664 SCount := M.ReadLongInt();
2666 for I := Low(gTriggers) to High(gTriggers) do
2667 if gTriggers[I].TriggerType = TRIGGER_SOUND then
2668 if gTriggers[I].ClientID = SID then
2669 with gTriggers[I] do
2670 begin
2671 if Sound <> nil then
2672 begin
2673 if SPlaying then
2674 begin
2675 if tgcLocal then
2676 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), tgcVolume/255.0)
2677 else
2678 Sound.PlayPanVolume((tgcPan-127.0)/128.0, tgcVolume/255.0);
2679 Sound.SetPosition(SPos);
2680 end
2681 else
2682 if Sound.IsPlaying then Sound.Stop;
2683 end;
2685 SoundPlayCount := SCount;
2686 end;
2687 end;
2689 procedure MC_RECV_TriggerMusic(var M: TMsg);
2690 var
2691 MName: string;
2692 MPlaying: Boolean;
2693 MPos: LongWord;
2694 MPaused: Boolean;
2695 begin
2696 if not gGameOn then Exit;
2698 MName := M.ReadString();
2699 MPlaying := M.ReadByte() <> 0;
2700 MPos := M.ReadLongWord();
2701 MPaused := M.ReadByte() <> 0;
2702 MPos := MPos+1; //k8: stfu, fpc!
2704 if MPlaying then
2705 begin
2706 gMusic.SetByName(MName);
2707 gMusic.Play(True);
2708 // gMusic.SetPosition(MPos);
2709 gMusic.SpecPause := MPaused;
2710 end
2711 else
2712 if gMusic.IsPlaying then gMusic.Stop;
2713 end;
2715 // MONSTERS
2717 procedure MC_RECV_MonsterSpawn(var M: TMsg);
2718 var
2719 ID: Word;
2720 MType, MState, MDir, MAnim, MBehav: Byte;
2721 X, Y, VX, VY, MTargTime, MHealth, MAmmo, MSleep: Integer;
2722 MTarg: Word;
2723 Mon: TMonster;
2724 begin
2725 ID := M.ReadWord();
2726 Mon := g_Monsters_ByUID(ID);
2727 if Mon <> nil then
2728 Exit;
2730 MType := M.ReadByte();
2731 MState := M.ReadByte();
2732 MAnim := M.ReadByte();
2733 MTarg := M.ReadWord();
2734 MTargTime := M.ReadLongInt();
2735 MBehav := M.ReadByte();
2736 MSleep := M.ReadLongInt();
2737 MHealth := M.ReadLongInt();
2738 MAmmo := M.ReadLongInt();
2740 X := M.ReadLongInt();
2741 Y := M.ReadLongInt();
2742 VX := M.ReadLongInt();
2743 VY := M.ReadLongInt();
2744 MDir := M.ReadByte();
2746 g_Monsters_Create(MType, X, Y, TDirection(MDir), False, ID);
2747 Mon := g_Monsters_ByUID(ID);
2748 if Mon = nil then
2749 Exit;
2751 with Mon do
2752 begin
2754 MonsterAnim := MAnim;
2755 MonsterTargetUID := MTarg;
2756 MonsterTargetTime := MTargTime;
2757 MonsterBehaviour := MBehav;
2758 MonsterSleep := MSleep;
2759 MonsterAmmo := MAmmo;
2760 SetHealth(MHealth);
2762 SetState(MState);
2764 setPosition(X, Y); // this will call positionChanged();
2765 GameVelX := VX;
2766 GameVelY := VY;
2767 end;
2768 end;
2770 procedure MC_RECV_MonsterPos(var M: TMsg);
2771 var
2772 Mon: TMonster;
2773 ID: Word;
2774 X, Y: Integer;
2775 begin
2776 ID := M.ReadWord();
2777 Mon := g_Monsters_ByUID(ID);
2778 if Mon = nil then
2779 Exit;
2781 with Mon do
2782 begin
2783 X := M.ReadLongInt();
2784 Y := M.ReadLongInt();
2785 Mon.setPosition(X, Y); // this will call `positionChanged()`
2786 GameVelX := M.ReadLongInt();
2787 GameVelY := M.ReadLongInt();
2788 GameDirection := TDirection(M.ReadByte());
2789 end;
2790 end;
2792 procedure MC_RECV_MonsterState(var M: TMsg);
2793 var
2794 ID, OldFire: Integer;
2795 MState, MFAnm: Byte;
2796 Mon: TMonster;
2797 AnimRevert: Boolean;
2798 begin
2799 ID := M.ReadWord();
2800 Mon := g_Monsters_ByUID(ID);
2801 if Mon = nil then Exit;
2803 MState := M.ReadByte();
2804 MFAnm := M.ReadByte();
2806 with Mon do
2807 begin
2808 MonsterTargetUID := M.ReadWord();
2809 MonsterTargetTime := M.ReadLongInt();
2810 MonsterSleep := M.ReadLongInt();
2811 MonsterHealth := M.ReadLongInt();
2812 MonsterAmmo := M.ReadLongInt();
2813 MonsterPain := M.ReadLongInt();
2814 AnimRevert := M.ReadByte() <> 0;
2815 OldFire := FFireTime;
2816 FFireTime := M.ReadLongInt();
2817 if (OldFire <= 0) and (FFireTime > 0) then
2818 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
2819 RevertAnim(AnimRevert);
2821 if MonsterState <> MState then
2822 begin
2823 if (MState = MONSTATE_GO) and (MonsterState = MONSTATE_SLEEP) then WakeUpSound();
2824 if (MState = MONSTATE_DIE) then DieSound();
2825 if (MState = MONSTATE_PAIN) then MakeBloodSimple(Min(200, MonsterPain));
2826 if (MState = MONSTATE_ATTACK) then kick(nil);
2827 if (MState = MONSTATE_DEAD) then SetDeadAnim();
2829 SetState(MState, MFAnm);
2830 end;
2831 end;
2832 end;
2834 procedure MC_RECV_MonsterShot(var M: TMsg);
2835 var
2836 ID: Integer;
2837 Mon: TMonster;
2838 X, Y, VX, VY: Integer;
2839 begin
2840 ID := M.ReadWord();
2842 Mon := g_Monsters_ByUID(ID);
2843 if Mon = nil then Exit;
2845 X := M.ReadLongInt();
2846 Y := M.ReadLongInt();
2847 VX := M.ReadLongInt();
2848 VY := M.ReadLongInt();
2850 Mon.ClientAttack(X, Y, VX, VY);
2851 end;
2853 procedure MC_RECV_MonsterDelete(var M: TMsg);
2854 var
2855 ID: Integer;
2856 Mon: TMonster;
2857 begin
2858 ID := M.ReadWord();
2859 Mon := g_Monsters_ByUID(ID);
2860 if Mon = nil then Exit;
2861 Mon.SetState(5);
2862 Mon.MonsterRemoved := True;
2863 end;
2865 procedure MC_RECV_TimeSync(var M: TMsg);
2866 var
2867 Time: LongWord;
2868 begin
2869 Time := M.ReadLongWord();
2871 if gState = STATE_INTERCUSTOM then
2872 gServInterTime := Min(Time, 255);
2873 end;
2875 procedure MC_RECV_VoteEvent(var M: TMsg);
2876 var
2877 EvID: Byte;
2878 Str1, Str2: string;
2879 Int1, Int2: SmallInt;
2880 begin
2881 EvID := M.ReadByte();
2882 Int1 := M.ReadSmallInt();
2883 Int2 := M.ReadSmallInt();
2884 Str1 := M.ReadString();
2885 Str2 := M.ReadString();
2887 case EvID of
2888 NET_VE_STARTED:
2889 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True);
2890 NET_VE_PASSED:
2891 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True);
2892 NET_VE_FAILED:
2893 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
2894 NET_VE_VOTE:
2895 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True);
2896 NET_VE_INPROGRESS:
2897 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True);
2898 end;
2899 end;
2901 // CLIENT SEND
2903 procedure MC_SEND_Info(Password: string);
2904 begin
2905 NetOut.Clear();
2907 NetOut.Write(Byte(NET_MSG_INFO));
2908 NetOut.Write(GAME_VERSION);
2909 NetOut.Write(Password);
2910 NetOut.Write(gPlayer1Settings.Name);
2911 NetOut.Write(gPlayer1Settings.Model);
2912 NetOut.Write(gPlayer1Settings.Color.R);
2913 NetOut.Write(gPlayer1Settings.Color.G);
2914 NetOut.Write(gPlayer1Settings.Color.B);
2915 NetOut.Write(gPlayer1Settings.Team);
2917 g_Net_Client_Send(True, NET_CHAN_SERVICE);
2918 end;
2920 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
2921 begin
2922 NetOut.Write(Byte(NET_MSG_CHAT));
2923 NetOut.Write(Txt);
2924 NetOut.Write(Mode);
2926 g_Net_Client_Send(True, NET_CHAN_CHAT);
2927 end;
2929 procedure MC_SEND_PlayerPos();
2930 var
2931 kByte: Word;
2932 Predict: Boolean;
2933 strafeDir: Byte;
2934 WeaponSelect: Word = 0;
2935 i: Integer;
2936 begin
2937 if not gGameOn then Exit;
2938 if gPlayers = nil then Exit;
2939 if gPlayer1 = nil then Exit;
2941 kByte := 0;
2942 Predict := NetPredictSelf; // and (not NetGotKeys);
2944 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2945 begin
2946 strafeDir := P1MoveButton shr 4;
2947 P1MoveButton := P1MoveButton and $0F;
2949 if gPlayerAction[0, ACTION_MOVELEFT] and (not gPlayerAction[0, ACTION_MOVERIGHT]) then
2950 P1MoveButton := 1
2951 else if (not gPlayerAction[0, ACTION_MOVELEFT]) and gPlayerAction[0, ACTION_MOVERIGHT] then
2952 P1MoveButton := 2
2953 else if (not gPlayerAction[0, ACTION_MOVELEFT]) and (not gPlayerAction[0, ACTION_MOVERIGHT]) then
2954 P1MoveButton := 0;
2956 // strafing
2957 if gPlayerAction[0, ACTION_STRAFE] then
2958 begin
2959 // new strafe mechanics
2960 if (strafeDir = 0) then
2961 strafeDir := P1MoveButton; // start strafing
2962 // now set direction according to strafe (reversed)
2963 if (strafeDir = 2) then
2964 gPlayer1.SetDirection(TDirection.D_LEFT)
2965 else if (strafeDir = 1) then
2966 gPlayer1.SetDirection(TDirection.D_RIGHT)
2967 end
2968 else
2969 begin
2970 strafeDir := 0; // not strafing anymore
2971 if (P1MoveButton = 2) and gPlayerAction[0, ACTION_MOVELEFT] then
2972 gPlayer1.SetDirection(TDirection.D_LEFT)
2973 else if (P1MoveButton = 1) and gPlayerAction[0, ACTION_MOVERIGHT] then
2974 gPlayer1.SetDirection(TDirection.D_RIGHT)
2975 else if P1MoveButton <> 0 then
2976 gPlayer1.SetDirection(TDirection(P1MoveButton-1));
2977 end;
2979 gPlayer1.ReleaseKeys;
2980 if P1MoveButton = 1 then
2981 begin
2982 kByte := kByte or NET_KEY_LEFT;
2983 if Predict then gPlayer1.PressKey(KEY_LEFT, 10000);
2984 end;
2985 if P1MoveButton = 2 then
2986 begin
2987 kByte := kByte or NET_KEY_RIGHT;
2988 if Predict then gPlayer1.PressKey(KEY_RIGHT, 10000);
2989 end;
2990 if gPlayerAction[0, ACTION_LOOKUP] then
2991 begin
2992 kByte := kByte or NET_KEY_UP;
2993 gPlayer1.PressKey(KEY_UP, 10000);
2994 end;
2995 if gPlayerAction[0, ACTION_LOOKDOWN] then
2996 begin
2997 kByte := kByte or NET_KEY_DOWN;
2998 gPlayer1.PressKey(KEY_DOWN, 10000);
2999 end;
3000 if gPlayerAction[0, ACTION_JUMP] then
3001 begin
3002 kByte := kByte or NET_KEY_JUMP;
3003 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3004 end;
3005 if gPlayerAction[0, ACTION_ATTACK] then kByte := kByte or NET_KEY_FIRE;
3006 if gPlayerAction[0, ACTION_ACTIVATE] then kByte := kByte or NET_KEY_OPEN;
3007 if gPlayerAction[0, ACTION_WEAPNEXT] then kByte := kByte or NET_KEY_NW;
3008 if gPlayerAction[0, ACTION_WEAPPREV] then kByte := kByte or NET_KEY_PW;
3010 gPlayerAction[0, ACTION_WEAPNEXT] := False; // HACK, remove after readyweaon&pendinweapon implementation
3011 gPlayerAction[0, ACTION_WEAPPREV] := False; // HACK, remove after readyweaon&pendinweapon implementation
3013 for i := WP_FIRST to WP_LAST do
3014 begin
3015 if gSelectWeapon[0, i] then
3016 begin
3017 WeaponSelect := WeaponSelect or Word(1 shl i);
3018 gSelectWeapon[0, i] := False
3019 end
3020 end;
3022 // fix movebutton state
3023 P1MoveButton := P1MoveButton or (strafeDir shl 4);
3024 end
3025 else
3026 kByte := NET_KEY_CHAT;
3028 NetOut.Write(Byte(NET_MSG_PLRPOS));
3029 NetOut.Write(gTime);
3030 NetOut.Write(kByte);
3031 NetOut.Write(Byte(gPlayer1.Direction));
3032 NetOut.Write(WeaponSelect);
3033 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3034 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS);
3036 //kBytePrev := kByte;
3037 //kDirPrev := gPlayer1.Direction;
3038 end;
3040 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
3041 begin
3042 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
3043 NetOut.Write(Byte(Start));
3044 NetOut.Write(Command);
3045 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3046 end;
3048 procedure MC_SEND_PlayerSettings();
3049 begin
3050 NetOut.Write(Byte(NET_MSG_PLRSET));
3051 NetOut.Write(gPlayer1Settings.Name);
3052 NetOut.Write(gPlayer1Settings.Model);
3053 NetOut.Write(gPlayer1Settings.Color.R);
3054 NetOut.Write(gPlayer1Settings.Color.G);
3055 NetOut.Write(gPlayer1Settings.Color.B);
3056 NetOut.Write(gPlayer1Settings.Team);
3058 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3059 end;
3061 procedure MC_SEND_FullStateRequest();
3062 begin
3063 NetOut.Write(Byte(NET_MSG_REQFST));
3065 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3066 end;
3068 procedure MC_SEND_CheatRequest(Kind: Byte);
3069 begin
3070 NetOut.Write(Byte(NET_MSG_CHEAT));
3071 NetOut.Write(Kind);
3073 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3074 end;
3075 procedure MC_SEND_RCONPassword(Password: string);
3076 begin
3077 NetOut.Write(Byte(NET_MSG_RCON_AUTH));
3078 NetOut.Write(Password);
3080 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3081 end;
3082 procedure MC_SEND_RCONCommand(Cmd: string);
3083 begin
3084 NetOut.Write(Byte(NET_MSG_RCON_CMD));
3085 NetOut.Write(Cmd);
3087 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3088 end;
3091 end.