Build 0.18.4.0
This commit is contained in:
@@ -647,6 +647,7 @@ namespace Barotrauma
|
||||
{
|
||||
msg.Write(false);
|
||||
}
|
||||
msg.Write(HumanPrefabHealthMultiplier);
|
||||
msg.Write(Wallet.Balance);
|
||||
msg.WriteRangedInteger(Wallet.RewardDistribution, 0, 100);
|
||||
msg.Write((byte)TeamID);
|
||||
|
||||
@@ -1676,7 +1676,7 @@ namespace Barotrauma
|
||||
GameMain.Server.SendConsoleMessage("No campaign active.", client, Color.Red);
|
||||
return;
|
||||
}
|
||||
mpCampaign.LastUpdateID++;
|
||||
mpCampaign.IncrementLastUpdateIdForFlag(MultiPlayerCampaign.NetFlags.MapAndMissions);
|
||||
GameMain.GameSession.Map.AllowDebugTeleport = !GameMain.GameSession.Map.AllowDebugTeleport;
|
||||
NewMessage(client.Name + (GameMain.GameSession.Map.AllowDebugTeleport ? " enabled" : " disabled") + " teleportation on the campaign map.", Color.White);
|
||||
GameMain.Server.SendConsoleMessage((GameMain.GameSession.Map.AllowDebugTeleport ? "Enabled" : "Disabled") + " teleportation on the campaign map.", client);
|
||||
@@ -2274,7 +2274,6 @@ namespace Barotrauma
|
||||
Wallet wallet = targetCharacter is null ? campaign.Bank : targetCharacter.Wallet;
|
||||
wallet.Give(money);
|
||||
GameAnalyticsManager.AddMoneyGainedEvent(money, GameAnalyticsManager.MoneySource.Cheat, "console");
|
||||
campaign.LastUpdateID++;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+197
-101
@@ -37,7 +37,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (forceMapUI == value) { return; }
|
||||
forceMapUI = value;
|
||||
LastUpdateID++;
|
||||
IncrementLastUpdateIdForFlag(NetFlags.MapAndMissions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,11 +71,43 @@ namespace Barotrauma
|
||||
get { return ForceMapUI || CoroutineManager.IsCoroutineRunning("LevelTransition"); }
|
||||
}
|
||||
|
||||
public static void StartNewCampaign(string savePath, string subPath, string seed, CampaignSettings settings)
|
||||
private bool purchasedHullRepairs, purchasedLostShuttles, purchasedItemRepairs;
|
||||
public override bool PurchasedHullRepairs
|
||||
{
|
||||
get { return purchasedHullRepairs; }
|
||||
set
|
||||
{
|
||||
if (purchasedHullRepairs == value) { return; }
|
||||
purchasedHullRepairs = value;
|
||||
IncrementLastUpdateIdForFlag(NetFlags.Misc);
|
||||
}
|
||||
}
|
||||
public override bool PurchasedLostShuttles
|
||||
{
|
||||
get { return purchasedLostShuttles; }
|
||||
set
|
||||
{
|
||||
if (purchasedLostShuttles == value) { return; }
|
||||
purchasedLostShuttles = value;
|
||||
IncrementLastUpdateIdForFlag(NetFlags.Misc);
|
||||
}
|
||||
}
|
||||
public override bool PurchasedItemRepairs
|
||||
{
|
||||
get { return purchasedItemRepairs; }
|
||||
set
|
||||
{
|
||||
if (purchasedItemRepairs == value) { return; }
|
||||
purchasedItemRepairs = value;
|
||||
IncrementLastUpdateIdForFlag(NetFlags.Misc);
|
||||
}
|
||||
}
|
||||
|
||||
public static void StartNewCampaign(string savePath, string subPath, string seed, CampaignSettings startingSettings)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(savePath)) { return; }
|
||||
|
||||
GameMain.GameSession = new GameSession(new SubmarineInfo(subPath), savePath, GameModePreset.MultiPlayerCampaign, settings, seed);
|
||||
GameMain.GameSession = new GameSession(new SubmarineInfo(subPath), savePath, GameModePreset.MultiPlayerCampaign, startingSettings, seed);
|
||||
GameMain.NetLobbyScreen.ToggleCampaignMode(true);
|
||||
SaveUtil.SaveGame(GameMain.GameSession.SavePath);
|
||||
|
||||
@@ -158,7 +190,7 @@ namespace Barotrauma
|
||||
public override void Start()
|
||||
{
|
||||
base.Start();
|
||||
lastUpdateID++;
|
||||
IncrementAllLastUpdateIds();
|
||||
}
|
||||
|
||||
private static bool IsOwner(Client client) => client != null && client.Connection == GameMain.Server.OwnerConnection;
|
||||
@@ -274,7 +306,7 @@ namespace Barotrauma
|
||||
|
||||
protected override IEnumerable<CoroutineStatus> DoLevelTransition(TransitionType transitionType, LevelData newLevel, Submarine leavingSub, bool mirror, List<TraitorMissionResult> traitorResults)
|
||||
{
|
||||
lastUpdateID++;
|
||||
IncrementAllLastUpdateIds();
|
||||
|
||||
switch (transitionType)
|
||||
{
|
||||
@@ -321,6 +353,7 @@ namespace Barotrauma
|
||||
yield return CoroutineStatus.Running;
|
||||
LeaveUnconnectedSubs(leavingSub);
|
||||
NextLevel = newLevel;
|
||||
GameMain.GameSession.SubmarineInfo = new SubmarineInfo(GameMain.GameSession.Submarine);
|
||||
SaveUtil.SaveGame(GameMain.GameSession.SavePath);
|
||||
}
|
||||
else
|
||||
@@ -329,7 +362,7 @@ namespace Barotrauma
|
||||
GameMain.Server.EndGame(TransitionType.None, wasSaved: false);
|
||||
LoadCampaign(GameMain.GameSession.SavePath);
|
||||
LastSaveID++;
|
||||
LastUpdateID++;
|
||||
IncrementAllLastUpdateIds();
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
@@ -360,14 +393,14 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
partial void InitProjSpecific()
|
||||
{
|
||||
CargoManager.OnItemsInBuyCrateChanged += () => { LastUpdateID++; };
|
||||
CargoManager.OnPurchasedItemsChanged += () => { LastUpdateID++; };
|
||||
CargoManager.OnSoldItemsChanged += () => { LastUpdateID++; };
|
||||
UpgradeManager.OnUpgradesChanged += () => { LastUpdateID++; };
|
||||
Map.OnLocationSelected += (loc, connection) => { LastUpdateID++; };
|
||||
Map.OnMissionsSelected += (loc, mission) => { LastUpdateID++; };
|
||||
Reputation.OnAnyReputationValueChanged += () => { LastUpdateID++; };
|
||||
{
|
||||
CargoManager.OnItemsInBuyCrateChanged += () => { IncrementLastUpdateIdForFlag(NetFlags.ItemsInBuyCrate); };
|
||||
CargoManager.OnPurchasedItemsChanged += () => { IncrementLastUpdateIdForFlag(NetFlags.PurchasedItems); };
|
||||
CargoManager.OnSoldItemsChanged += () => { IncrementLastUpdateIdForFlag(NetFlags.SoldItems); };
|
||||
UpgradeManager.OnUpgradesChanged += () => { IncrementLastUpdateIdForFlag(NetFlags.UpgradeManager); };
|
||||
Map.OnLocationSelected += (loc, connection) => { IncrementLastUpdateIdForFlag(NetFlags.MapAndMissions); };
|
||||
Map.OnMissionsSelected += (loc, mission) => { IncrementLastUpdateIdForFlag(NetFlags.MapAndMissions); };
|
||||
Reputation.OnAnyReputationValueChanged += () => { IncrementLastUpdateIdForFlag(NetFlags.Reputation); };
|
||||
|
||||
//increment save ID so clients know they're lacking the most up-to-date save file
|
||||
LastSaveID++;
|
||||
@@ -388,6 +421,7 @@ namespace Barotrauma
|
||||
discardedCharacters.Add(data);
|
||||
}
|
||||
characterData.Remove(data);
|
||||
IncrementLastUpdateIdForFlag(NetFlags.CharacterInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -402,6 +436,7 @@ namespace Barotrauma
|
||||
characterData.RemoveAll(cd => cd.MatchesClient(client));
|
||||
var data = new CharacterCampaignData(client);
|
||||
characterData.Add(data);
|
||||
IncrementLastUpdateIdForFlag(NetFlags.CharacterInfo);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -413,6 +448,7 @@ namespace Barotrauma
|
||||
var matchingData = GetClientCharacterData(client);
|
||||
if (matchingData != null) { client.CharacterInfo = matchingData.CharacterInfo; }
|
||||
}
|
||||
IncrementLastUpdateIdForFlag(NetFlags.CharacterInfo);
|
||||
}
|
||||
|
||||
public Dictionary<Client, Job> GetAssignedJobs(IEnumerable<Client> connectedClients)
|
||||
@@ -517,127 +553,187 @@ namespace Barotrauma
|
||||
base.End(transitionType);
|
||||
}
|
||||
|
||||
private bool IsFlagRequired(Client c, NetFlags flag)
|
||||
=> !c.LastRecvCampaignUpdate.TryGetValue(flag, out var id) || NetIdUtils.IdMoreRecent(GetLastUpdateIdForFlag(flag), id);
|
||||
|
||||
public void ServerWrite(IWriteMessage msg, Client c)
|
||||
{
|
||||
System.Diagnostics.Debug.Assert(map.Locations.Count < UInt16.MaxValue);
|
||||
|
||||
Reputation reputation = Map?.CurrentLocation?.Reputation;
|
||||
NetFlags requiredFlags = lastUpdateID.Keys.Where(k => IsFlagRequired(c, k)).Aggregate((NetFlags)0, (f1, f2) => f1 | f2);
|
||||
|
||||
msg.Write((UInt16)requiredFlags);
|
||||
|
||||
msg.Write(IsFirstRound);
|
||||
msg.Write(CampaignID);
|
||||
msg.Write(lastUpdateID);
|
||||
msg.Write(lastSaveID);
|
||||
msg.Write(map.Seed);
|
||||
msg.Write(map.CurrentLocationIndex == -1 ? UInt16.MaxValue : (UInt16)map.CurrentLocationIndex);
|
||||
msg.Write(map.SelectedLocationIndex == -1 ? UInt16.MaxValue : (UInt16)map.SelectedLocationIndex);
|
||||
|
||||
var selectedMissionIndices = map.GetSelectedMissionIndices();
|
||||
msg.Write((byte)selectedMissionIndices.Count());
|
||||
foreach (int selectedMissionIndex in selectedMissionIndices)
|
||||
|
||||
if (requiredFlags.HasFlag(NetFlags.Misc))
|
||||
{
|
||||
msg.Write((byte)selectedMissionIndex);
|
||||
msg.Write(GetLastUpdateIdForFlag(NetFlags.Misc));
|
||||
msg.Write(PurchasedHullRepairs);
|
||||
msg.Write(PurchasedItemRepairs);
|
||||
msg.Write(PurchasedLostShuttles);
|
||||
}
|
||||
|
||||
var subList = GameMain.NetLobbyScreen.GetSubList();
|
||||
List<int> ownedSubmarineIndices = new List<int>();
|
||||
for (int i = 0; i < subList.Count; i++)
|
||||
if (requiredFlags.HasFlag(NetFlags.MapAndMissions))
|
||||
{
|
||||
if (GameMain.GameSession.OwnedSubmarines.Any(s => s.Name == subList[i].Name))
|
||||
msg.Write(GetLastUpdateIdForFlag(NetFlags.MapAndMissions));
|
||||
msg.Write(ForceMapUI);
|
||||
msg.Write(map.AllowDebugTeleport);
|
||||
msg.Write(map.CurrentLocationIndex == -1 ? UInt16.MaxValue : (UInt16)map.CurrentLocationIndex);
|
||||
msg.Write(map.SelectedLocationIndex == -1 ? UInt16.MaxValue : (UInt16)map.SelectedLocationIndex);
|
||||
|
||||
if (map.CurrentLocation != null)
|
||||
{
|
||||
ownedSubmarineIndices.Add(i);
|
||||
}
|
||||
}
|
||||
msg.Write((ushort)ownedSubmarineIndices.Count);
|
||||
foreach (int index in ownedSubmarineIndices)
|
||||
{
|
||||
msg.Write((ushort)index);
|
||||
}
|
||||
|
||||
msg.Write(map.AllowDebugTeleport);
|
||||
msg.Write(reputation != null);
|
||||
if (reputation != null) { msg.Write(reputation.Value); }
|
||||
|
||||
// hopefully we'll never have more than 128 factions
|
||||
msg.Write((byte)Factions.Count);
|
||||
foreach (Faction faction in Factions)
|
||||
{
|
||||
msg.Write(faction.Prefab.Identifier);
|
||||
msg.Write(faction.Reputation.Value);
|
||||
}
|
||||
|
||||
msg.Write(ForceMapUI);
|
||||
|
||||
msg.Write(PurchasedHullRepairs);
|
||||
msg.Write(PurchasedItemRepairs);
|
||||
msg.Write(PurchasedLostShuttles);
|
||||
|
||||
if (map.CurrentLocation != null)
|
||||
{
|
||||
msg.Write((byte)map.CurrentLocation?.AvailableMissions.Count());
|
||||
foreach (Mission mission in map.CurrentLocation.AvailableMissions)
|
||||
{
|
||||
msg.Write(mission.Prefab.Identifier);
|
||||
if (mission.Locations[0] == mission.Locations[1])
|
||||
msg.Write((byte)map.CurrentLocation.AvailableMissions.Count());
|
||||
foreach (Mission mission in map.CurrentLocation.AvailableMissions)
|
||||
{
|
||||
msg.Write((byte)255);
|
||||
}
|
||||
else
|
||||
{
|
||||
Location missionDestination = mission.Locations[0] == map.CurrentLocation ? mission.Locations[1] : mission.Locations[0];
|
||||
LocationConnection connection = map.CurrentLocation.Connections.Find(c => c.OtherLocation(map.CurrentLocation) == missionDestination);
|
||||
msg.Write((byte)map.CurrentLocation.Connections.IndexOf(connection));
|
||||
msg.Write(mission.Prefab.Identifier);
|
||||
if (mission.Locations[0] == mission.Locations[1])
|
||||
{
|
||||
msg.Write((byte)255);
|
||||
}
|
||||
else
|
||||
{
|
||||
Location missionDestination = mission.Locations[0] == map.CurrentLocation ? mission.Locations[1] : mission.Locations[0];
|
||||
LocationConnection connection = map.CurrentLocation.Connections.Find(c => c.OtherLocation(map.CurrentLocation) == missionDestination);
|
||||
msg.Write((byte)map.CurrentLocation.Connections.IndexOf(connection));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Store balance
|
||||
bool hasStores = map.CurrentLocation.Stores != null && map.CurrentLocation.Stores.Any();
|
||||
msg.Write(hasStores);
|
||||
if (hasStores)
|
||||
else
|
||||
{
|
||||
msg.Write((byte)map.CurrentLocation.Stores.Count);
|
||||
foreach (var store in map.CurrentLocation.Stores.Values)
|
||||
msg.Write((byte)0);
|
||||
}
|
||||
|
||||
var selectedMissionIndices = map.GetSelectedMissionIndices();
|
||||
msg.Write((byte)selectedMissionIndices.Count());
|
||||
foreach (int selectedMissionIndex in selectedMissionIndices)
|
||||
{
|
||||
msg.Write((byte)selectedMissionIndex);
|
||||
}
|
||||
|
||||
WriteStores(msg);
|
||||
}
|
||||
|
||||
if (requiredFlags.HasFlag(NetFlags.SubList))
|
||||
{
|
||||
msg.Write(GetLastUpdateIdForFlag(NetFlags.SubList));
|
||||
var subList = GameMain.NetLobbyScreen.GetSubList();
|
||||
List<int> ownedSubmarineIndices = new List<int>();
|
||||
for (int i = 0; i < subList.Count; i++)
|
||||
{
|
||||
if (GameMain.GameSession.OwnedSubmarines.Any(s => s.Name == subList[i].Name))
|
||||
{
|
||||
msg.Write(store.Identifier);
|
||||
msg.Write((UInt16)store.Balance);
|
||||
ownedSubmarineIndices.Add(i);
|
||||
}
|
||||
}
|
||||
msg.Write((ushort)ownedSubmarineIndices.Count);
|
||||
foreach (int index in ownedSubmarineIndices)
|
||||
{
|
||||
msg.Write((ushort)index);
|
||||
}
|
||||
}
|
||||
else
|
||||
if (requiredFlags.HasFlag(NetFlags.UpgradeManager))
|
||||
{
|
||||
msg.Write((byte)0);
|
||||
// Store balance
|
||||
msg.Write(false);
|
||||
msg.Write(GetLastUpdateIdForFlag(NetFlags.UpgradeManager));
|
||||
msg.Write((ushort)UpgradeManager.PendingUpgrades.Count);
|
||||
foreach (var (prefab, category, level) in UpgradeManager.PendingUpgrades)
|
||||
{
|
||||
msg.Write(prefab.Identifier);
|
||||
msg.Write(category.Identifier);
|
||||
msg.Write((byte)level);
|
||||
}
|
||||
msg.Write((ushort)UpgradeManager.PurchasedItemSwaps.Count);
|
||||
foreach (var itemSwap in UpgradeManager.PurchasedItemSwaps)
|
||||
{
|
||||
msg.Write(itemSwap.ItemToRemove.ID);
|
||||
msg.Write(itemSwap.ItemToInstall?.Identifier ?? Identifier.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
WriteItems(msg, CargoManager.ItemsInBuyCrate);
|
||||
WriteItems(msg, CargoManager.ItemsInSellFromSubCrate);
|
||||
WriteItems(msg, CargoManager.PurchasedItems);
|
||||
WriteItems(msg, CargoManager.SoldItems);
|
||||
|
||||
msg.Write((ushort)UpgradeManager.PendingUpgrades.Count);
|
||||
foreach (var (prefab, category, level) in UpgradeManager.PendingUpgrades)
|
||||
if (requiredFlags.HasFlag(NetFlags.ItemsInBuyCrate))
|
||||
{
|
||||
msg.Write(prefab.Identifier);
|
||||
msg.Write(category.Identifier);
|
||||
msg.Write((byte)level);
|
||||
msg.Write(GetLastUpdateIdForFlag(NetFlags.ItemsInBuyCrate));
|
||||
WriteItems(msg, CargoManager.ItemsInBuyCrate);
|
||||
WriteStores(msg);
|
||||
}
|
||||
|
||||
msg.Write((ushort)UpgradeManager.PurchasedItemSwaps.Count);
|
||||
foreach (var itemSwap in UpgradeManager.PurchasedItemSwaps)
|
||||
if (requiredFlags.HasFlag(NetFlags.ItemsInSellFromSubCrate))
|
||||
{
|
||||
msg.Write(itemSwap.ItemToRemove.ID);
|
||||
msg.Write(itemSwap.ItemToInstall?.Identifier ?? Identifier.Empty);
|
||||
msg.Write(GetLastUpdateIdForFlag(NetFlags.ItemsInSellFromSubCrate));
|
||||
WriteItems(msg, CargoManager.ItemsInSellFromSubCrate);
|
||||
WriteStores(msg);
|
||||
}
|
||||
|
||||
var characterData = GetClientCharacterData(c);
|
||||
if (characterData?.CharacterInfo == null)
|
||||
if (requiredFlags.HasFlag(NetFlags.PurchasedItems))
|
||||
{
|
||||
msg.Write(false);
|
||||
msg.Write(GetLastUpdateIdForFlag(NetFlags.PurchasedItems));
|
||||
WriteItems(msg, CargoManager.PurchasedItems);
|
||||
WriteStores(msg);
|
||||
|
||||
}
|
||||
else
|
||||
if (requiredFlags.HasFlag(NetFlags.SoldItems))
|
||||
{
|
||||
msg.Write(true);
|
||||
characterData.CharacterInfo.ServerWrite(msg);
|
||||
msg.Write(GetLastUpdateIdForFlag(NetFlags.SoldItems));
|
||||
WriteItems(msg, CargoManager.SoldItems);
|
||||
WriteStores(msg);
|
||||
}
|
||||
if (requiredFlags.HasFlag(NetFlags.Reputation))
|
||||
{
|
||||
msg.Write(GetLastUpdateIdForFlag(NetFlags.Reputation));
|
||||
Reputation reputation = Map?.CurrentLocation?.Reputation;
|
||||
msg.Write(reputation != null);
|
||||
if (reputation != null) { msg.Write(reputation.Value); }
|
||||
|
||||
// hopefully we'll never have more than 128 factions
|
||||
msg.Write((byte)Factions.Count);
|
||||
foreach (Faction faction in Factions)
|
||||
{
|
||||
msg.Write(faction.Prefab.Identifier);
|
||||
msg.Write(faction.Reputation.Value);
|
||||
}
|
||||
}
|
||||
if (requiredFlags.HasFlag(NetFlags.CharacterInfo))
|
||||
{
|
||||
msg.Write(GetLastUpdateIdForFlag(NetFlags.CharacterInfo));
|
||||
var characterData = GetClientCharacterData(c);
|
||||
if (characterData?.CharacterInfo == null)
|
||||
{
|
||||
msg.Write(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.Write(true);
|
||||
characterData.CharacterInfo.ServerWrite(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void WriteStores(IWriteMessage msg)
|
||||
{
|
||||
if (map.CurrentLocation != null)
|
||||
{
|
||||
// Store balance
|
||||
bool hasStores = map.CurrentLocation.Stores != null && map.CurrentLocation.Stores.Any();
|
||||
msg.Write(hasStores);
|
||||
if (hasStores)
|
||||
{
|
||||
msg.Write((byte)map.CurrentLocation.Stores.Count);
|
||||
foreach (var store in map.CurrentLocation.Stores.Values)
|
||||
{
|
||||
msg.Write(store.Identifier);
|
||||
msg.Write((UInt16)store.Balance);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.Write((byte)0);
|
||||
// Store balance
|
||||
msg.Write(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -102,6 +102,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
msg.Write(autoPilot);
|
||||
msg.Write(TryExtractEventData<EventData>(extraData, out var eventData) && eventData.DockingButtonClicked);
|
||||
msg.Write(user?.ID ?? Entity.NullEntityID);
|
||||
|
||||
if (!autoPilot)
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Barotrauma.Networking
|
||||
public UInt16 LastSentEntityEventID = 0;
|
||||
public UInt16 LastRecvEntityEventID = 0;
|
||||
|
||||
public UInt16 LastRecvCampaignUpdate = 0;
|
||||
public readonly Dictionary<MultiPlayerCampaign.NetFlags, UInt16> LastRecvCampaignUpdate = new Dictionary<MultiPlayerCampaign.NetFlags, ushort>();
|
||||
public UInt16 LastRecvCampaignSave = 0;
|
||||
|
||||
public (UInt16 saveId, float time) LastCampaignSaveSendTime;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Barotrauma.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ namespace Barotrauma.Networking
|
||||
else
|
||||
{
|
||||
Log("Using SteamP2P networking.", ServerLog.MessageType.ServerMessage);
|
||||
serverPeer = new SteamP2PServerPeer(ownerSteamId.Value, serverSettings);
|
||||
serverPeer = new SteamP2PServerPeer(ownerSteamId.Value, ownerKey.Value, serverSettings);
|
||||
}
|
||||
|
||||
serverPeer.OnInitializationComplete = OnInitializationComplete;
|
||||
@@ -746,7 +746,7 @@ namespace Barotrauma.Networking
|
||||
string seed = inc.ReadString();
|
||||
string subName = inc.ReadString();
|
||||
string subHash = inc.ReadString();
|
||||
CampaignSettings settings = new CampaignSettings(inc);
|
||||
CampaignSettings settings = INetSerializableStruct.Read<CampaignSettings>(inc);
|
||||
|
||||
var matchingSub = SubmarineInfo.SavedSubmarines.FirstOrDefault(s => s.Name == subName && s.MD5Hash.StringRepresentation == subHash);
|
||||
|
||||
@@ -767,8 +767,7 @@ namespace Barotrauma.Networking
|
||||
string localSavePath = SaveUtil.CreateSavePath(SaveUtil.SaveType.Multiplayer, saveName);
|
||||
if (connectedClient.HasPermission(ClientPermissions.SelectMode) || connectedClient.HasPermission(ClientPermissions.ManageCampaign))
|
||||
{
|
||||
ServerSettings.RadiationEnabled = settings.RadiationEnabled;
|
||||
ServerSettings.MaxMissionCount = settings.MaxMissionCount;
|
||||
ServerSettings.CampaignSettings = settings;
|
||||
ServerSettings.SaveSettings();
|
||||
MultiPlayerCampaign.StartNewCampaign(localSavePath, matchingSub.FilePath, seed, settings);
|
||||
}
|
||||
@@ -833,6 +832,9 @@ namespace Barotrauma.Networking
|
||||
case ClientPacketHeader.EVENTMANAGER_RESPONSE:
|
||||
GameMain.GameSession?.EventManager.ServerRead(inc, connectedClient);
|
||||
break;
|
||||
case ClientPacketHeader.UPDATE_CHARACTERINFO:
|
||||
UpdateCharacterInfo(inc, connectedClient);
|
||||
break;
|
||||
case ClientPacketHeader.ERROR:
|
||||
HandleClientError(inc, connectedClient);
|
||||
break;
|
||||
@@ -1050,9 +1052,11 @@ namespace Barotrauma.Networking
|
||||
if (c.LastRecvCampaignSave > 0)
|
||||
{
|
||||
byte campaignID = inc.ReadByte();
|
||||
c.LastRecvCampaignUpdate = inc.ReadUInt16();
|
||||
foreach (MultiPlayerCampaign.NetFlags netFlag in Enum.GetValues(typeof(MultiPlayerCampaign.NetFlags)))
|
||||
{
|
||||
c.LastRecvCampaignUpdate[netFlag] = inc.ReadUInt16();
|
||||
}
|
||||
bool characterDiscarded = inc.ReadBoolean();
|
||||
|
||||
if (GameMain.GameSession?.GameMode is MultiPlayerCampaign campaign)
|
||||
{
|
||||
if (characterDiscarded) { campaign.DiscardClientCharacterData(c); }
|
||||
@@ -1061,7 +1065,11 @@ namespace Barotrauma.Networking
|
||||
if (campaign.CampaignID != campaignID)
|
||||
{
|
||||
c.LastRecvCampaignSave = (ushort)(campaign.LastSaveID - 1);
|
||||
c.LastRecvCampaignUpdate = (ushort)(campaign.LastUpdateID - 1);
|
||||
foreach (MultiPlayerCampaign.NetFlags netFlag in Enum.GetValues(typeof(MultiPlayerCampaign.NetFlags)))
|
||||
{
|
||||
c.LastRecvCampaignUpdate[netFlag] =
|
||||
(UInt16)(campaign.GetLastUpdateIdForFlag(netFlag) - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1122,9 +1130,11 @@ namespace Barotrauma.Networking
|
||||
if (c.LastRecvCampaignSave > 0)
|
||||
{
|
||||
byte campaignID = inc.ReadByte();
|
||||
c.LastRecvCampaignUpdate = inc.ReadUInt16();
|
||||
foreach (MultiPlayerCampaign.NetFlags netFlag in Enum.GetValues(typeof(MultiPlayerCampaign.NetFlags)))
|
||||
{
|
||||
c.LastRecvCampaignUpdate[netFlag] = inc.ReadUInt16();
|
||||
}
|
||||
bool characterDiscarded = inc.ReadBoolean();
|
||||
|
||||
if (GameMain.GameSession?.GameMode is MultiPlayerCampaign campaign)
|
||||
{
|
||||
if (characterDiscarded) { campaign.DiscardClientCharacterData(c); }
|
||||
@@ -1133,7 +1143,11 @@ namespace Barotrauma.Networking
|
||||
if (campaign.CampaignID != campaignID)
|
||||
{
|
||||
c.LastRecvCampaignSave = (ushort)(campaign.LastSaveID - 1);
|
||||
c.LastRecvCampaignUpdate = (ushort)(campaign.LastUpdateID - 1);
|
||||
foreach (MultiPlayerCampaign.NetFlags netFlag in Enum.GetValues(typeof(MultiPlayerCampaign.NetFlags)))
|
||||
{
|
||||
c.LastRecvCampaignUpdate[netFlag] =
|
||||
(UInt16)(campaign.GetLastUpdateIdForFlag(netFlag) - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1370,7 +1384,7 @@ namespace Barotrauma.Networking
|
||||
if (gameStarted)
|
||||
{
|
||||
Log("Client \"" + GameServer.ClientLogName(sender) + "\" ended the round.", ServerLog.MessageType.ServerMessage);
|
||||
if (mpCampaign != null && Level.IsLoadedOutpost && save)
|
||||
if (mpCampaign != null && Level.IsLoadedFriendlyOutpost && save)
|
||||
{
|
||||
mpCampaign.SavePlayers();
|
||||
GameMain.GameSession.SubmarineInfo = new SubmarineInfo(GameMain.GameSession.Submarine);
|
||||
@@ -1672,8 +1686,7 @@ namespace Barotrauma.Networking
|
||||
outmsg.Write(c.LastSentChatMsgID); //send this to client so they know which chat messages weren't received by the server
|
||||
outmsg.Write(c.LastSentEntityEventID);
|
||||
|
||||
if (GameMain.GameSession?.GameMode is MultiPlayerCampaign campaign && campaign.Preset == GameMain.NetLobbyScreen.SelectedMode &&
|
||||
NetIdUtils.IdMoreRecent(campaign.LastUpdateID, c.LastRecvCampaignUpdate))
|
||||
if (GameMain.GameSession?.GameMode is MultiPlayerCampaign campaign && campaign.Preset == GameMain.NetLobbyScreen.SelectedMode)
|
||||
{
|
||||
outmsg.Write(true);
|
||||
outmsg.WritePadBits();
|
||||
@@ -1899,8 +1912,7 @@ namespace Barotrauma.Networking
|
||||
int campaignBytes = outmsg.LengthBytes;
|
||||
var campaign = GameMain.GameSession?.GameMode as MultiPlayerCampaign;
|
||||
if (outmsg.LengthBytes < MsgConstants.MTU - 500 &&
|
||||
campaign != null && campaign.Preset == GameMain.NetLobbyScreen.SelectedMode &&
|
||||
NetIdUtils.IdMoreRecent(campaign.LastUpdateID, c.LastRecvCampaignUpdate))
|
||||
campaign != null && campaign.Preset == GameMain.NetLobbyScreen.SelectedMode)
|
||||
{
|
||||
outmsg.Write(true);
|
||||
outmsg.WritePadBits();
|
||||
@@ -2049,7 +2061,10 @@ namespace Barotrauma.Networking
|
||||
var campaign = GameMain.GameSession?.GameMode as MultiPlayerCampaign;
|
||||
msg.Write(campaign == null ? (byte)0 : campaign.CampaignID);
|
||||
msg.Write(campaign == null ? (UInt16)0 : campaign.LastSaveID);
|
||||
msg.Write(campaign == null ? (UInt16)0 : campaign.LastUpdateID);
|
||||
foreach (MultiPlayerCampaign.NetFlags flag in Enum.GetValues(typeof(MultiPlayerCampaign.NetFlags)))
|
||||
{
|
||||
msg.Write(campaign == null ? (UInt16)0 : campaign.GetLastUpdateIdForFlag(flag));
|
||||
}
|
||||
|
||||
connectedClients.ForEach(c => c.ReadyToStart = false);
|
||||
|
||||
@@ -2077,7 +2092,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
|
||||
startGameCoroutine = GameMain.Instance.ShowLoading(StartGame(selectedSub, selectedShuttle, selectedMode, CampaignSettings.Unsure), false);
|
||||
startGameCoroutine = GameMain.Instance.ShowLoading(StartGame(selectedSub, selectedShuttle, selectedMode, CampaignSettings.Empty), false);
|
||||
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
@@ -2195,7 +2210,7 @@ namespace Barotrauma.Networking
|
||||
Level.Loaded?.SpawnNPCs();
|
||||
Level.Loaded?.SpawnCorpses();
|
||||
Level.Loaded?.PrepareBeaconStation();
|
||||
AutoItemPlacer.SpawnItems();
|
||||
AutoItemPlacer.SpawnItems(campaign?.Settings.StartItemSet);
|
||||
|
||||
CrewManager crewManager = campaign?.CrewManager;
|
||||
|
||||
@@ -3203,18 +3218,27 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (checkActiveVote && Voting.ActiveVote != null)
|
||||
{
|
||||
int yes = GameMain.Server.ConnectedClients.Count(c => c.InGame && c.GetVote<int>(Voting.ActiveVote.VoteType) == 2);
|
||||
int no = GameMain.Server.ConnectedClients.Count(c => c.InGame && c.GetVote<int>(Voting.ActiveVote.VoteType) == 1);
|
||||
int max = GameMain.Server.ConnectedClients.Count(c => c.InGame);
|
||||
// Required ratio cannot be met
|
||||
if (no / (float)max > 1f - serverSettings.VoteRequiredRatio)
|
||||
{
|
||||
Voting.ActiveVote.Finish(Voting, passed: false);
|
||||
}
|
||||
else if (yes / (float)max >= serverSettings.VoteRequiredRatio)
|
||||
var inGameClients = GameMain.Server.ConnectedClients.Where(c => c.InGame);
|
||||
if (inGameClients.Count() == 1)
|
||||
{
|
||||
Voting.ActiveVote.Finish(Voting, passed: true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var eligibleClients = inGameClients.Where(c => c != Voting.ActiveVote.VoteStarter);
|
||||
int yes = eligibleClients.Count(c => c.GetVote<int>(Voting.ActiveVote.VoteType) == 2);
|
||||
int no = eligibleClients.Count(c => c.GetVote<int>(Voting.ActiveVote.VoteType) == 1);
|
||||
int max = eligibleClients.Count();
|
||||
// Required ratio cannot be met
|
||||
if (no / (float)max > 1f - serverSettings.VoteRequiredRatio)
|
||||
{
|
||||
Voting.ActiveVote.Finish(Voting, passed: false);
|
||||
}
|
||||
else if (yes / (float)max >= serverSettings.VoteRequiredRatio)
|
||||
{
|
||||
Voting.ActiveVote.Finish(Voting, passed: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Client.UpdateKickVotes(connectedClients);
|
||||
@@ -3295,7 +3319,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (voteType != VoteType.PurchaseSub)
|
||||
{
|
||||
GameMain.GameSession.SwitchSubmarine(targetSubmarine, deliveryFee, starter);
|
||||
GameMain.GameSession.SwitchSubmarine(targetSubmarine, subVote.TransferItems, deliveryFee, starter);
|
||||
}
|
||||
|
||||
Voting.StopSubmarineVote(true);
|
||||
|
||||
+15
-8
@@ -16,14 +16,21 @@ namespace Barotrauma.Networking
|
||||
private set;
|
||||
}
|
||||
|
||||
public SteamP2PServerPeer(UInt64 steamId, ServerSettings settings)
|
||||
private UInt64 ownerKey64 => unchecked((UInt64)ownerKey.Value);
|
||||
|
||||
private UInt64 ReadSteamId(IReadMessage inc)
|
||||
=> inc.ReadUInt64() ^ ownerKey64;
|
||||
private void WriteSteamId(IWriteMessage msg, UInt64 val)
|
||||
=> msg.Write(val ^ ownerKey64);
|
||||
|
||||
public SteamP2PServerPeer(UInt64 steamId, int ownerKey, ServerSettings settings)
|
||||
{
|
||||
serverSettings = settings;
|
||||
|
||||
connectedClients = new List<NetworkConnection>();
|
||||
pendingClients = new List<PendingClient>();
|
||||
|
||||
ownerKey = null;
|
||||
this.ownerKey = ownerKey;
|
||||
|
||||
OwnerSteamID = steamId;
|
||||
|
||||
@@ -33,7 +40,7 @@ namespace Barotrauma.Networking
|
||||
public override void Start()
|
||||
{
|
||||
IWriteMessage outMsg = new WriteOnlyMessage();
|
||||
outMsg.Write(OwnerSteamID);
|
||||
WriteSteamId(outMsg, OwnerSteamID);
|
||||
outMsg.Write((byte)DeliveryMethod.Reliable);
|
||||
outMsg.Write((byte)(PacketHeader.IsConnectionInitializationStep | PacketHeader.IsServerMessage));
|
||||
|
||||
@@ -122,8 +129,8 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (!started) { return; }
|
||||
|
||||
UInt64 senderSteamId = inc.ReadUInt64();
|
||||
UInt64 ownerSteamId = inc.ReadUInt64();
|
||||
UInt64 senderSteamId = ReadSteamId(inc);
|
||||
UInt64 ownerSteamId = ReadSteamId(inc);
|
||||
|
||||
PacketHeader packetHeader = (PacketHeader)inc.ReadByte();
|
||||
|
||||
@@ -264,7 +271,7 @@ namespace Barotrauma.Networking
|
||||
IWriteMessage msgToSend = new WriteOnlyMessage();
|
||||
byte[] msgData = new byte[16];
|
||||
msg.PrepareForSending(ref msgData, compressPastThreshold, out bool isCompressed, out int length);
|
||||
msgToSend.Write(conn.SteamID);
|
||||
WriteSteamId(msgToSend, conn.SteamID);
|
||||
msgToSend.Write((byte)deliveryMethod);
|
||||
msgToSend.Write((byte)((isCompressed ? PacketHeader.IsCompressed : PacketHeader.None) | PacketHeader.IsServerMessage));
|
||||
msgToSend.Write((UInt16)length);
|
||||
@@ -281,7 +288,7 @@ namespace Barotrauma.Networking
|
||||
if (string.IsNullOrWhiteSpace(msg)) { return; }
|
||||
|
||||
IWriteMessage msgToSend = new WriteOnlyMessage();
|
||||
msgToSend.Write(steamId);
|
||||
WriteSteamId(msgToSend, steamId);
|
||||
msgToSend.Write((byte)DeliveryMethod.Reliable);
|
||||
msgToSend.Write((byte)(PacketHeader.IsDisconnectMessage | PacketHeader.IsServerMessage));
|
||||
msgToSend.Write(msg);
|
||||
@@ -318,7 +325,7 @@ namespace Barotrauma.Networking
|
||||
protected override void SendMsgInternal(NetworkConnection conn, DeliveryMethod deliveryMethod, IWriteMessage msg)
|
||||
{
|
||||
IWriteMessage msgToSend = new WriteOnlyMessage();
|
||||
msgToSend.Write(conn.SteamID);
|
||||
WriteSteamId(msgToSend, conn.SteamID);
|
||||
msgToSend.Write((byte)deliveryMethod);
|
||||
msgToSend.Write(msg.Buffer, 0, msg.LengthBytes);
|
||||
byte[] bufToSend = (byte[])msgToSend.Buffer.Clone();
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
using Barotrauma.IO;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Barotrauma.Extensions;
|
||||
using Barotrauma.IO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Barotrauma.Extensions;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
@@ -36,7 +34,7 @@ namespace Barotrauma.Networking
|
||||
=> LastUpdateIdForFlag[flag] = (UInt16)(GameMain.NetLobbyScreen.LastUpdateID + 1);
|
||||
|
||||
private bool IsFlagRequired(Client c, NetFlags flag)
|
||||
=> LastUpdateIdForFlag[flag] > c.LastRecvLobbyUpdate;
|
||||
=> NetIdUtils.IdMoreRecent(LastUpdateIdForFlag[flag], c.LastRecvLobbyUpdate);
|
||||
|
||||
public NetFlags GetRequiredFlags(Client c)
|
||||
=> LastUpdateIdForFlag.Keys
|
||||
@@ -56,7 +54,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
var property = netProperties[key];
|
||||
property.SyncValue();
|
||||
if (property.LastUpdateID > c.LastRecvLobbyUpdate)
|
||||
if (NetIdUtils.IdMoreRecent(property.LastUpdateID, c.LastRecvLobbyUpdate))
|
||||
{
|
||||
outMsg.Write(key);
|
||||
netProperties[key].Write(outMsg);
|
||||
@@ -257,7 +255,7 @@ namespace Barotrauma.Networking
|
||||
doc.Root.SetAttributeValue("queryport", QueryPort);
|
||||
#endif
|
||||
doc.Root.SetAttributeValue("password", password ?? "");
|
||||
|
||||
|
||||
doc.Root.SetAttributeValue("enableupnp", EnableUPnP);
|
||||
doc.Root.SetAttributeValue("autorestart", autoRestart);
|
||||
|
||||
@@ -266,11 +264,12 @@ namespace Barotrauma.Networking
|
||||
doc.Root.SetAttributeValue("ServerMessage", ServerMessageText);
|
||||
|
||||
doc.Root.SetAttributeValue("HiddenSubs", string.Join(",", HiddenSubs));
|
||||
|
||||
|
||||
doc.Root.SetAttributeValue("AllowedRandomMissionTypes", string.Join(",", AllowedRandomMissionTypes));
|
||||
doc.Root.SetAttributeValue("AllowedClientNameChars", string.Join(",", AllowedClientNameChars.Select(c => $"{c.Start}-{c.End}")));
|
||||
|
||||
SerializableProperty.SerializeProperties(this, doc.Root, true);
|
||||
doc.Root.Add(CampaignSettings.Save());
|
||||
|
||||
System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings
|
||||
{
|
||||
@@ -399,7 +398,7 @@ namespace Barotrauma.Networking
|
||||
ServerName = doc.Root.GetAttributeString("name", "");
|
||||
if (ServerName.Length > NetConfig.ServerNameMaxLength) { ServerName = ServerName.Substring(0, NetConfig.ServerNameMaxLength); }
|
||||
ServerMessageText = doc.Root.GetAttributeString("ServerMessage", "");
|
||||
|
||||
|
||||
GameMain.NetLobbyScreen.SelectedModeIdentifier = GameModeIdentifier;
|
||||
//handle Random as the mission type, which is no longer a valid setting
|
||||
//MissionType.All offers equivalent functionality
|
||||
@@ -410,6 +409,14 @@ namespace Barotrauma.Networking
|
||||
GameMain.NetLobbyScreen.SetBotCount(BotCount);
|
||||
|
||||
MonsterEnabled ??= CharacterPrefab.Prefabs.Select(p => (p.Identifier, true)).ToDictionary();
|
||||
|
||||
foreach (XElement element in doc.Root.Elements())
|
||||
{
|
||||
if (element.Name.ToIdentifier() == nameof(Barotrauma.CampaignSettings))
|
||||
{
|
||||
CampaignSettings = new CampaignSettings(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string SelectNonHiddenSubmarine(string current = null)
|
||||
|
||||
@@ -27,11 +27,13 @@ namespace Barotrauma
|
||||
public VoteState State { get; set; }
|
||||
|
||||
public SubmarineInfo Sub;
|
||||
public bool TransferItems;
|
||||
public int DeliveryFee;
|
||||
|
||||
public SubmarineVote(Client starter, SubmarineInfo subInfo, int deliveryFee, VoteType voteType)
|
||||
public SubmarineVote(Client starter, SubmarineInfo subInfo, bool transferItems, int deliveryFee, VoteType voteType)
|
||||
{
|
||||
Sub = subInfo;
|
||||
TransferItems = transferItems;
|
||||
DeliveryFee = deliveryFee;
|
||||
VoteType = voteType;
|
||||
State = VoteState.Started;
|
||||
@@ -101,15 +103,12 @@ namespace Barotrauma
|
||||
|
||||
private readonly Dictionary<Client, (VoteType voteType, DateTime time)> rejectedVoteTimes = new Dictionary<Client, (VoteType voteType, DateTime time)>();
|
||||
|
||||
private void StartSubmarineVote(SubmarineInfo subInfo, VoteType voteType, Client sender)
|
||||
private void StartSubmarineVote(SubmarineInfo subInfo, bool transferItems, VoteType voteType, Client sender)
|
||||
{
|
||||
if (ActiveVote == null)
|
||||
{
|
||||
sender.SetVote(voteType, 2);
|
||||
}
|
||||
var subVote = new SubmarineVote(
|
||||
sender,
|
||||
subInfo,
|
||||
transferItems,
|
||||
voteType == VoteType.SwitchSub ? GameMain.GameSession.Map.DistanceToClosestLocationWithOutpost(GameMain.GameSession.Map.CurrentLocation, out Location endLocation) : 0,
|
||||
voteType);
|
||||
StartOrEnqueueVote(subVote);
|
||||
@@ -152,10 +151,6 @@ namespace Barotrauma
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (ActiveVote == null)
|
||||
{
|
||||
starter.SetVote(VoteType.TransferMoney, 2);
|
||||
}
|
||||
StartOrEnqueueVote(new TransferVote(starter, from, transferAmount, to));
|
||||
GameMain.Server.UpdateVoteStatus(checkActiveVote: false);
|
||||
}
|
||||
@@ -205,11 +200,19 @@ namespace Barotrauma
|
||||
|
||||
if (ActiveVote.Timer >= GameMain.NetworkMember.ServerSettings.VoteTimeout)
|
||||
{
|
||||
var inGameClients = GameMain.Server.ConnectedClients.Where(c => c.InGame);
|
||||
var eligibleClients = inGameClients.Where(c => c != ActiveVote.VoteStarter);
|
||||
|
||||
// Do not take unanswered into account for total
|
||||
int yes = GameMain.Server.ConnectedClients.Count(c => c.InGame && c.GetVote<int>(ActiveVote.VoteType) == 2);
|
||||
int no = GameMain.Server.ConnectedClients.Count(c => c.InGame && c.GetVote<int>(ActiveVote.VoteType) == 1);
|
||||
int yes = eligibleClients.Count(c => c.GetVote<int>(ActiveVote.VoteType) == 2);
|
||||
int no = eligibleClients.Count(c => c.GetVote<int>(ActiveVote.VoteType) == 1);
|
||||
int total = Math.Max(yes + no, 1);
|
||||
ActiveVote.Finish(this, passed: yes / (float)(total) >= GameMain.NetworkMember.ServerSettings.VoteRequiredRatio);
|
||||
|
||||
bool passed =
|
||||
yes / (float)total >= GameMain.NetworkMember.ServerSettings.VoteRequiredRatio ||
|
||||
inGameClients.Count() == 1;
|
||||
|
||||
ActiveVote.Finish(this, passed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,12 +296,13 @@ namespace Barotrauma
|
||||
{
|
||||
string subName = inc.ReadString();
|
||||
SubmarineInfo subInfo = SubmarineInfo.SavedSubmarines.FirstOrDefault(s => s.Name == subName);
|
||||
bool transferItems = inc.ReadBoolean();
|
||||
if (!ShouldRejectVote(sender, voteType))
|
||||
{
|
||||
if (GameMain.GameSession?.Campaign is MultiPlayerCampaign campaign &&
|
||||
(campaign.CanPurchaseSub(subInfo, sender) || GameMain.GameSession.IsSubmarineOwned(subInfo)))
|
||||
{
|
||||
StartSubmarineVote(subInfo, voteType, sender);
|
||||
StartSubmarineVote(subInfo, transferItems, voteType, sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -355,22 +359,24 @@ namespace Barotrauma
|
||||
{
|
||||
msg.Write((byte)ActiveVote.VoteType);
|
||||
if (ActiveVote.State != VoteState.None && ActiveVote.VoteType != VoteType.Unknown)
|
||||
{
|
||||
var yesClients = GameMain.Server.ConnectedClients.FindAll(c => c.InGame && c.GetVote<int>(ActiveVote.VoteType) == 2);
|
||||
msg.Write((byte)yesClients.Count);
|
||||
{
|
||||
var eligibleClients = GameMain.Server.ConnectedClients.Where(c => c.InGame && c != ActiveVote.VoteStarter);
|
||||
|
||||
var yesClients = eligibleClients.Where(c => c.GetVote<int>(ActiveVote.VoteType) == 2);
|
||||
msg.Write((byte)yesClients.Count());
|
||||
foreach (Client c in yesClients)
|
||||
{
|
||||
msg.Write(c.ID);
|
||||
}
|
||||
|
||||
var noClients = GameMain.Server.ConnectedClients.FindAll(c => c.InGame && c.GetVote<int>(ActiveVote.VoteType) == 1);
|
||||
msg.Write((byte)noClients.Count);
|
||||
var noClients = eligibleClients.Where(c => c.GetVote<int>(ActiveVote.VoteType) == 1);
|
||||
msg.Write((byte)noClients.Count());
|
||||
foreach (Client c in noClients)
|
||||
{
|
||||
msg.Write(c.ID);
|
||||
}
|
||||
|
||||
msg.Write((byte)GameMain.Server.ConnectedClients.Count(c => c.InGame));
|
||||
msg.Write((byte)eligibleClients.Count());
|
||||
|
||||
switch (ActiveVote.State)
|
||||
{
|
||||
@@ -384,6 +390,7 @@ namespace Barotrauma
|
||||
case VoteType.PurchaseAndSwitchSub:
|
||||
case VoteType.SwitchSub:
|
||||
msg.Write((ActiveVote as SubmarineVote).Sub.Name);
|
||||
msg.Write((ActiveVote as SubmarineVote).TransferItems);
|
||||
break;
|
||||
case VoteType.TransferMoney:
|
||||
var transferVote = (ActiveVote as TransferVote);
|
||||
@@ -405,8 +412,10 @@ namespace Barotrauma
|
||||
case VoteType.PurchaseSub:
|
||||
case VoteType.PurchaseAndSwitchSub:
|
||||
case VoteType.SwitchSub:
|
||||
msg.Write((ActiveVote as SubmarineVote).Sub.Name);
|
||||
msg.Write((short)(ActiveVote as SubmarineVote).DeliveryFee);
|
||||
var subVote = ActiveVote as SubmarineVote;
|
||||
msg.Write(subVote.Sub.Name);
|
||||
msg.Write(subVote.TransferItems);
|
||||
msg.Write((short)subVote.DeliveryFee);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user