DEADSOFTWARE

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