v0.12.0.2
This commit is contained in:
@@ -10,6 +10,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
public string Name;
|
||||
public string PreferredJob;
|
||||
public CharacterTeamType PreferredTeam;
|
||||
public UInt16 NameID;
|
||||
public UInt64 SteamID;
|
||||
public byte ID;
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
private byte myID;
|
||||
|
||||
private List<Client> otherClients;
|
||||
private readonly List<Client> otherClients;
|
||||
|
||||
public readonly List<SubmarineInfo> ServerSubmarines = new List<SubmarineInfo>();
|
||||
|
||||
@@ -94,13 +94,13 @@ namespace Barotrauma.Networking
|
||||
|
||||
private UInt16 lastSentChatMsgID = 0; //last message this client has successfully sent
|
||||
private UInt16 lastQueueChatMsgID = 0; //last message added to the queue
|
||||
private List<ChatMessage> chatMsgQueue = new List<ChatMessage>();
|
||||
private readonly List<ChatMessage> chatMsgQueue = new List<ChatMessage>();
|
||||
|
||||
public UInt16 LastSentEntityEventID;
|
||||
|
||||
private ClientEntityEventManager entityEventManager;
|
||||
private readonly ClientEntityEventManager entityEventManager;
|
||||
|
||||
private FileReceiver fileReceiver;
|
||||
private readonly FileReceiver fileReceiver;
|
||||
|
||||
#if DEBUG
|
||||
public void PrintReceiverTransters()
|
||||
@@ -138,6 +138,12 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
|
||||
private readonly List<Client> previouslyConnectedClients = new List<Client>();
|
||||
public IEnumerable<Client> PreviouslyConnectedClients
|
||||
{
|
||||
get { return previouslyConnectedClients; }
|
||||
}
|
||||
|
||||
public FileReceiver FileReceiver
|
||||
{
|
||||
get { return fileReceiver; }
|
||||
@@ -153,9 +159,9 @@ namespace Barotrauma.Networking
|
||||
get { return entityEventManager; }
|
||||
}
|
||||
|
||||
private object serverEndpoint;
|
||||
private int ownerKey;
|
||||
private bool steamP2POwner;
|
||||
private readonly object serverEndpoint;
|
||||
private readonly int ownerKey;
|
||||
private readonly bool steamP2POwner;
|
||||
|
||||
public bool IsServerOwner
|
||||
{
|
||||
@@ -852,7 +858,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
endMessage = inc.ReadString();
|
||||
bool missionSuccessful = inc.ReadBoolean();
|
||||
Character.TeamType winningTeam = (Character.TeamType)inc.ReadByte();
|
||||
CharacterTeamType winningTeam = (CharacterTeamType)inc.ReadByte();
|
||||
if (missionSuccessful && GameMain.GameSession?.Mission != null)
|
||||
{
|
||||
GameMain.GameSession.WinningTeam = winningTeam;
|
||||
@@ -1634,7 +1640,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (Submarine.MainSubs[i] == null) { break; }
|
||||
|
||||
var teamID = i == 0 ? Character.TeamType.Team1 : Character.TeamType.Team2;
|
||||
var teamID = i == 0 ? CharacterTeamType.Team1 : CharacterTeamType.Team2;
|
||||
Submarine.MainSubs[i].TeamID = teamID;
|
||||
foreach (Item item in Item.ItemList)
|
||||
{
|
||||
@@ -1828,6 +1834,7 @@ namespace Barotrauma.Networking
|
||||
UInt16 nameId = inc.ReadUInt16();
|
||||
string name = inc.ReadString();
|
||||
string preferredJob = inc.ReadString();
|
||||
byte preferredTeam = inc.ReadByte();
|
||||
UInt16 characterID = inc.ReadUInt16();
|
||||
float karma = inc.ReadSingle();
|
||||
bool muted = inc.ReadBoolean();
|
||||
@@ -1844,6 +1851,7 @@ namespace Barotrauma.Networking
|
||||
SteamID = steamId,
|
||||
Name = name,
|
||||
PreferredJob = preferredJob,
|
||||
PreferredTeam = (CharacterTeamType)preferredTeam,
|
||||
CharacterID = characterID,
|
||||
Karma = karma,
|
||||
Muted = muted,
|
||||
@@ -1878,6 +1886,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
existingClient.NameID = tc.NameID;
|
||||
existingClient.PreferredJob = tc.PreferredJob;
|
||||
existingClient.PreferredTeam = tc.PreferredTeam;
|
||||
existingClient.Character = null;
|
||||
existingClient.Karma = tc.Karma;
|
||||
existingClient.Muted = tc.Muted;
|
||||
@@ -1917,6 +1926,17 @@ namespace Barotrauma.Networking
|
||||
refreshCampaignUI = true;
|
||||
}
|
||||
}
|
||||
foreach (Client client in ConnectedClients)
|
||||
{
|
||||
if (!previouslyConnectedClients.Any(c => c.ID == client.ID))
|
||||
{
|
||||
while (previouslyConnectedClients.Count > 100)
|
||||
{
|
||||
previouslyConnectedClients.RemoveAt(0);
|
||||
}
|
||||
previouslyConnectedClients.Add(client);
|
||||
}
|
||||
}
|
||||
if (updateClientListId) { LastClientListUpdateID = listId; }
|
||||
|
||||
if (clientPeer is SteamP2POwnerPeer)
|
||||
@@ -2142,6 +2162,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
break;
|
||||
case ServerNetObject.ENTITY_POSITION:
|
||||
bool isItem = inc.ReadBoolean();
|
||||
UInt16 id = inc.ReadUInt16();
|
||||
uint msgLength = inc.ReadVariableUInt32();
|
||||
int msgEndPos = (int)(inc.BitPosition + msgLength * 8);
|
||||
@@ -2156,8 +2177,15 @@ namespace Barotrauma.Networking
|
||||
entities.Add(entity);
|
||||
if (entity != null && (entity is Item || entity is Character || entity is Submarine))
|
||||
{
|
||||
entity.ClientRead(objHeader.Value, inc, sendingTime);
|
||||
}
|
||||
if (entity is Item != isItem)
|
||||
{
|
||||
DebugConsole.AddWarning($"Received a potentially invalid ENTITY_POSITION message. Entity type does not match (server entity is {(isItem ? "an item" : "not an item")}, client entity is {(entity?.GetType().ToString() ?? "null")}). Ignoring the message...");
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.ClientRead(objHeader.Value, inc, sendingTime);
|
||||
}
|
||||
}
|
||||
|
||||
//force to the correct position in case the entity doesn't exist
|
||||
//or the message wasn't read correctly for whatever reason
|
||||
@@ -2230,9 +2258,9 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
GameAnalyticsManager.AddErrorEventOnce("GameClient.ReadInGameUpdate", GameAnalyticsSDK.Net.EGAErrorSeverity.Critical, string.Join("\n", errorLines));
|
||||
|
||||
DebugConsole.ThrowError("Writing object data to \"crashreport_object.log\", please send this file to us at http://github.com/Regalis11/Barotrauma/issues");
|
||||
DebugConsole.ThrowError("Writing object data to \"networkerror_data.log\", please send this file to us at http://github.com/Regalis11/Barotrauma/issues");
|
||||
|
||||
using (FileStream fl = File.Open("crashreport_object.log", System.IO.FileMode.Create))
|
||||
using (FileStream fl = File.Open("networkerror_data.log", System.IO.FileMode.Create))
|
||||
{
|
||||
using (System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fl))
|
||||
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(fl))
|
||||
@@ -2245,7 +2273,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Exception("Read error: please send us \"crashreport_object.bin\"!");
|
||||
throw new Exception("Read error: please send us \"networkerror_data.log\"!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2269,6 +2297,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
outmsg.Write("");
|
||||
}
|
||||
outmsg.Write((byte)GameMain.Config.TeamPreference);
|
||||
|
||||
if (!(GameMain.GameSession?.GameMode is MultiPlayerCampaign campaign) || campaign.LastSaveID == 0)
|
||||
{
|
||||
@@ -3241,12 +3270,12 @@ namespace Barotrauma.Networking
|
||||
|
||||
public virtual bool SelectCrewCharacter(Character character, GUIComponent frame)
|
||||
{
|
||||
if (character == null) return false;
|
||||
if (character == null) { return false; }
|
||||
|
||||
if (character != myCharacter)
|
||||
{
|
||||
var client = GameMain.NetworkMember.ConnectedClients.Find(c => c.Character == character);
|
||||
if (client == null) return false;
|
||||
var client = previouslyConnectedClients.Find(c => c.Character == character);
|
||||
if (client == null) { return false; }
|
||||
|
||||
CreateSelectionRelatedButtons(client, frame);
|
||||
}
|
||||
@@ -3256,7 +3285,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
public virtual bool SelectCrewClient(Client client, GUIComponent frame)
|
||||
{
|
||||
if (client == null || client.ID == ID) return false;
|
||||
if (client == null || client.ID == ID) { return false; }
|
||||
CreateSelectionRelatedButtons(client, frame);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ namespace Barotrauma
|
||||
CreateLabeledSlider(parent, 0.0f, 1.0f, 0.01f, nameof(DamageEnemyKarmaIncrease));
|
||||
CreateLabeledSlider(parent, 0.0f, 1.0f, 0.01f, nameof(ItemRepairKarmaIncrease));
|
||||
CreateLabeledSlider(parent, 0.0f, 10.0f, 0.05f, nameof(ExtinguishFireKarmaIncrease));
|
||||
CreateLabeledSlider(parent, 0.0f, 1.0f, 0.01f, nameof(BallastFloraKarmaIncrease));
|
||||
|
||||
new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.12f), parent.RectTransform), TextManager.Get("Karma.NegativeActions"),
|
||||
textAlignment: Alignment.Center, font: GUI.SubHeadingFont)
|
||||
@@ -61,7 +62,6 @@ namespace Barotrauma
|
||||
CreateLabeledNumberInput(parent, 0, 20, nameof(AllowedWireDisconnectionsPerMinute));
|
||||
CreateLabeledSlider(parent, 0.0f, 20.0f, 0.5f, nameof(WireDisconnectionKarmaDecrease));
|
||||
CreateLabeledSlider(parent, 0.0f, 30.0f, 1.0f, nameof(SpamFilterKarmaDecrease));
|
||||
CreateLabeledSlider(parent, 0.0f, 1.0f, 0.01f, nameof(BallastFloraKarmaIncrease));
|
||||
|
||||
//hide these for now if a localized text is not available
|
||||
if (TextManager.ContainsTag("Karma." + nameof(DangerousItemStealKarmaDecrease)))
|
||||
|
||||
+3
-3
@@ -226,7 +226,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
else
|
||||
{
|
||||
long msgPosition = msg.BitPosition;
|
||||
int msgPosition = msg.BitPosition;
|
||||
if (GameSettings.VerboseLogging)
|
||||
{
|
||||
DebugConsole.NewMessage("received msg " + thisEventID + " (" + entity.ToString() + ")",
|
||||
@@ -242,9 +242,9 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
string errorMsg = "Message byte position incorrect after reading an event for the entity \"" + entity.ToString()
|
||||
+ "\". Read " + (msg.BitPosition - msgPosition) + " bits, expected message length was " + (msgLength * 8) + " bits.";
|
||||
#if DEBUG
|
||||
|
||||
DebugConsole.ThrowError(errorMsg);
|
||||
#endif
|
||||
|
||||
GameAnalyticsManager.AddErrorEventOnce("ClientEntityEventManager.Read:BitPosMismatch", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
|
||||
|
||||
//TODO: force the BitPosition to correct place? Having some entity in a potentially incorrect state is not as bad as a desync kick
|
||||
|
||||
@@ -168,7 +168,19 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
Close(disableReconnect: true);
|
||||
|
||||
string missingModNames = "\n- " + string.Join("\n\n- ", missingPackages.Select(p => GetPackageStr(p))) + "\n\n";
|
||||
string missingModNames = "\n";
|
||||
int displayedModCount = 0;
|
||||
foreach (ServerContentPackage missingPackage in missingPackages)
|
||||
{
|
||||
missingModNames += "\n- " + GetPackageStr(missingPackage);
|
||||
displayedModCount++;
|
||||
if (GUI.Font.MeasureString(missingModNames).Y > GameMain.GraphicsHeight * 0.5f)
|
||||
{
|
||||
missingModNames += "\n\n" + TextManager.GetWithVariable("workshopitemdownloadprompttruncated", "[number]", (missingPackages.Count - displayedModCount).ToString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
missingModNames += "\n\n";
|
||||
|
||||
var msgBox = new GUIMessageBox(
|
||||
TextManager.Get("WorkshopItemDownloadTitle"),
|
||||
@@ -189,6 +201,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (!contentPackageOrderReceived)
|
||||
{
|
||||
GameMain.Config.BackUpModOrder();
|
||||
GameMain.Config.SwapPackages(corePackage.CorePackage, regularPackages.Select(p => p.RegularPackage).ToList());
|
||||
contentPackageOrderReceived = true;
|
||||
}
|
||||
|
||||
@@ -195,10 +195,11 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
foreach (var data in line.RichData)
|
||||
{
|
||||
UInt64 id = 0;
|
||||
if (!UInt64.TryParse(data.Metadata, out id)) { return; }
|
||||
Client client = GameMain.Client.ConnectedClients.Find(c => c.SteamID == id);
|
||||
client ??= GameMain.Client.ConnectedClients.Find(c => c.ID == id);
|
||||
if (!UInt64.TryParse(data.Metadata, out ulong id)) { return; }
|
||||
Client client = GameMain.Client.ConnectedClients.Find(c => c.SteamID == id)
|
||||
?? GameMain.Client.ConnectedClients.Find(c => c.ID == id)
|
||||
?? GameMain.Client.PreviouslyConnectedClients.FirstOrDefault(c => c.SteamID == id)
|
||||
?? GameMain.Client.PreviouslyConnectedClients.FirstOrDefault(c => c.ID == id);
|
||||
if (client != null && client.Karma < 40.0f)
|
||||
{
|
||||
textContainer = new GUIFrame(new RectTransform(new Vector2(1.0f, 0.0f), listBox.Content.RectTransform),
|
||||
@@ -243,10 +244,11 @@ namespace Barotrauma.Networking
|
||||
Data = data,
|
||||
OnClick = (component, area) =>
|
||||
{
|
||||
UInt64 id = 0;
|
||||
if (!UInt64.TryParse(area.Data.Metadata, out id)) { return; }
|
||||
Client client = GameMain.Client.ConnectedClients.Find(c => c.SteamID == id);
|
||||
client ??= GameMain.Client.ConnectedClients.Find(c => c.ID == id);
|
||||
if (!UInt64.TryParse(area.Data.Metadata, out UInt64 id)) { return; }
|
||||
Client client = GameMain.Client.ConnectedClients.Find(c => c.SteamID == id)
|
||||
?? GameMain.Client.ConnectedClients.Find(c => c.ID == id)
|
||||
?? GameMain.Client.PreviouslyConnectedClients.FirstOrDefault(c => c.SteamID == id)
|
||||
?? GameMain.Client.PreviouslyConnectedClients.FirstOrDefault(c => c.ID == id);
|
||||
if (client == null) { return; }
|
||||
GameMain.NetLobbyScreen.SelectPlayer(client);
|
||||
}
|
||||
|
||||
@@ -269,14 +269,13 @@ namespace Barotrauma.Steam
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: find a better strategy to fetch all lobbies, this is gonna take forever if we actually have 10000 lobbies
|
||||
Steamworks.Data.LobbyQuery lobbyQuery = Steamworks.SteamMatchmaking.CreateLobbyQuery().FilterDistanceWorldwide().WithMaxResults(10000);
|
||||
|
||||
Steamworks.Dispatch.OnDebugCallback = (callbackType, contents, isServer) =>
|
||||
{
|
||||
DebugConsole.NewMessage($"{callbackType}: " + contents, Color.Yellow);
|
||||
};
|
||||
TaskPool.Add("LobbyQueryRequest", lobbyQuery.RequestAsync(),
|
||||
|
||||
TaskPool.Add("LobbyQueryRequest", LobbyQueryRequest(),
|
||||
(t) =>
|
||||
{
|
||||
Steamworks.Dispatch.OnDebugCallback = null;
|
||||
@@ -286,7 +285,7 @@ namespace Barotrauma.Steam
|
||||
taskDone();
|
||||
return;
|
||||
}
|
||||
var lobbies = ((Task<Steamworks.Data.Lobby[]>)t).Result;
|
||||
var lobbies = ((Task<List<Steamworks.Data.Lobby>>)t).Result;
|
||||
if (lobbies != null)
|
||||
{
|
||||
foreach (var lobby in lobbies)
|
||||
@@ -373,6 +372,32 @@ namespace Barotrauma.Steam
|
||||
return true;
|
||||
}
|
||||
|
||||
public static async Task<List<Steamworks.Data.Lobby>> LobbyQueryRequest()
|
||||
{
|
||||
List<Steamworks.Data.Lobby> allLobbies = new List<Steamworks.Data.Lobby>();
|
||||
Steamworks.Data.LobbyQuery lobbyQuery = Steamworks.SteamMatchmaking.CreateLobbyQuery()
|
||||
.FilterDistanceWorldwide()
|
||||
.WithMaxResults(50);
|
||||
//steamworks seems to unable to retrieve more than 50
|
||||
//lobbies per request; to work around this, we'll make
|
||||
//up to 10 requests, asking to ignore all previous results
|
||||
//in each subsequent request
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
Steamworks.Data.Lobby[] lobbies = await lobbyQuery.RequestAsync();
|
||||
if (lobbies == null) { break; }
|
||||
foreach (var l in lobbies)
|
||||
{
|
||||
lobbyQuery = lobbyQuery
|
||||
.WithoutKeyValue("lobbyowner", l.GetData("lobbyowner"));
|
||||
}
|
||||
allLobbies.AddRange(lobbies);
|
||||
}
|
||||
|
||||
//make sure all returned lobbies are distinct, don't want any duplicates here
|
||||
return allLobbies.Select(l => l.Id).Distinct().Select(i => allLobbies.Find(l => l.Id == i)).ToList();
|
||||
}
|
||||
|
||||
public static void AssignLobbyDataToServerInfo(Steamworks.Data.Lobby lobby, ServerInfo serverInfo)
|
||||
{
|
||||
serverInfo.OwnerVerified = true;
|
||||
@@ -1173,7 +1198,7 @@ namespace Barotrauma.Steam
|
||||
|
||||
foreach (ContentFile contentFile in contentPackage.Files)
|
||||
{
|
||||
contentFile.Path = contentFile.Path.CleanUpPath();
|
||||
contentFile.Path = contentFile.Path.CleanUpPathCrossPlatform(correctFilenameCase: true, item?.Directory);
|
||||
string sourceFile = Path.Combine(item?.Directory, contentFile.Path);
|
||||
if (!File.Exists(sourceFile))
|
||||
{
|
||||
|
||||
@@ -239,7 +239,7 @@ namespace Barotrauma.Networking
|
||||
bool allowEnqueue = false;
|
||||
if (GameMain.WindowActive)
|
||||
{
|
||||
ForceLocal = captureTimer > 0 ? ForceLocal : false;
|
||||
ForceLocal = captureTimer > 0 ? ForceLocal : GameMain.Config.UseLocalVoiceByDefault;
|
||||
bool pttDown = false;
|
||||
if ((PlayerInput.KeyDown(InputType.Voice) || PlayerInput.KeyDown(InputType.LocalVoice)) &&
|
||||
GUI.KeyboardDispatcher.Subscriber == null)
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace Barotrauma.Networking
|
||||
var messageType = !client.VoipQueue.ForceLocal && ChatMessage.CanUseRadio(client.Character, out radio) ? ChatMessageType.Radio : ChatMessageType.Default;
|
||||
client.Character.ShowSpeechBubble(1.25f, ChatMessage.MessageColor[(int)messageType]);
|
||||
|
||||
client.VoipSound.UseRadioFilter = messageType == ChatMessageType.Radio;
|
||||
client.VoipSound.UseRadioFilter = messageType == ChatMessageType.Radio && !GameMain.Config.DisableVoiceChatFilters;
|
||||
if (client.VoipSound.UseRadioFilter)
|
||||
{
|
||||
client.VoipSound.SetRange(radio.Range * 0.8f, radio.Range);
|
||||
@@ -110,7 +110,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
client.VoipSound.SetRange(ChatMessage.SpeakRange * 0.4f, ChatMessage.SpeakRange);
|
||||
}
|
||||
if (!client.VoipSound.UseRadioFilter && Character.Controlled != null)
|
||||
if (!client.VoipSound.UseRadioFilter && Character.Controlled != null && !GameMain.Config.DisableVoiceChatFilters)
|
||||
{
|
||||
client.VoipSound.UseMuffleFilter = SoundPlayer.ShouldMuffleSound(Character.Controlled, client.Character.WorldPosition, ChatMessage.SpeakRange, client.Character.CurrentHull);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user