DEADSOFTWARE

net: anti full state spam (by fgsfds)
[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;
34 NET_MSG_FLAGPOS= 110;
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;
48 NET_MSG_IPOS = 123;
50 NET_MSG_MSPAWN = 131;
51 NET_MSG_MPOS = 132;
52 NET_MSG_MSTATE = 133;
53 NET_MSG_MSHOT = 134;
54 NET_MSG_MDEL = 135;
56 NET_MSG_PSTATE = 141;
57 NET_MSG_PTEX = 142;
59 NET_MSG_TSOUND = 151;
60 NET_MSG_TMUSIC = 152;
62 NET_MSG_SHDEL = 161;
63 NET_MSG_SHADD = 162;
64 NET_MSG_SHPOS = 163;
66 NET_MSG_RCON_AUTH = 191;
67 NET_MSG_RCON_CMD = 192;
68 NET_MSG_TIME_SYNC = 194;
69 NET_MSG_VOTE_EVENT = 195;
71 {
72 NET_MSG_MAP_REQUEST = 201;
73 NET_MSG_MAP_RESPONSE = 202;
74 NET_MSG_RES_REQUEST = 203;
75 NET_MSG_RES_RESPONSE = 204;
76 }
78 NET_CHAT_SYSTEM = 0;
79 NET_CHAT_PLAYER = 1;
80 NET_CHAT_TEAM = 2;
82 NET_RCON_NOAUTH = 0;
83 NET_RCON_PWGOOD = 1;
84 NET_RCON_PWBAD = 2;
86 NET_GFX_SPARK = 1;
87 NET_GFX_TELE = 2;
88 NET_GFX_RESPAWN = 3;
89 NET_GFX_FIRE = 4;
90 NET_GFX_EXPLODE = 5;
91 NET_GFX_BFGEXPL = 6;
92 NET_GFX_BFGHIT = 7;
93 NET_GFX_SHELL1 = 8;
94 NET_GFX_SHELL2 = 9;
95 NET_GFX_SHELL3 = 10;
97 NET_EV_MAPSTART = 1;
98 NET_EV_MAPEND = 2;
99 NET_EV_CHANGE_TEAM = 3;
100 NET_EV_PLAYER_KICK = 4;
101 NET_EV_PLAYER_BAN = 5;
102 NET_EV_LMS_WARMUP = 6;
103 NET_EV_LMS_SURVIVOR = 7;
104 NET_EV_RCON = 8;
105 NET_EV_BIGTEXT = 9;
106 NET_EV_SCORE = 10;
107 NET_EV_SCORE_MSG = 11;
108 NET_EV_LMS_START = 12;
109 NET_EV_LMS_WIN = 13;
110 NET_EV_TLMS_WIN = 14;
111 NET_EV_LMS_LOSE = 15;
112 NET_EV_LMS_DRAW = 16;
113 NET_EV_KILLCOMBO = 17;
114 NET_EV_PLAYER_TOUCH = 18;
115 NET_EV_SECRET = 19;
116 NET_EV_INTER_READY = 20;
117 NET_EV_LMS_NOSPAWN = 21;
119 NET_VE_STARTED = 1;
120 NET_VE_PASSED = 2;
121 NET_VE_FAILED = 3;
122 NET_VE_VOTE = 4;
123 NET_VE_REVOKE = 5;
124 NET_VE_INPROGRESS = 6;
126 NET_FLAG_GET = 1;
127 NET_FLAG_DROP = 2;
128 NET_FLAG_CAP = 3;
129 NET_FLAG_RETURN = 4;
131 NET_CHEAT_SUICIDE = 1;
132 NET_CHEAT_SPECTATE = 2;
133 NET_CHEAT_READY = 3;
134 NET_CHEAT_DROPFLAG = 4;
136 NET_MAX_DIFFTIME = 5000 div 36;
138 // HOST MESSAGES
140 procedure MH_MalformedPacket(C: pTNetClient);
141 procedure MH_ProcessFirstSpawn (C: pTNetClient);
143 procedure MH_RECV_Info(C: pTNetClient; var M: TMsg);
144 procedure MH_RECV_Chat(C: pTNetClient; var M: TMsg);
145 procedure MH_RECV_FullStateRequest(C: pTNetClient; var M: TMsg);
146 function MH_RECV_PlayerPos(C: pTNetClient; var M: TMsg): Word;
147 procedure MH_RECV_PlayerSettings(C: pTNetClient; var M: TMsg);
148 procedure MH_RECV_CheatRequest(C: pTNetClient; var M: TMsg);
149 procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
150 procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
151 //procedure MH_RECV_MapRequest(C: pTNetClient; var M: TMsg);
152 //procedure MH_RECV_ResRequest(C: pTNetClient; var M: TMsg);
153 procedure MH_RECV_Vote(C: pTNetClient; var M: TMsg);
155 // GAME
156 procedure MH_SEND_Everything(CreatePlayers: Boolean {= False}; ID: Integer {= NET_EVERYONE});
157 procedure MH_SEND_Info(ID: Byte);
158 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
159 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
160 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
161 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
162 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
163 procedure MH_SEND_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
164 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
165 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
166 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
167 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
168 procedure MH_SEND_FlagPos(Flag: Byte; ID: Integer = NET_EVERYONE);
169 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
170 // PLAYER
171 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
172 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
173 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
174 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
175 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
176 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
177 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
178 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
179 // ITEM
180 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
181 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
182 procedure MH_SEND_ItemPos(IID: Word; ID: Integer = NET_EVERYONE);
183 // PANEL
184 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
185 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
186 // MONSTER
187 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
188 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
189 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
190 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
191 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
192 // TRIGGER
193 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
194 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
195 // MISC
196 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
197 procedure MH_SEND_VoteEvent(EvType: Byte;
198 StrArg1: string = 'a'; StrArg2: string = 'b';
199 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
200 ID: Integer = NET_EVERYONE);
202 // CLIENT MESSAGES //
204 // GAME
205 procedure MC_RECV_Chat(var M: TMsg);
206 procedure MC_RECV_Effect(var M: TMsg);
207 procedure MC_RECV_Sound(var M: TMsg);
208 procedure MC_RECV_GameStats(var M: TMsg);
209 procedure MC_RECV_CoopStats(var M: TMsg);
210 procedure MC_RECV_GameEvent(var M: TMsg);
211 procedure MC_RECV_FlagEvent(var M: TMsg);
212 procedure MC_RECV_FlagPos(var M: TMsg);
213 procedure MC_RECV_GameSettings(var M: TMsg);
214 // PLAYER
215 function MC_RECV_PlayerCreate(var M: TMsg): Word;
216 function MC_RECV_PlayerPos(var M: TMsg): Word;
217 function MC_RECV_PlayerStats(var M: TMsg): Word;
218 function MC_RECV_PlayerDelete(var M: TMsg): Word;
219 function MC_RECV_PlayerDamage(var M: TMsg): Word;
220 function MC_RECV_PlayerDeath(var M: TMsg): Word;
221 function MC_RECV_PlayerFire(var M: TMsg): Word;
222 procedure MC_RECV_PlayerSettings(var M: TMsg);
223 // ITEM
224 procedure MC_RECV_ItemSpawn(var M: TMsg);
225 procedure MC_RECV_ItemDestroy(var M: TMsg);
226 procedure MC_RECV_ItemPos(var M: TMsg);
227 // PANEL
228 procedure MC_RECV_PanelTexture(var M: TMsg);
229 procedure MC_RECV_PanelState(var M: TMsg);
230 // MONSTER
231 procedure MC_RECV_MonsterSpawn(var M: TMsg);
232 procedure MC_RECV_MonsterPos(var M: TMsg);
233 procedure MC_RECV_MonsterState(var M: TMsg);
234 procedure MC_RECV_MonsterShot(var M: TMsg);
235 procedure MC_RECV_MonsterDelete(var M: TMsg);
236 // SHOT
237 procedure MC_RECV_CreateShot(var M: TMsg);
238 procedure MC_RECV_UpdateShot(var M: TMsg);
239 procedure MC_RECV_DeleteShot(var M: TMsg);
240 // TRIGGER
241 procedure MC_RECV_TriggerSound(var M: TMsg);
242 procedure MC_RECV_TriggerMusic(var M: TMsg);
243 // MISC
244 procedure MC_RECV_TimeSync(var M: TMsg);
245 procedure MC_RECV_VoteEvent(var M: TMsg);
246 // SERVICE
247 procedure MC_SEND_Info(Password: string);
248 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
249 procedure MC_SEND_PlayerPos();
250 procedure MC_SEND_FullStateRequest();
251 procedure MC_SEND_PlayerSettings();
252 procedure MC_SEND_CheatRequest(Kind: Byte);
253 procedure MC_SEND_RCONPassword(Password: string);
254 procedure MC_SEND_RCONCommand(Cmd: string);
255 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
256 // DOWNLOAD
257 //procedure MC_SEND_MapRequest();
258 //procedure MC_SEND_ResRequest(const resName: AnsiString);
261 type
262 TExternalResourceInfo = record
263 Name: string[255];
264 md5: TMD5Digest;
265 end;
267 TResDataMsg = record
268 MsgId: Byte;
269 FileSize: Integer;
270 FileData: AByte;
271 end;
273 TMapDataMsg = record
274 MsgId: Byte;
275 FileSize: Integer;
276 FileData: AByte;
277 ExternalResources: array of TExternalResourceInfo;
278 end;
280 function IsValidFileName(const S: String): Boolean;
281 function IsValidFilePath(const S: String): Boolean;
284 implementation
286 uses
287 Math, ENet, e_input, e_graphics, e_log,
288 g_textures, g_gfx, g_sound, g_console, g_basic, g_options, g_main,
289 g_game, g_player, g_map, g_panel, g_items, g_weapons, g_phys, g_gui,
290 g_language, g_monsters, g_netmaster, utils, wadreader, MAPDEF;
292 const
293 NET_KEY_LEFT = 1 shl 0;
294 NET_KEY_RIGHT = 1 shl 1;
295 NET_KEY_UP = 1 shl 2;
296 NET_KEY_DOWN = 1 shl 3;
297 NET_KEY_JUMP = 1 shl 4;
298 NET_KEY_FIRE = 1 shl 5;
299 NET_KEY_OPEN = 1 shl 6;
300 NET_KEY_CHAT = 1 shl 7;
301 NET_KEY_FORCEDIR = 1 shl 8;
303 //var
304 //kBytePrev: Word = 0;
305 //kDirPrev: TDirection = D_LEFT;
306 //HostGameTime: Word = 0;
309 function IsValidFileName(const S: String): Boolean;
310 const
311 Forbidden: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
312 var
313 I: Integer;
314 begin
315 Result := S <> '';
316 for I := 1 to Length(S) do
317 Result := Result and (not(S[I] in Forbidden));
318 end;
320 function IsValidFilePath(const S: String): Boolean;
321 var
322 I: Integer;
323 begin
324 Result := False;
325 if not IsValidFileName(S) then exit;
326 if FileExists(S) then exit;
327 I := LastDelimiter('\/', S);
328 if (I > 0) then
329 if (not DirectoryExists(Copy(S, 1, I-1))) then
330 exit;
331 Result := True;
332 end;
335 // HOST MESSAGES //
338 // GAME
340 procedure MH_MalformedPacket(C: pTNetClient);
341 begin
342 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
343 _lc[I_NET_DISC_PROTOCOL]);
344 enet_peer_disconnect(C^.Peer, NET_DISC_PROTOCOL);
345 end;
347 procedure MH_RECV_Chat(C: pTNetClient; var M: TMsg);
348 var
349 Txt: string;
350 Mode: Byte;
351 PID: Word;
352 Pl: TPlayer;
353 Err: Boolean;
354 begin
355 PID := C^.Player;
356 Pl := g_Player_Get(PID);
358 Err := False;
359 try
360 Txt := M.ReadString();
361 Mode := M.ReadByte();
362 except
363 Err := True;
364 end;
366 if Err then begin MH_MalformedPacket(C); Exit; end;
368 if (Mode = NET_CHAT_SYSTEM) then
369 Mode := NET_CHAT_PLAYER; // prevent sending system messages from clients
370 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
371 Mode := NET_CHAT_PLAYER; // revert to player chat in non-team game
373 if Pl = nil then
374 MH_SEND_Chat(Txt, Mode)
375 else
376 MH_SEND_Chat(Pl.Name + ': ' + Txt, Mode, IfThen(Mode = NET_CHAT_TEAM, Pl.Team, NET_EVERYONE));
377 end;
379 procedure MH_RECV_Info(C: pTNetClient; var M: TMsg);
380 var
381 Ver, PName, Model, Pw: string;
382 R, G, B, T: Byte;
383 WeapSwitch: Byte;
384 TmpPrefArray: Array [WP_FIRST .. WP_LAST + 1] of Byte;
385 SwitchEmpty: Byte;
386 SkipF: Byte;
387 PID: Word;
388 Color: TRGB;
389 I: Integer;
390 Err: Boolean;
391 begin
392 Err := False;
393 try
394 Ver := M.ReadString();
395 Pw := M.ReadString();
396 PName := M.ReadString();
397 Model := M.ReadString();
398 R := M.ReadByte();
399 G := M.ReadByte();
400 B := M.ReadByte();
401 T := M.ReadByte();
402 WeapSwitch := M.ReadByte();
403 for I := WP_FIRST to WP_LAST + 1 do
404 TmpPrefArray[I] := M.ReadByte();
405 SwitchEmpty := M.ReadByte();
406 SkipF := M.ReadByte();
407 except
408 Err := True;
409 end;
411 if Err then begin MH_MalformedPacket(C); Exit; end;
413 if Ver <> GAME_VERSION then
414 begin
415 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
416 _lc[I_NET_DISC_VERSION]);
417 enet_peer_disconnect(C^.Peer, NET_DISC_VERSION);
418 Exit;
419 end;
421 if g_Net_IsHostBanned(C^.Peer^.address.host) then
422 begin
423 if g_Net_IsHostBanned(C^.Peer^.address.host, True) then
424 begin
425 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
426 _lc[I_NET_DISC_BAN]);
427 enet_peer_disconnect(C^.Peer, NET_DISC_BAN);
428 end
429 else
430 begin
431 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
432 _lc[I_NET_DISC_BAN]);
433 enet_peer_disconnect(C^.Peer, NET_DISC_TEMPBAN);
434 end;
435 Exit;
436 end;
438 if NetPassword <> '' then
439 if AnsiLowerCase(NetPassword) <> AnsiLowerCase(Pw) then
440 begin
441 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
442 _lc[I_NET_DISC_PASSWORD]);
443 enet_peer_disconnect(C^.Peer, NET_DISC_PASSWORD);
444 Exit;
445 end;
447 if (C^.Player <> 0) then
448 begin
449 // already received info
450 g_Net_Penalize(C, 'client info spam');
451 Exit;
452 end;
454 Color.R := R;
455 Color.B := B;
456 Color.G := G;
458 PID := g_Player_Create(Model, Color, T, False);
459 with g_Player_Get(PID) do
460 begin
461 Name := PName;
462 WeapSwitchMode := WeapSwitch;
463 SetWeaponPrefs(TmpPrefArray);
464 SwitchToEmpty := SwitchEmpty;
465 SkipFist := SkipF;
466 Reset(True);
467 end;
469 C^.Player := PID;
470 C^.WaitForFirstSpawn := false;
471 C^.AuthTime := 0;
473 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
474 e_WriteLog('NET: Client ' + PName + ' [' + IntToStr(C^.ID) +
475 '] connected. Assigned player #' + IntToStr(PID) + '.', TMsgType.Notify);
477 MH_SEND_Info(C^.ID);
479 with g_Player_Get(PID) do
480 begin
481 Name := PName;
482 FClientID := C^.ID;
483 // round in progress, don't spawn
484 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C.ID, C.Player]);
485 //e_LogWritefln('spawning player with pid #%u...', [PID]);
486 //Respawn(gGameSettings.GameType = GT_SINGLE);
487 //k8: no, do not spawn a player yet, wait for "request full state" packet
488 Lives := 0;
489 Spectate;
490 FNoRespawn := True;
491 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
492 // that is, if we'll set it to `true`, the player can be spawned after
493 // warmup time ran out, for example, regardless of the real player state.
494 // also, this seems to work only for the initial connection. further
495 // map changes could initiate resource downloading, but the player will
496 // be spawned immediately.
497 // the proper solution will require another player state, "ephemeral".
498 // the player should start any map in "ephemeral" state, and turned into
499 // real mobj only when they sent a special "i am ready" packet. this packet
500 // must be sent after receiving the full state, so the player will get a full
501 // map view before going into game.
502 FWantsInGame := false;
503 C^.WaitForFirstSpawn := true;
504 end;
506 //if not C^.WaitForFirstSpawn then
507 begin
508 for I := Low(NetClients) to High(NetClients) do
509 begin
510 if NetClients[I].ID = C^.ID then Continue;
511 MH_SEND_PlayerCreate(PID, NetClients[I].ID);
512 MH_SEND_PlayerPos(True, PID, NetClients[I].ID);
513 MH_SEND_PlayerStats(PID, NetClients[I].ID);
514 end;
515 end;
517 if gState in [STATE_INTERCUSTOM, STATE_FOLD] then
518 MH_SEND_GameEvent(NET_EV_MAPEND, 0, 'N', C^.ID);
520 if NetUseMaster then
521 begin
522 //g_Net_Slist_Update;
523 g_Net_Slist_Pulse();
524 end;
525 end;
528 procedure MH_ProcessFirstSpawn (C: pTNetClient);
529 var
530 plr: TPlayer;
531 begin
532 if not C.WaitForFirstSpawn then exit;
533 plr := g_Player_Get(C^.Player);
534 if not assigned(plr) then exit;
535 g_Net_Slist_ServerPlayerComes();
536 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C.ID, C.Player]);
537 C.WaitForFirstSpawn := false;
538 plr.FNoRespawn := false;
539 plr.FWantsInGame := true; // TODO: look into this later
541 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
542 begin
543 plr.Spectate;
544 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN, 0, 'N', C.ID);
545 end
546 else
547 begin
548 plr.Respawn(False);
549 if gLMSRespawn > LMS_RESPAWN_NONE then
550 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime, 'N', C.ID);
551 end;
552 end;
555 procedure MH_RECV_FullStateRequest(C: pTNetClient; var M: TMsg);
556 begin
557 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
559 if C^.FullUpdateSent then
560 begin
561 // FullStateRequest spam?
562 g_Net_Penalize(C, 'duplicate full state request');
563 exit;
564 end;
566 if gGameOn then
567 begin
568 MH_SEND_Everything((C^.State = NET_STATE_AUTH), C^.ID)
569 end
570 else
571 begin
572 C^.RequestedFullUpdate := True;
573 end;
574 end;
576 // PLAYER
578 function MH_RECV_PlayerPos(C: pTNetClient; var M: TMsg): Word;
579 var
580 Dir, i: Byte;
581 WeaponAct: Byte;
582 WeaponSelect: Word;
583 PID: Word;
584 kByte: Word;
585 Pl: TPlayer;
586 GT: LongWord;
587 Err: Boolean;
588 begin
589 Result := 0;
590 Err := False;
591 if not gGameOn then Exit;
593 try
594 GT := M.ReadLongWord();
595 except
596 Err := True;
597 end;
599 if Err then begin MH_MalformedPacket(C); Exit; end;
601 PID := C^.Player;
602 Pl := g_Player_Get(PID);
603 if Pl = nil then
604 Exit;
606 if (GT > gTime + NET_MAX_DIFFTIME) or (GT < Pl.NetTime) then Exit;
608 with Pl do
609 begin
610 NetTime := GT;
611 try
612 kByte := M.ReadWord();
613 Dir := M.ReadByte();
614 WeaponAct := M.ReadByte();
615 WeaponSelect := M.ReadWord();
616 except
617 Err := True;
618 end;
620 if Err then begin MH_MalformedPacket(C); Exit; end;
622 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
623 if Direction <> TDirection(Dir) then
624 JustTeleported := False;
626 SetDirection(TDirection(Dir));
627 ReleaseKeys;
629 if kByte = NET_KEY_CHAT then
630 begin
631 PressKey(KEY_CHAT, 10000);
632 Exit;
633 end;
635 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
636 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
637 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
638 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
639 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
640 if LongBool(kByte and NET_KEY_FIRE) then PressKey(KEY_FIRE, 10000);
641 if LongBool(kByte and NET_KEY_OPEN) then PressKey(KEY_OPEN, 10000);
643 for i := 0 to 7 do
644 begin
645 if (WeaponAct and Byte(1 shl i)) <> 0 then
646 begin
647 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
648 ProcessWeaponAction(i);
649 end;
650 end;
652 for i := 0 to 15 do
653 begin
654 if (WeaponSelect and Word(1 shl i)) <> 0 then
655 begin
656 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
657 QueueWeaponSwitch(i);
658 end;
659 end;
660 end;
662 // MH_SEND_PlayerPos(False, PID, C^.ID);
663 end;
665 procedure MH_RECV_CheatRequest(C: pTNetClient; var M: TMsg);
666 var
667 CheatKind: Byte;
668 Pl: TPlayer;
669 Err: Boolean;
670 begin
671 Err := False;
672 Pl := g_Player_Get(C^.Player);
673 if Pl = nil then Exit;
675 try
676 CheatKind := M.ReadByte();
677 except
678 Err := True;
679 end;
681 if Err then begin MH_MalformedPacket(C); Exit; end;
683 case CheatKind of
684 NET_CHEAT_SUICIDE:
685 Pl.Damage(SUICIDE_DAMAGE, Pl.UID, 0, 0, HIT_SELF);
686 NET_CHEAT_SPECTATE:
687 begin
688 if Pl.FSpectator then
689 begin
690 if (gGameSettings.MaxLives = 0) or (gLMSRespawn > LMS_RESPAWN_NONE) then
691 Pl.Respawn(False)
692 else
693 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN, Pl.UID);
694 end
695 else
696 Pl.Spectate;
697 end;
698 NET_CHEAT_READY:
699 begin
700 if gState <> STATE_INTERCUSTOM then Exit;
701 Pl.FReady := not Pl.FReady;
702 if Pl.FReady then
703 begin
704 MH_SEND_GameEvent(NET_EV_INTER_READY, Pl.UID, 'Y');
705 Inc(gInterReadyCount);
706 end
707 else
708 begin
709 MH_SEND_GameEvent(NET_EV_INTER_READY, Pl.UID, 'N');
710 Dec(gInterReadyCount);
711 end;
712 end;
713 NET_CHEAT_DROPFLAG:
714 Pl.TryDropFlag();
715 end;
716 end;
718 procedure MH_RECV_PlayerSettings(C: pTNetClient; var M: TMsg);
719 var
720 TmpName: string;
721 TmpModel: string;
722 TmpColor: TRGB;
723 TmpTeam: Byte;
724 TmpWeapSwitch: Byte;
725 TmpPrefArray: Array [WP_FIRST .. WP_LAST + 1] of Byte;
726 TmpSwEmpty: Byte;
727 TmpSkipF: Byte;
728 I: Integer;
729 Pl: TPlayer;
730 Err: Boolean;
731 begin
732 Err := False;
733 try
734 TmpName := M.ReadString();
735 TmpModel := M.ReadString();
736 TmpColor.R := M.ReadByte();
737 TmpColor.G := M.ReadByte();
738 TmpColor.B := M.ReadByte();
739 TmpTeam := M.ReadByte();
740 TmpWeapSwitch := M.ReadByte();
741 for I := WP_FIRST to WP_LAST + 1 do
742 TmpPrefArray[I] := M.ReadByte();
743 TmpSwEmpty := M.ReadByte();
744 TmpSkipF := M.ReadByte();
745 except
746 Err := True;
747 end;
749 if Err then begin MH_MalformedPacket(C); Exit; end;
751 Pl := g_Player_Get(C^.Player);
752 if Pl = nil then Exit;
754 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
755 Pl.SwitchTeam
756 else
757 Pl.SetColor(TmpColor);
759 if Pl.Name <> TmpName then
760 begin
761 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
762 Pl.Name := TmpName;
763 end;
765 if TmpModel <> Pl.Model.Name then
766 Pl.SetModel(TmpModel);
768 if (TmpWeapSwitch <> Pl.WeapSwitchMode) then
769 Pl.WeapSwitchMode := TmpWeapSwitch;
771 Pl.SetWeaponPrefs(TmpPrefArray);
772 if (TmpSwEmpty <> Pl.SwitchToEmpty) then
773 Pl.SwitchToEmpty := TmpSwEmpty;
775 if (TmpSkipF <> Pl.SkipFist) then
776 Pl.SkipFist := TmpSkipF;
778 MH_SEND_PlayerSettings(Pl.UID, TmpModel);
779 end;
781 // RCON
783 procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
784 var
785 Pwd: string;
786 Err: Boolean;
787 begin
788 Err := False;
789 try
790 Pwd := M.ReadString();
791 except
792 Err := True;
793 end;
794 if Err then begin MH_MalformedPacket(C); Exit; end;
795 if not NetAllowRCON then Exit;
796 if Pwd = NetRCONPassword then
797 begin
798 C^.RCONAuth := True;
799 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWGOOD, 'N', C^.ID);
800 end
801 else
802 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWBAD, 'N', C^.ID);
803 end;
805 procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
806 var
807 Cmd: string;
808 Err: Boolean;
809 begin
810 Err := False;
811 try
812 Cmd := M.ReadString();
813 except
814 Err := True;
815 end;
816 if Err then begin MH_MalformedPacket(C); Exit; end;
817 if not NetAllowRCON then Exit;
818 if not C^.RCONAuth then
819 begin
820 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_NOAUTH, 'N', C^.ID);
821 Exit;
822 end;
823 g_Console_Process(Cmd);
824 end;
826 // MISC
828 procedure MH_RECV_Vote(C: pTNetClient; var M: TMsg);
829 var
830 Start: Boolean;
831 Name, Command: string;
832 Need: Integer;
833 Pl: TPlayer;
834 Err: Boolean;
835 begin
836 Err := False;
837 try
838 Start := M.ReadByte() <> 0;
839 Command := M.ReadString();
840 except
841 Err := True;
842 end;
844 if Err then begin MH_MalformedPacket(C); Exit; end;
846 Pl := g_Player_Get(C^.Player);
847 if Pl = nil then Exit;
848 Name := Pl.Name;
850 if Start then
851 begin
852 if not g_Console_CommandBlacklisted(Command) then
853 g_Game_StartVote(Command, Name);
854 end
855 else if gVoteInProgress then
856 begin
857 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
858 Need := Floor((NetClientCount+1)/2.0) + 1
859 else
860 Need := Floor(NetClientCount/2.0) + 1;
861 if C^.Voted then
862 begin
863 Dec(gVoteCount);
864 C^.Voted := False;
865 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [Name, gVoteCount, Need]), True);
866 MH_SEND_VoteEvent(NET_VE_REVOKE, Name, 'a', gVoteCount, Need);
867 end
868 else
869 begin
870 Inc(gVoteCount);
871 C^.Voted := True;
872 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Name, gVoteCount, Need]), True);
873 MH_SEND_VoteEvent(NET_VE_VOTE, Name, 'a', gVoteCount, Need);
874 g_Game_CheckVote;
875 end;
876 end;
877 end;
879 // GAME (SEND)
881 procedure MH_SEND_Everything(CreatePlayers: Boolean {= False}; ID: Integer {= NET_EVERYONE});
883 function sendItemRespawn (it: PItem): Boolean;
884 begin
885 result := false; // don't stop
886 MH_SEND_ItemSpawn(True, it.myid, ID);
887 end;
889 function sendMonSpawn (mon: TMonster): Boolean;
890 begin
891 result := false; // don't stop
892 MH_SEND_MonsterSpawn(mon.UID, ID);
893 end;
895 function sendPanelState (pan: TPanel): Boolean;
896 begin
897 result := false; // don't stop
898 MH_SEND_PanelState(pan.guid, ID); // anyway, to sync mplats
899 if (pan.CanChangeTexture) then MH_SEND_PanelTexture(pan.guid, pan.LastAnimLoop, ID);
900 end;
902 var
903 I: Integer;
904 begin
905 if (ID < 0) or (ID >= Length(NetClients)) then
906 exit; // bogus client, this shouldn't happen
908 NetClients[ID].FullUpdateSent := True;
910 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID, NetClients[ID].Player]);
912 MH_ProcessFirstSpawn(@NetClients[ID]);
914 if gPlayers <> nil then
915 begin
916 for I := Low(gPlayers) to High(gPlayers) do
917 begin
918 if gPlayers[I] <> nil then
919 begin
920 if CreatePlayers then MH_SEND_PlayerCreate(gPlayers[I].UID, ID);
921 MH_SEND_PlayerPos(True, gPlayers[I].UID, ID);
922 MH_SEND_PlayerStats(gPlayers[I].UID, ID);
924 if (gPlayers[I].Flag <> FLAG_NONE) and (gGameSettings.GameMode = GM_CTF) then
925 begin
926 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED, gPlayers[I].Flag, gPlayers[I].UID, True, ID);
927 end;
928 end;
929 end;
930 end;
932 g_Items_ForEachAlive(sendItemRespawn, true); // backwards
933 g_Mons_ForEach(sendMonSpawn);
934 g_Map_ForEachPanel(sendPanelState);
936 if gTriggers <> nil then
937 begin
938 for I := Low(gTriggers) to High(gTriggers) do
939 begin
940 if gTriggers[I].TriggerType = TRIGGER_SOUND then
941 begin
942 MH_SEND_TriggerSound(gTriggers[I], ID);
943 end;
944 end;
945 end;
947 if Shots <> nil then
948 begin
949 for I := Low(Shots) to High(Shots) do
950 begin
951 if Shots[i].ShotType in [6, 7, 8] then
952 begin
953 MH_SEND_CreateShot(i, ID);
954 end;
955 end;
956 end;
958 MH_SEND_TriggerMusic(ID);
960 MH_SEND_GameStats(ID);
961 MH_SEND_CoopStats(ID);
963 if gGameSettings.GameMode = GM_CTF then
964 begin
965 if gFlags[FLAG_RED].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_RED].State, FLAG_RED, 0, True, ID);
966 if gFlags[FLAG_BLUE].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_BLUE].State, FLAG_BLUE, 0, True, ID);
967 end;
969 if CreatePlayers and (ID >= 0) then NetClients[ID].State := NET_STATE_GAME;
971 g_Net_Flush();
972 end;
974 procedure MH_SEND_Info(ID: Byte);
975 begin
976 NetOut.Clear();
978 NetOut.Write(Byte(NET_MSG_INFO));
979 NetOut.Write(ID);
980 NetOut.Write(NetClients[ID].Player);
981 NetOut.Write(ExtractFileName(gGameSettings.WAD));
982 NetOut.Write(g_ExtractFileName(gMapInfo.Map));
983 NetOut.Write(gWADHash);
984 NetOut.Write(gGameSettings.GameMode);
985 NetOut.Write(gGameSettings.GoalLimit);
986 NetOut.Write(gGameSettings.TimeLimit);
987 NetOut.Write(gGameSettings.MaxLives);
988 NetOut.Write(gGameSettings.Options);
989 NetOut.Write(gTime);
991 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
992 end;
994 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
995 var
996 Name: string;
997 i: Integer;
998 Team: Byte;
999 begin
1000 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
1001 Mode := NET_CHAT_PLAYER;
1003 Team := 0;
1004 if (Mode = NET_CHAT_TEAM) then
1005 begin
1006 for i := Low(gPlayers) to High(gPlayers) do
1007 if (gPlayers[i] <> nil) and (gPlayers[i].FClientID >= 0) and
1008 (gPlayers[i].Team = ID) then
1009 begin
1010 NetOut.Write(Byte(NET_MSG_CHAT));
1011 NetOut.Write(Txt);
1012 NetOut.Write(Mode);
1013 g_Net_Host_Send(gPlayers[i].FClientID, True, NET_CHAN_CHAT);
1014 end;
1015 Team := ID;
1016 ID := NET_EVERYONE;
1017 end
1018 else
1019 begin
1020 NetOut.Write(Byte(NET_MSG_CHAT));
1021 NetOut.Write(Txt);
1022 NetOut.Write(Mode);
1023 g_Net_Host_Send(ID, True, NET_CHAN_CHAT);
1024 end;
1026 if Mode = NET_CHAT_SYSTEM then
1027 Exit;
1029 if ID = NET_EVERYONE then
1030 begin
1031 if Mode = NET_CHAT_PLAYER then
1032 begin
1033 g_Console_Add(Txt, True);
1034 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1035 g_Game_ChatSound(b_Text_Unformat(Txt));
1036 end
1037 else
1038 if Mode = NET_CHAT_TEAM then
1039 if gPlayer1 <> nil then
1040 begin
1041 if (gPlayer1.Team = TEAM_RED) and (Team = TEAM_RED) then
1042 begin
1043 g_Console_Add(#18'[Team] '#2 + Txt, True);
1044 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1045 g_Game_ChatSound(b_Text_Unformat(Txt));
1046 end
1047 else if (gPlayer1.Team = TEAM_BLUE) and (Team = TEAM_BLUE) then
1048 begin
1049 g_Console_Add(#20'[Team] '#2 + Txt, True);
1050 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1051 g_Game_ChatSound(b_Text_Unformat(Txt));
1052 end;
1053 end;
1054 end
1055 else
1056 begin
1057 Name := g_Net_ClientName_ByID(ID);
1058 g_Console_Add('-> ' + Name + ': ' + Txt, True);
1059 e_WriteLog('[Tell ' + Name + '] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1060 g_Game_ChatSound(b_Text_Unformat(Txt), False);
1061 end;
1062 end;
1064 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
1065 begin
1066 NetOut.Write(Byte(NET_MSG_GFX));
1067 NetOut.Write(Kind);
1068 NetOut.Write(X);
1069 NetOut.Write(Y);
1070 NetOut.Write(Ang);
1072 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
1073 end;
1075 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
1076 begin
1077 NetOut.Write(Byte(NET_MSG_SND));
1078 NetOut.Write(Name);
1079 if Pos then
1080 begin
1081 NetOut.Write(Byte(1));
1082 NetOut.Write(X);
1083 NetOut.Write(Y);
1084 end
1085 else
1086 NetOut.Write(Byte(0));
1088 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
1089 end;
1091 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
1092 begin
1093 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
1095 NetOut.Write(Byte(NET_MSG_SHADD));
1096 NetOut.Write(Proj);
1097 NetOut.Write(Shots[Proj].ShotType);
1098 NetOut.Write(Shots[Proj].Target);
1099 NetOut.Write(Shots[Proj].SpawnerUID);
1100 NetOut.Write(Shots[Proj].Timeout);
1101 NetOut.Write(Shots[Proj].Obj.X);
1102 NetOut.Write(Shots[Proj].Obj.Y);
1103 NetOut.Write(Shots[Proj].Obj.Vel.X);
1104 NetOut.Write(Shots[Proj].Obj.Vel.Y);
1106 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1107 end;
1109 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
1110 begin
1111 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
1113 NetOut.Write(Byte(NET_MSG_SHPOS));
1114 NetOut.Write(Proj);
1115 NetOut.Write(Shots[Proj].Obj.X);
1116 NetOut.Write(Shots[Proj].Obj.Y);
1117 NetOut.Write(Shots[Proj].Obj.Vel.X);
1118 NetOut.Write(Shots[Proj].Obj.Vel.Y);
1120 g_Net_Host_Send(ID, False, NET_CHAN_SHOTS);
1121 end;
1123 procedure MH_Send_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
1124 begin
1125 NetOut.Write(Byte(NET_MSG_SHDEL));
1126 NetOut.Write(Proj);
1127 NetOut.Write(Byte(Loud));
1128 NetOut.Write(X);
1129 NetOut.Write(Y);
1131 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1132 end;
1134 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
1135 begin
1136 NetOut.Write(Byte(NET_MSG_SCORE));
1137 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1138 begin
1139 NetOut.Write(gTeamStat[TEAM_RED].Goals);
1140 NetOut.Write(gTeamStat[TEAM_BLUE].Goals);
1141 end
1142 else
1143 if gGameSettings.GameMode = GM_COOP then
1144 begin
1145 NetOut.Write(gCoopMonstersKilled);
1146 NetOut.Write(gCoopSecretsFound);
1147 end;
1149 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1150 end;
1152 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
1153 begin
1154 NetOut.Write(Byte(NET_MSG_COOP));
1155 NetOut.Write(gTotalMonsters);
1156 NetOut.Write(gSecretsCount);
1157 NetOut.Write(gCoopTotalMonstersKilled);
1158 NetOut.Write(gCoopTotalSecretsFound);
1159 NetOut.Write(gCoopTotalMonsters);
1160 NetOut.Write(gCoopTotalSecrets);
1161 end;
1163 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
1164 begin
1165 NetOut.Write(Byte(NET_MSG_GEVENT));
1166 NetOut.Write(EvType);
1167 NetOut.Write(EvNum);
1168 NetOut.Write(EvStr);
1169 NetOut.Write(Byte(gLastMap));
1170 NetOut.Write(gTime);
1171 if (EvType = NET_EV_MAPSTART) and isWadPath(EvStr) then
1172 begin
1173 NetOut.Write(Byte(1));
1174 NetOut.Write(gWADHash);
1175 end else
1176 NetOut.Write(Byte(0));
1178 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
1179 end;
1181 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
1182 begin
1183 NetOut.Write(Byte(NET_MSG_FLAG));
1184 NetOut.Write(EvType);
1185 NetOut.Write(Flag);
1186 NetOut.Write(Byte(Quiet));
1187 NetOut.Write(PID);
1188 NetOut.Write(gFlags[Flag].State);
1189 NetOut.Write(gFlags[Flag].CaptureTime);
1190 NetOut.Write(gFlags[Flag].Obj.X);
1191 NetOut.Write(gFlags[Flag].Obj.Y);
1192 NetOut.Write(gFlags[Flag].Obj.Vel.X);
1193 NetOut.Write(gFlags[Flag].Obj.Vel.Y);
1194 NetOut.Write(Byte(gFlags[Flag].Direction));
1196 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1197 end;
1199 procedure MH_SEND_FlagPos(Flag: Byte; ID: Integer = NET_EVERYONE);
1200 begin
1201 NetOut.Write(Byte(NET_MSG_FLAGPOS));
1202 NetOut.Write(Flag);
1203 NetOut.Write(gFlags[Flag].Obj.X);
1204 NetOut.Write(gFlags[Flag].Obj.Y);
1205 NetOut.Write(gFlags[Flag].Obj.Vel.X);
1206 NetOut.Write(gFlags[Flag].Obj.Vel.Y);
1208 g_Net_Host_Send(ID, False, NET_CHAN_IMPORTANT);
1209 end;
1211 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
1212 begin
1213 NetOut.Write(Byte(NET_MSG_GSET));
1214 NetOut.Write(gGameSettings.GameMode);
1215 NetOut.Write(gGameSettings.GoalLimit);
1216 NetOut.Write(gGameSettings.TimeLimit);
1217 NetOut.Write(gGameSettings.MaxLives);
1218 NetOut.Write(gGameSettings.Options);
1220 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1221 end;
1223 // PLAYER (SEND)
1225 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
1226 var
1227 P: TPlayer;
1228 begin
1229 P := g_Player_Get(PID);
1230 if P = nil then Exit;
1232 NetOut.Write(Byte(NET_MSG_PLR));
1233 NetOut.Write(PID);
1234 NetOut.Write(P.Name);
1236 NetOut.Write(P.FActualModelName);
1237 NetOut.Write(P.FColor.R);
1238 NetOut.Write(P.FColor.G);
1239 NetOut.Write(P.FColor.B);
1240 NetOut.Write(P.Team);
1242 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT)
1243 end;
1245 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
1246 var
1247 kByte: Word;
1248 Pl: TPlayer;
1249 begin
1250 Pl := g_Player_Get(PID);
1251 if Pl = nil then Exit;
1252 if Pl.FDummy then Exit;
1254 NetOut.Write(Byte(NET_MSG_PLRPOS));
1255 NetOut.Write(gTime);
1256 NetOut.Write(PID);
1258 kByte := 0;
1260 with Pl do
1261 begin
1262 NetOut.Write(FPing);
1263 NetOut.Write(FLoss);
1264 if IsKeyPressed(KEY_CHAT) then
1265 kByte := NET_KEY_CHAT
1266 else
1267 begin
1268 if IsKeyPressed(KEY_LEFT) then kByte := kByte or NET_KEY_LEFT;
1269 if IsKeyPressed(KEY_RIGHT) then kByte := kByte or NET_KEY_RIGHT;
1270 if IsKeyPressed(KEY_UP) then kByte := kByte or NET_KEY_UP;
1271 if IsKeyPressed(KEY_DOWN) then kByte := kByte or NET_KEY_DOWN;
1272 if IsKeyPressed(KEY_JUMP) then kByte := kByte or NET_KEY_JUMP;
1273 end;
1275 if JustTeleported then kByte := kByte or NET_KEY_FORCEDIR;
1277 NetOut.Write(kByte);
1278 if Direction = TDirection.D_LEFT then NetOut.Write(Byte(0)) else NetOut.Write(Byte(1));
1279 NetOut.Write(GameX);
1280 NetOut.Write(GameY);
1281 NetOut.Write(GameVelX);
1282 NetOut.Write(GameVelY);
1283 NetOut.Write(GameAccelX);
1284 NetOut.Write(GameAccelY);
1285 end;
1287 g_Net_Host_Send(ID, Reliable, NET_CHAN_PLAYERPOS);
1288 end;
1290 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
1291 var
1292 P: TPlayer;
1293 I: Integer;
1294 begin
1295 P := g_Player_Get(PID);
1296 if P = nil then Exit;
1298 NetOut.Write(Byte(NET_MSG_PLRSTA));
1299 NetOut.Write(PID);
1301 with P do
1302 begin
1303 NetOut.Write(Byte(alive));
1304 NetOut.Write(Byte(GodMode));
1305 NetOut.Write(Health);
1306 NetOut.Write(Armor);
1307 NetOut.Write(Air);
1308 NetOut.Write(JetFuel);
1309 NetOut.Write(Lives);
1310 NetOut.Write(Team);
1312 for I := WP_FIRST to WP_LAST do
1313 NetOut.Write(Byte(FWeapon[I]));
1315 for I := A_BULLETS to A_HIGH do
1316 NetOut.Write(FAmmo[I]);
1318 for I := A_BULLETS to A_HIGH do
1319 NetOut.Write(FMaxAmmo[I]);
1321 for I := MR_SUIT to MR_MAX do
1322 NetOut.Write(LongWord(FMegaRulez[I]));
1324 NetOut.Write(Byte(R_ITEM_BACKPACK in FRulez));
1325 NetOut.Write(Byte(R_KEY_RED in FRulez));
1326 NetOut.Write(Byte(R_KEY_GREEN in FRulez));
1327 NetOut.Write(Byte(R_KEY_BLUE in FRulez));
1328 NetOut.Write(Byte(R_BERSERK in FRulez));
1330 NetOut.Write(Frags);
1331 NetOut.Write(Death);
1333 NetOut.Write(CurrWeap);
1335 NetOut.Write(Byte(FSpectator));
1336 NetOut.Write(Byte(FGhost));
1337 NetOut.Write(Byte(FPhysics));
1338 NetOut.Write(Byte(FNoRespawn));
1339 NetOut.Write(Byte(FJetpack));
1340 NetOut.Write(FFireTime);
1341 NetOut.Write(Byte(FFlaming));
1342 NetOut.Write(FSpawnInvul);
1343 end;
1345 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1346 end;
1348 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
1349 begin
1350 NetOut.Write(Byte(NET_MSG_PLRDMG));
1351 NetOut.Write(PID);
1352 NetOut.Write(Kind);
1353 NetOut.Write(Attacker);
1354 NetOut.Write(Value);
1355 NetOut.Write(VX);
1356 NetOut.Write(VY);
1358 g_Net_Host_Send(ID, False, NET_CHAN_PLAYER);
1359 end;
1361 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
1362 begin
1363 NetOut.Write(Byte(NET_MSG_PLRDIE));
1364 NetOut.Write(PID);
1365 NetOut.Write(KillType);
1366 NetOut.Write(DeathType);
1367 NetOut.Write(Attacker);
1369 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1370 end;
1372 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
1373 begin
1374 NetOut.Write(Byte(NET_MSG_PLRFIRE));
1375 NetOut.Write(PID);
1376 NetOut.Write(Weapon);
1377 NetOut.Write(X);
1378 NetOut.Write(Y);
1379 NetOut.Write(AX);
1380 NetOut.Write(AY);
1381 NetOut.Write(ShotID);
1383 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1384 end;
1386 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
1387 begin
1388 NetOut.Write(Byte(NET_MSG_PLRDEL));
1389 NetOut.Write(PID);
1391 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1392 end;
1394 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
1395 var
1396 Pl: TPlayer;
1397 begin
1398 Pl := g_Player_Get(PID);
1399 if Pl = nil then Exit;
1401 NetOut.Write(Byte(NET_MSG_PLRSET));
1402 NetOut.Write(PID);
1403 NetOut.Write(Pl.Name);
1404 if Mdl = '' then
1405 NetOut.Write(Pl.Model.Name)
1406 else
1407 NetOut.Write(Mdl);
1408 NetOut.Write(Pl.FColor.R);
1409 NetOut.Write(Pl.FColor.G);
1410 NetOut.Write(Pl.FColor.B);
1411 NetOut.Write(Pl.Team);
1413 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1414 end;
1416 // ITEM (SEND)
1418 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1419 var
1420 it: PItem;
1421 tt: Byte;
1422 begin
1423 it := g_Items_ByIdx(IID);
1425 NetOut.Write(Byte(NET_MSG_ISPAWN));
1426 NetOut.Write(IID);
1427 NetOut.Write(Byte(Quiet));
1428 tt := it.ItemType;
1429 if it.dropped then tt := tt or $80;
1430 NetOut.Write(tt);
1431 NetOut.Write(Byte(it.Fall));
1432 NetOut.Write(Byte(it.Respawnable));
1433 NetOut.Write(it.Obj.X);
1434 NetOut.Write(it.Obj.Y);
1435 NetOut.Write(it.Obj.Vel.X);
1436 NetOut.Write(it.Obj.Vel.Y);
1438 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1439 end;
1441 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1442 begin
1443 NetOut.Write(Byte(NET_MSG_IDEL));
1444 NetOut.Write(IID);
1445 NetOut.Write(Byte(Quiet));
1447 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1448 end;
1450 procedure MH_SEND_ItemPos(IID: Word; ID: Integer = NET_EVERYONE);
1451 var
1452 it: PItem;
1453 begin
1454 it := g_Items_ByIdx(IID);
1456 NetOut.Write(Byte(NET_MSG_IPOS));
1457 NetOut.Write(IID);
1458 NetOut.Write(it.Obj.X);
1459 NetOut.Write(it.Obj.Y);
1460 NetOut.Write(it.Obj.Vel.X);
1461 NetOut.Write(it.Obj.Vel.Y);
1463 g_Net_Host_Send(ID, False, NET_CHAN_LARGEDATA);
1464 end;
1466 // PANEL
1468 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
1469 var
1470 TP: TPanel;
1471 begin
1472 TP := g_Map_PanelByGUID(PGUID);
1473 if (TP = nil) then exit;
1475 with TP do
1476 begin
1477 NetOut.Write(Byte(NET_MSG_PTEX));
1478 NetOut.Write(LongWord(PGUID));
1479 NetOut.Write(FCurTexture);
1480 NetOut.Write(FCurFrame);
1481 NetOut.Write(FCurFrameCount);
1482 NetOut.Write(AnimLoop);
1483 end;
1485 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1486 end;
1488 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
1489 var
1490 TP: TPanel;
1491 mpflags: Byte = 0;
1492 begin
1493 TP := g_Map_PanelByGUID(PGUID);
1494 if (TP = nil) then exit;
1496 NetOut.Write(Byte(NET_MSG_PSTATE));
1497 NetOut.Write(LongWord(PGUID));
1498 NetOut.Write(Byte(TP.Enabled));
1499 NetOut.Write(TP.LiftType);
1500 NetOut.Write(TP.X);
1501 NetOut.Write(TP.Y);
1502 NetOut.Write(Word(TP.Width));
1503 NetOut.Write(Word(TP.Height));
1504 // mplats
1505 NetOut.Write(LongInt(TP.movingSpeedX));
1506 NetOut.Write(LongInt(TP.movingSpeedY));
1507 NetOut.Write(LongInt(TP.movingStartX));
1508 NetOut.Write(LongInt(TP.movingStartY));
1509 NetOut.Write(LongInt(TP.movingEndX));
1510 NetOut.Write(LongInt(TP.movingEndY));
1511 NetOut.Write(LongInt(TP.sizeSpeedX));
1512 NetOut.Write(LongInt(TP.sizeSpeedY));
1513 NetOut.Write(LongInt(TP.sizeEndX));
1514 NetOut.Write(LongInt(TP.sizeEndY));
1515 if TP.movingActive then mpflags := mpflags or 1;
1516 if TP.moveOnce then mpflags := mpflags or 2;
1517 NetOut.Write(Byte(mpflags));
1519 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1520 end;
1522 // TRIGGER
1524 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
1525 begin
1526 if gTriggers = nil then Exit;
1527 if T.Sound = nil then Exit;
1529 NetOut.Write(Byte(NET_MSG_TSOUND));
1530 NetOut.Write(T.ClientID);
1531 NetOut.Write(Byte(T.Sound.IsPlaying));
1532 NetOut.Write(LongWord(T.Sound.GetPosition));
1533 NetOut.Write(T.SoundPlayCount);
1535 g_Net_Host_Send(ID, True);
1536 end;
1538 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
1539 begin
1540 NetOut.Write(Byte(NET_MSG_TMUSIC));
1541 NetOut.Write(gMusic.Name);
1542 NetOut.Write(Byte(gMusic.IsPlaying));
1543 NetOut.Write(LongWord(gMusic.GetPosition));
1544 NetOut.Write(Byte(gMusic.SpecPause or gMusic.IsPaused));
1546 g_Net_Host_Send(ID, True);
1547 end;
1549 // MONSTER
1551 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
1552 var
1553 M: TMonster;
1554 begin
1555 M := g_Monsters_ByUID(UID);
1556 if M = nil then
1557 Exit;
1559 with M do
1560 begin
1561 NetOut.Write(Byte(NET_MSG_MSPAWN));
1562 NetOut.Write(UID);
1563 NetOut.Write(MonsterType);
1564 NetOut.Write(MonsterState);
1565 NetOut.Write(MonsterAnim);
1566 NetOut.Write(MonsterTargetUID);
1567 NetOut.Write(MonsterTargetTime);
1568 NetOut.Write(MonsterBehaviour);
1569 NetOut.Write(MonsterSleep);
1570 NetOut.Write(MonsterHealth);
1571 NetOut.Write(MonsterAmmo);
1572 NetOut.Write(GameX);
1573 NetOut.Write(GameY);
1574 NetOut.Write(GameVelX);
1575 NetOut.Write(GameVelY);
1576 NetOut.Write(Byte(GameDirection));
1577 end;
1579 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1580 end;
1582 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
1583 var
1584 M: TMonster;
1585 begin
1586 M := g_Monsters_ByUID(UID);
1587 if M = nil then Exit;
1589 NetOut.Write(Byte(NET_MSG_MPOS));
1590 NetOut.Write(UID);
1592 with M do
1593 begin
1594 NetOut.Write(GameX);
1595 NetOut.Write(GameY);
1596 NetOut.Write(GameVelX);
1597 NetOut.Write(GameVelY);
1598 NetOut.Write(Byte(GameDirection));
1599 end;
1601 g_Net_Host_Send(ID, False, NET_CHAN_MONSTERPOS);
1602 end;
1604 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
1605 var
1606 M: TMonster;
1607 begin
1608 M := g_Monsters_ByUID(UID);
1609 if M = nil then Exit;
1611 NetOut.Write(Byte(NET_MSG_MSTATE));
1612 NetOut.Write(UID);
1614 with M do
1615 begin
1616 NetOut.Write(MonsterState);
1617 NetOut.Write(ForcedAnim);
1618 NetOut.Write(MonsterTargetUID);
1619 NetOut.Write(MonsterTargetTime);
1620 NetOut.Write(MonsterSleep);
1621 NetOut.Write(MonsterHealth);
1622 NetOut.Write(MonsterAmmo);
1623 NetOut.Write(MonsterPain);
1624 NetOut.Write(Byte(AnimIsReverse));
1625 NetOut.Write(FFireTime);
1626 end;
1628 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1629 end;
1631 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
1632 begin
1633 NetOut.Write(Byte(NET_MSG_MSHOT));
1634 NetOut.Write(UID);
1635 NetOut.Write(X);
1636 NetOut.Write(Y);
1637 NetOut.Write(VX);
1638 NetOut.Write(VY);
1640 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1641 end;
1643 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
1644 var
1645 M: TMonster;
1646 begin
1647 M := g_Monsters_ByUID(UID);
1648 if M = nil then Exit;
1650 NetOut.Write(Byte(NET_MSG_MDEL));
1651 NetOut.Write(UID);
1653 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1654 end;
1656 // MISC
1658 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
1659 begin
1660 NetOut.Write(Byte(NET_MSG_TIME_SYNC));
1661 NetOut.Write(Time);
1663 g_Net_Host_Send(ID, False, NET_CHAN_SERVICE);
1664 end;
1666 procedure MH_SEND_VoteEvent(EvType: Byte;
1667 StrArg1: string = 'a'; StrArg2: string = 'b';
1668 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
1669 ID: Integer = NET_EVERYONE);
1670 begin
1671 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
1672 NetOut.Write(EvType);
1673 NetOut.Write(IntArg1);
1674 NetOut.Write(IntArg2);
1675 NetOut.Write(StrArg1);
1676 NetOut.Write(StrArg2);
1678 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1679 end;
1681 // CLIENT MESSAGES //
1683 // GAME
1685 procedure MC_RECV_Chat(var M: TMsg);
1686 var
1687 Txt: string;
1688 Mode: Byte;
1689 begin
1690 Txt := M.ReadString();
1691 Mode := M.ReadByte();
1693 if Mode <> NET_CHAT_SYSTEM then
1694 begin
1695 if NetDeafLevel = 0 then
1696 begin
1697 if Mode = NET_CHAT_PLAYER then
1698 begin
1699 g_Console_Add(Txt, True);
1700 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1701 g_Game_ChatSound(b_Text_Unformat(Txt));
1702 end else
1703 if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then
1704 begin
1705 if gPlayer1.Team = TEAM_RED then
1706 g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True);
1707 if gPlayer1.Team = TEAM_BLUE then
1708 g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True);
1709 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1710 g_Game_ChatSound(b_Text_Unformat(Txt));
1711 end;
1712 end;
1713 end else if (NetDeafLevel < 2) then
1714 g_Console_Add(Txt, True);
1715 end;
1717 procedure MC_RECV_Effect(var M: TMsg);
1718 var
1719 Kind: Byte;
1720 X, Y: Integer;
1721 Ang: SmallInt;
1722 Anim: TAnimation;
1723 ID: LongWord;
1724 begin
1725 if not gGameOn then Exit;
1726 Kind := M.ReadByte();
1727 X := M.ReadLongInt();
1728 Y := M.ReadLongInt();
1729 Ang := M.ReadSmallInt();
1731 case Kind of
1732 NET_GFX_SPARK:
1733 g_GFX_Spark(X, Y, 2 + Random(2), Ang, 0, 0);
1735 NET_GFX_TELE:
1736 begin
1737 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
1738 begin
1739 Anim := TAnimation.Create(ID, False, 3);
1740 g_GFX_OnceAnim(X, Y, Anim);
1741 Anim.Free();
1742 end;
1743 if Ang = 1 then
1744 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
1745 end;
1747 NET_GFX_EXPLODE:
1748 begin
1749 if g_Frames_Get(ID, 'FRAMES_EXPLODE_ROCKET') then
1750 begin
1751 Anim := TAnimation.Create(ID, False, 6);
1752 Anim.Blending := False;
1753 g_GFX_OnceAnim(X-64, Y-64, Anim);
1754 Anim.Free();
1755 end;
1756 if Ang = 1 then
1757 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X, Y);
1758 end;
1760 NET_GFX_BFGEXPL:
1761 begin
1762 if g_Frames_Get(ID, 'FRAMES_EXPLODE_BFG') then
1763 begin
1764 Anim := TAnimation.Create(ID, False, 6);
1765 Anim.Blending := False;
1766 g_GFX_OnceAnim(X-64, Y-64, Anim);
1767 Anim.Free();
1768 end;
1769 if Ang = 1 then
1770 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X, Y);
1771 end;
1773 NET_GFX_BFGHIT:
1774 begin
1775 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1776 begin
1777 Anim := TAnimation.Create(ID, False, 4);
1778 g_GFX_OnceAnim(X-32, Y-32, Anim);
1779 Anim.Free();
1780 end;
1781 end;
1783 NET_GFX_FIRE:
1784 begin
1785 if g_Frames_Get(ID, 'FRAMES_FIRE') then
1786 begin
1787 Anim := TAnimation.Create(ID, False, 4);
1788 g_GFX_OnceAnim(X, Y, Anim);
1789 Anim.Free();
1790 end;
1791 if Ang = 1 then
1792 g_Sound_PlayExAt('SOUND_FIRE', X, Y);
1793 end;
1795 NET_GFX_RESPAWN:
1796 begin
1797 if g_Frames_Get(ID, 'FRAMES_ITEM_RESPAWN') then
1798 begin
1799 Anim := TAnimation.Create(ID, False, 4);
1800 g_GFX_OnceAnim(X, Y, Anim);
1801 Anim.Free();
1802 end;
1803 if Ang = 1 then
1804 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
1805 end;
1807 NET_GFX_SHELL1:
1808 g_Player_CreateShell(X, Y, 0, -2, SHELL_BULLET);
1810 NET_GFX_SHELL2:
1811 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1813 NET_GFX_SHELL3:
1814 begin
1815 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1816 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1817 end;
1818 end;
1819 end;
1821 procedure MC_RECV_Sound(var M: TMsg);
1822 var
1823 Name: string;
1824 X, Y: Integer;
1825 Pos: Boolean;
1826 begin
1827 Name := M.ReadString();
1828 Pos := M.ReadByte() <> 0;
1829 if Pos then
1830 begin
1831 X := M.ReadLongInt();
1832 Y := M.ReadLongInt();
1833 g_Sound_PlayExAt(Name, X, Y);
1834 end
1835 else
1836 g_Sound_PlayEx(Name);
1837 end;
1839 procedure MC_RECV_CreateShot(var M: TMsg);
1840 var
1841 I, X, Y, XV, YV: Integer;
1842 Timeout: LongWord;
1843 Target, Spawner: Word;
1844 ShType: Byte;
1845 begin
1846 I := M.ReadLongInt();
1847 ShType := M.ReadByte();
1848 Target := M.ReadWord();
1849 Spawner := M.ReadWord();
1850 Timeout := M.ReadLongWord();
1851 X := M.ReadLongInt();
1852 Y := M.ReadLongInt();
1853 XV := M.ReadLongInt();
1854 YV := M.ReadLongInt();
1856 I := g_Weapon_CreateShot(I, ShType, Spawner, Target, X, Y, XV, YV);
1857 if (Shots <> nil) and (I <= High(Shots)) then
1858 begin
1859 Shots[I].Timeout := Timeout;
1860 //Shots[I].Target := Target; // TODO: find a use for Target later
1861 end;
1862 end;
1864 procedure MC_RECV_UpdateShot(var M: TMsg);
1865 var
1866 I, TX, TY, TXV, TYV: Integer;
1867 begin
1868 I := M.ReadLongInt();
1869 TX := M.ReadLongInt();
1870 TY := M.ReadLongInt();
1871 TXV := M.ReadLongInt();
1872 TYV := M.ReadLongInt();
1874 if (Shots <> nil) and (I <= High(Shots)) then
1875 with (Shots[i]) do
1876 begin
1877 Obj.X := TX;
1878 Obj.Y := TY;
1879 Obj.Vel.X := TXV;
1880 Obj.Vel.Y := TYV;
1881 end;
1882 end;
1884 procedure MC_RECV_DeleteShot(var M: TMsg);
1885 var
1886 I, X, Y: Integer;
1887 L: Boolean;
1888 begin
1889 if not gGameOn then Exit;
1890 I := M.ReadLongInt();
1891 L := (M.ReadByte() <> 0);
1892 X := M.ReadLongInt();
1893 Y := M.ReadLongInt();
1895 g_Weapon_DestroyShot(I, X, Y, L);
1896 end;
1898 procedure MC_RECV_GameStats(var M: TMsg);
1899 begin
1900 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1901 begin
1902 gTeamStat[TEAM_RED].Goals := M.ReadSmallInt();
1903 gTeamStat[TEAM_BLUE].Goals := M.ReadSmallInt();
1904 end
1905 else
1906 if gGameSettings.GameMode = GM_COOP then
1907 begin
1908 gCoopMonstersKilled := M.ReadWord();
1909 gCoopSecretsFound := M.ReadWord();
1910 end;
1911 end;
1913 procedure MC_RECV_CoopStats(var M: TMsg);
1914 begin
1915 gTotalMonsters := M.ReadLongInt();
1916 gSecretsCount := M.ReadLongInt();
1917 gCoopTotalMonstersKilled := M.ReadWord();
1918 gCoopTotalSecretsFound := M.ReadWord();
1919 gCoopTotalMonsters := M.ReadWord();
1920 gCoopTotalSecrets := M.ReadWord();
1921 end;
1923 procedure MC_RECV_GameEvent(var M: TMsg);
1924 var
1925 EvType: Byte;
1926 EvNum: Integer;
1927 EvStr: string;
1928 EvTime: LongWord;
1929 BHash: Boolean;
1930 EvHash: TMD5Digest;
1931 pl: TPlayer;
1932 i1, i2: TStrings_Locale;
1933 pln: String;
1934 cnt: Byte;
1935 goodCmd: Boolean = true;
1936 begin
1937 FillChar(EvHash, Sizeof(EvHash), 0);
1938 EvType := M.ReadByte();
1939 EvNum := M.ReadLongInt();
1940 EvStr := M.ReadString();
1941 gLastMap := M.ReadByte() <> 0;
1942 if gLastMap and (gGameSettings.GameMode = GM_COOP) then gStatsOff := True;
1943 gStatsPressed := True;
1944 EvTime := M.ReadLongWord();
1945 BHash := M.ReadByte() <> 0;
1946 if BHash then
1947 EvHash := M.ReadMD5();
1949 gTime := EvTime;
1951 if (g_Res_received_map_start <> 0) then
1952 begin
1953 if (g_Res_received_map_start < 0) then exit;
1954 goodCmd := false;
1955 case EvType of
1956 NET_EV_MAPSTART: goodCmd := true;
1957 NET_EV_MAPEND: goodCmd := true;
1958 NET_EV_PLAYER_KICK: goodCmd := true;
1959 NET_EV_PLAYER_BAN: goodCmd := true;
1960 NET_EV_LMS_WARMUP: goodCmd := true;
1961 end;
1962 if not goodCmd then exit;
1963 end;
1965 case EvType of
1966 NET_EV_MAPSTART:
1967 begin
1968 if (g_Res_received_map_start <> 0) then
1969 begin
1970 g_Res_received_map_start := -1;
1971 end
1972 else
1973 begin
1974 gGameOn := False;
1975 g_Game_ClearLoading();
1976 g_Game_StopAllSounds(True);
1978 gSwitchGameMode := Byte(EvNum);
1979 gGameSettings.GameMode := gSwitchGameMode;
1981 gWADHash := EvHash;
1982 if not g_Game_StartMap(false{asMegawad}, EvStr, True) then
1983 begin
1984 if not isWadPath(EvStr) then
1985 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + EvStr]))
1986 else
1987 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [EvStr]));
1988 Exit;
1989 end;
1991 MC_SEND_FullStateRequest;
1992 end;
1993 end;
1995 NET_EV_MAPEND:
1996 begin
1997 gLMSRespawn := LMS_RESPAWN_NONE;
1998 gLMSRespawnTime := 0;
1999 if (g_Res_received_map_start <> 0) then
2000 begin
2001 g_Res_received_map_start := -1;
2002 end
2003 else
2004 begin
2005 gMissionFailed := EvNum <> 0;
2006 gExit := EXIT_ENDLEVELCUSTOM;
2007 end;
2008 end;
2010 NET_EV_RCON:
2011 begin
2012 case EvNum of
2013 NET_RCON_NOAUTH:
2014 g_Console_Add(_lc[I_NET_RCON_NOAUTH], True);
2015 NET_RCON_PWGOOD:
2016 g_Console_Add(_lc[I_NET_RCON_PWD_VALID], True);
2017 NET_RCON_PWBAD:
2018 g_Console_Add(_lc[I_NET_RCON_PWD_INVALID], True);
2019 end;
2020 end;
2022 NET_EV_CHANGE_TEAM:
2023 begin
2024 if NetDeafLevel < 2 then
2025 begin
2026 if EvNum = TEAM_RED then
2027 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True);
2028 if EvNum = TEAM_BLUE then
2029 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True);
2030 end;
2031 end;
2033 NET_EV_PLAYER_KICK:
2034 begin
2035 g_Console_Add(Format(_lc[I_PLAYER_KICK], [EvStr]), True);
2036 if (g_Res_received_map_start <> 0) then g_Res_received_map_start := -1;
2037 end;
2039 NET_EV_PLAYER_BAN:
2040 begin
2041 g_Console_Add(Format(_lc[I_PLAYER_BAN], [EvStr]), True);
2042 if (g_Res_received_map_start <> 0) then g_Res_received_map_start := -1;
2043 end;
2045 NET_EV_LMS_WARMUP:
2046 begin
2047 if EvNum > 0 then
2048 begin
2049 gLMSRespawn := LMS_RESPAWN_WARMUP;
2050 gLMSRespawnTime := gTime + EvNum;
2051 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [EvNum div 1000]), True);
2052 end
2053 else if gPlayer1 = nil then
2054 begin
2055 g_Console_Add(_lc[I_PLAYER_SPECT4], True);
2056 end;
2057 end;
2059 NET_EV_LMS_SURVIVOR:
2060 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True);
2062 NET_EV_BIGTEXT:
2063 if NetDeafLevel < 2 then g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum));
2065 NET_EV_SCORE:
2066 begin
2067 pl := g_Player_Get(EvNum and $FFFF);
2068 if pl = nil then
2069 pln := '?'
2070 else
2071 pln := pl.Name;
2072 cnt := (EvNum shr 16) and $FF;
2073 if Pos('w', EvStr) = 0 then
2074 begin
2075 // Default score
2076 if Pos('t', EvStr) = 0 then
2077 begin
2078 // Player +/- score
2079 if Pos('-', EvStr) = 0 then
2080 begin
2081 if Pos('e', EvStr) = 0 then
2082 i1 := I_PLAYER_SCORE_ADD_OWN
2083 else
2084 i1 := I_PLAYER_SCORE_ADD_ENEMY;
2085 end else
2086 begin
2087 if Pos('e', EvStr) = 0 then
2088 i1 := I_PLAYER_SCORE_SUB_OWN
2089 else
2090 i1 := I_PLAYER_SCORE_SUB_ENEMY;
2091 end;
2092 // Which team
2093 if Pos('r', EvStr) > 0 then
2094 i2 := I_PLAYER_SCORE_TO_RED
2095 else
2096 i2 := I_PLAYER_SCORE_TO_BLUE;
2097 g_Console_Add(Format(_lc[i1], [pln, cnt, _lc[i2]]), True);
2098 end else
2099 begin
2100 // Team +/- score
2101 if Pos('-', EvStr) = 0 then
2102 i1 := I_PLAYER_SCORE_ADD_TEAM
2103 else
2104 i1 := I_PLAYER_SCORE_SUB_TEAM;
2105 // Which team
2106 if Pos('r', EvStr) > 0 then
2107 i2 := I_PLAYER_SCORE_RED
2108 else
2109 i2 := I_PLAYER_SCORE_BLUE;
2110 g_Console_Add(Format(_lc[i1], [_lc[i2], cnt]), True);
2111 end;
2112 end else
2113 begin
2114 // Game Win
2115 if Pos('e', EvStr) = 0 then
2116 i1 := I_PLAYER_SCORE_WIN_OWN
2117 else
2118 i1 := I_PLAYER_SCORE_WIN_ENEMY;
2119 // Which team
2120 if Pos('r', EvStr) > 0 then
2121 i2 := I_PLAYER_SCORE_TO_RED
2122 else
2123 i2 := I_PLAYER_SCORE_TO_BLUE;
2124 g_Console_Add(Format(_lc[i1], [pln, _lc[i2]]), True);
2125 end;
2126 end;
2128 NET_EV_SCORE_MSG:
2129 begin
2130 if EvNum = TEAM_RED then
2131 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
2132 if EvNum = TEAM_BLUE then
2133 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
2134 if EvNum = -TEAM_RED then
2135 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
2136 if EvNum = -TEAM_BLUE then
2137 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
2138 end;
2140 NET_EV_LMS_START:
2141 begin
2142 g_Player_RemoveAllCorpses;
2143 gLMSRespawn := LMS_RESPAWN_NONE;
2144 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
2145 end;
2147 NET_EV_LMS_WIN:
2148 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(EvStr)]), 144);
2150 NET_EV_TLMS_WIN:
2151 begin
2152 if EvNum = TEAM_RED then
2153 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
2154 if EvNum = TEAM_BLUE then
2155 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
2156 end;
2158 NET_EV_LMS_LOSE:
2159 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
2161 NET_EV_LMS_DRAW:
2162 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
2164 NET_EV_LMS_NOSPAWN:
2165 g_Console_Add(_lc[I_PLAYER_SPECT4], True);
2167 NET_EV_KILLCOMBO:
2168 g_Game_Announce_KillCombo(EvNum);
2170 NET_EV_PLAYER_TOUCH:
2171 begin
2172 pl := g_Player_Get(EvNum);
2173 if pl <> nil then
2174 pl.Touch();
2175 end;
2177 NET_EV_SECRET:
2178 begin
2179 pl := g_Player_Get(EvNum);
2180 if pl <> nil then
2181 begin
2182 g_Console_Add(Format(_lc[I_PLAYER_SECRET], [pl.Name]), True);
2183 g_Sound_PlayEx('SOUND_GAME_SECRET');
2184 end;
2185 end;
2187 NET_EV_INTER_READY:
2188 begin
2189 pl := g_Player_Get(EvNum);
2190 if pl <> nil then pl.FReady := (EvStr = 'Y');
2191 end;
2192 end;
2193 end;
2195 procedure MC_RECV_FlagPos(var M: TMsg);
2196 var
2197 Fl: Byte;
2198 begin
2199 Fl := M.ReadByte();
2200 if Fl = FLAG_NONE then Exit;
2201 gFlags[Fl].Obj.X := M.ReadLongInt();
2202 gFlags[Fl].Obj.Y := M.ReadLongInt();
2203 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
2204 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
2205 end;
2207 procedure MC_RECV_FlagEvent(var M: TMsg);
2208 var
2209 PID: Word;
2210 Pl: TPlayer;
2211 EvType: Byte;
2212 Fl, a: Byte;
2213 Quiet: Boolean;
2214 s, ts: string;
2215 begin
2216 EvType := M.ReadByte();
2217 Fl := M.ReadByte();
2219 if Fl = FLAG_NONE then Exit;
2221 Quiet := (M.ReadByte() <> 0);
2222 PID := M.ReadWord();
2224 gFlags[Fl].State := M.ReadByte();
2225 gFlags[Fl].CaptureTime := M.ReadLongWord();
2226 gFlags[Fl].Obj.X := M.ReadLongInt();
2227 gFlags[Fl].Obj.Y := M.ReadLongInt();
2228 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
2229 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
2230 gFlags[Fl].Direction := TDirection(M.ReadByte());
2232 Pl := g_Player_Get(PID);
2233 if (Pl = nil) and
2234 (EvType <> FLAG_STATE_NORMAL) and
2235 (EvType <> FLAG_STATE_DROPPED) and
2236 (EvType <> FLAG_STATE_RETURNED) then
2237 Exit;
2239 case EvType of
2240 FLAG_STATE_NORMAL:
2241 begin
2242 if Quiet or (Pl = nil) then Exit;
2244 if Fl = FLAG_RED then
2245 s := _lc[I_PLAYER_FLAG_RED]
2246 else
2247 s := _lc[I_PLAYER_FLAG_BLUE];
2249 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2251 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2252 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2253 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2254 a := 0
2255 else
2256 a := 1;
2258 if not sound_ret_flag[a].IsPlaying() then
2259 sound_ret_flag[a].Play();
2260 end;
2262 FLAG_STATE_CAPTURED:
2263 begin
2264 if (Pl <> nil) then Pl.SetFlag(Fl);
2266 if Quiet then Exit;
2268 if Fl = FLAG_RED then
2269 s := _lc[I_PLAYER_FLAG_RED]
2270 else
2271 s := _lc[I_PLAYER_FLAG_BLUE];
2273 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [Pl.Name, s]), True);
2274 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
2276 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2277 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2278 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2279 a := 0
2280 else
2281 a := 1;
2283 if not sound_get_flag[a].IsPlaying() then
2284 sound_get_flag[a].Play();
2285 end;
2287 FLAG_STATE_DROPPED:
2288 begin
2289 if (Pl <> nil) then Pl.SetFlag(FLAG_NONE);
2291 if Quiet or (Pl = nil) then Exit;
2293 if Fl = FLAG_RED then
2294 s := _lc[I_PLAYER_FLAG_RED]
2295 else
2296 s := _lc[I_PLAYER_FLAG_BLUE];
2298 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [Pl.Name, s]), True);
2299 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
2301 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2302 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2303 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2304 a := 0
2305 else
2306 a := 1;
2308 if not sound_lost_flag[a].IsPlaying() then
2309 sound_lost_flag[a].Play();
2310 end;
2312 FLAG_STATE_SCORED:
2313 begin
2314 g_Map_ResetFlag(FLAG_RED);
2315 g_Map_ResetFlag(FLAG_BLUE);
2316 if Quiet or (Pl = nil) then Exit;
2317 Pl.SetFlag(FLAG_NONE);
2319 if Fl = FLAG_RED then
2320 s := _lc[I_PLAYER_FLAG_RED]
2321 else
2322 s := _lc[I_PLAYER_FLAG_BLUE];
2324 ts := Format('%.4d', [gFlags[Fl].CaptureTime]);
2325 Insert('.', ts, Length(ts) + 1 - 3);
2326 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [Pl.Name, s, ts]), True);
2327 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
2329 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2330 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2331 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2332 a := 0
2333 else
2334 a := 1;
2336 if not sound_cap_flag[a].IsPlaying() then
2337 sound_cap_flag[a].Play();
2338 end;
2340 FLAG_STATE_RETURNED:
2341 begin
2342 g_Map_ResetFlag(Fl);
2343 if Quiet then Exit;
2345 if Fl = FLAG_RED then
2346 s := _lc[I_PLAYER_FLAG_RED]
2347 else
2348 s := _lc[I_PLAYER_FLAG_BLUE];
2350 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2352 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2353 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2354 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2355 a := 0
2356 else
2357 a := 1;
2359 if not sound_ret_flag[a].IsPlaying() then
2360 sound_ret_flag[a].Play();
2361 end;
2362 end;
2363 end;
2365 procedure MC_RECV_GameSettings(var M: TMsg);
2366 begin
2367 gGameSettings.GameMode := M.ReadByte();
2368 gGameSettings.GoalLimit := M.ReadWord();
2369 gGameSettings.TimeLimit := M.ReadWord();
2370 gGameSettings.MaxLives := M.ReadByte();
2371 gGameSettings.Options := M.ReadLongWord();
2372 end;
2374 // PLAYER
2376 function MC_RECV_PlayerCreate(var M: TMsg): Word;
2377 var
2378 PID, DID: Word;
2379 PName, Model: string;
2380 Color: TRGB;
2381 T: Byte;
2382 Pl: TPlayer;
2383 begin
2384 PID := M.ReadWord();
2385 Pl := g_Player_Get(PID);
2387 PName := M.ReadString();
2388 Model := M.ReadString();
2389 Color.R := M.ReadByte();
2390 Color.G := M.ReadByte();
2391 Color.B := M.ReadByte();
2392 T := M.ReadByte();
2394 Result := 0;
2395 if (PID <> NetPlrUID1) and (PID <> NetPlrUID2) then
2396 begin
2397 if (Pl <> nil) then Exit;
2398 DID := g_Player_Create(Model, Color, T, False);
2399 with g_Player_Get(DID) do
2400 begin
2401 UID := PID;
2402 Name := PName;
2403 Reset(True);
2404 end;
2405 end
2406 else
2407 begin
2408 if (PID = NetPlrUID1) and (gPlayer1 <> nil) then begin
2409 gPlayer1.UID := PID;
2410 gPlayer1.Model.SetColor(Color.R, Color.G, Color.B);
2411 gPlayer1.ChangeTeam(T);
2412 end;
2413 if (PID = NetPlrUID2) and (gPlayer2 <> nil) then begin
2414 gPlayer2.UID := PID;
2415 gPlayer2.Model.SetColor(Color.R, Color.G, Color.B);
2416 gPlayer2.ChangeTeam(T);
2417 end;
2418 end;
2420 if NetDeafLevel < 3 then
2421 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
2422 e_WriteLog('NET: Player ' + PName + ' [' + IntToStr(PID) + '] added.', TMsgType.Notify);
2423 Result := PID;
2424 end;
2426 function MC_RECV_PlayerPos(var M: TMsg): Word;
2427 var
2428 GT: LongWord;
2429 PID: Word;
2430 kByte: Word;
2431 Pl: TPlayer;
2432 Dir: Byte;
2433 TmpX, TmpY: Integer;
2434 begin
2435 Result := 0;
2437 GT := M.ReadLongWord();
2438 if GT < gTime - NET_MAX_DIFFTIME then
2439 begin
2440 gTime := GT;
2441 Exit;
2442 end;
2443 gTime := GT;
2445 PID := M.ReadWord();
2446 Pl := g_Player_Get(PID);
2448 if Pl = nil then Exit;
2450 Result := PID;
2452 with Pl do
2453 begin
2454 FPing := M.ReadWord();
2455 FLoss := M.ReadByte();
2456 kByte := M.ReadWord();
2457 Dir := M.ReadByte();
2459 TmpX := M.ReadLongInt();
2460 TmpY := M.ReadLongInt();
2462 ReleaseKeys;
2464 if LongBool(kByte and NET_KEY_CHAT) then
2465 PressKey(KEY_CHAT, 10000)
2466 else
2467 begin
2468 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
2469 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
2470 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
2471 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
2472 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
2473 end;
2475 JustTeleported := LongBool(kByte and NET_KEY_FORCEDIR);
2477 if ((Pl <> gPlayer1) and (Pl <> gPlayer2)) or JustTeleported then
2478 SetDirection(TDirection(Dir));
2480 GameVelX := M.ReadLongInt();
2481 GameVelY := M.ReadLongInt();
2482 GameAccelX := M.ReadLongInt();
2483 GameAccelY := M.ReadLongInt();
2484 SetLerp(TmpX, TmpY);
2485 if NetForcePlayerUpdate then Update();
2486 end;
2487 end;
2489 function MC_RECV_PlayerStats(var M: TMsg): Word;
2490 var
2491 PID: Word;
2492 Pl: TPlayer;
2493 I, OldFire: Integer;
2494 OldJet, Flam: Boolean;
2495 NewTeam: Byte;
2496 begin
2497 PID := M.ReadWord();
2498 Pl := g_Player_Get(PID);
2499 Result := 0;
2500 if Pl = nil then
2501 Exit;
2503 with Pl do
2504 begin
2505 alive := (M.ReadByte() <> 0);
2506 GodMode := (M.ReadByte() <> 0);
2507 Health := M.ReadLongInt();
2508 Armor := M.ReadLongInt();
2509 Air := M.ReadLongInt();
2510 JetFuel := M.ReadLongInt();
2511 Lives := M.ReadByte();
2512 NewTeam := M.ReadByte();
2514 for I := WP_FIRST to WP_LAST do
2515 FWeapon[I] := (M.ReadByte() <> 0);
2517 for I := A_BULLETS to A_HIGH do
2518 FAmmo[I] := M.ReadWord();
2520 for I := A_BULLETS to A_HIGH do
2521 FMaxAmmo[I] := M.ReadWord();
2523 for I := MR_SUIT to MR_MAX do
2524 FMegaRulez[I] := M.ReadLongWord();
2526 FRulez := [];
2527 if (M.ReadByte() <> 0) then
2528 FRulez := FRulez + [R_ITEM_BACKPACK];
2529 if (M.ReadByte() <> 0) then
2530 FRulez := FRulez + [R_KEY_RED];
2531 if (M.ReadByte() <> 0) then
2532 FRulez := FRulez + [R_KEY_GREEN];
2533 if (M.ReadByte() <> 0) then
2534 FRulez := FRulez + [R_KEY_BLUE];
2535 if (M.ReadByte() <> 0) then
2536 FRulez := FRulez + [R_BERSERK];
2538 Frags := M.ReadLongInt();
2539 Death := M.ReadLongInt();
2541 SetWeapon(M.ReadByte());
2543 FSpectator := M.ReadByte() <> 0;
2544 if FSpectator then
2545 begin
2546 if UID = NetPlrUID1 then
2547 begin
2548 gSpectLatchPID1 := UID;
2549 gPlayer1 := nil;
2550 end;
2551 if UID = NetPlrUID2 then
2552 begin
2553 gSpectLatchPID2 := UID;
2554 gPlayer2 := nil;
2555 end;
2556 end
2557 else
2558 begin
2559 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) and (UID = gSpectLatchPID1) then
2560 begin
2561 gPlayer1 := Pl;
2562 gSpectLatchPID1 := 0;
2563 end;
2564 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) and (UID = gSpectLatchPID2) then
2565 begin
2566 gPlayer2 := Pl;
2567 gSpectLatchPID2 := 0;
2568 end;
2569 end;
2570 FGhost := M.ReadByte() <> 0;
2571 FPhysics := M.ReadByte() <> 0;
2572 FNoRespawn := M.ReadByte() <> 0;
2573 OldJet := FJetpack;
2574 FJetpack := M.ReadByte() <> 0;
2575 OldFire := FFireTime;
2576 FFireTime := M.ReadLongInt();
2577 if (OldFire <= 0) and (FFireTime > 0) then
2578 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
2579 Flam := M.ReadByte() <> 0;
2580 FSpawnInvul := M.ReadLongInt();
2581 if OldJet and not FJetpack then
2582 JetpackOff
2583 else if not OldJet and FJetpack then
2584 JetpackOn;
2585 if FFlaming and not Flam then
2586 FlamerOff;
2587 if Team <> NewTeam then
2588 Pl.ChangeTeam(NewTeam);
2589 end;
2591 Result := PID;
2592 end;
2594 function MC_RECV_PlayerDamage(var M: TMsg): Word;
2595 var
2596 PID: Word;
2597 Pl: TPlayer;
2598 Kind: Byte;
2599 Attacker, Value: Word;
2600 VX, VY: Integer;
2601 begin
2602 Result := 0;
2603 if not gGameOn then Exit;
2604 PID := M.ReadWord();
2605 Pl := g_Player_Get(PID);
2606 if Pl = nil then Exit;
2608 Kind := M.ReadByte();
2609 Attacker := M.ReadWord();
2610 Value := M.ReadWord();
2611 VX := M.ReadWord();
2612 VY := M.ReadWord();
2614 with Pl do
2615 Damage(Value, Attacker, VX, VY, Kind);
2617 Result := PID;
2618 end;
2620 function MC_RECV_PlayerDeath(var M: TMsg): Word;
2621 var
2622 PID: Word;
2623 Pl: TPlayer;
2624 KillType, DeathType: Byte;
2625 Attacker: Word;
2626 begin
2627 Result := 0;
2628 if not gGameOn then Exit;
2629 PID := M.ReadWord();
2630 Pl := g_Player_Get(PID);
2631 if Pl = nil then Exit;
2633 KillType := M.ReadByte();
2634 DeathType := M.ReadByte();
2635 Attacker := M.ReadWord();
2637 with Pl do
2638 begin
2639 Kill(KillType, Attacker, DeathType);
2640 SoftReset;
2641 end;
2642 end;
2644 function MC_RECV_PlayerDelete(var M: TMsg): Word;
2645 var
2646 PID: Word;
2647 Pl: TPlayer;
2648 begin
2649 PID := M.ReadWord();
2650 Pl := g_Player_Get(PID);
2651 Result := 0;
2652 if Pl = nil then Exit;
2654 if NetDeafLevel < 3 then
2655 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2656 e_WriteLog('NET: Player ' + Pl.Name + ' [' + IntToStr(PID) + '] removed.', TMsgType.Notify);
2658 g_Player_Remove(PID);
2660 Result := PID;
2661 end;
2663 function MC_RECV_PlayerFire(var M: TMsg): Word;
2664 var
2665 PID: Word;
2666 Weap: Byte;
2667 Pl: TPlayer;
2668 X, Y, AX, AY: Integer;
2669 SHID: Integer;
2670 begin
2671 Result := 0;
2672 if not gGameOn then Exit;
2673 PID := M.ReadWord();
2674 Pl := g_Player_Get(PID);
2675 if Pl = nil then Exit;
2677 Weap := M.ReadByte();
2678 X := M.ReadLongInt();
2679 Y := M.ReadLongInt();
2680 AX := M.ReadLongInt();
2681 AY := M.ReadLongInt();
2682 SHID := M.ReadLongInt();
2684 with Pl do
2685 if alive then NetFire(Weap, X, Y, AX, AY, SHID);
2686 end;
2688 procedure MC_RECV_PlayerSettings(var M: TMsg);
2689 var
2690 TmpName: string;
2691 TmpModel: string;
2692 TmpColor: TRGB;
2693 TmpTeam: Byte;
2694 Pl: TPlayer;
2695 PID: Word;
2696 begin
2697 PID := M.ReadWord();
2698 Pl := g_Player_Get(PID);
2699 if Pl = nil then Exit;
2701 TmpName := M.ReadString();
2702 TmpModel := M.ReadString();
2703 TmpColor.R := M.ReadByte();
2704 TmpColor.G := M.ReadByte();
2705 TmpColor.B := M.ReadByte();
2706 TmpTeam := M.ReadByte();
2708 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
2709 begin
2710 Pl.ChangeTeam(TmpTeam);
2711 if gPlayer1 = Pl then
2712 gPlayer1Settings.Team := TmpTeam;
2713 if gPlayer2 = Pl then
2714 gPlayer2Settings.Team := TmpTeam;
2715 end else
2716 Pl.SetColor(TmpColor);
2718 if Pl.Name <> TmpName then
2719 begin
2720 if NetDeafLevel < 3 then
2721 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
2722 Pl.Name := TmpName;
2723 end;
2725 if TmpModel <> Pl.Model.Name then
2726 Pl.SetModel(TmpModel);
2727 end;
2729 // ITEM
2731 procedure MC_RECV_ItemSpawn(var M: TMsg);
2732 var
2733 ID: Word;
2734 AID: DWord;
2735 X, Y, VX, VY: Integer;
2736 T: Byte;
2737 Quiet, Fall{, Resp}: Boolean;
2738 Anim: TAnimation;
2739 it: PItem;
2740 begin
2741 if not gGameOn then Exit;
2742 ID := M.ReadWord();
2743 Quiet := M.ReadByte() <> 0;
2744 T := M.ReadByte();
2745 Fall := M.ReadByte() <> 0;
2746 {Resp :=} M.ReadByte();
2747 X := M.ReadLongInt();
2748 Y := M.ReadLongInt();
2749 VX := M.ReadLongInt();
2750 VY := M.ReadLongInt();
2752 g_Items_Create(X, Y, T and $7F, Fall, False, False, ID);
2753 if ((T and $80) <> 0) then g_Items_SetDrop(ID);
2755 it := g_Items_ByIdx(ID);
2756 it.Obj.Vel.X := VX;
2757 it.Obj.Vel.Y := VY;
2759 if not Quiet then
2760 begin
2761 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
2762 if g_Frames_Get(AID, 'FRAMES_ITEM_RESPAWN') then
2763 begin
2764 Anim := TAnimation.Create(AID, False, 4);
2765 g_GFX_OnceAnim(X+(it.Obj.Rect.Width div 2)-16, Y+(it.Obj.Rect.Height div 2)-16, Anim);
2766 Anim.Free();
2767 end;
2768 end;
2769 end;
2771 procedure MC_RECV_ItemDestroy(var M: TMsg);
2772 var
2773 ID: Word;
2774 Quiet: Boolean;
2775 begin
2776 if not gGameOn then Exit;
2777 ID := M.ReadWord();
2778 Quiet := M.ReadByte() <> 0;
2780 if not g_Items_ValidId(ID) then exit;
2782 if not Quiet then g_Items_EmitPickupSound(ID);
2784 g_Items_Remove(ID);
2785 end;
2787 procedure MC_RECV_ItemPos(var M: TMsg);
2788 var
2789 ID: Word;
2790 X, Y, VX, VY: Integer;
2791 it: PItem;
2792 begin
2793 if not gGameOn then Exit;
2795 ID := M.ReadWord();
2796 X := M.ReadLongInt();
2797 Y := M.ReadLongInt();
2798 VX := M.ReadLongInt();
2799 VY := M.ReadLongInt();
2801 if g_Items_ValidId(ID) then
2802 begin
2803 it := g_Items_ByIdx(ID);
2804 it.Obj.X := X;
2805 it.Obj.Y := Y;
2806 it.Obj.Vel.X := VX;
2807 it.Obj.Vel.Y := VY;
2808 it.positionChanged();
2809 end;
2810 end;
2812 // PANEL
2814 procedure MC_RECV_PanelTexture(var M: TMsg);
2815 var
2816 TP: TPanel;
2817 PGUID: Integer;
2818 Tex, Fr: Integer;
2819 Loop, Cnt: Byte;
2820 begin
2821 if not gGameOn then Exit;
2823 PGUID := Integer(M.ReadLongWord());
2824 Tex := M.ReadLongInt();
2825 Fr := M.ReadLongInt();
2826 Cnt := M.ReadByte();
2827 Loop := M.ReadByte();
2829 TP := g_Map_PanelByGUID(PGUID);
2830 if (TP <> nil) then
2831 begin
2832 // switch texture
2833 TP.SetTexture(Tex, Loop);
2834 TP.SetFrame(Fr, Cnt);
2835 end;
2836 end;
2838 procedure MC_RECV_PanelState(var M: TMsg);
2839 var
2840 PGUID: Integer;
2841 E: Boolean;
2842 Lift: Byte;
2843 X, Y, W, H: Integer;
2844 TP: TPanel;
2845 speedX, speedY, startX, startY, endX, endY: Integer;
2846 sizeSpX, sizeSpY, sizeEX, sizeEY: Integer;
2847 mpflags: Byte;
2848 begin
2849 if not gGameOn then Exit;
2851 PGUID := Integer(M.ReadLongWord());
2852 E := (M.ReadByte() <> 0);
2853 Lift := M.ReadByte();
2854 X := M.ReadLongInt();
2855 Y := M.ReadLongInt();
2856 W := M.ReadWord();
2857 H := M.ReadWord();
2858 // mplats
2859 speedX := M.ReadLongInt();
2860 speedY := M.ReadLongInt();
2861 startX := M.ReadLongInt();
2862 startY := M.ReadLongInt();
2863 endX := M.ReadLongInt();
2864 endY := M.ReadLongInt();
2865 sizeSpX := M.ReadLongInt();
2866 sizeSpY := M.ReadLongInt();
2867 sizeEX := M.ReadLongInt();
2868 sizeEY := M.ReadLongInt();
2869 mpflags := M.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2871 TP := g_Map_PanelByGUID(PGUID);
2872 if (TP = nil) then exit;
2874 // update lifts state
2875 if TP.isGLift then g_Map_SetLiftGUID(PGUID, Lift);
2877 // update enabled/disabled state for all panels
2878 if E then g_Map_EnableWallGUID(PGUID) else g_Map_DisableWallGUID(PGUID);
2880 // update panel position, as it can be moved (mplat)
2881 TP.X := X;
2882 TP.Y := Y;
2883 TP.Width := W;
2884 TP.Height := H;
2885 // update mplat state
2886 TP.movingSpeedX := speedX;
2887 TP.movingSpeedY := speedY;
2888 TP.movingStartX := startX;
2889 TP.movingStartY := startY;
2890 TP.movingEndX := endX;
2891 TP.movingEndY := endY;
2892 TP.sizeSpeedX := sizeSpX;
2893 TP.sizeSpeedY := sizeSpY;
2894 TP.sizeEndX := sizeEX;
2895 TP.sizeEndY := sizeEY;
2896 TP.movingActive := ((mpflags and 1) <> 0);
2897 TP.moveOnce := ((mpflags and 2) <> 0);
2898 // notify panel of it's position/size change, so it can fix other internal structures
2899 TP.positionChanged();
2900 end;
2902 // TRIGGERS
2904 procedure MC_RECV_TriggerSound(var M: TMsg);
2905 var
2906 SPlaying: Boolean;
2907 SPos, SID: LongWord;
2908 SCount: LongInt;
2909 I: Integer;
2910 begin
2911 if not gGameOn then Exit;
2912 if gTriggers = nil then Exit;
2914 SID := M.ReadLongWord();
2915 SPlaying := M.ReadByte() <> 0;
2916 SPos := M.ReadLongWord();
2917 SCount := M.ReadLongInt();
2919 for I := Low(gTriggers) to High(gTriggers) do
2920 if gTriggers[I].TriggerType = TRIGGER_SOUND then
2921 if gTriggers[I].ClientID = SID then
2922 with gTriggers[I] do
2923 begin
2924 if Sound <> nil then
2925 begin
2926 if SPlaying then
2927 begin
2928 if tgcLocal then
2929 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), tgcVolume/255.0)
2930 else
2931 Sound.PlayPanVolume((tgcPan-127.0)/128.0, tgcVolume/255.0);
2932 Sound.SetPosition(SPos);
2933 end
2934 else
2935 if Sound.IsPlaying then Sound.Stop;
2936 end;
2938 SoundPlayCount := SCount;
2939 end;
2940 end;
2942 procedure MC_RECV_TriggerMusic(var M: TMsg);
2943 var
2944 MName: string;
2945 MPlaying: Boolean;
2946 MPos: LongWord;
2947 MPaused: Boolean;
2948 begin
2949 if not gGameOn then Exit;
2951 MName := M.ReadString();
2952 MPlaying := M.ReadByte() <> 0;
2953 MPos := M.ReadLongWord();
2954 MPaused := M.ReadByte() <> 0;
2955 MPos := MPos+1; //k8: stfu, fpc!
2957 if MPlaying then
2958 begin
2959 gMusic.SetByName(MName);
2960 gMusic.Play(True);
2961 // gMusic.SetPosition(MPos);
2962 gMusic.SpecPause := MPaused;
2963 end
2964 else
2965 if gMusic.IsPlaying then gMusic.Stop;
2966 end;
2968 // MONSTERS
2970 procedure MC_RECV_MonsterSpawn(var M: TMsg);
2971 var
2972 ID: Word;
2973 MType, MState, MDir, MAnim, MBehav: Byte;
2974 X, Y, VX, VY, MTargTime, MHealth, MAmmo, MSleep: Integer;
2975 MTarg: Word;
2976 Mon: TMonster;
2977 begin
2978 ID := M.ReadWord();
2979 Mon := g_Monsters_ByUID(ID);
2980 if Mon <> nil then
2981 Exit;
2983 MType := M.ReadByte();
2984 MState := M.ReadByte();
2985 MAnim := M.ReadByte();
2986 MTarg := M.ReadWord();
2987 MTargTime := M.ReadLongInt();
2988 MBehav := M.ReadByte();
2989 MSleep := M.ReadLongInt();
2990 MHealth := M.ReadLongInt();
2991 MAmmo := M.ReadLongInt();
2993 X := M.ReadLongInt();
2994 Y := M.ReadLongInt();
2995 VX := M.ReadLongInt();
2996 VY := M.ReadLongInt();
2997 MDir := M.ReadByte();
2999 g_Monsters_Create(MType, X, Y, TDirection(MDir), False, ID);
3000 Mon := g_Monsters_ByUID(ID);
3001 if Mon = nil then
3002 Exit;
3004 with Mon do
3005 begin
3007 MonsterAnim := MAnim;
3008 MonsterTargetUID := MTarg;
3009 MonsterTargetTime := MTargTime;
3010 MonsterBehaviour := MBehav;
3011 MonsterSleep := MSleep;
3012 MonsterAmmo := MAmmo;
3013 SetHealth(MHealth);
3015 SetState(MState);
3017 setPosition(X, Y); // this will call positionChanged();
3018 GameVelX := VX;
3019 GameVelY := VY;
3020 end;
3021 end;
3023 procedure MC_RECV_MonsterPos(var M: TMsg);
3024 var
3025 Mon: TMonster;
3026 ID: Word;
3027 X, Y: Integer;
3028 begin
3029 ID := M.ReadWord();
3030 Mon := g_Monsters_ByUID(ID);
3031 if Mon = nil then
3032 Exit;
3034 with Mon do
3035 begin
3036 X := M.ReadLongInt();
3037 Y := M.ReadLongInt();
3038 Mon.setPosition(X, Y); // this will call `positionChanged()`
3039 GameVelX := M.ReadLongInt();
3040 GameVelY := M.ReadLongInt();
3041 GameDirection := TDirection(M.ReadByte());
3042 end;
3043 end;
3045 procedure MC_RECV_MonsterState(var M: TMsg);
3046 var
3047 ID, OldFire: Integer;
3048 MState, MFAnm: Byte;
3049 Mon: TMonster;
3050 AnimRevert: Boolean;
3051 begin
3052 ID := M.ReadWord();
3053 Mon := g_Monsters_ByUID(ID);
3054 if Mon = nil then Exit;
3056 MState := M.ReadByte();
3057 MFAnm := M.ReadByte();
3059 with Mon do
3060 begin
3061 MonsterTargetUID := M.ReadWord();
3062 MonsterTargetTime := M.ReadLongInt();
3063 MonsterSleep := M.ReadLongInt();
3064 MonsterHealth := M.ReadLongInt();
3065 MonsterAmmo := M.ReadLongInt();
3066 MonsterPain := M.ReadLongInt();
3067 AnimRevert := M.ReadByte() <> 0;
3068 OldFire := FFireTime;
3069 FFireTime := M.ReadLongInt();
3070 if (OldFire <= 0) and (FFireTime > 0) then
3071 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
3072 RevertAnim(AnimRevert);
3074 if MonsterState <> MState then
3075 begin
3076 if (MState = MONSTATE_GO) and (MonsterState = MONSTATE_SLEEP) then WakeUpSound();
3077 if (MState = MONSTATE_DIE) then DieSound();
3078 if (MState = MONSTATE_PAIN) then MakeBloodSimple(Min(200, MonsterPain));
3079 if (MState = MONSTATE_ATTACK) then kick(nil);
3080 if (MState = MONSTATE_DEAD) then SetDeadAnim();
3082 SetState(MState, MFAnm);
3083 end;
3084 end;
3085 end;
3087 procedure MC_RECV_MonsterShot(var M: TMsg);
3088 var
3089 ID: Integer;
3090 Mon: TMonster;
3091 X, Y, VX, VY: Integer;
3092 begin
3093 ID := M.ReadWord();
3095 Mon := g_Monsters_ByUID(ID);
3096 if Mon = nil then Exit;
3098 X := M.ReadLongInt();
3099 Y := M.ReadLongInt();
3100 VX := M.ReadLongInt();
3101 VY := M.ReadLongInt();
3103 Mon.ClientAttack(X, Y, VX, VY);
3104 end;
3106 procedure MC_RECV_MonsterDelete(var M: TMsg);
3107 var
3108 ID: Integer;
3109 Mon: TMonster;
3110 begin
3111 ID := M.ReadWord();
3112 Mon := g_Monsters_ByUID(ID);
3113 if Mon = nil then Exit;
3114 Mon.SetState(5);
3115 Mon.MonsterRemoved := True;
3116 end;
3118 procedure MC_RECV_TimeSync(var M: TMsg);
3119 var
3120 Time: LongWord;
3121 begin
3122 Time := M.ReadLongWord();
3124 if gState = STATE_INTERCUSTOM then
3125 gServInterTime := Min(Time, 255);
3126 end;
3128 procedure MC_RECV_VoteEvent(var M: TMsg);
3129 var
3130 EvID: Byte;
3131 Str1, Str2: string;
3132 Int1, Int2: SmallInt;
3133 begin
3134 EvID := M.ReadByte();
3135 Int1 := M.ReadSmallInt();
3136 Int2 := M.ReadSmallInt();
3137 Str1 := M.ReadString();
3138 Str2 := M.ReadString();
3140 if NetDeafLevel < 2 then
3141 case EvID of
3142 NET_VE_STARTED:
3143 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True);
3144 NET_VE_PASSED:
3145 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True);
3146 NET_VE_FAILED:
3147 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
3148 NET_VE_VOTE:
3149 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True);
3150 NET_VE_INPROGRESS:
3151 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True);
3152 end;
3153 end;
3155 // CLIENT SEND
3157 procedure MC_SEND_Info(Password: string);
3158 var i: Integer;
3159 begin
3160 NetOut.Clear();
3162 NetOut.Write(Byte(NET_MSG_INFO));
3163 NetOut.Write(GAME_VERSION);
3164 NetOut.Write(Password);
3165 NetOut.Write(gPlayer1Settings.Name);
3166 NetOut.Write(gPlayer1Settings.Model);
3167 NetOut.Write(gPlayer1Settings.Color.R);
3168 NetOut.Write(gPlayer1Settings.Color.G);
3169 NetOut.Write(gPlayer1Settings.Color.B);
3170 NetOut.Write(gPlayer1Settings.Team);
3171 NetOut.Write(gPlayer1Settings.WeaponSwitch);
3172 for i := WP_FIRST to WP_LAST + 1 do
3173 NetOut.Write(gPlayer1Settings.WeaponPreferences[i]);
3174 NetOut.Write(gPlayer1Settings.SwitchToEmpty);
3175 NetOut.Write(gPlayer1Settings.SkipFist);
3177 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3178 end;
3180 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
3181 begin
3182 NetOut.Write(Byte(NET_MSG_CHAT));
3183 NetOut.Write(Txt);
3184 NetOut.Write(Mode);
3186 g_Net_Client_Send(True, NET_CHAN_CHAT);
3187 end;
3189 procedure MC_SEND_PlayerPos();
3190 var
3191 kByte: Word;
3192 Predict: Boolean;
3193 strafeDir: Byte;
3194 WeaponAct: Byte = 0;
3195 WeaponSelect: Word = 0;
3196 i: Integer;
3197 begin
3198 if not gGameOn then Exit;
3199 if gPlayers = nil then Exit;
3200 if gPlayer1 = nil then Exit;
3202 kByte := 0;
3203 Predict := NetPredictSelf; // and (not NetGotKeys);
3205 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
3206 begin
3207 strafeDir := P1MoveButton shr 4;
3208 P1MoveButton := P1MoveButton and $0F;
3210 if gPlayerAction[0, ACTION_MOVELEFT] and (not gPlayerAction[0, ACTION_MOVERIGHT]) then
3211 P1MoveButton := 1
3212 else if (not gPlayerAction[0, ACTION_MOVELEFT]) and gPlayerAction[0, ACTION_MOVERIGHT] then
3213 P1MoveButton := 2
3214 else if (not gPlayerAction[0, ACTION_MOVELEFT]) and (not gPlayerAction[0, ACTION_MOVERIGHT]) then
3215 P1MoveButton := 0;
3217 // strafing
3218 if gPlayerAction[0, ACTION_STRAFE] then
3219 begin
3220 // new strafe mechanics
3221 if (strafeDir = 0) then
3222 strafeDir := P1MoveButton; // start strafing
3223 // now set direction according to strafe (reversed)
3224 if (strafeDir = 2) then
3225 gPlayer1.SetDirection(TDirection.D_LEFT)
3226 else if (strafeDir = 1) then
3227 gPlayer1.SetDirection(TDirection.D_RIGHT)
3228 end
3229 else
3230 begin
3231 strafeDir := 0; // not strafing anymore
3232 if (P1MoveButton = 2) and gPlayerAction[0, ACTION_MOVELEFT] then
3233 gPlayer1.SetDirection(TDirection.D_LEFT)
3234 else if (P1MoveButton = 1) and gPlayerAction[0, ACTION_MOVERIGHT] then
3235 gPlayer1.SetDirection(TDirection.D_RIGHT)
3236 else if P1MoveButton <> 0 then
3237 gPlayer1.SetDirection(TDirection(P1MoveButton-1));
3238 end;
3240 gPlayer1.ReleaseKeys;
3241 if P1MoveButton = 1 then
3242 begin
3243 kByte := kByte or NET_KEY_LEFT;
3244 if Predict then gPlayer1.PressKey(KEY_LEFT, 10000);
3245 end;
3246 if P1MoveButton = 2 then
3247 begin
3248 kByte := kByte or NET_KEY_RIGHT;
3249 if Predict then gPlayer1.PressKey(KEY_RIGHT, 10000);
3250 end;
3251 if gPlayerAction[0, ACTION_LOOKUP] then
3252 begin
3253 kByte := kByte or NET_KEY_UP;
3254 gPlayer1.PressKey(KEY_UP, 10000);
3255 end;
3256 if gPlayerAction[0, ACTION_LOOKDOWN] then
3257 begin
3258 kByte := kByte or NET_KEY_DOWN;
3259 gPlayer1.PressKey(KEY_DOWN, 10000);
3260 end;
3261 if gPlayerAction[0, ACTION_JUMP] then
3262 begin
3263 kByte := kByte or NET_KEY_JUMP;
3264 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3265 end;
3266 if gPlayerAction[0, ACTION_ATTACK] then kByte := kByte or NET_KEY_FIRE;
3267 if gPlayerAction[0, ACTION_ACTIVATE] then kByte := kByte or NET_KEY_OPEN;
3269 for i := WP_FACT to WP_LACT do
3270 begin
3271 if gWeaponAction[0, i] then
3272 begin
3273 WeaponAct := WeaponAct or Byte(1 shl i);
3274 gWeaponAction[0, i] := False
3275 end
3276 end;
3278 for i := WP_FIRST to WP_LAST do
3279 begin
3280 if gSelectWeapon[0, i] then
3281 begin
3282 WeaponSelect := WeaponSelect or Word(1 shl i);
3283 gSelectWeapon[0, i] := False
3284 end
3285 end;
3287 // fix movebutton state
3288 P1MoveButton := P1MoveButton or (strafeDir shl 4);
3289 end
3290 else
3291 kByte := NET_KEY_CHAT;
3293 NetOut.Write(Byte(NET_MSG_PLRPOS));
3294 NetOut.Write(gTime);
3295 NetOut.Write(kByte);
3296 NetOut.Write(Byte(gPlayer1.Direction));
3297 NetOut.Write(WeaponAct);
3298 NetOut.Write(WeaponSelect);
3299 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3300 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS);
3302 //kBytePrev := kByte;
3303 //kDirPrev := gPlayer1.Direction;
3304 end;
3306 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
3307 begin
3308 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
3309 NetOut.Write(Byte(Start));
3310 NetOut.Write(Command);
3311 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3312 end;
3314 procedure MC_SEND_PlayerSettings();
3315 var i: Integer;
3316 begin
3317 NetOut.Write(Byte(NET_MSG_PLRSET));
3318 NetOut.Write(gPlayer1Settings.Name);
3319 NetOut.Write(gPlayer1Settings.Model);
3320 NetOut.Write(gPlayer1Settings.Color.R);
3321 NetOut.Write(gPlayer1Settings.Color.G);
3322 NetOut.Write(gPlayer1Settings.Color.B);
3323 NetOut.Write(gPlayer1Settings.Team);
3324 NetOut.Write(gPlayer1Settings.WeaponSwitch);
3325 for i := WP_FIRST to WP_LAST + 1 do
3326 NetOut.Write(gPlayer1Settings.WeaponPreferences[i]);
3327 NetOut.Write(gPlayer1Settings.SwitchToEmpty);
3328 NetOut.Write(gPlayer1Settings.SkipFist);
3330 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3331 end;
3333 procedure MC_SEND_FullStateRequest();
3334 begin
3335 NetOut.Write(Byte(NET_MSG_REQFST));
3337 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3338 end;
3340 procedure MC_SEND_CheatRequest(Kind: Byte);
3341 begin
3342 NetOut.Write(Byte(NET_MSG_CHEAT));
3343 NetOut.Write(Kind);
3345 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3346 end;
3347 procedure MC_SEND_RCONPassword(Password: string);
3348 begin
3349 NetOut.Write(Byte(NET_MSG_RCON_AUTH));
3350 NetOut.Write(Password);
3352 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3353 end;
3354 procedure MC_SEND_RCONCommand(Cmd: string);
3355 begin
3356 NetOut.Write(Byte(NET_MSG_RCON_CMD));
3357 NetOut.Write(Cmd);
3359 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3360 end;
3363 end.