(f0d812055) v0.9.9.0

This commit is contained in:
Joonas Rikkonen
2020-04-23 19:19:37 +03:00
parent b647059b93
commit ac37a3b0e4
391 changed files with 15054 additions and 5420 deletions
@@ -11,6 +11,8 @@ namespace Barotrauma.Networking
Default, Error, Dead, Server, Radio, Private, Console, MessageBox, Order, ServerLog, ServerMessageBox
}
public enum PlayerConnectionChangeType { None = 0, Joined = 1, Kicked = 2, Disconnected = 3, Banned = 4 }
partial class ChatMessage
{
public const int MaxLength = 150;
@@ -58,8 +60,10 @@ namespace Barotrauma.Networking
}
public ChatMessageType Type;
public PlayerConnectionChangeType ChangeType;
public readonly Character Sender;
public readonly Client SenderClient;
public readonly string SenderName;
@@ -89,19 +93,21 @@ namespace Barotrauma.Networking
set;
}
protected ChatMessage(string senderName, string text, ChatMessageType type, Character sender)
protected ChatMessage(string senderName, string text, ChatMessageType type, Character sender, Client client, PlayerConnectionChangeType changeType = PlayerConnectionChangeType.None)
{
Text = text;
Type = type;
Sender = sender;
SenderClient = client;
SenderName = senderName;
ChangeType = changeType;
}
public static ChatMessage Create(string senderName, string text, ChatMessageType type, Character sender)
public static ChatMessage Create(string senderName, string text, ChatMessageType type, Character sender, Client client = null, PlayerConnectionChangeType changeType = PlayerConnectionChangeType.None)
{
return new ChatMessage(senderName, text, type, sender);
return new ChatMessage(senderName, text, type, sender, client ?? GameMain.NetworkMember?.ConnectedClients?.Find(c => c.Character == sender), changeType);
}
public static string GetChatMessageCommand(string message, out string messageWithoutCommand)
@@ -233,7 +233,7 @@ namespace Barotrauma.Networking
{
writeStream?.Write(msg, 0, msg.Length);
}
catch (IOException e)
catch (IOException)
{
shutDown = true;
break;
@@ -263,7 +263,7 @@ namespace Barotrauma.Networking
lengthBytes[1] = (byte)0;
writeStream?.Write(lengthBytes, 0, 2);
}
catch (IOException e)
catch (IOException)
{
shutDown = true;
break;
@@ -14,6 +14,8 @@ namespace Barotrauma.Networking
public byte ID;
public UInt64 SteamID;
public UInt16 Ping;
public string PreferredJob;
public Character.TeamType TeamID;
@@ -86,6 +88,14 @@ namespace Barotrauma.Networking
}
}
public bool Spectating
{
get
{
return inGame && character == null;
}
}
private bool muted;
public bool Muted
{
@@ -105,6 +115,8 @@ namespace Barotrauma.Networking
}
}
public bool HasPermissions = false;
public VoipQueue VoipQueue
{
get;
@@ -51,7 +51,7 @@ namespace Barotrauma.Networking
{
foreach (XElement subElement in element.Elements())
{
if (subElement.Name.ToString().ToLowerInvariant() != "command") continue;
if (!subElement.Name.ToString().Equals("command", StringComparison.OrdinalIgnoreCase)) { continue; }
string commandName = subElement.GetAttributeString("name", "");
DebugConsole.Command command = DebugConsole.FindCommand(commandName);
@@ -125,7 +125,7 @@ namespace Barotrauma
{
public readonly Entity Entity;
public readonly UInt16 OriginalID;
public readonly UInt16 OriginalID, OriginalInventoryID;
public readonly bool Remove = false;
@@ -133,6 +133,10 @@ namespace Barotrauma
{
Entity = entity;
OriginalID = entity.ID;
if (entity is Item item && item.ParentInventory?.Owner != null)
{
OriginalInventoryID = item.ParentInventory.Owner.ID;
}
Remove = remove;
}
}
@@ -53,8 +53,20 @@ namespace Barotrauma
[Serialize(0.25f, true)]
public float DamageFriendlyKarmaDecrease { get; set; }
[Serialize(0.25f, true)]
public float StunFriendlyKarmaDecrease { get; set; }
[Serialize(0.3f, true)]
public float StunFriendlyKarmaDecreaseThreshold { get; set; }
[Serialize(1.0f, true)]
public float ExtinguishFireKarmaIncrease { get; set; }
[Serialize(defaultValue: 15.0f, true)]
public float DangerousItemStealKarmaDecrease { get; set; }
[Serialize(defaultValue: false, true)]
public bool DangerousItemStealBots { get; set; }
private int allowedWireDisconnectionsPerMinute;
@@ -49,6 +49,26 @@ namespace Barotrauma.Networking
public const int MaxEventPacketsPerUpdate = 4;
/// <summary>
/// How long the server waits for the clients to get in sync after the round has started before kicking them
/// </summary>
public const float RoundStartSyncDuration = 60.0f;
/// <summary>
/// How long the server keeps events that everyone currently synced has received
/// </summary>
public const float EventRemovalTime = 15.0f;
/// <summary>
/// If a client hasn't received an event that has been succesfully sent to someone within this time, they get kicked
/// </summary>
public const float OldReceivedEventKickTime = 10.0f;
/// <summary>
/// If a client hasn't received an event after this time, they get kicked
/// </summary>
public const float OldEventKickTime = 30.0f;
/// <summary>
/// Interpolates the positional error of a physics body towards zero.
/// </summary>
@@ -15,7 +15,8 @@ namespace Barotrauma.Networking
ChangeProperty,
Control,
UpdateSkills,
Combine
Combine,
ExecuteAttack
}
public readonly Entity Entity;
@@ -19,6 +19,8 @@ namespace Barotrauma.Networking
VOICE,
PING_RESPONSE,
RESPONSE_STARTGAME, //tell the server whether you're ready to start
SERVER_COMMAND, //tell the server to end a round or kick/ban someone (special permissions required)
@@ -60,6 +62,9 @@ namespace Barotrauma.Networking
VOICE,
PING_REQUEST, //ping the client
CLIENT_PINGS, //tell the client the pings of all other clients
QUERY_STARTGAME, //ask the clients whether they're ready to start
STARTGAME, //start a new round
STARTGAMEFINALIZE, //finalize round initialization
@@ -212,9 +217,9 @@ namespace Barotrauma.Networking
return radioComponent.HasRequiredContainedItems(sender, addMessage: false);
}
public void AddChatMessage(string message, ChatMessageType type, string senderName = "", Character senderCharacter = null)
public void AddChatMessage(string message, ChatMessageType type, string senderName = "", Character senderCharacter = null, PlayerConnectionChangeType changeType = PlayerConnectionChangeType.None)
{
AddChatMessage(ChatMessage.Create(senderName, message, type, senderCharacter));
AddChatMessage(ChatMessage.Create(senderName, message, type, senderCharacter, changeType: changeType));
}
public virtual void AddChatMessage(ChatMessage message)
@@ -25,7 +25,7 @@ namespace Barotrauma.Networking
}
public OrderChatMessage(Order order, string orderOption, string text, Entity targetEntity, Character targetCharacter, Character sender)
: base(sender?.Name, text, ChatMessageType.Order, sender)
: base(sender?.Name, text, ChatMessageType.Order, sender, GameMain.NetworkMember.ConnectedClients.Find(c => c.Character == sender))
{
Order = order;
OrderOption = orderOption;
@@ -63,15 +63,14 @@ namespace Barotrauma.Networking
public Submarine RespawnShuttle { get; private set; }
public RespawnManager(NetworkMember networkMember, Submarine shuttle)
: base(shuttle)
public RespawnManager(NetworkMember networkMember, SubmarineInfo shuttleInfo)
: base(null)
{
this.networkMember = networkMember;
if (shuttle != null)
if (shuttleInfo != null)
{
RespawnShuttle = new Submarine(shuttle.FilePath, shuttle.MD5Hash.Hash, true);
RespawnShuttle.Load(false);
RespawnShuttle = new Submarine(shuttleInfo, true);
RespawnShuttle.PhysicsBody.FarseerBody.OnCollision += OnShuttleCollision;
//prevent wifi components from communicating between the respawn shuttle and other subs
@@ -11,7 +11,9 @@ namespace Barotrauma.Networking
private struct LogMessage
{
public readonly string Text;
public readonly string SanitizedText;
public readonly MessageType Type;
public readonly List<RichTextData> RichData;
public LogMessage(string text, MessageType type)
{
@@ -23,6 +25,7 @@ namespace Barotrauma.Networking
{
Text = $"[{DateTime.Now.ToString()}]\n {TextManager.GetServerMessage(text)}";
}
RichData = RichTextData.GetRichTextData(Text, out SanitizedText);
Type = type;
}
@@ -38,6 +41,7 @@ namespace Barotrauma.Networking
Wiring,
ServerMessage,
ConsoleUsage,
Karma,
Error,
}
@@ -51,6 +55,7 @@ namespace Barotrauma.Networking
{ MessageType.Wiring, new Color(255, 157, 85) },
{ MessageType.ServerMessage, new Color(157, 225, 160) },
{ MessageType.ConsoleUsage, new Color(0, 162, 232) },
{ MessageType.Karma, new Color(75, 88, 255) },
{ MessageType.Error, Color.Red },
};
@@ -64,6 +69,7 @@ namespace Barotrauma.Networking
{ MessageType.Wiring, "Wiring" },
{ MessageType.ServerMessage, "ServerMessage" },
{ MessageType.ConsoleUsage, "ConsoleUsage" },
{ MessageType.Karma, "Karma" },
{ MessageType.Error, "Error" }
};
@@ -101,12 +107,12 @@ namespace Barotrauma.Networking
{
//string logLine = "[" + DateTime.Now.ToLongTimeString() + "] " + line;
var newText = new LogMessage(line, messageType);
#if SERVER
DebugConsole.NewMessage(line, messageColor[messageType]); //TODO: REMOVE
DebugConsole.NewMessage(newText.SanitizedText, messageColor[messageType]); //TODO: REMOVE
#endif
var newText = new LogMessage(line, messageType);
lines.Enqueue(newText);
#if CLIENT
@@ -134,7 +140,7 @@ namespace Barotrauma.Networking
#if CLIENT
while (listBox != null && listBox.Content.CountChildren > LinesPerFile)
{
listBox.RemoveChild(listBox.Content.Children.First());
listBox.RemoveChild(reverseOrder ? listBox.Content.Children.First() : listBox.Content.Children.Last());
}
#endif
}
@@ -167,7 +173,7 @@ namespace Barotrauma.Networking
try
{
File.WriteAllLines(filePath, lines.Select(l => l.Text));
File.WriteAllLines(filePath, lines.Select(l => l.SanitizedText));
}
catch (Exception e)
{
@@ -138,7 +138,7 @@ namespace Barotrauma.Networking
{
return (a == null) == (b == null);
}
return a.ToString().Equals(b.ToString(), StringComparison.InvariantCulture);
return a.ToString().Equals(b.ToString(), StringComparison.OrdinalIgnoreCase);
}
}
@@ -608,6 +608,13 @@ namespace Barotrauma.Networking
set;
}
[Serialize(false, true)]
public bool DisableBotConversations
{
get;
set;
}
public float SelectedLevelDifficulty
{
get { return selectedLevelDifficulty; }
@@ -759,7 +766,7 @@ namespace Barotrauma.Networking
private set;
}
[Serialize(120.0f, true)]
[Serialize(600.0f, true)]
public float KickAFKTime
{
get;
@@ -1,6 +1,8 @@
using System;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
#if USE_STEAM
namespace Barotrauma.Steam
@@ -19,6 +21,8 @@ namespace Barotrauma.Steam
public const string MetadataFileName = "filelist.xml";
public const string CopyIndicatorFileName = ".copying";
private static readonly Dictionary<string, int> tagCommonness = new Dictionary<string, int>()
{
{ "submarine", 10 },
@@ -45,7 +49,7 @@ namespace Barotrauma.Steam
private static bool isInitialized;
public static bool IsInitialized => isInitialized;
public static void Initialize()
{
InitializeProjectSpecific();
@@ -70,27 +74,28 @@ namespace Barotrauma.Steam
return Steamworks.SteamClient.Name;
}
public static void OverlayCustomURL(string url)
{
if (!isInitialized || !Steamworks.SteamClient.IsValid)
{
return;
}
Steamworks.SteamFriends.OpenWebOverlay(url);
}
public static bool UnlockAchievement(string achievementName)
public static bool OverlayCustomURL(string url)
{
if (!isInitialized || !Steamworks.SteamClient.IsValid)
{
return false;
}
DebugConsole.Log("Unlocked achievement \"" + achievementName + "\"");
Steamworks.SteamFriends.OpenWebOverlay(url);
return true;
}
public static bool UnlockAchievement(string achievementIdentifier)
{
if (!isInitialized || !Steamworks.SteamClient.IsValid)
{
return false;
}
DebugConsole.Log("Unlocked achievement \"" + achievementIdentifier + "\"");
var achievements = Steamworks.SteamUserStats.Achievements.ToList();
int achIndex = achievements.FindIndex(ach => ach.Name == achievementName);
int achIndex = achievements.FindIndex(ach => ach.Identifier == achievementIdentifier);
bool unlocked = achIndex >= 0 ? achievements[achIndex].Trigger() : false;
if (!unlocked)
{
@@ -99,7 +104,7 @@ namespace Barotrauma.Steam
//(discovered[whateverbiomewasentered], kill[withwhateveritem], kill[somemonster] etc) so that we can add
//some types of new achievements without the need for client-side changes.
#if DEBUG
DebugConsole.NewMessage("Failed to unlock achievement \"" + achievementName + "\".");
DebugConsole.NewMessage("Failed to unlock achievement \"" + achievementIdentifier + "\".");
#endif
}
@@ -57,6 +57,12 @@ namespace Barotrauma.Networking
protected set;
}
public bool ForceLocal
{
get;
set;
}
public DateTime LastReadTime
{
get;
@@ -76,7 +82,7 @@ namespace Barotrauma.Networking
QueueID = id;
CanSend = canSend;
CanReceive = canReceive;
LatestBufferID = BUFFER_COUNT-1;
LatestBufferID = BUFFER_COUNT - 1;
firstRead = true;
LastReadTime = DateTime.Now;
@@ -84,7 +90,7 @@ namespace Barotrauma.Networking
public void EnqueueBuffer(int length)
{
if (length > byte.MaxValue) return;
if (length > byte.MaxValue) { return; }
newestBufferInd = (newestBufferInd + 1) % BUFFER_COUNT;
@@ -92,17 +98,18 @@ namespace Barotrauma.Networking
bufferLengths[newestBufferInd] = length;
BufferToQueue.CopyTo(buffers[newestBufferInd], 0);
if ((enqueuedTotalLength+length)>0) LatestBufferID++;
if ((enqueuedTotalLength + length) > 0) { LatestBufferID++; }
}
public void RetrieveBuffer(int id,out int outSize,out byte[] outBuf)
public void RetrieveBuffer(int id, out int outSize, out byte[] outBuf)
{
lock (buffers)
{
if (id >= LatestBufferID - (BUFFER_COUNT - 1) && id <= LatestBufferID)
{
int index = (newestBufferInd - (LatestBufferID - id)); if (index < 0) index += BUFFER_COUNT;
int index = newestBufferInd - (LatestBufferID - id);
if (index < 0) { index += BUFFER_COUNT; }
outSize = bufferLengths[index];
outBuf = buffers[index];
return;
@@ -114,9 +121,10 @@ namespace Barotrauma.Networking
public virtual void Write(IWriteMessage msg)
{
if (!CanSend) throw new Exception("Called Write on a VoipQueue not set up for sending");
if (!CanSend) { throw new Exception("Called Write on a VoipQueue not set up for sending"); }
msg.Write((UInt16)LatestBufferID);
msg.Write(ForceLocal); msg.WritePadBits();
for (int i = 0; i < BUFFER_COUNT; i++)
{
int index = (newestBufferInd + i + 1) % BUFFER_COUNT;
@@ -126,13 +134,15 @@ namespace Barotrauma.Networking
}
}
public virtual bool Read(IReadMessage msg)
public virtual bool Read(IReadMessage msg, bool discardData = false)
{
if (!CanReceive) throw new Exception("Called Read on a VoipQueue not set up for receiving");
if (!CanReceive) { throw new Exception("Called Read on a VoipQueue not set up for receiving"); }
UInt16 incLatestBufferID = msg.ReadUInt16();
if (firstRead || NetIdUtils.IdMoreRecent(incLatestBufferID,LatestBufferID))
if ((firstRead || NetIdUtils.IdMoreRecent(incLatestBufferID, LatestBufferID)) && !discardData)
{
ForceLocal = msg.ReadBoolean(); msg.ReadPadBits();
firstRead = false;
for (int i = 0; i < BUFFER_COUNT; i++)
{
@@ -146,6 +156,7 @@ namespace Barotrauma.Networking
}
else
{
msg.ReadBoolean(); msg.ReadPadBits();
for (int i = 0; i < BUFFER_COUNT; i++)
{
byte len = msg.ReadByte();