DEADSOFTWARE

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