v0.11.0.9
This commit is contained in:
@@ -26,6 +26,11 @@ namespace Barotrauma
|
||||
Vector2 comparePosition = recipient.SpectatePos == null ? recipient.Character.WorldPosition : recipient.SpectatePos.Value;
|
||||
|
||||
float distance = Vector2.Distance(comparePosition, WorldPosition);
|
||||
if (recipient.Character?.ViewTarget != null)
|
||||
{
|
||||
distance = Math.Min(distance, Vector2.Distance(recipient.Character.ViewTarget.WorldPosition, WorldPosition));
|
||||
}
|
||||
|
||||
float priority = 1.0f - MathUtils.InverseLerp(
|
||||
NetConfig.HighPrioCharacterPositionUpdateDistance,
|
||||
NetConfig.LowPrioCharacterPositionUpdateDistance,
|
||||
|
||||
@@ -1708,14 +1708,15 @@ namespace Barotrauma
|
||||
(Client client, Vector2 cursorWorldPos, string[] args) =>
|
||||
{
|
||||
Vector2 explosionPos = cursorWorldPos;
|
||||
float range = 500, force = 10, damage = 50, structureDamage = 10, itemDamage = 100, empStrength = 0.0f; ;
|
||||
float range = 500, force = 10, damage = 50, structureDamage = 10, itemDamage = 100, empStrength = 0.0f, ballastFloraStrength = 50f;
|
||||
if (args.Length > 0) float.TryParse(args[0], out range);
|
||||
if (args.Length > 1) float.TryParse(args[1], out force);
|
||||
if (args.Length > 2) float.TryParse(args[2], out damage);
|
||||
if (args.Length > 3) float.TryParse(args[3], out structureDamage);
|
||||
if (args.Length > 4) float.TryParse(args[4], out itemDamage);
|
||||
if (args.Length > 5) float.TryParse(args[5], out empStrength);
|
||||
new Explosion(range, force, damage, structureDamage, itemDamage, empStrength).Explode(explosionPos, null);
|
||||
if (args.Length > 6) float.TryParse(args[6], out ballastFloraStrength);
|
||||
new Explosion(range, force, damage, structureDamage, itemDamage, empStrength, ballastFloraStrength).Explode(explosionPos, null);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -2155,6 +2156,43 @@ namespace Barotrauma
|
||||
}
|
||||
);
|
||||
|
||||
commands.Add(new Command("readycheck", "Commence a ready check.", (string[] args) =>
|
||||
{
|
||||
if (Screen.Selected == GameMain.GameScreen && GameMain.NetworkMember != null)
|
||||
{
|
||||
CrewManager crewManager = GameMain.GameSession?.CrewManager;
|
||||
if (crewManager != null && crewManager.ActiveReadyCheck == null)
|
||||
{
|
||||
ReadyCheck.StartReadyCheck("");
|
||||
NewMessage("Attempted to commence a ready check.", Color.Green);
|
||||
return;
|
||||
}
|
||||
NewMessage("A ready check is already running.", Color.Red);
|
||||
return;
|
||||
}
|
||||
NewMessage("Ready checks cannot be commenced in the lobby.", Color.Red);
|
||||
}));
|
||||
|
||||
AssignOnClientRequestExecute(
|
||||
"readycheck",
|
||||
(senderClient, cursorWorldPos, args) =>
|
||||
{
|
||||
if (Screen.Selected == GameMain.GameScreen && GameMain.NetworkMember != null && !(GameMain.GameSession?.GameMode?.IsSinglePlayer ?? true))
|
||||
{
|
||||
CrewManager crewManager = GameMain.GameSession?.CrewManager;
|
||||
if (crewManager != null && crewManager.ActiveReadyCheck == null)
|
||||
{
|
||||
ReadyCheck.StartReadyCheck(senderClient.Name, senderClient);
|
||||
GameMain.Server.SendConsoleMessage("Attempted to commence a ready check.", senderClient);
|
||||
return;
|
||||
}
|
||||
GameMain.Server.SendConsoleMessage("A ready check is already running.", senderClient);
|
||||
return;
|
||||
}
|
||||
GameMain.Server.SendConsoleMessage("Ready checks cannot be commenced in the lobby.", senderClient);
|
||||
}
|
||||
);
|
||||
|
||||
#if DEBUG
|
||||
commands.Add(new Command("spamevents", "A debug command that creates a ton of entity events.", (string[] args) =>
|
||||
{
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using Barotrauma.Networking;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
partial class BeaconMission : Mission
|
||||
{
|
||||
public override void ServerWriteInitial(IWriteMessage msg, Client c)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace Barotrauma
|
||||
foreach (Item item in items)
|
||||
{
|
||||
item.WriteSpawnData(msg,
|
||||
item.OriginalID,
|
||||
item.ID,
|
||||
parentInventoryIDs.ContainsKey(item) ? parentInventoryIDs[item] : Entity.NullEntityID,
|
||||
parentItemContainerIndices.ContainsKey(item) ? parentItemContainerIndices[item] : (byte)0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using Barotrauma.Networking;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
partial class MineralMission : Mission
|
||||
{
|
||||
public override void ServerWriteInitial(IWriteMessage msg, Client c)
|
||||
{
|
||||
foreach (var kvp in SpawnedResources)
|
||||
{
|
||||
msg.Write((byte)kvp.Value.Count);
|
||||
var rotation = ResourceClusters[kvp.Key].Second;
|
||||
msg.Write(rotation);
|
||||
foreach (var r in kvp.Value)
|
||||
{
|
||||
r.WriteSpawnData(msg, r.ID, Entity.NullEntityID, 0);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var kvp in RelevantLevelResources)
|
||||
{
|
||||
msg.Write(kvp.Key);
|
||||
msg.Write((byte)kvp.Value.Length);
|
||||
foreach (var i in kvp.Value)
|
||||
{
|
||||
msg.Write(i.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ namespace Barotrauma
|
||||
msg.Write((byte)monsters.Count);
|
||||
foreach (Character monster in monsters)
|
||||
{
|
||||
monster.WriteSpawnData(msg, monster.OriginalID, restrictMessageSize: false);
|
||||
monster.WriteSpawnData(msg, monster.ID, restrictMessageSize: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using Barotrauma.Networking;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
partial class NestMission : Mission
|
||||
{
|
||||
public override void ServerWriteInitial(IWriteMessage msg, Client c)
|
||||
{
|
||||
msg.Write(nestPosition.X);
|
||||
msg.Write(nestPosition.Y);
|
||||
msg.Write((ushort)items.Count);
|
||||
foreach (Item item in items)
|
||||
{
|
||||
item.WriteSpawnData(msg, item.ID, Entity.NullEntityID, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,11 +18,11 @@ namespace Barotrauma
|
||||
msg.Write(usedExistingItem);
|
||||
if (usedExistingItem)
|
||||
{
|
||||
msg.Write(item.OriginalID);
|
||||
msg.Write(item.ID);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.WriteSpawnData(msg, item.OriginalID, originalInventoryID, originalItemContainerIndex);
|
||||
item.WriteSpawnData(msg, item.ID, originalInventoryID, originalItemContainerIndex);
|
||||
}
|
||||
|
||||
msg.Write((byte)executedEffectIndices.Count);
|
||||
|
||||
@@ -103,6 +103,7 @@ namespace Barotrauma
|
||||
MapEntityPrefab.Init();
|
||||
MapGenerationParams.Init();
|
||||
LevelGenerationParams.LoadPresets();
|
||||
CaveGenerationParams.LoadPresets();
|
||||
OutpostGenerationParams.LoadPresets();
|
||||
EventSet.LoadPrefabs();
|
||||
Order.Init();
|
||||
@@ -117,6 +118,7 @@ namespace Barotrauma
|
||||
NPCConversation.LoadAll(GetFilesOfType(ContentType.NPCConversations));
|
||||
ItemAssemblyPrefab.LoadAll();
|
||||
LevelObjectPrefab.LoadAll();
|
||||
BallastFloraPrefab.LoadAll(GetFilesOfType(ContentType.MapCreature));
|
||||
|
||||
GameModePreset.Init();
|
||||
DecalManager = new DecalManager();
|
||||
|
||||
+2
-2
@@ -30,9 +30,9 @@ namespace Barotrauma
|
||||
return other.SteamID == SteamID && other.ClientEndPoint == ClientEndPoint;
|
||||
}
|
||||
|
||||
public void SpawnInventoryItems(CharacterInfo characterInfo, Inventory inventory)
|
||||
public void SpawnInventoryItems(Character character, Inventory inventory)
|
||||
{
|
||||
characterInfo.SpawnInventoryItems(inventory, itemData);
|
||||
character.SpawnInventoryItems(inventory, itemData);
|
||||
}
|
||||
|
||||
public void ApplyHealthData(CharacterInfo characterInfo, Character character)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Barotrauma
|
||||
{
|
||||
partial class MissionMode : GameMode
|
||||
abstract partial class MissionMode : GameMode
|
||||
{
|
||||
public override void ShowStartMessage()
|
||||
{
|
||||
|
||||
+3
-3
@@ -216,6 +216,9 @@ namespace Barotrauma
|
||||
|
||||
characterData.ForEach(cd => cd.HasSpawned = false);
|
||||
|
||||
petsElement = new XElement("pets");
|
||||
PetBehavior.SavePets(petsElement);
|
||||
|
||||
//remove all items that are in someone's inventory
|
||||
foreach (Character c in Character.CharacterList)
|
||||
{
|
||||
@@ -237,9 +240,6 @@ namespace Barotrauma
|
||||
c.Inventory.DeleteAllItems();
|
||||
}
|
||||
|
||||
petsElement = new XElement("pets");
|
||||
PetBehavior.SavePets(petsElement);
|
||||
|
||||
yield return CoroutineStatus.Running;
|
||||
|
||||
if (leavingSub != Submarine.MainSub && !leavingSub.DockedTo.Contains(Submarine.MainSub))
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Barotrauma.Networking;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
internal partial class ReadyCheck
|
||||
{
|
||||
private static List<Client> ActivePlayers => GameMain.Server.ConnectedClients.Where(c => c != null && !c.Spectating && c.InGame).ToList();
|
||||
|
||||
public void InitializeReadyCheck(string author, Client? sender = null)
|
||||
{
|
||||
foreach (Client client in ActivePlayers)
|
||||
{
|
||||
if (client != null && !client.Spectating)
|
||||
{
|
||||
IWriteMessage msg = new WriteOnlyMessage();
|
||||
msg.Write((byte) ServerPacketHeader.READY_CHECK);
|
||||
msg.Write((byte) ReadyCheckState.Start);
|
||||
msg.Write(endTime);
|
||||
msg.Write(author);
|
||||
|
||||
if (sender != null)
|
||||
{
|
||||
msg.Write(true);
|
||||
msg.Write(sender.ID);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.Write(false);
|
||||
}
|
||||
|
||||
msg.Write((ushort) ActivePlayers.Count);
|
||||
foreach (byte clientId in Clients.Keys)
|
||||
{
|
||||
msg.Write(clientId);
|
||||
}
|
||||
|
||||
GameMain.Server.ServerPeer.Send(msg, client.Connection, DeliveryMethod.Reliable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateReadyCheck(byte otherClient, ReadyStatus state)
|
||||
{
|
||||
if (Clients.All(pair => pair.Value != ReadyStatus.Unanswered))
|
||||
{
|
||||
EndReadyCheck();
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (Client client in ActivePlayers)
|
||||
{
|
||||
IWriteMessage msg = new WriteOnlyMessage();
|
||||
msg.Write((byte) ServerPacketHeader.READY_CHECK);
|
||||
msg.Write((byte) ReadyCheckState.Update);
|
||||
msg.Write(time); // sync time
|
||||
msg.Write((byte) state);
|
||||
msg.Write(otherClient);
|
||||
GameMain.Server.ServerPeer.Send(msg, client.Connection, DeliveryMethod.Reliable);
|
||||
}
|
||||
}
|
||||
|
||||
partial void EndReadyCheck()
|
||||
{
|
||||
if (IsFinished) { return; }
|
||||
IsFinished = true;
|
||||
foreach (Client client in ActivePlayers)
|
||||
{
|
||||
if (client != null && !client.Spectating)
|
||||
{
|
||||
IWriteMessage msg = new WriteOnlyMessage();
|
||||
msg.Write((byte) ServerPacketHeader.READY_CHECK);
|
||||
msg.Write((byte) ReadyCheckState.End);
|
||||
msg.Write((ushort) Clients.Count);
|
||||
foreach (var (id, state) in Clients)
|
||||
{
|
||||
msg.Write(id);
|
||||
msg.Write((byte) state);
|
||||
}
|
||||
|
||||
GameMain.Server.ServerPeer.Send(msg, client.Connection, DeliveryMethod.Reliable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ServerRead(IReadMessage inc, Client client)
|
||||
{
|
||||
ReadyCheckState state = (ReadyCheckState) inc.ReadByte();
|
||||
ReadyCheck? readyCheck = GameMain.GameSession?.CrewManager?.ActiveReadyCheck;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case ReadyCheckState.Start when readyCheck == null:
|
||||
StartReadyCheck(client.Name, client);
|
||||
break;
|
||||
case ReadyCheckState.Update when readyCheck != null:
|
||||
|
||||
ReadyStatus status = (ReadyStatus) inc.ReadByte();
|
||||
if (!readyCheck.Clients.ContainsKey(client.ID)) { return; }
|
||||
|
||||
readyCheck.Clients[client.ID] = status;
|
||||
readyCheck.UpdateReadyCheck(client.ID, status);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void StartReadyCheck(string author, Client? sender = null)
|
||||
{
|
||||
if (GameMain.GameSession?.CrewManager == null || GameMain.GameSession.CrewManager.ActiveReadyCheck != null) { return; }
|
||||
|
||||
List<Client> connectedClients = GameMain.Server.ConnectedClients;
|
||||
ReadyCheck newReadyCheck = new ReadyCheck(connectedClients.Where(c => !c.Spectating).Select(c => c.ID).ToList(), 30);
|
||||
GameMain.GameSession.CrewManager.ActiveReadyCheck = newReadyCheck;
|
||||
newReadyCheck.InitializeReadyCheck(author, sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ namespace Barotrauma.Items.Components
|
||||
msg.Write(isBroken);
|
||||
msg.Write(extraData.Length == 3 ? (bool)extraData[2] : false); //forced open
|
||||
msg.Write(isStuck);
|
||||
msg.Write(isJammed);
|
||||
msg.WriteRangedSingle(stuck, 0.0f, 100.0f, 8);
|
||||
msg.Write(lastUser == null ? (UInt16)0 : lastUser.ID);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
if (pumpSpeedLockTimer <= 0.0f)
|
||||
{
|
||||
targetLevel = null;
|
||||
TargetLevel = null;
|
||||
}
|
||||
|
||||
FlowPercentage = newFlowPercentage;
|
||||
@@ -41,6 +41,16 @@ namespace Barotrauma.Items.Components
|
||||
//flowpercentage can only be adjusted at 10% intervals -> no need for more accuracy than this
|
||||
msg.WriteRangedInteger((int)(flowPercentage / 10.0f), -10, 10);
|
||||
msg.Write(IsActive);
|
||||
msg.Write(Hijacked);
|
||||
if (TargetLevel != null)
|
||||
{
|
||||
msg.Write(true);
|
||||
msg.Write(TargetLevel.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.Write(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,20 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
partial class Projectile : ItemComponent
|
||||
{
|
||||
private float launchRot;
|
||||
|
||||
public void ServerWrite(IWriteMessage msg, Client c, object[] extraData = null)
|
||||
{
|
||||
bool launch = extraData.Length > 2 && (bool)extraData[2];
|
||||
msg.Write(launch);
|
||||
if (launch)
|
||||
{
|
||||
msg.Write(User.ID);
|
||||
msg.Write(launchPos.X);
|
||||
msg.Write(launchPos.Y);
|
||||
msg.Write(launchRot);
|
||||
}
|
||||
|
||||
bool stuck = StickTarget != null && !item.Removed && !StickTargetRemoved();
|
||||
msg.Write(stuck);
|
||||
if (stuck)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Barotrauma.Networking;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
@@ -17,15 +19,70 @@ namespace Barotrauma.Items.Components
|
||||
GameServer.Log(GameServer.CharacterLogName(c.Character) + " entered \"" + newOutputValue + "\" on " + item.Name,
|
||||
ServerLog.MessageType.ItemInteraction);
|
||||
OutputValue = newOutputValue;
|
||||
ShowOnDisplay(newOutputValue);
|
||||
item.SendSignal(0, newOutputValue, "signal_out", null);
|
||||
item.CreateServerEvent(this);
|
||||
}
|
||||
}
|
||||
|
||||
partial void ShowOnDisplay(string input)
|
||||
{
|
||||
messageHistory.Add(input);
|
||||
while (messageHistory.Count > MaxMessages)
|
||||
{
|
||||
messageHistory.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void SyncHistory()
|
||||
{
|
||||
//split too long messages to multiple parts
|
||||
foreach (string str in messageHistory)
|
||||
{
|
||||
string msgToSend = str;
|
||||
if (msgToSend.Length > MaxMessageLength)
|
||||
{
|
||||
List<string> splitMessage = msgToSend.Split(' ').ToList();
|
||||
for (int i = 0; i < splitMessage.Count; i++)
|
||||
{
|
||||
if (splitMessage[i].Length > MaxMessageLength)
|
||||
{
|
||||
string temp = splitMessage[i];
|
||||
splitMessage[i] = temp.Substring(0, MaxMessageLength);
|
||||
splitMessage.Insert(i + 1, temp.Substring(MaxMessageLength, temp.Length - MaxMessageLength));
|
||||
}
|
||||
}
|
||||
while (msgToSend.Length > MaxMessageLength)
|
||||
{
|
||||
string tempMsg = "";
|
||||
do
|
||||
{
|
||||
tempMsg += splitMessage[0];
|
||||
splitMessage.RemoveAt(0);
|
||||
if (!splitMessage.Any()) { break; }
|
||||
tempMsg += " ";
|
||||
} while (tempMsg.Length + splitMessage[0].Length < MaxMessageLength);
|
||||
item.CreateServerEvent(this, new string[] { msgToSend });
|
||||
msgToSend = msgToSend.Remove(0, tempMsg.Length);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(msgToSend))
|
||||
{
|
||||
item.CreateServerEvent(this, new string[] { msgToSend });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ServerWrite(IWriteMessage msg, Client c, object[] extraData = null)
|
||||
{
|
||||
msg.Write(OutputValue);
|
||||
if (extraData.Length > 2 && extraData[2] is string str)
|
||||
{
|
||||
msg.Write(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.Write(OutputValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -238,7 +238,7 @@ namespace Barotrauma
|
||||
|
||||
public void WriteSpawnData(IWriteMessage msg, UInt16 entityID, UInt16 originalInventoryID, byte originalItemContainerIndex)
|
||||
{
|
||||
if (GameMain.Server == null) return;
|
||||
if (GameMain.Server == null) { return; }
|
||||
|
||||
msg.Write(Prefab.OriginalName);
|
||||
msg.Write(Prefab.Identifier);
|
||||
@@ -282,9 +282,16 @@ namespace Barotrauma
|
||||
msg.Write(tagsChanged);
|
||||
if (tagsChanged)
|
||||
{
|
||||
msg.Write(Tags);
|
||||
string[] splitTags = Tags.Split(',');
|
||||
msg.Write(string.Join(',', splitTags.Where(t => !prefab.Tags.Contains(t))));
|
||||
msg.Write(string.Join(',', prefab.Tags.Where(t => !splitTags.Contains(t))));
|
||||
}
|
||||
var nameTag = GetComponent<NameTag>();
|
||||
msg.Write(nameTag != null);
|
||||
if (nameTag != null)
|
||||
{
|
||||
msg.Write(nameTag.WrittenName ?? "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
partial void UpdateNetPosition(float deltaTime)
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
using Barotrauma.Items.Components;
|
||||
using Barotrauma.Networking;
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.MapCreatures.Behavior
|
||||
{
|
||||
partial class BallastFloraBehavior
|
||||
{
|
||||
partial void LoadPrefab(XElement element)
|
||||
{
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||
{
|
||||
case "branchsprite":
|
||||
case "hiddenflowersprite":
|
||||
break;
|
||||
case "flowersprite":
|
||||
flowerVariants++;
|
||||
break;
|
||||
case "leafsprite":
|
||||
leafVariants++;
|
||||
break;
|
||||
case "targets":
|
||||
LoadTargets(subElement);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void ServerWriteSpawn(IWriteMessage msg)
|
||||
{
|
||||
msg.Write(Prefab.Identifier);
|
||||
msg.Write(Offset.X);
|
||||
msg.Write(Offset.Y);
|
||||
}
|
||||
|
||||
public void ServerWriteBranchGrowth(IWriteMessage msg, BallastFloraBranch branch, int parentId = -1)
|
||||
{
|
||||
var (x, y) = branch.Position;
|
||||
msg.Write(parentId);
|
||||
msg.Write((int)branch.ID);
|
||||
msg.WriteRangedInteger((byte) branch.Type, 0b0000, 0b1111);
|
||||
msg.WriteRangedInteger((byte) branch.Sides, 0b0000, 0b1111);
|
||||
msg.WriteRangedInteger(branch.FlowerConfig.Serialize(), 0, 0xFFF);
|
||||
msg.WriteRangedInteger(branch.LeafConfig.Serialize(), 0, 0xFFF);
|
||||
msg.Write((ushort) branch.MaxHealth);
|
||||
msg.Write((int) (x / VineTile.Size));
|
||||
msg.Write((int) (y / VineTile.Size));
|
||||
}
|
||||
|
||||
public void ServerWriteBranchDamage(IWriteMessage msg, BallastFloraBranch branch, float damage)
|
||||
{
|
||||
msg.Write((int)branch.ID);
|
||||
msg.Write(damage);
|
||||
msg.Write(branch.Health);
|
||||
}
|
||||
|
||||
public void ServerWriteInfect(IWriteMessage msg, UInt16 itemID, bool infect, BallastFloraBranch infector = null)
|
||||
{
|
||||
msg.Write(itemID);
|
||||
msg.Write(infect);
|
||||
if (infect)
|
||||
{
|
||||
msg.Write(infector?.ID ?? -1);
|
||||
}
|
||||
}
|
||||
|
||||
public void ServerWriteBranchRemove(IWriteMessage msg, BallastFloraBranch branch)
|
||||
{
|
||||
msg.Write(branch.ID);
|
||||
}
|
||||
|
||||
public void SendNetworkMessage(params object[] extraData)
|
||||
{
|
||||
GameMain.Server.CreateEntityEvent(Parent, extraData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Barotrauma.MapCreatures.Behavior;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -70,6 +71,39 @@ namespace Barotrauma
|
||||
|
||||
public void ServerWrite(IWriteMessage message, Client c, object[] extraData = null)
|
||||
{
|
||||
if (extraData != null && extraData.Length >= 2 && extraData[0] is BallastFloraBehavior behavior && extraData[1] is BallastFloraBehavior.NetworkHeader header)
|
||||
{
|
||||
message.Write(true);
|
||||
message.Write((byte)header);
|
||||
|
||||
switch (header)
|
||||
{
|
||||
case BallastFloraBehavior.NetworkHeader.Spawn:
|
||||
behavior.ServerWriteSpawn(message);
|
||||
break;
|
||||
case BallastFloraBehavior.NetworkHeader.Kill:
|
||||
break;
|
||||
case BallastFloraBehavior.NetworkHeader.BranchCreate when extraData.Length >= 4 && extraData[2] is BallastFloraBranch branch && extraData[3] is int parentId:
|
||||
behavior.ServerWriteBranchGrowth(message, branch, parentId);
|
||||
break;
|
||||
case BallastFloraBehavior.NetworkHeader.BranchDamage when extraData.Length >= 4 && extraData[2] is BallastFloraBranch branch && extraData[3] is float damage:
|
||||
behavior.ServerWriteBranchDamage(message, branch, damage);
|
||||
break;
|
||||
case BallastFloraBehavior.NetworkHeader.BranchRemove when extraData.Length >= 3 && extraData[2] is BallastFloraBranch branch:
|
||||
behavior.ServerWriteBranchRemove(message, branch);
|
||||
break;
|
||||
case BallastFloraBehavior.NetworkHeader.Infect when extraData.Length >= 4 && extraData[2] is UInt16 itemID && extraData[3] is bool infect:
|
||||
BallastFloraBranch infector = null;
|
||||
if (extraData.Length >= 5 && extraData[4] is BallastFloraBranch b) { infector = b; }
|
||||
behavior.ServerWriteInfect(message, itemID, infect, infector);
|
||||
break;
|
||||
}
|
||||
|
||||
message.Write(behavior.PowerConsumptionTimer);
|
||||
return;
|
||||
}
|
||||
|
||||
message.Write(false);
|
||||
message.WriteRangedSingle(MathHelper.Clamp(waterVolume / Volume, 0.0f, 1.5f), 0.0f, 1.5f, 8);
|
||||
message.WriteRangedSingle(MathHelper.Clamp(OxygenPercentage, 0.0f, 100.0f), 0.0f, 100.0f, 8);
|
||||
|
||||
|
||||
@@ -127,8 +127,7 @@ namespace Barotrauma.Networking
|
||||
if (IPAddress.IsLoopback(IP)) { return false; }
|
||||
var bannedPlayer = bannedPlayers.Find(bp =>
|
||||
bp.CompareTo(IP) ||
|
||||
(steamID > 0 && bp.SteamID == steamID) ||
|
||||
(SteamManager.SteamIDStringToUInt64(bp.EndPoint) == steamID));
|
||||
(steamID > 0 && (bp.SteamID == steamID || SteamManager.SteamIDStringToUInt64(bp.EndPoint) == steamID)));
|
||||
reason = bannedPlayer?.Reason;
|
||||
return bannedPlayer != null;
|
||||
}
|
||||
|
||||
@@ -18,12 +18,15 @@ namespace Barotrauma.Networking
|
||||
Entity orderTargetEntity = null;
|
||||
OrderChatMessage orderMsg = null;
|
||||
OrderTarget orderTargetPosition = null;
|
||||
Order.OrderTargetType orderTargetType = Order.OrderTargetType.Entity;
|
||||
int? wallSectionIndex = null;
|
||||
if (type == ChatMessageType.Order)
|
||||
{
|
||||
int orderIndex = msg.ReadByte();
|
||||
orderTargetCharacter = Entity.FindEntityByID(msg.ReadUInt16()) as Character;
|
||||
orderTargetEntity = Entity.FindEntityByID(msg.ReadUInt16()) as Entity;
|
||||
int orderOptionIndex = msg.ReadByte();
|
||||
orderTargetType = (Order.OrderTargetType)msg.ReadByte();
|
||||
if (msg.ReadBoolean())
|
||||
{
|
||||
var x = msg.ReadSingle();
|
||||
@@ -31,6 +34,10 @@ namespace Barotrauma.Networking
|
||||
var hull = Entity.FindEntityByID(msg.ReadUInt16()) as Hull;
|
||||
orderTargetPosition = new OrderTarget(new Vector2(x, y), hull, true);
|
||||
}
|
||||
else if (orderTargetType == Order.OrderTargetType.WallSection)
|
||||
{
|
||||
wallSectionIndex = msg.ReadByte();
|
||||
}
|
||||
|
||||
if (orderIndex < 0 || orderIndex >= Order.PrefabList.Count)
|
||||
{
|
||||
@@ -39,9 +46,12 @@ namespace Barotrauma.Networking
|
||||
return;
|
||||
}
|
||||
|
||||
Order order = Order.PrefabList[orderIndex];
|
||||
string orderOption = orderOptionIndex < 0 || orderOptionIndex >= order.Options.Length ? "" : order.Options[orderOptionIndex];
|
||||
orderMsg = new OrderChatMessage(order, orderOption, orderTargetPosition ?? orderTargetEntity as ISpatialEntity, orderTargetCharacter, c.Character);
|
||||
Order orderPrefab = Order.PrefabList[orderIndex];
|
||||
string orderOption = orderOptionIndex < 0 || orderOptionIndex >= orderPrefab.Options.Length ? "" : orderPrefab.Options[orderOptionIndex];
|
||||
orderMsg = new OrderChatMessage(orderPrefab, orderOption, orderTargetPosition ?? orderTargetEntity as ISpatialEntity, orderTargetCharacter, c.Character)
|
||||
{
|
||||
WallSectionIndex = wallSectionIndex
|
||||
};
|
||||
txt = orderMsg.Text;
|
||||
}
|
||||
else
|
||||
@@ -119,16 +129,39 @@ namespace Barotrauma.Networking
|
||||
if (type == ChatMessageType.Order)
|
||||
{
|
||||
if (c.Character == null || c.Character.SpeechImpediment >= 100.0f || c.Character.IsDead) { return; }
|
||||
if (orderMsg.Order.TargetAllCharacters)
|
||||
Order order = null;
|
||||
if (orderMsg.Order.IsReport)
|
||||
{
|
||||
HumanAIController.ReportProblem(orderMsg.Sender, orderMsg.Order);
|
||||
}
|
||||
else if (orderTargetCharacter != null)
|
||||
else if (orderTargetCharacter != null && !orderMsg.Order.TargetAllCharacters)
|
||||
{
|
||||
var order = orderTargetPosition == null ?
|
||||
new Order(orderMsg.Order.Prefab, orderTargetEntity, orderMsg.Order.Prefab?.GetTargetItemComponent(orderTargetEntity as Item), orderMsg.Sender) :
|
||||
new Order(orderMsg.Order.Prefab, orderTargetPosition, orderMsg.Sender);
|
||||
orderTargetCharacter.SetOrder(order, orderMsg.OrderOption, orderMsg.Sender);
|
||||
switch (orderTargetType)
|
||||
{
|
||||
case Order.OrderTargetType.Entity:
|
||||
order = new Order(orderMsg.Order.Prefab, orderTargetEntity, orderMsg.Order.Prefab?.GetTargetItemComponent(orderTargetEntity as Item), orderGiver: orderMsg.Sender);
|
||||
break;
|
||||
case Order.OrderTargetType.Position:
|
||||
order = new Order(orderMsg.Order.Prefab, orderTargetPosition, orderGiver: orderMsg.Sender);
|
||||
break;
|
||||
}
|
||||
if (order != null)
|
||||
{
|
||||
orderTargetCharacter.SetOrder(order, orderMsg.OrderOption, orderMsg.Sender);
|
||||
}
|
||||
}
|
||||
else if (orderMsg.Order.IsIgnoreOrder)
|
||||
{
|
||||
switch (orderTargetType)
|
||||
{
|
||||
case Order.OrderTargetType.Entity:
|
||||
(orderTargetEntity as MapEntity)?.SetIgnoreByAI(orderMsg.Order.Identifier == "ignorethis");
|
||||
break;
|
||||
case Order.OrderTargetType.WallSection:
|
||||
if (!wallSectionIndex.HasValue) { break; }
|
||||
(orderTargetEntity as Structure)?.GetSection(wallSectionIndex.Value)?.SetIgnoreByAI(orderMsg.Order.Identifier == "ignorethis");
|
||||
break;
|
||||
}
|
||||
}
|
||||
GameMain.Server.SendOrderChatMessage(orderMsg);
|
||||
}
|
||||
|
||||
@@ -811,6 +811,9 @@ namespace Barotrauma.Networking
|
||||
case ClientPacketHeader.CREW:
|
||||
ReadCrewMessage(inc, connectedClient);
|
||||
break;
|
||||
case ClientPacketHeader.READY_CHECK:
|
||||
ReadyCheck.ServerRead(inc, connectedClient);
|
||||
break;
|
||||
case ClientPacketHeader.FILE_REQUEST:
|
||||
if (serverSettings.AllowFileTransfers)
|
||||
{
|
||||
@@ -1543,10 +1546,12 @@ namespace Barotrauma.Networking
|
||||
if (!character.Enabled) { continue; }
|
||||
if (c.SpectatePos == null)
|
||||
{
|
||||
if (c.Character != null && Vector2.DistanceSquared(character.WorldPosition, c.Character.WorldPosition) >= NetConfig.DisableCharacterDistSqr)
|
||||
float distSqr = Vector2.DistanceSquared(character.WorldPosition, c.Character.WorldPosition);
|
||||
if (c.Character.ViewTarget != null)
|
||||
{
|
||||
continue;
|
||||
distSqr = Math.Min(distSqr, Vector2.DistanceSquared(character.WorldPosition, c.Character.ViewTarget.WorldPosition));
|
||||
}
|
||||
if (distSqr >= NetConfig.DisableCharacterDistSqr) { continue; }
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2130,6 +2135,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
Level.Loaded?.SpawnNPCs();
|
||||
Level.Loaded?.SpawnCorpses();
|
||||
Level.Loaded?.PrepareBeaconStation();
|
||||
AutoItemPlacer.PlaceIfNeeded();
|
||||
|
||||
CrewManager crewManager = campaign?.CrewManager;
|
||||
@@ -2253,7 +2259,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
for (int i = 0; i < teamClients.Count; i++)
|
||||
{
|
||||
Character spawnedCharacter = Character.Create(teamClients[i].CharacterInfo, spawnWaypoints[i].WorldPosition, teamClients[i].CharacterInfo.Name, true, false);
|
||||
Character spawnedCharacter = Character.Create(teamClients[i].CharacterInfo, spawnWaypoints[i].WorldPosition, teamClients[i].CharacterInfo.Name, isRemotePlayer: true, hasAi: false);
|
||||
spawnedCharacter.AnimController.Frozen = true;
|
||||
spawnedCharacter.TeamID = teamID;
|
||||
teamClients[i].Character = spawnedCharacter;
|
||||
@@ -2269,7 +2275,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
else
|
||||
{
|
||||
characterData.SpawnInventoryItems(spawnedCharacter.Info, spawnedCharacter.Inventory);
|
||||
characterData.SpawnInventoryItems(spawnedCharacter, spawnedCharacter.Inventory);
|
||||
characterData.ApplyHealthData(spawnedCharacter.Info, spawnedCharacter);
|
||||
spawnedCharacter.GiveIdCardTags(mainSubWaypoints[i]);
|
||||
characterData.HasSpawned = true;
|
||||
@@ -2280,7 +2286,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
for (int i = teamClients.Count; i < teamClients.Count + bots.Count; i++)
|
||||
{
|
||||
Character spawnedCharacter = Character.Create(characterInfos[i], spawnWaypoints[i].WorldPosition, characterInfos[i].Name, false, true);
|
||||
Character spawnedCharacter = Character.Create(characterInfos[i], spawnWaypoints[i].WorldPosition, characterInfos[i].Name, isRemotePlayer: false, hasAi: true);
|
||||
spawnedCharacter.TeamID = teamID;
|
||||
spawnedCharacter.GiveJobItems(mainSubWaypoints[i]);
|
||||
spawnedCharacter.GiveIdCardTags(mainSubWaypoints[i]);
|
||||
@@ -2945,7 +2951,7 @@ namespace Barotrauma.Networking
|
||||
else if (type == ChatMessageType.Radio)
|
||||
{
|
||||
//send to chat-linked wifi components
|
||||
senderRadio.TransmitSignal(0, message, senderRadio.Item, senderCharacter, false);
|
||||
senderRadio.TransmitSignal(0, message, senderRadio.Item, senderCharacter, sentFromChat: true);
|
||||
}
|
||||
|
||||
//check which clients can receive the message and apply distance effects
|
||||
@@ -3662,7 +3668,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
public static void Log(string line, ServerLog.MessageType messageType)
|
||||
{
|
||||
if (GameMain.Server == null || !GameMain.Server.ServerSettings.SaveServerLogs) return;
|
||||
if (GameMain.Server == null || !GameMain.Server.ServerSettings.SaveServerLogs) { return; }
|
||||
|
||||
GameMain.Server.ServerSettings.ServerLog.WriteLine(line, messageType);
|
||||
|
||||
|
||||
@@ -226,6 +226,13 @@ namespace Barotrauma
|
||||
clientMemories.Remove(client);
|
||||
}
|
||||
|
||||
public void OnBallastFloraDamaged(Character character, float damage)
|
||||
{
|
||||
if (character == null) { return; }
|
||||
float karmaChange = damage * BallastFloraKarmaIncrease;
|
||||
AdjustKarma(character, karmaChange, "Damaged ballast flora");
|
||||
}
|
||||
|
||||
// ReSharper disable once UseNegatedPatternMatching, LoopCanBeConvertedToQuery
|
||||
public void OnItemTakenFromPlayer(CharacterInventory inventory, Client yoinker, Item item)
|
||||
{
|
||||
|
||||
+2
-2
@@ -490,7 +490,7 @@ namespace Barotrauma.Networking
|
||||
continue;
|
||||
}
|
||||
|
||||
byte msgLength = msg.ReadByte();
|
||||
int msgLength = (int)msg.ReadVariableUInt32();
|
||||
|
||||
IClientSerializable entity = Entity.FindEntityByID(entityID) as IClientSerializable;
|
||||
|
||||
@@ -499,7 +499,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (GameSettings.VerboseLogging)
|
||||
{
|
||||
DebugConsole.NewMessage("Received msg " + thisEventID, Color.Red);
|
||||
DebugConsole.NewMessage("Received msg " + thisEventID + ", expecting " + sender.LastSentEntityEventID, Color.Red);
|
||||
}
|
||||
msg.BitPosition += msgLength * 8;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@ namespace Barotrauma.Networking
|
||||
msg.Write(TargetCharacter == null ? (UInt16)0 : TargetCharacter.ID);
|
||||
msg.Write(TargetEntity is Entity ? (TargetEntity as Entity).ID : (UInt16)0);
|
||||
msg.Write((byte)Array.IndexOf(Order.Prefab.Options, OrderOption));
|
||||
if (TargetEntity is OrderTarget orderTarget)
|
||||
msg.Write((byte)Order.TargetType);
|
||||
if (Order.TargetType == Order.OrderTargetType.Position && TargetEntity is OrderTarget orderTarget)
|
||||
{
|
||||
msg.Write(true);
|
||||
msg.Write(orderTarget.Position.X);
|
||||
@@ -31,6 +32,10 @@ namespace Barotrauma.Networking
|
||||
else
|
||||
{
|
||||
msg.Write(false);
|
||||
if (Order.TargetType == Order.OrderTargetType.WallSection)
|
||||
{
|
||||
msg.Write((byte)(WallSectionIndex ?? Order.WallSectionIndex ?? 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-2
@@ -39,7 +39,16 @@ namespace Barotrauma.Networking
|
||||
public double UpdateTime;
|
||||
public double TimeOut;
|
||||
public int Retries;
|
||||
public UInt64? SteamID;
|
||||
private UInt64? steamId;
|
||||
public UInt64? SteamID
|
||||
{
|
||||
get { return steamId; }
|
||||
set
|
||||
{
|
||||
steamId = value;
|
||||
Connection.SetSteamIDIfUnknown(value ?? 0);
|
||||
}
|
||||
}
|
||||
public Int32? PasswordSalt;
|
||||
public bool AuthSessionStarted;
|
||||
|
||||
@@ -224,7 +233,7 @@ namespace Barotrauma.Networking
|
||||
case ConnectionInitialization.ContentPackageOrder:
|
||||
outMsg.Write(GameMain.Server.ServerName);
|
||||
|
||||
var mpContentPackages = GameMain.Config.AllEnabledPackages.Where(cp => cp.HasMultiplayerIncompatibleContent).ToList();
|
||||
var mpContentPackages = GameMain.Config.AllEnabledPackages.Where(cp => cp.HasMultiplayerIncompatibleContent).Reverse().ToList();
|
||||
outMsg.WriteVariableUInt32((UInt32)mpContentPackages.Count);
|
||||
for (int i = 0; i < mpContentPackages.Count; i++)
|
||||
{
|
||||
|
||||
@@ -275,7 +275,7 @@ namespace Barotrauma.Networking
|
||||
characterInfos[i].CurrentOrder = null;
|
||||
characterInfos[i].CurrentOrderOption = null;
|
||||
|
||||
var character = Character.Create(characterInfos[i], shuttleSpawnPoints[i].WorldPosition, characterInfos[i].Name, !bot, bot);
|
||||
var character = Character.Create(characterInfos[i], shuttleSpawnPoints[i].WorldPosition, characterInfos[i].Name, isRemotePlayer: !bot, hasAi: bot);
|
||||
character.TeamID = Character.TeamType.Team1;
|
||||
|
||||
if (bot)
|
||||
@@ -341,7 +341,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
else
|
||||
{
|
||||
characterData.SpawnInventoryItems(character.Info, character.Inventory);
|
||||
characterData.SpawnInventoryItems(character, character.Inventory);
|
||||
characterData.ApplyHealthData(character.Info, character);
|
||||
character.GiveIdCardTags(mainSubSpawnPoints[i]);
|
||||
characterData.HasSpawned = true;
|
||||
|
||||
@@ -123,9 +123,12 @@ namespace Barotrauma
|
||||
sb.AppendLine("\n");
|
||||
sb.AppendLine("Exception: " + exception.Message + " (" + exception.GetType().ToString() + ")");
|
||||
sb.AppendLine("Target site: " +exception.TargetSite.ToString());
|
||||
sb.AppendLine("Stack trace: ");
|
||||
sb.AppendLine(exception.StackTrace.CleanupStackTrace());
|
||||
sb.AppendLine("\n");
|
||||
if (exception.StackTrace != null)
|
||||
{
|
||||
sb.AppendLine("Stack trace: ");
|
||||
sb.AppendLine(exception.StackTrace.CleanupStackTrace());
|
||||
sb.AppendLine("\n");
|
||||
}
|
||||
|
||||
if (exception.InnerException != null)
|
||||
{
|
||||
@@ -134,8 +137,11 @@ namespace Barotrauma
|
||||
{
|
||||
sb.AppendLine("Target site: " + exception.InnerException.TargetSite.ToString());
|
||||
}
|
||||
sb.AppendLine("Stack trace: ");
|
||||
sb.AppendLine(exception.InnerException.StackTrace.CleanupStackTrace());
|
||||
if (exception.InnerException.StackTrace != null)
|
||||
{
|
||||
sb.AppendLine("Stack trace: ");
|
||||
sb.AppendLine(exception.InnerException.StackTrace.CleanupStackTrace());
|
||||
}
|
||||
}
|
||||
|
||||
sb.AppendLine("Last debug messages:");
|
||||
|
||||
Reference in New Issue
Block a user