DEADSOFTWARE

menu: optionally disable menu in client
[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 {$IFDEF ENABLE_MENU}
288 g_gui,
289 {$ENDIF}
290 Math, ENet, e_input, e_log, g_base, g_basic,
291 g_textures, g_gfx, g_sound, g_console, g_options,
292 g_game, g_player, g_map, g_panel, g_items, g_weapons, g_phys,
293 g_language, g_monsters, g_netmaster, utils, wadreader, MAPDEF;
295 const
296 NET_KEY_LEFT = 1 shl 0;
297 NET_KEY_RIGHT = 1 shl 1;
298 NET_KEY_UP = 1 shl 2;
299 NET_KEY_DOWN = 1 shl 3;
300 NET_KEY_JUMP = 1 shl 4;
301 NET_KEY_FIRE = 1 shl 5;
302 NET_KEY_OPEN = 1 shl 6;
303 NET_KEY_CHAT = 1 shl 7;
304 NET_KEY_FORCEDIR = 1 shl 8;
306 //var
307 //kBytePrev: Word = 0;
308 //kDirPrev: TDirection = D_LEFT;
309 //HostGameTime: Word = 0;
312 function IsValidFileName(const S: String): Boolean;
313 const
314 Forbidden: set of Char = ['<', '>', '|', '"', ':', '*', '?'];
315 var
316 I: Integer;
317 begin
318 Result := S <> '';
319 for I := 1 to Length(S) do
320 Result := Result and (not(S[I] in Forbidden));
321 end;
323 function IsValidFilePath(const S: String): Boolean;
324 var
325 I: Integer;
326 begin
327 Result := False;
328 if not IsValidFileName(S) then exit;
329 if FileExists(S) then exit;
330 I := LastDelimiter('\/', S);
331 if (I > 0) then
332 if (not DirectoryExists(Copy(S, 1, I-1))) then
333 exit;
334 Result := True;
335 end;
338 // HOST MESSAGES //
341 // GAME
343 procedure MH_MalformedPacket(C: pTNetClient);
344 begin
345 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
346 _lc[I_NET_DISC_PROTOCOL]);
347 g_Net_Host_Kick(C^.ID, NET_DISC_PROTOCOL);
348 end;
350 procedure MH_RECV_Chat(C: pTNetClient; var M: TMsg);
351 var
352 Txt: string;
353 Mode: Byte;
354 PID: Word;
355 Pl: TPlayer;
356 Err: Boolean;
357 begin
358 PID := C^.Player;
359 Pl := g_Player_Get(PID);
361 Err := False;
362 try
363 Txt := M.ReadString();
364 Mode := M.ReadByte();
365 except
366 Err := True;
367 end;
369 if Err then begin MH_MalformedPacket(C); Exit; end;
371 if (Mode = NET_CHAT_SYSTEM) then
372 Mode := NET_CHAT_PLAYER; // prevent sending system messages from clients
373 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
374 Mode := NET_CHAT_PLAYER; // revert to player chat in non-team game
376 if Pl = nil then
377 MH_SEND_Chat(Txt, Mode)
378 else
379 MH_SEND_Chat(Pl.Name + ': ' + Txt, Mode, IfThen(Mode = NET_CHAT_TEAM, Pl.Team, NET_EVERYONE));
380 end;
382 procedure MH_RECV_Info(C: pTNetClient; var M: TMsg);
383 var
384 Ver, PName, Model, Pw: string;
385 R, G, B, T: Byte;
386 WeapSwitch: Byte;
387 TmpPrefArray: Array [WP_FIRST .. WP_LAST + 1] of Byte;
388 SwitchEmpty: Byte;
389 SkipF: Byte;
390 PID: Word;
391 Color: TRGB;
392 I: Integer;
393 Err: Boolean;
394 begin
395 Err := False;
396 try
397 Ver := M.ReadString();
398 Pw := M.ReadString();
399 PName := M.ReadString();
400 Model := M.ReadString();
401 R := M.ReadByte();
402 G := M.ReadByte();
403 B := M.ReadByte();
404 T := M.ReadByte();
405 WeapSwitch := M.ReadByte();
406 for I := WP_FIRST to WP_LAST + 1 do
407 TmpPrefArray[I] := M.ReadByte();
408 SwitchEmpty := M.ReadByte();
409 SkipF := M.ReadByte();
410 except
411 Err := True;
412 end;
414 if Err then begin MH_MalformedPacket(C); Exit; end;
416 if Ver <> GAME_VERSION then
417 begin
418 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
419 _lc[I_NET_DISC_VERSION]);
420 g_Net_Host_Kick(C^.ID, NET_DISC_VERSION);
421 Exit;
422 end;
424 if g_Net_IsHostBanned(C^.Peer^.address.host) then
425 begin
426 if g_Net_IsHostBanned(C^.Peer^.address.host, True) then
427 begin
428 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
429 _lc[I_NET_DISC_BAN]);
430 g_Net_Host_Kick(C^.ID, NET_DISC_BAN);
431 end
432 else
433 begin
434 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
435 _lc[I_NET_DISC_BAN]);
436 g_Net_Host_Kick(C^.ID, NET_DISC_TEMPBAN);
437 end;
438 Exit;
439 end;
441 if NetPassword <> '' then
442 if AnsiLowerCase(NetPassword) <> AnsiLowerCase(Pw) then
443 begin
444 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
445 _lc[I_NET_DISC_PASSWORD]);
446 g_Net_Host_Kick(C^.ID, NET_DISC_PASSWORD);
447 Exit;
448 end;
450 if (C^.Player <> 0) then
451 begin
452 // already received info
453 g_Net_Penalize(C, 'client info spam');
454 Exit;
455 end;
457 Color.R := R;
458 Color.B := B;
459 Color.G := G;
461 PID := g_Player_Create(Model, Color, T, False);
462 with g_Player_Get(PID) do
463 begin
464 Name := PName;
465 WeapSwitchMode := WeapSwitch;
466 SetWeaponPrefs(TmpPrefArray);
467 SwitchToEmpty := SwitchEmpty;
468 SkipFist := SkipF;
469 if (g_Force_Model_Get() <> 0) then
470 SetModel(g_Forced_Model_GetName());
471 Reset(True);
472 end;
474 C^.Player := PID;
475 C^.WaitForFirstSpawn := false;
476 C^.AuthTime := 0;
478 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
479 e_WriteLog('NET: Client ' + PName + ' [' + IntToStr(C^.ID) +
480 '] connected. Assigned player #' + IntToStr(PID) + '.', TMsgType.Notify);
482 MH_SEND_Info(C^.ID);
484 with g_Player_Get(PID) do
485 begin
486 Name := PName;
487 FClientID := C^.ID;
488 // round in progress, don't spawn
489 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C.ID, C.Player]);
490 //e_LogWritefln('spawning player with pid #%u...', [PID]);
491 //Respawn(gGameSettings.GameType = GT_SINGLE);
492 //k8: no, do not spawn a player yet, wait for "request full state" packet
493 Lives := 0;
494 Spectate;
495 FNoRespawn := True;
496 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
497 // that is, if we'll set it to `true`, the player can be spawned after
498 // warmup time ran out, for example, regardless of the real player state.
499 // also, this seems to work only for the initial connection. further
500 // map changes could initiate resource downloading, but the player will
501 // be spawned immediately.
502 // the proper solution will require another player state, "ephemeral".
503 // the player should start any map in "ephemeral" state, and turned into
504 // real mobj only when they sent a special "i am ready" packet. this packet
505 // must be sent after receiving the full state, so the player will get a full
506 // map view before going into game.
507 FWantsInGame := false;
508 C^.WaitForFirstSpawn := true;
509 end;
511 //if not C^.WaitForFirstSpawn then
512 begin
513 for I := Low(NetClients) to High(NetClients) do
514 begin
515 if NetClients[I].ID = C^.ID then Continue;
516 MH_SEND_PlayerCreate(PID, NetClients[I].ID);
517 MH_SEND_PlayerPos(True, PID, NetClients[I].ID);
518 MH_SEND_PlayerStats(PID, NetClients[I].ID);
519 end;
520 end;
522 if gState in [STATE_INTERCUSTOM, STATE_FOLD] then
523 MH_SEND_GameEvent(NET_EV_MAPEND, 0, 'N', C^.ID);
525 if NetUseMaster then
526 begin
527 //g_Net_Slist_Update;
528 g_Net_Slist_Pulse();
529 end;
530 end;
533 procedure MH_ProcessFirstSpawn (C: pTNetClient);
534 var
535 plr: TPlayer;
536 begin
537 if not C.WaitForFirstSpawn then exit;
538 plr := g_Player_Get(C^.Player);
539 if not assigned(plr) then exit;
540 g_Net_Slist_ServerPlayerComes();
541 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C.ID, C.Player]);
542 C.WaitForFirstSpawn := false;
543 plr.FNoRespawn := false;
544 plr.FWantsInGame := true; // TODO: look into this later
546 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
547 begin
548 plr.Spectate;
549 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN, 0, 'N', C.ID);
550 end
551 else
552 begin
553 plr.Respawn(False);
554 if gLMSRespawn > LMS_RESPAWN_NONE then
555 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime, 'N', C.ID);
556 end;
557 end;
560 procedure MH_RECV_FullStateRequest(C: pTNetClient; var M: TMsg);
561 begin
562 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
564 if C^.FullUpdateSent then
565 begin
566 // FullStateRequest spam?
567 g_Net_Penalize(C, 'duplicate full state request');
568 exit;
569 end;
571 if gGameOn then
572 begin
573 MH_SEND_Everything((C^.State = NET_STATE_AUTH), C^.ID)
574 end
575 else
576 begin
577 C^.RequestedFullUpdate := True;
578 end;
579 end;
581 // PLAYER
583 function MH_RECV_PlayerPos(C: pTNetClient; var M: TMsg): Word;
584 var
585 Dir, i: Byte;
586 WeaponAct: Byte;
587 WeaponSelect: Word;
588 PID: Word;
589 kByte: Word;
590 Pl: TPlayer;
591 GT: LongWord;
592 Err: Boolean;
593 begin
594 Result := 0;
595 Err := False;
596 if not gGameOn then Exit;
598 try
599 GT := M.ReadLongWord();
600 except
601 Err := True;
602 end;
604 if Err then begin MH_MalformedPacket(C); Exit; end;
606 PID := C^.Player;
607 Pl := g_Player_Get(PID);
608 if Pl = nil then
609 Exit;
611 if (GT > gTime + NET_MAX_DIFFTIME) or (GT < Pl.NetTime) then Exit;
613 with Pl do
614 begin
615 NetTime := GT;
616 try
617 kByte := M.ReadWord();
618 Dir := M.ReadByte();
619 WeaponAct := M.ReadByte();
620 WeaponSelect := M.ReadWord();
621 except
622 Err := True;
623 end;
625 if Err then begin MH_MalformedPacket(C); Exit; end;
627 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
628 if Direction <> TDirection(Dir) then
629 JustTeleported := False;
631 SetDirection(TDirection(Dir));
632 ReleaseKeys;
634 if kByte = NET_KEY_CHAT then
635 begin
636 PressKey(KEY_CHAT, 10000);
637 Exit;
638 end;
640 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
641 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
642 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
643 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
644 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
645 if LongBool(kByte and NET_KEY_FIRE) then PressKey(KEY_FIRE, 10000);
646 if LongBool(kByte and NET_KEY_OPEN) then PressKey(KEY_OPEN, 10000);
648 for i := 0 to 7 do
649 begin
650 if (WeaponAct and Byte(1 shl i)) <> 0 then
651 begin
652 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
653 ProcessWeaponAction(i);
654 end;
655 end;
657 for i := 0 to 15 do
658 begin
659 if (WeaponSelect and Word(1 shl i)) <> 0 then
660 begin
661 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
662 QueueWeaponSwitch(i);
663 end;
664 end;
665 end;
667 // MH_SEND_PlayerPos(False, PID, C^.ID);
668 end;
670 procedure MH_RECV_CheatRequest(C: pTNetClient; var M: TMsg);
671 var
672 CheatKind: Byte;
673 Pl: TPlayer;
674 Err: Boolean;
675 begin
676 Err := False;
677 Pl := g_Player_Get(C^.Player);
678 if Pl = nil then Exit;
680 try
681 CheatKind := M.ReadByte();
682 except
683 Err := True;
684 end;
686 if Err then begin MH_MalformedPacket(C); Exit; end;
688 case CheatKind of
689 NET_CHEAT_SUICIDE:
690 Pl.Damage(SUICIDE_DAMAGE, Pl.UID, 0, 0, HIT_SELF);
691 NET_CHEAT_SPECTATE:
692 begin
693 if Pl.FSpectator then
694 begin
695 if (gGameSettings.MaxLives = 0) or (gLMSRespawn > LMS_RESPAWN_NONE) then
696 Pl.Respawn(False)
697 else
698 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN, Pl.UID);
699 end
700 else
701 Pl.Spectate;
702 end;
703 NET_CHEAT_READY:
704 begin
705 if gState <> STATE_INTERCUSTOM then Exit;
706 Pl.FReady := not Pl.FReady;
707 if Pl.FReady then
708 begin
709 MH_SEND_GameEvent(NET_EV_INTER_READY, Pl.UID, 'Y');
710 Inc(gInterReadyCount);
711 end
712 else
713 begin
714 MH_SEND_GameEvent(NET_EV_INTER_READY, Pl.UID, 'N');
715 Dec(gInterReadyCount);
716 end;
717 end;
718 NET_CHEAT_DROPFLAG:
719 Pl.TryDropFlag();
720 end;
721 end;
723 procedure MH_RECV_PlayerSettings(C: pTNetClient; var M: TMsg);
724 var
725 TmpName: string;
726 TmpModel: string;
727 TmpColor: TRGB;
728 TmpTeam: Byte;
729 TmpWeapSwitch: Byte;
730 TmpPrefArray: Array [WP_FIRST .. WP_LAST + 1] of Byte;
731 TmpSwEmpty: Byte;
732 TmpSkipF: Byte;
733 I: Integer;
734 Pl: TPlayer;
735 Err: Boolean;
736 begin
737 Err := False;
738 try
739 TmpName := M.ReadString();
740 TmpModel := M.ReadString();
741 TmpColor.R := M.ReadByte();
742 TmpColor.G := M.ReadByte();
743 TmpColor.B := M.ReadByte();
744 TmpTeam := M.ReadByte();
745 TmpWeapSwitch := M.ReadByte();
746 for I := WP_FIRST to WP_LAST + 1 do
747 TmpPrefArray[I] := M.ReadByte();
748 TmpSwEmpty := M.ReadByte();
749 TmpSkipF := M.ReadByte();
750 except
751 Err := True;
752 end;
754 if Err then begin MH_MalformedPacket(C); Exit; end;
756 Pl := g_Player_Get(C^.Player);
757 if Pl = nil then Exit;
759 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
760 Pl.SwitchTeam
761 else
762 Pl.SetColor(TmpColor);
764 if Pl.Name <> TmpName then
765 begin
766 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
767 Pl.Name := TmpName;
768 end;
770 if (g_Force_Model_Get() <> 0) then
771 TmpModel := g_Forced_Model_GetName();
772 if TmpModel <> Pl.Model.GetName() then
773 Pl.SetModel(TmpModel);
775 if (TmpWeapSwitch <> Pl.WeapSwitchMode) then
776 Pl.WeapSwitchMode := TmpWeapSwitch;
778 Pl.SetWeaponPrefs(TmpPrefArray);
779 if (TmpSwEmpty <> Pl.SwitchToEmpty) then
780 Pl.SwitchToEmpty := TmpSwEmpty;
782 if (TmpSkipF <> Pl.SkipFist) then
783 Pl.SkipFist := TmpSkipF;
785 MH_SEND_PlayerSettings(Pl.UID, TmpModel);
786 end;
788 // RCON
790 procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
791 var
792 Pwd: string;
793 Err: Boolean;
794 begin
795 Err := False;
796 try
797 Pwd := M.ReadString();
798 except
799 Err := True;
800 end;
801 if Err then begin MH_MalformedPacket(C); Exit; end;
802 if not NetAllowRCON then Exit;
803 if Pwd = NetRCONPassword then
804 begin
805 C^.RCONAuth := True;
806 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWGOOD, 'N', C^.ID);
807 end
808 else
809 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWBAD, 'N', C^.ID);
810 end;
812 procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
813 var
814 Cmd: string;
815 Err: Boolean;
816 begin
817 Err := False;
818 try
819 Cmd := M.ReadString();
820 except
821 Err := True;
822 end;
823 if Err then begin MH_MalformedPacket(C); Exit; end;
824 if not NetAllowRCON then Exit;
825 if not C^.RCONAuth then
826 begin
827 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_NOAUTH, 'N', C^.ID);
828 Exit;
829 end;
830 g_Console_Process(Cmd);
831 end;
833 // MISC
835 procedure MH_RECV_Vote(C: pTNetClient; var M: TMsg);
836 var
837 Start: Boolean;
838 Name, Command: string;
839 Need: Integer;
840 Pl: TPlayer;
841 Err: Boolean;
842 begin
843 Err := False;
844 try
845 Start := M.ReadByte() <> 0;
846 Command := M.ReadString();
847 except
848 Err := True;
849 end;
851 if Err then begin MH_MalformedPacket(C); Exit; end;
853 Pl := g_Player_Get(C^.Player);
854 if Pl = nil then Exit;
855 Name := Pl.Name;
857 if Start then
858 begin
859 if not g_Console_CommandBlacklisted(Command) then
860 g_Game_StartVote(Command, Name);
861 end
862 else if gVoteInProgress then
863 begin
864 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
865 Need := Floor((NetClientCount+1)/2.0) + 1
866 else
867 Need := Floor(NetClientCount/2.0) + 1;
868 if C^.Voted then
869 begin
870 Dec(gVoteCount);
871 C^.Voted := False;
872 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [Name, gVoteCount, Need]), True);
873 MH_SEND_VoteEvent(NET_VE_REVOKE, Name, 'a', gVoteCount, Need);
874 end
875 else
876 begin
877 Inc(gVoteCount);
878 C^.Voted := True;
879 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Name, gVoteCount, Need]), True);
880 MH_SEND_VoteEvent(NET_VE_VOTE, Name, 'a', gVoteCount, Need);
881 g_Game_CheckVote;
882 end;
883 end;
884 end;
886 // GAME (SEND)
888 procedure MH_SEND_Everything(CreatePlayers: Boolean {= False}; ID: Integer {= NET_EVERYONE});
890 function sendItemRespawn (it: PItem): Boolean;
891 begin
892 result := false; // don't stop
893 MH_SEND_ItemSpawn(True, it.myid, ID);
894 end;
896 function sendMonSpawn (mon: TMonster): Boolean;
897 begin
898 result := false; // don't stop
899 MH_SEND_MonsterSpawn(mon.UID, ID);
900 end;
902 function sendPanelState (pan: TPanel): Boolean;
903 begin
904 result := false; // don't stop
905 MH_SEND_PanelState(pan.guid, ID); // anyway, to sync mplats
906 if (pan.CanChangeTexture) then MH_SEND_PanelTexture(pan.guid, pan.LastAnimLoop, ID);
907 end;
909 var
910 I: Integer;
911 begin
912 if (ID < 0) or (ID >= Length(NetClients)) then
913 exit; // bogus client, this shouldn't happen
915 NetClients[ID].FullUpdateSent := True;
917 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID, NetClients[ID].Player]);
919 MH_ProcessFirstSpawn(@NetClients[ID]);
921 if gPlayers <> nil then
922 begin
923 for I := Low(gPlayers) to High(gPlayers) do
924 begin
925 if gPlayers[I] <> nil then
926 begin
927 if CreatePlayers then MH_SEND_PlayerCreate(gPlayers[I].UID, ID);
928 MH_SEND_PlayerPos(True, gPlayers[I].UID, ID);
929 MH_SEND_PlayerStats(gPlayers[I].UID, ID);
931 if (gPlayers[I].Flag <> FLAG_NONE) and (gGameSettings.GameMode = GM_CTF) then
932 begin
933 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED, gPlayers[I].Flag, gPlayers[I].UID, True, ID);
934 end;
935 end;
936 end;
937 end;
939 g_Items_ForEachAlive(sendItemRespawn, true); // backwards
940 g_Mons_ForEach(sendMonSpawn);
941 g_Map_ForEachPanel(sendPanelState);
943 if gTriggers <> nil then
944 begin
945 for I := Low(gTriggers) to High(gTriggers) do
946 begin
947 if gTriggers[I].TriggerType = TRIGGER_SOUND then
948 begin
949 MH_SEND_TriggerSound(gTriggers[I], ID);
950 end;
951 end;
952 end;
954 if Shots <> nil then
955 begin
956 for I := Low(Shots) to High(Shots) do
957 begin
958 if Shots[i].ShotType in [6, 7, 8] then
959 begin
960 MH_SEND_CreateShot(i, ID);
961 end;
962 end;
963 end;
965 MH_SEND_TriggerMusic(ID);
967 MH_SEND_GameStats(ID);
968 MH_SEND_CoopStats(ID);
970 if gGameSettings.GameMode = GM_CTF then
971 begin
972 if gFlags[FLAG_RED].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_RED].State, FLAG_RED, 0, True, ID);
973 if gFlags[FLAG_BLUE].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_BLUE].State, FLAG_BLUE, 0, True, ID);
974 end;
976 if CreatePlayers and (ID >= 0) then NetClients[ID].State := NET_STATE_GAME;
978 g_Net_Flush();
979 end;
981 procedure MH_SEND_Info(ID: Byte);
982 begin
983 NetOut.Clear();
985 NetOut.Write(Byte(NET_MSG_INFO));
986 NetOut.Write(ID);
987 NetOut.Write(NetClients[ID].Player);
988 NetOut.Write(ExtractFileName(gGameSettings.WAD));
989 NetOut.Write(g_ExtractFileName(gMapInfo.Map));
990 NetOut.Write(gWADHash);
991 NetOut.Write(gGameSettings.GameMode);
992 NetOut.Write(gGameSettings.ScoreLimit);
993 NetOut.Write(gGameSettings.TimeLimit);
994 NetOut.Write(gGameSettings.MaxLives);
995 NetOut.Write(gGameSettings.Options);
996 NetOut.Write(gTime);
998 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
999 end;
1001 procedure MH_SEND_Chat(Txt: string; Mode: Byte; ID: Integer = NET_EVERYONE);
1002 var
1003 Name: string;
1004 i: Integer;
1005 Team: Byte;
1006 begin
1007 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
1008 Mode := NET_CHAT_PLAYER;
1010 Team := 0;
1011 if (Mode = NET_CHAT_TEAM) then
1012 begin
1013 for i := Low(gPlayers) to High(gPlayers) do
1014 if (gPlayers[i] <> nil) and (gPlayers[i].FClientID >= 0) and
1015 (gPlayers[i].Team = ID) then
1016 begin
1017 NetOut.Write(Byte(NET_MSG_CHAT));
1018 NetOut.Write(Txt);
1019 NetOut.Write(Mode);
1020 g_Net_Host_Send(gPlayers[i].FClientID, True, NET_CHAN_CHAT);
1021 end;
1022 Team := ID;
1023 ID := NET_EVERYONE;
1024 end
1025 else
1026 begin
1027 NetOut.Write(Byte(NET_MSG_CHAT));
1028 NetOut.Write(Txt);
1029 NetOut.Write(Mode);
1030 g_Net_Host_Send(ID, True, NET_CHAN_CHAT);
1031 end;
1033 if Mode = NET_CHAT_SYSTEM then
1034 Exit;
1036 if ID = NET_EVERYONE then
1037 begin
1038 if Mode = NET_CHAT_PLAYER then
1039 begin
1040 g_Console_Add(Txt, True);
1041 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1042 g_Game_ChatSound(b_Text_Unformat(Txt));
1043 end
1044 else
1045 if Mode = NET_CHAT_TEAM then
1046 if gPlayer1 <> nil then
1047 begin
1048 if (gPlayer1.Team = TEAM_RED) and (Team = TEAM_RED) then
1049 begin
1050 g_Console_Add(#18'[Team] '#2 + Txt, True);
1051 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1052 g_Game_ChatSound(b_Text_Unformat(Txt));
1053 end
1054 else if (gPlayer1.Team = TEAM_BLUE) and (Team = TEAM_BLUE) then
1055 begin
1056 g_Console_Add(#20'[Team] '#2 + Txt, True);
1057 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1058 g_Game_ChatSound(b_Text_Unformat(Txt));
1059 end;
1060 end;
1061 end
1062 else
1063 begin
1064 Name := g_Net_ClientName_ByID(ID);
1065 g_Console_Add('-> ' + Name + ': ' + Txt, True);
1066 e_WriteLog('[Tell ' + Name + '] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1067 g_Game_ChatSound(b_Text_Unformat(Txt), False);
1068 end;
1069 end;
1071 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer = NET_EVERYONE);
1072 begin
1073 NetOut.Write(Byte(NET_MSG_GFX));
1074 NetOut.Write(Kind);
1075 NetOut.Write(X);
1076 NetOut.Write(Y);
1077 NetOut.Write(Ang);
1079 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
1080 end;
1082 procedure MH_SEND_Sound(X, Y: Integer; Name: string; Pos: Boolean = True; ID: Integer = NET_EVERYONE);
1083 begin
1084 NetOut.Write(Byte(NET_MSG_SND));
1085 NetOut.Write(Name);
1086 if Pos then
1087 begin
1088 NetOut.Write(Byte(1));
1089 NetOut.Write(X);
1090 NetOut.Write(Y);
1091 end
1092 else
1093 NetOut.Write(Byte(0));
1095 g_Net_Host_Send(ID, False, NET_CHAN_GAME);
1096 end;
1098 procedure MH_SEND_CreateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
1099 begin
1100 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
1102 NetOut.Write(Byte(NET_MSG_SHADD));
1103 NetOut.Write(Proj);
1104 NetOut.Write(Shots[Proj].ShotType);
1105 NetOut.Write(Shots[Proj].Target);
1106 NetOut.Write(Shots[Proj].SpawnerUID);
1107 NetOut.Write(Shots[Proj].Timeout);
1108 NetOut.Write(Shots[Proj].Obj.X);
1109 NetOut.Write(Shots[Proj].Obj.Y);
1110 NetOut.Write(Shots[Proj].Obj.Vel.X);
1111 NetOut.Write(Shots[Proj].Obj.Vel.Y);
1113 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1114 end;
1116 procedure MH_SEND_UpdateShot(Proj: LongInt; ID: Integer = NET_EVERYONE);
1117 begin
1118 if (Shots = nil) or (Proj < 0) or (Proj > High(Shots)) then Exit;
1120 NetOut.Write(Byte(NET_MSG_SHPOS));
1121 NetOut.Write(Proj);
1122 NetOut.Write(Shots[Proj].Obj.X);
1123 NetOut.Write(Shots[Proj].Obj.Y);
1124 NetOut.Write(Shots[Proj].Obj.Vel.X);
1125 NetOut.Write(Shots[Proj].Obj.Vel.Y);
1127 g_Net_Host_Send(ID, False, NET_CHAN_SHOTS);
1128 end;
1130 procedure MH_Send_DeleteShot(Proj: LongInt; X, Y: LongInt; Loud: Boolean = True; ID: Integer = NET_EVERYONE);
1131 begin
1132 NetOut.Write(Byte(NET_MSG_SHDEL));
1133 NetOut.Write(Proj);
1134 NetOut.Write(Byte(Loud));
1135 NetOut.Write(X);
1136 NetOut.Write(Y);
1138 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1139 end;
1141 procedure MH_SEND_GameStats(ID: Integer = NET_EVERYONE);
1142 begin
1143 NetOut.Write(Byte(NET_MSG_SCORE));
1144 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1145 begin
1146 NetOut.Write(gTeamStat[TEAM_RED].Score);
1147 NetOut.Write(gTeamStat[TEAM_BLUE].Score);
1148 end
1149 else
1150 if gGameSettings.GameMode = GM_COOP then
1151 begin
1152 NetOut.Write(gCoopMonstersKilled);
1153 NetOut.Write(gCoopSecretsFound);
1154 end;
1156 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1157 end;
1159 procedure MH_SEND_CoopStats(ID: Integer = NET_EVERYONE);
1160 begin
1161 NetOut.Write(Byte(NET_MSG_COOP));
1162 NetOut.Write(gTotalMonsters);
1163 NetOut.Write(gSecretsCount);
1164 NetOut.Write(gCoopTotalMonstersKilled);
1165 NetOut.Write(gCoopTotalSecretsFound);
1166 NetOut.Write(gCoopTotalMonsters);
1167 NetOut.Write(gCoopTotalSecrets);
1168 end;
1170 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer = 0; EvStr: string = 'N'; ID: Integer = NET_EVERYONE);
1171 begin
1172 NetOut.Write(Byte(NET_MSG_GEVENT));
1173 NetOut.Write(EvType);
1174 NetOut.Write(EvNum);
1175 NetOut.Write(EvStr);
1176 NetOut.Write(Byte(gLastMap));
1177 NetOut.Write(gTime);
1178 if (EvType = NET_EV_MAPSTART) and isWadPath(EvStr) then
1179 begin
1180 NetOut.Write(Byte(1));
1181 NetOut.Write(gWADHash);
1182 end else
1183 NetOut.Write(Byte(0));
1185 g_Net_Host_Send(ID, True, NET_CHAN_SERVICE);
1186 end;
1188 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean = False; ID: Integer = NET_EVERYONE);
1189 begin
1190 NetOut.Write(Byte(NET_MSG_FLAG));
1191 NetOut.Write(EvType);
1192 NetOut.Write(Flag);
1193 NetOut.Write(Byte(Quiet));
1194 NetOut.Write(PID);
1195 NetOut.Write(gFlags[Flag].State);
1196 NetOut.Write(gFlags[Flag].CaptureTime);
1197 NetOut.Write(gFlags[Flag].Obj.X);
1198 NetOut.Write(gFlags[Flag].Obj.Y);
1199 NetOut.Write(gFlags[Flag].Obj.Vel.X);
1200 NetOut.Write(gFlags[Flag].Obj.Vel.Y);
1201 NetOut.Write(Byte(gFlags[Flag].Direction));
1203 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1204 end;
1206 procedure MH_SEND_FlagPos(Flag: Byte; ID: Integer = NET_EVERYONE);
1207 begin
1208 NetOut.Write(Byte(NET_MSG_FLAGPOS));
1209 NetOut.Write(Flag);
1210 NetOut.Write(gFlags[Flag].Obj.X);
1211 NetOut.Write(gFlags[Flag].Obj.Y);
1212 NetOut.Write(gFlags[Flag].Obj.Vel.X);
1213 NetOut.Write(gFlags[Flag].Obj.Vel.Y);
1215 g_Net_Host_Send(ID, False, NET_CHAN_IMPORTANT);
1216 end;
1218 procedure MH_SEND_GameSettings(ID: Integer = NET_EVERYONE);
1219 begin
1220 NetOut.Write(Byte(NET_MSG_GSET));
1221 NetOut.Write(gGameSettings.GameMode);
1222 NetOut.Write(gGameSettings.ScoreLimit);
1223 NetOut.Write(gGameSettings.TimeLimit);
1224 NetOut.Write(gGameSettings.MaxLives);
1225 NetOut.Write(gGameSettings.Options);
1227 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1228 end;
1230 // PLAYER (SEND)
1232 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer = NET_EVERYONE);
1233 var
1234 P: TPlayer;
1235 begin
1236 P := g_Player_Get(PID);
1237 if P = nil then Exit;
1239 NetOut.Write(Byte(NET_MSG_PLR));
1240 NetOut.Write(PID);
1241 NetOut.Write(P.Name);
1243 NetOut.Write(P.FActualModelName);
1244 NetOut.Write(P.FColor.R);
1245 NetOut.Write(P.FColor.G);
1246 NetOut.Write(P.FColor.B);
1247 NetOut.Write(P.Team);
1249 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT)
1250 end;
1252 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer = NET_EVERYONE);
1253 var
1254 kByte: Word;
1255 Pl: TPlayer;
1256 begin
1257 Pl := g_Player_Get(PID);
1258 if Pl = nil then Exit;
1259 if Pl.FDummy then Exit;
1261 NetOut.Write(Byte(NET_MSG_PLRPOS));
1262 NetOut.Write(gTime);
1263 NetOut.Write(PID);
1265 kByte := 0;
1267 with Pl do
1268 begin
1269 NetOut.Write(FPing);
1270 NetOut.Write(FLoss);
1271 if IsKeyPressed(KEY_CHAT) then
1272 kByte := NET_KEY_CHAT
1273 else
1274 begin
1275 if IsKeyPressed(KEY_LEFT) then kByte := kByte or NET_KEY_LEFT;
1276 if IsKeyPressed(KEY_RIGHT) then kByte := kByte or NET_KEY_RIGHT;
1277 if IsKeyPressed(KEY_UP) then kByte := kByte or NET_KEY_UP;
1278 if IsKeyPressed(KEY_DOWN) then kByte := kByte or NET_KEY_DOWN;
1279 if IsKeyPressed(KEY_JUMP) then kByte := kByte or NET_KEY_JUMP;
1280 end;
1282 if JustTeleported then kByte := kByte or NET_KEY_FORCEDIR;
1284 NetOut.Write(kByte);
1285 if Direction = TDirection.D_LEFT then NetOut.Write(Byte(0)) else NetOut.Write(Byte(1));
1286 NetOut.Write(GameX);
1287 NetOut.Write(GameY);
1288 NetOut.Write(GameVelX);
1289 NetOut.Write(GameVelY);
1290 NetOut.Write(GameAccelX);
1291 NetOut.Write(GameAccelY);
1292 end;
1294 g_Net_Host_Send(ID, Reliable, NET_CHAN_PLAYERPOS);
1295 end;
1297 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer = NET_EVERYONE);
1298 var
1299 P: TPlayer;
1300 I: Integer;
1301 begin
1302 P := g_Player_Get(PID);
1303 if P = nil then Exit;
1305 NetOut.Write(Byte(NET_MSG_PLRSTA));
1306 NetOut.Write(PID);
1308 with P do
1309 begin
1310 NetOut.Write(Byte(alive));
1311 NetOut.Write(Byte(GodMode));
1312 NetOut.Write(Health);
1313 NetOut.Write(Armor);
1314 NetOut.Write(Air);
1315 NetOut.Write(JetFuel);
1316 NetOut.Write(Lives);
1317 NetOut.Write(Team);
1319 for I := WP_FIRST to WP_LAST do
1320 NetOut.Write(Byte(FWeapon[I]));
1322 for I := A_BULLETS to A_HIGH do
1323 NetOut.Write(FAmmo[I]);
1325 for I := A_BULLETS to A_HIGH do
1326 NetOut.Write(FMaxAmmo[I]);
1328 for I := MR_SUIT to MR_MAX do
1329 NetOut.Write(LongWord(FMegaRulez[I]));
1331 NetOut.Write(Byte(R_ITEM_BACKPACK in FRulez));
1332 NetOut.Write(Byte(R_KEY_RED in FRulez));
1333 NetOut.Write(Byte(R_KEY_GREEN in FRulez));
1334 NetOut.Write(Byte(R_KEY_BLUE in FRulez));
1335 NetOut.Write(Byte(R_BERSERK in FRulez));
1337 NetOut.Write(Frags);
1338 NetOut.Write(Death);
1340 NetOut.Write(CurrWeap);
1342 NetOut.Write(Byte(FSpectator));
1343 NetOut.Write(Byte(FGhost));
1344 NetOut.Write(Byte(FPhysics));
1345 NetOut.Write(Byte(FNoRespawn));
1346 NetOut.Write(Byte(FJetpack));
1347 NetOut.Write(FFireTime);
1348 NetOut.Write(Byte(FFlaming));
1349 NetOut.Write(FSpawnInvul);
1350 end;
1352 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1353 end;
1355 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer = NET_EVERYONE);
1356 begin
1357 NetOut.Write(Byte(NET_MSG_PLRDMG));
1358 NetOut.Write(PID);
1359 NetOut.Write(Kind);
1360 NetOut.Write(Attacker);
1361 NetOut.Write(Value);
1362 NetOut.Write(VX);
1363 NetOut.Write(VY);
1365 g_Net_Host_Send(ID, False, NET_CHAN_PLAYER);
1366 end;
1368 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer = NET_EVERYONE);
1369 begin
1370 NetOut.Write(Byte(NET_MSG_PLRDIE));
1371 NetOut.Write(PID);
1372 NetOut.Write(KillType);
1373 NetOut.Write(DeathType);
1374 NetOut.Write(Attacker);
1376 g_Net_Host_Send(ID, True, NET_CHAN_PLAYER);
1377 end;
1379 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer = -1; ID: Integer = NET_EVERYONE);
1380 begin
1381 NetOut.Write(Byte(NET_MSG_PLRFIRE));
1382 NetOut.Write(PID);
1383 NetOut.Write(Weapon);
1384 NetOut.Write(X);
1385 NetOut.Write(Y);
1386 NetOut.Write(AX);
1387 NetOut.Write(AY);
1388 NetOut.Write(ShotID);
1390 g_Net_Host_Send(ID, True, NET_CHAN_SHOTS);
1391 end;
1393 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer = NET_EVERYONE);
1394 begin
1395 NetOut.Write(Byte(NET_MSG_PLRDEL));
1396 NetOut.Write(PID);
1398 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1399 end;
1401 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: string = ''; ID: Integer = NET_EVERYONE);
1402 var
1403 Pl: TPlayer;
1404 begin
1405 Pl := g_Player_Get(PID);
1406 if Pl = nil then Exit;
1408 NetOut.Write(Byte(NET_MSG_PLRSET));
1409 NetOut.Write(PID);
1410 NetOut.Write(Pl.Name);
1411 if Mdl = '' then
1412 NetOut.Write(Pl.Model.GetName())
1413 else
1414 NetOut.Write(Mdl);
1415 NetOut.Write(Pl.FColor.R);
1416 NetOut.Write(Pl.FColor.G);
1417 NetOut.Write(Pl.FColor.B);
1418 NetOut.Write(Pl.Team);
1420 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1421 end;
1423 // ITEM (SEND)
1425 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1426 var
1427 it: PItem;
1428 tt: Byte;
1429 begin
1430 it := g_Items_ByIdx(IID);
1432 NetOut.Write(Byte(NET_MSG_ISPAWN));
1433 NetOut.Write(IID);
1434 NetOut.Write(Byte(Quiet));
1435 tt := it.ItemType;
1436 if it.dropped then tt := tt or $80;
1437 NetOut.Write(tt);
1438 NetOut.Write(Byte(it.Fall));
1439 NetOut.Write(Byte(it.Respawnable));
1440 NetOut.Write(it.Obj.X);
1441 NetOut.Write(it.Obj.Y);
1442 NetOut.Write(it.Obj.Vel.X);
1443 NetOut.Write(it.Obj.Vel.Y);
1445 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1446 end;
1448 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer = NET_EVERYONE);
1449 begin
1450 NetOut.Write(Byte(NET_MSG_IDEL));
1451 NetOut.Write(IID);
1452 NetOut.Write(Byte(Quiet));
1454 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1455 end;
1457 procedure MH_SEND_ItemPos(IID: Word; ID: Integer = NET_EVERYONE);
1458 var
1459 it: PItem;
1460 begin
1461 it := g_Items_ByIdx(IID);
1463 NetOut.Write(Byte(NET_MSG_IPOS));
1464 NetOut.Write(IID);
1465 NetOut.Write(it.Obj.X);
1466 NetOut.Write(it.Obj.Y);
1467 NetOut.Write(it.Obj.Vel.X);
1468 NetOut.Write(it.Obj.Vel.Y);
1470 g_Net_Host_Send(ID, False, NET_CHAN_LARGEDATA);
1471 end;
1473 // PANEL
1475 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer = NET_EVERYONE);
1476 var
1477 TP: TPanel;
1478 begin
1479 TP := g_Map_PanelByGUID(PGUID);
1480 if (TP = nil) then exit;
1482 with TP do
1483 begin
1484 NetOut.Write(Byte(NET_MSG_PTEX));
1485 NetOut.Write(LongWord(PGUID));
1486 NetOut.Write(FCurTexture);
1487 NetOut.Write(FCurFrame);
1488 NetOut.Write(FCurFrameCount);
1489 NetOut.Write(AnimLoop);
1490 end;
1492 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1493 end;
1495 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer = NET_EVERYONE);
1496 var
1497 TP: TPanel;
1498 mpflags: Byte = 0;
1499 begin
1500 TP := g_Map_PanelByGUID(PGUID);
1501 if (TP = nil) then exit;
1503 NetOut.Write(Byte(NET_MSG_PSTATE));
1504 NetOut.Write(LongWord(PGUID));
1505 NetOut.Write(Byte(TP.Enabled));
1506 NetOut.Write(TP.LiftType);
1507 NetOut.Write(TP.X);
1508 NetOut.Write(TP.Y);
1509 NetOut.Write(Word(TP.Width));
1510 NetOut.Write(Word(TP.Height));
1511 // mplats
1512 NetOut.Write(LongInt(TP.movingSpeedX));
1513 NetOut.Write(LongInt(TP.movingSpeedY));
1514 NetOut.Write(LongInt(TP.movingStartX));
1515 NetOut.Write(LongInt(TP.movingStartY));
1516 NetOut.Write(LongInt(TP.movingEndX));
1517 NetOut.Write(LongInt(TP.movingEndY));
1518 NetOut.Write(LongInt(TP.sizeSpeedX));
1519 NetOut.Write(LongInt(TP.sizeSpeedY));
1520 NetOut.Write(LongInt(TP.sizeEndX));
1521 NetOut.Write(LongInt(TP.sizeEndY));
1522 if TP.movingActive then mpflags := mpflags or 1;
1523 if TP.moveOnce then mpflags := mpflags or 2;
1524 NetOut.Write(Byte(mpflags));
1526 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1527 end;
1529 // TRIGGER
1531 procedure MH_SEND_TriggerSound(var T: TTrigger; ID: Integer = NET_EVERYONE);
1532 begin
1533 if gTriggers = nil then Exit;
1534 if T.Sound = nil then Exit;
1536 NetOut.Write(Byte(NET_MSG_TSOUND));
1537 NetOut.Write(T.ClientID);
1538 NetOut.Write(Byte(T.Sound.IsPlaying));
1539 NetOut.Write(LongWord(T.Sound.GetPosition));
1540 NetOut.Write(T.SoundPlayCount);
1542 g_Net_Host_Send(ID, True);
1543 end;
1545 procedure MH_SEND_TriggerMusic(ID: Integer = NET_EVERYONE);
1546 begin
1547 NetOut.Write(Byte(NET_MSG_TMUSIC));
1548 NetOut.Write(gMusic.Name);
1549 NetOut.Write(Byte(gMusic.IsPlaying));
1550 NetOut.Write(LongWord(gMusic.GetPosition));
1551 NetOut.Write(Byte(gMusic.SpecPause or gMusic.IsPaused));
1553 g_Net_Host_Send(ID, True);
1554 end;
1556 // MONSTER
1558 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer = NET_EVERYONE);
1559 var
1560 M: TMonster;
1561 begin
1562 M := g_Monsters_ByUID(UID);
1563 if M = nil then
1564 Exit;
1566 with M do
1567 begin
1568 NetOut.Write(Byte(NET_MSG_MSPAWN));
1569 NetOut.Write(UID);
1570 NetOut.Write(MonsterType);
1571 NetOut.Write(MonsterState);
1572 NetOut.Write(MonsterAnim);
1573 NetOut.Write(MonsterTargetUID);
1574 NetOut.Write(MonsterTargetTime);
1575 NetOut.Write(MonsterBehaviour);
1576 NetOut.Write(MonsterSleep);
1577 NetOut.Write(MonsterHealth);
1578 NetOut.Write(MonsterAmmo);
1579 NetOut.Write(GameX);
1580 NetOut.Write(GameY);
1581 NetOut.Write(GameVelX);
1582 NetOut.Write(GameVelY);
1583 NetOut.Write(Byte(GameDirection));
1584 end;
1586 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1587 end;
1589 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer = NET_EVERYONE);
1590 var
1591 M: TMonster;
1592 begin
1593 M := g_Monsters_ByUID(UID);
1594 if M = nil then Exit;
1596 NetOut.Write(Byte(NET_MSG_MPOS));
1597 NetOut.Write(UID);
1599 with M do
1600 begin
1601 NetOut.Write(GameX);
1602 NetOut.Write(GameY);
1603 NetOut.Write(GameVelX);
1604 NetOut.Write(GameVelY);
1605 NetOut.Write(Byte(GameDirection));
1606 end;
1608 g_Net_Host_Send(ID, False, NET_CHAN_MONSTERPOS);
1609 end;
1611 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte = 255; ID: Integer = NET_EVERYONE);
1612 var
1613 M: TMonster;
1614 begin
1615 M := g_Monsters_ByUID(UID);
1616 if M = nil then Exit;
1618 NetOut.Write(Byte(NET_MSG_MSTATE));
1619 NetOut.Write(UID);
1621 with M do
1622 begin
1623 NetOut.Write(MonsterState);
1624 NetOut.Write(ForcedAnim);
1625 NetOut.Write(MonsterTargetUID);
1626 NetOut.Write(MonsterTargetTime);
1627 NetOut.Write(MonsterSleep);
1628 NetOut.Write(MonsterHealth);
1629 NetOut.Write(MonsterAmmo);
1630 NetOut.Write(MonsterPain);
1631 NetOut.Write(Byte(AnimIsReverse));
1632 NetOut.Write(FFireTime);
1633 end;
1635 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1636 end;
1638 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer = NET_EVERYONE);
1639 begin
1640 NetOut.Write(Byte(NET_MSG_MSHOT));
1641 NetOut.Write(UID);
1642 NetOut.Write(X);
1643 NetOut.Write(Y);
1644 NetOut.Write(VX);
1645 NetOut.Write(VY);
1647 g_Net_Host_Send(ID, True, NET_CHAN_MONSTER);
1648 end;
1650 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer = NET_EVERYONE);
1651 var
1652 M: TMonster;
1653 begin
1654 M := g_Monsters_ByUID(UID);
1655 if M = nil then Exit;
1657 NetOut.Write(Byte(NET_MSG_MDEL));
1658 NetOut.Write(UID);
1660 g_Net_Host_Send(ID, True, NET_CHAN_LARGEDATA);
1661 end;
1663 // MISC
1665 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
1666 begin
1667 NetOut.Write(Byte(NET_MSG_TIME_SYNC));
1668 NetOut.Write(Time);
1670 g_Net_Host_Send(ID, False, NET_CHAN_SERVICE);
1671 end;
1673 procedure MH_SEND_VoteEvent(EvType: Byte;
1674 StrArg1: string = 'a'; StrArg2: string = 'b';
1675 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0;
1676 ID: Integer = NET_EVERYONE);
1677 begin
1678 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
1679 NetOut.Write(EvType);
1680 NetOut.Write(IntArg1);
1681 NetOut.Write(IntArg2);
1682 NetOut.Write(StrArg1);
1683 NetOut.Write(StrArg2);
1685 g_Net_Host_Send(ID, True, NET_CHAN_IMPORTANT);
1686 end;
1688 // CLIENT MESSAGES //
1690 // GAME
1692 procedure MC_RECV_Chat(var M: TMsg);
1693 var
1694 Txt: string;
1695 Mode: Byte;
1696 begin
1697 Txt := M.ReadString();
1698 Mode := M.ReadByte();
1700 if Mode <> NET_CHAT_SYSTEM then
1701 begin
1702 if NetDeafLevel = 0 then
1703 begin
1704 if Mode = NET_CHAT_PLAYER then
1705 begin
1706 g_Console_Add(Txt, True);
1707 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1708 g_Game_ChatSound(b_Text_Unformat(Txt));
1709 end else
1710 if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then
1711 begin
1712 if gPlayer1.Team = TEAM_RED then
1713 g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True);
1714 if gPlayer1.Team = TEAM_BLUE then
1715 g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True);
1716 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1717 g_Game_ChatSound(b_Text_Unformat(Txt));
1718 end;
1719 end;
1720 end else if (NetDeafLevel < 2) then
1721 g_Console_Add(Txt, True);
1722 end;
1724 procedure MC_RECV_Effect(var M: TMsg);
1725 var
1726 Kind: Byte;
1727 X, Y: Integer;
1728 Ang: SmallInt;
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 g_GFX_QueueEffect(R_GFX_TELEPORT_FAST, X, Y);
1743 if Ang = 1 then
1744 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
1745 end;
1747 NET_GFX_EXPLODE:
1748 begin
1749 g_GFX_QueueEffect(R_GFX_EXPLODE_ROCKET, X - 64, Y - 64);
1750 if Ang = 1 then
1751 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X, Y);
1752 end;
1754 NET_GFX_BFGEXPL:
1755 begin
1756 g_GFX_QueueEffect(R_GFX_EXPLODE_BFG, X - 64, Y - 64);
1757 if Ang = 1 then
1758 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X, Y);
1759 end;
1761 NET_GFX_BFGHIT:
1762 begin
1763 g_GFX_QueueEffect(R_GFX_BFG_HIT, X - 32, Y - 32);
1764 end;
1766 NET_GFX_FIRE:
1767 begin
1768 g_GFX_QueueEffect(R_GFX_FIRE, X, Y);
1769 if Ang = 1 then
1770 g_Sound_PlayExAt('SOUND_FIRE', X, Y);
1771 end;
1773 NET_GFX_RESPAWN:
1774 begin
1775 g_GFX_QueueEffect(R_GFX_ITEM_RESPAWN, X, Y);
1776 if Ang = 1 then
1777 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
1778 end;
1780 NET_GFX_SHELL1:
1781 g_Player_CreateShell(X, Y, 0, -2, SHELL_BULLET);
1783 NET_GFX_SHELL2:
1784 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1786 NET_GFX_SHELL3:
1787 begin
1788 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1789 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1790 end;
1791 end;
1792 end;
1794 procedure MC_RECV_Sound(var M: TMsg);
1795 var
1796 Name: string;
1797 X, Y: Integer;
1798 Pos: Boolean;
1799 begin
1800 Name := M.ReadString();
1801 Pos := M.ReadByte() <> 0;
1802 if Pos then
1803 begin
1804 X := M.ReadLongInt();
1805 Y := M.ReadLongInt();
1806 g_Sound_PlayExAt(Name, X, Y);
1807 end
1808 else
1809 g_Sound_PlayEx(Name);
1810 end;
1812 procedure MC_RECV_CreateShot(var M: TMsg);
1813 var
1814 I, X, Y, XV, YV: Integer;
1815 Timeout: LongWord;
1816 Target, Spawner: Word;
1817 ShType: Byte;
1818 begin
1819 I := M.ReadLongInt();
1820 ShType := M.ReadByte();
1821 Target := M.ReadWord();
1822 Spawner := M.ReadWord();
1823 Timeout := M.ReadLongWord();
1824 X := M.ReadLongInt();
1825 Y := M.ReadLongInt();
1826 XV := M.ReadLongInt();
1827 YV := M.ReadLongInt();
1829 I := g_Weapon_CreateShot(I, ShType, Spawner, Target, X, Y, XV, YV);
1830 if (Shots <> nil) and (I <= High(Shots)) then
1831 begin
1832 Shots[I].Timeout := Timeout;
1833 //Shots[I].Target := Target; // TODO: find a use for Target later
1834 end;
1835 end;
1837 procedure MC_RECV_UpdateShot(var M: TMsg);
1838 var
1839 I, TX, TY, TXV, TYV: Integer;
1840 begin
1841 I := M.ReadLongInt();
1842 TX := M.ReadLongInt();
1843 TY := M.ReadLongInt();
1844 TXV := M.ReadLongInt();
1845 TYV := M.ReadLongInt();
1847 if (Shots <> nil) and (I <= High(Shots)) then
1848 with (Shots[i]) do
1849 begin
1850 Obj.X := TX;
1851 Obj.Y := TY;
1852 Obj.Vel.X := TXV;
1853 Obj.Vel.Y := TYV;
1854 end;
1855 end;
1857 procedure MC_RECV_DeleteShot(var M: TMsg);
1858 var
1859 I, X, Y: Integer;
1860 L: Boolean;
1861 begin
1862 if not gGameOn then Exit;
1863 I := M.ReadLongInt();
1864 L := (M.ReadByte() <> 0);
1865 X := M.ReadLongInt();
1866 Y := M.ReadLongInt();
1868 g_Weapon_DestroyShot(I, X, Y, L);
1869 end;
1871 procedure MC_RECV_GameStats(var M: TMsg);
1872 begin
1873 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1874 begin
1875 gTeamStat[TEAM_RED].Score := M.ReadSmallInt();
1876 gTeamStat[TEAM_BLUE].Score := M.ReadSmallInt();
1877 end
1878 else
1879 if gGameSettings.GameMode = GM_COOP then
1880 begin
1881 gCoopMonstersKilled := M.ReadWord();
1882 gCoopSecretsFound := M.ReadWord();
1883 end;
1884 end;
1886 procedure MC_RECV_CoopStats(var M: TMsg);
1887 begin
1888 gTotalMonsters := M.ReadLongInt();
1889 gSecretsCount := M.ReadLongInt();
1890 gCoopTotalMonstersKilled := M.ReadWord();
1891 gCoopTotalSecretsFound := M.ReadWord();
1892 gCoopTotalMonsters := M.ReadWord();
1893 gCoopTotalSecrets := M.ReadWord();
1894 end;
1896 procedure MC_RECV_GameEvent(var M: TMsg);
1897 var
1898 EvType: Byte;
1899 EvNum: Integer;
1900 EvStr: string;
1901 EvTime: LongWord;
1902 BHash: Boolean;
1903 EvHash: TMD5Digest;
1904 pl: TPlayer;
1905 i1, i2: TStrings_Locale;
1906 pln: String;
1907 cnt: Byte;
1908 goodCmd: Boolean = true;
1909 begin
1910 FillChar(EvHash, Sizeof(EvHash), 0);
1911 EvType := M.ReadByte();
1912 EvNum := M.ReadLongInt();
1913 EvStr := M.ReadString();
1914 gLastMap := M.ReadByte() <> 0;
1915 if gLastMap and (gGameSettings.GameMode = GM_COOP) then gStatsOff := True;
1916 gStatsPressed := True;
1917 EvTime := M.ReadLongWord();
1918 BHash := M.ReadByte() <> 0;
1919 if BHash then
1920 EvHash := M.ReadMD5();
1922 gTime := EvTime;
1924 if (g_Res_received_map_start <> 0) then
1925 begin
1926 if (g_Res_received_map_start < 0) then exit;
1927 goodCmd := false;
1928 case EvType of
1929 NET_EV_MAPSTART: goodCmd := true;
1930 NET_EV_MAPEND: goodCmd := true;
1931 NET_EV_PLAYER_KICK: goodCmd := true;
1932 NET_EV_PLAYER_BAN: goodCmd := true;
1933 NET_EV_LMS_WARMUP: goodCmd := true;
1934 end;
1935 if not goodCmd then exit;
1936 end;
1938 case EvType of
1939 NET_EV_MAPSTART:
1940 begin
1941 if (g_Res_received_map_start <> 0) then
1942 begin
1943 g_Res_received_map_start := -1;
1944 end
1945 else
1946 begin
1947 gGameOn := False;
1948 g_Game_ClearLoading();
1949 g_Game_StopAllSounds(True);
1951 gSwitchGameMode := Byte(EvNum);
1952 gGameSettings.GameMode := gSwitchGameMode;
1954 gWADHash := EvHash;
1955 if not g_Game_StartMap(false{asMegawad}, EvStr, True) then
1956 begin
1957 if not isWadPath(EvStr) then
1958 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + EvStr]))
1959 else
1960 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [EvStr]));
1961 Exit;
1962 end;
1964 MC_SEND_FullStateRequest;
1965 end;
1966 end;
1968 NET_EV_MAPEND:
1969 begin
1970 gLMSRespawn := LMS_RESPAWN_NONE;
1971 gLMSRespawnTime := 0;
1972 if (g_Res_received_map_start <> 0) then
1973 begin
1974 g_Res_received_map_start := -1;
1975 end
1976 else
1977 begin
1978 gMissionFailed := EvNum <> 0;
1979 gExit := EXIT_ENDLEVELCUSTOM;
1980 end;
1981 end;
1983 NET_EV_RCON:
1984 begin
1985 case EvNum of
1986 NET_RCON_NOAUTH:
1987 g_Console_Add(_lc[I_NET_RCON_NOAUTH], True);
1988 NET_RCON_PWGOOD:
1989 g_Console_Add(_lc[I_NET_RCON_PWD_VALID], True);
1990 NET_RCON_PWBAD:
1991 g_Console_Add(_lc[I_NET_RCON_PWD_INVALID], True);
1992 end;
1993 end;
1995 NET_EV_CHANGE_TEAM:
1996 begin
1997 if NetDeafLevel < 2 then
1998 begin
1999 if EvNum = TEAM_RED then
2000 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True);
2001 if EvNum = TEAM_BLUE then
2002 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True);
2003 end;
2004 end;
2006 NET_EV_PLAYER_KICK:
2007 begin
2008 g_Console_Add(Format(_lc[I_PLAYER_KICK], [EvStr]), True);
2009 if (g_Res_received_map_start <> 0) then g_Res_received_map_start := -1;
2010 end;
2012 NET_EV_PLAYER_BAN:
2013 begin
2014 g_Console_Add(Format(_lc[I_PLAYER_BAN], [EvStr]), True);
2015 if (g_Res_received_map_start <> 0) then g_Res_received_map_start := -1;
2016 end;
2018 NET_EV_LMS_WARMUP:
2019 begin
2020 if EvNum > 0 then
2021 begin
2022 gLMSRespawn := LMS_RESPAWN_WARMUP;
2023 gLMSRespawnTime := gTime + EvNum;
2024 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [EvNum div 1000]), True);
2025 end
2026 else if gPlayer1 = nil then
2027 begin
2028 g_Console_Add(_lc[I_PLAYER_SPECT4], True);
2029 end;
2030 end;
2032 NET_EV_LMS_SURVIVOR:
2033 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True);
2035 NET_EV_BIGTEXT:
2036 if NetDeafLevel < 2 then g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum));
2038 NET_EV_SCORE:
2039 begin
2040 pl := g_Player_Get(EvNum and $FFFF);
2041 if pl = nil then
2042 pln := '?'
2043 else
2044 pln := pl.Name;
2045 cnt := (EvNum shr 16) and $FF;
2046 if Pos('w', EvStr) = 0 then
2047 begin
2048 // Default score
2049 if Pos('t', EvStr) = 0 then
2050 begin
2051 // Player +/- score
2052 if Pos('-', EvStr) = 0 then
2053 begin
2054 if Pos('e', EvStr) = 0 then
2055 i1 := I_PLAYER_SCORE_ADD_OWN
2056 else
2057 i1 := I_PLAYER_SCORE_ADD_ENEMY;
2058 end else
2059 begin
2060 if Pos('e', EvStr) = 0 then
2061 i1 := I_PLAYER_SCORE_SUB_OWN
2062 else
2063 i1 := I_PLAYER_SCORE_SUB_ENEMY;
2064 end;
2065 // Which team
2066 if Pos('r', EvStr) > 0 then
2067 i2 := I_PLAYER_SCORE_TO_RED
2068 else
2069 i2 := I_PLAYER_SCORE_TO_BLUE;
2070 g_Console_Add(Format(_lc[i1], [pln, cnt, _lc[i2]]), True);
2071 end else
2072 begin
2073 // Team +/- score
2074 if Pos('-', EvStr) = 0 then
2075 i1 := I_PLAYER_SCORE_ADD_TEAM
2076 else
2077 i1 := I_PLAYER_SCORE_SUB_TEAM;
2078 // Which team
2079 if Pos('r', EvStr) > 0 then
2080 i2 := I_PLAYER_SCORE_RED
2081 else
2082 i2 := I_PLAYER_SCORE_BLUE;
2083 g_Console_Add(Format(_lc[i1], [_lc[i2], cnt]), True);
2084 end;
2085 end else
2086 begin
2087 // Game Win
2088 if Pos('e', EvStr) = 0 then
2089 i1 := I_PLAYER_SCORE_WIN_OWN
2090 else
2091 i1 := I_PLAYER_SCORE_WIN_ENEMY;
2092 // Which team
2093 if Pos('r', EvStr) > 0 then
2094 i2 := I_PLAYER_SCORE_TO_RED
2095 else
2096 i2 := I_PLAYER_SCORE_TO_BLUE;
2097 g_Console_Add(Format(_lc[i1], [pln, _lc[i2]]), True);
2098 end;
2099 end;
2101 NET_EV_SCORE_MSG:
2102 begin
2103 if EvNum = TEAM_RED then
2104 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
2105 if EvNum = TEAM_BLUE then
2106 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
2107 if EvNum = -TEAM_RED then
2108 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
2109 if EvNum = -TEAM_BLUE then
2110 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
2111 end;
2113 NET_EV_LMS_START:
2114 begin
2115 g_Player_RemoveAllCorpses;
2116 gLMSRespawn := LMS_RESPAWN_NONE;
2117 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
2118 end;
2120 NET_EV_LMS_WIN:
2121 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(EvStr)]), 144);
2123 NET_EV_TLMS_WIN:
2124 begin
2125 if EvNum = TEAM_RED then
2126 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
2127 if EvNum = TEAM_BLUE then
2128 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
2129 end;
2131 NET_EV_LMS_LOSE:
2132 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
2134 NET_EV_LMS_DRAW:
2135 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
2137 NET_EV_LMS_NOSPAWN:
2138 g_Console_Add(_lc[I_PLAYER_SPECT4], True);
2140 NET_EV_KILLCOMBO:
2141 g_Game_Announce_KillCombo(EvNum);
2143 NET_EV_PLAYER_TOUCH:
2144 begin
2145 pl := g_Player_Get(EvNum);
2146 if pl <> nil then
2147 pl.Touch();
2148 end;
2150 NET_EV_SECRET:
2151 begin
2152 pl := g_Player_Get(EvNum);
2153 if pl <> nil then
2154 begin
2155 g_Console_Add(Format(_lc[I_PLAYER_SECRET], [pl.Name]), True);
2156 g_Sound_PlayEx('SOUND_GAME_SECRET');
2157 end;
2158 end;
2160 NET_EV_INTER_READY:
2161 begin
2162 pl := g_Player_Get(EvNum);
2163 if pl <> nil then pl.FReady := (EvStr = 'Y');
2164 end;
2165 end;
2166 end;
2168 procedure MC_RECV_FlagPos(var M: TMsg);
2169 var
2170 Fl: Byte;
2171 begin
2172 Fl := M.ReadByte();
2173 if Fl = FLAG_NONE then Exit;
2174 gFlags[Fl].Obj.X := M.ReadLongInt();
2175 gFlags[Fl].Obj.Y := M.ReadLongInt();
2176 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
2177 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
2178 end;
2180 procedure MC_RECV_FlagEvent(var M: TMsg);
2181 var
2182 PID: Word;
2183 Pl: TPlayer;
2184 EvType: Byte;
2185 Fl, a: Byte;
2186 Quiet: Boolean;
2187 s, ts: string;
2188 begin
2189 EvType := M.ReadByte();
2190 Fl := M.ReadByte();
2192 if Fl = FLAG_NONE then Exit;
2194 Quiet := (M.ReadByte() <> 0);
2195 PID := M.ReadWord();
2197 gFlags[Fl].State := M.ReadByte();
2198 gFlags[Fl].CaptureTime := M.ReadLongWord();
2199 gFlags[Fl].Obj.X := M.ReadLongInt();
2200 gFlags[Fl].Obj.Y := M.ReadLongInt();
2201 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
2202 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
2203 gFlags[Fl].Direction := TDirection(M.ReadByte());
2205 Pl := g_Player_Get(PID);
2206 if (Pl = nil) and
2207 (EvType <> FLAG_STATE_NORMAL) and
2208 (EvType <> FLAG_STATE_DROPPED) and
2209 (EvType <> FLAG_STATE_RETURNED) then
2210 Exit;
2212 case EvType of
2213 FLAG_STATE_NORMAL:
2214 begin
2215 if Quiet or (Pl = nil) then Exit;
2217 if Fl = FLAG_RED then
2218 s := _lc[I_PLAYER_FLAG_RED]
2219 else
2220 s := _lc[I_PLAYER_FLAG_BLUE];
2222 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2224 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2225 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2226 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2227 a := 0
2228 else
2229 a := 1;
2231 if not sound_ret_flag[a].IsPlaying() then
2232 sound_ret_flag[a].Play();
2233 end;
2235 FLAG_STATE_CAPTURED:
2236 begin
2237 if (Pl <> nil) then Pl.SetFlag(Fl);
2239 if Quiet then Exit;
2241 if Fl = FLAG_RED then
2242 s := _lc[I_PLAYER_FLAG_RED]
2243 else
2244 s := _lc[I_PLAYER_FLAG_BLUE];
2246 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [Pl.Name, s]), True);
2247 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
2249 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2250 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2251 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2252 a := 0
2253 else
2254 a := 1;
2256 if not sound_get_flag[a].IsPlaying() then
2257 sound_get_flag[a].Play();
2258 end;
2260 FLAG_STATE_DROPPED:
2261 begin
2262 if (Pl <> nil) then Pl.SetFlag(FLAG_NONE);
2264 if Quiet or (Pl = nil) then Exit;
2266 if Fl = FLAG_RED then
2267 s := _lc[I_PLAYER_FLAG_RED]
2268 else
2269 s := _lc[I_PLAYER_FLAG_BLUE];
2271 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [Pl.Name, s]), True);
2272 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
2274 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2275 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2276 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2277 a := 0
2278 else
2279 a := 1;
2281 if not sound_lost_flag[a].IsPlaying() then
2282 sound_lost_flag[a].Play();
2283 end;
2285 FLAG_STATE_SCORED:
2286 begin
2287 g_Map_ResetFlag(FLAG_RED);
2288 g_Map_ResetFlag(FLAG_BLUE);
2289 if Quiet or (Pl = nil) then Exit;
2290 Pl.SetFlag(FLAG_NONE);
2292 if Fl = FLAG_RED then
2293 s := _lc[I_PLAYER_FLAG_RED]
2294 else
2295 s := _lc[I_PLAYER_FLAG_BLUE];
2297 ts := Format('%.4d', [gFlags[Fl].CaptureTime]);
2298 Insert('.', ts, Length(ts) + 1 - 3);
2299 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [Pl.Name, s, ts]), True);
2300 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
2302 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2303 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2304 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2305 a := 0
2306 else
2307 a := 1;
2309 if not sound_cap_flag[a].IsPlaying() then
2310 sound_cap_flag[a].Play();
2311 end;
2313 FLAG_STATE_RETURNED:
2314 begin
2315 g_Map_ResetFlag(Fl);
2316 if Quiet then Exit;
2318 if Fl = FLAG_RED then
2319 s := _lc[I_PLAYER_FLAG_RED]
2320 else
2321 s := _lc[I_PLAYER_FLAG_BLUE];
2323 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2325 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2326 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2327 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2328 a := 0
2329 else
2330 a := 1;
2332 if not sound_ret_flag[a].IsPlaying() then
2333 sound_ret_flag[a].Play();
2334 end;
2335 end;
2336 end;
2338 procedure MC_RECV_GameSettings(var M: TMsg);
2339 begin
2340 gGameSettings.GameMode := M.ReadByte();
2341 gGameSettings.ScoreLimit := M.ReadWord();
2342 gGameSettings.TimeLimit := M.ReadWord();
2343 gGameSettings.MaxLives := M.ReadByte();
2344 gGameSettings.Options := M.ReadLongWord();
2345 end;
2347 // PLAYER
2349 function MC_RECV_PlayerCreate(var M: TMsg): Word;
2350 var
2351 PID, DID: Word;
2352 PName, Model: string;
2353 Color: TRGB;
2354 T: Byte;
2355 Pl: TPlayer;
2356 begin
2357 PID := M.ReadWord();
2358 Pl := g_Player_Get(PID);
2360 PName := M.ReadString();
2361 Model := M.ReadString();
2362 Color.R := M.ReadByte();
2363 Color.G := M.ReadByte();
2364 Color.B := M.ReadByte();
2365 T := M.ReadByte();
2367 Result := 0;
2368 if (PID <> NetPlrUID1) and (PID <> NetPlrUID2) then
2369 begin
2370 if (Pl <> nil) then Exit;
2371 if (g_Force_Model_Get() <> 0) then
2372 Model := g_Forced_Model_GetName();
2373 DID := g_Player_Create(Model, Color, T, False);
2374 with g_Player_Get(DID) do
2375 begin
2376 UID := PID;
2377 Name := PName;
2378 Reset(True);
2379 end;
2380 end
2381 else
2382 begin
2383 if (PID = NetPlrUID1) and (gPlayer1 <> nil) then begin
2384 gPlayer1.UID := PID;
2385 gPlayer1.Model.SetColor(Color.R, Color.G, Color.B);
2386 gPlayer1.ChangeTeam(T);
2387 end;
2388 if (PID = NetPlrUID2) and (gPlayer2 <> nil) then begin
2389 gPlayer2.UID := PID;
2390 gPlayer2.Model.SetColor(Color.R, Color.G, Color.B);
2391 gPlayer2.ChangeTeam(T);
2392 end;
2393 end;
2395 if NetDeafLevel < 3 then
2396 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
2397 e_WriteLog('NET: Player ' + PName + ' [' + IntToStr(PID) + '] added.', TMsgType.Notify);
2398 Result := PID;
2399 end;
2401 function MC_RECV_PlayerPos(var M: TMsg): Word;
2402 var
2403 GT: LongWord;
2404 PID: Word;
2405 kByte: Word;
2406 Pl: TPlayer;
2407 Dir: Byte;
2408 TmpX, TmpY: Integer;
2409 begin
2410 Result := 0;
2412 GT := M.ReadLongWord();
2413 if GT < gTime - NET_MAX_DIFFTIME then
2414 begin
2415 gTime := GT;
2416 Exit;
2417 end;
2418 gTime := GT;
2420 PID := M.ReadWord();
2421 Pl := g_Player_Get(PID);
2423 if Pl = nil then Exit;
2425 Result := PID;
2427 with Pl do
2428 begin
2429 FPing := M.ReadWord();
2430 FLoss := M.ReadByte();
2431 kByte := M.ReadWord();
2432 Dir := M.ReadByte();
2434 TmpX := M.ReadLongInt();
2435 TmpY := M.ReadLongInt();
2437 ReleaseKeys;
2439 if LongBool(kByte and NET_KEY_CHAT) then
2440 PressKey(KEY_CHAT, 10000)
2441 else
2442 begin
2443 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
2444 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
2445 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
2446 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
2447 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
2448 end;
2450 JustTeleported := LongBool(kByte and NET_KEY_FORCEDIR);
2452 if ((Pl <> gPlayer1) and (Pl <> gPlayer2)) or JustTeleported then
2453 SetDirection(TDirection(Dir));
2455 GameVelX := M.ReadLongInt();
2456 GameVelY := M.ReadLongInt();
2457 GameAccelX := M.ReadLongInt();
2458 GameAccelY := M.ReadLongInt();
2459 SetLerp(TmpX, TmpY);
2460 if NetForcePlayerUpdate then Update();
2461 end;
2462 end;
2464 function MC_RECV_PlayerStats(var M: TMsg): Word;
2465 var
2466 PID: Word;
2467 Pl: TPlayer;
2468 I, OldFire: Integer;
2469 OldJet, Flam: Boolean;
2470 NewTeam: Byte;
2471 begin
2472 PID := M.ReadWord();
2473 Pl := g_Player_Get(PID);
2474 Result := 0;
2475 if Pl = nil then
2476 Exit;
2478 with Pl do
2479 begin
2480 alive := (M.ReadByte() <> 0);
2481 GodMode := (M.ReadByte() <> 0);
2482 Health := M.ReadLongInt();
2483 Armor := M.ReadLongInt();
2484 Air := M.ReadLongInt();
2485 JetFuel := M.ReadLongInt();
2486 Lives := M.ReadByte();
2487 NewTeam := M.ReadByte();
2489 for I := WP_FIRST to WP_LAST do
2490 FWeapon[I] := (M.ReadByte() <> 0);
2492 for I := A_BULLETS to A_HIGH do
2493 FAmmo[I] := M.ReadWord();
2495 for I := A_BULLETS to A_HIGH do
2496 FMaxAmmo[I] := M.ReadWord();
2498 for I := MR_SUIT to MR_MAX do
2499 FMegaRulez[I] := M.ReadLongWord();
2501 FRulez := [];
2502 if (M.ReadByte() <> 0) then
2503 FRulez := FRulez + [R_ITEM_BACKPACK];
2504 if (M.ReadByte() <> 0) then
2505 FRulez := FRulez + [R_KEY_RED];
2506 if (M.ReadByte() <> 0) then
2507 FRulez := FRulez + [R_KEY_GREEN];
2508 if (M.ReadByte() <> 0) then
2509 FRulez := FRulez + [R_KEY_BLUE];
2510 if (M.ReadByte() <> 0) then
2511 FRulez := FRulez + [R_BERSERK];
2513 Frags := M.ReadLongInt();
2514 Death := M.ReadLongInt();
2516 SetWeapon(M.ReadByte());
2518 FSpectator := M.ReadByte() <> 0;
2519 if FSpectator then
2520 begin
2521 if UID = NetPlrUID1 then
2522 begin
2523 gSpectLatchPID1 := UID;
2524 gPlayer1 := nil;
2525 end;
2526 if UID = NetPlrUID2 then
2527 begin
2528 gSpectLatchPID2 := UID;
2529 gPlayer2 := nil;
2530 end;
2531 end
2532 else
2533 begin
2534 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) and (UID = gSpectLatchPID1) then
2535 begin
2536 gPlayer1 := Pl;
2537 gSpectLatchPID1 := 0;
2538 end;
2539 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) and (UID = gSpectLatchPID2) then
2540 begin
2541 gPlayer2 := Pl;
2542 gSpectLatchPID2 := 0;
2543 end;
2544 end;
2545 FGhost := M.ReadByte() <> 0;
2546 FPhysics := M.ReadByte() <> 0;
2547 FNoRespawn := M.ReadByte() <> 0;
2548 OldJet := FJetpack;
2549 FJetpack := M.ReadByte() <> 0;
2550 OldFire := FFireTime;
2551 FFireTime := M.ReadLongInt();
2552 if (OldFire <= 0) and (FFireTime > 0) then
2553 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
2554 Flam := M.ReadByte() <> 0;
2555 FSpawnInvul := M.ReadLongInt();
2556 if OldJet and not FJetpack then
2557 JetpackOff
2558 else if not OldJet and FJetpack then
2559 JetpackOn;
2560 if FFlaming and not Flam then
2561 FlamerOff;
2562 if Team <> NewTeam then
2563 Pl.ChangeTeam(NewTeam);
2564 end;
2566 Result := PID;
2567 end;
2569 function MC_RECV_PlayerDamage(var M: TMsg): Word;
2570 var
2571 PID: Word;
2572 Pl: TPlayer;
2573 Kind: Byte;
2574 Attacker, Value: Word;
2575 VX, VY: Integer;
2576 begin
2577 Result := 0;
2578 if not gGameOn then Exit;
2579 PID := M.ReadWord();
2580 Pl := g_Player_Get(PID);
2581 if Pl = nil then Exit;
2583 Kind := M.ReadByte();
2584 Attacker := M.ReadWord();
2585 Value := M.ReadWord();
2586 VX := M.ReadWord();
2587 VY := M.ReadWord();
2589 with Pl do
2590 Damage(Value, Attacker, VX, VY, Kind);
2592 Result := PID;
2593 end;
2595 function MC_RECV_PlayerDeath(var M: TMsg): Word;
2596 var
2597 PID: Word;
2598 Pl: TPlayer;
2599 KillType, DeathType: Byte;
2600 Attacker: Word;
2601 begin
2602 Result := 0;
2603 if not gGameOn then Exit;
2604 PID := M.ReadWord();
2605 Pl := g_Player_Get(PID);
2606 if Pl = nil then Exit;
2608 KillType := M.ReadByte();
2609 DeathType := M.ReadByte();
2610 Attacker := M.ReadWord();
2612 with Pl do
2613 begin
2614 Kill(KillType, Attacker, DeathType);
2615 SoftReset;
2616 end;
2617 end;
2619 function MC_RECV_PlayerDelete(var M: TMsg): Word;
2620 var
2621 PID: Word;
2622 Pl: TPlayer;
2623 begin
2624 PID := M.ReadWord();
2625 Pl := g_Player_Get(PID);
2626 Result := 0;
2627 if Pl = nil then Exit;
2629 if NetDeafLevel < 3 then
2630 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2631 e_WriteLog('NET: Player ' + Pl.Name + ' [' + IntToStr(PID) + '] removed.', TMsgType.Notify);
2633 g_Player_Remove(PID);
2635 Result := PID;
2636 end;
2638 function MC_RECV_PlayerFire(var M: TMsg): Word;
2639 var
2640 PID: Word;
2641 Weap: Byte;
2642 Pl: TPlayer;
2643 X, Y, AX, AY: Integer;
2644 SHID: Integer;
2645 begin
2646 Result := 0;
2647 if not gGameOn then Exit;
2648 PID := M.ReadWord();
2649 Pl := g_Player_Get(PID);
2650 if Pl = nil then Exit;
2652 Weap := M.ReadByte();
2653 X := M.ReadLongInt();
2654 Y := M.ReadLongInt();
2655 AX := M.ReadLongInt();
2656 AY := M.ReadLongInt();
2657 SHID := M.ReadLongInt();
2659 with Pl do
2660 if alive then NetFire(Weap, X, Y, AX, AY, SHID);
2661 end;
2663 procedure MC_RECV_PlayerSettings(var M: TMsg);
2664 var
2665 TmpName: string;
2666 TmpModel: string;
2667 CheckModel: string;
2668 TmpColor: TRGB;
2669 TmpTeam: Byte;
2670 Pl: TPlayer;
2671 PID: Word;
2672 begin
2673 PID := M.ReadWord();
2674 Pl := g_Player_Get(PID);
2675 if Pl = nil then Exit;
2677 TmpName := M.ReadString();
2678 TmpModel := M.ReadString();
2679 TmpColor.R := M.ReadByte();
2680 TmpColor.G := M.ReadByte();
2681 TmpColor.B := M.ReadByte();
2682 TmpTeam := M.ReadByte();
2684 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
2685 begin
2686 Pl.ChangeTeam(TmpTeam);
2687 if gPlayer1 = Pl then
2688 gPlayer1Settings.Team := TmpTeam;
2689 if gPlayer2 = Pl then
2690 gPlayer2Settings.Team := TmpTeam;
2691 end else
2692 Pl.SetColor(TmpColor);
2694 if Pl.Name <> TmpName then
2695 begin
2696 if NetDeafLevel < 3 then
2697 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
2698 Pl.Name := TmpName;
2699 end;
2701 if (g_Force_Model_Get() <> 0) then
2702 TmpModel := g_Forced_Model_GetName();
2703 if TmpModel <> Pl.Model.GetName() then
2704 Pl.SetModel(TmpModel);
2705 end;
2707 // ITEM
2709 procedure MC_RECV_ItemSpawn(var M: TMsg);
2710 var
2711 ID: Word;
2712 X, Y, VX, VY: Integer;
2713 T: Byte;
2714 Quiet, Fall{, Resp}: Boolean;
2715 it: PItem;
2716 begin
2717 if not gGameOn then Exit;
2718 ID := M.ReadWord();
2719 Quiet := M.ReadByte() <> 0;
2720 T := M.ReadByte();
2721 Fall := M.ReadByte() <> 0;
2722 {Resp :=} M.ReadByte();
2723 X := M.ReadLongInt();
2724 Y := M.ReadLongInt();
2725 VX := M.ReadLongInt();
2726 VY := M.ReadLongInt();
2728 g_Items_Create(X, Y, T and $7F, Fall, False, False, ID);
2729 if ((T and $80) <> 0) then g_Items_SetDrop(ID);
2731 it := g_Items_ByIdx(ID);
2732 it.Obj.Vel.X := VX;
2733 it.Obj.Vel.Y := VY;
2735 if not Quiet then
2736 begin
2737 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
2738 g_GFX_QueueEffect(R_GFX_ITEM_RESPAWN, X+(it.Obj.Rect.Width div 2)-16, Y+(it.Obj.Rect.Height div 2)-16);
2739 end;
2740 end;
2742 procedure MC_RECV_ItemDestroy(var M: TMsg);
2743 var
2744 ID: Word;
2745 Quiet: Boolean;
2746 begin
2747 if not gGameOn then Exit;
2748 ID := M.ReadWord();
2749 Quiet := M.ReadByte() <> 0;
2751 if not g_Items_ValidId(ID) then exit;
2753 if not Quiet then g_Items_EmitPickupSound(ID);
2755 g_Items_Remove(ID);
2756 end;
2758 procedure MC_RECV_ItemPos(var M: TMsg);
2759 var
2760 ID: Word;
2761 X, Y, VX, VY: Integer;
2762 it: PItem;
2763 begin
2764 if not gGameOn then Exit;
2766 ID := M.ReadWord();
2767 X := M.ReadLongInt();
2768 Y := M.ReadLongInt();
2769 VX := M.ReadLongInt();
2770 VY := M.ReadLongInt();
2772 if g_Items_ValidId(ID) then
2773 begin
2774 it := g_Items_ByIdx(ID);
2775 it.Obj.X := X;
2776 it.Obj.Y := Y;
2777 it.Obj.Vel.X := VX;
2778 it.Obj.Vel.Y := VY;
2779 it.positionChanged();
2780 end;
2781 end;
2783 // PANEL
2785 procedure MC_RECV_PanelTexture(var M: TMsg);
2786 var
2787 TP: TPanel;
2788 PGUID: Integer;
2789 Tex, Fr: Integer;
2790 Loop, Cnt: Byte;
2791 begin
2792 if not gGameOn then Exit;
2794 PGUID := Integer(M.ReadLongWord());
2795 Tex := M.ReadLongInt();
2796 Fr := M.ReadLongInt();
2797 Cnt := M.ReadByte();
2798 Loop := M.ReadByte();
2800 TP := g_Map_PanelByGUID(PGUID);
2801 if (TP <> nil) then
2802 begin
2803 // switch texture
2804 TP.SetTexture(Tex, Loop);
2805 TP.SetFrame(Fr, Cnt);
2806 end;
2807 end;
2809 procedure MC_RECV_PanelState(var M: TMsg);
2810 var
2811 PGUID: Integer;
2812 E: Boolean;
2813 Lift: Byte;
2814 X, Y, W, H: Integer;
2815 TP: TPanel;
2816 speedX, speedY, startX, startY, endX, endY: Integer;
2817 sizeSpX, sizeSpY, sizeEX, sizeEY: Integer;
2818 mpflags: Byte;
2819 begin
2820 if not gGameOn then Exit;
2822 PGUID := Integer(M.ReadLongWord());
2823 E := (M.ReadByte() <> 0);
2824 Lift := M.ReadByte();
2825 X := M.ReadLongInt();
2826 Y := M.ReadLongInt();
2827 W := M.ReadWord();
2828 H := M.ReadWord();
2829 // mplats
2830 speedX := M.ReadLongInt();
2831 speedY := M.ReadLongInt();
2832 startX := M.ReadLongInt();
2833 startY := M.ReadLongInt();
2834 endX := M.ReadLongInt();
2835 endY := M.ReadLongInt();
2836 sizeSpX := M.ReadLongInt();
2837 sizeSpY := M.ReadLongInt();
2838 sizeEX := M.ReadLongInt();
2839 sizeEY := M.ReadLongInt();
2840 mpflags := M.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2842 TP := g_Map_PanelByGUID(PGUID);
2843 if (TP = nil) then exit;
2845 // update lifts state
2846 if TP.isGLift then g_Map_SetLiftGUID(PGUID, Lift);
2848 // update enabled/disabled state for all panels
2849 if E then g_Map_EnableWallGUID(PGUID) else g_Map_DisableWallGUID(PGUID);
2851 // update panel position, as it can be moved (mplat)
2852 TP.X := X;
2853 TP.Y := Y;
2854 TP.Width := W;
2855 TP.Height := H;
2856 // update mplat state
2857 TP.movingSpeedX := speedX;
2858 TP.movingSpeedY := speedY;
2859 TP.movingStartX := startX;
2860 TP.movingStartY := startY;
2861 TP.movingEndX := endX;
2862 TP.movingEndY := endY;
2863 TP.sizeSpeedX := sizeSpX;
2864 TP.sizeSpeedY := sizeSpY;
2865 TP.sizeEndX := sizeEX;
2866 TP.sizeEndY := sizeEY;
2867 TP.movingActive := ((mpflags and 1) <> 0);
2868 TP.moveOnce := ((mpflags and 2) <> 0);
2869 // notify panel of it's position/size change, so it can fix other internal structures
2870 TP.positionChanged();
2871 end;
2873 // TRIGGERS
2875 procedure MC_RECV_TriggerSound(var M: TMsg);
2876 var
2877 SPlaying: Boolean;
2878 SPos, SID: LongWord;
2879 SCount: LongInt;
2880 I: Integer;
2881 begin
2882 if not gGameOn then Exit;
2883 if gTriggers = nil then Exit;
2885 SID := M.ReadLongWord();
2886 SPlaying := M.ReadByte() <> 0;
2887 SPos := M.ReadLongWord();
2888 SCount := M.ReadLongInt();
2890 for I := Low(gTriggers) to High(gTriggers) do
2891 if gTriggers[I].TriggerType = TRIGGER_SOUND then
2892 if gTriggers[I].ClientID = SID then
2893 with gTriggers[I] do
2894 begin
2895 if Sound <> nil then
2896 begin
2897 if SPlaying then
2898 begin
2899 if tgcLocal then
2900 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), tgcVolume/255.0)
2901 else
2902 Sound.PlayPanVolume((tgcPan-127.0)/128.0, tgcVolume/255.0);
2903 Sound.SetPosition(SPos);
2904 end
2905 else
2906 if Sound.IsPlaying then Sound.Stop;
2907 end;
2909 SoundPlayCount := SCount;
2910 end;
2911 end;
2913 procedure MC_RECV_TriggerMusic(var M: TMsg);
2914 var
2915 MName: string;
2916 MPlaying: Boolean;
2917 MPos: LongWord;
2918 MPaused: Boolean;
2919 begin
2920 if not gGameOn then Exit;
2922 MName := M.ReadString();
2923 MPlaying := M.ReadByte() <> 0;
2924 MPos := M.ReadLongWord();
2925 MPaused := M.ReadByte() <> 0;
2926 MPos := MPos+1; //k8: stfu, fpc!
2928 if MPlaying then
2929 begin
2930 gMusic.SetByName(MName);
2931 gMusic.Play(True);
2932 // gMusic.SetPosition(MPos);
2933 gMusic.SpecPause := MPaused;
2934 end
2935 else
2936 if gMusic.IsPlaying then gMusic.Stop;
2937 end;
2939 // MONSTERS
2941 procedure MC_RECV_MonsterSpawn(var M: TMsg);
2942 var
2943 ID: Word;
2944 MType, MState, MDir, MAnim, MBehav: Byte;
2945 X, Y, VX, VY, MTargTime, MHealth, MAmmo, MSleep: Integer;
2946 MTarg: Word;
2947 Mon: TMonster;
2948 begin
2949 ID := M.ReadWord();
2950 Mon := g_Monsters_ByUID(ID);
2951 if Mon <> nil then
2952 Exit;
2954 MType := M.ReadByte();
2955 MState := M.ReadByte();
2956 MAnim := M.ReadByte();
2957 MTarg := M.ReadWord();
2958 MTargTime := M.ReadLongInt();
2959 MBehav := M.ReadByte();
2960 MSleep := M.ReadLongInt();
2961 MHealth := M.ReadLongInt();
2962 MAmmo := M.ReadLongInt();
2964 X := M.ReadLongInt();
2965 Y := M.ReadLongInt();
2966 VX := M.ReadLongInt();
2967 VY := M.ReadLongInt();
2968 MDir := M.ReadByte();
2970 g_Monsters_Create(MType, X, Y, TDirection(MDir), False, ID);
2971 Mon := g_Monsters_ByUID(ID);
2972 if Mon = nil then
2973 Exit;
2975 with Mon do
2976 begin
2978 MonsterAnim := MAnim;
2979 MonsterTargetUID := MTarg;
2980 MonsterTargetTime := MTargTime;
2981 MonsterBehaviour := MBehav;
2982 MonsterSleep := MSleep;
2983 MonsterAmmo := MAmmo;
2984 SetHealth(MHealth);
2986 SetState(MState);
2988 setPosition(X, Y); // this will call positionChanged();
2989 GameVelX := VX;
2990 GameVelY := VY;
2991 end;
2992 end;
2994 procedure MC_RECV_MonsterPos(var M: TMsg);
2995 var
2996 Mon: TMonster;
2997 ID: Word;
2998 X, Y: Integer;
2999 begin
3000 ID := M.ReadWord();
3001 Mon := g_Monsters_ByUID(ID);
3002 if Mon = nil then
3003 Exit;
3005 with Mon do
3006 begin
3007 X := M.ReadLongInt();
3008 Y := M.ReadLongInt();
3009 Mon.setPosition(X, Y); // this will call `positionChanged()`
3010 GameVelX := M.ReadLongInt();
3011 GameVelY := M.ReadLongInt();
3012 GameDirection := TDirection(M.ReadByte());
3013 end;
3014 end;
3016 procedure MC_RECV_MonsterState(var M: TMsg);
3017 var
3018 ID, OldFire: Integer;
3019 MState, MFAnm: Byte;
3020 Mon: TMonster;
3021 AnimRevert: Boolean;
3022 begin
3023 ID := M.ReadWord();
3024 Mon := g_Monsters_ByUID(ID);
3025 if Mon = nil then Exit;
3027 MState := M.ReadByte();
3028 MFAnm := M.ReadByte();
3030 with Mon do
3031 begin
3032 MonsterTargetUID := M.ReadWord();
3033 MonsterTargetTime := M.ReadLongInt();
3034 MonsterSleep := M.ReadLongInt();
3035 MonsterHealth := M.ReadLongInt();
3036 MonsterAmmo := M.ReadLongInt();
3037 MonsterPain := M.ReadLongInt();
3038 AnimRevert := M.ReadByte() <> 0;
3039 OldFire := FFireTime;
3040 FFireTime := M.ReadLongInt();
3041 if (OldFire <= 0) and (FFireTime > 0) then
3042 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
3043 RevertAnim(AnimRevert);
3045 if MonsterState <> MState then
3046 begin
3047 if (MState = MONSTATE_GO) and (MonsterState = MONSTATE_SLEEP) then WakeUpSound();
3048 if (MState = MONSTATE_DIE) then DieSound();
3049 if (MState = MONSTATE_PAIN) then MakeBloodSimple(Min(200, MonsterPain));
3050 if (MState = MONSTATE_ATTACK) then kick(nil);
3051 if (MState = MONSTATE_DEAD) then SetDeadAnim();
3053 SetState(MState, MFAnm);
3054 end;
3055 end;
3056 end;
3058 procedure MC_RECV_MonsterShot(var M: TMsg);
3059 var
3060 ID: Integer;
3061 Mon: TMonster;
3062 X, Y, VX, VY: Integer;
3063 begin
3064 ID := M.ReadWord();
3066 Mon := g_Monsters_ByUID(ID);
3067 if Mon = nil then Exit;
3069 X := M.ReadLongInt();
3070 Y := M.ReadLongInt();
3071 VX := M.ReadLongInt();
3072 VY := M.ReadLongInt();
3074 Mon.ClientAttack(X, Y, VX, VY);
3075 end;
3077 procedure MC_RECV_MonsterDelete(var M: TMsg);
3078 var
3079 ID: Integer;
3080 Mon: TMonster;
3081 begin
3082 ID := M.ReadWord();
3083 Mon := g_Monsters_ByUID(ID);
3084 if Mon = nil then Exit;
3085 Mon.SetState(5);
3086 Mon.MonsterRemoved := True;
3087 end;
3089 procedure MC_RECV_TimeSync(var M: TMsg);
3090 var
3091 Time: LongWord;
3092 begin
3093 Time := M.ReadLongWord();
3095 if gState = STATE_INTERCUSTOM then
3096 gServInterTime := Min(Time, 255);
3097 end;
3099 procedure MC_RECV_VoteEvent(var M: TMsg);
3100 var
3101 EvID: Byte;
3102 Str1, Str2: string;
3103 Int1, Int2: SmallInt;
3104 begin
3105 EvID := M.ReadByte();
3106 Int1 := M.ReadSmallInt();
3107 Int2 := M.ReadSmallInt();
3108 Str1 := M.ReadString();
3109 Str2 := M.ReadString();
3111 if NetDeafLevel < 2 then
3112 case EvID of
3113 NET_VE_STARTED:
3114 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True);
3115 NET_VE_PASSED:
3116 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True);
3117 NET_VE_FAILED:
3118 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
3119 NET_VE_VOTE:
3120 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True);
3121 NET_VE_INPROGRESS:
3122 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True);
3123 end;
3124 end;
3126 // CLIENT SEND
3128 procedure MC_SEND_Info(Password: string);
3129 var i: Integer;
3130 begin
3131 NetOut.Clear();
3133 NetOut.Write(Byte(NET_MSG_INFO));
3134 NetOut.Write(GAME_VERSION);
3135 NetOut.Write(Password);
3136 NetOut.Write(gPlayer1Settings.Name);
3137 NetOut.Write(gPlayer1Settings.Model);
3138 NetOut.Write(gPlayer1Settings.Color.R);
3139 NetOut.Write(gPlayer1Settings.Color.G);
3140 NetOut.Write(gPlayer1Settings.Color.B);
3141 NetOut.Write(gPlayer1Settings.Team);
3142 NetOut.Write(gPlayer1Settings.WeaponSwitch);
3143 for i := WP_FIRST to WP_LAST + 1 do
3144 NetOut.Write(gPlayer1Settings.WeaponPreferences[i]);
3145 NetOut.Write(gPlayer1Settings.SwitchToEmpty);
3146 NetOut.Write(gPlayer1Settings.SkipFist);
3148 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3149 end;
3151 procedure MC_SEND_Chat(Txt: string; Mode: Byte);
3152 begin
3153 NetOut.Write(Byte(NET_MSG_CHAT));
3154 NetOut.Write(Txt);
3155 NetOut.Write(Mode);
3157 g_Net_Client_Send(True, NET_CHAN_CHAT);
3158 end;
3160 procedure MC_SEND_PlayerPos();
3161 var
3162 kByte: Word;
3163 Predict: Boolean;
3164 strafeDir: Byte;
3165 WeaponAct: Byte = 0;
3166 WeaponSelect: Word = 0;
3167 i: Integer;
3168 begin
3169 if not gGameOn then Exit;
3170 if gPlayers = nil then Exit;
3171 if gPlayer1 = nil then Exit;
3173 kByte := 0;
3174 Predict := NetPredictSelf; // and (not NetGotKeys);
3176 {$IFDEF DISABLE_MENU}
3177 if (not gConsoleShow) and (not gChatShow) then
3178 {$ELSE}
3179 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
3180 {$ENDIF}
3181 begin
3182 strafeDir := P1MoveButton shr 4;
3183 P1MoveButton := P1MoveButton and $0F;
3185 if gPlayerAction[0, ACTION_MOVELEFT] and (not gPlayerAction[0, ACTION_MOVERIGHT]) then
3186 P1MoveButton := 1
3187 else if (not gPlayerAction[0, ACTION_MOVELEFT]) and gPlayerAction[0, ACTION_MOVERIGHT] then
3188 P1MoveButton := 2
3189 else if (not gPlayerAction[0, ACTION_MOVELEFT]) and (not gPlayerAction[0, ACTION_MOVERIGHT]) then
3190 P1MoveButton := 0;
3192 // strafing
3193 if gPlayerAction[0, ACTION_STRAFE] then
3194 begin
3195 // new strafe mechanics
3196 if (strafeDir = 0) then
3197 strafeDir := P1MoveButton; // start strafing
3198 // now set direction according to strafe (reversed)
3199 if (strafeDir = 2) then
3200 gPlayer1.SetDirection(TDirection.D_LEFT)
3201 else if (strafeDir = 1) then
3202 gPlayer1.SetDirection(TDirection.D_RIGHT)
3203 end
3204 else
3205 begin
3206 strafeDir := 0; // not strafing anymore
3207 if (P1MoveButton = 2) and gPlayerAction[0, ACTION_MOVELEFT] then
3208 gPlayer1.SetDirection(TDirection.D_LEFT)
3209 else if (P1MoveButton = 1) and gPlayerAction[0, ACTION_MOVERIGHT] then
3210 gPlayer1.SetDirection(TDirection.D_RIGHT)
3211 else if P1MoveButton <> 0 then
3212 gPlayer1.SetDirection(TDirection(P1MoveButton-1));
3213 end;
3215 gPlayer1.ReleaseKeys;
3216 if P1MoveButton = 1 then
3217 begin
3218 kByte := kByte or NET_KEY_LEFT;
3219 if Predict then gPlayer1.PressKey(KEY_LEFT, 10000);
3220 end;
3221 if P1MoveButton = 2 then
3222 begin
3223 kByte := kByte or NET_KEY_RIGHT;
3224 if Predict then gPlayer1.PressKey(KEY_RIGHT, 10000);
3225 end;
3226 if gPlayerAction[0, ACTION_LOOKUP] then
3227 begin
3228 kByte := kByte or NET_KEY_UP;
3229 gPlayer1.PressKey(KEY_UP, 10000);
3230 end;
3231 if gPlayerAction[0, ACTION_LOOKDOWN] then
3232 begin
3233 kByte := kByte or NET_KEY_DOWN;
3234 gPlayer1.PressKey(KEY_DOWN, 10000);
3235 end;
3236 if gPlayerAction[0, ACTION_JUMP] then
3237 begin
3238 kByte := kByte or NET_KEY_JUMP;
3239 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3240 end;
3241 if gPlayerAction[0, ACTION_ATTACK] then kByte := kByte or NET_KEY_FIRE;
3242 if gPlayerAction[0, ACTION_ACTIVATE] then kByte := kByte or NET_KEY_OPEN;
3244 for i := WP_FACT to WP_LACT do
3245 begin
3246 if gWeaponAction[0, i] then
3247 begin
3248 WeaponAct := WeaponAct or Byte(1 shl i);
3249 gWeaponAction[0, i] := False
3250 end
3251 end;
3253 for i := WP_FIRST to WP_LAST do
3254 begin
3255 if gSelectWeapon[0, i] then
3256 begin
3257 WeaponSelect := WeaponSelect or Word(1 shl i);
3258 gSelectWeapon[0, i] := False
3259 end
3260 end;
3262 // fix movebutton state
3263 P1MoveButton := P1MoveButton or (strafeDir shl 4);
3264 end
3265 else
3266 kByte := NET_KEY_CHAT;
3268 NetOut.Write(Byte(NET_MSG_PLRPOS));
3269 NetOut.Write(gTime);
3270 NetOut.Write(kByte);
3271 NetOut.Write(Byte(gPlayer1.Direction));
3272 NetOut.Write(WeaponAct);
3273 NetOut.Write(WeaponSelect);
3274 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3275 g_Net_Client_Send(True, NET_CHAN_PLAYERPOS);
3277 //kBytePrev := kByte;
3278 //kDirPrev := gPlayer1.Direction;
3279 end;
3281 procedure MC_SEND_Vote(Start: Boolean = False; Command: string = 'a');
3282 begin
3283 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
3284 NetOut.Write(Byte(Start));
3285 NetOut.Write(Command);
3286 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3287 end;
3289 procedure MC_SEND_PlayerSettings();
3290 var i: Integer;
3291 begin
3292 NetOut.Write(Byte(NET_MSG_PLRSET));
3293 NetOut.Write(gPlayer1Settings.Name);
3294 NetOut.Write(gPlayer1Settings.Model);
3295 NetOut.Write(gPlayer1Settings.Color.R);
3296 NetOut.Write(gPlayer1Settings.Color.G);
3297 NetOut.Write(gPlayer1Settings.Color.B);
3298 NetOut.Write(gPlayer1Settings.Team);
3299 NetOut.Write(gPlayer1Settings.WeaponSwitch);
3300 for i := WP_FIRST to WP_LAST + 1 do
3301 NetOut.Write(gPlayer1Settings.WeaponPreferences[i]);
3302 NetOut.Write(gPlayer1Settings.SwitchToEmpty);
3303 NetOut.Write(gPlayer1Settings.SkipFist);
3305 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3306 end;
3308 procedure MC_SEND_FullStateRequest();
3309 begin
3310 NetOut.Write(Byte(NET_MSG_REQFST));
3312 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3313 end;
3315 procedure MC_SEND_CheatRequest(Kind: Byte);
3316 begin
3317 NetOut.Write(Byte(NET_MSG_CHEAT));
3318 NetOut.Write(Kind);
3320 g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
3321 end;
3322 procedure MC_SEND_RCONPassword(Password: string);
3323 begin
3324 NetOut.Write(Byte(NET_MSG_RCON_AUTH));
3325 NetOut.Write(Password);
3327 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3328 end;
3329 procedure MC_SEND_RCONCommand(Cmd: string);
3330 begin
3331 NetOut.Write(Byte(NET_MSG_RCON_CMD));
3332 NetOut.Write(Cmd);
3334 g_Net_Client_Send(True, NET_CHAN_SERVICE);
3335 end;
3338 end.