Merge branch 'heads/upstream' into OBT/1.2.0(SpringUpdate)
This commit is contained in:
@@ -65,7 +65,7 @@ namespace Barotrauma
|
||||
var owner = GameMain.Server.ConnectedClients.Find(c => c.Character == this);
|
||||
if (owner != null)
|
||||
{
|
||||
if (!GameMain.LuaCs.Game.overrideTraitors)
|
||||
if (!LuaCsSetup.Instance.Game.overrideTraitors)
|
||||
{
|
||||
GameMain.Server.SendDirectChatMessage(TextManager.FormatServerMessage("KilledByTraitorNotification"), owner, ChatMessageType.ServerMessageBoxInGame);
|
||||
}
|
||||
|
||||
@@ -320,11 +320,7 @@ namespace Barotrauma
|
||||
|
||||
if (TalentTree.IsViableTalentForCharacter(this, prefab.Identifier, talentSelection))
|
||||
{
|
||||
bool? should = GameMain.LuaCs.Hook.Call<bool?>("character.updateTalent", this, prefab, c);
|
||||
if (should == null)
|
||||
{
|
||||
GiveTalent(prefab.Identifier);
|
||||
}
|
||||
GiveTalent(prefab.Identifier);
|
||||
talentSelection.Add(prefab.Identifier);
|
||||
}
|
||||
}
|
||||
@@ -815,7 +811,7 @@ namespace Barotrauma
|
||||
|
||||
var tempBuffer = new ReadWriteMessage();
|
||||
WriteStatus(tempBuffer, forceAfflictionData: true);
|
||||
if (msgLengthBeforeStatus + tempBuffer.LengthBytes >= 255 && restrictMessageSize && GameMain.LuaCs.Networking.RestrictMessageSize)
|
||||
if (msgLengthBeforeStatus + tempBuffer.LengthBytes >= 255 && restrictMessageSize)
|
||||
{
|
||||
msg.WriteBoolean(false);
|
||||
if (msgLengthBeforeStatus < 255)
|
||||
|
||||
@@ -10,6 +10,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using Barotrauma.Steam;
|
||||
using Barotrauma.Extensions;
|
||||
using Barotrauma.LuaCs.Events;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -1287,45 +1288,6 @@ namespace Barotrauma
|
||||
GameMain.NetLobbyScreen.LevelSeed = string.Join(" ", args);
|
||||
}));
|
||||
|
||||
|
||||
commands.Add(new Command("lua", "lua: Runs a string.", (string[] args) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
GameMain.LuaCs.Lua.DoString(string.Join(" ", args));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LuaCsLogger.HandleException(ex, LuaCsMessageOrigin.LuaMod);
|
||||
}
|
||||
}));
|
||||
|
||||
commands.Add(new Command("reloadlua|reloadcs|reloadluacs", "Re-initializes the LuaCs environment.", (string[] args) =>
|
||||
{
|
||||
GameMain.LuaCs.Initialize();
|
||||
}));
|
||||
|
||||
commands.Add(new Command("toggleluadebug", "Toggles the MoonSharp Debug Server.", (string[] args) =>
|
||||
{
|
||||
int port = 41912;
|
||||
|
||||
if (args.Length > 0)
|
||||
{
|
||||
int.TryParse(args[0], out port);
|
||||
}
|
||||
|
||||
GameMain.LuaCs.ToggleDebugger(port);
|
||||
}));
|
||||
|
||||
/*
|
||||
commands.Add(new Command("install_cl_ep", "Installs Client-Side ProjectEP into your client.", (string[] args) =>
|
||||
{
|
||||
LuaCsInstaller.Install();
|
||||
}));
|
||||
*/
|
||||
// Removed due to critical partical issues
|
||||
// TODO: Partical manager requires a refactor to solve race condition
|
||||
|
||||
commands.Add(new Command("randomizeseed", "randomizeseed: Toggles level seed randomization on/off.", (string[] args) =>
|
||||
{
|
||||
GameMain.Server.ServerSettings.RandomizeSeed = !GameMain.Server.ServerSettings.RandomizeSeed;
|
||||
|
||||
@@ -79,6 +79,15 @@ namespace Barotrauma
|
||||
convAction.SelectedOption = selectedOption;
|
||||
if (convAction.Options.Any() && !convAction.GetEndingOptions().Contains(selectedOption))
|
||||
{
|
||||
var option = convAction.Options[selectedOption];
|
||||
if (option.ForceSay && sender.Character != null)
|
||||
{
|
||||
sender.Character.ForceSay(
|
||||
option.ForceSayText.IsNullOrEmpty() ? TextManager.Get(option.Text).Fallback(option.Text) : TextManager.Get(option.ForceSayText).Fallback(option.ForceSayText),
|
||||
option.ForceSayInRadio,
|
||||
option.ForceSayRemoveQuotes);
|
||||
}
|
||||
|
||||
foreach (Client c in convAction.TargetClients)
|
||||
{
|
||||
if (c == sender) { continue; }
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace Barotrauma
|
||||
switch (winCondition)
|
||||
{
|
||||
case WinCondition.LastManStanding:
|
||||
if (crews[0].Count == 0 || crews[1].Count == 0)
|
||||
if (crews[0].Count == 0 && crews[1].Count == 0)
|
||||
{
|
||||
//if there are no characters in either crew, end the round
|
||||
teamDead[0] = teamDead[1] = true;
|
||||
|
||||
@@ -14,6 +14,7 @@ using MoonSharp.Interpreter;
|
||||
using System.Net;
|
||||
using Barotrauma.Extensions;
|
||||
using System.Threading.Tasks;
|
||||
using Barotrauma.LuaCs.Events;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -35,8 +36,6 @@ namespace Barotrauma
|
||||
set { world = value; }
|
||||
}
|
||||
|
||||
public static LuaCsSetup LuaCs;
|
||||
|
||||
public static GameServer Server;
|
||||
public static NetworkMember NetworkMember
|
||||
{
|
||||
@@ -113,6 +112,8 @@ namespace Barotrauma
|
||||
GameScreen = new GameScreen();
|
||||
|
||||
MainThread = Thread.CurrentThread;
|
||||
|
||||
LuaCsSetup.Instance.GetType();
|
||||
}
|
||||
|
||||
public void Init()
|
||||
@@ -131,8 +132,6 @@ namespace Barotrauma
|
||||
NetLobbyScreen = new NetLobbyScreen();
|
||||
|
||||
CheckContentPackage();
|
||||
|
||||
LuaCs = new LuaCsSetup();
|
||||
}
|
||||
|
||||
|
||||
@@ -244,6 +243,9 @@ namespace Barotrauma
|
||||
//handled in TryStartChildServerRelay
|
||||
i += 2;
|
||||
break;
|
||||
case "-lenienthandshake":
|
||||
NetConfig.UseLenientHandshake = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,12 +369,16 @@ namespace Barotrauma
|
||||
TaskPool.Update();
|
||||
CoroutineManager.Update(paused: false, (float)Timing.Step);
|
||||
|
||||
GameMain.LuaCs.Update();
|
||||
performanceCounterTimer.Stop();
|
||||
if (GameMain.LuaCs.PerformanceCounter.EnablePerformanceCounter)
|
||||
if (LuaCsSetup.Instance.PerformanceCounterService.EnablePerformanceCounter)
|
||||
{
|
||||
GameMain.LuaCs.PerformanceCounter.UpdateElapsedTime = (double)performanceCounterTimer.ElapsedTicks / Stopwatch.Frequency;
|
||||
LuaCsSetup.Instance.PerformanceCounterService.AddElapsedTicks(new SimplePerformanceData("Update", performanceCounterTimer.ElapsedTicks));
|
||||
}
|
||||
if (LuaCsSetup.Instance.PerformanceCounter.EnablePerformanceCounter)
|
||||
{
|
||||
LuaCsSetup.Instance.PerformanceCounter.UpdateElapsedTime = (double)performanceCounterTimer.ElapsedTicks / Stopwatch.Frequency;
|
||||
}
|
||||
|
||||
performanceCounterTimer.Reset();
|
||||
|
||||
Timing.Accumulator -= Timing.Step;
|
||||
@@ -459,7 +465,17 @@ namespace Barotrauma
|
||||
public void Exit()
|
||||
{
|
||||
ShouldRun = false;
|
||||
GameMain.LuaCs.Stop();
|
||||
try
|
||||
{
|
||||
if (LuaCsSetup.Instance is not null)
|
||||
{
|
||||
LuaCsSetup.Instance.Dispose();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError($"Error while disposing of LuaCsForBarotrauma: {e.Message} | {e.StackTrace}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Barotrauma.Items.Components
|
||||
public void ServerEventWrite(IWriteMessage msg, Client c, NetEntityEvent.IData extraData = null)
|
||||
{
|
||||
msg.WriteBoolean(State);
|
||||
msg.WriteUInt16(user == null ? (ushort)0 : user.ID);
|
||||
msg.WriteUInt16(User == null || User.Removed ? (ushort)0 : User.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,11 @@ namespace Barotrauma.Items.Components
|
||||
public void ServerEventRead(IReadMessage msg, Client c)
|
||||
{
|
||||
if (c.Character == null) { return; }
|
||||
var requestedFixAction = (FixActions)msg.ReadRangedInteger(0, 2);
|
||||
var QTESuccess = msg.ReadBoolean();
|
||||
FixActions requestedFixAction = (FixActions)msg.ReadRangedInteger(0, 2);
|
||||
bool QTESuccess = msg.ReadBoolean();
|
||||
|
||||
if (!item.CanClientAccess(c) || !HasRequiredItems(c.Character, addMessage: false)) { return; }
|
||||
|
||||
if (requestedFixAction != FixActions.None)
|
||||
{
|
||||
if (!c.Character.IsTraitor && requestedFixAction == FixActions.Sabotage)
|
||||
|
||||
@@ -121,9 +121,9 @@ namespace Barotrauma
|
||||
if (shouldBeRemoved)
|
||||
{
|
||||
bool itemAccessDenied = prevItems.Contains(item) && // if the item was in the inventory before
|
||||
!itemAccessibility[item] && // and the sender is not allowed to access it
|
||||
(item.PreviousParentInventory == null || // and either the item has no previous inventory
|
||||
!sender.Character.CanAccessInventory(item.PreviousParentInventory)); // or the sender can't access the previous inventory
|
||||
!itemAccessibility[item] && // and the sender is not allowed to access it
|
||||
(item.PreviousParentInventory == null || // and either the item has no previous inventory
|
||||
!sender.Character.CanAccessInventory(item.PreviousParentInventory)); // or the sender can't access the previous inventory
|
||||
|
||||
if (itemAccessDenied)
|
||||
{
|
||||
@@ -136,7 +136,7 @@ namespace Barotrauma
|
||||
Item droppedItem = item;
|
||||
Entity prevOwner = Owner;
|
||||
Inventory previousInventory = droppedItem.ParentInventory;
|
||||
droppedItem.Drop(null);
|
||||
droppedItem.Drop(sender.Character);
|
||||
droppedItem.PreviousParentInventory = previousInventory;
|
||||
|
||||
var previousCharacterInventory = prevOwner switch
|
||||
@@ -188,9 +188,18 @@ namespace Barotrauma
|
||||
if (holdable != null && !holdable.CanBeDeattached()) { continue; }
|
||||
|
||||
|
||||
bool itemAccessDenied = !prevItems.Contains(item) && !itemAccessibility[item] &&
|
||||
(sender.Character == null || item.PreviousParentInventory == null || !sender.Character.CanAccessInventory(item.PreviousParentInventory));
|
||||
|
||||
bool itemAccessDenied = !prevItems.Contains(item) &&
|
||||
!itemAccessibility[item] &&
|
||||
(item.PreviousParentInventory == null ||
|
||||
!sender.Character.CanAccessInventory(item.PreviousParentInventory));
|
||||
|
||||
// Prevent modified clients from being able to steal items from characters by item swapping with an existing item
|
||||
// due to drag and drop being enabled
|
||||
if (!sender.Character.CanAccessInventory(this, CharacterInventory.AccessLevel.AllowBotsAndPets) && GetItemAt(slotIndex) != null)
|
||||
{
|
||||
itemAccessDenied = true;
|
||||
}
|
||||
|
||||
//more restricted "adding" of handcuffs: we can't allow putting handcuffs on a player just because dragging and dropping is allowed
|
||||
if (item.HasTag(Tags.HandLockerItem) && !itemAccessDenied)
|
||||
{
|
||||
|
||||
@@ -12,8 +12,6 @@ namespace Barotrauma
|
||||
{
|
||||
private CoroutineHandle logPropertyChangeCoroutine;
|
||||
|
||||
public Inventory PreviousParentInventory;
|
||||
|
||||
public override Sprite Sprite
|
||||
{
|
||||
get { return base.Prefab?.Sprite; }
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
partial class Client
|
||||
{
|
||||
public void SetClientCharacter(Character character)
|
||||
{
|
||||
GameMain.Server.SetClientCharacter(this, character);
|
||||
}
|
||||
|
||||
public void Kick(string reason = "")
|
||||
{
|
||||
GameMain.Server.KickClient(this.Connection, reason);
|
||||
}
|
||||
|
||||
public void Ban(string reason = "", float seconds = -1)
|
||||
{
|
||||
if (seconds == -1)
|
||||
{
|
||||
GameMain.Server.BanClient(this, reason, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameMain.Server.BanClient(this, reason, TimeSpan.FromSeconds(seconds));
|
||||
}
|
||||
}
|
||||
|
||||
public static void UnbanPlayer(string playerName)
|
||||
{
|
||||
GameMain.Server.UnbanPlayer(playerName);
|
||||
}
|
||||
|
||||
public static void BanPlayer(string player, string reason, bool range = false, float seconds = -1)
|
||||
{
|
||||
if (seconds == -1)
|
||||
{
|
||||
GameMain.Server.BanPlayer(player, reason, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameMain.Server.BanPlayer(player, reason, TimeSpan.FromSeconds(seconds));
|
||||
}
|
||||
}
|
||||
|
||||
public bool CheckPermission(ClientPermissions permissions)
|
||||
{
|
||||
return this.Permissions.HasFlag(permissions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Reflection;
|
||||
|
||||
partial class Item
|
||||
{
|
||||
public object CreateServerEventString(string component)
|
||||
{
|
||||
var comp = GetComponentString(component);
|
||||
|
||||
if (comp == null)
|
||||
return null;
|
||||
|
||||
MethodInfo method = typeof(Item).GetMethod(nameof(Item.CreateServerEvent), new Type[]{ Type.MakeGenericMethodParameter(0) });
|
||||
MethodInfo generic = method.MakeGenericMethod(comp.GetType());
|
||||
return generic.Invoke(this, new object[]{ comp });
|
||||
}
|
||||
|
||||
public object CreateServerEventString(string component, object[] extraData)
|
||||
{
|
||||
var comp = GetComponentString(component);
|
||||
|
||||
if (comp == null)
|
||||
return null;
|
||||
|
||||
MethodInfo method = typeof(Item).GetMethod(nameof(Item.CreateServerEvent), new Type[]{ Type.MakeGenericMethodParameter(0), typeof(object[]) });
|
||||
MethodInfo generic = method.MakeGenericMethod(comp.GetType());
|
||||
return generic.Invoke(this, new object[]{comp, extraData });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
using Barotrauma.Networking;
|
||||
|
||||
partial struct Signal
|
||||
{
|
||||
public static Signal Create(string value, int stepsTaken = 0, Character sender = null, Item source = null, float power = 0.0f, float strength = 1.0f)
|
||||
{
|
||||
return new Signal(value, stepsTaken, sender, source, power, strength);
|
||||
}
|
||||
}
|
||||
|
||||
partial class Quality
|
||||
{
|
||||
public void SetValue(StatType statType, float value)
|
||||
{
|
||||
statValues[statType] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Barotrauma.LuaCs;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -9,7 +10,7 @@ namespace Barotrauma
|
||||
{
|
||||
public static void Install()
|
||||
{
|
||||
ContentPackage luaPackage = LuaCsSetup.GetPackage(LuaCsSetup.LuaForBarotraumaId);
|
||||
ContentPackage luaPackage = LuaCsSetup.GetLuaCsPackage();
|
||||
|
||||
if (luaPackage == null)
|
||||
{
|
||||
@@ -45,8 +46,9 @@ namespace Barotrauma
|
||||
File.Copy(Path.Combine(path, "Binary", file), file, true);
|
||||
}
|
||||
|
||||
File.WriteAllText(LuaCsSetup.VersionFile, luaPackage.ModVersion);
|
||||
|
||||
#if WINDOWS
|
||||
File.WriteAllText("LuaCsDedicatedServer.bat", "\"%LocalAppData%/Daedalic Entertainment GmbH/Barotrauma/WorkshopMods/Installed/2559634234/Binary/DedicatedServer.exe\"");
|
||||
#endif
|
||||
}
|
||||
catch (UnauthorizedAccessException e)
|
||||
{
|
||||
|
||||
@@ -1,194 +0,0 @@
|
||||
using Barotrauma.Networking;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
partial class LuaCsNetworking
|
||||
{
|
||||
private const int MaxRegisterPerClient = 1000;
|
||||
|
||||
private Dictionary<string, int> clientRegisterCount = new Dictionary<string, int>();
|
||||
|
||||
private ushort currentId = 0;
|
||||
|
||||
public void NetMessageReceived(IReadMessage netMessage, ClientPacketHeader header, Client client = null)
|
||||
{
|
||||
if (header != ClientPacketHeader.LUA_NET_MESSAGE)
|
||||
{
|
||||
GameMain.LuaCs.Hook.Call("netMessageReceived", netMessage, header, client);
|
||||
return;
|
||||
}
|
||||
|
||||
LuaCsClientToServer luaCsHeader = (LuaCsClientToServer)netMessage.ReadByte();
|
||||
|
||||
switch (luaCsHeader)
|
||||
{
|
||||
case LuaCsClientToServer.NetMessageString:
|
||||
HandleNetMessageString(netMessage, client);
|
||||
break;
|
||||
|
||||
case LuaCsClientToServer.NetMessageId:
|
||||
HandleNetMessageId(netMessage, client);
|
||||
break;
|
||||
|
||||
case LuaCsClientToServer.RequestAllIds:
|
||||
WriteAllIds(client);
|
||||
break;
|
||||
|
||||
case LuaCsClientToServer.RequestSingleId:
|
||||
RequestIdSingle(netMessage, client);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleNetMessageId(IReadMessage netMessage, Client client = null)
|
||||
{
|
||||
ushort id = netMessage.ReadUInt16();
|
||||
|
||||
if (idToString.ContainsKey(id))
|
||||
{
|
||||
string name = idToString[id];
|
||||
|
||||
HandleNetMessage(netMessage, name, client);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GameSettings.CurrentConfig.VerboseLogging)
|
||||
{
|
||||
LuaCsLogger.LogError($"Received NetMessage for unknown id {id} from {GameServer.ClientLogName(client)}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IWriteMessage Start(string netMessageName)
|
||||
{
|
||||
var message = new WriteOnlyMessage();
|
||||
|
||||
message.WriteByte((byte)ServerPacketHeader.LUA_NET_MESSAGE);
|
||||
|
||||
if (stringToId.ContainsKey(netMessageName))
|
||||
{
|
||||
message.WriteByte((byte)LuaCsServerToClient.NetMessageId);
|
||||
message.WriteUInt16(stringToId[netMessageName]);
|
||||
}
|
||||
else
|
||||
{
|
||||
message.WriteByte((byte)LuaCsServerToClient.NetMessageString);
|
||||
message.WriteString(netMessageName);
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
public void Receive(string netMessageName, LuaCsAction callback)
|
||||
{
|
||||
RegisterId(netMessageName);
|
||||
|
||||
netReceives[netMessageName] = callback;
|
||||
}
|
||||
|
||||
public ushort RegisterId(string name)
|
||||
{
|
||||
if (stringToId.ContainsKey(name))
|
||||
{
|
||||
return stringToId[name];
|
||||
}
|
||||
|
||||
if (currentId >= ushort.MaxValue)
|
||||
{
|
||||
LuaCsLogger.LogError($"Tried to register more than {ushort.MaxValue} network ids!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
currentId++;
|
||||
|
||||
idToString[currentId] = name;
|
||||
stringToId[name] = currentId;
|
||||
|
||||
WriteIdToAll(currentId, name);
|
||||
|
||||
return currentId;
|
||||
}
|
||||
|
||||
private void RequestIdSingle(IReadMessage netMessage, Client client)
|
||||
{
|
||||
string name = netMessage.ReadString();
|
||||
|
||||
if (!stringToId.ContainsKey(name) && client.AccountId.TryUnwrap(out AccountId id))
|
||||
{
|
||||
if (!clientRegisterCount.ContainsKey(id.StringRepresentation))
|
||||
{
|
||||
clientRegisterCount[id.StringRepresentation] = 0;
|
||||
}
|
||||
|
||||
clientRegisterCount[id.StringRepresentation]++;
|
||||
|
||||
if (clientRegisterCount[id.StringRepresentation] > MaxRegisterPerClient)
|
||||
{
|
||||
LuaCsLogger.Log($"{GameServer.ClientLogName(client)} Tried to register more than {MaxRegisterPerClient} Ids!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
RegisterId(name);
|
||||
}
|
||||
|
||||
private void WriteIdToAll(ushort id, string name)
|
||||
{
|
||||
WriteOnlyMessage message = new WriteOnlyMessage();
|
||||
message.WriteByte((byte)ServerPacketHeader.LUA_NET_MESSAGE);
|
||||
message.WriteByte((byte)LuaCsServerToClient.ReceiveIds);
|
||||
|
||||
message.WriteUInt16(1);
|
||||
message.WriteUInt16(id);
|
||||
message.WriteString(name);
|
||||
|
||||
Send(message, null, DeliveryMethod.Reliable);
|
||||
}
|
||||
|
||||
private void WriteAllIds(Client client)
|
||||
{
|
||||
WriteOnlyMessage message = new WriteOnlyMessage();
|
||||
message.WriteByte((byte)ServerPacketHeader.LUA_NET_MESSAGE);
|
||||
message.WriteByte((byte)LuaCsServerToClient.ReceiveIds);
|
||||
|
||||
message.WriteUInt16((ushort)idToString.Count());
|
||||
foreach ((ushort id, string name) in idToString)
|
||||
{
|
||||
message.WriteUInt16(id);
|
||||
message.WriteString(name);
|
||||
}
|
||||
|
||||
Send(message, client.Connection, DeliveryMethod.Reliable);
|
||||
}
|
||||
|
||||
public void ClientWriteLobby(Client client) => GameMain.Server.ClientWriteLobby(client);
|
||||
|
||||
public void Send(IWriteMessage netMessage, NetworkConnection connection = null, DeliveryMethod deliveryMethod = DeliveryMethod.Reliable)
|
||||
{
|
||||
if (connection == null)
|
||||
{
|
||||
foreach (NetworkConnection conn in Client.ClientList.Select(c => c.Connection))
|
||||
{
|
||||
GameMain.Server.ServerPeer.Send(netMessage, conn, deliveryMethod);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GameMain.Server.ServerPeer.Send(netMessage, connection, deliveryMethod);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateClientPermissions(Client client)
|
||||
{
|
||||
GameMain.Server.UpdateClientPermissions(client);
|
||||
}
|
||||
|
||||
public int FileSenderMaxPacketsPerUpdate
|
||||
{
|
||||
get { return FileSender.FileTransferOut.MaxPacketsPerUpdate; }
|
||||
set { FileSender.FileTransferOut.MaxPacketsPerUpdate = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Barotrauma.Networking;
|
||||
|
||||
namespace Barotrauma;
|
||||
|
||||
partial class LuaCsSetup
|
||||
{
|
||||
partial void CheckReadyToRun(Action onReadyToRun)
|
||||
{
|
||||
onReadyToRun?.Invoke();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles changes in game states tracked by screen changes.
|
||||
/// </summary>
|
||||
/// <param name="screen">The new game screen.</param>
|
||||
public partial void OnScreenSelected(Screen screen)
|
||||
{
|
||||
// the server is always in the running state unless explicitly stopped.
|
||||
if (screen == UnimplementedScreen.Instance)
|
||||
SetRunState(RunState.Unloaded);
|
||||
SetRunState(RunState.Running);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
using Barotrauma.LuaCs.Events;
|
||||
using Barotrauma.Networking;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace Barotrauma.LuaCs;
|
||||
|
||||
partial class NetworkingService : INetworkingService, IEventClientRawNetMessageReceived
|
||||
{
|
||||
private const int MaxRegisterPerClient = 1000;
|
||||
|
||||
private Dictionary<string, int> clientRegisterCount = new Dictionary<string, int>();
|
||||
|
||||
private ushort currentId = 0;
|
||||
|
||||
public IWriteMessage Start(NetId netId)
|
||||
{
|
||||
var message = new WriteOnlyMessage();
|
||||
|
||||
message.WriteByte((byte)ServerHeader);
|
||||
|
||||
if (idToPacket.ContainsKey(netId))
|
||||
{
|
||||
message.WriteByte((byte)ServerToClient.NetMessageInternalId);
|
||||
message.WriteUInt16(idToPacket[netId]);
|
||||
}
|
||||
else
|
||||
{
|
||||
message.WriteByte((byte)ServerToClient.NetMessageNetId);
|
||||
NetId.Write(message, netId);
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
public bool? OnReceivedClientNetMessage(IReadMessage netMessage, ClientPacketHeader clientPacketHeader, NetworkConnection sender)
|
||||
{
|
||||
if (clientPacketHeader != ClientHeader)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Client client = GameMain.Server.ConnectedClients.First(c => c.Connection == sender);
|
||||
|
||||
ClientToServer luaCsHeader = (ClientToServer)netMessage.ReadByte();
|
||||
|
||||
switch (luaCsHeader)
|
||||
{
|
||||
case ClientToServer.NetMessageNetId:
|
||||
HandleNetMessageString(netMessage, client);
|
||||
break;
|
||||
|
||||
case ClientToServer.NetMessageInternalId:
|
||||
HandleNetMessageId(netMessage, client);
|
||||
break;
|
||||
|
||||
case ClientToServer.RequestSync:
|
||||
WriteSync(client);
|
||||
break;
|
||||
|
||||
case ClientToServer.RequestSingleNetId:
|
||||
RequestIdSingle(netMessage, client);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void HandleNetMessageId(IReadMessage netMessage, Client client = null)
|
||||
{
|
||||
ushort id = netMessage.ReadUInt16();
|
||||
|
||||
if (packetToId.ContainsKey(id))
|
||||
{
|
||||
NetId netId = packetToId[id];
|
||||
|
||||
HandleNetMessage(netMessage, netId, client);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GameSettings.CurrentConfig.VerboseLogging)
|
||||
{
|
||||
_loggerService.LogError($"Received NetMessage for unknown id {id} from {GameServer.ClientLogName(client)}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ushort RegisterId(NetId netId)
|
||||
{
|
||||
if (idToPacket.ContainsKey(netId))
|
||||
{
|
||||
return idToPacket[netId];
|
||||
}
|
||||
|
||||
if (currentId >= ushort.MaxValue)
|
||||
{
|
||||
_loggerService.LogError($"Tried to register more than {ushort.MaxValue} network ids!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
currentId++;
|
||||
|
||||
packetToId[currentId] = netId;
|
||||
idToPacket[netId] = currentId;
|
||||
|
||||
WriteIdToAll(currentId, netId);
|
||||
|
||||
return currentId;
|
||||
}
|
||||
|
||||
private void RequestIdSingle(IReadMessage netMessage, Client client)
|
||||
{
|
||||
NetId netId = NetId.Read(netMessage);
|
||||
|
||||
if (!idToPacket.ContainsKey(netId) && client.AccountId.TryUnwrap(out AccountId id))
|
||||
{
|
||||
if (!clientRegisterCount.ContainsKey(id.StringRepresentation))
|
||||
{
|
||||
clientRegisterCount[id.StringRepresentation] = 0;
|
||||
}
|
||||
|
||||
clientRegisterCount[id.StringRepresentation]++;
|
||||
|
||||
if (clientRegisterCount[id.StringRepresentation] > MaxRegisterPerClient)
|
||||
{
|
||||
_loggerService.Log($"{GameServer.ClientLogName(client)} Tried to register more than {MaxRegisterPerClient} Ids!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
RegisterId(netId);
|
||||
}
|
||||
|
||||
private void WriteIdToAll(ushort packet, NetId netId)
|
||||
{
|
||||
WriteOnlyMessage message = new WriteOnlyMessage();
|
||||
message.WriteByte((byte)ServerHeader);
|
||||
message.WriteByte((byte)ServerToClient.ReceiveNetIds);
|
||||
|
||||
message.WriteUInt16(1);
|
||||
message.WriteUInt16(packet);
|
||||
NetId.Write(message, netId);
|
||||
|
||||
SendToClient(message, null, DeliveryMethod.Reliable);
|
||||
}
|
||||
|
||||
private void WriteSync(Client client)
|
||||
{
|
||||
WriteOnlyMessage message = new WriteOnlyMessage();
|
||||
message.WriteByte((byte)ServerHeader);
|
||||
message.WriteByte((byte)ServerToClient.ReceiveNetIds);
|
||||
|
||||
message.WriteUInt16((ushort)packetToId.Count());
|
||||
foreach ((ushort packet, NetId netId) in packetToId)
|
||||
{
|
||||
message.WriteUInt16(packet);
|
||||
NetId.Write(message, netId);
|
||||
}
|
||||
|
||||
SendToClient(message, client.Connection, DeliveryMethod.Reliable);
|
||||
|
||||
// TODO: when we move to using GUIDs for everything, this should combined into a single message
|
||||
foreach (INetworkSyncVar netVar in netVars.Keys)
|
||||
{
|
||||
SendNetVar(netVar, client.Connection);
|
||||
}
|
||||
}
|
||||
|
||||
public void SendToClient(IWriteMessage netMessage, NetworkConnection connection = null, DeliveryMethod deliveryMethod = DeliveryMethod.Reliable)
|
||||
{
|
||||
if (connection == null)
|
||||
{
|
||||
foreach (NetworkConnection conn in ModUtils.Client.ClientList.Select(c => c.Connection))
|
||||
{
|
||||
GameMain.Server.ServerPeer.Send(netMessage, conn, deliveryMethod);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GameMain.Server.ServerPeer.Send(netMessage, connection, deliveryMethod);
|
||||
}
|
||||
}
|
||||
|
||||
public void Send(IWriteMessage netMessage, NetworkConnection connection = null, DeliveryMethod deliveryMethod = DeliveryMethod.Reliable)
|
||||
=> SendToClient(netMessage, connection, deliveryMethod);
|
||||
}
|
||||
@@ -112,6 +112,7 @@ namespace Barotrauma
|
||||
msg.WriteRangedSingle(normalizedXPos, 0.0f, 1.0f, 8);
|
||||
msg.WriteRangedSingle(normalizedYPos, 0.0f, 1.0f, 8);
|
||||
msg.WriteRangedSingle(decal.Scale, 0f, 2f, 12);
|
||||
msg.WriteRangedSingle(decal.BaseAlpha, 0f, 1f, 8);
|
||||
}
|
||||
break;
|
||||
case BallastFloraEventData ballastFloraEventData:
|
||||
@@ -251,7 +252,7 @@ namespace Barotrauma
|
||||
break;
|
||||
case EventType.Decal:
|
||||
byte decalIndex = msg.ReadByte();
|
||||
float decalAlpha = msg.ReadRangedSingle(0.0f, 1.0f, 255);
|
||||
float decalAlpha = msg.ReadRangedSingle(0f, 1f, 8);
|
||||
if (decalIndex < 0 || decalIndex >= decals.Count) { return; }
|
||||
if (c.Character != null && c.Character.AllowInput && c.Character.HeldItems.Any(it => it.GetComponent<Sprayer>() != null))
|
||||
{
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using Barotrauma.LuaCs.Events;
|
||||
using MoonSharp.Interpreter;
|
||||
using MoonSharp.VsCodeDebugger.SDK;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
@@ -67,6 +69,9 @@ namespace Barotrauma.Networking
|
||||
txt = msg.ReadString() ?? "";
|
||||
}
|
||||
|
||||
// Sanitize incoming text message from client so they can't use RichString features
|
||||
txt = txt.Replace('‖', ' ');
|
||||
|
||||
if (!NetIdUtils.IdMoreRecent(ID, c.LastSentChatMsgID)) { return; }
|
||||
|
||||
c.LastSentChatMsgID = ID;
|
||||
@@ -86,12 +91,9 @@ namespace Barotrauma.Networking
|
||||
HandleSpamFilter(c, txt, out bool flaggedAsSpam, similarityMultiplier);
|
||||
if (flaggedAsSpam) { return; }
|
||||
|
||||
var should = GameMain.LuaCs.Hook.Call<bool?>("chatMessage", txt, c, type);
|
||||
|
||||
if (should != null && should.Value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
bool? should = null;
|
||||
LuaCsSetup.Instance.EventService.PublishEvent<IEventChatMessage>(x => should = x.OnChatMessage(txt, c, type, ChatMessage.Create(c.Name, txt, type, null, c)) ?? should);
|
||||
if (should != null && should.Value) { return; }
|
||||
|
||||
if (type == ChatMessageType.Order)
|
||||
{
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
using Barotrauma.Extensions;
|
||||
using Barotrauma.IO;
|
||||
using Barotrauma.Items.Components;
|
||||
using Barotrauma.LuaCs.Events;
|
||||
using Barotrauma.PerkBehaviors;
|
||||
using Barotrauma.Steam;
|
||||
using Lidgren.Network;
|
||||
using Microsoft.Xna.Framework;
|
||||
using MoonSharp.Interpreter;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Xml.Linq;
|
||||
using MoonSharp.Interpreter;
|
||||
using System.Net;
|
||||
using Barotrauma.PerkBehaviors;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
@@ -245,7 +246,6 @@ namespace Barotrauma.Networking
|
||||
|
||||
VoipServer = new VoipServer(serverPeer);
|
||||
|
||||
GameMain.LuaCs.Initialize();
|
||||
Log("Server started", ServerLog.MessageType.ServerMessage);
|
||||
|
||||
GameMain.NetLobbyScreen.Select();
|
||||
@@ -339,8 +339,6 @@ namespace Barotrauma.Networking
|
||||
SendConsoleMessage("Granted all permissions to " + newClient.Name + ".", newClient);
|
||||
}
|
||||
|
||||
GameMain.LuaCs.Hook.Call("client.connected", newClient);
|
||||
|
||||
SendChatMessage($"ServerMessage.JoinedServer~[client]={ClientLogName(newClient)}", ChatMessageType.Server, changeType: PlayerConnectionChangeType.Joined);
|
||||
ServerSettings.ServerDetailsChanged = true;
|
||||
|
||||
@@ -442,7 +440,7 @@ namespace Barotrauma.Networking
|
||||
(permadeathMode && (!character.IsDead || character.CauseOfDeath?.Type == CauseOfDeathType.Disconnected)));
|
||||
if (!character.IsDead)
|
||||
{
|
||||
if (!GameMain.LuaCs.Game.disableDisconnectCharacter)
|
||||
if (!LuaCsSetup.Instance.Game.disableDisconnectCharacter)
|
||||
{
|
||||
character.KillDisconnectedTimer += deltaTime;
|
||||
character.SetStun(1.0f);
|
||||
@@ -837,8 +835,6 @@ namespace Barotrauma.Networking
|
||||
using var _ = dosProtection.Start(connectedClient);
|
||||
|
||||
ClientPacketHeader header = (ClientPacketHeader)inc.ReadByte();
|
||||
|
||||
GameMain.LuaCs.Networking.NetMessageReceived(inc, header, connectedClient);
|
||||
|
||||
switch (header)
|
||||
{
|
||||
@@ -2314,7 +2310,6 @@ namespace Barotrauma.Networking
|
||||
segmentTable.StartNewSegment(ServerNetSegment.ClientList);
|
||||
outmsg.WriteUInt16(LastClientListUpdateID);
|
||||
|
||||
GameMain.LuaCs.Hook.Call("writeClientList", c, outmsg);
|
||||
outmsg.WriteByte((byte)Team1Count);
|
||||
outmsg.WriteByte((byte)Team2Count);
|
||||
|
||||
@@ -2340,13 +2335,6 @@ namespace Barotrauma.Networking
|
||||
IsOwner = client.Connection == OwnerConnection,
|
||||
IsDownloading = FileSender.ActiveTransfers.Any(t => t.Connection == client.Connection)
|
||||
};
|
||||
|
||||
var result = GameMain.LuaCs.Hook.Call<TempClient?>("writeClientList.modifyTempClientData", c, client, tempClientData, outmsg);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
tempClientData = result.Value;
|
||||
}
|
||||
|
||||
outmsg.WriteNetSerializableStruct(tempClientData);
|
||||
outmsg.WritePadBits();
|
||||
@@ -3199,7 +3187,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
TraitorManager.Initialize(GameMain.GameSession.EventManager, Level.Loaded);
|
||||
if (GameMain.LuaCs.Game.overrideTraitors)
|
||||
if (LuaCsSetup.Instance.Game.overrideTraitors)
|
||||
{
|
||||
TraitorManager.Enabled = false;
|
||||
}
|
||||
@@ -3228,8 +3216,6 @@ namespace Barotrauma.Networking
|
||||
|
||||
roundStartTime = DateTime.Now;
|
||||
|
||||
GameMain.LuaCs.Hook.Call("roundStart");
|
||||
|
||||
startGameCoroutine = null;
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
@@ -3402,15 +3388,6 @@ namespace Barotrauma.Networking
|
||||
GameMain.GameSession.EndRound(endMessage);
|
||||
}
|
||||
TraitorManager.TraitorResults? traitorResults = traitorManager?.GetEndResults() ?? null;
|
||||
var result = GameMain.LuaCs.Hook.Call<List<object>>("roundEnd");
|
||||
if (result != null)
|
||||
{
|
||||
foreach (var data in result)
|
||||
{
|
||||
if (data is TraitorManager.TraitorResults traitorResultData) { traitorResults = traitorResultData; }
|
||||
if (data is string endMessageData) { endMessage = endMessageData; }
|
||||
}
|
||||
}
|
||||
|
||||
EndRoundTimer = 0.0f;
|
||||
|
||||
@@ -3543,7 +3520,8 @@ namespace Barotrauma.Networking
|
||||
return false;
|
||||
}
|
||||
|
||||
var result = GameMain.LuaCs.Hook.Call<bool?>("tryChangeClientName", c, newName, newJob, newTeam);
|
||||
bool? result = null;
|
||||
LuaCsSetup.Instance.EventService.PublishEvent<IEventTryClientChangeName>(x => result = x.OnTryClienChangeName(c, newName, newJob, newTeam) ?? result);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
@@ -3747,8 +3725,6 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (client == null) return;
|
||||
|
||||
GameMain.LuaCs.Hook.Call("client.disconnected", client);
|
||||
|
||||
if (client.Character != null)
|
||||
{
|
||||
client.Character.ClientDisconnected = true;
|
||||
@@ -3997,21 +3973,29 @@ namespace Barotrauma.Networking
|
||||
senderName = null;
|
||||
senderCharacter = null;
|
||||
}
|
||||
else if (type == ChatMessageType.Radio && !GameMain.LuaCs.Game.overrideSignalRadio)
|
||||
else if (type == ChatMessageType.Radio && !LuaCsSetup.Instance.Game.overrideSignalRadio)
|
||||
{
|
||||
//send to chat-linked wifi components
|
||||
Signal s = new Signal(message, sender: senderCharacter, source: senderRadio.Item);
|
||||
senderRadio.TransmitSignal(s, sentFromChat: true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var hookChatMsg = ChatMessage.Create(senderName, message, (ChatMessageType)type, senderCharacter, senderClient, changeType);
|
||||
|
||||
var should = GameMain.LuaCs.Hook.Call<bool?>("modifyChatMessage", hookChatMsg, senderRadio);
|
||||
bool shouldSkip = false;
|
||||
LuaCsSetup.Instance.EventService.PublishEvent<IEventModifyChatMessage>(sub =>
|
||||
{
|
||||
if (sub.OnModifyMessagePredicate(hookChatMsg, senderRadio) is true)
|
||||
{
|
||||
shouldSkip = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (should != null && should.Value)
|
||||
if (shouldSkip)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//check which clients can receive the message and apply distance effects
|
||||
foreach (Client client in ConnectedClients)
|
||||
{
|
||||
@@ -4682,8 +4666,6 @@ namespace Barotrauma.Networking
|
||||
$"No suitable jobs available for {c.Name} (karma {c.Karma}). Assigning a random job: {c.AssignedJob.Prefab.Name}.");
|
||||
}
|
||||
}
|
||||
|
||||
GameMain.LuaCs.Hook.Call("jobsAssigned", unassigned);
|
||||
}
|
||||
|
||||
public void AssignBotJobs(List<CharacterInfo> bots, CharacterTeamType teamID, bool isPvP)
|
||||
@@ -4814,7 +4796,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (GameMain.Server == null || !GameMain.Server.ServerSettings.SaveServerLogs) { return; }
|
||||
|
||||
GameMain.LuaCs?.Hook?.Call("serverLog", line, messageType);
|
||||
LuaCsSetup.Instance?.EventService.PublishEvent<IEventServerLog>(x => x.OnServerLog(line, messageType));
|
||||
|
||||
GameMain.Server.ServerSettings.ServerLog.WriteLine(line, messageType);
|
||||
|
||||
|
||||
@@ -244,6 +244,8 @@ namespace Barotrauma
|
||||
Character targetCharacter = inventory.Owner as Character;
|
||||
|
||||
if (yoinker == null || item == null || thiefCharacter == null || targetCharacter == null || thiefCharacter == targetCharacter) { return; }
|
||||
|
||||
if (thiefCharacter.TeamID != targetCharacter.TeamID) { return; }
|
||||
|
||||
if (targetClient == null && (!DangerousItemStealBots || targetCharacter.AIController == null)) { return; }
|
||||
|
||||
@@ -261,7 +263,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
Item foundItem = null;
|
||||
if (isValid(item))
|
||||
if (IsValid(item))
|
||||
{
|
||||
foundItem = item;
|
||||
}
|
||||
@@ -269,7 +271,7 @@ namespace Barotrauma
|
||||
{
|
||||
foreach (Item containedItem in item.ContainedItems)
|
||||
{
|
||||
if (isValid(containedItem))
|
||||
if (IsValid(containedItem))
|
||||
{
|
||||
foundItem = containedItem;
|
||||
break;
|
||||
@@ -277,16 +279,19 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
static bool isValid(Item item)
|
||||
static bool IsValid(Item item)
|
||||
{
|
||||
return item.GetComponent<IdCard>() != null || item.GetComponent<RangedWeapon>() != null || item.GetComponent<MeleeWeapon>() != null;
|
||||
return item.GetComponent<IdCard>() != null || IsWeapon(item);
|
||||
}
|
||||
static bool IsWeapon(Item item)
|
||||
{
|
||||
//a threshold of 10 excludes things like tools, all "proper weapons" seem to have a priority higher than that
|
||||
return item.Components.Max(c => c.CombatPriority) > 10.0f || item.HasTag(Tags.Weapon);
|
||||
}
|
||||
|
||||
if (foundItem == null) { return; }
|
||||
|
||||
bool isIdCard = foundItem.GetComponent<IdCard>() != null;
|
||||
bool isWeapon = foundItem.GetComponent<RangedWeapon>() != null || foundItem.GetComponent<MeleeWeapon>() != null;
|
||||
|
||||
if (isIdCard)
|
||||
{
|
||||
string name = string.Empty;
|
||||
@@ -325,7 +330,7 @@ namespace Barotrauma
|
||||
JobPrefab clientJob = yoinker.CharacterInfo?.Job?.Prefab;
|
||||
|
||||
// security officers receive less karma penalty
|
||||
if (clientJob != null && clientJob.Identifier == "securityofficer" && isWeapon)
|
||||
if (clientJob != null && clientJob.Identifier == "securityofficer" && IsWeapon(foundItem))
|
||||
{
|
||||
karmaDecrease *= 0.5f;
|
||||
}
|
||||
|
||||
+8
-10
@@ -33,6 +33,13 @@ namespace Barotrauma.Networking
|
||||
DualStack = GameSettings.CurrentConfig.UseDualModeSockets,
|
||||
LocalAddress = serverSettings.ListenIPAddress,
|
||||
};
|
||||
if (NetConfig.UseLenientHandshake)
|
||||
{
|
||||
// More lenient timeouts for local testing, so the server would start even without perfect conditions
|
||||
netPeerConfiguration.ConnectionTimeout = 60.0f;
|
||||
netPeerConfiguration.ResendHandshakeInterval = 5.0f;
|
||||
netPeerConfiguration.MaximumHandshakeAttempts = 20;
|
||||
}
|
||||
|
||||
netPeerConfiguration.DisableMessageType(
|
||||
NetIncomingMessageType.DebugMessage
|
||||
@@ -187,16 +194,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (netServer == null) { return; }
|
||||
|
||||
var skipDeny = false;
|
||||
{
|
||||
var result = GameMain.LuaCs.Hook.Call<bool?>("lidgren.handleConnection", inc);
|
||||
if (result != null) {
|
||||
if (result.Value) skipDeny = true;
|
||||
else return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!skipDeny && connectedClients.Count >= serverSettings.MaxPlayers)
|
||||
if (connectedClients.Count >= serverSettings.MaxPlayers)
|
||||
{
|
||||
inc.SenderConnection.Deny(PeerDisconnectPacket.WithReason(DisconnectReason.ServerFull).ToLidgrenStringRepresentation());
|
||||
return;
|
||||
|
||||
+1
-6
@@ -257,12 +257,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
protected void UpdatePendingClient(PendingClient pendingClient)
|
||||
{
|
||||
var skipRemove = false;
|
||||
var result = GameMain.LuaCs.Hook.Call<bool?>("handlePendingClient", pendingClient);
|
||||
|
||||
if (result != null) skipRemove = result.Value;
|
||||
|
||||
if (!skipRemove && connectedClients.Count >= serverSettings.MaxPlayers)
|
||||
if (connectedClients.Count >= serverSettings.MaxPlayers)
|
||||
{
|
||||
RemovePendingClient(pendingClient, PeerDisconnectPacket.WithReason(DisconnectReason.ServerFull));
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Barotrauma.Networking
|
||||
MultiPlayerCampaign campaign = GameMain.GameSession.GameMode as MultiPlayerCampaign;
|
||||
foreach (Client c in networkMember.ConnectedClients)
|
||||
{
|
||||
if (GameMain.LuaCs.Game.overrideRespawnSub)
|
||||
if (LuaCsSetup.Instance.Game.overrideRespawnSub)
|
||||
continue;
|
||||
|
||||
if (!c.InGame) { continue; }
|
||||
@@ -169,7 +169,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
private bool ShouldStartRespawnCountdown(int characterToRespawnCount)
|
||||
{
|
||||
if (GameMain.LuaCs.Game.overrideRespawnSub)
|
||||
if (LuaCsSetup.Instance.Game.overrideRespawnSub)
|
||||
{
|
||||
characterToRespawnCount = 0;
|
||||
}
|
||||
@@ -187,7 +187,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
var teamId = teamSpecificState.TeamID;
|
||||
var respawnShuttle = GetShuttle(teamId);
|
||||
if (respawnShuttle != null && !GameMain.LuaCs.Game.overrideRespawnSub)
|
||||
if (respawnShuttle != null && !LuaCsSetup.Instance.Game.overrideRespawnSub)
|
||||
{
|
||||
respawnShuttle.Velocity = Vector2.Zero;
|
||||
}
|
||||
@@ -240,7 +240,7 @@ namespace Barotrauma.Networking
|
||||
if (RespawnShuttles.Any())
|
||||
{
|
||||
ResetShuttle(teamSpecificState);
|
||||
if (GameMain.LuaCs.Game.overrideRespawnSub)
|
||||
if (LuaCsSetup.Instance.Game.overrideRespawnSub)
|
||||
{
|
||||
teamSpecificState.CurrentState = State.Waiting;
|
||||
}
|
||||
@@ -596,6 +596,23 @@ namespace Barotrauma.Networking
|
||||
teamSpecificState.RespawnItems.AddRange(AutoItemPlacer.RegenerateLoot(respawnShuttle, respawnContainer));
|
||||
}
|
||||
}
|
||||
else if (character.InWater)
|
||||
{
|
||||
if (divingSuitPrefab != null)
|
||||
{
|
||||
var divingSuit = new Item(divingSuitPrefab, character.Position, respawnSub);
|
||||
Spawner.CreateNetworkEvent(new EntitySpawner.SpawnEntity(divingSuit));
|
||||
character.Inventory.TryPutItem(divingSuit, user: null, allowedSlots: divingSuit.AllowedSlots);
|
||||
teamSpecificState.RespawnItems.Add(divingSuit);
|
||||
if (oxyPrefab != null && divingSuit.GetComponent<ItemContainer>() != null)
|
||||
{
|
||||
var oxyTank = new Item(oxyPrefab, character.Position, respawnSub);
|
||||
Spawner.CreateNetworkEvent(new EntitySpawner.SpawnEntity(oxyTank));
|
||||
divingSuit.Combine(oxyTank, user: null);
|
||||
teamSpecificState.RespawnItems.Add(oxyTank);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var characterData = campaign?.GetClientCharacterData(clients[i]);
|
||||
// NOTE: This was where Reaper's tax got applied
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Barotrauma.Networking
|
||||
.Aggregate(NetFlags.None, (f1, f2) => f1 | f2);
|
||||
|
||||
private bool IsFlagRequired(Client c, NetFlags flag)
|
||||
=> NetIdUtils.IdMoreRecent(LastUpdateIdForFlag[flag], c.LastRecvLobbyUpdate);
|
||||
=> NetIdUtils.IdMoreRecent(LastUpdateIdForFlag[flag], c.LastRecvLobbyUpdate) || !c.InitialLobbyUpdateSent;
|
||||
|
||||
public NetFlags GetRequiredFlags(Client c)
|
||||
=> LastUpdateIdForFlag.Keys
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
using Barotrauma.Items.Components;
|
||||
using Barotrauma.LuaCs.Events;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static Barotrauma.CharacterHealth;
|
||||
using static Barotrauma.MedicalClinic;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
@@ -96,7 +99,8 @@ namespace Barotrauma.Networking
|
||||
ChatMessage.CanUseRadio(sender.Character, out WifiComponent senderRadio) &&
|
||||
(recipientSpectating || ChatMessage.CanUseRadio(recipient.Character, out recipientRadio)))
|
||||
{
|
||||
var canUse = GameMain.LuaCs.Hook.Call<bool?>("canUseVoiceRadio", new object[] { sender, recipient });
|
||||
bool? canUse = null;
|
||||
LuaCsSetup.Instance.EventService.PublishEvent<IEventCanUseVoiceRadio>(x => canUse = x.OnCanUseVoiceRadio(sender, recipient) ?? canUse);
|
||||
|
||||
if (canUse != null)
|
||||
{
|
||||
@@ -116,7 +120,8 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
|
||||
float range = GameMain.LuaCs.Hook.Call<float?>("changeLocalVoiceRange", sender, recipient) ?? 1.0f;
|
||||
float range = 1.0f;
|
||||
LuaCsSetup.Instance.EventService.PublishEvent<IEventChangeLocalVoiceRange>(x => range = x.OnChangeLocalVoiceRange(sender, recipient) ?? range);
|
||||
|
||||
if (recipientSpectating)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user