DEADSOFTWARE

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