DEADSOFTWARE

Make autoswitch server-side. Add option to skip empty weapons by travi$
[d2df-sdl.git] / src / game / g_netmsg.pas
index 3590bd43add3c68343b3c1535fe6d9b37cc5dee6..55b99b3705acbc0ddbe05e00b04ba3657ea2c9fd 100644 (file)
@@ -380,6 +380,9 @@ procedure MH_RECV_Info(C: pTNetClient; var M: TMsg);
 var
   Ver, PName, Model, Pw: string;
   R, G, B, T: Byte;
+  WeapSwitch: Byte;
+  TmpPrefArray: Array [WP_FIRST .. WP_LAST + 1] of Byte;
+  SwitchEmpty: Byte;
   PID: Word;
   Color: TRGB;
   I: Integer;
@@ -395,6 +398,11 @@ begin
     G := M.ReadByte();
     B := M.ReadByte();
     T := M.ReadByte();
+    WeapSwitch := M.ReadByte();
+    if (WeapSwitch = 2) then
+      for I := WP_FIRST to WP_LAST + 1 do
+        TmpPrefArray[I] := M.ReadByte();
+    SwitchEmpty := M.ReadByte();
   except
     Err := True;
   end;
@@ -450,11 +458,16 @@ begin
   with g_Player_Get(PID) do
   begin
     Name := PName;
+    WeapSwitchMode := WeapSwitch;
+    if (WeapSwitch = 2) then
+      SetWeaponPrefs(TmpPrefArray);
+    SwitchToEmpty := SwitchEmpty;
     Reset(True);
   end;
 
   C^.Player := PID;
   C^.WaitForFirstSpawn := false;
+  C^.AuthTime := 0;
 
   g_Console_Add(Format(_lc[I_PLAYER_JOIN], [PName]), True);
   e_WriteLog('NET: Client ' + PName + ' [' + IntToStr(C^.ID) +
@@ -699,6 +712,10 @@ var
   TmpModel: string;
   TmpColor: TRGB;
   TmpTeam: Byte;
+  TmpWeapSwitch: Byte;
+  TmpPrefArray: Array [WP_FIRST .. WP_LAST + 1] of Byte;
+  TmpSwEmpty: Byte;
+  I: Integer;
   Pl: TPlayer;
   Err: Boolean;
 begin
@@ -710,6 +727,11 @@ begin
     TmpColor.G := M.ReadByte();
     TmpColor.B := M.ReadByte();
     TmpTeam := M.ReadByte();
+    TmpWeapSwitch := M.ReadByte();
+    if (TmpWeapSwitch = 2) then
+      for I := WP_FIRST to WP_LAST + 1 do
+        TmpPrefArray[I] := M.ReadByte();
+    TmpSwEmpty := M.ReadByte();
   except
     Err := True;
   end;
@@ -733,6 +755,14 @@ begin
   if TmpModel <> Pl.Model.Name then
     Pl.SetModel(TmpModel);
 
+  if (TmpWeapSwitch <> Pl.WeapSwitchMode) then
+    Pl.WeapSwitchMode := TmpWeapSwitch;
+
+  if (TmpWeapSwitch = 2) then
+    Pl.SetWeaponPrefs(TmpPrefArray);
+
+  if (TmpSwEmpty <> Pl.SwitchToEmpty) then
+    Pl.SwitchToEmpty := TmpSwEmpty;
   MH_SEND_PlayerSettings(Pl.UID, TmpModel);
 end;
 
@@ -2646,6 +2676,7 @@ var
   TmpModel: string;
   TmpColor: TRGB;
   TmpTeam: Byte;
+  i: Integer;
   Pl: TPlayer;
   PID: Word;
 begin
@@ -3110,6 +3141,7 @@ end;
 // CLIENT SEND
 
 procedure MC_SEND_Info(Password: string);
+var i: Integer;
 begin
   NetOut.Clear();
 
@@ -3122,6 +3154,11 @@ begin
   NetOut.Write(gPlayer1Settings.Color.G);
   NetOut.Write(gPlayer1Settings.Color.B);
   NetOut.Write(gPlayer1Settings.Team);
+  NetOut.Write(gPlayer1Settings.WeaponSwitch);
+  if (gPlayer1Settings.WeaponSwitch = 2) then
+    for i := WP_FIRST to WP_LAST + 1 do
+      NetOut.Write(gPlayer1Settings.WeaponPreferences[i]);
+  NetOut.Write(gPlayer1Settings.SwitchToEmpty);
 
   g_Net_Client_Send(True, NET_CHAN_SERVICE);
 end;
@@ -3261,6 +3298,7 @@ begin
 end;
 
 procedure MC_SEND_PlayerSettings();
+var i: Integer;
 begin
   NetOut.Write(Byte(NET_MSG_PLRSET));
   NetOut.Write(gPlayer1Settings.Name);
@@ -3269,7 +3307,11 @@ begin
   NetOut.Write(gPlayer1Settings.Color.G);
   NetOut.Write(gPlayer1Settings.Color.B);
   NetOut.Write(gPlayer1Settings.Team);
-
+  NetOut.Write(gPlayer1Settings.WeaponSwitch);
+  if (gPlayer1Settings.WeaponSwitch = 2) then
+    for i := WP_FIRST to WP_LAST + 1 do
+      NetOut.Write(gPlayer1Settings.WeaponPreferences[i]);
+  NetOut.Write(gPlayer1Settings.SwitchToEmpty);
   g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
 end;