Merge https://github.com/Regalis11/Barotrauma into develop
This commit is contained in:
@@ -60,6 +60,10 @@ namespace Barotrauma
|
||||
{
|
||||
distance = Math.Min(distance, Vector2.Distance(recipient.Character.ViewTarget.WorldPosition, WorldPosition));
|
||||
}
|
||||
if (ViewTarget != null && ViewTarget != this)
|
||||
{
|
||||
distance = Math.Min(distance, Vector2.Distance(comparePosition, ViewTarget.WorldPosition));
|
||||
}
|
||||
|
||||
float priority = 1.0f - MathUtils.InverseLerp(
|
||||
NetConfig.HighPrioCharacterPositionUpdateDistance,
|
||||
@@ -155,8 +159,6 @@ namespace Barotrauma
|
||||
|
||||
memInput.RemoveAt(memInput.Count - 1);
|
||||
|
||||
TransformCursorPos();
|
||||
|
||||
if ((dequeuedInput == InputNetFlags.None || dequeuedInput == InputNetFlags.FacingLeft) && Math.Abs(AnimController.Collider.LinearVelocity.X) < 0.005f && Math.Abs(AnimController.Collider.LinearVelocity.Y) < 0.2f)
|
||||
{
|
||||
while (memInput.Count > 5 && memInput[memInput.Count - 1].states == dequeuedInput)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Barotrauma.Networking;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -16,11 +17,10 @@ namespace Barotrauma
|
||||
foreach (var kvp in spawnedResources)
|
||||
{
|
||||
msg.WriteByte((byte)kvp.Value.Count);
|
||||
var rotation = resourceClusters[kvp.Key].Rotation;
|
||||
msg.WriteSingle(rotation);
|
||||
foreach (var r in kvp.Value)
|
||||
msg.WriteSingle(kvp.Value.FirstOrDefault()?.Rotation ?? 0.0f);
|
||||
foreach (var item in kvp.Value)
|
||||
{
|
||||
r.WriteSpawnData(msg, r.ID, Entity.NullEntityID, 0, -1);
|
||||
item.WriteSpawnData(msg, item.ID, Entity.NullEntityID, 0, -1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ namespace Barotrauma
|
||||
{
|
||||
msg.WriteIdentifier(kvp.Key);
|
||||
msg.WriteByte((byte)kvp.Value.Length);
|
||||
foreach (var i in kvp.Value)
|
||||
foreach (var item in kvp.Value)
|
||||
{
|
||||
msg.WriteUInt16(i.ID);
|
||||
msg.WriteUInt16(item.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-1
@@ -6,7 +6,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Barotrauma.Steam;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -1310,6 +1309,10 @@ namespace Barotrauma
|
||||
|
||||
public override bool TryPurchase(Client client, int price)
|
||||
{
|
||||
//disconnected clients can never purchase anything
|
||||
//(can happen e.g. if someone starts a vote to buy something and then disconnects)
|
||||
if (client != null && !GameMain.Server.ConnectedClients.Contains(client)) { return false; }
|
||||
|
||||
Wallet wallet = GetWallet(client);
|
||||
if (!AllowedToManageWallets(client))
|
||||
{
|
||||
@@ -1359,6 +1362,12 @@ namespace Barotrauma
|
||||
modeElement.Add(Settings.Save());
|
||||
modeElement.Add(SaveStats());
|
||||
modeElement.Add(Bank.Save());
|
||||
|
||||
if (GameMain.GameSession?.EventManager != null)
|
||||
{
|
||||
modeElement.Add(GameMain.GameSession?.EventManager.Save());
|
||||
}
|
||||
|
||||
CampaignMetadata?.Save(modeElement);
|
||||
Map.Save(modeElement);
|
||||
CargoManager?.SavePurchasedItems(modeElement);
|
||||
|
||||
@@ -18,11 +18,11 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (item.CanClientAccess(c))
|
||||
{
|
||||
lastReceivedTargetForce = null;
|
||||
if (Math.Abs(newTargetForce - targetForce) > 0.01f)
|
||||
{
|
||||
GameServer.Log(GameServer.CharacterLogName(c.Character) + " set the force of " + item.Name + " to " + (int)(newTargetForce) + " %", ServerLog.MessageType.ItemInteraction);
|
||||
}
|
||||
|
||||
targetForce = newTargetForce;
|
||||
User = c.Character;
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ namespace Barotrauma.Items.Components
|
||||
//already connected, no need to do anything
|
||||
if (Connections[i].Wires.Contains(newWire)) { continue; }
|
||||
|
||||
newWire.Connect(Connections[i], true, true);
|
||||
newWire.TryConnect(Connections[i], true, true);
|
||||
Connections[i].TryAddLink(newWire);
|
||||
|
||||
var otherConnection = newWire.OtherConnection(Connections[i]);
|
||||
|
||||
@@ -23,15 +23,13 @@ namespace Barotrauma.Networking
|
||||
|
||||
public override Voting Voting { get; }
|
||||
|
||||
private string serverName;
|
||||
public string ServerName
|
||||
{
|
||||
get { return serverName; }
|
||||
get { return ServerSettings.ServerName; }
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value)) { return; }
|
||||
|
||||
serverName = value;
|
||||
ServerSettings.ServerName = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,8 +134,6 @@ namespace Barotrauma.Networking
|
||||
name = name.Substring(0, NetConfig.ServerNameMaxLength);
|
||||
}
|
||||
|
||||
this.serverName = name;
|
||||
|
||||
LastClientListUpdateID = 0;
|
||||
|
||||
ServerSettings = new ServerSettings(this, name, port, queryPort, maxPlayers, isPublic, attemptUPnP, listenIp);
|
||||
@@ -1680,38 +1676,54 @@ namespace Barotrauma.Networking
|
||||
//characters or items spawned mid-round don't necessarily exist at the client's end yet
|
||||
if (!c.NeedsMidRoundSync)
|
||||
{
|
||||
foreach (Character character in Character.CharacterList)
|
||||
Character clientCharacter = c.Character;
|
||||
foreach (Character otherCharacter in Character.CharacterList)
|
||||
{
|
||||
if (!character.Enabled) { continue; }
|
||||
if (!otherCharacter.Enabled) { continue; }
|
||||
if (c.SpectatePos == null)
|
||||
{
|
||||
float distSqr = Vector2.DistanceSquared(character.WorldPosition, c.Character.WorldPosition);
|
||||
if (c.Character.ViewTarget != null)
|
||||
//not spectating ->
|
||||
// check if the client's character, or the entity they're viewing,
|
||||
// is close enough to the other character or the entity the other character is viewing
|
||||
float distSqr = GetShortestDistance(clientCharacter.WorldPosition, otherCharacter);
|
||||
if (clientCharacter.ViewTarget != null && clientCharacter.ViewTarget != clientCharacter)
|
||||
{
|
||||
distSqr = Math.Min(distSqr, Vector2.DistanceSquared(character.WorldPosition, c.Character.ViewTarget.WorldPosition));
|
||||
distSqr = Math.Min(distSqr, GetShortestDistance(clientCharacter.ViewTarget.WorldPosition, otherCharacter));
|
||||
}
|
||||
if (distSqr >= MathUtils.Pow2(character.Params.DisableDistance)) { continue; }
|
||||
if (distSqr >= MathUtils.Pow2(otherCharacter.Params.DisableDistance)) { continue; }
|
||||
}
|
||||
else
|
||||
else if (otherCharacter != clientCharacter)
|
||||
{
|
||||
if (character != c.Character && Vector2.DistanceSquared(character.WorldPosition, c.SpectatePos.Value) >= MathUtils.Pow2(character.Params.DisableDistance))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
//spectating ->
|
||||
// check if the position the client is viewing
|
||||
// is close enough to the other character or the entity the other character is viewing
|
||||
if (GetShortestDistance(c.SpectatePos.Value, otherCharacter) >= MathUtils.Pow2(otherCharacter.Params.DisableDistance)) { continue; }
|
||||
}
|
||||
|
||||
float updateInterval = character.GetPositionUpdateInterval(c);
|
||||
c.PositionUpdateLastSent.TryGetValue(character, out float lastSent);
|
||||
static float GetShortestDistance(Vector2 viewPos, Character targetCharacter)
|
||||
{
|
||||
float distSqr = Vector2.DistanceSquared(viewPos, targetCharacter.WorldPosition);
|
||||
if (targetCharacter.ViewTarget != null && targetCharacter.ViewTarget != targetCharacter)
|
||||
{
|
||||
//if the character is viewing something (far-away turret?),
|
||||
//we might want to send updates about it to the spectating client even though they're far away from the actual character
|
||||
distSqr = Math.Min(distSqr, Vector2.DistanceSquared(viewPos, targetCharacter.ViewTarget.WorldPosition));
|
||||
}
|
||||
return distSqr;
|
||||
}
|
||||
|
||||
float updateInterval = otherCharacter.GetPositionUpdateInterval(c);
|
||||
c.PositionUpdateLastSent.TryGetValue(otherCharacter, out float lastSent);
|
||||
if (lastSent > NetTime.Now)
|
||||
{
|
||||
//sent in the future -> can't be right, remove
|
||||
c.PositionUpdateLastSent.Remove(character);
|
||||
c.PositionUpdateLastSent.Remove(otherCharacter);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lastSent > NetTime.Now - updateInterval) { continue; }
|
||||
}
|
||||
if (!c.PendingPositionUpdates.Contains(character)) { c.PendingPositionUpdates.Enqueue(character); }
|
||||
if (!c.PendingPositionUpdates.Contains(otherCharacter)) { c.PendingPositionUpdates.Enqueue(otherCharacter); }
|
||||
}
|
||||
|
||||
foreach (Submarine sub in Submarine.Loaded)
|
||||
@@ -3138,7 +3150,7 @@ namespace Barotrauma.Networking
|
||||
default:
|
||||
if (command != "")
|
||||
{
|
||||
if (command.ToLower() == serverName.ToLower())
|
||||
if (command.ToLower() == ServerName.ToLower())
|
||||
{
|
||||
//a private message to the host
|
||||
if (OwnerConnection != null)
|
||||
@@ -3193,7 +3205,7 @@ namespace Barotrauma.Networking
|
||||
//msg sent by the server
|
||||
if (senderCharacter == null)
|
||||
{
|
||||
senderName = serverName;
|
||||
senderName = ServerName;
|
||||
}
|
||||
else //msg sent by an AI character
|
||||
{
|
||||
@@ -3227,7 +3239,7 @@ namespace Barotrauma.Networking
|
||||
//msg sent by the server
|
||||
if (senderCharacter == null)
|
||||
{
|
||||
senderName = serverName;
|
||||
senderName = ServerName;
|
||||
}
|
||||
else //sent by an AI character, not allowed when the game is not running
|
||||
{
|
||||
@@ -3459,33 +3471,35 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
|
||||
public void SwitchSubmarine()
|
||||
public bool TrySwitchSubmarine()
|
||||
{
|
||||
if (Voting.ActiveVote is not Voting.SubmarineVote subVote) { return; }
|
||||
if (Voting.ActiveVote is not Voting.SubmarineVote subVote) { return false; }
|
||||
|
||||
SubmarineInfo targetSubmarine = subVote.Sub;
|
||||
VoteType voteType = Voting.ActiveVote.VoteType;
|
||||
Client starter = Voting.ActiveVote.VoteStarter;
|
||||
|
||||
bool purchaseFailed = false;
|
||||
switch (voteType)
|
||||
{
|
||||
case VoteType.PurchaseAndSwitchSub:
|
||||
case VoteType.PurchaseSub:
|
||||
// Pay for submarine
|
||||
GameMain.GameSession.PurchaseSubmarine(targetSubmarine, starter);
|
||||
purchaseFailed = !GameMain.GameSession.TryPurchaseSubmarine(targetSubmarine, starter);
|
||||
break;
|
||||
case VoteType.SwitchSub:
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (voteType != VoteType.PurchaseSub)
|
||||
if (voteType != VoteType.PurchaseSub && !purchaseFailed)
|
||||
{
|
||||
GameMain.GameSession.SwitchSubmarine(targetSubmarine, subVote.TransferItems, starter);
|
||||
}
|
||||
|
||||
Voting.StopSubmarineVote(true);
|
||||
Voting.StopSubmarineVote(passed: !purchaseFailed);
|
||||
return !purchaseFailed;
|
||||
}
|
||||
|
||||
public void UpdateClientPermissions(Client client)
|
||||
|
||||
@@ -370,6 +370,8 @@ namespace Barotrauma.Networking
|
||||
"192-255",
|
||||
"384-591",
|
||||
"1024-1279",
|
||||
"4352-4607", //Hangul Jamo
|
||||
"44032-55215", //Hangul Syllables
|
||||
"19968-21327","21329-40959","13312-19903","131072-173791","173824-178207","178208-183983","63744-64255","194560-195103" //CJK
|
||||
};
|
||||
|
||||
|
||||
@@ -42,7 +42,11 @@ namespace Barotrauma
|
||||
{
|
||||
if (passed)
|
||||
{
|
||||
GameMain.Server?.SwitchSubmarine();
|
||||
if (GameMain.Server != null && !GameMain.Server.TrySwitchSubmarine())
|
||||
{
|
||||
passed = false;
|
||||
State = VoteState.Failed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -71,6 +71,15 @@ namespace Barotrauma
|
||||
StrikesResetInterval = 60,
|
||||
StrikeThreshold = 6;
|
||||
|
||||
private const int MinPacketLimitMultipler = 1;
|
||||
|
||||
private static int GetMaxPacketLimit(ServerSettings settings)
|
||||
=> (int)MathF.Ceiling(
|
||||
settings.MaxPacketAmount *
|
||||
MathF.Max(
|
||||
settings.TickRate / (float)ServerSettings.DefaultTickRate,
|
||||
MinPacketLimitMultipler)); // Prevent the rate limit multiplier from being less than 1.
|
||||
|
||||
/// <summary>
|
||||
/// Called when the server receives a packet to start logging how much time it takes to process.
|
||||
/// </summary>
|
||||
@@ -122,11 +131,7 @@ namespace Barotrauma
|
||||
|
||||
private void StartFor(Client client)
|
||||
{
|
||||
if (!clients.ContainsKey(client))
|
||||
{
|
||||
clients.Add(client, new OffenseData());
|
||||
}
|
||||
|
||||
clients.TryAdd(client, new OffenseData());
|
||||
clients[client].Stopwatch.Start();
|
||||
}
|
||||
|
||||
@@ -149,7 +154,7 @@ namespace Barotrauma
|
||||
if (GameMain.Server?.ServerSettings is not { } settings) { return; }
|
||||
|
||||
// client is sending too many packets, kick them
|
||||
if (data.PacketCount > settings.MaxPacketAmount && settings.MaxPacketAmount > ServerSettings.PacketLimitMin)
|
||||
if (data.PacketCount > GetMaxPacketLimit(settings) && settings.MaxPacketAmount > ServerSettings.PacketLimitMin)
|
||||
{
|
||||
AttemptKickClient(client, TextManager.Get("PacketLimitKicked"));
|
||||
clients.Remove(client);
|
||||
@@ -216,7 +221,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (GameMain.Server?.ServerSettings is { MaxPacketAmount: > ServerSettings.PacketLimitMin } settings)
|
||||
{
|
||||
if (data.PacketCount > settings.MaxPacketAmount * 0.9f)
|
||||
if (data.PacketCount > GetMaxPacketLimit(settings) * 0.9f)
|
||||
{
|
||||
GameServer.Log($"{NetworkMember.ClientLogName(client)} is sending a lot of packets and almost got kicked! ({data.PacketCount}).", ServerLog.MessageType.DoSProtection);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user