DEADSOFTWARE

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