DEADSOFTWARE

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