(f2e516dfe) v0.9.3.2
This commit is contained in:
@@ -18,7 +18,7 @@ namespace Barotrauma.Networking
|
||||
this.ExpirationTime = expirationTime;
|
||||
this.UniqueIdentifier = LastIdentifier; LastIdentifier++;
|
||||
|
||||
this.IsRangeBan = IP.IndexOf(".x")>-1;
|
||||
this.IsRangeBan = IP.IndexOf(".x") > -1;
|
||||
}
|
||||
|
||||
public BannedPlayer(string name, ulong steamID, string reason, DateTime? expirationTime)
|
||||
@@ -30,6 +30,8 @@ namespace Barotrauma.Networking
|
||||
this.UniqueIdentifier = LastIdentifier; LastIdentifier++;
|
||||
|
||||
this.IsRangeBan = false;
|
||||
|
||||
this.IP = "";
|
||||
}
|
||||
|
||||
public bool CompareTo(string ipCompare)
|
||||
@@ -276,28 +278,42 @@ namespace Barotrauma.Networking
|
||||
|
||||
public void ServerAdminWrite(IWriteMessage outMsg, Client c)
|
||||
{
|
||||
if (!c.HasPermission(ClientPermissions.Ban))
|
||||
try
|
||||
{
|
||||
outMsg.Write(false); outMsg.WritePadBits();
|
||||
return;
|
||||
}
|
||||
outMsg.Write(true);
|
||||
outMsg.Write(c.Connection == GameMain.Server.OwnerConnection);
|
||||
if (outMsg == null) { throw new ArgumentException("OutMsg was null"); }
|
||||
if (GameMain.Server == null) { throw new Exception("GameMain.Server was null"); }
|
||||
|
||||
outMsg.WritePadBits();
|
||||
outMsg.WriteVariableUInt32((UInt32)bannedPlayers.Count);
|
||||
for (int i = 0; i < bannedPlayers.Count; i++)
|
||||
{
|
||||
BannedPlayer bannedPlayer = bannedPlayers[i];
|
||||
|
||||
outMsg.Write(bannedPlayer.Name);
|
||||
outMsg.Write(bannedPlayer.UniqueIdentifier);
|
||||
outMsg.Write(bannedPlayer.IsRangeBan); outMsg.WritePadBits();
|
||||
if (c.Connection == GameMain.Server.OwnerConnection)
|
||||
if (!c.HasPermission(ClientPermissions.Ban))
|
||||
{
|
||||
outMsg.Write(bannedPlayer.IP);
|
||||
outMsg.Write(bannedPlayer.SteamID);
|
||||
outMsg.Write(false); outMsg.WritePadBits();
|
||||
return;
|
||||
}
|
||||
|
||||
outMsg.Write(true);
|
||||
outMsg.Write(c.Connection == GameMain.Server.OwnerConnection);
|
||||
|
||||
outMsg.WritePadBits();
|
||||
outMsg.WriteVariableUInt32((UInt32)bannedPlayers.Count);
|
||||
for (int i = 0; i < bannedPlayers.Count; i++)
|
||||
{
|
||||
BannedPlayer bannedPlayer = bannedPlayers[i];
|
||||
|
||||
outMsg.Write(bannedPlayer.Name);
|
||||
outMsg.Write(bannedPlayer.UniqueIdentifier);
|
||||
outMsg.Write(bannedPlayer.IsRangeBan); outMsg.WritePadBits();
|
||||
if (c.Connection == GameMain.Server.OwnerConnection)
|
||||
{
|
||||
outMsg.Write(bannedPlayer.IP);
|
||||
outMsg.Write(bannedPlayer.SteamID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception e)
|
||||
{
|
||||
string errorMsg = "Error while writing banlist. {" + e + "}\n" + e.StackTrace;
|
||||
GameAnalyticsManager.AddErrorEventOnce("Banlist.ServerAdminWrite", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,11 @@ namespace Barotrauma
|
||||
partial class EntitySpawner : Entity, IServerSerializable
|
||||
{
|
||||
public void CreateNetworkEvent(Entity entity, bool remove)
|
||||
{
|
||||
CreateNetworkEventProjSpecific(entity, remove);
|
||||
}
|
||||
|
||||
partial void CreateNetworkEventProjSpecific(Entity entity, bool remove)
|
||||
{
|
||||
if (GameMain.Server != null && entity != null)
|
||||
{
|
||||
|
||||
@@ -264,17 +264,15 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
newClient.GivePermission(ClientPermissions.All);
|
||||
newClient.PermittedConsoleCommands.AddRange(DebugConsole.Commands);
|
||||
|
||||
GameMain.Server.UpdateClientPermissions(newClient);
|
||||
GameMain.Server.SendConsoleMessage("Granted all permissions to " + newClient.Name + ".", newClient);
|
||||
SendConsoleMessage("Granted all permissions to " + newClient.Name + ".", newClient);
|
||||
}
|
||||
|
||||
GameMain.Server.SendChatMessage($"ServerMessage.JoinedServer~[client]={clName}", ChatMessageType.Server, null);
|
||||
SendChatMessage($"ServerMessage.JoinedServer~[client]={clName}", ChatMessageType.Server, null);
|
||||
serverSettings.ServerDetailsChanged = true;
|
||||
|
||||
if (previousPlayer != null && previousPlayer.Name != newClient.Name)
|
||||
{
|
||||
GameMain.Server.SendChatMessage($"ServerMessage.PreviousClientName~[client]={clName}~[previousname]={previousPlayer.Name}", ChatMessageType.Server, null);
|
||||
SendChatMessage($"ServerMessage.PreviousClientName~[client]={clName}~[previousname]={previousPlayer.Name}", ChatMessageType.Server, null);
|
||||
previousPlayer.Name = newClient.Name;
|
||||
}
|
||||
|
||||
@@ -299,6 +297,8 @@ namespace Barotrauma.Networking
|
||||
newClient.SetPermissions(ClientPermissions.None, new List<DebugConsole.Command>());
|
||||
}
|
||||
}
|
||||
|
||||
UpdateClientPermissions(newClient);
|
||||
}
|
||||
|
||||
private void OnClientDisconnect(NetworkConnection connection, string disconnectMsg)
|
||||
@@ -653,9 +653,18 @@ namespace Barotrauma.Networking
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Failed to write a network message for the client \"" + c.Name + "\"!", e);
|
||||
GameAnalyticsManager.AddErrorEventOnce("GameServer.Update:ClientWriteFailed" + e.StackTrace, GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
|
||||
"Failed to write a network message for the client \"" + c.Name + "\"! (MidRoundSyncing: " + c.NeedsMidRoundSync + ")\n"
|
||||
+ e.Message + "\n" + e.StackTrace);
|
||||
|
||||
string errorMsg = "Failed to write a network message for the client \"" + c.Name + "\"! (MidRoundSyncing: " + c.NeedsMidRoundSync + ")\n"
|
||||
+ e.Message + "\n" + e.StackTrace;
|
||||
if (e.InnerException != null)
|
||||
{
|
||||
errorMsg += "\nInner exception: " + e.InnerException.Message + "\n" + e.InnerException.StackTrace;
|
||||
}
|
||||
|
||||
GameAnalyticsManager.AddErrorEventOnce(
|
||||
"GameServer.Update:ClientWriteFailed" + e.StackTrace,
|
||||
GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
|
||||
errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -832,7 +841,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
Log(c.Name + " has reported an error: " + errorStr, ServerLog.MessageType.Error);
|
||||
GameAnalyticsManager.AddErrorEventOnce("GameServer.HandleClientError:LevelsDontMatch" + error, GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorStr);
|
||||
GameAnalyticsManager.AddErrorEventOnce("GameServer.HandleClientError:" + errorStr, GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorStr);
|
||||
|
||||
if (c.Connection == OwnerConnection)
|
||||
{
|
||||
@@ -1475,7 +1484,7 @@ namespace Barotrauma.Networking
|
||||
private void WriteClientList(Client c, IWriteMessage outmsg)
|
||||
{
|
||||
bool hasChanged = NetIdUtils.IdMoreRecent(LastClientListUpdateID, c.LastRecvClientListUpdate);
|
||||
if (!hasChanged) return;
|
||||
if (!hasChanged) { return; }
|
||||
|
||||
outmsg.Write((byte)ServerNetObject.CLIENT_LIST);
|
||||
outmsg.Write(LastClientListUpdateID);
|
||||
@@ -1502,6 +1511,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
outmsg.Write((byte)ServerNetObject.SYNC_IDS);
|
||||
|
||||
int settingsBytes = outmsg.LengthBytes;
|
||||
|
||||
if (NetIdUtils.IdMoreRecent(GameMain.NetLobbyScreen.LastUpdateID, c.LastRecvLobbyUpdate))
|
||||
{
|
||||
outmsg.Write(true);
|
||||
@@ -1534,9 +1545,9 @@ namespace Barotrauma.Networking
|
||||
|
||||
outmsg.Write(serverSettings.AllowSpectating);
|
||||
|
||||
outmsg.WriteRangedIntegerDeprecated(0, 2, (int)serverSettings.TraitorsEnabled);
|
||||
outmsg.WriteRangedInteger((int)serverSettings.TraitorsEnabled, 0, 2);
|
||||
|
||||
outmsg.WriteRangedIntegerDeprecated(0, Enum.GetValues(typeof(MissionType)).Length - 1, (GameMain.NetLobbyScreen.MissionTypeIndex));
|
||||
outmsg.WriteRangedInteger((GameMain.NetLobbyScreen.MissionTypeIndex), 0, Enum.GetValues(typeof(MissionType)).Length - 1);
|
||||
|
||||
outmsg.Write((byte)GameMain.NetLobbyScreen.SelectedModeIndex);
|
||||
outmsg.Write(GameMain.NetLobbyScreen.LevelSeed);
|
||||
@@ -1556,9 +1567,12 @@ namespace Barotrauma.Networking
|
||||
outmsg.Write(false);
|
||||
outmsg.WritePadBits();
|
||||
}
|
||||
settingsBytes = outmsg.LengthBytes - settingsBytes;
|
||||
|
||||
int campaignBytes = outmsg.LengthBytes;
|
||||
var campaign = GameMain.GameSession?.GameMode as MultiPlayerCampaign;
|
||||
if (campaign != null && campaign.Preset == GameMain.NetLobbyScreen.SelectedMode &&
|
||||
if (outmsg.LengthBytes < MsgConstants.MTU - 500 &&
|
||||
campaign != null && campaign.Preset == GameMain.NetLobbyScreen.SelectedMode &&
|
||||
NetIdUtils.IdMoreRecent(campaign.LastUpdateID, c.LastRecvCampaignUpdate))
|
||||
{
|
||||
outmsg.Write(true);
|
||||
@@ -1570,12 +1584,20 @@ namespace Barotrauma.Networking
|
||||
outmsg.Write(false);
|
||||
outmsg.WritePadBits();
|
||||
}
|
||||
campaignBytes = outmsg.LengthBytes - campaignBytes;
|
||||
|
||||
outmsg.Write(c.LastSentChatMsgID); //send this to client so they know which chat messages weren't received by the server
|
||||
|
||||
WriteClientList(c, outmsg);
|
||||
int clientListBytes = outmsg.LengthBytes;
|
||||
if (outmsg.LengthBytes < MsgConstants.MTU - 500)
|
||||
{
|
||||
WriteClientList(c, outmsg);
|
||||
}
|
||||
clientListBytes = outmsg.LengthBytes - clientListBytes;
|
||||
|
||||
int chatMessageBytes = outmsg.LengthBytes;
|
||||
WriteChatMessages(outmsg, c);
|
||||
chatMessageBytes = outmsg.LengthBytes - outmsg.LengthBytes;
|
||||
|
||||
outmsg.Write((byte)ServerNetObject.END_OF_MESSAGE);
|
||||
|
||||
@@ -1597,7 +1619,14 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (outmsg.LengthBytes > MsgConstants.MTU)
|
||||
{
|
||||
DebugConsole.ThrowError("Maximum packet size exceeded (" + outmsg.LengthBytes + " > " + MsgConstants.MTU + ")");
|
||||
string errorMsg = "Maximum packet size exceeded (" + outmsg.LengthBytes + " > " + MsgConstants.MTU + ")";
|
||||
errorMsg +=
|
||||
" Client list size: " + clientListBytes + " bytes\n" +
|
||||
" Chat message size: " + chatMessageBytes + " bytes\n" +
|
||||
" Campaign size: " + campaignBytes + " bytes\n" +
|
||||
" Settings size: " + settingsBytes + " bytes\n\n";
|
||||
DebugConsole.ThrowError(errorMsg);
|
||||
GameAnalyticsManager.AddErrorEventOnce("GameServer.ClientWriteIngame1:ClientWriteLobby" + outmsg.LengthBytes, GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
|
||||
}
|
||||
|
||||
serverPeer.Send(outmsg, c.Connection, DeliveryMethod.Unreliable);
|
||||
@@ -2018,6 +2047,8 @@ namespace Barotrauma.Networking
|
||||
c.PositionUpdateLastSent.Clear();
|
||||
}
|
||||
|
||||
KarmaManager.OnRoundEnded();
|
||||
|
||||
#if DEBUG
|
||||
messageCount.Clear();
|
||||
#endif
|
||||
@@ -2644,25 +2675,48 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
|
||||
//send the message to the client whose permissions are being modified and the clients who are allowed to modify permissions
|
||||
List<Client> recipients = new List<Client>() { client };
|
||||
foreach (Client otherClient in connectedClients)
|
||||
{
|
||||
if (otherClient.HasPermission(ClientPermissions.ManagePermissions) && !recipients.Contains(otherClient))
|
||||
{
|
||||
recipients.Add(otherClient);
|
||||
}
|
||||
}
|
||||
foreach (Client recipient in recipients)
|
||||
{
|
||||
CoroutineManager.StartCoroutine(SendClientPermissionsAfterClientListSynced(recipient, client));
|
||||
}
|
||||
serverSettings.SaveClientPermissions();
|
||||
}
|
||||
|
||||
|
||||
private IEnumerable<object> SendClientPermissionsAfterClientListSynced(Client recipient, Client client)
|
||||
{
|
||||
DateTime timeOut = DateTime.Now + new TimeSpan(0, 0, 10);
|
||||
while (recipient.LastRecvClientListUpdate < LastClientListUpdateID)
|
||||
{
|
||||
if (DateTime.Now > timeOut || GameMain.Server == null || !connectedClients.Contains(recipient))
|
||||
{
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
|
||||
SendClientPermissions(recipient, client);
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
|
||||
private void SendClientPermissions(Client recipient, Client client)
|
||||
{
|
||||
if (recipient?.Connection == null) { return; }
|
||||
|
||||
IWriteMessage msg = new WriteOnlyMessage();
|
||||
msg.Write((byte)ServerPacketHeader.PERMISSIONS);
|
||||
client.WritePermissions(msg);
|
||||
|
||||
//send the message to the client whose permissions are being modified and the clients who are allowed to modify permissions
|
||||
List<NetworkConnection> recipients = new List<NetworkConnection>() { client.Connection };
|
||||
foreach (Client otherClient in connectedClients)
|
||||
{
|
||||
if (otherClient.HasPermission(ClientPermissions.ManagePermissions) && !recipients.Contains(otherClient.Connection))
|
||||
{
|
||||
recipients.Add(otherClient.Connection);
|
||||
}
|
||||
}
|
||||
foreach (NetworkConnection c in recipients)
|
||||
{
|
||||
serverPeer.Send(msg, c, DeliveryMethod.Reliable);
|
||||
}
|
||||
|
||||
serverSettings.SaveClientPermissions();
|
||||
serverPeer.Send(msg, recipient.Connection, DeliveryMethod.Reliable);
|
||||
}
|
||||
|
||||
public void GiveAchievement(Character character, string achievementIdentifier)
|
||||
|
||||
@@ -12,7 +12,6 @@ namespace Barotrauma
|
||||
{
|
||||
public List<Pair<Wire, float>> WireDisconnectTime = new List<Pair<Wire, float>>();
|
||||
|
||||
//the client's karma value when they were last sent a notification about it (e.g. "your karma is very low")
|
||||
public float PreviousNotifiedKarma;
|
||||
|
||||
public float StructureDamageAccumulator;
|
||||
@@ -23,6 +22,13 @@ namespace Barotrauma
|
||||
get { return Math.Max(StructureDamageAccumulator, structureDamagePerSecond); }
|
||||
set { structureDamagePerSecond = value; }
|
||||
}
|
||||
|
||||
//when did a given character last attack this one
|
||||
public Dictionary<Character, double> LastAttackTime
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new Dictionary<Character, double>();
|
||||
}
|
||||
|
||||
public bool TestMode = false;
|
||||
@@ -31,9 +37,7 @@ namespace Barotrauma
|
||||
private readonly List<Client> bannedClients = new List<Client>();
|
||||
|
||||
private DateTime perSecondUpdate;
|
||||
|
||||
private double KarmaNotificationTime;
|
||||
|
||||
|
||||
public void UpdateClients(IEnumerable<Client> clients, float deltaTime)
|
||||
{
|
||||
if (!GameMain.Server.GameStarted) { return; }
|
||||
@@ -41,32 +45,34 @@ namespace Barotrauma
|
||||
bannedClients.Clear();
|
||||
foreach (Client client in clients)
|
||||
{
|
||||
var clientMemory = GetClientMemory(client);
|
||||
UpdateClient(client, deltaTime);
|
||||
|
||||
if (perSecondUpdate < DateTime.Now)
|
||||
{
|
||||
var clientMemory = GetClientMemory(client);
|
||||
clientMemory.StructureDamagePerSecond = clientMemory.StructureDamageAccumulator;
|
||||
clientMemory.StructureDamageAccumulator = 0.0f;
|
||||
|
||||
var toRemove = clientMemory.LastAttackTime.Where(pair => pair.Value < Timing.TotalTime - AllowedRetaliationTime).Select(pair => pair.Key).ToList();
|
||||
foreach (var lastAttacker in toRemove)
|
||||
{
|
||||
clientMemory.LastAttackTime.Remove(lastAttacker);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (perSecondUpdate < DateTime.Now)
|
||||
{
|
||||
perSecondUpdate = DateTime.Now + new TimeSpan(0, 0, 1);
|
||||
}
|
||||
|
||||
if (TestMode || Timing.TotalTime > KarmaNotificationTime)
|
||||
{
|
||||
foreach (Client client in clients)
|
||||
{
|
||||
SendKarmaNotifications(client);
|
||||
}
|
||||
KarmaNotificationTime = Timing.TotalTime + KarmaNotificationInterval;
|
||||
perSecondUpdate = DateTime.Now + new TimeSpan(0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
foreach (Client bannedClient in bannedClients)
|
||||
{
|
||||
if (bannedClient.KarmaKickCount < KicksBeforeBan)
|
||||
bannedClient.KarmaKickCount++;
|
||||
if (bannedClient.KarmaKickCount <= KicksBeforeBan)
|
||||
{
|
||||
GameMain.Server.KickClient(bannedClient, $"KarmaKicked~[banthreshold]={(int)KickBanThreshold}", resetKarma: true);
|
||||
}
|
||||
@@ -74,15 +80,17 @@ namespace Barotrauma
|
||||
{
|
||||
GameMain.Server.BanClient(bannedClient, $"KarmaBanned~[banthreshold]={(int)KickBanThreshold}", duration: TimeSpan.FromSeconds(GameMain.Server.ServerSettings.AutoBanTime));
|
||||
}
|
||||
bannedClient.KarmaKickCount++;
|
||||
}
|
||||
}
|
||||
|
||||
private void SendKarmaNotifications(Client client, string debugKarmaChangeReason = "")
|
||||
{
|
||||
//send a notification about karma changing if the karma has changed by x% within the last second
|
||||
|
||||
var clientMemory = GetClientMemory(client);
|
||||
float karmaChange = client.Karma - clientMemory.PreviousNotifiedKarma;
|
||||
if (Math.Abs(karmaChange) > KarmaNotificationInterval || (TestMode && Math.Abs(karmaChange) > 2.0f))
|
||||
if (Math.Abs(karmaChange) > 1.0f &&
|
||||
(TestMode || Math.Abs(karmaChange) / clientMemory.PreviousNotifiedKarma > KarmaNotificationInterval / 100.0f))
|
||||
{
|
||||
if (TestMode)
|
||||
{
|
||||
@@ -102,8 +110,8 @@ namespace Barotrauma
|
||||
{
|
||||
GameMain.Server.SendDirectChatMessage(TextManager.Get(karmaChange < 0 ? "KarmaDecreasedUnknownAmount" : "KarmaIncreasedUnknownAmount"), client);
|
||||
}
|
||||
clientMemory.PreviousNotifiedKarma = client.Karma;
|
||||
}
|
||||
clientMemory.PreviousNotifiedKarma = client.Karma;
|
||||
}
|
||||
|
||||
private void UpdateClient(Client client, float deltaTime)
|
||||
@@ -156,7 +164,7 @@ namespace Barotrauma
|
||||
AdjustKarma(client.Character, karmaDecrease, "Disconnected excessive number of wires");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (client.Character?.Info?.Job.Prefab.Identifier == "captain" && client.Character.SelectedConstruction != null)
|
||||
{
|
||||
if (client.Character.SelectedConstruction.GetComponent<Steering>() != null)
|
||||
@@ -180,6 +188,18 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public void OnRoundEnded()
|
||||
{
|
||||
if (ResetKarmaBetweenRounds)
|
||||
{
|
||||
clientMemories.Clear();
|
||||
foreach (Client client in GameMain.Server.ConnectedClients)
|
||||
{
|
||||
client.Karma = Math.Max(50.0f, client.Karma);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnClientDisconnected(Client client)
|
||||
{
|
||||
clientMemories.Remove(client);
|
||||
@@ -210,7 +230,41 @@ namespace Barotrauma
|
||||
isEnemy = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool targetIsHusk = target.CharacterHealth?.GetAffliction<AfflictionHusk>("huskinfection")?.State == AfflictionHusk.InfectionState.Active;
|
||||
bool attackerIsHusk = attacker.CharacterHealth?.GetAffliction<AfflictionHusk>("huskinfection")?.State == AfflictionHusk.InfectionState.Active;
|
||||
//huskified characters count as enemies to healthy characters and vice versa
|
||||
if (targetIsHusk != attackerIsHusk) { isEnemy = true; }
|
||||
|
||||
if (appliedAfflictions != null)
|
||||
{
|
||||
foreach (Affliction affliction in appliedAfflictions)
|
||||
{
|
||||
if (MathUtils.NearlyEqual(affliction.Prefab.KarmaChangeOnApplied, 0.0f)) { continue; }
|
||||
damage -= affliction.Prefab.KarmaChangeOnApplied * affliction.Strength;
|
||||
}
|
||||
}
|
||||
|
||||
Client targetClient = GameMain.Server.ConnectedClients.Find(c => c.Character == target);
|
||||
if (damage > 0 && targetClient != null)
|
||||
{
|
||||
var targetMemory = GetClientMemory(targetClient);
|
||||
targetMemory.LastAttackTime[attacker] = Timing.TotalTime;
|
||||
}
|
||||
|
||||
Client attackerClient = GameMain.Server.ConnectedClients.Find(c => c.Character == attacker);
|
||||
if (attackerClient != null)
|
||||
{
|
||||
//if the attacker has been attacked by the target within the last x seconds, ignore the damage
|
||||
//(= no karma penalty from retaliating against someone who attacked you)
|
||||
var attackerMemory = GetClientMemory(attackerClient);
|
||||
if (attackerMemory.LastAttackTime.ContainsKey(target) &&
|
||||
attackerMemory.LastAttackTime[target] > Timing.TotalTime - AllowedRetaliationTime)
|
||||
{
|
||||
damage = Math.Min(damage, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//attacking/healing clowns has a smaller effect on karma
|
||||
if (target.HasEquippedItem("clownmask") &&
|
||||
target.HasEquippedItem("clowncostume"))
|
||||
@@ -218,15 +272,21 @@ namespace Barotrauma
|
||||
damage *= 0.5f;
|
||||
}
|
||||
|
||||
if (appliedAfflictions != null)
|
||||
//smaller karma penalty for attacking someone who's aiming with a weapon
|
||||
if (damage > 0.0f &&
|
||||
target.IsKeyDown(InputType.Aim) &&
|
||||
target.SelectedItems.Any(it => it != null && (it.GetComponent<MeleeWeapon>() != null || it.GetComponent<RangedWeapon>() != null)))
|
||||
{
|
||||
foreach (Affliction affliction in appliedAfflictions)
|
||||
{
|
||||
if (MathUtils.NearlyEqual(affliction.Prefab.KarmaChangeOnApplied, 0.0f)) { continue; }
|
||||
damage -= affliction.Prefab.KarmaChangeOnApplied * affliction.Strength;
|
||||
}
|
||||
damage *= 0.5f;
|
||||
}
|
||||
|
||||
//damage scales according to the karma of the target
|
||||
//(= smaller karma penalty from attacking someone who has a low karma)
|
||||
if (damage > 0 && targetClient != null)
|
||||
{
|
||||
damage *= MathUtils.InverseLerp(0.0f, 50.0f, targetClient.Karma);
|
||||
}
|
||||
|
||||
if (isEnemy)
|
||||
{
|
||||
if (damage > 0)
|
||||
|
||||
+16
-5
@@ -37,8 +37,8 @@ namespace Barotrauma.Networking
|
||||
Retries = 0;
|
||||
SteamID = null;
|
||||
PasswordSalt = null;
|
||||
UpdateTime = Timing.TotalTime;
|
||||
TimeOut = 20.0;
|
||||
UpdateTime = Timing.TotalTime+Timing.Step*3.0;
|
||||
TimeOut = NetworkConnection.TimeoutThreshold;
|
||||
AuthSessionStarted = false;
|
||||
}
|
||||
}
|
||||
@@ -319,7 +319,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (netServer == null) { return; }
|
||||
|
||||
pendingClient.TimeOut = 20.0;
|
||||
pendingClient.TimeOut = NetworkConnection.TimeoutThreshold;
|
||||
|
||||
ConnectionInitialization initializationStep = (ConnectionInitialization)inc.ReadByte();
|
||||
|
||||
@@ -327,6 +327,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (pendingClient.InitializationStep != initializationStep) return;
|
||||
|
||||
pendingClient.UpdateTime = Timing.TotalTime + Timing.Step;
|
||||
|
||||
switch (initializationStep)
|
||||
{
|
||||
case ConnectionInitialization.SteamTicketAndVersion:
|
||||
@@ -522,6 +524,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
OnInitializationComplete?.Invoke(newConnection);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -554,6 +557,10 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
NetSendResult result = netServer.SendMessage(outMsg, pendingClient.Connection, NetDeliveryMethod.ReliableUnordered);
|
||||
if (result != NetSendResult.Sent && result != NetSendResult.Queued)
|
||||
{
|
||||
DebugConsole.NewMessage("Failed to send initialization step " + pendingClient.InitializationStep.ToString() + " to pending client: " + result.ToString(), Microsoft.Xna.Framework.Color.Yellow);
|
||||
}
|
||||
//DebugConsole.NewMessage("sent update to pending client: "+result);
|
||||
}
|
||||
|
||||
@@ -588,7 +595,7 @@ namespace Barotrauma.Networking
|
||||
if (netServer == null) { return; }
|
||||
|
||||
PendingClient pendingClient = pendingClients.Find(c => c.SteamID == steamID);
|
||||
DebugConsole.NewMessage(steamID + " validation: " + status+", "+(pendingClient!=null));
|
||||
DebugConsole.Log(steamID + " validation: " + status+", "+(pendingClient!=null));
|
||||
|
||||
if (pendingClient == null)
|
||||
{
|
||||
@@ -653,7 +660,11 @@ namespace Barotrauma.Networking
|
||||
lidgrenMsg.Write((UInt16)length);
|
||||
lidgrenMsg.Write(msgData, 0, length);
|
||||
|
||||
netServer.SendMessage(lidgrenMsg, lidgrenConn.NetConnection, lidgrenDeliveryMethod);
|
||||
NetSendResult result = netServer.SendMessage(lidgrenMsg, lidgrenConn.NetConnection, lidgrenDeliveryMethod);
|
||||
if (result != NetSendResult.Sent && result != NetSendResult.Queued)
|
||||
{
|
||||
DebugConsole.NewMessage("Failed to send message to "+conn.Name+": " + result.ToString(), Microsoft.Xna.Framework.Color.Yellow);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Disconnect(NetworkConnection conn,string msg=null)
|
||||
|
||||
+26
-8
@@ -40,14 +40,14 @@ namespace Barotrauma.Networking
|
||||
Retries = 0;
|
||||
SteamID = steamId;
|
||||
PasswordSalt = null;
|
||||
UpdateTime = Timing.TotalTime;
|
||||
TimeOut = 20.0;
|
||||
UpdateTime = Timing.TotalTime+Timing.Step*3.0;
|
||||
TimeOut = NetworkConnection.TimeoutThreshold;
|
||||
AuthSessionStarted = false;
|
||||
}
|
||||
|
||||
public void Heartbeat()
|
||||
{
|
||||
TimeOut = 5.0;
|
||||
TimeOut = NetworkConnection.TimeoutThreshold;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (isServerMessage)
|
||||
{
|
||||
DebugConsole.ThrowError("got server message from" + senderSteamId.ToString());
|
||||
DebugConsole.ThrowError("Got server message from" + senderSteamId.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -346,7 +346,11 @@ namespace Barotrauma.Networking
|
||||
NetOutgoingMessage outMsg = netServer.CreateMessage();
|
||||
outMsg.Write(OwnerSteamID);
|
||||
outMsg.Write((byte)(PacketHeader.IsConnectionInitializationStep | PacketHeader.IsServerMessage));
|
||||
netServer.SendMessage(outMsg, netConnection, NetDeliveryMethod.ReliableUnordered);
|
||||
NetSendResult result = netServer.SendMessage(outMsg, netConnection, NetDeliveryMethod.ReliableUnordered);
|
||||
if (result != NetSendResult.Sent && result != NetSendResult.Queued)
|
||||
{
|
||||
DebugConsole.NewMessage("Failed to send connection confirmation message to owner: " + result.ToString(), Microsoft.Xna.Framework.Color.Yellow);
|
||||
}
|
||||
break;
|
||||
case NetConnectionStatus.Disconnected:
|
||||
DebugConsole.NewMessage("Owner disconnected: closing the server...");
|
||||
@@ -360,7 +364,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (netServer == null) { return; }
|
||||
|
||||
pendingClient.TimeOut = 20.0;
|
||||
pendingClient.TimeOut = NetworkConnection.TimeoutThreshold;
|
||||
|
||||
ConnectionInitialization initializationStep = (ConnectionInitialization)inc.ReadByte();
|
||||
|
||||
@@ -368,6 +372,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (pendingClient.InitializationStep != initializationStep) return;
|
||||
|
||||
pendingClient.UpdateTime = Timing.TotalTime+Timing.Step;
|
||||
|
||||
switch (initializationStep)
|
||||
{
|
||||
case ConnectionInitialization.SteamTicketAndVersion:
|
||||
@@ -549,6 +555,10 @@ namespace Barotrauma.Networking
|
||||
if (netConnection != null)
|
||||
{
|
||||
NetSendResult result = netServer.SendMessage(outMsg, netConnection, NetDeliveryMethod.ReliableUnordered);
|
||||
if (result != NetSendResult.Sent && result != NetSendResult.Queued)
|
||||
{
|
||||
DebugConsole.NewMessage("Failed to send initialization step " + pendingClient.InitializationStep.ToString() + " to pending client: " + result.ToString(), Microsoft.Xna.Framework.Color.Yellow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -609,7 +619,11 @@ namespace Barotrauma.Networking
|
||||
lidgrenMsg.Write((UInt16)length);
|
||||
lidgrenMsg.Write(msgData, 0, length);
|
||||
|
||||
netServer.SendMessage(lidgrenMsg, netConnection, lidgrenDeliveryMethod);
|
||||
NetSendResult result = netServer.SendMessage(lidgrenMsg, netConnection, lidgrenDeliveryMethod);
|
||||
if (result != NetSendResult.Sent && result != NetSendResult.Queued)
|
||||
{
|
||||
DebugConsole.NewMessage("Failed to send message to " + conn.Name + ": " + result.ToString(), Microsoft.Xna.Framework.Color.Yellow);
|
||||
}
|
||||
}
|
||||
|
||||
private void SendDisconnectMessage(UInt64 steamId, string msg)
|
||||
@@ -622,7 +636,11 @@ namespace Barotrauma.Networking
|
||||
lidgrenMsg.Write((byte)(PacketHeader.IsDisconnectMessage | PacketHeader.IsServerMessage));
|
||||
lidgrenMsg.Write(msg);
|
||||
|
||||
netServer.SendMessage(lidgrenMsg, netConnection, NetDeliveryMethod.ReliableUnordered);
|
||||
NetSendResult result = netServer.SendMessage(lidgrenMsg, netConnection, NetDeliveryMethod.ReliableUnordered);
|
||||
if (result != NetSendResult.Sent && result != NetSendResult.Queued)
|
||||
{
|
||||
DebugConsole.NewMessage("Failed to send disconnect message to " + Steam.SteamManager.SteamIDUInt64ToString(steamId) + ": " + result.ToString(), Microsoft.Xna.Framework.Color.Yellow);
|
||||
}
|
||||
}
|
||||
|
||||
private void Disconnect(NetworkConnection conn, string msg, bool sendDisconnectMessage)
|
||||
|
||||
@@ -327,7 +327,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
public void ServerWrite(IWriteMessage msg, Client c, object[] extraData = null)
|
||||
{
|
||||
msg.WriteRangedIntegerDeprecated(0, Enum.GetNames(typeof(State)).Length, (int)CurrentState);
|
||||
msg.WriteRangedInteger((int)CurrentState, 0, Enum.GetNames(typeof(State)).Length);
|
||||
|
||||
switch (CurrentState)
|
||||
{
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace Barotrauma.Networking
|
||||
outMsg.Write(HasPassword);
|
||||
outMsg.Write(isPublic);
|
||||
outMsg.WritePadBits();
|
||||
outMsg.WriteRangedIntegerDeprecated(1, 60, TickRate);
|
||||
outMsg.WriteRangedInteger(TickRate, 1, 60);
|
||||
|
||||
WriteExtraCargo(outMsg);
|
||||
|
||||
@@ -236,8 +236,8 @@ namespace Barotrauma.Networking
|
||||
GameMain.NetLobbyScreen.SetLevelDifficulty(selectedLevelDifficulty);
|
||||
|
||||
GameMain.NetLobbyScreen.SetTraitorsEnabled(traitorsEnabled);
|
||||
|
||||
string[] allowedClientNameCharsStr = doc.Root.GetAttributeStringArray("AllowedClientNameChars",
|
||||
|
||||
string[] defaultAllowedClientNameChars =
|
||||
new string[] {
|
||||
"32-33",
|
||||
"38-46",
|
||||
@@ -248,8 +248,16 @@ namespace Barotrauma.Networking
|
||||
"95-122",
|
||||
"192-255",
|
||||
"384-591",
|
||||
"1024-1279"
|
||||
});
|
||||
"1024-1279",
|
||||
"19968-40959","13312-19903","131072-173791","173824-178207","178208-183983","63744-64255","194560-195103" //CJK
|
||||
};
|
||||
|
||||
string[] allowedClientNameCharsStr = doc.Root.GetAttributeStringArray("AllowedClientNameChars", defaultAllowedClientNameChars);
|
||||
if (doc.Root.GetAttributeString("AllowedClientNameChars", "") == "65-90,97-122,48-59")
|
||||
{
|
||||
allowedClientNameCharsStr = defaultAllowedClientNameChars;
|
||||
}
|
||||
|
||||
foreach (string allowedClientNameCharRange in allowedClientNameCharsStr)
|
||||
{
|
||||
string[] splitRange = allowedClientNameCharRange.Split('-');
|
||||
@@ -275,7 +283,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
|
||||
if (min > -1 && max > -1) AllowedClientNameChars.Add(new Pair<int, int>(min, max));
|
||||
if (min > -1 && max > -1) { AllowedClientNameChars.Add(new Pair<int, int>(min, max)); }
|
||||
}
|
||||
|
||||
AllowedRandomMissionTypes = new List<MissionType>();
|
||||
|
||||
Reference in New Issue
Block a user