DEADSOFTWARE

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