(5a377a8ee) Unstable v0.9.1000.0
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Barotrauma.IO;
|
||||
using System.IO.Pipes;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -12,8 +12,8 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
static partial class ChildServerRelay
|
||||
{
|
||||
private static Stream writeStream;
|
||||
private static Stream readStream;
|
||||
private static System.IO.Stream writeStream;
|
||||
private static System.IO.Stream readStream;
|
||||
private static volatile bool shutDown;
|
||||
public static bool HasShutDown
|
||||
{
|
||||
@@ -233,7 +233,12 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
writeStream?.Write(msg, 0, msg.Length);
|
||||
}
|
||||
catch (IOException)
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
shutDown = true;
|
||||
break;
|
||||
}
|
||||
catch (System.IO.IOException)
|
||||
{
|
||||
shutDown = true;
|
||||
break;
|
||||
@@ -263,7 +268,12 @@ namespace Barotrauma.Networking
|
||||
lengthBytes[1] = (byte)0;
|
||||
writeStream?.Write(lengthBytes, 0, 2);
|
||||
}
|
||||
catch (IOException)
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
shutDown = true;
|
||||
break;
|
||||
}
|
||||
catch (System.IO.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;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Barotrauma.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Barotrauma.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
@@ -53,8 +52,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;
|
||||
@@ -104,7 +115,7 @@ namespace Barotrauma
|
||||
doc = XMLExtensions.TryLoadXml(ConfigFile);
|
||||
break;
|
||||
}
|
||||
catch (IOException)
|
||||
catch (System.IO.IOException)
|
||||
{
|
||||
if (i == maxLoadRetries) { break; }
|
||||
DebugConsole.NewMessage("Opening karma settings file \"" + ConfigFile + "\" failed, retrying in 250 ms...");
|
||||
@@ -159,7 +170,7 @@ namespace Barotrauma
|
||||
doc.Root.Add(preset.Value);
|
||||
}
|
||||
|
||||
XmlWriterSettings settings = new XmlWriterSettings
|
||||
System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings
|
||||
{
|
||||
Indent = true,
|
||||
NewLineOnAttributes = true
|
||||
@@ -172,11 +183,11 @@ namespace Barotrauma
|
||||
{
|
||||
using (var writer = XmlWriter.Create(ConfigFile, settings))
|
||||
{
|
||||
doc.Save(writer);
|
||||
doc.SaveSafe(writer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
catch (IOException)
|
||||
catch (System.IO.IOException)
|
||||
{
|
||||
if (i == maxLoadRetries) { throw; }
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
+2
-1
@@ -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;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Lidgren.Network;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Barotrauma.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
@@ -519,7 +519,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
else
|
||||
{
|
||||
using (MemoryStream output = new MemoryStream())
|
||||
using (System.IO.MemoryStream output = new System.IO.MemoryStream())
|
||||
{
|
||||
using (DeflateStream dstream = new DeflateStream(output, CompressionLevel.Fastest))
|
||||
{
|
||||
@@ -613,9 +613,9 @@ namespace Barotrauma.Networking
|
||||
if (isCompressed)
|
||||
{
|
||||
byte[] decompressedData;
|
||||
using (MemoryStream input = new MemoryStream(inBuf, startPos, inLength))
|
||||
using (System.IO.MemoryStream input = new System.IO.MemoryStream(inBuf, startPos, inLength))
|
||||
{
|
||||
using (MemoryStream output = new MemoryStream())
|
||||
using (System.IO.MemoryStream output = new System.IO.MemoryStream())
|
||||
{
|
||||
using (DeflateStream dstream = new DeflateStream(input, CompressionMode.Decompress))
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Barotrauma.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using Barotrauma.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
@@ -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
|
||||
@@ -47,7 +49,7 @@ namespace Barotrauma.Steam
|
||||
|
||||
private static bool isInitialized;
|
||||
public static bool IsInitialized => isInitialized;
|
||||
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
InitializeProjectSpecific();
|
||||
|
||||
@@ -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,30 +121,39 @@ 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);
|
||||
for (int i = 0; i < BUFFER_COUNT; i++)
|
||||
msg.Write(ForceLocal); msg.WritePadBits();
|
||||
lock (buffers)
|
||||
{
|
||||
int index = (newestBufferInd + i + 1) % BUFFER_COUNT;
|
||||
for (int i = 0; i < BUFFER_COUNT; i++)
|
||||
{
|
||||
int index = (newestBufferInd + i + 1) % BUFFER_COUNT;
|
||||
|
||||
msg.Write((byte)bufferLengths[index]);
|
||||
msg.Write(buffers[index], 0, bufferLengths[index]);
|
||||
msg.Write((byte)bufferLengths[index]);
|
||||
msg.Write(buffers[index], 0, bufferLengths[index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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++)
|
||||
lock (buffers)
|
||||
{
|
||||
bufferLengths[i] = msg.ReadByte();
|
||||
buffers[i] = msg.ReadBytes(bufferLengths[i]);
|
||||
for (int i = 0; i < BUFFER_COUNT; i++)
|
||||
{
|
||||
bufferLengths[i] = msg.ReadByte();
|
||||
buffers[i] = msg.ReadBytes(bufferLengths[i]);
|
||||
}
|
||||
}
|
||||
newestBufferInd = BUFFER_COUNT - 1;
|
||||
LatestBufferID = incLatestBufferID;
|
||||
@@ -146,6 +162,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.ReadBoolean(); msg.ReadPadBits();
|
||||
for (int i = 0; i < BUFFER_COUNT; i++)
|
||||
{
|
||||
byte len = msg.ReadByte();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Barotrauma.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
|
||||
Reference in New Issue
Block a user