DEADSOFTWARE

net: kick clients if they take too long to auth
[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 PID: Word;
384 Color: TRGB;
385 I: Integer;
386 Err: Boolean;
387 begin
388 Err := False;
389 try
390 Ver := M.ReadString();
391 Pw := M.ReadString();
392 PName := M.ReadString();
393 Model := M.ReadString();
394 R := M.ReadByte();
395 G := M.ReadByte();
396 B := M.ReadByte();
397 T := M.ReadByte();
398 except
399 Err := True;
400 end;
402 if Err then begin MH_MalformedPacket(C); Exit; end;
404 if Ver <> GAME_VERSION then
405 begin
406 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
407 _lc[I_NET_DISC_VERSION]);
408 enet_peer_disconnect(C^.Peer, NET_DISC_VERSION);
409 Exit;
410 end;
412 if g_Net_IsHostBanned(C^.Peer^.address.host) then
413 begin
414 if g_Net_IsHostBanned(C^.Peer^.address.host, True) then
415 begin
416 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
417 _lc[I_NET_DISC_BAN]);
418 enet_peer_disconnect(C^.Peer, NET_DISC_BAN);
419 end
420 else
421 begin
422 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
423 _lc[I_NET_DISC_BAN]);
424 enet_peer_disconnect(C^.Peer, NET_DISC_TEMPBAN);
425 end;
426 Exit;
427 end;
429 if NetPassword <> '' then
430 if AnsiLowerCase(NetPassword) <> AnsiLowerCase(Pw) then
431 begin
432 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
433 _lc[I_NET_DISC_PASSWORD]);
434 enet_peer_disconnect(C^.Peer, NET_DISC_PASSWORD);
435 Exit;
436 end;
438 if (C^.Player <> 0) then
439 begin
440 // already received info
441 g_Net_Penalize(C, 'client info spam');
442 Exit;
443 end;
445 Color.R := R;
446 Color.B := B;
447 Color.G := G;
449 PID := g_Player_Create(Model, Color, T, False);
450 with g_Player_Get(PID) do
451 begin
452 Name := PName;
453 Reset(True);
454 end;
456 C^.Player := PID;
457 C^.WaitForFirstSpawn := false;
458 C^.AuthTime := 0;
460 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
461 e_WriteLog('NET: Client ' + PName + ' [' + IntToStr(C^.ID) +
462 '] connected. Assigned player #' + IntToStr(PID) + '.', TMsgType.Notify);
464 MH_SEND_Info(C^.ID);
466 with g_Player_Get(PID) do
467 begin
468 Name := PName;
469 FClientID := C^.ID;
470 // round in progress, don't spawn
471 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C.ID, C.Player]);
472 //e_LogWritefln('spawning player with pid #%u...', [PID]);
473 //Respawn(gGameSettings.GameType = GT_SINGLE);
474 //k8: no, do not spawn a player yet, wait for "request full state" packet
475 Lives := 0;
476 Spectate;
477 FNoRespawn := True;
478 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
479 // that is, if we'll set it to `true`, the player can be spawned after
480 // warmup time ran out, for example, regardless of the real player state.
481 // also, this seems to work only for the initial connection. further
482 // map changes could initiate resource downloading, but the player will
483 // be spawned immediately.
484 // the proper solution will require another player state, "ephemeral".
485 // the player should start any map in "ephemeral" state, and turned into
486 // real mobj only when they sent a special "i am ready" packet. this packet
487 // must be sent after receiving the full state, so the player will get a full
488 // map view before going into game.
489 FWantsInGame := false;
490 C^.WaitForFirstSpawn := true;
491 end;
493 //if not C^.WaitForFirstSpawn then
494 begin
495 for I := Low(NetClients) to High(NetClients) do
496 begin
497 if NetClients[I].ID = C^.ID then Continue;
498 MH_SEND_PlayerCreate(PID, NetClients[I].ID);
499 MH_SEND_PlayerPos(True, PID, NetClients[I].ID);
500 MH_SEND_PlayerStats(PID, NetClients[I].ID);
501 end;
502 end;
504 if gState in [STATE_INTERCUSTOM, STATE_FOLD] then
505 MH_SEND_GameEvent(NET_EV_MAPEND, 0, 'N', C^.ID);
507 if NetUseMaster then
508 begin
509 //g_Net_Slist_Update;
510 g_Net_Slist_Pulse();
511 end;
512 end;
515 procedure MH_ProcessFirstSpawn (C: pTNetClient);
516 var
517 plr: TPlayer;
518 begin
519 if not C.WaitForFirstSpawn then exit;
520 plr := g_Player_Get(C^.Player);
521 if not assigned(plr) then exit;
522 g_Net_Slist_ServerPlayerComes();
523 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C.ID, C.Player]);
524 C.WaitForFirstSpawn := false;
525 plr.FNoRespawn := false;
526 plr.FWantsInGame := true; // TODO: look into this later
528 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
529 begin
530 plr.Spectate;
531 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN, 0, 'N', C.ID);
532 end
533 else
534 begin
535 plr.Respawn(False);
536 if gLMSRespawn > LMS_RESPAWN_NONE then
537 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime, 'N', C.ID);
538 end;
539 end;
542 procedure MH_RECV_FullStateRequest(C: pTNetClient; var M: TMsg);
543 begin
544 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
545 if gGameOn then
546 begin
547 MH_SEND_Everything((C^.State = NET_STATE_AUTH), C^.ID)
548 end
549 else
550 begin
551 C^.RequestedFullUpdate := True;
552 end;
553 end;
555 // PLAYER
557 function MH_RECV_PlayerPos(C: pTNetClient; var M: TMsg): Word;
558 var
559 Dir, i: Byte;
560 WeaponAct: Byte;
561 WeaponSelect: Word;
562 PID: Word;
563 kByte: Word;
564 Pl: TPlayer;
565 GT: LongWord;
566 Err: Boolean;
567 begin
568 Result := 0;
569 Err := False;
570 if not gGameOn then Exit;
572 try
573 GT := M.ReadLongWord();
574 except
575 Err := True;
576 end;
578 if Err then begin MH_MalformedPacket(C); Exit; end;
580 PID := C^.Player;
581 Pl := g_Player_Get(PID);
582 if Pl = nil then
583 Exit;
585 if (GT > gTime + NET_MAX_DIFFTIME) or (GT < Pl.NetTime) then Exit;
587 with Pl do
588 begin
589 NetTime := GT;
590 try
591 kByte := M.ReadWord();
592 Dir := M.ReadByte();
593 WeaponAct := M.ReadByte();
594 WeaponSelect := M.ReadWord();
595 except
596 Err := True;
597 end;
599 if Err then begin MH_MalformedPacket(C); Exit; end;
601 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
602 if Direction <> TDirection(Dir) then
603 JustTeleported := False;
605 SetDirection(TDirection(Dir));
606 ReleaseKeys;
608 if kByte = NET_KEY_CHAT then
609 begin
610 PressKey(KEY_CHAT, 10000);
611 Exit;
612 end;
614 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
615 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
616 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
617 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
618 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
619 if LongBool(kByte and NET_KEY_FIRE) then PressKey(KEY_FIRE, 10000);
620 if LongBool(kByte and NET_KEY_OPEN) then PressKey(KEY_OPEN, 10000);
622 for i := 0 to 7 do
623 begin
624 if (WeaponAct and Byte(1 shl i)) <> 0 then
625 begin
626 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
627 ProcessWeaponAction(i);
628 end;
629 end;
631 for i := 0 to 15 do
632 begin
633 if (WeaponSelect and Word(1 shl i)) <> 0 then
634 begin
635 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
636 QueueWeaponSwitch(i);
637 end;
638 end;
639 end;
641 // MH_SEND_PlayerPos(False, PID, C^.ID);
642 end;
644 procedure MH_RECV_CheatRequest(C: pTNetClient; var M: TMsg);
645 var
646 CheatKind: Byte;
647 Pl: TPlayer;
648 Err: Boolean;
649 begin
650 Err := False;
651 Pl := g_Player_Get(C^.Player);
652 if Pl = nil then Exit;
654 try
655 CheatKind := M.ReadByte();
656 except
657 Err := True;
658 end;
660 if Err then begin MH_MalformedPacket(C); Exit; end;
662 case CheatKind of
663 NET_CHEAT_SUICIDE:
664 Pl.Damage(SUICIDE_DAMAGE, Pl.UID, 0, 0, HIT_SELF);
665 NET_CHEAT_SPECTATE:
666 begin
667 if Pl.FSpectator then
668 begin
669 if (gGameSettings.MaxLives = 0) or (gLMSRespawn > LMS_RESPAWN_NONE) then
670 Pl.Respawn(False)
671 else
672 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN, Pl.UID);
673 end
674 else
675 Pl.Spectate;
676 end;
677 NET_CHEAT_READY:
678 begin
679 if gState <> STATE_INTERCUSTOM then Exit;
680 Pl.FReady := not Pl.FReady;
681 if Pl.FReady then
682 begin
683 MH_SEND_GameEvent(NET_EV_INTER_READY, Pl.UID, 'Y');
684 Inc(gInterReadyCount);
685 end
686 else
687 begin
688 MH_SEND_GameEvent(NET_EV_INTER_READY, Pl.UID, 'N');
689 Dec(gInterReadyCount);
690 end;
691 end;
692 NET_CHEAT_DROPFLAG:
693 Pl.TryDropFlag();
694 end;
695 end;
697 procedure MH_RECV_PlayerSettings(C: pTNetClient; var M: TMsg);
698 var
699 TmpName: string;
700 TmpModel: string;
701 TmpColor: TRGB;
702 TmpTeam: Byte;
703 Pl: TPlayer;
704 Err: Boolean;
705 begin
706 Err := False;
707 try
708 TmpName := M.ReadString();
709 TmpModel := M.ReadString();
710 TmpColor.R := M.ReadByte();
711 TmpColor.G := M.ReadByte();
712 TmpColor.B := M.ReadByte();
713 TmpTeam := M.ReadByte();
714 except
715 Err := True;
716 end;
718 if Err then begin MH_MalformedPacket(C); Exit; end;
720 Pl := g_Player_Get(C^.Player);
721 if Pl = nil then Exit;
723 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
724 Pl.SwitchTeam
725 else
726 Pl.SetColor(TmpColor);
728 if Pl.Name <> TmpName then
729 begin
730 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
731 Pl.Name := TmpName;
732 end;
734 if TmpModel <> Pl.Model.Name then
735 Pl.SetModel(TmpModel);
737 MH_SEND_PlayerSettings(Pl.UID, TmpModel);
738 end;
740 // RCON
742 procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
743 var
744 Pwd: string;
745 Err: Boolean;
746 begin
747 Err := False;
748 try
749 Pwd := M.ReadString();
750 except
751 Err := True;
752 end;
753 if Err then begin MH_MalformedPacket(C); Exit; end;
754 if not NetAllowRCON then Exit;
755 if Pwd = NetRCONPassword then
756 begin
757 C^.RCONAuth := True;
758 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWGOOD, 'N', C^.ID);
759 end
760 else
761 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWBAD, 'N', C^.ID);
762 end;
764 procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
765 var
766 Cmd: string;
767 Err: Boolean;
768 begin
769 Err := False;
770 try
771 Cmd := M.ReadString();
772 except
773 Err := True;
774 end;
775 if Err then begin MH_MalformedPacket(C); Exit; end;
776 if not NetAllowRCON then Exit;
777 if not C^.RCONAuth then
778 begin
779 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_NOAUTH, 'N', C^.ID);
780 Exit;
781 end;
782 g_Console_Process(Cmd);
783 end;
785 // MISC
787 procedure MH_RECV_Vote(C: pTNetClient; var M: TMsg);
788 var
789 Start: Boolean;
790 Name, Command: string;
791 Need: Integer;
792 Pl: TPlayer;
793 Err: Boolean;
794 begin
795 Err := False;
796 try
797 Start := M.ReadByte() <> 0;
798 Command := M.ReadString();
799 except
800 Err := True;
801 end;
803 if Err then begin MH_MalformedPacket(C); Exit; end;
805 Pl := g_Player_Get(C^.Player);
806 if Pl = nil then Exit;
807 Name := Pl.Name;
809 if Start then
810 begin
811 if not g_Console_CommandBlacklisted(Command) then
812 g_Game_StartVote(Command, Name);
813 end
814 else if gVoteInProgress then
815 begin
816 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
817 Need := Floor((NetClientCount+1)/2.0) + 1
818 else
819 Need := Floor(NetClientCount/2.0) + 1;
820 if C^.Voted then
821 begin
822 Dec(gVoteCount);
823 C^.Voted := False;
824 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [Name, gVoteCount, Need]), True);
825 MH_SEND_VoteEvent(NET_VE_REVOKE, Name, 'a', gVoteCount, Need);
826 end
827 else
828 begin
829 Inc(gVoteCount);
830 C^.Voted := True;
831 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Name, gVoteCount, Need]), True);
832 MH_SEND_VoteEvent(NET_VE_VOTE, Name, 'a', gVoteCount, Need);
833 g_Game_CheckVote;
834 end;
835 end;
836 end;
838 // GAME (SEND)
840 procedure MH_SEND_Everything(CreatePlayers: Boolean {= False}; ID: Integer {= NET_EVERYONE});
842 function sendItemRespawn (it: PItem): Boolean;
843 begin
844 result := false; // don't stop
845 MH_SEND_ItemSpawn(True, it.myid, ID);
846 end;
848 function sendMonSpawn (mon: TMonster): Boolean;
849 begin
850 result := false; // don't stop
851 MH_SEND_MonsterSpawn(mon.UID, ID);
852 end;
854 function sendPanelState (pan: TPanel): Boolean;
855 begin
856 result := false; // don't stop
857 MH_SEND_PanelState(pan.guid, ID); // anyway, to sync mplats
858 if (pan.CanChangeTexture) then MH_SEND_PanelTexture(pan.guid, pan.LastAnimLoop, ID);
859 end;
861 var
862 I: Integer;
863 begin
864 if (ID >= 0) and (ID < length(NetClients)) then
865 begin
866 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID, NetClients[ID].Player]);
867 MH_ProcessFirstSpawn(@NetClients[ID]);
868 end;
870 if gPlayers <> nil then
871 begin
872 for I := Low(gPlayers) to High(gPlayers) do
873 begin
874 if gPlayers[I] <> nil then
875 begin
876 if CreatePlayers then MH_SEND_PlayerCreate(gPlayers[I].UID, ID);
877 MH_SEND_PlayerPos(True, gPlayers[I].UID, ID);
878 MH_SEND_PlayerStats(gPlayers[I].UID, ID);
880 if (gPlayers[I].Flag <> FLAG_NONE) and (gGameSettings.GameMode = GM_CTF) then
881 begin
882 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED, gPlayers[I].Flag, gPlayers[I].UID, True, ID);
883 end;
884 end;
885 end;
886 end;
888 g_Items_ForEachAlive(sendItemRespawn, true); // backwards
889 g_Mons_ForEach(sendMonSpawn);
890 g_Map_ForEachPanel(sendPanelState);
892 if gTriggers <> nil then
893 begin
894 for I := Low(gTriggers) to High(gTriggers) do
895 begin
896 if gTriggers[I].TriggerType = TRIGGER_SOUND then
897 begin
898 MH_SEND_TriggerSound(gTriggers[I], ID);
899 end;
900 end;
901 end;
903 if Shots <> nil then
904 begin
905 for I := Low(Shots) to High(Shots) do
906 begin
907 if Shots[i].ShotType in [6, 7, 8] then
908 begin
909 MH_SEND_CreateShot(i, ID);
910 end;
911 end;
912 end;
914 MH_SEND_TriggerMusic(ID);
916 MH_SEND_GameStats(ID);
917 MH_SEND_CoopStats(ID);
919 if gGameSettings.GameMode = GM_CTF then
920 begin
921 if gFlags[FLAG_RED].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_RED].State, FLAG_RED, 0, True, ID);
922 if gFlags[FLAG_BLUE].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_BLUE].State, FLAG_BLUE, 0, True, ID);
923 end;
925 if CreatePlayers and (ID >= 0) then NetClients[ID].State := NET_STATE_GAME;
927 g_Net_Flush();
928 end;
930 procedure MH_SEND_Info(ID: Byte);
931 begin
932 NetOut.Clear();
934 NetOut.Write(Byte(NET_MSG_INFO));
935 NetOut.Write(ID);
936 NetOut.Write(NetClients[ID].Player);
937 NetOut.Write(ExtractFileName(gGameSettings.WAD));
938 NetOut.Write(g_ExtractFileName(gMapInfo.Map));
939 NetOut.Write(gWADHash);
940 NetOut.Write(gGameSettings.GameMode);
941 NetOut.Write(gGameSettings.GoalLimit);
942 NetOut.Write(gGameSettings.TimeLimit);
943 NetOut.Write(gGameSettings.MaxLives);
944 NetOut.Write(gGameSettings.Options);
945 NetOut.Write(gTime);
947 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
948 end;
950 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
951 var
952 Name: string;
953 i: Integer;
954 Team: Byte;
955 begin
956 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
957 Mode := NET_CHAT_PLAYER;
959 Team := 0;
960 if (Mode = NET_CHAT_TEAM) then
961 begin
962 for i := Low(gPlayers) to High(gPlayers) do
963 if (gPlayers[i] <> nil) and (gPlayers[i].FClientID >= 0) and
964 (gPlayers[i].Team = ID) then
965 begin
966 NetOut.Write(Byte(NET_MSG_CHAT));
967 NetOut.Write(Txt);
968 NetOut.Write(Mode);
969 g_Net_Host_Send(gPlayers[i].FClientID, True, NET_CHAN_CHAT);
970 end;
971 Team := ID;
972 ID := NET_EVERYONE;
973 end
974 else
975 begin
976 NetOut.Write(Byte(NET_MSG_CHAT));
977 NetOut.Write(Txt);
978 NetOut.Write(Mode);
979 g_Net_Host_Send(ID, True, NET_CHAN_CHAT);
980 end;
982 if Mode = NET_CHAT_SYSTEM then
983 Exit;
985 if ID = NET_EVERYONE then
986 begin
987 if Mode = NET_CHAT_PLAYER then
988 begin
989 g_Console_Add(Txt, True);
990 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
991 g_Game_ChatSound(b_Text_Unformat(Txt));
992 end
993 else
994 if Mode = NET_CHAT_TEAM then
995 if gPlayer1 <> nil then
996 begin
997 if (gPlayer1.Team = TEAM_RED) and (Team = TEAM_RED) then
998 begin
999 g_Console_Add(#18'[Team] '#2 + Txt, True);
1000 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1001 g_Game_ChatSound(b_Text_Unformat(Txt));
1002 end
1003 else if (gPlayer1.Team = TEAM_BLUE) and (Team = TEAM_BLUE) then
1004 begin
1005 g_Console_Add(#20'[Team] '#2 + Txt, True);
1006 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1007 g_Game_ChatSound(b_Text_Unformat(Txt));
1008 end;
1009 end;
1010 end
1011 else
1012 begin
1013 Name := g_Net_ClientName_ByID(ID);
1014 g_Console_Add('-> ' + Name + ': ' + Txt, True);
1015 e_WriteLog('[Tell ' + Name + '] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1016 g_Game_ChatSound(b_Text_Unformat(Txt), False);
1017 end;
1018 end;
1020 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
1021 begin
1022 NetOut.Write(Byte(NET_MSG_GFX));
1023 NetOut.Write(Kind);
1024 NetOut.Write(X);
1025 NetOut.Write(Y);
1026 NetOut.Write(Ang);
1028 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
1029 end;
1031 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
1032 begin
1033 NetOut.Write(Byte(NET_MSG_SND));
1034 NetOut.Write(Name);
1035 if Pos then
1036 begin
1037 NetOut.Write(Byte(1));
1038 NetOut.Write(X);
1039 NetOut.Write(Y);
1040 end
1041 else
1042 NetOut.Write(Byte(0));
1044 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
1045 end;
1047 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
1048 begin
1049 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
1051 NetOut.Write(Byte(NET_MSG_SHADD));
1052 NetOut.Write(Proj);
1053 NetOut.Write(Shots[Proj].ShotType);
1054 NetOut.Write(Shots[Proj].Target);
1055 NetOut.Write(Shots[Proj].SpawnerUID);
1056 NetOut.Write(Shots[Proj].Timeout);
1057 NetOut.Write(Shots[Proj].Obj.X);
1058 NetOut.Write(Shots[Proj].Obj.Y);
1059 NetOut.Write(Shots[Proj].Obj.Vel.X);
1060 NetOut.Write(Shots[Proj].Obj.Vel.Y);
1062 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1063 end;
1065 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
1066 begin
1067 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
1069 NetOut.Write(Byte(NET_MSG_SHPOS));
1070 NetOut.Write(Proj);
1071 NetOut.Write(Shots[Proj].Obj.X);
1072 NetOut.Write(Shots[Proj].Obj.Y);
1073 NetOut.Write(Shots[Proj].Obj.Vel.X);
1074 NetOut.Write(Shots[Proj].Obj.Vel.Y);
1076 g_Net_Host_Send(ID, False, NET_CHAN_SHOTS);
1077 end;
1079 procedure MH_Send_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
1080 begin
1081 NetOut.Write(Byte(NET_MSG_SHDEL));
1082 NetOut.Write(Proj);
1083 NetOut.Write(Byte(Loud));
1084 NetOut.Write(X);
1085 NetOut.Write(Y);
1087 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1088 end;
1090 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
1091 begin
1092 NetOut.Write(Byte(NET_MSG_SCORE));
1093 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1094 begin
1095 NetOut.Write(gTeamStat[TEAM_RED].Goals);
1096 NetOut.Write(gTeamStat[TEAM_BLUE].Goals);
1097 end
1098 else
1099 if gGameSettings.GameMode = GM_COOP then
1100 begin
1101 NetOut.Write(gCoopMonstersKilled);
1102 NetOut.Write(gCoopSecretsFound);
1103 end;
1105 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1106 end;
1108 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
1109 begin
1110 NetOut.Write(Byte(NET_MSG_COOP));
1111 NetOut.Write(gTotalMonsters);
1112 NetOut.Write(gSecretsCount);
1113 NetOut.Write(gCoopTotalMonstersKilled);
1114 NetOut.Write(gCoopTotalSecretsFound);
1115 NetOut.Write(gCoopTotalMonsters);
1116 NetOut.Write(gCoopTotalSecrets);
1117 end;
1119 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
1120 begin
1121 NetOut.Write(Byte(NET_MSG_GEVENT));
1122 NetOut.Write(EvType);
1123 NetOut.Write(EvNum);
1124 NetOut.Write(EvStr);
1125 NetOut.Write(Byte(gLastMap));
1126 NetOut.Write(gTime);
1127 if (EvType = NET_EV_MAPSTART) and isWadPath(EvStr) then
1128 begin
1129 NetOut.Write(Byte(1));
1130 NetOut.Write(gWADHash);
1131 end else
1132 NetOut.Write(Byte(0));
1134 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
1135 end;
1137 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
1138 begin
1139 NetOut.Write(Byte(NET_MSG_FLAG));
1140 NetOut.Write(EvType);
1141 NetOut.Write(Flag);
1142 NetOut.Write(Byte(Quiet));
1143 NetOut.Write(PID);
1144 NetOut.Write(gFlags[Flag].State);
1145 NetOut.Write(gFlags[Flag].CaptureTime);
1146 NetOut.Write(gFlags[Flag].Obj.X);
1147 NetOut.Write(gFlags[Flag].Obj.Y);
1148 NetOut.Write(gFlags[Flag].Obj.Vel.X);
1149 NetOut.Write(gFlags[Flag].Obj.Vel.Y);
1150 NetOut.Write(Byte(gFlags[Flag].Direction));
1152 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1153 end;
1155 procedure MH_SEND_FlagPos(Flag: Byte; ID: Integer = NET_EVERYONE);
1156 begin
1157 NetOut.Write(Byte(NET_MSG_FLAGPOS));
1158 NetOut.Write(Flag);
1159 NetOut.Write(gFlags[Flag].Obj.X);
1160 NetOut.Write(gFlags[Flag].Obj.Y);
1161 NetOut.Write(gFlags[Flag].Obj.Vel.X);
1162 NetOut.Write(gFlags[Flag].Obj.Vel.Y);
1164 g_Net_Host_Send(ID, False, NET_CHAN_IMPORTANT);
1165 end;
1167 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
1168 begin
1169 NetOut.Write(Byte(NET_MSG_GSET));
1170 NetOut.Write(gGameSettings.GameMode);
1171 NetOut.Write(gGameSettings.GoalLimit);
1172 NetOut.Write(gGameSettings.TimeLimit);
1173 NetOut.Write(gGameSettings.MaxLives);
1174 NetOut.Write(gGameSettings.Options);
1176 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1177 end;
1179 // PLAYER (SEND)
1181 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
1182 var
1183 P: TPlayer;
1184 begin
1185 P := g_Player_Get(PID);
1186 if P = nil then Exit;
1188 NetOut.Write(Byte(NET_MSG_PLR));
1189 NetOut.Write(PID);
1190 NetOut.Write(P.Name);
1192 NetOut.Write(P.FActualModelName);
1193 NetOut.Write(P.FColor.R);
1194 NetOut.Write(P.FColor.G);
1195 NetOut.Write(P.FColor.B);
1196 NetOut.Write(P.Team);
1198 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT)
1199 end;
1201 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
1202 var
1203 kByte: Word;
1204 Pl: TPlayer;
1205 begin
1206 Pl := g_Player_Get(PID);
1207 if Pl = nil then Exit;
1208 if Pl.FDummy then Exit;
1210 NetOut.Write(Byte(NET_MSG_PLRPOS));
1211 NetOut.Write(gTime);
1212 NetOut.Write(PID);
1214 kByte := 0;
1216 with Pl do
1217 begin
1218 NetOut.Write(FPing);
1219 NetOut.Write(FLoss);
1220 if IsKeyPressed(KEY_CHAT) then
1221 kByte := NET_KEY_CHAT
1222 else
1223 begin
1224 if IsKeyPressed(KEY_LEFT) then kByte := kByte or NET_KEY_LEFT;
1225 if IsKeyPressed(KEY_RIGHT) then kByte := kByte or NET_KEY_RIGHT;
1226 if IsKeyPressed(KEY_UP) then kByte := kByte or NET_KEY_UP;
1227 if IsKeyPressed(KEY_DOWN) then kByte := kByte or NET_KEY_DOWN;
1228 if IsKeyPressed(KEY_JUMP) then kByte := kByte or NET_KEY_JUMP;
1229 end;
1231 if JustTeleported then kByte := kByte or NET_KEY_FORCEDIR;
1233 NetOut.Write(kByte);
1234 if Direction = TDirection.D_LEFT then NetOut.Write(Byte(0)) else NetOut.Write(Byte(1));
1235 NetOut.Write(GameX);
1236 NetOut.Write(GameY);
1237 NetOut.Write(GameVelX);
1238 NetOut.Write(GameVelY);
1239 NetOut.Write(GameAccelX);
1240 NetOut.Write(GameAccelY);
1241 end;
1243 g_Net_Host_Send(ID, Reliable, NET_CHAN_PLAYERPOS);
1244 end;
1246 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
1247 var
1248 P: TPlayer;
1249 I: Integer;
1250 begin
1251 P := g_Player_Get(PID);
1252 if P = nil then Exit;
1254 NetOut.Write(Byte(NET_MSG_PLRSTA));
1255 NetOut.Write(PID);
1257 with P do
1258 begin
1259 NetOut.Write(Byte(alive));
1260 NetOut.Write(Byte(GodMode));
1261 NetOut.Write(Health);
1262 NetOut.Write(Armor);
1263 NetOut.Write(Air);
1264 NetOut.Write(JetFuel);
1265 NetOut.Write(Lives);
1266 NetOut.Write(Team);
1268 for I := WP_FIRST to WP_LAST do
1269 NetOut.Write(Byte(FWeapon[I]));
1271 for I := A_BULLETS to A_HIGH do
1272 NetOut.Write(FAmmo[I]);
1274 for I := A_BULLETS to A_HIGH do
1275 NetOut.Write(FMaxAmmo[I]);
1277 for I := MR_SUIT to MR_MAX do
1278 NetOut.Write(LongWord(FMegaRulez[I]));
1280 NetOut.Write(Byte(R_ITEM_BACKPACK in FRulez));
1281 NetOut.Write(Byte(R_KEY_RED in FRulez));
1282 NetOut.Write(Byte(R_KEY_GREEN in FRulez));
1283 NetOut.Write(Byte(R_KEY_BLUE in FRulez));
1284 NetOut.Write(Byte(R_BERSERK in FRulez));
1286 NetOut.Write(Frags);
1287 NetOut.Write(Death);
1289 NetOut.Write(CurrWeap);
1291 NetOut.Write(Byte(FSpectator));
1292 NetOut.Write(Byte(FGhost));
1293 NetOut.Write(Byte(FPhysics));
1294 NetOut.Write(Byte(FNoRespawn));
1295 NetOut.Write(Byte(FJetpack));
1296 NetOut.Write(FFireTime);
1297 NetOut.Write(Byte(FFlaming));
1298 NetOut.Write(FSpawnInvul);
1299 end;
1301 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1302 end;
1304 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
1305 begin
1306 NetOut.Write(Byte(NET_MSG_PLRDMG));
1307 NetOut.Write(PID);
1308 NetOut.Write(Kind);
1309 NetOut.Write(Attacker);
1310 NetOut.Write(Value);
1311 NetOut.Write(VX);
1312 NetOut.Write(VY);
1314 g_Net_Host_Send(ID, False, NET_CHAN_PLAYER);
1315 end;
1317 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
1318 begin
1319 NetOut.Write(Byte(NET_MSG_PLRDIE));
1320 NetOut.Write(PID);
1321 NetOut.Write(KillType);
1322 NetOut.Write(DeathType);
1323 NetOut.Write(Attacker);
1325 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1326 end;
1328 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
1329 begin
1330 NetOut.Write(Byte(NET_MSG_PLRFIRE));
1331 NetOut.Write(PID);
1332 NetOut.Write(Weapon);
1333 NetOut.Write(X);
1334 NetOut.Write(Y);
1335 NetOut.Write(AX);
1336 NetOut.Write(AY);
1337 NetOut.Write(ShotID);
1339 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1340 end;
1342 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
1343 begin
1344 NetOut.Write(Byte(NET_MSG_PLRDEL));
1345 NetOut.Write(PID);
1347 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1348 end;
1350 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
1351 var
1352 Pl: TPlayer;
1353 begin
1354 Pl := g_Player_Get(PID);
1355 if Pl = nil then Exit;
1357 NetOut.Write(Byte(NET_MSG_PLRSET));
1358 NetOut.Write(PID);
1359 NetOut.Write(Pl.Name);
1360 if Mdl = '' then
1361 NetOut.Write(Pl.Model.Name)
1362 else
1363 NetOut.Write(Mdl);
1364 NetOut.Write(Pl.FColor.R);
1365 NetOut.Write(Pl.FColor.G);
1366 NetOut.Write(Pl.FColor.B);
1367 NetOut.Write(Pl.Team);
1369 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1370 end;
1372 // ITEM (SEND)
1374 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1375 var
1376 it: PItem;
1377 tt: Byte;
1378 begin
1379 it := g_Items_ByIdx(IID);
1381 NetOut.Write(Byte(NET_MSG_ISPAWN));
1382 NetOut.Write(IID);
1383 NetOut.Write(Byte(Quiet));
1384 tt := it.ItemType;
1385 if it.dropped then tt := tt or $80;
1386 NetOut.Write(tt);
1387 NetOut.Write(Byte(it.Fall));
1388 NetOut.Write(Byte(it.Respawnable));
1389 NetOut.Write(it.Obj.X);
1390 NetOut.Write(it.Obj.Y);
1391 NetOut.Write(it.Obj.Vel.X);
1392 NetOut.Write(it.Obj.Vel.Y);
1394 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1395 end;
1397 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1398 begin
1399 NetOut.Write(Byte(NET_MSG_IDEL));
1400 NetOut.Write(IID);
1401 NetOut.Write(Byte(Quiet));
1403 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1404 end;
1406 procedure MH_SEND_ItemPos(IID: Word; ID: Integer = NET_EVERYONE);
1407 var
1408 it: PItem;
1409 begin
1410 it := g_Items_ByIdx(IID);
1412 NetOut.Write(Byte(NET_MSG_IPOS));
1413 NetOut.Write(IID);
1414 NetOut.Write(it.Obj.X);
1415 NetOut.Write(it.Obj.Y);
1416 NetOut.Write(it.Obj.Vel.X);
1417 NetOut.Write(it.Obj.Vel.Y);
1419 g_Net_Host_Send(ID, False, NET_CHAN_LARGEDATA);
1420 end;
1422 // PANEL
1424 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
1425 var
1426 TP: TPanel;
1427 begin
1428 TP := g_Map_PanelByGUID(PGUID);
1429 if (TP = nil) then exit;
1431 with TP do
1432 begin
1433 NetOut.Write(Byte(NET_MSG_PTEX));
1434 NetOut.Write(LongWord(PGUID));
1435 NetOut.Write(FCurTexture);
1436 NetOut.Write(FCurFrame);
1437 NetOut.Write(FCurFrameCount);
1438 NetOut.Write(AnimLoop);
1439 end;
1441 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1442 end;
1444 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
1445 var
1446 TP: TPanel;
1447 mpflags: Byte = 0;
1448 begin
1449 TP := g_Map_PanelByGUID(PGUID);
1450 if (TP = nil) then exit;
1452 NetOut.Write(Byte(NET_MSG_PSTATE));
1453 NetOut.Write(LongWord(PGUID));
1454 NetOut.Write(Byte(TP.Enabled));
1455 NetOut.Write(TP.LiftType);
1456 NetOut.Write(TP.X);
1457 NetOut.Write(TP.Y);
1458 NetOut.Write(Word(TP.Width));
1459 NetOut.Write(Word(TP.Height));
1460 // mplats
1461 NetOut.Write(LongInt(TP.movingSpeedX));
1462 NetOut.Write(LongInt(TP.movingSpeedY));
1463 NetOut.Write(LongInt(TP.movingStartX));
1464 NetOut.Write(LongInt(TP.movingStartY));
1465 NetOut.Write(LongInt(TP.movingEndX));
1466 NetOut.Write(LongInt(TP.movingEndY));
1467 NetOut.Write(LongInt(TP.sizeSpeedX));
1468 NetOut.Write(LongInt(TP.sizeSpeedY));
1469 NetOut.Write(LongInt(TP.sizeEndX));
1470 NetOut.Write(LongInt(TP.sizeEndY));
1471 if TP.movingActive then mpflags := mpflags or 1;
1472 if TP.moveOnce then mpflags := mpflags or 2;
1473 NetOut.Write(Byte(mpflags));
1475 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1476 end;
1478 // TRIGGER
1480 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
1481 begin
1482 if gTriggers = nil then Exit;
1483 if T.Sound = nil then Exit;
1485 NetOut.Write(Byte(NET_MSG_TSOUND));
1486 NetOut.Write(T.ClientID);
1487 NetOut.Write(Byte(T.Sound.IsPlaying));
1488 NetOut.Write(LongWord(T.Sound.GetPosition));
1489 NetOut.Write(T.SoundPlayCount);
1491 g_Net_Host_Send(ID, True);
1492 end;
1494 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
1495 begin
1496 NetOut.Write(Byte(NET_MSG_TMUSIC));
1497 NetOut.Write(gMusic.Name);
1498 NetOut.Write(Byte(gMusic.IsPlaying));
1499 NetOut.Write(LongWord(gMusic.GetPosition));
1500 NetOut.Write(Byte(gMusic.SpecPause or gMusic.IsPaused));
1502 g_Net_Host_Send(ID, True);
1503 end;
1505 // MONSTER
1507 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
1508 var
1509 M: TMonster;
1510 begin
1511 M := g_Monsters_ByUID(UID);
1512 if M = nil then
1513 Exit;
1515 with M do
1516 begin
1517 NetOut.Write(Byte(NET_MSG_MSPAWN));
1518 NetOut.Write(UID);
1519 NetOut.Write(MonsterType);
1520 NetOut.Write(MonsterState);
1521 NetOut.Write(MonsterAnim);
1522 NetOut.Write(MonsterTargetUID);
1523 NetOut.Write(MonsterTargetTime);
1524 NetOut.Write(MonsterBehaviour);
1525 NetOut.Write(MonsterSleep);
1526 NetOut.Write(MonsterHealth);
1527 NetOut.Write(MonsterAmmo);
1528 NetOut.Write(GameX);
1529 NetOut.Write(GameY);
1530 NetOut.Write(GameVelX);
1531 NetOut.Write(GameVelY);
1532 NetOut.Write(Byte(GameDirection));
1533 end;
1535 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1536 end;
1538 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
1539 var
1540 M: TMonster;
1541 begin
1542 M := g_Monsters_ByUID(UID);
1543 if M = nil then Exit;
1545 NetOut.Write(Byte(NET_MSG_MPOS));
1546 NetOut.Write(UID);
1548 with M do
1549 begin
1550 NetOut.Write(GameX);
1551 NetOut.Write(GameY);
1552 NetOut.Write(GameVelX);
1553 NetOut.Write(GameVelY);
1554 NetOut.Write(Byte(GameDirection));
1555 end;
1557 g_Net_Host_Send(ID, False, NET_CHAN_MONSTERPOS);
1558 end;
1560 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
1561 var
1562 M: TMonster;
1563 begin
1564 M := g_Monsters_ByUID(UID);
1565 if M = nil then Exit;
1567 NetOut.Write(Byte(NET_MSG_MSTATE));
1568 NetOut.Write(UID);
1570 with M do
1571 begin
1572 NetOut.Write(MonsterState);
1573 NetOut.Write(ForcedAnim);
1574 NetOut.Write(MonsterTargetUID);
1575 NetOut.Write(MonsterTargetTime);
1576 NetOut.Write(MonsterSleep);
1577 NetOut.Write(MonsterHealth);
1578 NetOut.Write(MonsterAmmo);
1579 NetOut.Write(MonsterPain);
1580 NetOut.Write(Byte(AnimIsReverse));
1581 NetOut.Write(FFireTime);
1582 end;
1584 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1585 end;
1587 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
1588 begin
1589 NetOut.Write(Byte(NET_MSG_MSHOT));
1590 NetOut.Write(UID);
1591 NetOut.Write(X);
1592 NetOut.Write(Y);
1593 NetOut.Write(VX);
1594 NetOut.Write(VY);
1596 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1597 end;
1599 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
1600 var
1601 M: TMonster;
1602 begin
1603 M := g_Monsters_ByUID(UID);
1604 if M = nil then Exit;
1606 NetOut.Write(Byte(NET_MSG_MDEL));
1607 NetOut.Write(UID);
1609 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1610 end;
1612 // MISC
1614 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
1615 begin
1616 NetOut.Write(Byte(NET_MSG_TIME_SYNC));
1617 NetOut.Write(Time);
1619 g_Net_Host_Send(ID, False, NET_CHAN_SERVICE);
1620 end;
1622 procedure MH_SEND_VoteEvent(EvType: Byte;
1623 StrArg1: string = 'a'; StrArg2: string = 'b';
1624 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
1625 ID: Integer = NET_EVERYONE);
1626 begin
1627 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
1628 NetOut.Write(EvType);
1629 NetOut.Write(IntArg1);
1630 NetOut.Write(IntArg2);
1631 NetOut.Write(StrArg1);
1632 NetOut.Write(StrArg2);
1634 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1635 end;
1637 // CLIENT MESSAGES //
1639 // GAME
1641 procedure MC_RECV_Chat(var M: TMsg);
1642 var
1643 Txt: string;
1644 Mode: Byte;
1645 begin
1646 Txt := M.ReadString();
1647 Mode := M.ReadByte();
1649 if Mode <> NET_CHAT_SYSTEM then
1650 begin
1651 if NetDeafLevel = 0 then
1652 begin
1653 if Mode = NET_CHAT_PLAYER then
1654 begin
1655 g_Console_Add(Txt, True);
1656 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1657 g_Game_ChatSound(b_Text_Unformat(Txt));
1658 end else
1659 if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then
1660 begin
1661 if gPlayer1.Team = TEAM_RED then
1662 g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True);
1663 if gPlayer1.Team = TEAM_BLUE then
1664 g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True);
1665 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1666 g_Game_ChatSound(b_Text_Unformat(Txt));
1667 end;
1668 end;
1669 end else if (NetDeafLevel < 2) then
1670 g_Console_Add(Txt, True);
1671 end;
1673 procedure MC_RECV_Effect(var M: TMsg);
1674 var
1675 Kind: Byte;
1676 X, Y: Integer;
1677 Ang: SmallInt;
1678 Anim: TAnimation;
1679 ID: LongWord;
1680 begin
1681 if not gGameOn then Exit;
1682 Kind := M.ReadByte();
1683 X := M.ReadLongInt();
1684 Y := M.ReadLongInt();
1685 Ang := M.ReadSmallInt();
1687 case Kind of
1688 NET_GFX_SPARK:
1689 g_GFX_Spark(X, Y, 2 + Random(2), Ang, 0, 0);
1691 NET_GFX_TELE:
1692 begin
1693 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
1694 begin
1695 Anim := TAnimation.Create(ID, False, 3);
1696 g_GFX_OnceAnim(X, Y, Anim);
1697 Anim.Free();
1698 end;
1699 if Ang = 1 then
1700 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
1701 end;
1703 NET_GFX_EXPLODE:
1704 begin
1705 if g_Frames_Get(ID, 'FRAMES_EXPLODE_ROCKET') then
1706 begin
1707 Anim := TAnimation.Create(ID, False, 6);
1708 Anim.Blending := False;
1709 g_GFX_OnceAnim(X-64, Y-64, Anim);
1710 Anim.Free();
1711 end;
1712 if Ang = 1 then
1713 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X, Y);
1714 end;
1716 NET_GFX_BFGEXPL:
1717 begin
1718 if g_Frames_Get(ID, 'FRAMES_EXPLODE_BFG') then
1719 begin
1720 Anim := TAnimation.Create(ID, False, 6);
1721 Anim.Blending := False;
1722 g_GFX_OnceAnim(X-64, Y-64, Anim);
1723 Anim.Free();
1724 end;
1725 if Ang = 1 then
1726 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X, Y);
1727 end;
1729 NET_GFX_BFGHIT:
1730 begin
1731 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1732 begin
1733 Anim := TAnimation.Create(ID, False, 4);
1734 g_GFX_OnceAnim(X-32, Y-32, Anim);
1735 Anim.Free();
1736 end;
1737 end;
1739 NET_GFX_FIRE:
1740 begin
1741 if g_Frames_Get(ID, 'FRAMES_FIRE') then
1742 begin
1743 Anim := TAnimation.Create(ID, False, 4);
1744 g_GFX_OnceAnim(X, Y, Anim);
1745 Anim.Free();
1746 end;
1747 if Ang = 1 then
1748 g_Sound_PlayExAt('SOUND_FIRE', X, Y);
1749 end;
1751 NET_GFX_RESPAWN:
1752 begin
1753 if g_Frames_Get(ID, 'FRAMES_ITEM_RESPAWN') then
1754 begin
1755 Anim := TAnimation.Create(ID, False, 4);
1756 g_GFX_OnceAnim(X, Y, Anim);
1757 Anim.Free();
1758 end;
1759 if Ang = 1 then
1760 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
1761 end;
1763 NET_GFX_SHELL1:
1764 g_Player_CreateShell(X, Y, 0, -2, SHELL_BULLET);
1766 NET_GFX_SHELL2:
1767 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1769 NET_GFX_SHELL3:
1770 begin
1771 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1772 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1773 end;
1774 end;
1775 end;
1777 procedure MC_RECV_Sound(var M: TMsg);
1778 var
1779 Name: string;
1780 X, Y: Integer;
1781 Pos: Boolean;
1782 begin
1783 Name := M.ReadString();
1784 Pos := M.ReadByte() <> 0;
1785 if Pos then
1786 begin
1787 X := M.ReadLongInt();
1788 Y := M.ReadLongInt();
1789 g_Sound_PlayExAt(Name, X, Y);
1790 end
1791 else
1792 g_Sound_PlayEx(Name);
1793 end;
1795 procedure MC_RECV_CreateShot(var M: TMsg);
1796 var
1797 I, X, Y, XV, YV: Integer;
1798 Timeout: LongWord;
1799 Target, Spawner: Word;
1800 ShType: Byte;
1801 begin
1802 I := M.ReadLongInt();
1803 ShType := M.ReadByte();
1804 Target := M.ReadWord();
1805 Spawner := M.ReadWord();
1806 Timeout := M.ReadLongWord();
1807 X := M.ReadLongInt();
1808 Y := M.ReadLongInt();
1809 XV := M.ReadLongInt();
1810 YV := M.ReadLongInt();
1812 I := g_Weapon_CreateShot(I, ShType, Spawner, Target, X, Y, XV, YV);
1813 if (Shots <> nil) and (I <= High(Shots)) then
1814 begin
1815 Shots[I].Timeout := Timeout;
1816 //Shots[I].Target := Target; // TODO: find a use for Target later
1817 end;
1818 end;
1820 procedure MC_RECV_UpdateShot(var M: TMsg);
1821 var
1822 I, TX, TY, TXV, TYV: Integer;
1823 begin
1824 I := M.ReadLongInt();
1825 TX := M.ReadLongInt();
1826 TY := M.ReadLongInt();
1827 TXV := M.ReadLongInt();
1828 TYV := M.ReadLongInt();
1830 if (Shots <> nil) and (I <= High(Shots)) then
1831 with (Shots[i]) do
1832 begin
1833 Obj.X := TX;
1834 Obj.Y := TY;
1835 Obj.Vel.X := TXV;
1836 Obj.Vel.Y := TYV;
1837 end;
1838 end;
1840 procedure MC_RECV_DeleteShot(var M: TMsg);
1841 var
1842 I, X, Y: Integer;
1843 L: Boolean;
1844 begin
1845 if not gGameOn then Exit;
1846 I := M.ReadLongInt();
1847 L := (M.ReadByte() <> 0);
1848 X := M.ReadLongInt();
1849 Y := M.ReadLongInt();
1851 g_Weapon_DestroyShot(I, X, Y, L);
1852 end;
1854 procedure MC_RECV_GameStats(var M: TMsg);
1855 begin
1856 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1857 begin
1858 gTeamStat[TEAM_RED].Goals := M.ReadSmallInt();
1859 gTeamStat[TEAM_BLUE].Goals := M.ReadSmallInt();
1860 end
1861 else
1862 if gGameSettings.GameMode = GM_COOP then
1863 begin
1864 gCoopMonstersKilled := M.ReadWord();
1865 gCoopSecretsFound := M.ReadWord();
1866 end;
1867 end;
1869 procedure MC_RECV_CoopStats(var M: TMsg);
1870 begin
1871 gTotalMonsters := M.ReadLongInt();
1872 gSecretsCount := M.ReadLongInt();
1873 gCoopTotalMonstersKilled := M.ReadWord();
1874 gCoopTotalSecretsFound := M.ReadWord();
1875 gCoopTotalMonsters := M.ReadWord();
1876 gCoopTotalSecrets := M.ReadWord();
1877 end;
1879 procedure MC_RECV_GameEvent(var M: TMsg);
1880 var
1881 EvType: Byte;
1882 EvNum: Integer;
1883 EvStr: string;
1884 EvTime: LongWord;
1885 BHash: Boolean;
1886 EvHash: TMD5Digest;
1887 pl: TPlayer;
1888 i1, i2: TStrings_Locale;
1889 pln: String;
1890 cnt: Byte;
1891 goodCmd: Boolean = true;
1892 begin
1893 FillChar(EvHash, Sizeof(EvHash), 0);
1894 EvType := M.ReadByte();
1895 EvNum := M.ReadLongInt();
1896 EvStr := M.ReadString();
1897 gLastMap := M.ReadByte() <> 0;
1898 if gLastMap and (gGameSettings.GameMode = GM_COOP) then gStatsOff := True;
1899 gStatsPressed := True;
1900 EvTime := M.ReadLongWord();
1901 BHash := M.ReadByte() <> 0;
1902 if BHash then
1903 EvHash := M.ReadMD5();
1905 gTime := EvTime;
1907 if (g_Res_received_map_start <> 0) then
1908 begin
1909 if (g_Res_received_map_start < 0) then exit;
1910 goodCmd := false;
1911 case EvType of
1912 NET_EV_MAPSTART: goodCmd := true;
1913 NET_EV_MAPEND: goodCmd := true;
1914 NET_EV_PLAYER_KICK: goodCmd := true;
1915 NET_EV_PLAYER_BAN: goodCmd := true;
1916 NET_EV_LMS_WARMUP: goodCmd := true;
1917 end;
1918 if not goodCmd then exit;
1919 end;
1921 case EvType of
1922 NET_EV_MAPSTART:
1923 begin
1924 if (g_Res_received_map_start <> 0) then
1925 begin
1926 g_Res_received_map_start := -1;
1927 end
1928 else
1929 begin
1930 gGameOn := False;
1931 g_Game_ClearLoading();
1932 g_Game_StopAllSounds(True);
1934 gSwitchGameMode := Byte(EvNum);
1935 gGameSettings.GameMode := gSwitchGameMode;
1937 gWADHash := EvHash;
1938 if not g_Game_StartMap(false{asMegawad}, EvStr, True) then
1939 begin
1940 if not isWadPath(EvStr) then
1941 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + EvStr]))
1942 else
1943 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [EvStr]));
1944 Exit;
1945 end;
1947 MC_SEND_FullStateRequest;
1948 end;
1949 end;
1951 NET_EV_MAPEND:
1952 begin
1953 gLMSRespawn := LMS_RESPAWN_NONE;
1954 gLMSRespawnTime := 0;
1955 if (g_Res_received_map_start <> 0) then
1956 begin
1957 g_Res_received_map_start := -1;
1958 end
1959 else
1960 begin
1961 gMissionFailed := EvNum <> 0;
1962 gExit := EXIT_ENDLEVELCUSTOM;
1963 end;
1964 end;
1966 NET_EV_RCON:
1967 begin
1968 case EvNum of
1969 NET_RCON_NOAUTH:
1970 g_Console_Add(_lc[I_NET_RCON_NOAUTH], True);
1971 NET_RCON_PWGOOD:
1972 g_Console_Add(_lc[I_NET_RCON_PWD_VALID], True);
1973 NET_RCON_PWBAD:
1974 g_Console_Add(_lc[I_NET_RCON_PWD_INVALID], True);
1975 end;
1976 end;
1978 NET_EV_CHANGE_TEAM:
1979 begin
1980 if NetDeafLevel < 2 then
1981 begin
1982 if EvNum = TEAM_RED then
1983 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True);
1984 if EvNum = TEAM_BLUE then
1985 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True);
1986 end;
1987 end;
1989 NET_EV_PLAYER_KICK:
1990 begin
1991 g_Console_Add(Format(_lc[I_PLAYER_KICK], [EvStr]), True);
1992 if (g_Res_received_map_start <> 0) then g_Res_received_map_start := -1;
1993 end;
1995 NET_EV_PLAYER_BAN:
1996 begin
1997 g_Console_Add(Format(_lc[I_PLAYER_BAN], [EvStr]), True);
1998 if (g_Res_received_map_start <> 0) then g_Res_received_map_start := -1;
1999 end;
2001 NET_EV_LMS_WARMUP:
2002 begin
2003 if EvNum > 0 then
2004 begin
2005 gLMSRespawn := LMS_RESPAWN_WARMUP;
2006 gLMSRespawnTime := gTime + EvNum;
2007 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [EvNum div 1000]), True);
2008 end
2009 else if gPlayer1 = nil then
2010 begin
2011 g_Console_Add(_lc[I_PLAYER_SPECT4], True);
2012 end;
2013 end;
2015 NET_EV_LMS_SURVIVOR:
2016 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True);
2018 NET_EV_BIGTEXT:
2019 if NetDeafLevel < 2 then g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum));
2021 NET_EV_SCORE:
2022 begin
2023 pl := g_Player_Get(EvNum and $FFFF);
2024 if pl = nil then
2025 pln := '?'
2026 else
2027 pln := pl.Name;
2028 cnt := (EvNum shr 16) and $FF;
2029 if Pos('w', EvStr) = 0 then
2030 begin
2031 // Default score
2032 if Pos('t', EvStr) = 0 then
2033 begin
2034 // Player +/- score
2035 if Pos('-', EvStr) = 0 then
2036 begin
2037 if Pos('e', EvStr) = 0 then
2038 i1 := I_PLAYER_SCORE_ADD_OWN
2039 else
2040 i1 := I_PLAYER_SCORE_ADD_ENEMY;
2041 end else
2042 begin
2043 if Pos('e', EvStr) = 0 then
2044 i1 := I_PLAYER_SCORE_SUB_OWN
2045 else
2046 i1 := I_PLAYER_SCORE_SUB_ENEMY;
2047 end;
2048 // Which team
2049 if Pos('r', EvStr) > 0 then
2050 i2 := I_PLAYER_SCORE_TO_RED
2051 else
2052 i2 := I_PLAYER_SCORE_TO_BLUE;
2053 g_Console_Add(Format(_lc[i1], [pln, cnt, _lc[i2]]), True);
2054 end else
2055 begin
2056 // Team +/- score
2057 if Pos('-', EvStr) = 0 then
2058 i1 := I_PLAYER_SCORE_ADD_TEAM
2059 else
2060 i1 := I_PLAYER_SCORE_SUB_TEAM;
2061 // Which team
2062 if Pos('r', EvStr) > 0 then
2063 i2 := I_PLAYER_SCORE_RED
2064 else
2065 i2 := I_PLAYER_SCORE_BLUE;
2066 g_Console_Add(Format(_lc[i1], [_lc[i2], cnt]), True);
2067 end;
2068 end else
2069 begin
2070 // Game Win
2071 if Pos('e', EvStr) = 0 then
2072 i1 := I_PLAYER_SCORE_WIN_OWN
2073 else
2074 i1 := I_PLAYER_SCORE_WIN_ENEMY;
2075 // Which team
2076 if Pos('r', EvStr) > 0 then
2077 i2 := I_PLAYER_SCORE_TO_RED
2078 else
2079 i2 := I_PLAYER_SCORE_TO_BLUE;
2080 g_Console_Add(Format(_lc[i1], [pln, _lc[i2]]), True);
2081 end;
2082 end;
2084 NET_EV_SCORE_MSG:
2085 begin
2086 if EvNum = TEAM_RED then
2087 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
2088 if EvNum = TEAM_BLUE then
2089 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
2090 if EvNum = -TEAM_RED then
2091 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
2092 if EvNum = -TEAM_BLUE then
2093 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
2094 end;
2096 NET_EV_LMS_START:
2097 begin
2098 g_Player_RemoveAllCorpses;
2099 gLMSRespawn := LMS_RESPAWN_NONE;
2100 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
2101 end;
2103 NET_EV_LMS_WIN:
2104 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(EvStr)]), 144);
2106 NET_EV_TLMS_WIN:
2107 begin
2108 if EvNum = TEAM_RED then
2109 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
2110 if EvNum = TEAM_BLUE then
2111 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
2112 end;
2114 NET_EV_LMS_LOSE:
2115 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
2117 NET_EV_LMS_DRAW:
2118 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
2120 NET_EV_LMS_NOSPAWN:
2121 g_Console_Add(_lc[I_PLAYER_SPECT4], True);
2123 NET_EV_KILLCOMBO:
2124 g_Game_Announce_KillCombo(EvNum);
2126 NET_EV_PLAYER_TOUCH:
2127 begin
2128 pl := g_Player_Get(EvNum);
2129 if pl <> nil then
2130 pl.Touch();
2131 end;
2133 NET_EV_SECRET:
2134 begin
2135 pl := g_Player_Get(EvNum);
2136 if pl <> nil then
2137 begin
2138 g_Console_Add(Format(_lc[I_PLAYER_SECRET], [pl.Name]), True);
2139 g_Sound_PlayEx('SOUND_GAME_SECRET');
2140 end;
2141 end;
2143 NET_EV_INTER_READY:
2144 begin
2145 pl := g_Player_Get(EvNum);
2146 if pl <> nil then pl.FReady := (EvStr = 'Y');
2147 end;
2148 end;
2149 end;
2151 procedure MC_RECV_FlagPos(var M: TMsg);
2152 var
2153 Fl: Byte;
2154 begin
2155 Fl := M.ReadByte();
2156 if Fl = FLAG_NONE then Exit;
2157 gFlags[Fl].Obj.X := M.ReadLongInt();
2158 gFlags[Fl].Obj.Y := M.ReadLongInt();
2159 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
2160 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
2161 end;
2163 procedure MC_RECV_FlagEvent(var M: TMsg);
2164 var
2165 PID: Word;
2166 Pl: TPlayer;
2167 EvType: Byte;
2168 Fl, a: Byte;
2169 Quiet: Boolean;
2170 s, ts: string;
2171 begin
2172 EvType := M.ReadByte();
2173 Fl := M.ReadByte();
2175 if Fl = FLAG_NONE then Exit;
2177 Quiet := (M.ReadByte() <> 0);
2178 PID := M.ReadWord();
2180 gFlags[Fl].State := M.ReadByte();
2181 gFlags[Fl].CaptureTime := M.ReadLongWord();
2182 gFlags[Fl].Obj.X := M.ReadLongInt();
2183 gFlags[Fl].Obj.Y := M.ReadLongInt();
2184 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
2185 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
2186 gFlags[Fl].Direction := TDirection(M.ReadByte());
2188 Pl := g_Player_Get(PID);
2189 if (Pl = nil) and
2190 (EvType <> FLAG_STATE_NORMAL) and
2191 (EvType <> FLAG_STATE_DROPPED) and
2192 (EvType <> FLAG_STATE_RETURNED) then
2193 Exit;
2195 case EvType of
2196 FLAG_STATE_NORMAL:
2197 begin
2198 if Quiet or (Pl = nil) then Exit;
2200 if Fl = FLAG_RED then
2201 s := _lc[I_PLAYER_FLAG_RED]
2202 else
2203 s := _lc[I_PLAYER_FLAG_BLUE];
2205 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2207 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2208 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2209 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2210 a := 0
2211 else
2212 a := 1;
2214 if not sound_ret_flag[a].IsPlaying() then
2215 sound_ret_flag[a].Play();
2216 end;
2218 FLAG_STATE_CAPTURED:
2219 begin
2220 if (Pl <> nil) then Pl.SetFlag(Fl);
2222 if Quiet then Exit;
2224 if Fl = FLAG_RED then
2225 s := _lc[I_PLAYER_FLAG_RED]
2226 else
2227 s := _lc[I_PLAYER_FLAG_BLUE];
2229 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [Pl.Name, s]), True);
2230 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
2232 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2233 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2234 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2235 a := 0
2236 else
2237 a := 1;
2239 if not sound_get_flag[a].IsPlaying() then
2240 sound_get_flag[a].Play();
2241 end;
2243 FLAG_STATE_DROPPED:
2244 begin
2245 if (Pl <> nil) then Pl.SetFlag(FLAG_NONE);
2247 if Quiet or (Pl = nil) then Exit;
2249 if Fl = FLAG_RED then
2250 s := _lc[I_PLAYER_FLAG_RED]
2251 else
2252 s := _lc[I_PLAYER_FLAG_BLUE];
2254 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [Pl.Name, s]), True);
2255 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
2257 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2258 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2259 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2260 a := 0
2261 else
2262 a := 1;
2264 if not sound_lost_flag[a].IsPlaying() then
2265 sound_lost_flag[a].Play();
2266 end;
2268 FLAG_STATE_SCORED:
2269 begin
2270 g_Map_ResetFlag(FLAG_RED);
2271 g_Map_ResetFlag(FLAG_BLUE);
2272 if Quiet or (Pl = nil) then Exit;
2273 Pl.SetFlag(FLAG_NONE);
2275 if Fl = FLAG_RED then
2276 s := _lc[I_PLAYER_FLAG_RED]
2277 else
2278 s := _lc[I_PLAYER_FLAG_BLUE];
2280 ts := Format('%.4d', [gFlags[Fl].CaptureTime]);
2281 Insert('.', ts, Length(ts) + 1 - 3);
2282 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [Pl.Name, s, ts]), True);
2283 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
2285 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2286 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2287 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2288 a := 0
2289 else
2290 a := 1;
2292 if not sound_cap_flag[a].IsPlaying() then
2293 sound_cap_flag[a].Play();
2294 end;
2296 FLAG_STATE_RETURNED:
2297 begin
2298 g_Map_ResetFlag(Fl);
2299 if Quiet then Exit;
2301 if Fl = FLAG_RED then
2302 s := _lc[I_PLAYER_FLAG_RED]
2303 else
2304 s := _lc[I_PLAYER_FLAG_BLUE];
2306 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2308 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2309 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2310 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2311 a := 0
2312 else
2313 a := 1;
2315 if not sound_ret_flag[a].IsPlaying() then
2316 sound_ret_flag[a].Play();
2317 end;
2318 end;
2319 end;
2321 procedure MC_RECV_GameSettings(var M: TMsg);
2322 begin
2323 gGameSettings.GameMode := M.ReadByte();
2324 gGameSettings.GoalLimit := M.ReadWord();
2325 gGameSettings.TimeLimit := M.ReadWord();
2326 gGameSettings.MaxLives := M.ReadByte();
2327 gGameSettings.Options := M.ReadLongWord();
2328 end;
2330 // PLAYER
2332 function MC_RECV_PlayerCreate(var M: TMsg): Word;
2333 var
2334 PID, DID: Word;
2335 PName, Model: string;
2336 Color: TRGB;
2337 T: Byte;
2338 Pl: TPlayer;
2339 begin
2340 PID := M.ReadWord();
2341 Pl := g_Player_Get(PID);
2343 PName := M.ReadString();
2344 Model := M.ReadString();
2345 Color.R := M.ReadByte();
2346 Color.G := M.ReadByte();
2347 Color.B := M.ReadByte();
2348 T := M.ReadByte();
2350 Result := 0;
2351 if (PID <> NetPlrUID1) and (PID <> NetPlrUID2) then
2352 begin
2353 if (Pl <> nil) then Exit;
2354 DID := g_Player_Create(Model, Color, T, False);
2355 with g_Player_Get(DID) do
2356 begin
2357 UID := PID;
2358 Name := PName;
2359 Reset(True);
2360 end;
2361 end
2362 else
2363 begin
2364 if (PID = NetPlrUID1) and (gPlayer1 <> nil) then begin
2365 gPlayer1.UID := PID;
2366 gPlayer1.Model.SetColor(Color.R, Color.G, Color.B);
2367 gPlayer1.ChangeTeam(T);
2368 end;
2369 if (PID = NetPlrUID2) and (gPlayer2 <> nil) then begin
2370 gPlayer2.UID := PID;
2371 gPlayer2.Model.SetColor(Color.R, Color.G, Color.B);
2372 gPlayer2.ChangeTeam(T);
2373 end;
2374 end;
2376 if NetDeafLevel < 3 then
2377 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
2378 e_WriteLog('NET: Player ' + PName + ' [' + IntToStr(PID) + '] added.', TMsgType.Notify);
2379 Result := PID;
2380 end;
2382 function MC_RECV_PlayerPos(var M: TMsg): Word;
2383 var
2384 GT: LongWord;
2385 PID: Word;
2386 kByte: Word;
2387 Pl: TPlayer;
2388 Dir: Byte;
2389 TmpX, TmpY: Integer;
2390 begin
2391 Result := 0;
2393 GT := M.ReadLongWord();
2394 if GT < gTime - NET_MAX_DIFFTIME then
2395 begin
2396 gTime := GT;
2397 Exit;
2398 end;
2399 gTime := GT;
2401 PID := M.ReadWord();
2402 Pl := g_Player_Get(PID);
2404 if Pl = nil then Exit;
2406 Result := PID;
2408 with Pl do
2409 begin
2410 FPing := M.ReadWord();
2411 FLoss := M.ReadByte();
2412 kByte := M.ReadWord();
2413 Dir := M.ReadByte();
2415 TmpX := M.ReadLongInt();
2416 TmpY := M.ReadLongInt();
2418 ReleaseKeys;
2420 if LongBool(kByte and NET_KEY_CHAT) then
2421 PressKey(KEY_CHAT, 10000)
2422 else
2423 begin
2424 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
2425 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
2426 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
2427 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
2428 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
2429 end;
2431 JustTeleported := LongBool(kByte and NET_KEY_FORCEDIR);
2433 if ((Pl <> gPlayer1) and (Pl <> gPlayer2)) or JustTeleported then
2434 SetDirection(TDirection(Dir));
2436 GameVelX := M.ReadLongInt();
2437 GameVelY := M.ReadLongInt();
2438 GameAccelX := M.ReadLongInt();
2439 GameAccelY := M.ReadLongInt();
2440 SetLerp(TmpX, TmpY);
2441 if NetForcePlayerUpdate then Update();
2442 end;
2443 end;
2445 function MC_RECV_PlayerStats(var M: TMsg): Word;
2446 var
2447 PID: Word;
2448 Pl: TPlayer;
2449 I, OldFire: Integer;
2450 OldJet, Flam: Boolean;
2451 NewTeam: Byte;
2452 begin
2453 PID := M.ReadWord();
2454 Pl := g_Player_Get(PID);
2455 Result := 0;
2456 if Pl = nil then
2457 Exit;
2459 with Pl do
2460 begin
2461 alive := (M.ReadByte() <> 0);
2462 GodMode := (M.ReadByte() <> 0);
2463 Health := M.ReadLongInt();
2464 Armor := M.ReadLongInt();
2465 Air := M.ReadLongInt();
2466 JetFuel := M.ReadLongInt();
2467 Lives := M.ReadByte();
2468 NewTeam := M.ReadByte();
2470 for I := WP_FIRST to WP_LAST do
2471 FWeapon[I] := (M.ReadByte() <> 0);
2473 for I := A_BULLETS to A_HIGH do
2474 FAmmo[I] := M.ReadWord();
2476 for I := A_BULLETS to A_HIGH do
2477 FMaxAmmo[I] := M.ReadWord();
2479 for I := MR_SUIT to MR_MAX do
2480 FMegaRulez[I] := M.ReadLongWord();
2482 FRulez := [];
2483 if (M.ReadByte() <> 0) then
2484 FRulez := FRulez + [R_ITEM_BACKPACK];
2485 if (M.ReadByte() <> 0) then
2486 FRulez := FRulez + [R_KEY_RED];
2487 if (M.ReadByte() <> 0) then
2488 FRulez := FRulez + [R_KEY_GREEN];
2489 if (M.ReadByte() <> 0) then
2490 FRulez := FRulez + [R_KEY_BLUE];
2491 if (M.ReadByte() <> 0) then
2492 FRulez := FRulez + [R_BERSERK];
2494 Frags := M.ReadLongInt();
2495 Death := M.ReadLongInt();
2497 SetWeapon(M.ReadByte());
2499 FSpectator := M.ReadByte() <> 0;
2500 if FSpectator then
2501 begin
2502 if UID = NetPlrUID1 then
2503 begin
2504 gSpectLatchPID1 := UID;
2505 gPlayer1 := nil;
2506 end;
2507 if UID = NetPlrUID2 then
2508 begin
2509 gSpectLatchPID2 := UID;
2510 gPlayer2 := nil;
2511 end;
2512 end
2513 else
2514 begin
2515 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) and (UID = gSpectLatchPID1) then
2516 begin
2517 gPlayer1 := Pl;
2518 gSpectLatchPID1 := 0;
2519 end;
2520 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) and (UID = gSpectLatchPID2) then
2521 begin
2522 gPlayer2 := Pl;
2523 gSpectLatchPID2 := 0;
2524 end;
2525 end;
2526 FGhost := M.ReadByte() <> 0;
2527 FPhysics := M.ReadByte() <> 0;
2528 FNoRespawn := M.ReadByte() <> 0;
2529 OldJet := FJetpack;
2530 FJetpack := M.ReadByte() <> 0;
2531 OldFire := FFireTime;
2532 FFireTime := M.ReadLongInt();
2533 if (OldFire <= 0) and (FFireTime > 0) then
2534 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
2535 Flam := M.ReadByte() <> 0;
2536 FSpawnInvul := M.ReadLongInt();
2537 if OldJet and not FJetpack then
2538 JetpackOff
2539 else if not OldJet and FJetpack then
2540 JetpackOn;
2541 if FFlaming and not Flam then
2542 FlamerOff;
2543 if Team <> NewTeam then
2544 Pl.ChangeTeam(NewTeam);
2545 end;
2547 Result := PID;
2548 end;
2550 function MC_RECV_PlayerDamage(var M: TMsg): Word;
2551 var
2552 PID: Word;
2553 Pl: TPlayer;
2554 Kind: Byte;
2555 Attacker, Value: Word;
2556 VX, VY: Integer;
2557 begin
2558 Result := 0;
2559 if not gGameOn then Exit;
2560 PID := M.ReadWord();
2561 Pl := g_Player_Get(PID);
2562 if Pl = nil then Exit;
2564 Kind := M.ReadByte();
2565 Attacker := M.ReadWord();
2566 Value := M.ReadWord();
2567 VX := M.ReadWord();
2568 VY := M.ReadWord();
2570 with Pl do
2571 Damage(Value, Attacker, VX, VY, Kind);
2573 Result := PID;
2574 end;
2576 function MC_RECV_PlayerDeath(var M: TMsg): Word;
2577 var
2578 PID: Word;
2579 Pl: TPlayer;
2580 KillType, DeathType: Byte;
2581 Attacker: Word;
2582 begin
2583 Result := 0;
2584 if not gGameOn then Exit;
2585 PID := M.ReadWord();
2586 Pl := g_Player_Get(PID);
2587 if Pl = nil then Exit;
2589 KillType := M.ReadByte();
2590 DeathType := M.ReadByte();
2591 Attacker := M.ReadWord();
2593 with Pl do
2594 begin
2595 Kill(KillType, Attacker, DeathType);
2596 SoftReset;
2597 end;
2598 end;
2600 function MC_RECV_PlayerDelete(var M: TMsg): Word;
2601 var
2602 PID: Word;
2603 Pl: TPlayer;
2604 begin
2605 PID := M.ReadWord();
2606 Pl := g_Player_Get(PID);
2607 Result := 0;
2608 if Pl = nil then Exit;
2610 if NetDeafLevel < 3 then
2611 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2612 e_WriteLog('NET: Player ' + Pl.Name + ' [' + IntToStr(PID) + '] removed.', TMsgType.Notify);
2614 g_Player_Remove(PID);
2616 Result := PID;
2617 end;
2619 function MC_RECV_PlayerFire(var M: TMsg): Word;
2620 var
2621 PID: Word;
2622 Weap: Byte;
2623 Pl: TPlayer;
2624 X, Y, AX, AY: Integer;
2625 SHID: Integer;
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 Weap := M.ReadByte();
2634 X := M.ReadLongInt();
2635 Y := M.ReadLongInt();
2636 AX := M.ReadLongInt();
2637 AY := M.ReadLongInt();
2638 SHID := M.ReadLongInt();
2640 with Pl do
2641 if alive then NetFire(Weap, X, Y, AX, AY, SHID);
2642 end;
2644 procedure MC_RECV_PlayerSettings(var M: TMsg);
2645 var
2646 TmpName: string;
2647 TmpModel: string;
2648 TmpColor: TRGB;
2649 TmpTeam: Byte;
2650 Pl: TPlayer;
2651 PID: Word;
2652 begin
2653 PID := M.ReadWord();
2654 Pl := g_Player_Get(PID);
2655 if Pl = nil then Exit;
2657 TmpName := M.ReadString();
2658 TmpModel := M.ReadString();
2659 TmpColor.R := M.ReadByte();
2660 TmpColor.G := M.ReadByte();
2661 TmpColor.B := M.ReadByte();
2662 TmpTeam := M.ReadByte();
2664 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
2665 begin
2666 Pl.ChangeTeam(TmpTeam);
2667 if gPlayer1 = Pl then
2668 gPlayer1Settings.Team := TmpTeam;
2669 if gPlayer2 = Pl then
2670 gPlayer2Settings.Team := TmpTeam;
2671 end else
2672 Pl.SetColor(TmpColor);
2674 if Pl.Name <> TmpName then
2675 begin
2676 if NetDeafLevel < 3 then
2677 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
2678 Pl.Name := TmpName;
2679 end;
2681 if TmpModel <> Pl.Model.Name then
2682 Pl.SetModel(TmpModel);
2683 end;
2685 // ITEM
2687 procedure MC_RECV_ItemSpawn(var M: TMsg);
2688 var
2689 ID: Word;
2690 AID: DWord;
2691 X, Y, VX, VY: Integer;
2692 T: Byte;
2693 Quiet, Fall{, Resp}: Boolean;
2694 Anim: TAnimation;
2695 it: PItem;
2696 begin
2697 if not gGameOn then Exit;
2698 ID := M.ReadWord();
2699 Quiet := M.ReadByte() <> 0;
2700 T := M.ReadByte();
2701 Fall := M.ReadByte() <> 0;
2702 {Resp :=} M.ReadByte();
2703 X := M.ReadLongInt();
2704 Y := M.ReadLongInt();
2705 VX := M.ReadLongInt();
2706 VY := M.ReadLongInt();
2708 g_Items_Create(X, Y, T and $7F, Fall, False, False, ID);
2709 if ((T and $80) <> 0) then g_Items_SetDrop(ID);
2711 it := g_Items_ByIdx(ID);
2712 it.Obj.Vel.X := VX;
2713 it.Obj.Vel.Y := VY;
2715 if not Quiet then
2716 begin
2717 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
2718 if g_Frames_Get(AID, 'FRAMES_ITEM_RESPAWN') then
2719 begin
2720 Anim := TAnimation.Create(AID, False, 4);
2721 g_GFX_OnceAnim(X+(it.Obj.Rect.Width div 2)-16, Y+(it.Obj.Rect.Height div 2)-16, Anim);
2722 Anim.Free();
2723 end;
2724 end;
2725 end;
2727 procedure MC_RECV_ItemDestroy(var M: TMsg);
2728 var
2729 ID: Word;
2730 Quiet: Boolean;
2731 begin
2732 if not gGameOn then Exit;
2733 ID := M.ReadWord();
2734 Quiet := M.ReadByte() <> 0;
2736 if not g_Items_ValidId(ID) then exit;
2738 if not Quiet then g_Items_EmitPickupSound(ID);
2740 g_Items_Remove(ID);
2741 end;
2743 procedure MC_RECV_ItemPos(var M: TMsg);
2744 var
2745 ID: Word;
2746 X, Y, VX, VY: Integer;
2747 it: PItem;
2748 begin
2749 if not gGameOn then Exit;
2751 ID := M.ReadWord();
2752 X := M.ReadLongInt();
2753 Y := M.ReadLongInt();
2754 VX := M.ReadLongInt();
2755 VY := M.ReadLongInt();
2757 if g_Items_ValidId(ID) then
2758 begin
2759 it := g_Items_ByIdx(ID);
2760 it.Obj.X := X;
2761 it.Obj.Y := Y;
2762 it.Obj.Vel.X := VX;
2763 it.Obj.Vel.Y := VY;
2764 it.positionChanged();
2765 end;
2766 end;
2768 // PANEL
2770 procedure MC_RECV_PanelTexture(var M: TMsg);
2771 var
2772 TP: TPanel;
2773 PGUID: Integer;
2774 Tex, Fr: Integer;
2775 Loop, Cnt: Byte;
2776 begin
2777 if not gGameOn then Exit;
2779 PGUID := Integer(M.ReadLongWord());
2780 Tex := M.ReadLongInt();
2781 Fr := M.ReadLongInt();
2782 Cnt := M.ReadByte();
2783 Loop := M.ReadByte();
2785 TP := g_Map_PanelByGUID(PGUID);
2786 if (TP <> nil) then
2787 begin
2788 // switch texture
2789 TP.SetTexture(Tex, Loop);
2790 TP.SetFrame(Fr, Cnt);
2791 end;
2792 end;
2794 procedure MC_RECV_PanelState(var M: TMsg);
2795 var
2796 PGUID: Integer;
2797 E: Boolean;
2798 Lift: Byte;
2799 X, Y, W, H: Integer;
2800 TP: TPanel;
2801 speedX, speedY, startX, startY, endX, endY: Integer;
2802 sizeSpX, sizeSpY, sizeEX, sizeEY: Integer;
2803 mpflags: Byte;
2804 begin
2805 if not gGameOn then Exit;
2807 PGUID := Integer(M.ReadLongWord());
2808 E := (M.ReadByte() <> 0);
2809 Lift := M.ReadByte();
2810 X := M.ReadLongInt();
2811 Y := M.ReadLongInt();
2812 W := M.ReadWord();
2813 H := M.ReadWord();
2814 // mplats
2815 speedX := M.ReadLongInt();
2816 speedY := M.ReadLongInt();
2817 startX := M.ReadLongInt();
2818 startY := M.ReadLongInt();
2819 endX := M.ReadLongInt();
2820 endY := M.ReadLongInt();
2821 sizeSpX := M.ReadLongInt();
2822 sizeSpY := M.ReadLongInt();
2823 sizeEX := M.ReadLongInt();
2824 sizeEY := M.ReadLongInt();
2825 mpflags := M.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2827 TP := g_Map_PanelByGUID(PGUID);
2828 if (TP = nil) then exit;
2830 // update lifts state
2831 if TP.isGLift then g_Map_SetLiftGUID(PGUID, Lift);
2833 // update enabled/disabled state for all panels
2834 if E then g_Map_EnableWallGUID(PGUID) else g_Map_DisableWallGUID(PGUID);
2836 // update panel position, as it can be moved (mplat)
2837 TP.X := X;
2838 TP.Y := Y;
2839 TP.Width := W;
2840 TP.Height := H;
2841 // update mplat state
2842 TP.movingSpeedX := speedX;
2843 TP.movingSpeedY := speedY;
2844 TP.movingStartX := startX;
2845 TP.movingStartY := startY;
2846 TP.movingEndX := endX;
2847 TP.movingEndY := endY;
2848 TP.sizeSpeedX := sizeSpX;
2849 TP.sizeSpeedY := sizeSpY;
2850 TP.sizeEndX := sizeEX;
2851 TP.sizeEndY := sizeEY;
2852 TP.movingActive := ((mpflags and 1) <> 0);
2853 TP.moveOnce := ((mpflags and 2) <> 0);
2854 // notify panel of it's position/size change, so it can fix other internal structures
2855 TP.positionChanged();
2856 end;
2858 // TRIGGERS
2860 procedure MC_RECV_TriggerSound(var M: TMsg);
2861 var
2862 SPlaying: Boolean;
2863 SPos, SID: LongWord;
2864 SCount: LongInt;
2865 I: Integer;
2866 begin
2867 if not gGameOn then Exit;
2868 if gTriggers = nil then Exit;
2870 SID := M.ReadLongWord();
2871 SPlaying := M.ReadByte() <> 0;
2872 SPos := M.ReadLongWord();
2873 SCount := M.ReadLongInt();
2875 for I := Low(gTriggers) to High(gTriggers) do
2876 if gTriggers[I].TriggerType = TRIGGER_SOUND then
2877 if gTriggers[I].ClientID = SID then
2878 with gTriggers[I] do
2879 begin
2880 if Sound <> nil then
2881 begin
2882 if SPlaying then
2883 begin
2884 if tgcLocal then
2885 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), tgcVolume/255.0)
2886 else
2887 Sound.PlayPanVolume((tgcPan-127.0)/128.0, tgcVolume/255.0);
2888 Sound.SetPosition(SPos);
2889 end
2890 else
2891 if Sound.IsPlaying then Sound.Stop;
2892 end;
2894 SoundPlayCount := SCount;
2895 end;
2896 end;
2898 procedure MC_RECV_TriggerMusic(var M: TMsg);
2899 var
2900 MName: string;
2901 MPlaying: Boolean;
2902 MPos: LongWord;
2903 MPaused: Boolean;
2904 begin
2905 if not gGameOn then Exit;
2907 MName := M.ReadString();
2908 MPlaying := M.ReadByte() <> 0;
2909 MPos := M.ReadLongWord();
2910 MPaused := M.ReadByte() <> 0;
2911 MPos := MPos+1; //k8: stfu, fpc!
2913 if MPlaying then
2914 begin
2915 gMusic.SetByName(MName);
2916 gMusic.Play(True);
2917 // gMusic.SetPosition(MPos);
2918 gMusic.SpecPause := MPaused;
2919 end
2920 else
2921 if gMusic.IsPlaying then gMusic.Stop;
2922 end;
2924 // MONSTERS
2926 procedure MC_RECV_MonsterSpawn(var M: TMsg);
2927 var
2928 ID: Word;
2929 MType, MState, MDir, MAnim, MBehav: Byte;
2930 X, Y, VX, VY, MTargTime, MHealth, MAmmo, MSleep: Integer;
2931 MTarg: Word;
2932 Mon: TMonster;
2933 begin
2934 ID := M.ReadWord();
2935 Mon := g_Monsters_ByUID(ID);
2936 if Mon <> nil then
2937 Exit;
2939 MType := M.ReadByte();
2940 MState := M.ReadByte();
2941 MAnim := M.ReadByte();
2942 MTarg := M.ReadWord();
2943 MTargTime := M.ReadLongInt();
2944 MBehav := M.ReadByte();
2945 MSleep := M.ReadLongInt();
2946 MHealth := M.ReadLongInt();
2947 MAmmo := M.ReadLongInt();
2949 X := M.ReadLongInt();
2950 Y := M.ReadLongInt();
2951 VX := M.ReadLongInt();
2952 VY := M.ReadLongInt();
2953 MDir := M.ReadByte();
2955 g_Monsters_Create(MType, X, Y, TDirection(MDir), False, ID);
2956 Mon := g_Monsters_ByUID(ID);
2957 if Mon = nil then
2958 Exit;
2960 with Mon do
2961 begin
2963 MonsterAnim := MAnim;
2964 MonsterTargetUID := MTarg;
2965 MonsterTargetTime := MTargTime;
2966 MonsterBehaviour := MBehav;
2967 MonsterSleep := MSleep;
2968 MonsterAmmo := MAmmo;
2969 SetHealth(MHealth);
2971 SetState(MState);
2973 setPosition(X, Y); // this will call positionChanged();
2974 GameVelX := VX;
2975 GameVelY := VY;
2976 end;
2977 end;
2979 procedure MC_RECV_MonsterPos(var M: TMsg);
2980 var
2981 Mon: TMonster;
2982 ID: Word;
2983 X, Y: Integer;
2984 begin
2985 ID := M.ReadWord();
2986 Mon := g_Monsters_ByUID(ID);
2987 if Mon = nil then
2988 Exit;
2990 with Mon do
2991 begin
2992 X := M.ReadLongInt();
2993 Y := M.ReadLongInt();
2994 Mon.setPosition(X, Y); // this will call `positionChanged()`
2995 GameVelX := M.ReadLongInt();
2996 GameVelY := M.ReadLongInt();
2997 GameDirection := TDirection(M.ReadByte());
2998 end;
2999 end;
3001 procedure MC_RECV_MonsterState(var M: TMsg);
3002 var
3003 ID, OldFire: Integer;
3004 MState, MFAnm: Byte;
3005 Mon: TMonster;
3006 AnimRevert: Boolean;
3007 begin
3008 ID := M.ReadWord();
3009 Mon := g_Monsters_ByUID(ID);
3010 if Mon = nil then Exit;
3012 MState := M.ReadByte();
3013 MFAnm := M.ReadByte();
3015 with Mon do
3016 begin
3017 MonsterTargetUID := M.ReadWord();
3018 MonsterTargetTime := M.ReadLongInt();
3019 MonsterSleep := M.ReadLongInt();
3020 MonsterHealth := M.ReadLongInt();
3021 MonsterAmmo := M.ReadLongInt();
3022 MonsterPain := M.ReadLongInt();
3023 AnimRevert := M.ReadByte() <> 0;
3024 OldFire := FFireTime;
3025 FFireTime := M.ReadLongInt();
3026 if (OldFire <= 0) and (FFireTime > 0) then
3027 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
3028 RevertAnim(AnimRevert);
3030 if MonsterState <> MState then
3031 begin
3032 if (MState = MONSTATE_GO) and (MonsterState = MONSTATE_SLEEP) then WakeUpSound();
3033 if (MState = MONSTATE_DIE) then DieSound();
3034 if (MState = MONSTATE_PAIN) then MakeBloodSimple(Min(200, MonsterPain));
3035 if (MState = MONSTATE_ATTACK) then kick(nil);
3036 if (MState = MONSTATE_DEAD) then SetDeadAnim();
3038 SetState(MState, MFAnm);
3039 end;
3040 end;
3041 end;
3043 procedure MC_RECV_MonsterShot(var M: TMsg);
3044 var
3045 ID: Integer;
3046 Mon: TMonster;
3047 X, Y, VX, VY: Integer;
3048 begin
3049 ID := M.ReadWord();
3051 Mon := g_Monsters_ByUID(ID);
3052 if Mon = nil then Exit;
3054 X := M.ReadLongInt();
3055 Y := M.ReadLongInt();
3056 VX := M.ReadLongInt();
3057 VY := M.ReadLongInt();
3059 Mon.ClientAttack(X, Y, VX, VY);
3060 end;
3062 procedure MC_RECV_MonsterDelete(var M: TMsg);
3063 var
3064 ID: Integer;
3065 Mon: TMonster;
3066 begin
3067 ID := M.ReadWord();
3068 Mon := g_Monsters_ByUID(ID);
3069 if Mon = nil then Exit;
3070 Mon.SetState(5);
3071 Mon.MonsterRemoved := True;
3072 end;
3074 procedure MC_RECV_TimeSync(var M: TMsg);
3075 var
3076 Time: LongWord;
3077 begin
3078 Time := M.ReadLongWord();
3080 if gState = STATE_INTERCUSTOM then
3081 gServInterTime := Min(Time, 255);
3082 end;
3084 procedure MC_RECV_VoteEvent(var M: TMsg);
3085 var
3086 EvID: Byte;
3087 Str1, Str2: string;
3088 Int1, Int2: SmallInt;
3089 begin
3090 EvID := M.ReadByte();
3091 Int1 := M.ReadSmallInt();
3092 Int2 := M.ReadSmallInt();
3093 Str1 := M.ReadString();
3094 Str2 := M.ReadString();
3096 if NetDeafLevel < 2 then
3097 case EvID of
3098 NET_VE_STARTED:
3099 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True);
3100 NET_VE_PASSED:
3101 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True);
3102 NET_VE_FAILED:
3103 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
3104 NET_VE_VOTE:
3105 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True);
3106 NET_VE_INPROGRESS:
3107 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True);
3108 end;
3109 end;
3111 // CLIENT SEND
3113 procedure MC_SEND_Info(Password: string);
3114 begin
3115 NetOut.Clear();
3117 NetOut.Write(Byte(NET_MSG_INFO));
3118 NetOut.Write(GAME_VERSION);
3119 NetOut.Write(Password);
3120 NetOut.Write(gPlayer1Settings.Name);
3121 NetOut.Write(gPlayer1Settings.Model);
3122 NetOut.Write(gPlayer1Settings.Color.R);
3123 NetOut.Write(gPlayer1Settings.Color.G);
3124 NetOut.Write(gPlayer1Settings.Color.B);
3125 NetOut.Write(gPlayer1Settings.Team);
3127 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3128 end;
3130 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
3131 begin
3132 NetOut.Write(Byte(NET_MSG_CHAT));
3133 NetOut.Write(Txt);
3134 NetOut.Write(Mode);
3136 g_Net_Client_Send(True, NET_CHAN_CHAT);
3137 end;
3139 procedure MC_SEND_PlayerPos();
3140 var
3141 kByte: Word;
3142 Predict: Boolean;
3143 strafeDir: Byte;
3144 WeaponAct: Byte = 0;
3145 WeaponSelect: Word = 0;
3146 i: Integer;
3147 begin
3148 if not gGameOn then Exit;
3149 if gPlayers = nil then Exit;
3150 if gPlayer1 = nil then Exit;
3152 kByte := 0;
3153 Predict := NetPredictSelf; // and (not NetGotKeys);
3155 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
3156 begin
3157 strafeDir := P1MoveButton shr 4;
3158 P1MoveButton := P1MoveButton and $0F;
3160 if gPlayerAction[0, ACTION_MOVELEFT] and (not gPlayerAction[0, ACTION_MOVERIGHT]) then
3161 P1MoveButton := 1
3162 else if (not gPlayerAction[0, ACTION_MOVELEFT]) and gPlayerAction[0, ACTION_MOVERIGHT] then
3163 P1MoveButton := 2
3164 else if (not gPlayerAction[0, ACTION_MOVELEFT]) and (not gPlayerAction[0, ACTION_MOVERIGHT]) then
3165 P1MoveButton := 0;
3167 // strafing
3168 if gPlayerAction[0, ACTION_STRAFE] then
3169 begin
3170 // new strafe mechanics
3171 if (strafeDir = 0) then
3172 strafeDir := P1MoveButton; // start strafing
3173 // now set direction according to strafe (reversed)
3174 if (strafeDir = 2) then
3175 gPlayer1.SetDirection(TDirection.D_LEFT)
3176 else if (strafeDir = 1) then
3177 gPlayer1.SetDirection(TDirection.D_RIGHT)
3178 end
3179 else
3180 begin
3181 strafeDir := 0; // not strafing anymore
3182 if (P1MoveButton = 2) and gPlayerAction[0, ACTION_MOVELEFT] then
3183 gPlayer1.SetDirection(TDirection.D_LEFT)
3184 else if (P1MoveButton = 1) and gPlayerAction[0, ACTION_MOVERIGHT] then
3185 gPlayer1.SetDirection(TDirection.D_RIGHT)
3186 else if P1MoveButton <> 0 then
3187 gPlayer1.SetDirection(TDirection(P1MoveButton-1));
3188 end;
3190 gPlayer1.ReleaseKeys;
3191 if P1MoveButton = 1 then
3192 begin
3193 kByte := kByte or NET_KEY_LEFT;
3194 if Predict then gPlayer1.PressKey(KEY_LEFT, 10000);
3195 end;
3196 if P1MoveButton = 2 then
3197 begin
3198 kByte := kByte or NET_KEY_RIGHT;
3199 if Predict then gPlayer1.PressKey(KEY_RIGHT, 10000);
3200 end;
3201 if gPlayerAction[0, ACTION_LOOKUP] then
3202 begin
3203 kByte := kByte or NET_KEY_UP;
3204 gPlayer1.PressKey(KEY_UP, 10000);
3205 end;
3206 if gPlayerAction[0, ACTION_LOOKDOWN] then
3207 begin
3208 kByte := kByte or NET_KEY_DOWN;
3209 gPlayer1.PressKey(KEY_DOWN, 10000);
3210 end;
3211 if gPlayerAction[0, ACTION_JUMP] then
3212 begin
3213 kByte := kByte or NET_KEY_JUMP;
3214 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3215 end;
3216 if gPlayerAction[0, ACTION_ATTACK] then kByte := kByte or NET_KEY_FIRE;
3217 if gPlayerAction[0, ACTION_ACTIVATE] then kByte := kByte or NET_KEY_OPEN;
3219 for i := WP_FACT to WP_LACT do
3220 begin
3221 if gWeaponAction[0, i] then
3222 begin
3223 WeaponAct := WeaponAct or Byte(1 shl i);
3224 gWeaponAction[0, i] := False
3225 end
3226 end;
3228 for i := WP_FIRST to WP_LAST do
3229 begin
3230 if gSelectWeapon[0, i] then
3231 begin
3232 WeaponSelect := WeaponSelect or Word(1 shl i);
3233 gSelectWeapon[0, i] := False
3234 end
3235 end;
3237 // fix movebutton state
3238 P1MoveButton := P1MoveButton or (strafeDir shl 4);
3239 end
3240 else
3241 kByte := NET_KEY_CHAT;
3243 NetOut.Write(Byte(NET_MSG_PLRPOS));
3244 NetOut.Write(gTime);
3245 NetOut.Write(kByte);
3246 NetOut.Write(Byte(gPlayer1.Direction));
3247 NetOut.Write(WeaponAct);
3248 NetOut.Write(WeaponSelect);
3249 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3250 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS);
3252 //kBytePrev := kByte;
3253 //kDirPrev := gPlayer1.Direction;
3254 end;
3256 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
3257 begin
3258 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
3259 NetOut.Write(Byte(Start));
3260 NetOut.Write(Command);
3261 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3262 end;
3264 procedure MC_SEND_PlayerSettings();
3265 begin
3266 NetOut.Write(Byte(NET_MSG_PLRSET));
3267 NetOut.Write(gPlayer1Settings.Name);
3268 NetOut.Write(gPlayer1Settings.Model);
3269 NetOut.Write(gPlayer1Settings.Color.R);
3270 NetOut.Write(gPlayer1Settings.Color.G);
3271 NetOut.Write(gPlayer1Settings.Color.B);
3272 NetOut.Write(gPlayer1Settings.Team);
3274 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3275 end;
3277 procedure MC_SEND_FullStateRequest();
3278 begin
3279 NetOut.Write(Byte(NET_MSG_REQFST));
3281 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3282 end;
3284 procedure MC_SEND_CheatRequest(Kind: Byte);
3285 begin
3286 NetOut.Write(Byte(NET_MSG_CHEAT));
3287 NetOut.Write(Kind);
3289 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3290 end;
3291 procedure MC_SEND_RCONPassword(Password: string);
3292 begin
3293 NetOut.Write(Byte(NET_MSG_RCON_AUTH));
3294 NetOut.Write(Password);
3296 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3297 end;
3298 procedure MC_SEND_RCONCommand(Cmd: string);
3299 begin
3300 NetOut.Write(Byte(NET_MSG_RCON_CMD));
3301 NetOut.Write(Cmd);
3303 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3304 end;
3307 end.