sound: allow to completelly disable sound
[d2df-sdl.git] / src / game / g_netmsg.pas
blob720a5fc7ae457767d9a406b69ba289f5f5a63236
1 (* Copyright (C) Doom 2D: Forever Developers
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.
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.
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/>.
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_PJDEL = 161;
63 NET_MSG_PJADD = 162;
64 NET_MSG_PJPOS = 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;
72 NET_MSG_MAP_REQUEST = 201;
73 NET_MSG_MAP_RESPONSE = 202;
74 NET_MSG_RES_REQUEST = 203;
75 NET_MSG_RES_RESPONSE = 204;
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_CreateProj(Proj: LongInt; ID: Integer = NET_EVERYONE);
162 procedure MH_SEND_UpdateProj(Proj: LongInt; ID: Integer = NET_EVERYONE);
163 procedure MH_SEND_DeleteProj(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; 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(ClientID: DWORD; play: Boolean; pos: LongWord; count: Integer; ID: Integer = NET_EVERYONE);
194 procedure MH_SEND_TriggerMusic(name: String; play: Boolean; pos: LongWord; pause: Boolean; ID: Integer = NET_EVERYONE);
195 // MISC
196 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer = NET_EVERYONE);
197 procedure MH_SEND_VoteEvent(EvType: Byte; StrArg1: String = 'a'; StrArg2: String = 'b';
198 IntArg1: SmallInt = 0; IntArg2: SmallInt = 0; ID: Integer = NET_EVERYONE);
200 // CLIENT MESSAGES //
202 // GAME
203 procedure MC_RECV_Chat(var M: TMsg);
204 procedure MC_RECV_Effect(var M: TMsg);
205 procedure MC_RECV_Sound(var M: TMsg);
206 procedure MC_RECV_GameStats(var M: TMsg);
207 procedure MC_RECV_CoopStats(var M: TMsg);
208 procedure MC_RECV_GameEvent(var M: TMsg);
209 procedure MC_RECV_FlagEvent(var M: TMsg);
210 procedure MC_RECV_FlagPos(var M: TMsg);
211 procedure MC_RECV_GameSettings(var M: TMsg);
212 // PLAYER
213 function MC_RECV_PlayerCreate(var M: TMsg): Word;
214 function MC_RECV_PlayerPos(var M: TMsg): Word;
215 function MC_RECV_PlayerStats(var M: TMsg): Word;
216 function MC_RECV_PlayerDelete(var M: TMsg): Word;
217 function MC_RECV_PlayerDamage(var M: TMsg): Word;
218 function MC_RECV_PlayerDeath(var M: TMsg): Word;
219 function MC_RECV_PlayerFire(var M: TMsg): Word;
220 procedure MC_RECV_PlayerSettings(var M: TMsg);
221 // ITEM
222 procedure MC_RECV_ItemSpawn(var M: TMsg);
223 procedure MC_RECV_ItemDestroy(var M: TMsg);
224 procedure MC_RECV_ItemPos(var M: TMsg);
225 // PANEL
226 procedure MC_RECV_PanelTexture(var M: TMsg);
227 procedure MC_RECV_PanelState(var M: TMsg);
228 // MONSTER
229 procedure MC_RECV_MonsterSpawn(var M: TMsg);
230 procedure MC_RECV_MonsterPos(var M: TMsg);
231 procedure MC_RECV_MonsterState(var M: TMsg);
232 procedure MC_RECV_MonsterShot(var M: TMsg);
233 procedure MC_RECV_MonsterDelete(var M: TMsg);
234 // PROJECTILES
235 procedure MC_RECV_CreateProj(var M: TMsg);
236 procedure MC_RECV_UpdateProj(var M: TMsg);
237 procedure MC_RECV_DeleteProj(var M: TMsg);
238 // TRIGGER
239 procedure MC_RECV_TriggerSound(var M: TMsg);
240 procedure MC_RECV_TriggerMusic(var M: TMsg);
241 // MISC
242 procedure MC_RECV_TimeSync(var M: TMsg);
243 procedure MC_RECV_VoteEvent(var M: TMsg);
244 // SERVICE
245 procedure MC_SEND_Info(Password: String);
246 procedure MC_SEND_Chat(Txt: String; Mode: Byte);
247 procedure MC_SEND_PlayerPos();
248 procedure MC_SEND_FullStateRequest();
249 procedure MC_SEND_PlayerSettings();
250 procedure MC_SEND_CheatRequest(Kind: Byte);
251 procedure MC_SEND_RCONPassword(Password: String);
252 procedure MC_SEND_RCONCommand(Cmd: String);
253 procedure MC_SEND_Vote(Start: Boolean = False; Command: String = 'a');
254 // DOWNLOAD
255 //procedure MC_SEND_MapRequest();
256 //procedure MC_SEND_ResRequest(const resName: AnsiString);
259 type
260 TExternalResourceInfo = record
261 Name: String[255];
262 md5: TMD5Digest;
263 end;
265 TResDataMsg = record
266 MsgId: Byte;
267 FileSize: Integer;
268 FileData: AByte;
269 end;
271 TMapDataMsg = record
272 MsgId: Byte;
273 FileSize: Integer;
274 FileData: AByte;
275 ExternalResources: array of TExternalResourceInfo;
276 end;
278 implementation
280 uses
281 {$IFDEF ENABLE_SOUND}
282 g_sound,
283 {$ENDIF}
284 Math, ENet, e_input, e_graphics, e_log,
285 g_textures, g_gfx, g_console, g_basic, g_options, g_main,
286 g_game, g_player, g_map, g_panel, g_items, g_weapons, g_phys, g_gui,
287 g_language, g_monsters, g_netmaster, utils, wadreader, MAPDEF;
289 const
290 NET_KEY_LEFT = 1 shl 0;
291 NET_KEY_RIGHT = 1 shl 1;
292 NET_KEY_UP = 1 shl 2;
293 NET_KEY_DOWN = 1 shl 3;
294 NET_KEY_JUMP = 1 shl 4;
295 NET_KEY_FIRE = 1 shl 5;
296 NET_KEY_OPEN = 1 shl 6;
297 NET_KEY_CHAT = 1 shl 7;
298 NET_KEY_FORCEDIR = 1 shl 8;
300 //var
301 //kBytePrev: Word = 0;
302 //kDirPrev: TDirection = D_LEFT;
303 //HostGameTime: Word = 0;
306 // HOST MESSAGES //
309 // GAME
311 procedure MH_MalformedPacket(C: pTNetClient);
312 begin
313 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
314 _lc[I_NET_DISC_BADMSG]);
315 g_Net_Host_Ban(C, True);
316 end;
318 procedure MH_RECV_Chat(C: pTNetClient; var M: TMsg);
320 Txt: String;
321 Mode: Byte;
322 PID: Word;
323 Pl: TPlayer;
324 Err: Boolean;
325 begin
326 PID := C^.Player;
327 Pl := g_Player_Get(PID);
329 Err := False;
331 Txt := M.ReadString();
332 Mode := M.ReadByte();
333 except
334 Err := True;
335 end;
337 if Err then begin MH_MalformedPacket(C); Exit; end;
339 if (Mode = NET_CHAT_SYSTEM) then
340 Mode := NET_CHAT_PLAYER; // prevent sending system messages from clients
341 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
342 Mode := NET_CHAT_PLAYER; // revert to player chat in non-team game
344 if Pl = nil then
345 MH_SEND_Chat(Txt, Mode)
346 else
347 MH_SEND_Chat(Pl.Name + ': ' + Txt, Mode, IfThen(Mode = NET_CHAT_TEAM, Pl.Team, NET_EVERYONE));
348 end;
350 procedure MH_RECV_Info(C: pTNetClient; var M: TMsg);
352 Ver, PName, Model, Pw: String;
353 R, G, B, T: Byte;
354 WeapSwitch: Byte;
355 TmpPrefArray: Array [WP_FIRST .. WP_LAST + 1] of Byte;
356 SwitchEmpty: Byte;
357 SkipF: Byte;
358 PID: Word;
359 Color: TRGB;
360 I: Integer;
361 Err: Boolean;
362 begin
363 Err := False;
365 Ver := M.ReadString();
366 Pw := M.ReadString();
367 PName := M.ReadString();
368 Model := M.ReadString();
369 R := M.ReadByte();
370 G := M.ReadByte();
371 B := M.ReadByte();
372 T := M.ReadByte();
373 WeapSwitch := M.ReadByte();
374 for I := WP_FIRST to WP_LAST + 1 do
375 TmpPrefArray[I] := M.ReadByte();
376 SwitchEmpty := M.ReadByte();
377 SkipF := M.ReadByte();
378 except
379 Err := True;
380 end;
382 if Err then begin MH_MalformedPacket(C); Exit; end;
384 if Ver <> GAME_VERSION then
385 begin
386 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
387 _lc[I_NET_DISC_VERSION]);
388 g_Net_Host_Kick(C^.ID, NET_DISC_VERSION);
389 Exit;
390 end;
392 if g_Net_IsAddressBanned(C^.Peer^.address.host) then
393 begin
394 if g_Net_IsAddressBanned(C^.Peer^.address.host, True) then
395 begin
396 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
397 _lc[I_NET_DISC_BAN]);
398 g_Net_Host_Kick(C^.ID, NET_DISC_BAN);
400 else
401 begin
402 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
403 _lc[I_NET_DISC_BAN]);
404 g_Net_Host_Kick(C^.ID, NET_DISC_TEMPBAN);
405 end;
406 Exit;
407 end;
409 if NetPassword <> '' then
410 if AnsiLowerCase(NetPassword) <> AnsiLowerCase(Pw) then
411 begin
412 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_MSG_HOST_REJECT] +
413 _lc[I_NET_DISC_PASSWORD]);
414 g_Net_Host_Kick(C^.ID, NET_DISC_PASSWORD);
415 Exit;
416 end;
418 if (C^.Player <> 0) then
419 begin
420 // already received info
421 g_Net_Penalize(C, 'client info spam');
422 Exit;
423 end;
425 Color.R := R;
426 Color.B := B;
427 Color.G := G;
429 PID := g_Player_Create(Model, Color, T, False);
430 with g_Player_Get(PID) do
431 begin
432 Name := PName;
433 WeapSwitchMode := WeapSwitch;
434 SetWeaponPrefs(TmpPrefArray);
435 SwitchToEmpty := SwitchEmpty;
436 SkipIronFist := SkipF;
437 if (g_Force_Model_Get() <> 0) then
438 SetModel(g_Forced_Model_GetName());
439 Reset(True);
440 end;
442 C^.Player := PID;
443 C^.WaitForFirstSpawn := false;
444 C^.AuthTime := 0;
446 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
447 e_WriteLog('NET: Client ' + PName + ' [' + IntToStr(C^.ID) +
448 '] connected. Assigned player #' + IntToStr(PID) + '.', TMsgType.Notify);
450 MH_SEND_Info(C^.ID);
452 with g_Player_Get(PID) do
453 begin
454 Name := PName;
455 FClientID := C^.ID;
456 // round in progress, don't spawn
457 e_LogWritefln('*** client #%u (cid #%u) authenticated...', [C.ID, C.Player]);
458 //e_LogWritefln('spawning player with pid #%u...', [PID]);
459 //Respawn(gGameSettings.GameType = GT_SINGLE);
460 //k8: no, do not spawn a player yet, wait for "request full state" packet
461 Lives := 0;
462 Spectate;
463 FNoRespawn := True;
464 // `FWantsInGame` seems to mean "spawn the player on the next occasion".
465 // that is, if we'll set it to `true`, the player can be spawned after
466 // warmup time ran out, for example, regardless of the real player state.
467 // also, this seems to work only for the initial connection. further
468 // map changes could initiate resource downloading, but the player will
469 // be spawned immediately.
470 // the proper solution will require another player state, "ephemeral".
471 // the player should start any map in "ephemeral" state, and turned into
472 // real mobj only when they sent a special "i am ready" packet. this packet
473 // must be sent after receiving the full state, so the player will get a full
474 // map view before going into game.
475 FWantsInGame := false;
476 C^.WaitForFirstSpawn := true;
477 end;
479 //if not C^.WaitForFirstSpawn then
480 begin
481 for I := Low(NetClients) to High(NetClients) do
482 begin
483 if NetClients[I].ID = C^.ID then Continue;
484 MH_SEND_PlayerCreate(PID, NetClients[I].ID);
485 MH_SEND_PlayerPos(True, PID, NetClients[I].ID);
486 MH_SEND_PlayerStats(PID, NetClients[I].ID);
487 end;
488 end;
490 if gState in [STATE_INTERCUSTOM, STATE_FOLD] then
491 MH_SEND_GameEvent(NET_EV_MAPEND, 0, 'N', C^.ID);
493 if NetUseMaster then
494 begin
495 //g_Net_Slist_Update;
496 g_Net_Slist_Pulse();
497 end;
498 end;
501 procedure MH_ProcessFirstSpawn (C: pTNetClient);
503 plr: TPlayer;
504 begin
505 if not C.WaitForFirstSpawn then Exit;
506 plr := g_Player_Get(C^.Player);
507 if not assigned(plr) then Exit;
508 g_Net_Slist_ServerPlayerComes();
509 e_LogWritefln('*** client #%u (cid #%u) first spawn', [C.ID, C.Player]);
510 C.WaitForFirstSpawn := false;
511 plr.FNoRespawn := false;
512 plr.FWantsInGame := true; // TODO: look into this later
514 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
515 begin
516 plr.Spectate;
517 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN, 0, 'N', C.ID);
519 else
520 begin
521 plr.Respawn(False);
522 if gLMSRespawn > LMS_RESPAWN_NONE then
523 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime, 'N', C.ID);
524 end;
525 end;
528 procedure MH_RECV_FullStateRequest(C: pTNetClient; var M: TMsg);
529 begin
530 //e_LogWritefln('*** client #%u (cid #%u) full state request', [C.ID, C.Player]);
532 if C^.FullUpdateSent then
533 begin
534 // FullStateRequest spam?
535 g_Net_Penalize(C, 'duplicate full state request');
536 Exit;
537 end;
539 if gGameOn then
540 begin
541 MH_SEND_Everything((C^.State = NET_STATE_AUTH), C^.ID)
543 else
544 begin
545 C^.RequestedFullUpdate := True;
546 end;
547 end;
549 // PLAYER
551 function MH_RECV_PlayerPos(C: pTNetClient; var M: TMsg): Word;
553 Dir, i: Byte;
554 WeaponAct: Byte;
555 WeaponSelect: Word;
556 PID: Word;
557 kByte: Word;
558 Pl: TPlayer;
559 GT: LongWord;
560 Err: Boolean;
561 begin
562 Result := 0;
563 Err := False;
564 if not gGameOn then Exit;
567 GT := M.ReadLongWord();
568 except
569 Err := True;
570 end;
572 if Err then begin MH_MalformedPacket(C); Exit; end;
574 PID := C^.Player;
575 Pl := g_Player_Get(PID);
576 if Pl = nil then
577 Exit;
579 if (GT > gTime + NET_MAX_DIFFTIME) or (GT < Pl.NetTime) then Exit;
581 with Pl do
582 begin
583 NetTime := GT;
585 kByte := M.ReadWord();
586 Dir := M.ReadByte();
587 WeaponAct := M.ReadByte();
588 WeaponSelect := M.ReadWord();
589 except
590 Err := True;
591 end;
593 if Err then begin MH_MalformedPacket(C); Exit; end;
595 //e_WriteLog(Format('R:ws=%d', [WeaponSelect]), MSG_WARNING);
596 if Direction <> TDirection(Dir) then
597 JustTeleported := False;
599 SetDirection(TDirection(Dir));
600 ReleaseKeys;
602 if kByte = NET_KEY_CHAT then
603 begin
604 PressKey(KEY_CHAT, 10000);
605 Exit;
606 end;
608 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
609 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
610 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
611 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
612 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
613 if LongBool(kByte and NET_KEY_FIRE) then PressKey(KEY_FIRE, 10000);
614 if LongBool(kByte and NET_KEY_OPEN) then PressKey(KEY_OPEN, 10000);
616 for i := 0 to 7 do
617 begin
618 if (WeaponAct and Byte(1 shl i)) <> 0 then
619 begin
620 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
621 ProcessWeaponAction(i);
622 end;
623 end;
625 for i := 0 to 15 do
626 begin
627 if (WeaponSelect and Word(1 shl i)) <> 0 then
628 begin
629 //e_WriteLog(Format(' R:wn=%d', [i]), MSG_WARNING);
630 QueueWeaponSwitch(i);
631 end;
632 end;
633 end;
635 // MH_SEND_PlayerPos(False, PID, C^.ID);
636 end;
638 procedure MH_RECV_CheatRequest(C: pTNetClient; var M: TMsg);
640 CheatKind: Byte;
641 Pl: TPlayer;
642 Err: Boolean;
643 begin
644 Err := False;
645 Pl := g_Player_Get(C^.Player);
646 if Pl = nil then Exit;
649 CheatKind := M.ReadByte();
650 except
651 Err := True;
652 end;
654 if Err then begin MH_MalformedPacket(C); Exit; end;
656 case CheatKind of
657 NET_CHEAT_SUICIDE:
658 Pl.Damage(SUICIDE_DAMAGE, Pl.UID, 0, 0, HIT_SELF);
659 NET_CHEAT_SPECTATE:
660 begin
661 if Pl.FSpectator then
662 begin
663 if (gGameSettings.MaxLives = 0) or (gLMSRespawn > LMS_RESPAWN_NONE) then
664 Pl.Respawn(False)
665 else
666 MH_SEND_GameEvent(NET_EV_LMS_NOSPAWN, Pl.UID);
668 else
669 Pl.Spectate;
670 end;
671 NET_CHEAT_READY:
672 begin
673 if gState <> STATE_INTERCUSTOM then Exit;
674 Pl.FReady := not Pl.FReady;
675 if Pl.FReady then
676 begin
677 MH_SEND_GameEvent(NET_EV_INTER_READY, Pl.UID, 'Y');
678 Inc(gInterReadyCount);
680 else
681 begin
682 MH_SEND_GameEvent(NET_EV_INTER_READY, Pl.UID, 'N');
683 Dec(gInterReadyCount);
684 end;
685 end;
686 NET_CHEAT_DROPFLAG:
687 Pl.TryDropFlag();
688 end;
689 end;
691 procedure MH_RECV_PlayerSettings(C: pTNetClient; var M: TMsg);
693 TmpName: String;
694 TmpModel: String;
695 TmpColor: TRGB;
696 TmpTeam: Byte;
697 TmpWeapSwitch: Byte;
698 TmpPrefArray: Array [WP_FIRST .. WP_LAST + 1] of Byte;
699 TmpSwEmpty: Byte;
700 TmpSkipF: Byte;
701 I: Integer;
702 Pl: TPlayer;
703 Err: Boolean;
704 begin
705 Err := False;
707 TmpName := M.ReadString();
708 TmpModel := M.ReadString();
709 TmpColor.R := M.ReadByte();
710 TmpColor.G := M.ReadByte();
711 TmpColor.B := M.ReadByte();
712 TmpTeam := M.ReadByte();
713 TmpWeapSwitch := M.ReadByte();
714 for I := WP_FIRST to WP_LAST + 1 do
715 TmpPrefArray[I] := M.ReadByte();
716 TmpSwEmpty := M.ReadByte();
717 TmpSkipF := M.ReadByte();
718 except
719 Err := True;
720 end;
722 if Err then begin MH_MalformedPacket(C); Exit; end;
724 Pl := g_Player_Get(C^.Player);
725 if Pl = nil then Exit;
727 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
728 Pl.SwitchTeam
729 else
730 Pl.SetColor(TmpColor);
732 if Pl.Name <> TmpName then
733 begin
734 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
735 Pl.Name := TmpName;
736 end;
738 if (g_Force_Model_Get() <> 0) then
739 TmpModel := g_Forced_Model_GetName();
740 if TmpModel <> Pl.Model.Name then
741 Pl.SetModel(TmpModel);
743 if (TmpWeapSwitch <> Pl.WeapSwitchMode) then
744 Pl.WeapSwitchMode := TmpWeapSwitch;
746 Pl.SetWeaponPrefs(TmpPrefArray);
747 if (TmpSwEmpty <> Pl.SwitchToEmpty) then
748 Pl.SwitchToEmpty := TmpSwEmpty;
750 if (TmpSkipF <> Pl.SkipIronFist) then
751 Pl.SkipIronFist := TmpSkipF;
753 MH_SEND_PlayerSettings(Pl.UID, TmpModel);
754 end;
756 // RCON
758 procedure MH_RECV_RCONPassword(C: pTNetClient; var M: TMsg);
760 Pwd: String;
761 Err: Boolean;
762 begin
763 Err := False;
765 Pwd := M.ReadString();
766 except
767 Err := True;
768 end;
769 if Err then begin MH_MalformedPacket(C); Exit; end;
770 if not NetAllowRCON then Exit;
771 if Pwd = NetRCONPassword then
772 begin
773 C^.RCONAuth := True;
774 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWGOOD, 'N', C^.ID);
776 else
777 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_PWBAD, 'N', C^.ID);
778 end;
780 procedure MH_RECV_RCONCommand(C: pTNetClient; var M: TMsg);
782 Cmd: String;
783 Err: Boolean;
784 begin
785 Err := False;
787 Cmd := M.ReadString();
788 except
789 Err := True;
790 end;
791 if Err then begin MH_MalformedPacket(C); Exit; end;
792 if not NetAllowRCON then Exit;
793 if not C^.RCONAuth then
794 begin
795 MH_SEND_GameEvent(NET_EV_RCON, NET_RCON_NOAUTH, 'N', C^.ID);
796 Exit;
797 end;
798 g_Console_Process(Cmd);
799 end;
801 // MISC
803 procedure MH_RECV_Vote(C: pTNetClient; var M: TMsg);
805 Start: Boolean;
806 Name, Command: String;
807 Need: Integer;
808 Pl: TPlayer;
809 Err: Boolean;
810 begin
811 Err := False;
813 Start := M.ReadByte() <> 0;
814 Command := M.ReadString();
815 except
816 Err := True;
817 end;
819 if Err then begin MH_MalformedPacket(C); Exit; end;
821 Pl := g_Player_Get(C^.Player);
822 if Pl = nil then Exit;
823 Name := Pl.Name;
825 if Start then
826 begin
827 if not g_Console_CommandBlacklisted(Command) then
828 g_Game_StartVote(Command, Name);
830 else if gVoteInProgress then
831 begin
832 if (gPlayer1 <> nil) or (gPlayer2 <> nil)
833 then Need := Floor((NetClientCount+1)/2.0) + 1
834 else Need := Floor(NetClientCount/2.0) + 1;
835 if C^.Voted then
836 begin
837 Dec(gVoteCount);
838 C^.Voted := False;
839 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [Name, gVoteCount, Need]), True);
840 MH_SEND_VoteEvent(NET_VE_REVOKE, Name, 'a', gVoteCount, Need);
842 else
843 begin
844 Inc(gVoteCount);
845 C^.Voted := True;
846 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Name, gVoteCount, Need]), True);
847 MH_SEND_VoteEvent(NET_VE_VOTE, Name, 'a', gVoteCount, Need);
848 g_Game_CheckVote;
849 end;
850 end;
851 end;
853 // GAME (SEND)
855 procedure MH_SEND_Everything(CreatePlayers: Boolean; ID: Integer);
857 function sendItemRespawn (it: PItem): Boolean;
858 begin
859 result := false; // don't stop
860 MH_SEND_ItemSpawn(True, it.myid, ID);
861 end;
863 function sendMonSpawn (mon: TMonster): Boolean;
864 begin
865 result := false; // don't stop
866 MH_SEND_MonsterSpawn(mon.UID, ID);
867 end;
869 function sendPanelState (pan: TPanel): Boolean;
870 begin
871 result := false; // don't stop
872 MH_SEND_PanelState(pan.guid, ID); // anyway, to sync mplats
873 if (pan.CanChangeTexture) then MH_SEND_PanelTexture(pan.guid, pan.LastAnimLoop, ID);
874 end;
877 I: Integer;
878 begin
879 if (Low(NetClients) > ID) or (High(NetClients) < ID) then
880 Exit; // bogus client, this shouldn't happen
882 NetClients[ID].FullUpdateSent := True;
884 e_LogWritefln('*** client #%u (cid #%u) will get everything', [ID, NetClients[ID].Player]);
886 MH_ProcessFirstSpawn(@NetClients[ID]);
888 for I := Low(gPlayers) to High(gPlayers) do
889 begin
890 if gPlayers[I] <> nil then
891 begin
892 if CreatePlayers then MH_SEND_PlayerCreate(gPlayers[I].UID, ID);
893 MH_SEND_PlayerPos(True, gPlayers[I].UID, ID);
894 MH_SEND_PlayerStats(gPlayers[I].UID, ID);
896 if (gPlayers[I].Flag <> FLAG_NONE) and (gGameSettings.GameMode = GM_CTF) then
897 MH_SEND_FlagEvent(FLAG_STATE_CAPTURED, gPlayers[I].Flag, gPlayers[I].UID, True, ID);
898 end;
899 end;
901 g_Items_ForEachAlive(sendItemRespawn, true); // backwards
902 g_Mons_ForEach(sendMonSpawn);
903 g_Map_ForEachPanel(sendPanelState);
905 for I := Low(gTriggers) to High(gTriggers) do
906 begin
907 if gTriggers[I].TriggerType = TRIGGER_SOUND then
908 begin
909 {$IFDEF ENABLE_SOUND}
910 if gTriggers[I].Sound <> nil then
911 with gTriggers[I] do
912 MH_SEND_TriggerSound(ClientID, Sound.IsPlaying(), Sound.GetPosition(), SoundPlayCount, ID);
913 {$ELSE}
914 with gTriggers[I] do
915 MH_SEND_TriggerSound(ClientID, SoundPlay, SoundPos, SoundPlayCount, ID);
916 {$ENDIF}
917 end;
918 end;
920 for I := Low(Projectiles) to High(Projectiles) do
921 begin
922 if Projectiles[i].ShotType in [WEAPON_ROCKETLAUNCHER, WEAPON_PLASMA, WEAPON_BFG] then
923 MH_SEND_CreateProj(i, ID);
924 end;
926 {$IFDEF ENABLE_SOUND}
927 MH_SEND_TriggerMusic(gMusic.Name, gMusic.IsPlaying, gMusic.GetPosition, gMusic.SpecPause or gMusic.IsPaused, ID);
928 {$ELSE}
929 MH_SEND_TriggerMusic(gMusicName, gMusicPlay, gMusicPos, gMusicPause or not gMusicPlay, ID);
930 {$ENDIF}
932 MH_SEND_GameStats(ID);
933 MH_SEND_CoopStats(ID);
935 if gGameSettings.GameMode = GM_CTF then
936 begin
937 if gFlags[FLAG_RED].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_RED].State, FLAG_RED, 0, True, ID);
938 if gFlags[FLAG_BLUE].State <> FLAG_STATE_CAPTURED then MH_SEND_FlagEvent(gFlags[FLAG_BLUE].State, FLAG_BLUE, 0, True, ID);
939 end;
941 if CreatePlayers and (ID >= 0) then NetClients[ID].State := NET_STATE_GAME;
943 g_Net_Flush();
944 end;
946 procedure MH_SEND_Info(ID: Byte);
947 begin
948 NetOut.Clear();
950 NetOut.Write(Byte(NET_MSG_INFO));
951 NetOut.Write(ID);
952 NetOut.Write(NetClients[ID].Player);
953 NetOut.Write(ExtractFileName(gGameSettings.WAD));
954 NetOut.Write(g_ExtractFileName(gMapInfo.Map));
955 NetOut.Write(gWADHash);
956 NetOut.Write(gGameSettings.GameMode);
957 NetOut.Write(gGameSettings.ScoreLimit);
958 NetOut.Write(gGameSettings.TimeLimit);
959 NetOut.Write(gGameSettings.MaxLives);
960 NetOut.Write(LongWord(gGameSettings.Options));
961 NetOut.Write(gTime);
963 g_Net_Host_Send(ID, True);
964 end;
966 procedure MH_SEND_Chat(Txt: String; Mode: Byte; ID: Integer);
968 Name: String;
969 i: Integer;
970 Team: Byte;
971 begin
972 if (Mode = NET_CHAT_TEAM) and (not gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
973 Mode := NET_CHAT_PLAYER;
975 Team := 0;
976 if (Mode = NET_CHAT_TEAM) then
977 begin
978 for i := Low(gPlayers) to High(gPlayers) do
979 if (gPlayers[i] <> nil) and (gPlayers[i].FClientID >= 0) and
980 (gPlayers[i].Team = ID) then
981 begin
982 NetOut.Write(Byte(NET_MSG_CHAT));
983 NetOut.Write(Txt);
984 NetOut.Write(Mode);
985 g_Net_Host_Send(gPlayers[i].FClientID, True);
986 end;
987 Team := ID;
988 ID := NET_EVERYONE;
990 else
991 begin
992 NetOut.Write(Byte(NET_MSG_CHAT));
993 NetOut.Write(Txt);
994 NetOut.Write(Mode);
995 g_Net_Host_Send(ID, True);
996 end;
998 if Mode = NET_CHAT_SYSTEM then
999 Exit;
1001 if ID = NET_EVERYONE then
1002 begin
1003 if Mode = NET_CHAT_PLAYER then
1004 begin
1005 g_Console_Add(Txt, True);
1006 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1007 {$IFDEF ENABLE_SOUND}
1008 g_Game_ChatSound(b_Text_Unformat(Txt));
1009 {$ENDIF}
1011 else
1012 if Mode = NET_CHAT_TEAM then
1013 if gPlayer1 <> nil then
1014 begin
1015 if (gPlayer1.Team = TEAM_RED) and (Team = TEAM_RED) then
1016 begin
1017 g_Console_Add(#18'[Team] '#2 + Txt, True);
1018 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1019 {$IFDEF ENABLE_SOUND}
1020 g_Game_ChatSound(b_Text_Unformat(Txt));
1021 {$ENDIF}
1023 else if (gPlayer1.Team = TEAM_BLUE) and (Team = TEAM_BLUE) then
1024 begin
1025 g_Console_Add(#20'[Team] '#2 + Txt, True);
1026 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1027 {$IFDEF ENABLE_SOUND}
1028 g_Game_ChatSound(b_Text_Unformat(Txt));
1029 {$ENDIF}
1030 end;
1031 end;
1033 else
1034 begin
1035 Name := g_Net_ClientName_ByID(ID);
1036 g_Console_Add('-> ' + Name + ': ' + Txt, True);
1037 e_WriteLog('[Tell ' + Name + '] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1038 {$IFDEF ENABLE_SOUND}
1039 g_Game_ChatSound(b_Text_Unformat(Txt), False);
1040 {$ENDIF}
1041 end;
1042 end;
1044 procedure MH_SEND_Effect(X, Y: Integer; Ang: SmallInt; Kind: Byte; ID: Integer);
1045 begin
1046 NetOut.Write(Byte(NET_MSG_GFX));
1047 NetOut.Write(Kind);
1048 NetOut.Write(X);
1049 NetOut.Write(Y);
1050 NetOut.Write(Ang);
1052 g_Net_Host_Send(ID, False);
1053 end;
1055 procedure MH_SEND_Sound(X, Y: Integer; Name: String; Pos: Boolean; ID: Integer);
1056 begin
1057 NetOut.Write(Byte(NET_MSG_SND));
1058 NetOut.Write(Name);
1059 if Pos then
1060 begin
1061 NetOut.Write(Byte(1));
1062 NetOut.Write(X);
1063 NetOut.Write(Y);
1065 else
1066 NetOut.Write(Byte(0));
1068 g_Net_Host_Send(ID, False);
1069 end;
1071 procedure MH_SEND_CreateProj(Proj: LongInt; ID: Integer);
1072 begin
1073 if (Low(Projectiles) > Proj) or (High(Projectiles) < Proj) then
1074 Exit;
1076 NetOut.Write(Byte(NET_MSG_PJADD));
1077 NetOut.Write(Proj);
1078 NetOut.Write(Projectiles[Proj].ShotType);
1079 NetOut.Write(Projectiles[Proj].Target);
1080 NetOut.Write(Projectiles[Proj].SpawnerUID);
1081 NetOut.Write(Projectiles[Proj].Timeout);
1082 NetOut.Write(Projectiles[Proj].Obj.X);
1083 NetOut.Write(Projectiles[Proj].Obj.Y);
1084 NetOut.Write(Projectiles[Proj].Obj.Vel.X);
1085 NetOut.Write(Projectiles[Proj].Obj.Vel.Y);
1087 g_Net_Host_Send(ID, True);
1088 end;
1090 procedure MH_SEND_UpdateProj(Proj: LongInt; ID: Integer);
1091 begin
1092 if (Low(Projectiles) > Proj) or (High(Projectiles) < Proj) then
1093 Exit;
1095 NetOut.Write(Byte(NET_MSG_PJPOS));
1096 NetOut.Write(Proj);
1097 NetOut.Write(Projectiles[Proj].Obj.X);
1098 NetOut.Write(Projectiles[Proj].Obj.Y);
1099 NetOut.Write(Projectiles[Proj].Obj.Vel.X);
1100 NetOut.Write(Projectiles[Proj].Obj.Vel.Y);
1102 g_Net_Host_Send(ID, False);
1103 end;
1105 procedure MH_SEND_DeleteProj(Proj: LongInt; X, Y: LongInt; Loud: Boolean; ID: Integer);
1106 begin
1107 NetOut.Write(Byte(NET_MSG_PJDEL));
1108 NetOut.Write(Proj);
1109 NetOut.Write(Byte(Loud));
1110 NetOut.Write(X);
1111 NetOut.Write(Y);
1113 g_Net_Host_Send(ID, True);
1114 end;
1116 procedure MH_SEND_GameStats(ID: Integer);
1117 begin
1118 NetOut.Write(Byte(NET_MSG_SCORE));
1119 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1120 begin
1121 NetOut.Write(gTeamStat[TEAM_RED].Score);
1122 NetOut.Write(gTeamStat[TEAM_BLUE].Score);
1124 else
1125 if gGameSettings.GameMode = GM_COOP then
1126 begin
1127 NetOut.Write(gCoopMonstersKilled);
1128 NetOut.Write(gCoopSecretsFound);
1129 end;
1131 g_Net_Host_Send(ID, True);
1132 end;
1134 procedure MH_SEND_CoopStats(ID: Integer);
1135 begin
1136 NetOut.Write(Byte(NET_MSG_COOP));
1137 NetOut.Write(gTotalMonsters);
1138 NetOut.Write(gSecretsCount);
1139 NetOut.Write(gCoopTotalMonstersKilled);
1140 NetOut.Write(gCoopTotalSecretsFound);
1141 NetOut.Write(gCoopTotalMonsters);
1142 NetOut.Write(gCoopTotalSecrets);
1143 end;
1145 procedure MH_SEND_GameEvent(EvType: Byte; EvNum: Integer; EvStr: String; ID: Integer);
1146 begin
1147 NetOut.Write(Byte(NET_MSG_GEVENT));
1148 NetOut.Write(EvType);
1149 NetOut.Write(EvNum);
1150 NetOut.Write(EvStr);
1151 NetOut.Write(Byte(gLastMap));
1152 NetOut.Write(gTime);
1153 if (EvType = NET_EV_MAPSTART) and isWadPath(EvStr) then
1154 begin
1155 NetOut.Write(Byte(1));
1156 NetOut.Write(gWADHash);
1157 end else
1158 NetOut.Write(Byte(0));
1160 g_Net_Host_Send(ID, True);
1161 end;
1163 procedure MH_SEND_FlagEvent(EvType: Byte; Flag: Byte; PID: Word; Quiet: Boolean; ID: Integer);
1164 begin
1165 NetOut.Write(Byte(NET_MSG_FLAG));
1166 NetOut.Write(EvType);
1167 NetOut.Write(Flag);
1168 NetOut.Write(Byte(Quiet));
1169 NetOut.Write(PID);
1170 NetOut.Write(gFlags[Flag].State);
1171 NetOut.Write(gFlags[Flag].CaptureTime);
1172 NetOut.Write(gFlags[Flag].Obj.X);
1173 NetOut.Write(gFlags[Flag].Obj.Y);
1174 NetOut.Write(gFlags[Flag].Obj.Vel.X);
1175 NetOut.Write(gFlags[Flag].Obj.Vel.Y);
1176 NetOut.Write(Byte(gFlags[Flag].Direction));
1178 g_Net_Host_Send(ID, True);
1179 end;
1181 procedure MH_SEND_FlagPos(Flag: Byte; ID: Integer);
1182 begin
1183 NetOut.Write(Byte(NET_MSG_FLAGPOS));
1184 NetOut.Write(Flag);
1185 NetOut.Write(gFlags[Flag].Obj.X);
1186 NetOut.Write(gFlags[Flag].Obj.Y);
1187 NetOut.Write(gFlags[Flag].Obj.Vel.X);
1188 NetOut.Write(gFlags[Flag].Obj.Vel.Y);
1190 g_Net_Host_Send(ID, False);
1191 end;
1193 procedure MH_SEND_GameSettings(ID: Integer);
1194 begin
1195 NetOut.Write(Byte(NET_MSG_GSET));
1196 NetOut.Write(gGameSettings.GameMode);
1197 NetOut.Write(gGameSettings.ScoreLimit);
1198 NetOut.Write(gGameSettings.TimeLimit);
1199 NetOut.Write(gGameSettings.MaxLives);
1200 NetOut.Write(LongWord(gGameSettings.Options));
1202 g_Net_Host_Send(ID, True);
1203 end;
1205 // PLAYER (SEND)
1207 procedure MH_SEND_PlayerCreate(PID: Word; ID: Integer);
1209 P: TPlayer;
1210 begin
1211 P := g_Player_Get(PID);
1212 if P = nil then Exit;
1214 NetOut.Write(Byte(NET_MSG_PLR));
1215 NetOut.Write(PID);
1216 NetOut.Write(P.Name);
1218 NetOut.Write(P.FActualModelName);
1219 NetOut.Write(P.FColor.R);
1220 NetOut.Write(P.FColor.G);
1221 NetOut.Write(P.FColor.B);
1222 NetOut.Write(P.Team);
1224 g_Net_Host_Send(ID, True);
1225 end;
1227 procedure MH_SEND_PlayerPos(Reliable: Boolean; PID: Word; ID: Integer);
1229 kByte: Word;
1230 Pl: TPlayer;
1231 begin
1232 Pl := g_Player_Get(PID);
1233 if Pl = nil then Exit;
1234 if Pl.FDummy then Exit;
1236 NetOut.Write(Byte(NET_MSG_PLRPOS));
1237 NetOut.Write(gTime);
1238 NetOut.Write(PID);
1240 kByte := 0;
1242 with Pl do
1243 begin
1244 NetOut.Write(FPing);
1245 NetOut.Write(FLoss);
1246 if IsKeyPressed(KEY_CHAT) then
1247 kByte := NET_KEY_CHAT
1248 else
1249 begin
1250 if IsKeyPressed(KEY_LEFT) then kByte := kByte or NET_KEY_LEFT;
1251 if IsKeyPressed(KEY_RIGHT) then kByte := kByte or NET_KEY_RIGHT;
1252 if IsKeyPressed(KEY_UP) then kByte := kByte or NET_KEY_UP;
1253 if IsKeyPressed(KEY_DOWN) then kByte := kByte or NET_KEY_DOWN;
1254 if IsKeyPressed(KEY_JUMP) then kByte := kByte or NET_KEY_JUMP;
1255 end;
1257 if JustTeleported then kByte := kByte or NET_KEY_FORCEDIR;
1259 NetOut.Write(kByte);
1260 if Direction = TDirection.D_LEFT then NetOut.Write(Byte(0)) else NetOut.Write(Byte(1));
1261 NetOut.Write(GameX);
1262 NetOut.Write(GameY);
1263 NetOut.Write(GameVelX);
1264 NetOut.Write(GameVelY);
1265 NetOut.Write(GameAccelX);
1266 NetOut.Write(GameAccelY);
1267 end;
1269 g_Net_Host_Send(ID, Reliable);
1270 end;
1272 procedure MH_SEND_PlayerStats(PID: Word; ID: Integer);
1274 P: TPlayer;
1275 I: Integer;
1276 begin
1277 P := g_Player_Get(PID);
1278 if P = nil then Exit;
1280 NetOut.Write(Byte(NET_MSG_PLRSTA));
1281 NetOut.Write(PID);
1283 with P do
1284 begin
1285 NetOut.Write(Byte(alive));
1286 NetOut.Write(Byte(GodMode));
1287 NetOut.Write(Health);
1288 NetOut.Write(Armor);
1289 NetOut.Write(Air);
1290 NetOut.Write(JetFuel);
1291 NetOut.Write(Lives);
1292 NetOut.Write(Team);
1294 for I := WP_FIRST to WP_LAST do
1295 NetOut.Write(Byte(FWeapon[I]));
1297 for I := A_BULLETS to A_HIGH do
1298 NetOut.Write(FAmmo[I]);
1300 for I := A_BULLETS to A_HIGH do
1301 NetOut.Write(FMaxAmmo[I]);
1303 for I := MR_SUIT to MR_MAX do
1304 NetOut.Write(LongWord(FPowerups[I]));
1306 NetOut.Write(Byte(R_ITEM_BACKPACK in FInventory));
1307 NetOut.Write(Byte(R_KEY_RED in FInventory));
1308 NetOut.Write(Byte(R_KEY_GREEN in FInventory));
1309 NetOut.Write(Byte(R_KEY_BLUE in FInventory));
1310 NetOut.Write(Byte(R_BERSERK in FInventory));
1312 NetOut.Write(Frags);
1313 NetOut.Write(Death);
1315 NetOut.Write(CurrWeap);
1317 NetOut.Write(Byte(FSpectator));
1318 NetOut.Write(Byte(FGhost));
1319 NetOut.Write(Byte(FPhysics));
1320 NetOut.Write(Byte(FNoRespawn));
1321 NetOut.Write(Byte(FJetpack));
1322 NetOut.Write(FFireTime);
1323 NetOut.Write(Byte(FFlaming));
1324 NetOut.Write(FSpawnInvul);
1325 end;
1327 g_Net_Host_Send(ID, True);
1328 end;
1330 procedure MH_SEND_PlayerDamage(PID: Word; Kind: Byte; Attacker, Value: Word; VX, VY: Integer; ID: Integer);
1331 begin
1332 NetOut.Write(Byte(NET_MSG_PLRDMG));
1333 NetOut.Write(PID);
1334 NetOut.Write(Kind);
1335 NetOut.Write(Attacker);
1336 NetOut.Write(Value);
1337 NetOut.Write(VX);
1338 NetOut.Write(VY);
1340 g_Net_Host_Send(ID, False);
1341 end;
1343 procedure MH_SEND_PlayerDeath(PID: Word; KillType, DeathType: Byte; Attacker: Word; ID: Integer);
1344 begin
1345 NetOut.Write(Byte(NET_MSG_PLRDIE));
1346 NetOut.Write(PID);
1347 NetOut.Write(KillType);
1348 NetOut.Write(DeathType);
1349 NetOut.Write(Attacker);
1351 g_Net_Host_Send(ID, True);
1352 end;
1354 procedure MH_SEND_PlayerFire(PID: Word; Weapon: Byte; X, Y, AX, AY: Integer; ShotID: Integer;
1355 ID: Integer);
1356 begin
1357 NetOut.Write(Byte(NET_MSG_PLRFIRE));
1358 NetOut.Write(PID);
1359 NetOut.Write(Weapon);
1360 NetOut.Write(X);
1361 NetOut.Write(Y);
1362 NetOut.Write(AX);
1363 NetOut.Write(AY);
1364 NetOut.Write(ShotID);
1366 g_Net_Host_Send(ID, True);
1367 end;
1369 procedure MH_SEND_PlayerDelete(PID: Word; ID: Integer);
1370 begin
1371 NetOut.Write(Byte(NET_MSG_PLRDEL));
1372 NetOut.Write(PID);
1374 g_Net_Host_Send(ID, True);
1375 end;
1377 procedure MH_SEND_PlayerSettings(PID: Word; Mdl: String; ID: Integer);
1379 Pl: TPlayer;
1380 begin
1381 Pl := g_Player_Get(PID);
1382 if Pl = nil then Exit;
1384 NetOut.Write(Byte(NET_MSG_PLRSET));
1385 NetOut.Write(PID);
1386 NetOut.Write(Pl.Name);
1387 if Mdl = ''
1388 then NetOut.Write(Pl.Model.Name)
1389 else NetOut.Write(Mdl);
1390 NetOut.Write(Pl.FColor.R);
1391 NetOut.Write(Pl.FColor.G);
1392 NetOut.Write(Pl.FColor.B);
1393 NetOut.Write(Pl.Team);
1395 g_Net_Host_Send(ID, True);
1396 end;
1398 // ITEM (SEND)
1400 procedure MH_SEND_ItemSpawn(Quiet: Boolean; IID: Word; ID: Integer);
1402 it: PItem;
1403 tt: Byte;
1404 begin
1405 it := g_Items_ByIdx(IID);
1407 NetOut.Write(Byte(NET_MSG_ISPAWN));
1408 NetOut.Write(IID);
1409 NetOut.Write(Byte(Quiet));
1410 tt := it.ItemType;
1411 if it.dropped then tt := tt or $80;
1412 NetOut.Write(tt);
1413 NetOut.Write(Byte(it.Fall));
1414 NetOut.Write(Byte(it.Respawnable));
1415 NetOut.Write(it.Obj.X);
1416 NetOut.Write(it.Obj.Y);
1417 NetOut.Write(it.Obj.Vel.X);
1418 NetOut.Write(it.Obj.Vel.Y);
1420 g_Net_Host_Send(ID, True);
1421 end;
1423 procedure MH_SEND_ItemDestroy(Quiet: Boolean; IID: Word; ID: Integer);
1424 begin
1425 NetOut.Write(Byte(NET_MSG_IDEL));
1426 NetOut.Write(IID);
1427 NetOut.Write(Byte(Quiet));
1429 g_Net_Host_Send(ID, True);
1430 end;
1432 procedure MH_SEND_ItemPos(IID: Word; ID: Integer);
1434 it: PItem;
1435 begin
1436 it := g_Items_ByIdx(IID);
1438 NetOut.Write(Byte(NET_MSG_IPOS));
1439 NetOut.Write(IID);
1440 NetOut.Write(it.Obj.X);
1441 NetOut.Write(it.Obj.Y);
1442 NetOut.Write(it.Obj.Vel.X);
1443 NetOut.Write(it.Obj.Vel.Y);
1445 g_Net_Host_Send(ID, False);
1446 end;
1448 // PANEL
1450 procedure MH_SEND_PanelTexture(PGUID: Integer; AnimLoop: Byte; ID: Integer);
1452 TP: TPanel;
1453 begin
1454 TP := g_Map_PanelByGUID(PGUID);
1455 if (TP = nil) then Exit;
1457 with TP do
1458 begin
1459 NetOut.Write(Byte(NET_MSG_PTEX));
1460 NetOut.Write(LongWord(PGUID));
1461 NetOut.Write(FCurTexture);
1462 NetOut.Write(FCurFrame);
1463 NetOut.Write(FCurFrameCount);
1464 NetOut.Write(AnimLoop);
1465 end;
1467 g_Net_Host_Send(ID, True);
1468 end;
1470 procedure MH_SEND_PanelState(PGUID: Integer; ID: Integer);
1472 TP: TPanel;
1473 mpflags: Byte = 0;
1474 begin
1475 TP := g_Map_PanelByGUID(PGUID);
1476 if (TP = nil) then Exit;
1478 NetOut.Write(Byte(NET_MSG_PSTATE));
1479 NetOut.Write(LongWord(PGUID));
1480 NetOut.Write(Byte(TP.Enabled));
1481 NetOut.Write(TP.LiftType);
1482 NetOut.Write(TP.X);
1483 NetOut.Write(TP.Y);
1484 NetOut.Write(Word(TP.Width));
1485 NetOut.Write(Word(TP.Height));
1486 // mplats
1487 NetOut.Write(LongInt(TP.movingSpeedX));
1488 NetOut.Write(LongInt(TP.movingSpeedY));
1489 NetOut.Write(LongInt(TP.movingStartX));
1490 NetOut.Write(LongInt(TP.movingStartY));
1491 NetOut.Write(LongInt(TP.movingEndX));
1492 NetOut.Write(LongInt(TP.movingEndY));
1493 NetOut.Write(LongInt(TP.sizeSpeedX));
1494 NetOut.Write(LongInt(TP.sizeSpeedY));
1495 NetOut.Write(LongInt(TP.sizeEndX));
1496 NetOut.Write(LongInt(TP.sizeEndY));
1497 if TP.movingActive then mpflags := mpflags or 1;
1498 if TP.moveOnce then mpflags := mpflags or 2;
1499 NetOut.Write(Byte(mpflags));
1501 g_Net_Host_Send(ID, True);
1502 end;
1504 // TRIGGER
1506 procedure MH_SEND_TriggerSound(ClientID: DWORD; play: Boolean; pos: LongWord; count: Integer; ID: Integer);
1507 begin
1508 if gTriggers = nil then Exit;
1510 NetOut.Write(Byte(NET_MSG_TSOUND));
1511 NetOut.Write(ClientID);
1512 NetOut.Write(Byte(play));
1513 NetOut.Write(LongWord(pos));
1514 NetOut.Write(count);
1516 g_Net_Host_Send(ID, True);
1517 end;
1519 procedure MH_SEND_TriggerMusic(name: String; play: Boolean; pos: LongWord; pause: Boolean; ID: Integer);
1520 begin
1521 NetOut.Write(Byte(NET_MSG_TMUSIC));
1522 NetOut.Write(name);
1523 NetOut.Write(Byte(play));
1524 NetOut.Write(LongWord(pos));
1525 NetOut.Write(Byte(pause));
1527 g_Net_Host_Send(ID, True);
1528 end;
1530 // MONSTER
1532 procedure MH_SEND_MonsterSpawn(UID: Word; ID: Integer);
1534 M: TMonster;
1535 begin
1536 M := g_Monsters_ByUID(UID);
1537 if M = nil then
1538 Exit;
1540 with M do
1541 begin
1542 NetOut.Write(Byte(NET_MSG_MSPAWN));
1543 NetOut.Write(UID);
1544 NetOut.Write(MonsterType);
1545 NetOut.Write(MonsterState);
1546 NetOut.Write(MonsterAnim);
1547 NetOut.Write(MonsterTargetUID);
1548 NetOut.Write(MonsterTargetTime);
1549 NetOut.Write(MonsterBehaviour);
1550 NetOut.Write(MonsterSleep);
1551 NetOut.Write(MonsterHealth);
1552 NetOut.Write(MonsterAmmo);
1553 NetOut.Write(GameX);
1554 NetOut.Write(GameY);
1555 NetOut.Write(GameVelX);
1556 NetOut.Write(GameVelY);
1557 NetOut.Write(Byte(GameDirection));
1558 end;
1560 g_Net_Host_Send(ID, True);
1561 end;
1563 procedure MH_SEND_MonsterPos(UID: Word; ID: Integer);
1565 M: TMonster;
1566 begin
1567 M := g_Monsters_ByUID(UID);
1568 if M = nil then Exit;
1570 NetOut.Write(Byte(NET_MSG_MPOS));
1571 NetOut.Write(UID);
1573 with M do
1574 begin
1575 NetOut.Write(GameX);
1576 NetOut.Write(GameY);
1577 NetOut.Write(GameVelX);
1578 NetOut.Write(GameVelY);
1579 NetOut.Write(Byte(GameDirection));
1580 end;
1582 g_Net_Host_Send(ID, False);
1583 end;
1585 procedure MH_SEND_MonsterState(UID: Word; ForcedAnim: Byte; ID: Integer);
1587 M: TMonster;
1588 begin
1589 M := g_Monsters_ByUID(UID);
1590 if M = nil then Exit;
1592 NetOut.Write(Byte(NET_MSG_MSTATE));
1593 NetOut.Write(UID);
1595 with M do
1596 begin
1597 NetOut.Write(MonsterState);
1598 NetOut.Write(ForcedAnim);
1599 NetOut.Write(MonsterTargetUID);
1600 NetOut.Write(MonsterTargetTime);
1601 NetOut.Write(MonsterSleep);
1602 NetOut.Write(MonsterHealth);
1603 NetOut.Write(MonsterAmmo);
1604 NetOut.Write(MonsterPain);
1605 NetOut.Write(Byte(AnimIsReverse));
1606 NetOut.Write(FFireTime);
1607 end;
1609 g_Net_Host_Send(ID, True);
1610 end;
1612 procedure MH_SEND_MonsterShot(UID: Word; X, Y, VX, VY: Integer; ID: Integer);
1613 begin
1614 NetOut.Write(Byte(NET_MSG_MSHOT));
1615 NetOut.Write(UID);
1616 NetOut.Write(X);
1617 NetOut.Write(Y);
1618 NetOut.Write(VX);
1619 NetOut.Write(VY);
1621 g_Net_Host_Send(ID, True);
1622 end;
1624 procedure MH_SEND_MonsterDelete(UID: Word; ID: Integer);
1626 M: TMonster;
1627 begin
1628 M := g_Monsters_ByUID(UID);
1629 if M = nil then Exit;
1631 NetOut.Write(Byte(NET_MSG_MDEL));
1632 NetOut.Write(UID);
1634 g_Net_Host_Send(ID, True);
1635 end;
1637 // MISC
1639 procedure MH_SEND_TimeSync(Time: LongWord; ID: Integer);
1640 begin
1641 NetOut.Write(Byte(NET_MSG_TIME_SYNC));
1642 NetOut.Write(Time);
1644 g_Net_Host_Send(ID, False);
1645 end;
1647 procedure MH_SEND_VoteEvent(EvType: Byte; StrArg1: String; StrArg2: String; IntArg1: SmallInt;
1648 IntArg2: SmallInt; ID: Integer);
1649 begin
1650 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
1651 NetOut.Write(EvType);
1652 NetOut.Write(IntArg1);
1653 NetOut.Write(IntArg2);
1654 NetOut.Write(StrArg1);
1655 NetOut.Write(StrArg2);
1657 g_Net_Host_Send(ID, True);
1658 end;
1660 // CLIENT MESSAGES //
1662 // GAME
1664 procedure MC_RECV_Chat(var M: TMsg);
1666 Txt: String;
1667 Mode: Byte;
1668 begin
1669 Txt := M.ReadString();
1670 Mode := M.ReadByte();
1672 if Mode <> NET_CHAT_SYSTEM then
1673 begin
1674 if NetDeafLevel = 0 then
1675 begin
1676 if Mode = NET_CHAT_PLAYER then
1677 begin
1678 g_Console_Add(Txt, True);
1679 e_WriteLog('[Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1680 {$IFDEF ENABLE_SOUND}
1681 g_Game_ChatSound(b_Text_Unformat(Txt));
1682 {$ENDIF}
1683 end else
1684 if (Mode = NET_CHAT_TEAM) and (gPlayer1 <> nil) then
1685 begin
1686 if gPlayer1.Team = TEAM_RED then
1687 g_Console_Add(b_Text_Format('\r[Team] ') + Txt, True);
1688 if gPlayer1.Team = TEAM_BLUE then
1689 g_Console_Add(b_Text_Format('\b[Team] ') + Txt, True);
1690 e_WriteLog('[Team Chat] ' + b_Text_Unformat(Txt), TMsgType.Notify);
1691 {$IFDEF ENABLE_SOUND}
1692 g_Game_ChatSound(b_Text_Unformat(Txt));
1693 {$ENDIF}
1694 end;
1695 end;
1696 end else if (NetDeafLevel < 2) then
1697 g_Console_Add(Txt, True);
1698 end;
1700 procedure MC_RECV_Effect(var M: TMsg);
1702 Kind: Byte;
1703 X, Y: Integer;
1704 Ang: SmallInt;
1705 Anim: TAnimation;
1706 ID: LongWord;
1707 begin
1708 if not gGameOn then Exit;
1709 Kind := M.ReadByte();
1710 X := M.ReadLongInt();
1711 Y := M.ReadLongInt();
1712 Ang := M.ReadSmallInt();
1714 case Kind of
1715 NET_GFX_SPARK:
1716 g_GFX_Spark(X, Y, 2 + Random(2), Ang, 0, 0);
1718 NET_GFX_TELE:
1719 begin
1720 if g_Frames_Get(ID, 'FRAMES_TELEPORT') then
1721 begin
1722 Anim := TAnimation.Create(ID, False, 3);
1723 g_GFX_OnceAnim(X, Y, Anim);
1724 Anim.Free();
1725 end;
1726 {$IFDEF ENABLE_SOUND}
1727 if Ang = 1 then
1728 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', X, Y);
1729 {$ENDIF}
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 {$IFDEF ENABLE_SOUND}
1742 if Ang = 1 then
1743 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEROCKET', X, Y);
1744 {$ENDIF}
1745 end;
1747 NET_GFX_BFGEXPL:
1748 begin
1749 if g_Frames_Get(ID, 'FRAMES_EXPLODE_BFG') then
1750 begin
1751 Anim := TAnimation.Create(ID, False, 6);
1752 Anim.Blending := False;
1753 g_GFX_OnceAnim(X-64, Y-64, Anim);
1754 Anim.Free();
1755 end;
1756 {$IFDEF ENABLE_SOUND}
1757 if Ang = 1 then
1758 g_Sound_PlayExAt('SOUND_WEAPON_EXPLODEBFG', X, Y);
1759 {$ENDIF}
1760 end;
1762 NET_GFX_BFGHIT:
1763 begin
1764 if g_Frames_Get(ID, 'FRAMES_BFGHIT') then
1765 begin
1766 Anim := TAnimation.Create(ID, False, 4);
1767 g_GFX_OnceAnim(X-32, Y-32, Anim);
1768 Anim.Free();
1769 end;
1770 end;
1772 NET_GFX_FIRE:
1773 begin
1774 if g_Frames_Get(ID, 'FRAMES_FIRE') then
1775 begin
1776 Anim := TAnimation.Create(ID, False, 4);
1777 g_GFX_OnceAnim(X, Y, Anim);
1778 Anim.Free();
1779 end;
1780 {$IFDEF ENABLE_SOUND}
1781 if Ang = 1 then
1782 g_Sound_PlayExAt('SOUND_FIRE', X, Y);
1783 {$ENDIF}
1784 end;
1786 NET_GFX_RESPAWN:
1787 begin
1788 if g_Frames_Get(ID, 'FRAMES_ITEM_RESPAWN') then
1789 begin
1790 Anim := TAnimation.Create(ID, False, 4);
1791 g_GFX_OnceAnim(X, Y, Anim);
1792 Anim.Free();
1793 end;
1794 {$IFDEF ENABLE_SOUND}
1795 if Ang = 1 then
1796 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
1797 {$ENDIF}
1798 end;
1800 NET_GFX_SHELL1:
1801 g_Player_CreateShell(X, Y, 0, -2, SHELL_BULLET);
1803 NET_GFX_SHELL2:
1804 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1806 NET_GFX_SHELL3:
1807 begin
1808 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1809 g_Player_CreateShell(X, Y, 0, -2, SHELL_SHELL);
1810 end;
1811 end;
1812 end;
1814 procedure MC_RECV_Sound(var M: TMsg);
1816 Name: String;
1817 X, Y: Integer;
1818 Pos: Boolean;
1819 begin
1820 Name := M.ReadString();
1821 Pos := M.ReadByte() <> 0;
1822 if Pos then
1823 begin
1824 X := M.ReadLongInt();
1825 Y := M.ReadLongInt();
1826 {$IFDEF ENABLE_SOUND}
1827 g_Sound_PlayExAt(Name, X, Y);
1828 {$ENDIF}
1830 else
1831 begin
1832 {$IFDEF ENABLE_SOUND}
1833 g_Sound_PlayEx(Name);
1834 {$ENDIF}
1835 end;
1836 end;
1838 procedure MC_RECV_CreateProj(var M: TMsg);
1840 I, X, Y, XV, YV: Integer;
1841 Timeout: LongWord;
1842 Target, Spawner: Word;
1843 ShType: Byte;
1844 begin
1845 I := M.ReadLongInt();
1846 ShType := M.ReadByte();
1847 Target := M.ReadWord();
1848 Spawner := M.ReadWord();
1849 Timeout := M.ReadLongWord();
1850 X := M.ReadLongInt();
1851 Y := M.ReadLongInt();
1852 XV := M.ReadLongInt();
1853 YV := M.ReadLongInt();
1855 I := g_Weapon_CreateProj(I, ShType, Spawner, Target, X, Y, XV, YV);
1856 if (Low(Projectiles) <= I) and (High(Projectiles) >= I) then
1857 begin
1858 Projectiles[I].Timeout := Timeout;
1859 //Projectiles[I].Target := Target; // TODO: find a use for Target later
1860 end;
1861 end;
1863 procedure MC_RECV_UpdateProj(var M: TMsg);
1865 I, TX, TY, TXV, TYV: Integer;
1866 begin
1867 I := M.ReadLongInt();
1868 TX := M.ReadLongInt();
1869 TY := M.ReadLongInt();
1870 TXV := M.ReadLongInt();
1871 TYV := M.ReadLongInt();
1873 if (Low(Projectiles) <= I) and (High(Projectiles) >= I) then
1874 with (Projectiles[i]) do
1875 begin
1876 Obj.X := TX;
1877 Obj.Y := TY;
1878 Obj.Vel.X := TXV;
1879 Obj.Vel.Y := TYV;
1880 end;
1881 end;
1883 procedure MC_RECV_DeleteProj(var M: TMsg);
1885 I, X, Y: Integer;
1886 L: Boolean;
1887 begin
1888 if not gGameOn then Exit;
1889 I := M.ReadLongInt();
1890 L := (M.ReadByte() <> 0);
1891 X := M.ReadLongInt();
1892 Y := M.ReadLongInt();
1894 g_Weapon_DestroyProj(I, X, Y, L);
1895 end;
1897 procedure MC_RECV_GameStats(var M: TMsg);
1898 begin
1899 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1900 begin
1901 gTeamStat[TEAM_RED].Score := M.ReadSmallInt();
1902 gTeamStat[TEAM_BLUE].Score := M.ReadSmallInt();
1904 else
1905 if gGameSettings.GameMode = GM_COOP then
1906 begin
1907 gCoopMonstersKilled := M.ReadWord();
1908 gCoopSecretsFound := M.ReadWord();
1909 end;
1910 end;
1912 procedure MC_RECV_CoopStats(var M: TMsg);
1913 begin
1914 gTotalMonsters := M.ReadLongInt();
1915 gSecretsCount := M.ReadLongInt();
1916 gCoopTotalMonstersKilled := M.ReadWord();
1917 gCoopTotalSecretsFound := M.ReadWord();
1918 gCoopTotalMonsters := M.ReadWord();
1919 gCoopTotalSecrets := M.ReadWord();
1920 end;
1922 procedure MC_RECV_GameEvent(var M: TMsg);
1924 EvType: Byte;
1925 EvNum: Integer;
1926 EvStr: String;
1927 EvTime: LongWord;
1928 BHash: Boolean;
1929 EvHash: TMD5Digest;
1930 pl: TPlayer;
1931 i1, i2: TStrings_Locale;
1932 pln: String;
1933 cnt: Byte;
1934 goodCmd: Boolean = true;
1935 begin
1936 FillChar(EvHash, Sizeof(EvHash), 0);
1937 EvType := M.ReadByte();
1938 EvNum := M.ReadLongInt();
1939 EvStr := M.ReadString();
1940 gLastMap := M.ReadByte() <> 0;
1941 if gLastMap and (gGameSettings.GameMode = GM_COOP) then gStatsOff := True;
1942 gStatsPressed := True;
1943 EvTime := M.ReadLongWord();
1944 BHash := M.ReadByte() <> 0;
1945 if BHash then
1946 EvHash := M.ReadMD5();
1948 gTime := EvTime;
1950 if (g_Res_received_map_start <> 0) then
1951 begin
1952 if (g_Res_received_map_start < 0) then Exit;
1953 goodCmd := false;
1954 case EvType of
1955 NET_EV_MAPSTART: goodCmd := true;
1956 NET_EV_MAPEND: goodCmd := true;
1957 NET_EV_PLAYER_KICK: goodCmd := true;
1958 NET_EV_PLAYER_BAN: goodCmd := true;
1959 NET_EV_LMS_WARMUP: goodCmd := true;
1960 end;
1961 if not goodCmd then Exit;
1962 end;
1964 case EvType of
1965 NET_EV_MAPSTART:
1966 begin
1967 if (g_Res_received_map_start <> 0) then
1968 begin
1969 g_Res_received_map_start := -1;
1971 else
1972 begin
1973 gGameOn := False;
1974 g_Game_ClearLoading();
1975 {$IFDEF ENABLE_SOUND}
1976 g_Game_StopAllSounds(True);
1977 {$ENDIF}
1979 gSwitchGameMode := Byte(EvNum);
1980 gGameSettings.GameMode := gSwitchGameMode;
1982 gWADHash := EvHash;
1983 if not g_Game_StartMap(false{asMegawad}, EvStr, True) then
1984 begin
1985 if not isWadPath(EvStr) then
1986 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + EvStr]))
1987 else
1988 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [EvStr]));
1989 Exit;
1990 end;
1992 MC_SEND_FullStateRequest;
1993 end;
1994 end;
1996 NET_EV_MAPEND:
1997 begin
1998 gLMSRespawn := LMS_RESPAWN_NONE;
1999 gLMSRespawnTime := 0;
2000 if (g_Res_received_map_start <> 0) then
2001 begin
2002 g_Res_received_map_start := -1;
2004 else
2005 begin
2006 gMissionFailed := EvNum <> 0;
2007 gExit := EXIT_ENDLEVELCUSTOM;
2008 end;
2009 end;
2011 NET_EV_RCON:
2012 begin
2013 case EvNum of
2014 NET_RCON_NOAUTH:
2015 g_Console_Add(_lc[I_NET_RCON_NOAUTH], True);
2016 NET_RCON_PWGOOD:
2017 g_Console_Add(_lc[I_NET_RCON_PWD_VALID], True);
2018 NET_RCON_PWBAD:
2019 g_Console_Add(_lc[I_NET_RCON_PWD_INVALID], True);
2020 end;
2021 end;
2023 NET_EV_CHANGE_TEAM:
2024 begin
2025 if NetDeafLevel < 2 then
2026 begin
2027 if EvNum = TEAM_RED then
2028 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_RED], [EvStr]), True);
2029 if EvNum = TEAM_BLUE then
2030 g_Console_Add(Format(_lc[I_PLAYER_CHTEAM_BLUE], [EvStr]), True);
2031 end;
2032 end;
2034 NET_EV_PLAYER_KICK:
2035 begin
2036 g_Console_Add(Format(_lc[I_PLAYER_KICK], [EvStr]), True);
2037 if (g_Res_received_map_start <> 0) then g_Res_received_map_start := -1;
2038 end;
2040 NET_EV_PLAYER_BAN:
2041 begin
2042 g_Console_Add(Format(_lc[I_PLAYER_BAN], [EvStr]), True);
2043 if (g_Res_received_map_start <> 0) then g_Res_received_map_start := -1;
2044 end;
2046 NET_EV_LMS_WARMUP:
2047 begin
2048 if EvNum > 0 then
2049 begin
2050 gLMSRespawn := LMS_RESPAWN_WARMUP;
2051 gLMSRespawnTime := gTime + EvNum;
2052 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [EvNum div 1000]), True);
2054 else if gPlayer1 = nil then
2055 begin
2056 g_Console_Add(_lc[I_PLAYER_SPECT4], True);
2057 end;
2058 end;
2060 NET_EV_LMS_SURVIVOR:
2061 g_Console_Add('*** ' + _lc[I_MESSAGE_LMS_SURVIVOR] + ' ***', True);
2063 NET_EV_BIGTEXT:
2064 if NetDeafLevel < 2 then g_Game_Message(AnsiUpperCase(EvStr), Word(EvNum));
2066 NET_EV_SCORE:
2067 begin
2068 pl := g_Player_Get(EvNum and $FFFF);
2069 if pl = nil then
2070 pln := '?'
2071 else
2072 pln := pl.Name;
2073 cnt := (EvNum shr 16) and $FF;
2074 if Pos('w', EvStr) = 0 then
2075 begin
2076 // Default score
2077 if Pos('t', EvStr) = 0 then
2078 begin
2079 // Player +/- score
2080 if Pos('-', EvStr) = 0 then
2081 begin
2082 if Pos('e', EvStr) = 0 then
2083 i1 := I_PLAYER_SCORE_ADD_OWN
2084 else
2085 i1 := I_PLAYER_SCORE_ADD_ENEMY;
2086 end else
2087 begin
2088 if Pos('e', EvStr) = 0 then
2089 i1 := I_PLAYER_SCORE_SUB_OWN
2090 else
2091 i1 := I_PLAYER_SCORE_SUB_ENEMY;
2092 end;
2093 // Which team
2094 if Pos('r', EvStr) > 0 then
2095 i2 := I_PLAYER_SCORE_TO_RED
2096 else
2097 i2 := I_PLAYER_SCORE_TO_BLUE;
2098 g_Console_Add(Format(_lc[i1], [pln, cnt, _lc[i2]]), True);
2099 end else
2100 begin
2101 // Team +/- score
2102 if Pos('-', EvStr) = 0 then
2103 i1 := I_PLAYER_SCORE_ADD_TEAM
2104 else
2105 i1 := I_PLAYER_SCORE_SUB_TEAM;
2106 // Which team
2107 if Pos('r', EvStr) > 0 then
2108 i2 := I_PLAYER_SCORE_RED
2109 else
2110 i2 := I_PLAYER_SCORE_BLUE;
2111 g_Console_Add(Format(_lc[i1], [_lc[i2], cnt]), True);
2112 end;
2113 end else
2114 begin
2115 // Game Win
2116 if Pos('e', EvStr) = 0 then
2117 i1 := I_PLAYER_SCORE_WIN_OWN
2118 else
2119 i1 := I_PLAYER_SCORE_WIN_ENEMY;
2120 // Which team
2121 if Pos('r', EvStr) > 0 then
2122 i2 := I_PLAYER_SCORE_TO_RED
2123 else
2124 i2 := I_PLAYER_SCORE_TO_BLUE;
2125 g_Console_Add(Format(_lc[i1], [pln, _lc[i2]]), True);
2126 end;
2127 end;
2129 NET_EV_SCORE_MSG:
2130 begin
2131 if EvNum = TEAM_RED then
2132 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
2133 if EvNum = TEAM_BLUE then
2134 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_ADD], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
2135 if EvNum = -TEAM_RED then
2136 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 108);
2137 if EvNum = -TEAM_BLUE then
2138 g_Game_Message(Format(_lc[I_MESSAGE_SCORE_SUB], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 108);
2139 end;
2141 NET_EV_LMS_START:
2142 begin
2143 g_Player_RemoveAllCorpses;
2144 gLMSRespawn := LMS_RESPAWN_NONE;
2145 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
2146 end;
2148 NET_EV_LMS_WIN:
2149 g_Game_Message(Format(_lc[I_MESSAGE_LMS_WIN], [AnsiUpperCase(EvStr)]), 144);
2151 NET_EV_TLMS_WIN:
2152 begin
2153 if EvNum = TEAM_RED then
2154 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_RED])]), 144);
2155 if EvNum = TEAM_BLUE then
2156 g_Game_Message(Format(_lc[I_MESSAGE_TLMS_WIN], [AnsiUpperCase(_lc[I_GAME_TEAM_BLUE])]), 144);
2157 end;
2159 NET_EV_LMS_LOSE:
2160 g_Game_Message(_lc[I_MESSAGE_LMS_LOSE], 144);
2162 NET_EV_LMS_DRAW:
2163 g_Game_Message(_lc[I_GAME_WIN_DRAW], 144);
2165 NET_EV_LMS_NOSPAWN:
2166 g_Console_Add(_lc[I_PLAYER_SPECT4], True);
2168 NET_EV_KILLCOMBO:
2169 begin
2170 {$IFDEF ENABLE_SOUND}
2171 g_Game_Announce_KillCombo(EvNum);
2172 {$ENDIF}
2173 end;
2175 NET_EV_PLAYER_TOUCH:
2176 begin
2177 pl := g_Player_Get(EvNum);
2178 if pl <> nil then
2179 pl.Touch();
2180 end;
2182 NET_EV_SECRET:
2183 begin
2184 pl := g_Player_Get(EvNum);
2185 if pl <> nil then
2186 begin
2187 g_Console_Add(Format(_lc[I_PLAYER_SECRET], [pl.Name]), True);
2188 {$IFDEF ENABLE_SOUND}
2189 g_Sound_PlayEx('SOUND_GAME_SECRET');
2190 {$ENDIF}
2191 end;
2192 end;
2194 NET_EV_INTER_READY:
2195 begin
2196 pl := g_Player_Get(EvNum);
2197 if pl <> nil then pl.FReady := (EvStr = 'Y');
2198 end;
2199 end;
2200 end;
2202 procedure MC_RECV_FlagPos(var M: TMsg);
2204 Fl: Byte;
2205 begin
2206 Fl := M.ReadByte();
2207 if Fl = FLAG_NONE then Exit;
2208 gFlags[Fl].Obj.X := M.ReadLongInt();
2209 gFlags[Fl].Obj.Y := M.ReadLongInt();
2210 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
2211 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
2212 end;
2214 procedure MC_RECV_FlagEvent(var M: TMsg);
2216 PID: Word;
2217 Pl: TPlayer;
2218 EvType: Byte;
2219 Fl, a: Byte;
2220 Quiet: Boolean;
2221 s, ts: String;
2222 begin
2223 EvType := M.ReadByte();
2224 Fl := M.ReadByte();
2226 if Fl = FLAG_NONE then Exit;
2228 Quiet := (M.ReadByte() <> 0);
2229 PID := M.ReadWord();
2231 gFlags[Fl].State := M.ReadByte();
2232 gFlags[Fl].CaptureTime := M.ReadLongWord();
2233 gFlags[Fl].Obj.X := M.ReadLongInt();
2234 gFlags[Fl].Obj.Y := M.ReadLongInt();
2235 gFlags[Fl].Obj.Vel.X := M.ReadLongInt();
2236 gFlags[Fl].Obj.Vel.Y := M.ReadLongInt();
2237 gFlags[Fl].Direction := TDirection(M.ReadByte());
2239 Pl := g_Player_Get(PID);
2240 if (Pl = nil) and
2241 (EvType <> FLAG_STATE_NORMAL) and
2242 (EvType <> FLAG_STATE_DROPPED) and
2243 (EvType <> FLAG_STATE_RETURNED) then
2244 Exit;
2246 case EvType of
2247 FLAG_STATE_NORMAL:
2248 begin
2249 if Quiet or (Pl = nil) then Exit;
2251 if Fl = FLAG_RED then
2252 s := _lc[I_PLAYER_FLAG_RED]
2253 else
2254 s := _lc[I_PLAYER_FLAG_BLUE];
2256 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2258 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2259 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2260 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2261 a := 0
2262 else
2263 a := 1;
2265 {$IFDEF ENABLE_SOUND}
2266 if not sound_ret_flag[a].IsPlaying() then
2267 sound_ret_flag[a].Play();
2268 {$ENDIF}
2269 end;
2271 FLAG_STATE_CAPTURED:
2272 begin
2273 if (Pl <> nil) then Pl.SetFlag(Fl);
2275 if Quiet then Exit;
2277 if Fl = FLAG_RED then
2278 s := _lc[I_PLAYER_FLAG_RED]
2279 else
2280 s := _lc[I_PLAYER_FLAG_BLUE];
2282 g_Console_Add(Format(_lc[I_PLAYER_FLAG_GET], [Pl.Name, s]), True);
2283 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_GET], [AnsiUpperCase(s)]), 144);
2285 {$IFDEF ENABLE_SOUND}
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_get_flag[a].IsPlaying() then
2294 sound_get_flag[a].Play();
2295 {$ENDIF}
2296 end;
2298 FLAG_STATE_DROPPED:
2299 begin
2300 if (Pl <> nil) then Pl.SetFlag(FLAG_NONE);
2302 if Quiet or (Pl = nil) then Exit;
2304 if Fl = FLAG_RED then
2305 s := _lc[I_PLAYER_FLAG_RED]
2306 else
2307 s := _lc[I_PLAYER_FLAG_BLUE];
2309 g_Console_Add(Format(_lc[I_PLAYER_FLAG_DROP], [Pl.Name, s]), True);
2310 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_DROP], [AnsiUpperCase(s)]), 144);
2312 {$IFDEF ENABLE_SOUND}
2313 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2314 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2315 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2316 a := 0
2317 else
2318 a := 1;
2320 if not sound_lost_flag[a].IsPlaying() then
2321 sound_lost_flag[a].Play();
2322 {$ENDIF}
2323 end;
2325 FLAG_STATE_SCORED:
2326 begin
2327 g_Map_ResetFlag(FLAG_RED);
2328 g_Map_ResetFlag(FLAG_BLUE);
2329 if Quiet or (Pl = nil) then Exit;
2330 Pl.SetFlag(FLAG_NONE);
2332 if Fl = FLAG_RED then
2333 s := _lc[I_PLAYER_FLAG_RED]
2334 else
2335 s := _lc[I_PLAYER_FLAG_BLUE];
2337 ts := Format('%.4d', [gFlags[Fl].CaptureTime]);
2338 Insert('.', ts, Length(ts) + 1 - 3);
2339 g_Console_Add(Format(_lc[I_PLAYER_FLAG_CAPTURE], [Pl.Name, s, ts]), True);
2340 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_CAPTURE], [AnsiUpperCase(s)]), 144);
2342 {$IFDEF ENABLE_SOUND}
2343 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2344 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2345 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2346 a := 0
2347 else
2348 a := 1;
2350 if not sound_cap_flag[a].IsPlaying() then
2351 sound_cap_flag[a].Play();
2352 {$ENDIF}
2353 end;
2355 FLAG_STATE_RETURNED:
2356 begin
2357 g_Map_ResetFlag(Fl);
2358 if Quiet then Exit;
2360 if Fl = FLAG_RED then
2361 s := _lc[I_PLAYER_FLAG_RED]
2362 else
2363 s := _lc[I_PLAYER_FLAG_BLUE];
2365 g_Game_Message(Format(_lc[I_MESSAGE_FLAG_RETURN], [AnsiUpperCase(s)]), 144);
2367 {$IFDEF ENABLE_SOUND}
2368 if ((Pl = gPlayer1) or (Pl = gPlayer2)
2369 or ((gPlayer1 <> nil) and (gPlayer1.Team = Pl.Team))
2370 or ((gPlayer2 <> nil) and (gPlayer2.Team = Pl.Team))) then
2371 a := 0
2372 else
2373 a := 1;
2375 if not sound_ret_flag[a].IsPlaying() then
2376 sound_ret_flag[a].Play();
2377 {$ENDIF}
2378 end;
2379 end;
2380 end;
2382 procedure MC_RECV_GameSettings(var M: TMsg);
2383 begin
2384 gGameSettings.GameMode := M.ReadByte();
2385 gGameSettings.ScoreLimit := M.ReadWord();
2386 gGameSettings.TimeLimit := M.ReadWord();
2387 gGameSettings.MaxLives := M.ReadByte();
2388 gGameSettings.Options := TGameOptions(M.ReadLongWord());
2389 end;
2391 // PLAYER
2393 function MC_RECV_PlayerCreate(var M: TMsg): Word;
2395 PID, DID: Word;
2396 PName, Model: String;
2397 Color: TRGB;
2398 T: Byte;
2399 Pl: TPlayer;
2400 begin
2401 PID := M.ReadWord();
2402 Pl := g_Player_Get(PID);
2404 PName := M.ReadString();
2405 Model := M.ReadString();
2406 Color.R := M.ReadByte();
2407 Color.G := M.ReadByte();
2408 Color.B := M.ReadByte();
2409 T := M.ReadByte();
2411 Result := 0;
2412 if (PID <> NetPlrUID1) and (PID <> NetPlrUID2) then
2413 begin
2414 if (Pl <> nil) then Exit;
2415 if (g_Force_Model_Get() <> 0) then
2416 Model := g_Forced_Model_GetName();
2417 DID := g_Player_Create(Model, Color, T, False);
2418 with g_Player_Get(DID) do
2419 begin
2420 UID := PID;
2421 Name := PName;
2422 Reset(True);
2423 end;
2425 else
2426 begin
2427 if (PID = NetPlrUID1) and (gPlayer1 <> nil) then begin
2428 gPlayer1.UID := PID;
2429 gPlayer1.Model.SetColor(Color.R, Color.G, Color.B);
2430 gPlayer1.ChangeTeam(T);
2431 end;
2432 if (PID = NetPlrUID2) and (gPlayer2 <> nil) then begin
2433 gPlayer2.UID := PID;
2434 gPlayer2.Model.SetColor(Color.R, Color.G, Color.B);
2435 gPlayer2.ChangeTeam(T);
2436 end;
2437 end;
2439 if NetDeafLevel < 3 then
2440 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
2441 e_WriteLog('NET: Player ' + PName + ' [' + IntToStr(PID) + '] added.', TMsgType.Notify);
2442 Result := PID;
2443 end;
2445 function MC_RECV_PlayerPos(var M: TMsg): Word;
2447 GT: LongWord;
2448 PID: Word;
2449 kByte: Word;
2450 Pl: TPlayer;
2451 Dir: Byte;
2452 TmpX, TmpY: Integer;
2453 begin
2454 Result := 0;
2456 GT := M.ReadLongWord();
2457 if GT < gTime - NET_MAX_DIFFTIME then
2458 begin
2459 gTime := GT;
2460 Exit;
2461 end;
2462 gTime := GT;
2464 PID := M.ReadWord();
2465 Pl := g_Player_Get(PID);
2467 if Pl = nil then Exit;
2469 Result := PID;
2471 with Pl do
2472 begin
2473 FPing := M.ReadWord();
2474 FLoss := M.ReadByte();
2475 kByte := M.ReadWord();
2476 Dir := M.ReadByte();
2478 TmpX := M.ReadLongInt();
2479 TmpY := M.ReadLongInt();
2481 ReleaseKeys;
2483 if LongBool(kByte and NET_KEY_CHAT) then
2484 PressKey(KEY_CHAT, 10000)
2485 else
2486 begin
2487 if LongBool(kByte and NET_KEY_LEFT) then PressKey(KEY_LEFT, 10000);
2488 if LongBool(kByte and NET_KEY_RIGHT) then PressKey(KEY_RIGHT, 10000);
2489 if LongBool(kByte and NET_KEY_UP) then PressKey(KEY_UP, 10000);
2490 if LongBool(kByte and NET_KEY_DOWN) then PressKey(KEY_DOWN, 10000);
2491 if LongBool(kByte and NET_KEY_JUMP) then PressKey(KEY_JUMP, 10000);
2492 end;
2494 JustTeleported := LongBool(kByte and NET_KEY_FORCEDIR);
2496 if ((Pl <> gPlayer1) and (Pl <> gPlayer2)) or JustTeleported then
2497 SetDirection(TDirection(Dir));
2499 GameVelX := M.ReadLongInt();
2500 GameVelY := M.ReadLongInt();
2501 GameAccelX := M.ReadLongInt();
2502 GameAccelY := M.ReadLongInt();
2503 SetLerp(TmpX, TmpY);
2504 if NetForcePlayerUpdate then Update();
2505 end;
2506 end;
2508 function MC_RECV_PlayerStats(var M: TMsg): Word;
2510 PID: Word;
2511 Pl: TPlayer;
2512 I, OldFire: Integer;
2513 OldJet, Flam: Boolean;
2514 NewTeam: Byte;
2515 begin
2516 PID := M.ReadWord();
2517 Pl := g_Player_Get(PID);
2518 Result := 0;
2519 if Pl = nil then
2520 Exit;
2522 with Pl do
2523 begin
2524 alive := (M.ReadByte() <> 0);
2525 GodMode := (M.ReadByte() <> 0);
2526 Health := M.ReadLongInt();
2527 Armor := M.ReadLongInt();
2528 Air := M.ReadLongInt();
2529 JetFuel := M.ReadLongInt();
2530 Lives := M.ReadByte();
2531 NewTeam := M.ReadByte();
2533 for I := WP_FIRST to WP_LAST do
2534 FWeapon[I] := (M.ReadByte() <> 0);
2536 for I := A_BULLETS to A_HIGH do
2537 FAmmo[I] := M.ReadWord();
2539 for I := A_BULLETS to A_HIGH do
2540 FMaxAmmo[I] := M.ReadWord();
2542 for I := MR_SUIT to MR_MAX do
2543 FPowerups[I] := M.ReadLongWord();
2545 FInventory := [];
2546 if (M.ReadByte() <> 0) then FInventory += [R_ITEM_BACKPACK];
2547 if (M.ReadByte() <> 0) then FInventory += [R_KEY_RED];
2548 if (M.ReadByte() <> 0) then FInventory += [R_KEY_GREEN];
2549 if (M.ReadByte() <> 0) then FInventory += [R_KEY_BLUE];
2550 if (M.ReadByte() <> 0) then FInventory += [R_BERSERK];
2552 Frags := M.ReadLongInt();
2553 Death := M.ReadLongInt();
2555 SetWeapon(M.ReadByte());
2557 FSpectator := M.ReadByte() <> 0;
2558 if FSpectator then
2559 begin
2560 if UID = NetPlrUID1 then
2561 begin
2562 gSpectLatchPID1 := UID;
2563 gPlayer1 := nil;
2564 end;
2565 if UID = NetPlrUID2 then
2566 begin
2567 gSpectLatchPID2 := UID;
2568 gPlayer2 := nil;
2569 end;
2571 else
2572 begin
2573 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) and (UID = gSpectLatchPID1) then
2574 begin
2575 gPlayer1 := Pl;
2576 gSpectLatchPID1 := 0;
2577 end;
2578 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) and (UID = gSpectLatchPID2) then
2579 begin
2580 gPlayer2 := Pl;
2581 gSpectLatchPID2 := 0;
2582 end;
2583 end;
2584 FGhost := M.ReadByte() <> 0;
2585 FPhysics := M.ReadByte() <> 0;
2586 FNoRespawn := M.ReadByte() <> 0;
2587 OldJet := FJetpack;
2588 FJetpack := M.ReadByte() <> 0;
2589 OldFire := FFireTime;
2590 FFireTime := M.ReadLongInt();
2591 {$IFDEF ENABLE_SOUND}
2592 if (OldFire <= 0) and (FFireTime > 0) then
2593 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
2594 {$ENDIF}
2595 Flam := M.ReadByte() <> 0;
2596 FSpawnInvul := M.ReadLongInt();
2597 if OldJet and not FJetpack then
2598 JetpackOff
2599 else if not OldJet and FJetpack then
2600 JetpackOn;
2601 if FFlaming and not Flam then
2602 FlamerOff;
2603 if Team <> NewTeam then
2604 Pl.ChangeTeam(NewTeam);
2605 end;
2607 Result := PID;
2608 end;
2610 function MC_RECV_PlayerDamage(var M: TMsg): Word;
2612 PID: Word;
2613 Pl: TPlayer;
2614 Kind: Byte;
2615 Attacker, Value: Word;
2616 VX, VY: Integer;
2617 begin
2618 Result := 0;
2619 if not gGameOn then Exit;
2620 PID := M.ReadWord();
2621 Pl := g_Player_Get(PID);
2622 if Pl = nil then Exit;
2624 Kind := M.ReadByte();
2625 Attacker := M.ReadWord();
2626 Value := M.ReadWord();
2627 VX := M.ReadWord();
2628 VY := M.ReadWord();
2630 with Pl do
2631 Damage(Value, Attacker, VX, VY, Kind);
2633 Result := PID;
2634 end;
2636 function MC_RECV_PlayerDeath(var M: TMsg): Word;
2638 PID: Word;
2639 Pl: TPlayer;
2640 KillType, DeathType: Byte;
2641 Attacker: Word;
2642 begin
2643 Result := 0;
2644 if not gGameOn then Exit;
2645 PID := M.ReadWord();
2646 Pl := g_Player_Get(PID);
2647 if Pl = nil then Exit;
2649 KillType := M.ReadByte();
2650 DeathType := M.ReadByte();
2651 Attacker := M.ReadWord();
2653 with Pl do
2654 begin
2655 Kill(KillType, Attacker, DeathType);
2656 SoftReset;
2657 end;
2658 end;
2660 function MC_RECV_PlayerDelete(var M: TMsg): Word;
2662 PID: Word;
2663 Pl: TPlayer;
2664 begin
2665 PID := M.ReadWord();
2666 Pl := g_Player_Get(PID);
2667 Result := 0;
2668 if Pl = nil then Exit;
2670 if NetDeafLevel < 3 then
2671 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2672 e_WriteLog('NET: Player ' + Pl.Name + ' [' + IntToStr(PID) + '] removed.', TMsgType.Notify);
2674 g_Player_Remove(PID);
2676 Result := PID;
2677 end;
2679 function MC_RECV_PlayerFire(var M: TMsg): Word;
2681 PID: Word;
2682 Weap: Byte;
2683 Pl: TPlayer;
2684 X, Y, AX, AY: Integer;
2685 SHID: Integer;
2686 begin
2687 Result := 0;
2688 if not gGameOn then Exit;
2689 PID := M.ReadWord();
2690 Pl := g_Player_Get(PID);
2691 if Pl = nil then Exit;
2693 Weap := M.ReadByte();
2694 X := M.ReadLongInt();
2695 Y := M.ReadLongInt();
2696 AX := M.ReadLongInt();
2697 AY := M.ReadLongInt();
2698 SHID := M.ReadLongInt();
2700 with Pl do
2701 if alive then NetFire(Weap, X, Y, AX, AY, SHID);
2702 end;
2704 procedure MC_RECV_PlayerSettings(var M: TMsg);
2706 TmpName: String;
2707 TmpModel: String;
2708 CheckModel: String;
2709 TmpColor: TRGB;
2710 TmpTeam: Byte;
2711 Pl: TPlayer;
2712 PID: Word;
2713 begin
2714 PID := M.ReadWord();
2715 Pl := g_Player_Get(PID);
2716 if Pl = nil then Exit;
2718 TmpName := M.ReadString();
2719 TmpModel := M.ReadString();
2720 TmpColor.R := M.ReadByte();
2721 TmpColor.G := M.ReadByte();
2722 TmpColor.B := M.ReadByte();
2723 TmpTeam := M.ReadByte();
2725 if (gGameSettings.GameMode in [GM_TDM, GM_CTF]) and (Pl.Team <> TmpTeam) then
2726 begin
2727 Pl.ChangeTeam(TmpTeam);
2728 if gPlayer1 = Pl then
2729 gPlayer1Settings.Team := TmpTeam;
2730 if gPlayer2 = Pl then
2731 gPlayer2Settings.Team := TmpTeam;
2732 end else
2733 Pl.SetColor(TmpColor);
2735 if Pl.Name <> TmpName then
2736 begin
2737 if NetDeafLevel < 3 then
2738 g_Console_Add(Format(_lc[I_PLAYER_NAME], [Pl.Name, TmpName]), True);
2739 Pl.Name := TmpName;
2740 end;
2742 if (g_Force_Model_Get() <> 0) then
2743 TmpModel := g_Forced_Model_GetName();
2744 if TmpModel <> Pl.Model.Name then
2745 Pl.SetModel(TmpModel);
2746 end;
2748 // ITEM
2750 procedure MC_RECV_ItemSpawn(var M: TMsg);
2752 ID: Word;
2753 AID: DWord;
2754 X, Y, VX, VY: Integer;
2755 T: Byte;
2756 Quiet, Fall{, Resp}: Boolean;
2757 Anim: TAnimation;
2758 it: PItem;
2759 begin
2760 if not gGameOn then Exit;
2761 ID := M.ReadWord();
2762 Quiet := M.ReadByte() <> 0;
2763 T := M.ReadByte();
2764 Fall := M.ReadByte() <> 0;
2765 {Resp :=} M.ReadByte();
2766 X := M.ReadLongInt();
2767 Y := M.ReadLongInt();
2768 VX := M.ReadLongInt();
2769 VY := M.ReadLongInt();
2771 g_Items_Create(X, Y, T and $7F, Fall, False, False, ID);
2772 if ((T and $80) <> 0) then g_Items_SetDrop(ID);
2774 it := g_Items_ByIdx(ID);
2775 it.Obj.Vel.X := VX;
2776 it.Obj.Vel.Y := VY;
2778 if not Quiet then
2779 begin
2780 {$IFDEF ENABLE_SOUND}
2781 g_Sound_PlayExAt('SOUND_ITEM_RESPAWNITEM', X, Y);
2782 {$ENDIF}
2783 if g_Frames_Get(AID, 'FRAMES_ITEM_RESPAWN') then
2784 begin
2785 Anim := TAnimation.Create(AID, False, 4);
2786 g_GFX_OnceAnim(X+(it.Obj.Rect.Width div 2)-16, Y+(it.Obj.Rect.Height div 2)-16, Anim);
2787 Anim.Free();
2788 end;
2789 end;
2790 end;
2792 procedure MC_RECV_ItemDestroy(var M: TMsg);
2794 ID: Word;
2795 Quiet: Boolean;
2796 begin
2797 if not gGameOn then
2798 Exit;
2800 ID := M.ReadWord();
2801 Quiet := M.ReadByte() <> 0;
2803 if not g_Items_ValidId(ID) then
2804 Exit;
2806 {$IFDEF ENABLE_SOUND}
2807 if not Quiet then
2808 g_Items_EmitPickupSound(ID);
2809 {$ENDIF}
2811 g_Items_Remove(ID);
2812 end;
2814 procedure MC_RECV_ItemPos(var M: TMsg);
2816 ID: Word;
2817 X, Y, VX, VY: Integer;
2818 it: PItem;
2819 begin
2820 if not gGameOn then Exit;
2822 ID := M.ReadWord();
2823 X := M.ReadLongInt();
2824 Y := M.ReadLongInt();
2825 VX := M.ReadLongInt();
2826 VY := M.ReadLongInt();
2828 if g_Items_ValidId(ID) then
2829 begin
2830 it := g_Items_ByIdx(ID);
2831 it.Obj.X := X;
2832 it.Obj.Y := Y;
2833 it.Obj.Vel.X := VX;
2834 it.Obj.Vel.Y := VY;
2835 it.positionChanged();
2836 end;
2837 end;
2839 // PANEL
2841 procedure MC_RECV_PanelTexture(var M: TMsg);
2843 TP: TPanel;
2844 PGUID: Integer;
2845 Tex, Fr: Integer;
2846 Loop, Cnt: Byte;
2847 begin
2848 if not gGameOn then Exit;
2850 PGUID := Integer(M.ReadLongWord());
2851 Tex := M.ReadLongInt();
2852 Fr := M.ReadLongInt();
2853 Cnt := M.ReadByte();
2854 Loop := M.ReadByte();
2856 TP := g_Map_PanelByGUID(PGUID);
2857 if (TP <> nil) then
2858 begin
2859 // switch texture
2860 TP.SetTexture(Tex, Loop);
2861 TP.SetFrame(Fr, Cnt);
2862 end;
2863 end;
2865 procedure MC_RECV_PanelState(var M: TMsg);
2867 PGUID: Integer;
2868 E: Boolean;
2869 Lift: Byte;
2870 X, Y, W, H: Integer;
2871 TP: TPanel;
2872 speedX, speedY, startX, startY, endX, endY: Integer;
2873 sizeSpX, sizeSpY, sizeEX, sizeEY: Integer;
2874 mpflags: Byte;
2875 begin
2876 if not gGameOn then Exit;
2878 PGUID := Integer(M.ReadLongWord());
2879 E := (M.ReadByte() <> 0);
2880 Lift := M.ReadByte();
2881 X := M.ReadLongInt();
2882 Y := M.ReadLongInt();
2883 W := M.ReadWord();
2884 H := M.ReadWord();
2885 // mplats
2886 speedX := M.ReadLongInt();
2887 speedY := M.ReadLongInt();
2888 startX := M.ReadLongInt();
2889 startY := M.ReadLongInt();
2890 endX := M.ReadLongInt();
2891 endY := M.ReadLongInt();
2892 sizeSpX := M.ReadLongInt();
2893 sizeSpY := M.ReadLongInt();
2894 sizeEX := M.ReadLongInt();
2895 sizeEY := M.ReadLongInt();
2896 mpflags := M.ReadByte(); // bit0: TP.movingActive; bit1: TP.moveOnce
2898 TP := g_Map_PanelByGUID(PGUID);
2899 if (TP = nil) then Exit;
2901 // update lifts state
2902 if TP.isGLift then g_Map_SetLiftGUID(PGUID, Lift);
2904 // update enabled/disabled state for all panels
2905 if E then g_Map_EnableWallGUID(PGUID) else g_Map_DisableWallGUID(PGUID);
2907 // update panel position, as it can be moved (mplat)
2908 TP.X := X;
2909 TP.Y := Y;
2910 TP.Width := W;
2911 TP.Height := H;
2912 // update mplat state
2913 TP.movingSpeedX := speedX;
2914 TP.movingSpeedY := speedY;
2915 TP.movingStartX := startX;
2916 TP.movingStartY := startY;
2917 TP.movingEndX := endX;
2918 TP.movingEndY := endY;
2919 TP.sizeSpeedX := sizeSpX;
2920 TP.sizeSpeedY := sizeSpY;
2921 TP.sizeEndX := sizeEX;
2922 TP.sizeEndY := sizeEY;
2923 TP.movingActive := ((mpflags and 1) <> 0);
2924 TP.moveOnce := ((mpflags and 2) <> 0);
2925 // notify panel of it's position/size change, so it can fix other internal structures
2926 TP.positionChanged();
2927 end;
2929 // TRIGGERS
2931 procedure MC_RECV_TriggerSound(var M: TMsg);
2933 SPlaying: Boolean;
2934 SPos, SID: LongWord;
2935 SCount: LongInt;
2936 I: Integer;
2937 begin
2938 if not gGameOn then Exit;
2939 if gTriggers = nil then Exit;
2941 SID := M.ReadLongWord();
2942 SPlaying := M.ReadByte() <> 0;
2943 SPos := M.ReadLongWord();
2944 SCount := M.ReadLongInt();
2946 for I := Low(gTriggers) to High(gTriggers) do
2947 if gTriggers[I].TriggerType = TRIGGER_SOUND then
2948 if gTriggers[I].ClientID = SID then
2949 with gTriggers[I] do
2950 begin
2951 {$IFDEF ENABLE_SOUND}
2952 if Sound <> nil then
2953 begin
2954 if SPlaying then
2955 begin
2956 if tgcLocal then
2957 Sound.PlayVolumeAt(X+(Width div 2), Y+(Height div 2), tgcVolume/255.0)
2958 else
2959 Sound.PlayPanVolume((tgcPan-127.0)/128.0, tgcVolume/255.0);
2960 Sound.SetPosition(SPos);
2962 else if Sound.IsPlaying then
2963 Sound.Stop;
2964 end;
2965 {$ELSE}
2966 if SPlaying then
2967 begin
2968 SoundPlay := True;
2969 SoundPos := SPos;
2971 else if SoundPlay then
2972 begin
2973 SoundPlay := False;
2974 SoundPos := 0;
2975 end;
2976 {$ENDIF}
2978 SoundPlayCount := SCount;
2979 end;
2980 end;
2982 procedure MC_RECV_TriggerMusic(var M: TMsg);
2984 MName: String;
2985 MPlaying: Boolean;
2986 MPos: LongWord;
2987 MPaused: Boolean;
2988 begin
2989 if not gGameOn then Exit;
2991 MName := M.ReadString();
2992 MPlaying := M.ReadByte() <> 0;
2993 MPos := M.ReadLongWord();
2994 MPaused := M.ReadByte() <> 0;
2995 MPos := MPos+1; //k8: stfu, fpc!
2997 {$IFDEF ENABLE_SOUND}
2998 if MPlaying then
2999 begin
3000 gMusic.SetByName(MName);
3001 gMusic.Play(True);
3002 gMusic.SetPosition(MPos);
3003 gMusic.SpecPause := MPaused;
3005 else if gMusic.IsPlaying then
3006 begin
3007 gMusic.Stop;
3008 end;
3009 {$ELSE}
3010 if MPlaying then
3011 begin
3012 gMusicName := MName;
3013 gMusicPlay := True;
3014 gMusicPos := MPos;
3015 gMusicPause := MPaused;
3017 else if gMusicPlay then
3018 begin
3019 gMusicPlay := False;
3020 gMusicPos := 0;
3021 end;
3022 {$ENDIF}
3023 end;
3025 // MONSTERS
3027 procedure MC_RECV_MonsterSpawn(var M: TMsg);
3029 ID: Word;
3030 MType, MState, MDir, MAnim, MBehav: Byte;
3031 X, Y, VX, VY, MTargTime, MHealth, MAmmo, MSleep: Integer;
3032 MTarg: Word;
3033 Mon: TMonster;
3034 begin
3035 ID := M.ReadWord();
3036 Mon := g_Monsters_ByUID(ID);
3037 if Mon <> nil then
3038 Exit;
3040 MType := M.ReadByte();
3041 MState := M.ReadByte();
3042 MAnim := M.ReadByte();
3043 MTarg := M.ReadWord();
3044 MTargTime := M.ReadLongInt();
3045 MBehav := M.ReadByte();
3046 MSleep := M.ReadLongInt();
3047 MHealth := M.ReadLongInt();
3048 MAmmo := M.ReadLongInt();
3050 X := M.ReadLongInt();
3051 Y := M.ReadLongInt();
3052 VX := M.ReadLongInt();
3053 VY := M.ReadLongInt();
3054 MDir := M.ReadByte();
3056 g_Monsters_Create(MType, X, Y, TDirection(MDir), False, ID);
3057 Mon := g_Monsters_ByUID(ID);
3058 if Mon = nil then
3059 Exit;
3061 with Mon do
3062 begin
3064 MonsterAnim := MAnim;
3065 MonsterTargetUID := MTarg;
3066 MonsterTargetTime := MTargTime;
3067 MonsterBehaviour := MBehav;
3068 MonsterSleep := MSleep;
3069 MonsterAmmo := MAmmo;
3070 SetHealth(MHealth);
3072 SetState(MState);
3074 setPosition(X, Y); // this will call positionChanged();
3075 GameVelX := VX;
3076 GameVelY := VY;
3077 end;
3078 end;
3080 procedure MC_RECV_MonsterPos(var M: TMsg);
3082 Mon: TMonster;
3083 ID: Word;
3084 X, Y: Integer;
3085 begin
3086 ID := M.ReadWord();
3087 Mon := g_Monsters_ByUID(ID);
3088 if Mon = nil then
3089 Exit;
3091 with Mon do
3092 begin
3093 X := M.ReadLongInt();
3094 Y := M.ReadLongInt();
3095 Mon.setPosition(X, Y); // this will call `positionChanged()`
3096 GameVelX := M.ReadLongInt();
3097 GameVelY := M.ReadLongInt();
3098 GameDirection := TDirection(M.ReadByte());
3099 end;
3100 end;
3102 procedure MC_RECV_MonsterState(var M: TMsg);
3104 ID, OldFire: Integer;
3105 MState, MFAnm: Byte;
3106 Mon: TMonster;
3107 AnimRevert: Boolean;
3108 begin
3109 ID := M.ReadWord();
3110 Mon := g_Monsters_ByUID(ID);
3111 if Mon = nil then Exit;
3113 MState := M.ReadByte();
3114 MFAnm := M.ReadByte();
3116 with Mon do
3117 begin
3118 MonsterTargetUID := M.ReadWord();
3119 MonsterTargetTime := M.ReadLongInt();
3120 MonsterSleep := M.ReadLongInt();
3121 MonsterHealth := M.ReadLongInt();
3122 MonsterAmmo := M.ReadLongInt();
3123 MonsterPain := M.ReadLongInt();
3124 AnimRevert := M.ReadByte() <> 0;
3125 OldFire := FFireTime;
3126 FFireTime := M.ReadLongInt();
3127 {$IFDEF ENABLE_SOUND}
3128 if (OldFire <= 0) and (FFireTime > 0) then
3129 g_Sound_PlayExAt('SOUND_IGNITE', Obj.X, Obj.Y);
3130 {$ENDIF}
3131 RevertAnim(AnimRevert);
3133 if MonsterState <> MState then
3134 begin
3135 if (MState = MONSTATE_GO) and (MonsterState = MONSTATE_SLEEP) then WakeUpSound();
3136 if (MState = MONSTATE_DIE) then DieSound();
3137 if (MState = MONSTATE_PAIN) then MakeBloodSimple(Min(200, MonsterPain));
3138 if (MState = MONSTATE_ATTACK) then kick(nil);
3139 if (MState = MONSTATE_DEAD) then SetDeadAnim();
3141 SetState(MState, MFAnm);
3142 end;
3143 end;
3144 end;
3146 procedure MC_RECV_MonsterShot(var M: TMsg);
3148 ID: Integer;
3149 Mon: TMonster;
3150 X, Y, VX, VY: Integer;
3151 begin
3152 ID := M.ReadWord();
3154 Mon := g_Monsters_ByUID(ID);
3155 if Mon = nil then Exit;
3157 X := M.ReadLongInt();
3158 Y := M.ReadLongInt();
3159 VX := M.ReadLongInt();
3160 VY := M.ReadLongInt();
3162 Mon.ClientAttack(X, Y, VX, VY);
3163 end;
3165 procedure MC_RECV_MonsterDelete(var M: TMsg);
3167 ID: Integer;
3168 Mon: TMonster;
3169 begin
3170 ID := M.ReadWord();
3171 Mon := g_Monsters_ByUID(ID);
3172 if Mon = nil then Exit;
3173 Mon.SetState(5);
3174 Mon.MonsterRemoved := True;
3175 end;
3177 procedure MC_RECV_TimeSync(var M: TMsg);
3179 Time: LongWord;
3180 begin
3181 Time := M.ReadLongWord();
3183 if gState = STATE_INTERCUSTOM then
3184 gServInterTime := Min(Time, 255);
3185 end;
3187 procedure MC_RECV_VoteEvent(var M: TMsg);
3189 EvID: Byte;
3190 Str1, Str2: String;
3191 Int1, Int2: SmallInt;
3192 begin
3193 EvID := M.ReadByte();
3194 Int1 := M.ReadSmallInt();
3195 Int2 := M.ReadSmallInt();
3196 Str1 := M.ReadString();
3197 Str2 := M.ReadString();
3199 if NetDeafLevel < 2 then
3200 case EvID of
3201 NET_VE_STARTED:
3202 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Str1, Str2, Int1]), True);
3203 NET_VE_PASSED:
3204 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [Str1]), True);
3205 NET_VE_FAILED:
3206 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
3207 NET_VE_VOTE:
3208 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [Str1, Int1, Int2]), True);
3209 NET_VE_INPROGRESS:
3210 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [Str1]), True);
3211 end;
3212 end;
3214 // CLIENT SEND
3216 procedure MC_SEND_Info(Password: String);
3217 var i: Integer;
3218 begin
3219 NetOut.Clear();
3221 NetOut.Write(Byte(NET_MSG_INFO));
3222 NetOut.Write(GAME_VERSION);
3223 NetOut.Write(Password);
3224 NetOut.Write(gPlayer1Settings.Name);
3225 NetOut.Write(gPlayer1Settings.Model);
3226 NetOut.Write(gPlayer1Settings.Color.R);
3227 NetOut.Write(gPlayer1Settings.Color.G);
3228 NetOut.Write(gPlayer1Settings.Color.B);
3229 NetOut.Write(gPlayer1Settings.Team);
3230 NetOut.Write(gPlayer1Settings.WeaponSwitch);
3231 for i := WP_FIRST to WP_LAST + 1 do
3232 NetOut.Write(gPlayer1Settings.WeaponPreferences[i]);
3233 NetOut.Write(gPlayer1Settings.SwitchToEmpty);
3234 NetOut.Write(gPlayer1Settings.SkipIronFist);
3236 g_Net_Client_Send(True);
3237 end;
3239 procedure MC_SEND_Chat(Txt: String; Mode: Byte);
3240 begin
3241 NetOut.Write(Byte(NET_MSG_CHAT));
3242 NetOut.Write(Txt);
3243 NetOut.Write(Mode);
3245 g_Net_Client_Send(True);
3246 end;
3248 procedure MC_SEND_PlayerPos();
3250 kByte: Word;
3251 Predict: Boolean;
3252 strafeDir: Byte;
3253 WeaponAct: Byte = 0;
3254 WeaponSelect: Word = 0;
3255 i: Integer;
3256 begin
3257 if not gGameOn then Exit;
3258 if gPlayers = nil then Exit;
3259 if gPlayer1 = nil then Exit;
3261 kByte := 0;
3262 Predict := NetPredictSelf; // and (not NetGotKeys);
3264 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
3265 begin
3266 strafeDir := P1MoveButton shr 4;
3267 P1MoveButton := P1MoveButton and $0F;
3269 if gPlayerAction[0, ACTION_MOVELEFT] and (not gPlayerAction[0, ACTION_MOVERIGHT]) then
3270 P1MoveButton := 1
3271 else if (not gPlayerAction[0, ACTION_MOVELEFT]) and gPlayerAction[0, ACTION_MOVERIGHT] then
3272 P1MoveButton := 2
3273 else if (not gPlayerAction[0, ACTION_MOVELEFT]) and (not gPlayerAction[0, ACTION_MOVERIGHT]) then
3274 P1MoveButton := 0;
3276 // strafing
3277 if gPlayerAction[0, ACTION_STRAFE] then
3278 begin
3279 // new strafe mechanics
3280 if (strafeDir = 0) then
3281 strafeDir := P1MoveButton; // start strafing
3282 // now set direction according to strafe (reversed)
3283 if (strafeDir = 2) then
3284 gPlayer1.SetDirection(TDirection.D_LEFT)
3285 else if (strafeDir = 1) then
3286 gPlayer1.SetDirection(TDirection.D_RIGHT)
3288 else
3289 begin
3290 strafeDir := 0; // not strafing anymore
3291 if (P1MoveButton = 2) and gPlayerAction[0, ACTION_MOVELEFT] then
3292 gPlayer1.SetDirection(TDirection.D_LEFT)
3293 else if (P1MoveButton = 1) and gPlayerAction[0, ACTION_MOVERIGHT] then
3294 gPlayer1.SetDirection(TDirection.D_RIGHT)
3295 else if P1MoveButton <> 0 then
3296 gPlayer1.SetDirection(TDirection(P1MoveButton-1));
3297 end;
3299 gPlayer1.ReleaseKeys;
3300 if P1MoveButton = 1 then
3301 begin
3302 kByte := kByte or NET_KEY_LEFT;
3303 if Predict then gPlayer1.PressKey(KEY_LEFT, 10000);
3304 end;
3305 if P1MoveButton = 2 then
3306 begin
3307 kByte := kByte or NET_KEY_RIGHT;
3308 if Predict then gPlayer1.PressKey(KEY_RIGHT, 10000);
3309 end;
3310 if gPlayerAction[0, ACTION_LOOKUP] then
3311 begin
3312 kByte := kByte or NET_KEY_UP;
3313 gPlayer1.PressKey(KEY_UP, 10000);
3314 end;
3315 if gPlayerAction[0, ACTION_LOOKDOWN] then
3316 begin
3317 kByte := kByte or NET_KEY_DOWN;
3318 gPlayer1.PressKey(KEY_DOWN, 10000);
3319 end;
3320 if gPlayerAction[0, ACTION_JUMP] then
3321 begin
3322 kByte := kByte or NET_KEY_JUMP;
3323 // gPlayer1.PressKey(KEY_JUMP, 10000); // TODO: Make a prediction option
3324 end;
3325 if gPlayerAction[0, ACTION_ATTACK] then kByte := kByte or NET_KEY_FIRE;
3326 if gPlayerAction[0, ACTION_ACTIVATE] then kByte := kByte or NET_KEY_OPEN;
3328 for i := WP_FACT to WP_LACT do
3329 begin
3330 if gWeaponAction[0, i] then
3331 begin
3332 WeaponAct := WeaponAct or Byte(1 shl i);
3333 gWeaponAction[0, i] := False
3335 end;
3337 for i := WP_FIRST to WP_LAST do
3338 begin
3339 if gSelectWeapon[0, i] then
3340 begin
3341 WeaponSelect := WeaponSelect or Word(1 shl i);
3342 gSelectWeapon[0, i] := False
3344 end;
3346 // fix movebutton state
3347 P1MoveButton := P1MoveButton or (strafeDir shl 4);
3349 else
3350 kByte := NET_KEY_CHAT;
3352 NetOut.Write(Byte(NET_MSG_PLRPOS));
3353 NetOut.Write(gTime);
3354 NetOut.Write(kByte);
3355 NetOut.Write(Byte(gPlayer1.Direction));
3356 NetOut.Write(WeaponAct);
3357 NetOut.Write(WeaponSelect);
3358 //e_WriteLog(Format('S:ws=%d', [WeaponSelect]), MSG_WARNING);
3359 g_Net_Client_Send(True);
3361 //kBytePrev := kByte;
3362 //kDirPrev := gPlayer1.Direction;
3363 end;
3365 procedure MC_SEND_Vote(Start: Boolean; Command: String);
3366 begin
3367 NetOut.Write(Byte(NET_MSG_VOTE_EVENT));
3368 NetOut.Write(Byte(Start));
3369 NetOut.Write(Command);
3370 g_Net_Client_Send(True);
3371 end;
3373 procedure MC_SEND_PlayerSettings();
3374 var i: Integer;
3375 begin
3376 NetOut.Write(Byte(NET_MSG_PLRSET));
3377 NetOut.Write(gPlayer1Settings.Name);
3378 NetOut.Write(gPlayer1Settings.Model);
3379 NetOut.Write(gPlayer1Settings.Color.R);
3380 NetOut.Write(gPlayer1Settings.Color.G);
3381 NetOut.Write(gPlayer1Settings.Color.B);
3382 NetOut.Write(gPlayer1Settings.Team);
3383 NetOut.Write(gPlayer1Settings.WeaponSwitch);
3384 for i := WP_FIRST to WP_LAST + 1 do
3385 NetOut.Write(gPlayer1Settings.WeaponPreferences[i]);
3386 NetOut.Write(gPlayer1Settings.SwitchToEmpty);
3387 NetOut.Write(gPlayer1Settings.SkipIronFist);
3389 g_Net_Client_Send(True);
3390 end;
3392 procedure MC_SEND_FullStateRequest();
3393 begin
3394 NetOut.Write(Byte(NET_MSG_REQFST));
3396 g_Net_Client_Send(True);
3397 end;
3399 procedure MC_SEND_CheatRequest(Kind: Byte);
3400 begin
3401 NetOut.Write(Byte(NET_MSG_CHEAT));
3402 NetOut.Write(Kind);
3404 g_Net_Client_Send(True);
3405 end;
3406 procedure MC_SEND_RCONPassword(Password: String);
3407 begin
3408 NetOut.Write(Byte(NET_MSG_RCON_AUTH));
3409 NetOut.Write(Password);
3411 g_Net_Client_Send(True);
3412 end;
3413 procedure MC_SEND_RCONCommand(Cmd: String);
3414 begin
3415 NetOut.Write(Byte(NET_MSG_RCON_CMD));
3416 NetOut.Write(Cmd);
3418 g_Net_Client_Send(True);
3419 end;
3422 end.