DEADSOFTWARE

more anti autism measures
[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;
459 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
460 e_WriteLog('NET: Client ' + PName + ' [' + IntToStr(C^.ID) +
461 '] connected. Assigned player #' + IntToStr(PID) + '.', TMsgType.Notify);
463 MH_SEND_Info(C^.ID);
465 with g_Player_Get(PID) do
466 begin
467 Name := PName;
468 FClientID := C^.ID;
469 // round in progress, don't spawn
470 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C.ID, C.Player]);
471 //e_LogWritefln('spawning player with pid #%u...', [PID]);
472 //Respawn(gGameSettings.GameType = GT_SINGLE);
473 //k8: no, do not spawn a player yet, wait for "request full state" packet
474 Lives := 0;
475 Spectate;
476 FNoRespawn := True;
477 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
478 // that is, if we'll set it to `true`, the player can be spawned after
479 // warmup time ran out, for example, regardless of the real player state.
480 // also, this seems to work only for the initial connection. further
481 // map changes could initiate resource downloading, but the player will
482 // be spawned immediately.
483 // the proper solution will require another player state, "ephemeral".
484 // the player should start any map in "ephemeral" state, and turned into
485 // real mobj only when they sent a special "i am ready" packet. this packet
486 // must be sent after receiving the full state, so the player will get a full
487 // map view before going into game.
488 FWantsInGame := false;
489 C^.WaitForFirstSpawn := true;
490 end;
492 //if not C^.WaitForFirstSpawn then
493 begin
494 for I := Low(NetClients) to High(NetClients) do
495 begin
496 if NetClients[I].ID = C^.ID then Continue;
497 MH_SEND_PlayerCreate(PID, NetClients[I].ID);
498 MH_SEND_PlayerPos(True, PID, NetClients[I].ID);
499 MH_SEND_PlayerStats(PID, NetClients[I].ID);
500 end;
501 end;
503 if gState in [STATE_INTERCUSTOM, STATE_FOLD] then
504 MH_SEND_GameEvent(NET_EV_MAPEND, 0, 'N', C^.ID);
506 if NetUseMaster then
507 begin
508 //g_Net_Slist_Update;
509 g_Net_Slist_Pulse();
510 end;
511 end;
514 procedure MH_ProcessFirstSpawn (C: pTNetClient);
515 var
516 plr: TPlayer;
517 begin
518 if not C.WaitForFirstSpawn then exit;
519 plr := g_Player_Get(C^.Player);
520 if not assigned(plr) then exit;
521 g_Net_Slist_ServerPlayerComes();
522 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C.ID, C.Player]);
523 C.WaitForFirstSpawn := false;
524 plr.FNoRespawn := false;
525 plr.FWantsInGame := true; // TODO: look into this later
527 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
528 begin
529 plr.Spectate;
530 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN, 0, 'N', C.ID);
531 end
532 else
533 begin
534 plr.Respawn(False);
535 if gLMSRespawn > LMS_RESPAWN_NONE then
536 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime, 'N', C.ID);
537 end;
538 end;
541 procedure MH_RECV_FullStateRequest(C: pTNetClient; var M: TMsg);
542 begin
543 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
544 if gGameOn then
545 begin
546 MH_SEND_Everything((C^.State = NET_STATE_AUTH), C^.ID)
547 end
548 else
549 begin
550 C^.RequestedFullUpdate := True;
551 end;
552 end;
554 // PLAYER
556 function MH_RECV_PlayerPos(C: pTNetClient; var M: TMsg): Word;
557 var
558 Dir, i: Byte;
559 WeaponAct: Byte;
560 WeaponSelect: Word;
561 PID: Word;
562 kByte: Word;
563 Pl: TPlayer;
564 GT: LongWord;
565 Err: Boolean;
566 begin
567 Result := 0;
568 Err := False;
569 if not gGameOn then Exit;
571 try
572 GT := M.ReadLongWord();
573 except
574 Err := True;
575 end;
577 if Err then begin MH_MalformedPacket(C); Exit; end;
579 PID := C^.Player;
580 Pl := g_Player_Get(PID);
581 if Pl = nil then
582 Exit;
584 if (GT > gTime + NET_MAX_DIFFTIME) or (GT < Pl.NetTime) then Exit;
586 with Pl do
587 begin
588 NetTime := GT;
589 try
590 kByte := M.ReadWord();
591 Dir := M.ReadByte();
592 WeaponAct := M.ReadByte();
593 WeaponSelect := M.ReadWord();
594 except
595 Err := True;
596 end;
598 if Err then begin MH_MalformedPacket(C); Exit; end;
600 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
601 if Direction <> TDirection(Dir) then
602 JustTeleported := False;
604 SetDirection(TDirection(Dir));
605 ReleaseKeys;
607 if kByte = NET_KEY_CHAT then
608 begin
609 PressKey(KEY_CHAT, 10000);
610 Exit;
611 end;
613 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
614 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
615 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
616 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
617 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
618 if LongBool(kByte and NET_KEY_FIRE) then PressKey(KEY_FIRE, 10000);
619 if LongBool(kByte and NET_KEY_OPEN) then PressKey(KEY_OPEN, 10000);
621 for i := 0 to 7 do
622 begin
623 if (WeaponAct and Byte(1 shl i)) <> 0 then
624 begin
625 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
626 ProcessWeaponAction(i);
627 end;
628 end;
630 for i := 0 to 15 do
631 begin
632 if (WeaponSelect and Word(1 shl i)) <> 0 then
633 begin
634 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
635 QueueWeaponSwitch(i);
636 end;
637 end;
638 end;
640 // MH_SEND_PlayerPos(False, PID, C^.ID);
641 end;
643 procedure MH_RECV_CheatRequest(C: pTNetClient; var M: TMsg);
644 var
645 CheatKind: Byte;
646 Pl: TPlayer;
647 Err: Boolean;
648 begin
649 Err := False;
650 Pl := g_Player_Get(C^.Player);
651 if Pl = nil then Exit;
653 try
654 CheatKind := M.ReadByte();
655 except
656 Err := True;
657 end;
659 if Err then begin MH_MalformedPacket(C); Exit; end;
661 case CheatKind of
662 NET_CHEAT_SUICIDE:
663 Pl.Damage(SUICIDE_DAMAGE, Pl.UID, 0, 0, HIT_SELF);
664 NET_CHEAT_SPECTATE:
665 begin
666 if Pl.FSpectator then
667 begin
668 if (gGameSettings.MaxLives = 0) or (gLMSRespawn > LMS_RESPAWN_NONE) then
669 Pl.Respawn(False)
670 else
671 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN, Pl.UID);
672 end
673 else
674 Pl.Spectate;
675 end;
676 NET_CHEAT_READY:
677 begin
678 if gState <> STATE_INTERCUSTOM then Exit;
679 Pl.FReady := not Pl.FReady;
680 if Pl.FReady then
681 begin
682 MH_SEND_GameEvent(NET_EV_INTER_READY, Pl.UID, 'Y');
683 Inc(gInterReadyCount);
684 end
685 else
686 begin
687 MH_SEND_GameEvent(NET_EV_INTER_READY, Pl.UID, 'N');
688 Dec(gInterReadyCount);
689 end;
690 end;
691 NET_CHEAT_DROPFLAG:
692 Pl.TryDropFlag();
693 end;
694 end;
696 procedure MH_RECV_PlayerSettings(C: pTNetClient; var M: TMsg);
697 var
698 TmpName: string;
699 TmpModel: string;
700 TmpColor: TRGB;
701 TmpTeam: Byte;
702 Pl: TPlayer;
703 Err: Boolean;
704 begin
705 Err := False;
706 try
707 TmpName := M.ReadString();
708 TmpModel := M.ReadString();
709 TmpColor.R := M.ReadByte();
710 TmpColor.G := M.ReadByte();
711 TmpColor.B := M.ReadByte();
712 TmpTeam := M.ReadByte();
713 except
714 Err := True;
715 end;
717 if Err then begin MH_MalformedPacket(C); Exit; end;
719 Pl := g_Player_Get(C^.Player);
720 if Pl = nil then Exit;
722 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
723 Pl.SwitchTeam
724 else
725 Pl.SetColor(TmpColor);
727 if Pl.Name <> TmpName then
728 begin
729 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
730 Pl.Name := TmpName;
731 end;
733 if TmpModel <> Pl.Model.Name then
734 Pl.SetModel(TmpModel);
736 MH_SEND_PlayerSettings(Pl.UID, TmpModel);
737 end;
739 // RCON
741 procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
742 var
743 Pwd: string;
744 Err: Boolean;
745 begin
746 Err := False;
747 try
748 Pwd := M.ReadString();
749 except
750 Err := True;
751 end;
752 if Err then begin MH_MalformedPacket(C); Exit; end;
753 if not NetAllowRCON then Exit;
754 if Pwd = NetRCONPassword then
755 begin
756 C^.RCONAuth := True;
757 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWGOOD, 'N', C^.ID);
758 end
759 else
760 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWBAD, 'N', C^.ID);
761 end;
763 procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
764 var
765 Cmd: string;
766 Err: Boolean;
767 begin
768 Err := False;
769 try
770 Cmd := M.ReadString();
771 except
772 Err := True;
773 end;
774 if Err then begin MH_MalformedPacket(C); Exit; end;
775 if not NetAllowRCON then Exit;
776 if not C^.RCONAuth then
777 begin
778 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_NOAUTH, 'N', C^.ID);
779 Exit;
780 end;
781 g_Console_Process(Cmd);
782 end;
784 // MISC
786 procedure MH_RECV_Vote(C: pTNetClient; var M: TMsg);
787 var
788 Start: Boolean;
789 Name, Command: string;
790 Need: Integer;
791 Pl: TPlayer;
792 Err: Boolean;
793 begin
794 Err := False;
795 try
796 Start := M.ReadByte() <> 0;
797 Command := M.ReadString();
798 except
799 Err := True;
800 end;
802 if Err then begin MH_MalformedPacket(C); Exit; end;
804 Pl := g_Player_Get(C^.Player);
805 if Pl = nil then Exit;
806 Name := Pl.Name;
808 if Start then
809 begin
810 if not g_Console_CommandBlacklisted(Command) then
811 g_Game_StartVote(Command, Name);
812 end
813 else if gVoteInProgress then
814 begin
815 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
816 Need := Floor((NetClientCount+1)/2.0) + 1
817 else
818 Need := Floor(NetClientCount/2.0) + 1;
819 if C^.Voted then
820 begin
821 Dec(gVoteCount);
822 C^.Voted := False;
823 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [Name, gVoteCount, Need]), True);
824 MH_SEND_VoteEvent(NET_VE_REVOKE, Name, 'a', gVoteCount, Need);
825 end
826 else
827 begin
828 Inc(gVoteCount);
829 C^.Voted := True;
830 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Name, gVoteCount, Need]), True);
831 MH_SEND_VoteEvent(NET_VE_VOTE, Name, 'a', gVoteCount, Need);
832 g_Game_CheckVote;
833 end;
834 end;
835 end;
837 // GAME (SEND)
839 procedure MH_SEND_Everything(CreatePlayers: Boolean {= False}; ID: Integer {= NET_EVERYONE});
841 function sendItemRespawn (it: PItem): Boolean;
842 begin
843 result := false; // don't stop
844 MH_SEND_ItemSpawn(True, it.myid, ID);
845 end;
847 function sendMonSpawn (mon: TMonster): Boolean;
848 begin
849 result := false; // don't stop
850 MH_SEND_MonsterSpawn(mon.UID, ID);
851 end;
853 function sendPanelState (pan: TPanel): Boolean;
854 begin
855 result := false; // don't stop
856 MH_SEND_PanelState(pan.guid, ID); // anyway, to sync mplats
857 if (pan.CanChangeTexture) then MH_SEND_PanelTexture(pan.guid, pan.LastAnimLoop, ID);
858 end;
860 var
861 I: Integer;
862 begin
863 if (ID >= 0) and (ID < length(NetClients)) then
864 begin
865 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID, NetClients[ID].Player]);
866 MH_ProcessFirstSpawn(@NetClients[ID]);
867 end;
869 if gPlayers <> nil then
870 begin
871 for I := Low(gPlayers) to High(gPlayers) do
872 begin
873 if gPlayers[I] <> nil then
874 begin
875 if CreatePlayers then MH_SEND_PlayerCreate(gPlayers[I].UID, ID);
876 MH_SEND_PlayerPos(True, gPlayers[I].UID, ID);
877 MH_SEND_PlayerStats(gPlayers[I].UID, ID);
879 if (gPlayers[I].Flag <> FLAG_NONE) and (gGameSettings.GameMode = GM_CTF) then
880 begin
881 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED, gPlayers[I].Flag, gPlayers[I].UID, True, ID);
882 end;
883 end;
884 end;
885 end;
887 g_Items_ForEachAlive(sendItemRespawn, true); // backwards
888 g_Mons_ForEach(sendMonSpawn);
889 g_Map_ForEachPanel(sendPanelState);
891 if gTriggers <> nil then
892 begin
893 for I := Low(gTriggers) to High(gTriggers) do
894 begin
895 if gTriggers[I].TriggerType = TRIGGER_SOUND then
896 begin
897 MH_SEND_TriggerSound(gTriggers[I], ID);
898 end;
899 end;
900 end;
902 if Shots <> nil then
903 begin
904 for I := Low(Shots) to High(Shots) do
905 begin
906 if Shots[i].ShotType in [6, 7, 8] then
907 begin
908 MH_SEND_CreateShot(i, ID);
909 end;
910 end;
911 end;
913 MH_SEND_TriggerMusic(ID);
915 MH_SEND_GameStats(ID);
916 MH_SEND_CoopStats(ID);
918 if gGameSettings.GameMode = GM_CTF then
919 begin
920 if gFlags[FLAG_RED].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_RED].State, FLAG_RED, 0, True, ID);
921 if gFlags[FLAG_BLUE].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_BLUE].State, FLAG_BLUE, 0, True, ID);
922 end;
924 if CreatePlayers and (ID >= 0) then NetClients[ID].State := NET_STATE_GAME;
926 g_Net_Flush();
927 end;
929 procedure MH_SEND_Info(ID: Byte);
930 begin
931 NetOut.Clear();
933 NetOut.Write(Byte(NET_MSG_INFO));
934 NetOut.Write(ID);
935 NetOut.Write(NetClients[ID].Player);
936 NetOut.Write(ExtractFileName(gGameSettings.WAD));
937 NetOut.Write(g_ExtractFileName(gMapInfo.Map));
938 NetOut.Write(gWADHash);
939 NetOut.Write(gGameSettings.GameMode);
940 NetOut.Write(gGameSettings.GoalLimit);
941 NetOut.Write(gGameSettings.TimeLimit);
942 NetOut.Write(gGameSettings.MaxLives);
943 NetOut.Write(gGameSettings.Options);
944 NetOut.Write(gTime);
946 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
947 end;
949 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
950 var
951 Name: string;
952 i: Integer;
953 Team: Byte;
954 begin
955 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
956 Mode := NET_CHAT_PLAYER;
958 Team := 0;
959 if (Mode = NET_CHAT_TEAM) then
960 begin
961 for i := Low(gPlayers) to High(gPlayers) do
962 if (gPlayers[i] <> nil) and (gPlayers[i].FClientID >= 0) and
963 (gPlayers[i].Team = ID) then
964 begin
965 NetOut.Write(Byte(NET_MSG_CHAT));
966 NetOut.Write(Txt);
967 NetOut.Write(Mode);
968 g_Net_Host_Send(gPlayers[i].FClientID, True, NET_CHAN_CHAT);
969 end;
970 Team := ID;
971 ID := NET_EVERYONE;
972 end
973 else
974 begin
975 NetOut.Write(Byte(NET_MSG_CHAT));
976 NetOut.Write(Txt);
977 NetOut.Write(Mode);
978 g_Net_Host_Send(ID, True, NET_CHAN_CHAT);
979 end;
981 if Mode = NET_CHAT_SYSTEM then
982 Exit;
984 if ID = NET_EVERYONE then
985 begin
986 if Mode = NET_CHAT_PLAYER then
987 begin
988 g_Console_Add(Txt, True);
989 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
990 g_Game_ChatSound(b_Text_Unformat(Txt));
991 end
992 else
993 if Mode = NET_CHAT_TEAM then
994 if gPlayer1 <> nil then
995 begin
996 if (gPlayer1.Team = TEAM_RED) and (Team = TEAM_RED) then
997 begin
998 g_Console_Add(#18'[Team] '#2 + Txt, True);
999 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1000 g_Game_ChatSound(b_Text_Unformat(Txt));
1001 end
1002 else if (gPlayer1.Team = TEAM_BLUE) and (Team = TEAM_BLUE) then
1003 begin
1004 g_Console_Add(#20'[Team] '#2 + Txt, True);
1005 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1006 g_Game_ChatSound(b_Text_Unformat(Txt));
1007 end;
1008 end;
1009 end
1010 else
1011 begin
1012 Name := g_Net_ClientName_ByID(ID);
1013 g_Console_Add('-> ' + Name + ': ' + Txt, True);
1014 e_WriteLog('[Tell ' + Name + '] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1015 g_Game_ChatSound(b_Text_Unformat(Txt), False);
1016 end;
1017 end;
1019 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
1020 begin
1021 NetOut.Write(Byte(NET_MSG_GFX));
1022 NetOut.Write(Kind);
1023 NetOut.Write(X);
1024 NetOut.Write(Y);
1025 NetOut.Write(Ang);
1027 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
1028 end;
1030 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
1031 begin
1032 NetOut.Write(Byte(NET_MSG_SND));
1033 NetOut.Write(Name);
1034 if Pos then
1035 begin
1036 NetOut.Write(Byte(1));
1037 NetOut.Write(X);
1038 NetOut.Write(Y);
1039 end
1040 else
1041 NetOut.Write(Byte(0));
1043 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
1044 end;
1046 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
1047 begin
1048 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
1050 NetOut.Write(Byte(NET_MSG_SHADD));
1051 NetOut.Write(Proj);
1052 NetOut.Write(Shots[Proj].ShotType);
1053 NetOut.Write(Shots[Proj].Target);
1054 NetOut.Write(Shots[Proj].SpawnerUID);
1055 NetOut.Write(Shots[Proj].Timeout);
1056 NetOut.Write(Shots[Proj].Obj.X);
1057 NetOut.Write(Shots[Proj].Obj.Y);
1058 NetOut.Write(Shots[Proj].Obj.Vel.X);
1059 NetOut.Write(Shots[Proj].Obj.Vel.Y);
1061 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1062 end;
1064 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
1065 begin
1066 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
1068 NetOut.Write(Byte(NET_MSG_SHPOS));
1069 NetOut.Write(Proj);
1070 NetOut.Write(Shots[Proj].Obj.X);
1071 NetOut.Write(Shots[Proj].Obj.Y);
1072 NetOut.Write(Shots[Proj].Obj.Vel.X);
1073 NetOut.Write(Shots[Proj].Obj.Vel.Y);
1075 g_Net_Host_Send(ID, False, NET_CHAN_SHOTS);
1076 end;
1078 procedure MH_Send_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
1079 begin
1080 NetOut.Write(Byte(NET_MSG_SHDEL));
1081 NetOut.Write(Proj);
1082 NetOut.Write(Byte(Loud));
1083 NetOut.Write(X);
1084 NetOut.Write(Y);
1086 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1087 end;
1089 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
1090 begin
1091 NetOut.Write(Byte(NET_MSG_SCORE));
1092 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1093 begin
1094 NetOut.Write(gTeamStat[TEAM_RED].Goals);
1095 NetOut.Write(gTeamStat[TEAM_BLUE].Goals);
1096 end
1097 else
1098 if gGameSettings.GameMode = GM_COOP then
1099 begin
1100 NetOut.Write(gCoopMonstersKilled);
1101 NetOut.Write(gCoopSecretsFound);
1102 end;
1104 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1105 end;
1107 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
1108 begin
1109 NetOut.Write(Byte(NET_MSG_COOP));
1110 NetOut.Write(gTotalMonsters);
1111 NetOut.Write(gSecretsCount);
1112 NetOut.Write(gCoopTotalMonstersKilled);
1113 NetOut.Write(gCoopTotalSecretsFound);
1114 NetOut.Write(gCoopTotalMonsters);
1115 NetOut.Write(gCoopTotalSecrets);
1116 end;
1118 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
1119 begin
1120 NetOut.Write(Byte(NET_MSG_GEVENT));
1121 NetOut.Write(EvType);
1122 NetOut.Write(EvNum);
1123 NetOut.Write(EvStr);
1124 NetOut.Write(Byte(gLastMap));
1125 NetOut.Write(gTime);
1126 if (EvType = NET_EV_MAPSTART) and isWadPath(EvStr) then
1127 begin
1128 NetOut.Write(Byte(1));
1129 NetOut.Write(gWADHash);
1130 end else
1131 NetOut.Write(Byte(0));
1133 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
1134 end;
1136 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
1137 begin
1138 NetOut.Write(Byte(NET_MSG_FLAG));
1139 NetOut.Write(EvType);
1140 NetOut.Write(Flag);
1141 NetOut.Write(Byte(Quiet));
1142 NetOut.Write(PID);
1143 NetOut.Write(gFlags[Flag].State);
1144 NetOut.Write(gFlags[Flag].CaptureTime);
1145 NetOut.Write(gFlags[Flag].Obj.X);
1146 NetOut.Write(gFlags[Flag].Obj.Y);
1147 NetOut.Write(gFlags[Flag].Obj.Vel.X);
1148 NetOut.Write(gFlags[Flag].Obj.Vel.Y);
1149 NetOut.Write(Byte(gFlags[Flag].Direction));
1151 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1152 end;
1154 procedure MH_SEND_FlagPos(Flag: Byte; ID: Integer = NET_EVERYONE);
1155 begin
1156 NetOut.Write(Byte(NET_MSG_FLAGPOS));
1157 NetOut.Write(Flag);
1158 NetOut.Write(gFlags[Flag].Obj.X);
1159 NetOut.Write(gFlags[Flag].Obj.Y);
1160 NetOut.Write(gFlags[Flag].Obj.Vel.X);
1161 NetOut.Write(gFlags[Flag].Obj.Vel.Y);
1163 g_Net_Host_Send(ID, False, NET_CHAN_IMPORTANT);
1164 end;
1166 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
1167 begin
1168 NetOut.Write(Byte(NET_MSG_GSET));
1169 NetOut.Write(gGameSettings.GameMode);
1170 NetOut.Write(gGameSettings.GoalLimit);
1171 NetOut.Write(gGameSettings.TimeLimit);
1172 NetOut.Write(gGameSettings.MaxLives);
1173 NetOut.Write(gGameSettings.Options);
1175 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1176 end;
1178 // PLAYER (SEND)
1180 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
1181 var
1182 P: TPlayer;
1183 begin
1184 P := g_Player_Get(PID);
1185 if P = nil then Exit;
1187 NetOut.Write(Byte(NET_MSG_PLR));
1188 NetOut.Write(PID);
1189 NetOut.Write(P.Name);
1191 NetOut.Write(P.FActualModelName);
1192 NetOut.Write(P.FColor.R);
1193 NetOut.Write(P.FColor.G);
1194 NetOut.Write(P.FColor.B);
1195 NetOut.Write(P.Team);
1197 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT)
1198 end;
1200 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
1201 var
1202 kByte: Word;
1203 Pl: TPlayer;
1204 begin
1205 Pl := g_Player_Get(PID);
1206 if Pl = nil then Exit;
1207 if Pl.FDummy then Exit;
1209 NetOut.Write(Byte(NET_MSG_PLRPOS));
1210 NetOut.Write(gTime);
1211 NetOut.Write(PID);
1213 kByte := 0;
1215 with Pl do
1216 begin
1217 NetOut.Write(FPing);
1218 NetOut.Write(FLoss);
1219 if IsKeyPressed(KEY_CHAT) then
1220 kByte := NET_KEY_CHAT
1221 else
1222 begin
1223 if IsKeyPressed(KEY_LEFT) then kByte := kByte or NET_KEY_LEFT;
1224 if IsKeyPressed(KEY_RIGHT) then kByte := kByte or NET_KEY_RIGHT;
1225 if IsKeyPressed(KEY_UP) then kByte := kByte or NET_KEY_UP;
1226 if IsKeyPressed(KEY_DOWN) then kByte := kByte or NET_KEY_DOWN;
1227 if IsKeyPressed(KEY_JUMP) then kByte := kByte or NET_KEY_JUMP;
1228 end;
1230 if JustTeleported then kByte := kByte or NET_KEY_FORCEDIR;
1232 NetOut.Write(kByte);
1233 if Direction = TDirection.D_LEFT then NetOut.Write(Byte(0)) else NetOut.Write(Byte(1));
1234 NetOut.Write(GameX);
1235 NetOut.Write(GameY);
1236 NetOut.Write(GameVelX);
1237 NetOut.Write(GameVelY);
1238 NetOut.Write(GameAccelX);
1239 NetOut.Write(GameAccelY);
1240 end;
1242 g_Net_Host_Send(ID, Reliable, NET_CHAN_PLAYERPOS);
1243 end;
1245 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
1246 var
1247 P: TPlayer;
1248 I: Integer;
1249 begin
1250 P := g_Player_Get(PID);
1251 if P = nil then Exit;
1253 NetOut.Write(Byte(NET_MSG_PLRSTA));
1254 NetOut.Write(PID);
1256 with P do
1257 begin
1258 NetOut.Write(Byte(alive));
1259 NetOut.Write(Byte(GodMode));
1260 NetOut.Write(Health);
1261 NetOut.Write(Armor);
1262 NetOut.Write(Air);
1263 NetOut.Write(JetFuel);
1264 NetOut.Write(Lives);
1265 NetOut.Write(Team);
1267 for I := WP_FIRST to WP_LAST do
1268 NetOut.Write(Byte(FWeapon[I]));
1270 for I := A_BULLETS to A_HIGH do
1271 NetOut.Write(FAmmo[I]);
1273 for I := A_BULLETS to A_HIGH do
1274 NetOut.Write(FMaxAmmo[I]);
1276 for I := MR_SUIT to MR_MAX do
1277 NetOut.Write(LongWord(FMegaRulez[I]));
1279 NetOut.Write(Byte(R_ITEM_BACKPACK in FRulez));
1280 NetOut.Write(Byte(R_KEY_RED in FRulez));
1281 NetOut.Write(Byte(R_KEY_GREEN in FRulez));
1282 NetOut.Write(Byte(R_KEY_BLUE in FRulez));
1283 NetOut.Write(Byte(R_BERSERK in FRulez));
1285 NetOut.Write(Frags);
1286 NetOut.Write(Death);
1288 NetOut.Write(CurrWeap);
1290 NetOut.Write(Byte(FSpectator));
1291 NetOut.Write(Byte(FGhost));
1292 NetOut.Write(Byte(FPhysics));
1293 NetOut.Write(Byte(FNoRespawn));
1294 NetOut.Write(Byte(FJetpack));
1295 NetOut.Write(FFireTime);
1296 NetOut.Write(Byte(FFlaming));
1297 NetOut.Write(FSpawnInvul);
1298 end;
1300 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1301 end;
1303 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
1304 begin
1305 NetOut.Write(Byte(NET_MSG_PLRDMG));
1306 NetOut.Write(PID);
1307 NetOut.Write(Kind);
1308 NetOut.Write(Attacker);
1309 NetOut.Write(Value);
1310 NetOut.Write(VX);
1311 NetOut.Write(VY);
1313 g_Net_Host_Send(ID, False, NET_CHAN_PLAYER);
1314 end;
1316 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
1317 begin
1318 NetOut.Write(Byte(NET_MSG_PLRDIE));
1319 NetOut.Write(PID);
1320 NetOut.Write(KillType);
1321 NetOut.Write(DeathType);
1322 NetOut.Write(Attacker);
1324 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1325 end;
1327 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
1328 begin
1329 NetOut.Write(Byte(NET_MSG_PLRFIRE));
1330 NetOut.Write(PID);
1331 NetOut.Write(Weapon);
1332 NetOut.Write(X);
1333 NetOut.Write(Y);
1334 NetOut.Write(AX);
1335 NetOut.Write(AY);
1336 NetOut.Write(ShotID);
1338 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1339 end;
1341 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
1342 begin
1343 NetOut.Write(Byte(NET_MSG_PLRDEL));
1344 NetOut.Write(PID);
1346 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1347 end;
1349 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
1350 var
1351 Pl: TPlayer;
1352 begin
1353 Pl := g_Player_Get(PID);
1354 if Pl = nil then Exit;
1356 NetOut.Write(Byte(NET_MSG_PLRSET));
1357 NetOut.Write(PID);
1358 NetOut.Write(Pl.Name);
1359 if Mdl = '' then
1360 NetOut.Write(Pl.Model.Name)
1361 else
1362 NetOut.Write(Mdl);
1363 NetOut.Write(Pl.FColor.R);
1364 NetOut.Write(Pl.FColor.G);
1365 NetOut.Write(Pl.FColor.B);
1366 NetOut.Write(Pl.Team);
1368 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1369 end;
1371 // ITEM (SEND)
1373 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1374 var
1375 it: PItem;
1376 tt: Byte;
1377 begin
1378 it := g_Items_ByIdx(IID);
1380 NetOut.Write(Byte(NET_MSG_ISPAWN));
1381 NetOut.Write(IID);
1382 NetOut.Write(Byte(Quiet));
1383 tt := it.ItemType;
1384 if it.dropped then tt := tt or $80;
1385 NetOut.Write(tt);
1386 NetOut.Write(Byte(it.Fall));
1387 NetOut.Write(Byte(it.Respawnable));
1388 NetOut.Write(it.Obj.X);
1389 NetOut.Write(it.Obj.Y);
1390 NetOut.Write(it.Obj.Vel.X);
1391 NetOut.Write(it.Obj.Vel.Y);
1393 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1394 end;
1396 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1397 begin
1398 NetOut.Write(Byte(NET_MSG_IDEL));
1399 NetOut.Write(IID);
1400 NetOut.Write(Byte(Quiet));
1402 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1403 end;
1405 procedure MH_SEND_ItemPos(IID: Word; ID: Integer = NET_EVERYONE);
1406 var
1407 it: PItem;
1408 begin
1409 it := g_Items_ByIdx(IID);
1411 NetOut.Write(Byte(NET_MSG_IPOS));
1412 NetOut.Write(IID);
1413 NetOut.Write(it.Obj.X);
1414 NetOut.Write(it.Obj.Y);
1415 NetOut.Write(it.Obj.Vel.X);
1416 NetOut.Write(it.Obj.Vel.Y);
1418 g_Net_Host_Send(ID, False, NET_CHAN_LARGEDATA);
1419 end;
1421 // PANEL
1423 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
1424 var
1425 TP: TPanel;
1426 begin
1427 TP := g_Map_PanelByGUID(PGUID);
1428 if (TP = nil) then exit;
1430 with TP do
1431 begin
1432 NetOut.Write(Byte(NET_MSG_PTEX));
1433 NetOut.Write(LongWord(PGUID));
1434 NetOut.Write(FCurTexture);
1435 NetOut.Write(FCurFrame);
1436 NetOut.Write(FCurFrameCount);
1437 NetOut.Write(AnimLoop);
1438 end;
1440 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1441 end;
1443 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
1444 var
1445 TP: TPanel;
1446 mpflags: Byte = 0;
1447 begin
1448 TP := g_Map_PanelByGUID(PGUID);
1449 if (TP = nil) then exit;
1451 NetOut.Write(Byte(NET_MSG_PSTATE));
1452 NetOut.Write(LongWord(PGUID));
1453 NetOut.Write(Byte(TP.Enabled));
1454 NetOut.Write(TP.LiftType);
1455 NetOut.Write(TP.X);
1456 NetOut.Write(TP.Y);
1457 NetOut.Write(Word(TP.Width));
1458 NetOut.Write(Word(TP.Height));
1459 // mplats
1460 NetOut.Write(LongInt(TP.movingSpeedX));
1461 NetOut.Write(LongInt(TP.movingSpeedY));
1462 NetOut.Write(LongInt(TP.movingStartX));
1463 NetOut.Write(LongInt(TP.movingStartY));
1464 NetOut.Write(LongInt(TP.movingEndX));
1465 NetOut.Write(LongInt(TP.movingEndY));
1466 NetOut.Write(LongInt(TP.sizeSpeedX));
1467 NetOut.Write(LongInt(TP.sizeSpeedY));
1468 NetOut.Write(LongInt(TP.sizeEndX));
1469 NetOut.Write(LongInt(TP.sizeEndY));
1470 if TP.movingActive then mpflags := mpflags or 1;
1471 if TP.moveOnce then mpflags := mpflags or 2;
1472 NetOut.Write(Byte(mpflags));
1474 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1475 end;
1477 // TRIGGER
1479 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
1480 begin
1481 if gTriggers = nil then Exit;
1482 if T.Sound = nil then Exit;
1484 NetOut.Write(Byte(NET_MSG_TSOUND));
1485 NetOut.Write(T.ClientID);
1486 NetOut.Write(Byte(T.Sound.IsPlaying));
1487 NetOut.Write(LongWord(T.Sound.GetPosition));
1488 NetOut.Write(T.SoundPlayCount);
1490 g_Net_Host_Send(ID, True);
1491 end;
1493 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
1494 begin
1495 NetOut.Write(Byte(NET_MSG_TMUSIC));
1496 NetOut.Write(gMusic.Name);
1497 NetOut.Write(Byte(gMusic.IsPlaying));
1498 NetOut.Write(LongWord(gMusic.GetPosition));
1499 NetOut.Write(Byte(gMusic.SpecPause or gMusic.IsPaused));
1501 g_Net_Host_Send(ID, True);
1502 end;
1504 // MONSTER
1506 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
1507 var
1508 M: TMonster;
1509 begin
1510 M := g_Monsters_ByUID(UID);
1511 if M = nil then
1512 Exit;
1514 with M do
1515 begin
1516 NetOut.Write(Byte(NET_MSG_MSPAWN));
1517 NetOut.Write(UID);
1518 NetOut.Write(MonsterType);
1519 NetOut.Write(MonsterState);
1520 NetOut.Write(MonsterAnim);
1521 NetOut.Write(MonsterTargetUID);
1522 NetOut.Write(MonsterTargetTime);
1523 NetOut.Write(MonsterBehaviour);
1524 NetOut.Write(MonsterSleep);
1525 NetOut.Write(MonsterHealth);
1526 NetOut.Write(MonsterAmmo);
1527 NetOut.Write(GameX);
1528 NetOut.Write(GameY);
1529 NetOut.Write(GameVelX);
1530 NetOut.Write(GameVelY);
1531 NetOut.Write(Byte(GameDirection));
1532 end;
1534 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1535 end;
1537 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
1538 var
1539 M: TMonster;
1540 begin
1541 M := g_Monsters_ByUID(UID);
1542 if M = nil then Exit;
1544 NetOut.Write(Byte(NET_MSG_MPOS));
1545 NetOut.Write(UID);
1547 with M do
1548 begin
1549 NetOut.Write(GameX);
1550 NetOut.Write(GameY);
1551 NetOut.Write(GameVelX);
1552 NetOut.Write(GameVelY);
1553 NetOut.Write(Byte(GameDirection));
1554 end;
1556 g_Net_Host_Send(ID, False, NET_CHAN_MONSTERPOS);
1557 end;
1559 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
1560 var
1561 M: TMonster;
1562 begin
1563 M := g_Monsters_ByUID(UID);
1564 if M = nil then Exit;
1566 NetOut.Write(Byte(NET_MSG_MSTATE));
1567 NetOut.Write(UID);
1569 with M do
1570 begin
1571 NetOut.Write(MonsterState);
1572 NetOut.Write(ForcedAnim);
1573 NetOut.Write(MonsterTargetUID);
1574 NetOut.Write(MonsterTargetTime);
1575 NetOut.Write(MonsterSleep);
1576 NetOut.Write(MonsterHealth);
1577 NetOut.Write(MonsterAmmo);
1578 NetOut.Write(MonsterPain);
1579 NetOut.Write(Byte(AnimIsReverse));
1580 NetOut.Write(FFireTime);
1581 end;
1583 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1584 end;
1586 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
1587 begin
1588 NetOut.Write(Byte(NET_MSG_MSHOT));
1589 NetOut.Write(UID);
1590 NetOut.Write(X);
1591 NetOut.Write(Y);
1592 NetOut.Write(VX);
1593 NetOut.Write(VY);
1595 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1596 end;
1598 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
1599 var
1600 M: TMonster;
1601 begin
1602 M := g_Monsters_ByUID(UID);
1603 if M = nil then Exit;
1605 NetOut.Write(Byte(NET_MSG_MDEL));
1606 NetOut.Write(UID);
1608 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1609 end;
1611 // MISC
1613 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
1614 begin
1615 NetOut.Write(Byte(NET_MSG_TIME_SYNC));
1616 NetOut.Write(Time);
1618 g_Net_Host_Send(ID, False, NET_CHAN_SERVICE);
1619 end;
1621 procedure MH_SEND_VoteEvent(EvType: Byte;
1622 StrArg1: string = 'a'; StrArg2: string = 'b';
1623 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
1624 ID: Integer = NET_EVERYONE);
1625 begin
1626 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
1627 NetOut.Write(EvType);
1628 NetOut.Write(IntArg1);
1629 NetOut.Write(IntArg2);
1630 NetOut.Write(StrArg1);
1631 NetOut.Write(StrArg2);
1633 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1634 end;
1636 // CLIENT MESSAGES //
1638 // GAME
1640 procedure MC_RECV_Chat(var M: TMsg);
1641 var
1642 Txt: string;
1643 Mode: Byte;
1644 begin
1645 Txt := M.ReadString();
1646 Mode := M.ReadByte();
1648 if Mode <> NET_CHAT_SYSTEM then
1649 begin
1650 if NetDeafLevel = 0 then
1651 begin
1652 if Mode = NET_CHAT_PLAYER then
1653 begin
1654 g_Console_Add(Txt, True);
1655 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1656 g_Game_ChatSound(b_Text_Unformat(Txt));
1657 end else
1658 if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then
1659 begin
1660 if gPlayer1.Team = TEAM_RED then
1661 g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True);
1662 if gPlayer1.Team = TEAM_BLUE then
1663 g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True);
1664 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1665 g_Game_ChatSound(b_Text_Unformat(Txt));
1666 end;
1667 end;
1668 end else if (NetDeafLevel < 2) then
1669 g_Console_Add(Txt, True);
1670 end;
1672 procedure MC_RECV_Effect(var M: TMsg);
1673 var
1674 Kind: Byte;
1675 X, Y: Integer;
1676 Ang: SmallInt;
1677 Anim: TAnimation;
1678 ID: LongWord;
1679 begin
1680 if not gGameOn then Exit;
1681 Kind := M.ReadByte();
1682 X := M.ReadLongInt();
1683 Y := M.ReadLongInt();
1684 Ang := M.ReadSmallInt();
1686 case Kind of
1687 NET_GFX_SPARK:
1688 g_GFX_Spark(X, Y, 2 + Random(2), Ang, 0, 0);
1690 NET_GFX_TELE:
1691 begin
1692 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
1693 begin
1694 Anim := TAnimation.Create(ID, False, 3);
1695 g_GFX_OnceAnim(X, Y, Anim);
1696 Anim.Free();
1697 end;
1698 if Ang = 1 then
1699 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
1700 end;
1702 NET_GFX_EXPLODE:
1703 begin
1704 if g_Frames_Get(ID, 'FRAMES_EXPLODE_ROCKET') then
1705 begin
1706 Anim := TAnimation.Create(ID, False, 6);
1707 Anim.Blending := False;
1708 g_GFX_OnceAnim(X-64, Y-64, Anim);
1709 Anim.Free();
1710 end;
1711 if Ang = 1 then
1712 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X, Y);
1713 end;
1715 NET_GFX_BFGEXPL:
1716 begin
1717 if g_Frames_Get(ID, 'FRAMES_EXPLODE_BFG') then
1718 begin
1719 Anim := TAnimation.Create(ID, False, 6);
1720 Anim.Blending := False;
1721 g_GFX_OnceAnim(X-64, Y-64, Anim);
1722 Anim.Free();
1723 end;
1724 if Ang = 1 then
1725 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X, Y);
1726 end;
1728 NET_GFX_BFGHIT:
1729 begin
1730 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1731 begin
1732 Anim := TAnimation.Create(ID, False, 4);
1733 g_GFX_OnceAnim(X-32, Y-32, Anim);
1734 Anim.Free();
1735 end;
1736 end;
1738 NET_GFX_FIRE:
1739 begin
1740 if g_Frames_Get(ID, 'FRAMES_FIRE') then
1741 begin
1742 Anim := TAnimation.Create(ID, False, 4);
1743 g_GFX_OnceAnim(X, Y, Anim);
1744 Anim.Free();
1745 end;
1746 if Ang = 1 then
1747 g_Sound_PlayExAt('SOUND_FIRE', X, Y);
1748 end;
1750 NET_GFX_RESPAWN:
1751 begin
1752 if g_Frames_Get(ID, 'FRAMES_ITEM_RESPAWN') then
1753 begin
1754 Anim := TAnimation.Create(ID, False, 4);
1755 g_GFX_OnceAnim(X, Y, Anim);
1756 Anim.Free();
1757 end;
1758 if Ang = 1 then
1759 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
1760 end;
1762 NET_GFX_SHELL1:
1763 g_Player_CreateShell(X, Y, 0, -2, SHELL_BULLET);
1765 NET_GFX_SHELL2:
1766 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1768 NET_GFX_SHELL3:
1769 begin
1770 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1771 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1772 end;
1773 end;
1774 end;
1776 procedure MC_RECV_Sound(var M: TMsg);
1777 var
1778 Name: string;
1779 X, Y: Integer;
1780 Pos: Boolean;
1781 begin
1782 Name := M.ReadString();
1783 Pos := M.ReadByte() <> 0;
1784 if Pos then
1785 begin
1786 X := M.ReadLongInt();
1787 Y := M.ReadLongInt();
1788 g_Sound_PlayExAt(Name, X, Y);
1789 end
1790 else
1791 g_Sound_PlayEx(Name);
1792 end;
1794 procedure MC_RECV_CreateShot(var M: TMsg);
1795 var
1796 I, X, Y, XV, YV: Integer;
1797 Timeout: LongWord;
1798 Target, Spawner: Word;
1799 ShType: Byte;
1800 begin
1801 I := M.ReadLongInt();
1802 ShType := M.ReadByte();
1803 Target := M.ReadWord();
1804 Spawner := M.ReadWord();
1805 Timeout := M.ReadLongWord();
1806 X := M.ReadLongInt();
1807 Y := M.ReadLongInt();
1808 XV := M.ReadLongInt();
1809 YV := M.ReadLongInt();
1811 I := g_Weapon_CreateShot(I, ShType, Spawner, Target, X, Y, XV, YV);
1812 if (Shots <> nil) and (I <= High(Shots)) then
1813 begin
1814 Shots[I].Timeout := Timeout;
1815 //Shots[I].Target := Target; // TODO: find a use for Target later
1816 end;
1817 end;
1819 procedure MC_RECV_UpdateShot(var M: TMsg);
1820 var
1821 I, TX, TY, TXV, TYV: Integer;
1822 begin
1823 I := M.ReadLongInt();
1824 TX := M.ReadLongInt();
1825 TY := M.ReadLongInt();
1826 TXV := M.ReadLongInt();
1827 TYV := M.ReadLongInt();
1829 if (Shots <> nil) and (I <= High(Shots)) then
1830 with (Shots[i]) do
1831 begin
1832 Obj.X := TX;
1833 Obj.Y := TY;
1834 Obj.Vel.X := TXV;
1835 Obj.Vel.Y := TYV;
1836 end;
1837 end;
1839 procedure MC_RECV_DeleteShot(var M: TMsg);
1840 var
1841 I, X, Y: Integer;
1842 L: Boolean;
1843 begin
1844 if not gGameOn then Exit;
1845 I := M.ReadLongInt();
1846 L := (M.ReadByte() <> 0);
1847 X := M.ReadLongInt();
1848 Y := M.ReadLongInt();
1850 g_Weapon_DestroyShot(I, X, Y, L);
1851 end;
1853 procedure MC_RECV_GameStats(var M: TMsg);
1854 begin
1855 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1856 begin
1857 gTeamStat[TEAM_RED].Goals := M.ReadSmallInt();
1858 gTeamStat[TEAM_BLUE].Goals := M.ReadSmallInt();
1859 end
1860 else
1861 if gGameSettings.GameMode = GM_COOP then
1862 begin
1863 gCoopMonstersKilled := M.ReadWord();
1864 gCoopSecretsFound := M.ReadWord();
1865 end;
1866 end;
1868 procedure MC_RECV_CoopStats(var M: TMsg);
1869 begin
1870 gTotalMonsters := M.ReadLongInt();
1871 gSecretsCount := M.ReadLongInt();
1872 gCoopTotalMonstersKilled := M.ReadWord();
1873 gCoopTotalSecretsFound := M.ReadWord();
1874 gCoopTotalMonsters := M.ReadWord();
1875 gCoopTotalSecrets := M.ReadWord();
1876 end;
1878 procedure MC_RECV_GameEvent(var M: TMsg);
1879 var
1880 EvType: Byte;
1881 EvNum: Integer;
1882 EvStr: string;
1883 EvTime: LongWord;
1884 BHash: Boolean;
1885 EvHash: TMD5Digest;
1886 pl: TPlayer;
1887 i1, i2: TStrings_Locale;
1888 pln: String;
1889 cnt: Byte;
1890 goodCmd: Boolean = true;
1891 begin
1892 FillChar(EvHash, Sizeof(EvHash), 0);
1893 EvType := M.ReadByte();
1894 EvNum := M.ReadLongInt();
1895 EvStr := M.ReadString();
1896 gLastMap := M.ReadByte() <> 0;
1897 if gLastMap and (gGameSettings.GameMode = GM_COOP) then gStatsOff := True;
1898 gStatsPressed := True;
1899 EvTime := M.ReadLongWord();
1900 BHash := M.ReadByte() <> 0;
1901 if BHash then
1902 EvHash := M.ReadMD5();
1904 gTime := EvTime;
1906 if (g_Res_received_map_start <> 0) then
1907 begin
1908 if (g_Res_received_map_start < 0) then exit;
1909 goodCmd := false;
1910 case EvType of
1911 NET_EV_MAPSTART: goodCmd := true;
1912 NET_EV_MAPEND: goodCmd := true;
1913 NET_EV_PLAYER_KICK: goodCmd := true;
1914 NET_EV_PLAYER_BAN: goodCmd := true;
1915 NET_EV_LMS_WARMUP: goodCmd := true;
1916 end;
1917 if not goodCmd then exit;
1918 end;
1920 case EvType of
1921 NET_EV_MAPSTART:
1922 begin
1923 if (g_Res_received_map_start <> 0) then
1924 begin
1925 g_Res_received_map_start := -1;
1926 end
1927 else
1928 begin
1929 gGameOn := False;
1930 g_Game_ClearLoading();
1931 g_Game_StopAllSounds(True);
1933 gSwitchGameMode := Byte(EvNum);
1934 gGameSettings.GameMode := gSwitchGameMode;
1936 gWADHash := EvHash;
1937 if not g_Game_StartMap(false{asMegawad}, EvStr, True) then
1938 begin
1939 if not isWadPath(EvStr) then
1940 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + EvStr]))
1941 else
1942 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [EvStr]));
1943 Exit;
1944 end;
1946 MC_SEND_FullStateRequest;
1947 end;
1948 end;
1950 NET_EV_MAPEND:
1951 begin
1952 gLMSRespawn := LMS_RESPAWN_NONE;
1953 gLMSRespawnTime := 0;
1954 if (g_Res_received_map_start <> 0) then
1955 begin
1956 g_Res_received_map_start := -1;
1957 end
1958 else
1959 begin
1960 gMissionFailed := EvNum <> 0;
1961 gExit := EXIT_ENDLEVELCUSTOM;
1962 end;
1963 end;
1965 NET_EV_RCON:
1966 begin
1967 case EvNum of
1968 NET_RCON_NOAUTH:
1969 g_Console_Add(_lc[I_NET_RCON_NOAUTH], True);
1970 NET_RCON_PWGOOD:
1971 g_Console_Add(_lc[I_NET_RCON_PWD_VALID], True);
1972 NET_RCON_PWBAD:
1973 g_Console_Add(_lc[I_NET_RCON_PWD_INVALID], True);
1974 end;
1975 end;
1977 NET_EV_CHANGE_TEAM:
1978 begin
1979 if NetDeafLevel < 2 then
1980 begin
1981 if EvNum = TEAM_RED then
1982 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True);
1983 if EvNum = TEAM_BLUE then
1984 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True);
1985 end;
1986 end;
1988 NET_EV_PLAYER_KICK:
1989 begin
1990 g_Console_Add(Format(_lc[I_PLAYER_KICK], [EvStr]), True);
1991 if (g_Res_received_map_start <> 0) then g_Res_received_map_start := -1;
1992 end;
1994 NET_EV_PLAYER_BAN:
1995 begin
1996 g_Console_Add(Format(_lc[I_PLAYER_BAN], [EvStr]), True);
1997 if (g_Res_received_map_start <> 0) then g_Res_received_map_start := -1;
1998 end;
2000 NET_EV_LMS_WARMUP:
2001 begin
2002 if EvNum > 0 then
2003 begin
2004 gLMSRespawn := LMS_RESPAWN_WARMUP;
2005 gLMSRespawnTime := gTime + EvNum;
2006 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [EvNum div 1000]), True);
2007 end
2008 else if gPlayer1 = nil then
2009 begin
2010 g_Console_Add(_lc[I_PLAYER_SPECT4], True);
2011 end;
2012 end;
2014 NET_EV_LMS_SURVIVOR:
2015 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True);
2017 NET_EV_BIGTEXT:
2018 if NetDeafLevel < 2 then g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum));
2020 NET_EV_SCORE:
2021 begin
2022 pl := g_Player_Get(EvNum and $FFFF);
2023 if pl = nil then
2024 pln := '?'
2025 else
2026 pln := pl.Name;
2027 cnt := (EvNum shr 16) and $FF;
2028 if Pos('w', EvStr) = 0 then
2029 begin
2030 // Default score
2031 if Pos('t', EvStr) = 0 then
2032 begin
2033 // Player +/- score
2034 if Pos('-', EvStr) = 0 then
2035 begin
2036 if Pos('e', EvStr) = 0 then
2037 i1 := I_PLAYER_SCORE_ADD_OWN
2038 else
2039 i1 := I_PLAYER_SCORE_ADD_ENEMY;
2040 end else
2041 begin
2042 if Pos('e', EvStr) = 0 then
2043 i1 := I_PLAYER_SCORE_SUB_OWN
2044 else
2045 i1 := I_PLAYER_SCORE_SUB_ENEMY;
2046 end;
2047 // Which team
2048 if Pos('r', EvStr) > 0 then
2049 i2 := I_PLAYER_SCORE_TO_RED
2050 else
2051 i2 := I_PLAYER_SCORE_TO_BLUE;
2052 g_Console_Add(Format(_lc[i1], [pln, cnt, _lc[i2]]), True);
2053 end else
2054 begin
2055 // Team +/- score
2056 if Pos('-', EvStr) = 0 then
2057 i1 := I_PLAYER_SCORE_ADD_TEAM
2058 else
2059 i1 := I_PLAYER_SCORE_SUB_TEAM;
2060 // Which team
2061 if Pos('r', EvStr) > 0 then
2062 i2 := I_PLAYER_SCORE_RED
2063 else
2064 i2 := I_PLAYER_SCORE_BLUE;
2065 g_Console_Add(Format(_lc[i1], [_lc[i2], cnt]), True);
2066 end;
2067 end else
2068 begin
2069 // Game Win
2070 if Pos('e', EvStr) = 0 then
2071 i1 := I_PLAYER_SCORE_WIN_OWN
2072 else
2073 i1 := I_PLAYER_SCORE_WIN_ENEMY;
2074 // Which team
2075 if Pos('r', EvStr) > 0 then
2076 i2 := I_PLAYER_SCORE_TO_RED
2077 else
2078 i2 := I_PLAYER_SCORE_TO_BLUE;
2079 g_Console_Add(Format(_lc[i1], [pln, _lc[i2]]), True);
2080 end;
2081 end;
2083 NET_EV_SCORE_MSG:
2084 begin
2085 if EvNum = TEAM_RED then
2086 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
2087 if EvNum = TEAM_BLUE then
2088 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
2089 if EvNum = -TEAM_RED then
2090 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
2091 if EvNum = -TEAM_BLUE then
2092 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
2093 end;
2095 NET_EV_LMS_START:
2096 begin
2097 g_Player_RemoveAllCorpses;
2098 gLMSRespawn := LMS_RESPAWN_NONE;
2099 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
2100 end;
2102 NET_EV_LMS_WIN:
2103 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(EvStr)]), 144);
2105 NET_EV_TLMS_WIN:
2106 begin
2107 if EvNum = TEAM_RED then
2108 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
2109 if EvNum = TEAM_BLUE then
2110 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
2111 end;
2113 NET_EV_LMS_LOSE:
2114 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
2116 NET_EV_LMS_DRAW:
2117 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
2119 NET_EV_LMS_NOSPAWN:
2120 g_Console_Add(_lc[I_PLAYER_SPECT4], True);
2122 NET_EV_KILLCOMBO:
2123 g_Game_Announce_KillCombo(EvNum);
2125 NET_EV_PLAYER_TOUCH:
2126 begin
2127 pl := g_Player_Get(EvNum);
2128 if pl <> nil then
2129 pl.Touch();
2130 end;
2132 NET_EV_SECRET:
2133 begin
2134 pl := g_Player_Get(EvNum);
2135 if pl <> nil then
2136 begin
2137 g_Console_Add(Format(_lc[I_PLAYER_SECRET], [pl.Name]), True);
2138 g_Sound_PlayEx('SOUND_GAME_SECRET');
2139 end;
2140 end;
2142 NET_EV_INTER_READY:
2143 begin
2144 pl := g_Player_Get(EvNum);
2145 if pl <> nil then pl.FReady := (EvStr = 'Y');
2146 end;
2147 end;
2148 end;
2150 procedure MC_RECV_FlagPos(var M: TMsg);
2151 var
2152 Fl: Byte;
2153 begin
2154 Fl := M.ReadByte();
2155 if Fl = FLAG_NONE then Exit;
2156 gFlags[Fl].Obj.X := M.ReadLongInt();
2157 gFlags[Fl].Obj.Y := M.ReadLongInt();
2158 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
2159 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
2160 end;
2162 procedure MC_RECV_FlagEvent(var M: TMsg);
2163 var
2164 PID: Word;
2165 Pl: TPlayer;
2166 EvType: Byte;
2167 Fl, a: Byte;
2168 Quiet: Boolean;
2169 s, ts: string;
2170 begin
2171 EvType := M.ReadByte();
2172 Fl := M.ReadByte();
2174 if Fl = FLAG_NONE then Exit;
2176 Quiet := (M.ReadByte() <> 0);
2177 PID := M.ReadWord();
2179 gFlags[Fl].State := M.ReadByte();
2180 gFlags[Fl].CaptureTime := M.ReadLongWord();
2181 gFlags[Fl].Obj.X := M.ReadLongInt();
2182 gFlags[Fl].Obj.Y := M.ReadLongInt();
2183 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
2184 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
2185 gFlags[Fl].Direction := TDirection(M.ReadByte());
2187 Pl := g_Player_Get(PID);
2188 if (Pl = nil) and
2189 (EvType <> FLAG_STATE_NORMAL) and
2190 (EvType <> FLAG_STATE_DROPPED) and
2191 (EvType <> FLAG_STATE_RETURNED) then
2192 Exit;
2194 case EvType of
2195 FLAG_STATE_NORMAL:
2196 begin
2197 if Quiet or (Pl = nil) then Exit;
2199 if Fl = FLAG_RED then
2200 s := _lc[I_PLAYER_FLAG_RED]
2201 else
2202 s := _lc[I_PLAYER_FLAG_BLUE];
2204 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2206 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2207 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2208 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2209 a := 0
2210 else
2211 a := 1;
2213 if not sound_ret_flag[a].IsPlaying() then
2214 sound_ret_flag[a].Play();
2215 end;
2217 FLAG_STATE_CAPTURED:
2218 begin
2219 if (Pl <> nil) then Pl.SetFlag(Fl);
2221 if Quiet then Exit;
2223 if Fl = FLAG_RED then
2224 s := _lc[I_PLAYER_FLAG_RED]
2225 else
2226 s := _lc[I_PLAYER_FLAG_BLUE];
2228 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [Pl.Name, s]), True);
2229 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
2231 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2232 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2233 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2234 a := 0
2235 else
2236 a := 1;
2238 if not sound_get_flag[a].IsPlaying() then
2239 sound_get_flag[a].Play();
2240 end;
2242 FLAG_STATE_DROPPED:
2243 begin
2244 if (Pl <> nil) then Pl.SetFlag(FLAG_NONE);
2246 if Quiet or (Pl = nil) then Exit;
2248 if Fl = FLAG_RED then
2249 s := _lc[I_PLAYER_FLAG_RED]
2250 else
2251 s := _lc[I_PLAYER_FLAG_BLUE];
2253 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [Pl.Name, s]), True);
2254 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
2256 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2257 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2258 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2259 a := 0
2260 else
2261 a := 1;
2263 if not sound_lost_flag[a].IsPlaying() then
2264 sound_lost_flag[a].Play();
2265 end;
2267 FLAG_STATE_SCORED:
2268 begin
2269 g_Map_ResetFlag(FLAG_RED);
2270 g_Map_ResetFlag(FLAG_BLUE);
2271 if Quiet or (Pl = nil) then Exit;
2272 Pl.SetFlag(FLAG_NONE);
2274 if Fl = FLAG_RED then
2275 s := _lc[I_PLAYER_FLAG_RED]
2276 else
2277 s := _lc[I_PLAYER_FLAG_BLUE];
2279 ts := Format('%.4d', [gFlags[Fl].CaptureTime]);
2280 Insert('.', ts, Length(ts) + 1 - 3);
2281 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [Pl.Name, s, ts]), True);
2282 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
2284 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2285 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2286 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2287 a := 0
2288 else
2289 a := 1;
2291 if not sound_cap_flag[a].IsPlaying() then
2292 sound_cap_flag[a].Play();
2293 end;
2295 FLAG_STATE_RETURNED:
2296 begin
2297 g_Map_ResetFlag(Fl);
2298 if Quiet then Exit;
2300 if Fl = FLAG_RED then
2301 s := _lc[I_PLAYER_FLAG_RED]
2302 else
2303 s := _lc[I_PLAYER_FLAG_BLUE];
2305 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2307 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2308 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2309 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2310 a := 0
2311 else
2312 a := 1;
2314 if not sound_ret_flag[a].IsPlaying() then
2315 sound_ret_flag[a].Play();
2316 end;
2317 end;
2318 end;
2320 procedure MC_RECV_GameSettings(var M: TMsg);
2321 begin
2322 gGameSettings.GameMode := M.ReadByte();
2323 gGameSettings.GoalLimit := M.ReadWord();
2324 gGameSettings.TimeLimit := M.ReadWord();
2325 gGameSettings.MaxLives := M.ReadByte();
2326 gGameSettings.Options := M.ReadLongWord();
2327 end;
2329 // PLAYER
2331 function MC_RECV_PlayerCreate(var M: TMsg): Word;
2332 var
2333 PID, DID: Word;
2334 PName, Model: string;
2335 Color: TRGB;
2336 T: Byte;
2337 Pl: TPlayer;
2338 begin
2339 PID := M.ReadWord();
2340 Pl := g_Player_Get(PID);
2342 PName := M.ReadString();
2343 Model := M.ReadString();
2344 Color.R := M.ReadByte();
2345 Color.G := M.ReadByte();
2346 Color.B := M.ReadByte();
2347 T := M.ReadByte();
2349 Result := 0;
2350 if (PID <> NetPlrUID1) and (PID <> NetPlrUID2) then
2351 begin
2352 if (Pl <> nil) then Exit;
2353 DID := g_Player_Create(Model, Color, T, False);
2354 with g_Player_Get(DID) do
2355 begin
2356 UID := PID;
2357 Name := PName;
2358 Reset(True);
2359 end;
2360 end
2361 else
2362 begin
2363 if (PID = NetPlrUID1) and (gPlayer1 <> nil) then begin
2364 gPlayer1.UID := PID;
2365 gPlayer1.Model.SetColor(Color.R, Color.G, Color.B);
2366 gPlayer1.ChangeTeam(T);
2367 end;
2368 if (PID = NetPlrUID2) and (gPlayer2 <> nil) then begin
2369 gPlayer2.UID := PID;
2370 gPlayer2.Model.SetColor(Color.R, Color.G, Color.B);
2371 gPlayer2.ChangeTeam(T);
2372 end;
2373 end;
2375 if NetDeafLevel < 3 then
2376 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
2377 e_WriteLog('NET: Player ' + PName + ' [' + IntToStr(PID) + '] added.', TMsgType.Notify);
2378 Result := PID;
2379 end;
2381 function MC_RECV_PlayerPos(var M: TMsg): Word;
2382 var
2383 GT: LongWord;
2384 PID: Word;
2385 kByte: Word;
2386 Pl: TPlayer;
2387 Dir: Byte;
2388 TmpX, TmpY: Integer;
2389 begin
2390 Result := 0;
2392 GT := M.ReadLongWord();
2393 if GT < gTime - NET_MAX_DIFFTIME then
2394 begin
2395 gTime := GT;
2396 Exit;
2397 end;
2398 gTime := GT;
2400 PID := M.ReadWord();
2401 Pl := g_Player_Get(PID);
2403 if Pl = nil then Exit;
2405 Result := PID;
2407 with Pl do
2408 begin
2409 FPing := M.ReadWord();
2410 FLoss := M.ReadByte();
2411 kByte := M.ReadWord();
2412 Dir := M.ReadByte();
2414 TmpX := M.ReadLongInt();
2415 TmpY := M.ReadLongInt();
2417 ReleaseKeys;
2419 if LongBool(kByte and NET_KEY_CHAT) then
2420 PressKey(KEY_CHAT, 10000)
2421 else
2422 begin
2423 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
2424 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
2425 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
2426 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
2427 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
2428 end;
2430 JustTeleported := LongBool(kByte and NET_KEY_FORCEDIR);
2432 if ((Pl <> gPlayer1) and (Pl <> gPlayer2)) or JustTeleported then
2433 SetDirection(TDirection(Dir));
2435 GameVelX := M.ReadLongInt();
2436 GameVelY := M.ReadLongInt();
2437 GameAccelX := M.ReadLongInt();
2438 GameAccelY := M.ReadLongInt();
2439 SetLerp(TmpX, TmpY);
2440 if NetForcePlayerUpdate then Update();
2441 end;
2442 end;
2444 function MC_RECV_PlayerStats(var M: TMsg): Word;
2445 var
2446 PID: Word;
2447 Pl: TPlayer;
2448 I, OldFire: Integer;
2449 OldJet, Flam: Boolean;
2450 NewTeam: Byte;
2451 begin
2452 PID := M.ReadWord();
2453 Pl := g_Player_Get(PID);
2454 Result := 0;
2455 if Pl = nil then
2456 Exit;
2458 with Pl do
2459 begin
2460 alive := (M.ReadByte() <> 0);
2461 GodMode := (M.ReadByte() <> 0);
2462 Health := M.ReadLongInt();
2463 Armor := M.ReadLongInt();
2464 Air := M.ReadLongInt();
2465 JetFuel := M.ReadLongInt();
2466 Lives := M.ReadByte();
2467 NewTeam := M.ReadByte();
2469 for I := WP_FIRST to WP_LAST do
2470 FWeapon[I] := (M.ReadByte() <> 0);
2472 for I := A_BULLETS to A_HIGH do
2473 FAmmo[I] := M.ReadWord();
2475 for I := A_BULLETS to A_HIGH do
2476 FMaxAmmo[I] := M.ReadWord();
2478 for I := MR_SUIT to MR_MAX do
2479 FMegaRulez[I] := M.ReadLongWord();
2481 FRulez := [];
2482 if (M.ReadByte() <> 0) then
2483 FRulez := FRulez + [R_ITEM_BACKPACK];
2484 if (M.ReadByte() <> 0) then
2485 FRulez := FRulez + [R_KEY_RED];
2486 if (M.ReadByte() <> 0) then
2487 FRulez := FRulez + [R_KEY_GREEN];
2488 if (M.ReadByte() <> 0) then
2489 FRulez := FRulez + [R_KEY_BLUE];
2490 if (M.ReadByte() <> 0) then
2491 FRulez := FRulez + [R_BERSERK];
2493 Frags := M.ReadLongInt();
2494 Death := M.ReadLongInt();
2496 SetWeapon(M.ReadByte());
2498 FSpectator := M.ReadByte() <> 0;
2499 if FSpectator then
2500 begin
2501 if UID = NetPlrUID1 then
2502 begin
2503 gSpectLatchPID1 := UID;
2504 gPlayer1 := nil;
2505 end;
2506 if UID = NetPlrUID2 then
2507 begin
2508 gSpectLatchPID2 := UID;
2509 gPlayer2 := nil;
2510 end;
2511 end
2512 else
2513 begin
2514 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) and (UID = gSpectLatchPID1) then
2515 begin
2516 gPlayer1 := Pl;
2517 gSpectLatchPID1 := 0;
2518 end;
2519 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) and (UID = gSpectLatchPID2) then
2520 begin
2521 gPlayer2 := Pl;
2522 gSpectLatchPID2 := 0;
2523 end;
2524 end;
2525 FGhost := M.ReadByte() <> 0;
2526 FPhysics := M.ReadByte() <> 0;
2527 FNoRespawn := M.ReadByte() <> 0;
2528 OldJet := FJetpack;
2529 FJetpack := M.ReadByte() <> 0;
2530 OldFire := FFireTime;
2531 FFireTime := M.ReadLongInt();
2532 if (OldFire <= 0) and (FFireTime > 0) then
2533 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
2534 Flam := M.ReadByte() <> 0;
2535 FSpawnInvul := M.ReadLongInt();
2536 if OldJet and not FJetpack then
2537 JetpackOff
2538 else if not OldJet and FJetpack then
2539 JetpackOn;
2540 if FFlaming and not Flam then
2541 FlamerOff;
2542 if Team <> NewTeam then
2543 Pl.ChangeTeam(NewTeam);
2544 end;
2546 Result := PID;
2547 end;
2549 function MC_RECV_PlayerDamage(var M: TMsg): Word;
2550 var
2551 PID: Word;
2552 Pl: TPlayer;
2553 Kind: Byte;
2554 Attacker, Value: Word;
2555 VX, VY: Integer;
2556 begin
2557 Result := 0;
2558 if not gGameOn then Exit;
2559 PID := M.ReadWord();
2560 Pl := g_Player_Get(PID);
2561 if Pl = nil then Exit;
2563 Kind := M.ReadByte();
2564 Attacker := M.ReadWord();
2565 Value := M.ReadWord();
2566 VX := M.ReadWord();
2567 VY := M.ReadWord();
2569 with Pl do
2570 Damage(Value, Attacker, VX, VY, Kind);
2572 Result := PID;
2573 end;
2575 function MC_RECV_PlayerDeath(var M: TMsg): Word;
2576 var
2577 PID: Word;
2578 Pl: TPlayer;
2579 KillType, DeathType: Byte;
2580 Attacker: Word;
2581 begin
2582 Result := 0;
2583 if not gGameOn then Exit;
2584 PID := M.ReadWord();
2585 Pl := g_Player_Get(PID);
2586 if Pl = nil then Exit;
2588 KillType := M.ReadByte();
2589 DeathType := M.ReadByte();
2590 Attacker := M.ReadWord();
2592 with Pl do
2593 begin
2594 Kill(KillType, Attacker, DeathType);
2595 SoftReset;
2596 end;
2597 end;
2599 function MC_RECV_PlayerDelete(var M: TMsg): Word;
2600 var
2601 PID: Word;
2602 Pl: TPlayer;
2603 begin
2604 PID := M.ReadWord();
2605 Pl := g_Player_Get(PID);
2606 Result := 0;
2607 if Pl = nil then Exit;
2609 if NetDeafLevel < 3 then
2610 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2611 e_WriteLog('NET: Player ' + Pl.Name + ' [' + IntToStr(PID) + '] removed.', TMsgType.Notify);
2613 g_Player_Remove(PID);
2615 Result := PID;
2616 end;
2618 function MC_RECV_PlayerFire(var M: TMsg): Word;
2619 var
2620 PID: Word;
2621 Weap: Byte;
2622 Pl: TPlayer;
2623 X, Y, AX, AY: Integer;
2624 SHID: Integer;
2625 begin
2626 Result := 0;
2627 if not gGameOn then Exit;
2628 PID := M.ReadWord();
2629 Pl := g_Player_Get(PID);
2630 if Pl = nil then Exit;
2632 Weap := M.ReadByte();
2633 X := M.ReadLongInt();
2634 Y := M.ReadLongInt();
2635 AX := M.ReadLongInt();
2636 AY := M.ReadLongInt();
2637 SHID := M.ReadLongInt();
2639 with Pl do
2640 if alive then NetFire(Weap, X, Y, AX, AY, SHID);
2641 end;
2643 procedure MC_RECV_PlayerSettings(var M: TMsg);
2644 var
2645 TmpName: string;
2646 TmpModel: string;
2647 TmpColor: TRGB;
2648 TmpTeam: Byte;
2649 Pl: TPlayer;
2650 PID: Word;
2651 begin
2652 PID := M.ReadWord();
2653 Pl := g_Player_Get(PID);
2654 if Pl = nil then Exit;
2656 TmpName := M.ReadString();
2657 TmpModel := M.ReadString();
2658 TmpColor.R := M.ReadByte();
2659 TmpColor.G := M.ReadByte();
2660 TmpColor.B := M.ReadByte();
2661 TmpTeam := M.ReadByte();
2663 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
2664 begin
2665 Pl.ChangeTeam(TmpTeam);
2666 if gPlayer1 = Pl then
2667 gPlayer1Settings.Team := TmpTeam;
2668 if gPlayer2 = Pl then
2669 gPlayer2Settings.Team := TmpTeam;
2670 end else
2671 Pl.SetColor(TmpColor);
2673 if Pl.Name <> TmpName then
2674 begin
2675 if NetDeafLevel < 3 then
2676 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
2677 Pl.Name := TmpName;
2678 end;
2680 if TmpModel <> Pl.Model.Name then
2681 Pl.SetModel(TmpModel);
2682 end;
2684 // ITEM
2686 procedure MC_RECV_ItemSpawn(var M: TMsg);
2687 var
2688 ID: Word;
2689 AID: DWord;
2690 X, Y, VX, VY: Integer;
2691 T: Byte;
2692 Quiet, Fall{, Resp}: Boolean;
2693 Anim: TAnimation;
2694 it: PItem;
2695 begin
2696 if not gGameOn then Exit;
2697 ID := M.ReadWord();
2698 Quiet := M.ReadByte() <> 0;
2699 T := M.ReadByte();
2700 Fall := M.ReadByte() <> 0;
2701 {Resp :=} M.ReadByte();
2702 X := M.ReadLongInt();
2703 Y := M.ReadLongInt();
2704 VX := M.ReadLongInt();
2705 VY := M.ReadLongInt();
2707 g_Items_Create(X, Y, T and $7F, Fall, False, False, ID);
2708 if ((T and $80) <> 0) then g_Items_SetDrop(ID);
2710 it := g_Items_ByIdx(ID);
2711 it.Obj.Vel.X := VX;
2712 it.Obj.Vel.Y := VY;
2714 if not Quiet then
2715 begin
2716 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
2717 if g_Frames_Get(AID, 'FRAMES_ITEM_RESPAWN') then
2718 begin
2719 Anim := TAnimation.Create(AID, False, 4);
2720 g_GFX_OnceAnim(X+(it.Obj.Rect.Width div 2)-16, Y+(it.Obj.Rect.Height div 2)-16, Anim);
2721 Anim.Free();
2722 end;
2723 end;
2724 end;
2726 procedure MC_RECV_ItemDestroy(var M: TMsg);
2727 var
2728 ID: Word;
2729 Quiet: Boolean;
2730 begin
2731 if not gGameOn then Exit;
2732 ID := M.ReadWord();
2733 Quiet := M.ReadByte() <> 0;
2735 if not g_Items_ValidId(ID) then exit;
2737 if not Quiet then g_Items_EmitPickupSound(ID);
2739 g_Items_Remove(ID);
2740 end;
2742 procedure MC_RECV_ItemPos(var M: TMsg);
2743 var
2744 ID: Word;
2745 X, Y, VX, VY: Integer;
2746 it: PItem;
2747 begin
2748 if not gGameOn then Exit;
2750 ID := M.ReadWord();
2751 X := M.ReadLongInt();
2752 Y := M.ReadLongInt();
2753 VX := M.ReadLongInt();
2754 VY := M.ReadLongInt();
2756 if g_Items_ValidId(ID) then
2757 begin
2758 it := g_Items_ByIdx(ID);
2759 it.Obj.X := X;
2760 it.Obj.Y := Y;
2761 it.Obj.Vel.X := VX;
2762 it.Obj.Vel.Y := VY;
2763 it.positionChanged();
2764 end;
2765 end;
2767 // PANEL
2769 procedure MC_RECV_PanelTexture(var M: TMsg);
2770 var
2771 TP: TPanel;
2772 PGUID: Integer;
2773 Tex, Fr: Integer;
2774 Loop, Cnt: Byte;
2775 begin
2776 if not gGameOn then Exit;
2778 PGUID := Integer(M.ReadLongWord());
2779 Tex := M.ReadLongInt();
2780 Fr := M.ReadLongInt();
2781 Cnt := M.ReadByte();
2782 Loop := M.ReadByte();
2784 TP := g_Map_PanelByGUID(PGUID);
2785 if (TP <> nil) then
2786 begin
2787 // switch texture
2788 TP.SetTexture(Tex, Loop);
2789 TP.SetFrame(Fr, Cnt);
2790 end;
2791 end;
2793 procedure MC_RECV_PanelState(var M: TMsg);
2794 var
2795 PGUID: Integer;
2796 E: Boolean;
2797 Lift: Byte;
2798 X, Y, W, H: Integer;
2799 TP: TPanel;
2800 speedX, speedY, startX, startY, endX, endY: Integer;
2801 sizeSpX, sizeSpY, sizeEX, sizeEY: Integer;
2802 mpflags: Byte;
2803 begin
2804 if not gGameOn then Exit;
2806 PGUID := Integer(M.ReadLongWord());
2807 E := (M.ReadByte() <> 0);
2808 Lift := M.ReadByte();
2809 X := M.ReadLongInt();
2810 Y := M.ReadLongInt();
2811 W := M.ReadWord();
2812 H := M.ReadWord();
2813 // mplats
2814 speedX := M.ReadLongInt();
2815 speedY := M.ReadLongInt();
2816 startX := M.ReadLongInt();
2817 startY := M.ReadLongInt();
2818 endX := M.ReadLongInt();
2819 endY := M.ReadLongInt();
2820 sizeSpX := M.ReadLongInt();
2821 sizeSpY := M.ReadLongInt();
2822 sizeEX := M.ReadLongInt();
2823 sizeEY := M.ReadLongInt();
2824 mpflags := M.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2826 TP := g_Map_PanelByGUID(PGUID);
2827 if (TP = nil) then exit;
2829 // update lifts state
2830 if TP.isGLift then g_Map_SetLiftGUID(PGUID, Lift);
2832 // update enabled/disabled state for all panels
2833 if E then g_Map_EnableWallGUID(PGUID) else g_Map_DisableWallGUID(PGUID);
2835 // update panel position, as it can be moved (mplat)
2836 TP.X := X;
2837 TP.Y := Y;
2838 TP.Width := W;
2839 TP.Height := H;
2840 // update mplat state
2841 TP.movingSpeedX := speedX;
2842 TP.movingSpeedY := speedY;
2843 TP.movingStartX := startX;
2844 TP.movingStartY := startY;
2845 TP.movingEndX := endX;
2846 TP.movingEndY := endY;
2847 TP.sizeSpeedX := sizeSpX;
2848 TP.sizeSpeedY := sizeSpY;
2849 TP.sizeEndX := sizeEX;
2850 TP.sizeEndY := sizeEY;
2851 TP.movingActive := ((mpflags and 1) <> 0);
2852 TP.moveOnce := ((mpflags and 2) <> 0);
2853 // notify panel of it's position/size change, so it can fix other internal structures
2854 TP.positionChanged();
2855 end;
2857 // TRIGGERS
2859 procedure MC_RECV_TriggerSound(var M: TMsg);
2860 var
2861 SPlaying: Boolean;
2862 SPos, SID: LongWord;
2863 SCount: LongInt;
2864 I: Integer;
2865 begin
2866 if not gGameOn then Exit;
2867 if gTriggers = nil then Exit;
2869 SID := M.ReadLongWord();
2870 SPlaying := M.ReadByte() <> 0;
2871 SPos := M.ReadLongWord();
2872 SCount := M.ReadLongInt();
2874 for I := Low(gTriggers) to High(gTriggers) do
2875 if gTriggers[I].TriggerType = TRIGGER_SOUND then
2876 if gTriggers[I].ClientID = SID then
2877 with gTriggers[I] do
2878 begin
2879 if Sound <> nil then
2880 begin
2881 if SPlaying then
2882 begin
2883 if tgcLocal then
2884 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), tgcVolume/255.0)
2885 else
2886 Sound.PlayPanVolume((tgcPan-127.0)/128.0, tgcVolume/255.0);
2887 Sound.SetPosition(SPos);
2888 end
2889 else
2890 if Sound.IsPlaying then Sound.Stop;
2891 end;
2893 SoundPlayCount := SCount;
2894 end;
2895 end;
2897 procedure MC_RECV_TriggerMusic(var M: TMsg);
2898 var
2899 MName: string;
2900 MPlaying: Boolean;
2901 MPos: LongWord;
2902 MPaused: Boolean;
2903 begin
2904 if not gGameOn then Exit;
2906 MName := M.ReadString();
2907 MPlaying := M.ReadByte() <> 0;
2908 MPos := M.ReadLongWord();
2909 MPaused := M.ReadByte() <> 0;
2910 MPos := MPos+1; //k8: stfu, fpc!
2912 if MPlaying then
2913 begin
2914 gMusic.SetByName(MName);
2915 gMusic.Play(True);
2916 // gMusic.SetPosition(MPos);
2917 gMusic.SpecPause := MPaused;
2918 end
2919 else
2920 if gMusic.IsPlaying then gMusic.Stop;
2921 end;
2923 // MONSTERS
2925 procedure MC_RECV_MonsterSpawn(var M: TMsg);
2926 var
2927 ID: Word;
2928 MType, MState, MDir, MAnim, MBehav: Byte;
2929 X, Y, VX, VY, MTargTime, MHealth, MAmmo, MSleep: Integer;
2930 MTarg: Word;
2931 Mon: TMonster;
2932 begin
2933 ID := M.ReadWord();
2934 Mon := g_Monsters_ByUID(ID);
2935 if Mon <> nil then
2936 Exit;
2938 MType := M.ReadByte();
2939 MState := M.ReadByte();
2940 MAnim := M.ReadByte();
2941 MTarg := M.ReadWord();
2942 MTargTime := M.ReadLongInt();
2943 MBehav := M.ReadByte();
2944 MSleep := M.ReadLongInt();
2945 MHealth := M.ReadLongInt();
2946 MAmmo := M.ReadLongInt();
2948 X := M.ReadLongInt();
2949 Y := M.ReadLongInt();
2950 VX := M.ReadLongInt();
2951 VY := M.ReadLongInt();
2952 MDir := M.ReadByte();
2954 g_Monsters_Create(MType, X, Y, TDirection(MDir), False, ID);
2955 Mon := g_Monsters_ByUID(ID);
2956 if Mon = nil then
2957 Exit;
2959 with Mon do
2960 begin
2962 MonsterAnim := MAnim;
2963 MonsterTargetUID := MTarg;
2964 MonsterTargetTime := MTargTime;
2965 MonsterBehaviour := MBehav;
2966 MonsterSleep := MSleep;
2967 MonsterAmmo := MAmmo;
2968 SetHealth(MHealth);
2970 SetState(MState);
2972 setPosition(X, Y); // this will call positionChanged();
2973 GameVelX := VX;
2974 GameVelY := VY;
2975 end;
2976 end;
2978 procedure MC_RECV_MonsterPos(var M: TMsg);
2979 var
2980 Mon: TMonster;
2981 ID: Word;
2982 X, Y: Integer;
2983 begin
2984 ID := M.ReadWord();
2985 Mon := g_Monsters_ByUID(ID);
2986 if Mon = nil then
2987 Exit;
2989 with Mon do
2990 begin
2991 X := M.ReadLongInt();
2992 Y := M.ReadLongInt();
2993 Mon.setPosition(X, Y); // this will call `positionChanged()`
2994 GameVelX := M.ReadLongInt();
2995 GameVelY := M.ReadLongInt();
2996 GameDirection := TDirection(M.ReadByte());
2997 end;
2998 end;
3000 procedure MC_RECV_MonsterState(var M: TMsg);
3001 var
3002 ID, OldFire: Integer;
3003 MState, MFAnm: Byte;
3004 Mon: TMonster;
3005 AnimRevert: Boolean;
3006 begin
3007 ID := M.ReadWord();
3008 Mon := g_Monsters_ByUID(ID);
3009 if Mon = nil then Exit;
3011 MState := M.ReadByte();
3012 MFAnm := M.ReadByte();
3014 with Mon do
3015 begin
3016 MonsterTargetUID := M.ReadWord();
3017 MonsterTargetTime := M.ReadLongInt();
3018 MonsterSleep := M.ReadLongInt();
3019 MonsterHealth := M.ReadLongInt();
3020 MonsterAmmo := M.ReadLongInt();
3021 MonsterPain := M.ReadLongInt();
3022 AnimRevert := M.ReadByte() <> 0;
3023 OldFire := FFireTime;
3024 FFireTime := M.ReadLongInt();
3025 if (OldFire <= 0) and (FFireTime > 0) then
3026 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
3027 RevertAnim(AnimRevert);
3029 if MonsterState <> MState then
3030 begin
3031 if (MState = MONSTATE_GO) and (MonsterState = MONSTATE_SLEEP) then WakeUpSound();
3032 if (MState = MONSTATE_DIE) then DieSound();
3033 if (MState = MONSTATE_PAIN) then MakeBloodSimple(Min(200, MonsterPain));
3034 if (MState = MONSTATE_ATTACK) then kick(nil);
3035 if (MState = MONSTATE_DEAD) then SetDeadAnim();
3037 SetState(MState, MFAnm);
3038 end;
3039 end;
3040 end;
3042 procedure MC_RECV_MonsterShot(var M: TMsg);
3043 var
3044 ID: Integer;
3045 Mon: TMonster;
3046 X, Y, VX, VY: Integer;
3047 begin
3048 ID := M.ReadWord();
3050 Mon := g_Monsters_ByUID(ID);
3051 if Mon = nil then Exit;
3053 X := M.ReadLongInt();
3054 Y := M.ReadLongInt();
3055 VX := M.ReadLongInt();
3056 VY := M.ReadLongInt();
3058 Mon.ClientAttack(X, Y, VX, VY);
3059 end;
3061 procedure MC_RECV_MonsterDelete(var M: TMsg);
3062 var
3063 ID: Integer;
3064 Mon: TMonster;
3065 begin
3066 ID := M.ReadWord();
3067 Mon := g_Monsters_ByUID(ID);
3068 if Mon = nil then Exit;
3069 Mon.SetState(5);
3070 Mon.MonsterRemoved := True;
3071 end;
3073 procedure MC_RECV_TimeSync(var M: TMsg);
3074 var
3075 Time: LongWord;
3076 begin
3077 Time := M.ReadLongWord();
3079 if gState = STATE_INTERCUSTOM then
3080 gServInterTime := Min(Time, 255);
3081 end;
3083 procedure MC_RECV_VoteEvent(var M: TMsg);
3084 var
3085 EvID: Byte;
3086 Str1, Str2: string;
3087 Int1, Int2: SmallInt;
3088 begin
3089 EvID := M.ReadByte();
3090 Int1 := M.ReadSmallInt();
3091 Int2 := M.ReadSmallInt();
3092 Str1 := M.ReadString();
3093 Str2 := M.ReadString();
3095 if NetDeafLevel < 2 then
3096 case EvID of
3097 NET_VE_STARTED:
3098 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True);
3099 NET_VE_PASSED:
3100 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True);
3101 NET_VE_FAILED:
3102 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
3103 NET_VE_VOTE:
3104 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True);
3105 NET_VE_INPROGRESS:
3106 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True);
3107 end;
3108 end;
3110 // CLIENT SEND
3112 procedure MC_SEND_Info(Password: string);
3113 begin
3114 NetOut.Clear();
3116 NetOut.Write(Byte(NET_MSG_INFO));
3117 NetOut.Write(GAME_VERSION);
3118 NetOut.Write(Password);
3119 NetOut.Write(gPlayer1Settings.Name);
3120 NetOut.Write(gPlayer1Settings.Model);
3121 NetOut.Write(gPlayer1Settings.Color.R);
3122 NetOut.Write(gPlayer1Settings.Color.G);
3123 NetOut.Write(gPlayer1Settings.Color.B);
3124 NetOut.Write(gPlayer1Settings.Team);
3126 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3127 end;
3129 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
3130 begin
3131 NetOut.Write(Byte(NET_MSG_CHAT));
3132 NetOut.Write(Txt);
3133 NetOut.Write(Mode);
3135 g_Net_Client_Send(True, NET_CHAN_CHAT);
3136 end;
3138 procedure MC_SEND_PlayerPos();
3139 var
3140 kByte: Word;
3141 Predict: Boolean;
3142 strafeDir: Byte;
3143 WeaponAct: Byte = 0;
3144 WeaponSelect: Word = 0;
3145 i: Integer;
3146 begin
3147 if not gGameOn then Exit;
3148 if gPlayers = nil then Exit;
3149 if gPlayer1 = nil then Exit;
3151 kByte := 0;
3152 Predict := NetPredictSelf; // and (not NetGotKeys);
3154 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
3155 begin
3156 strafeDir := P1MoveButton shr 4;
3157 P1MoveButton := P1MoveButton and $0F;
3159 if gPlayerAction[0, ACTION_MOVELEFT] and (not gPlayerAction[0, ACTION_MOVERIGHT]) then
3160 P1MoveButton := 1
3161 else if (not gPlayerAction[0, ACTION_MOVELEFT]) and gPlayerAction[0, ACTION_MOVERIGHT] then
3162 P1MoveButton := 2
3163 else if (not gPlayerAction[0, ACTION_MOVELEFT]) and (not gPlayerAction[0, ACTION_MOVERIGHT]) then
3164 P1MoveButton := 0;
3166 // strafing
3167 if gPlayerAction[0, ACTION_STRAFE] then
3168 begin
3169 // new strafe mechanics
3170 if (strafeDir = 0) then
3171 strafeDir := P1MoveButton; // start strafing
3172 // now set direction according to strafe (reversed)
3173 if (strafeDir = 2) then
3174 gPlayer1.SetDirection(TDirection.D_LEFT)
3175 else if (strafeDir = 1) then
3176 gPlayer1.SetDirection(TDirection.D_RIGHT)
3177 end
3178 else
3179 begin
3180 strafeDir := 0; // not strafing anymore
3181 if (P1MoveButton = 2) and gPlayerAction[0, ACTION_MOVELEFT] then
3182 gPlayer1.SetDirection(TDirection.D_LEFT)
3183 else if (P1MoveButton = 1) and gPlayerAction[0, ACTION_MOVERIGHT] then
3184 gPlayer1.SetDirection(TDirection.D_RIGHT)
3185 else if P1MoveButton <> 0 then
3186 gPlayer1.SetDirection(TDirection(P1MoveButton-1));
3187 end;
3189 gPlayer1.ReleaseKeys;
3190 if P1MoveButton = 1 then
3191 begin
3192 kByte := kByte or NET_KEY_LEFT;
3193 if Predict then gPlayer1.PressKey(KEY_LEFT, 10000);
3194 end;
3195 if P1MoveButton = 2 then
3196 begin
3197 kByte := kByte or NET_KEY_RIGHT;
3198 if Predict then gPlayer1.PressKey(KEY_RIGHT, 10000);
3199 end;
3200 if gPlayerAction[0, ACTION_LOOKUP] then
3201 begin
3202 kByte := kByte or NET_KEY_UP;
3203 gPlayer1.PressKey(KEY_UP, 10000);
3204 end;
3205 if gPlayerAction[0, ACTION_LOOKDOWN] then
3206 begin
3207 kByte := kByte or NET_KEY_DOWN;
3208 gPlayer1.PressKey(KEY_DOWN, 10000);
3209 end;
3210 if gPlayerAction[0, ACTION_JUMP] then
3211 begin
3212 kByte := kByte or NET_KEY_JUMP;
3213 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3214 end;
3215 if gPlayerAction[0, ACTION_ATTACK] then kByte := kByte or NET_KEY_FIRE;
3216 if gPlayerAction[0, ACTION_ACTIVATE] then kByte := kByte or NET_KEY_OPEN;
3218 for i := WP_FACT to WP_LACT do
3219 begin
3220 if gWeaponAction[0, i] then
3221 begin
3222 WeaponAct := WeaponAct or Byte(1 shl i);
3223 gWeaponAction[0, i] := False
3224 end
3225 end;
3227 for i := WP_FIRST to WP_LAST do
3228 begin
3229 if gSelectWeapon[0, i] then
3230 begin
3231 WeaponSelect := WeaponSelect or Word(1 shl i);
3232 gSelectWeapon[0, i] := False
3233 end
3234 end;
3236 // fix movebutton state
3237 P1MoveButton := P1MoveButton or (strafeDir shl 4);
3238 end
3239 else
3240 kByte := NET_KEY_CHAT;
3242 NetOut.Write(Byte(NET_MSG_PLRPOS));
3243 NetOut.Write(gTime);
3244 NetOut.Write(kByte);
3245 NetOut.Write(Byte(gPlayer1.Direction));
3246 NetOut.Write(WeaponAct);
3247 NetOut.Write(WeaponSelect);
3248 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3249 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS);
3251 //kBytePrev := kByte;
3252 //kDirPrev := gPlayer1.Direction;
3253 end;
3255 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
3256 begin
3257 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
3258 NetOut.Write(Byte(Start));
3259 NetOut.Write(Command);
3260 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3261 end;
3263 procedure MC_SEND_PlayerSettings();
3264 begin
3265 NetOut.Write(Byte(NET_MSG_PLRSET));
3266 NetOut.Write(gPlayer1Settings.Name);
3267 NetOut.Write(gPlayer1Settings.Model);
3268 NetOut.Write(gPlayer1Settings.Color.R);
3269 NetOut.Write(gPlayer1Settings.Color.G);
3270 NetOut.Write(gPlayer1Settings.Color.B);
3271 NetOut.Write(gPlayer1Settings.Team);
3273 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3274 end;
3276 procedure MC_SEND_FullStateRequest();
3277 begin
3278 NetOut.Write(Byte(NET_MSG_REQFST));
3280 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3281 end;
3283 procedure MC_SEND_CheatRequest(Kind: Byte);
3284 begin
3285 NetOut.Write(Byte(NET_MSG_CHEAT));
3286 NetOut.Write(Kind);
3288 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3289 end;
3290 procedure MC_SEND_RCONPassword(Password: string);
3291 begin
3292 NetOut.Write(Byte(NET_MSG_RCON_AUTH));
3293 NetOut.Write(Password);
3295 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3296 end;
3297 procedure MC_SEND_RCONCommand(Cmd: string);
3298 begin
3299 NetOut.Write(Byte(NET_MSG_RCON_CMD));
3300 NetOut.Write(Cmd);
3302 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3303 end;
3306 end.