From a2cb256aa6ccb9d4e277187e72be3b0f3e9c40a3 Mon Sep 17 00:00:00 2001 From: Evil Factory <36804725+evilfactory@users.noreply.github.com> Date: Sun, 15 Aug 2021 17:17:49 -0300 Subject: [PATCH] plenty of new things --- .../ServerSource/Lua/LuaClasses.cs | 41 ++++++++++++++++++- .../ServerSource/Lua/LuaSetup.cs | 16 ++++++-- .../ServerSource/Networking/ChatMessage.cs | 2 +- .../ServerSource/Networking/GameServer.cs | 13 +++++- .../Networking/Voip/VoipServer.cs | 6 +++ .../Items/Components/ItemComponent.cs | 12 ++++++ .../Items/Components/Signal/Signal.cs | 14 +++---- .../Items/Components/Signal/WifiComponent.cs | 9 ++++ .../BarotraumaShared/SharedSource/Map/Gap.cs | 8 ++++ .../SharedSource/Networking/ChatMessage.cs | 6 +-- 10 files changed, 109 insertions(+), 18 deletions(-) diff --git a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaClasses.cs b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaClasses.cs index 758b5b4e1..250513e69 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaClasses.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaClasses.cs @@ -5,6 +5,7 @@ using MoonSharp.Interpreter; using Microsoft.Xna.Framework; using Barotrauma.Networking; using System.Threading.Tasks; +using Barotrauma.Items.Components; namespace Barotrauma { @@ -125,18 +126,24 @@ namespace Barotrauma public bool allowWifiChat = false; public bool overrideTraitors = false; public bool overrideRespawnSub = false; - + public bool overrideSignalRadio = false; + public bool disableSpamFilter = false; public LuaGame(LuaSetup e) { env = e; } - public static void SendMessage(string msg, ChatMessageType messageType = ChatMessageType.Server, Client sender = null, Character character = null) + public static void SendMessage(string msg, ChatMessageType? messageType = null, Client sender = null, Character character = null) { GameMain.Server.SendChatMessage(msg, messageType, sender, character); } + public static void SendMessage(string msg, int messageType, Client sender = null, Character character = null) + { + GameMain.Server.SendChatMessage(msg, (ChatMessageType)messageType, sender, character); + } + public static void SendTraitorMessage(Client client, string msg, string missionid, TraitorMessageType type) { GameMain.Server.SendTraitorMessage(client, msg, missionid, type); @@ -152,6 +159,11 @@ namespace Barotrauma } + public static void SendDirectChatMessage(ChatMessage chatMessage, Client client) + { + GameMain.Server.SendDirectChatMessage(chatMessage, client); + } + public void OverrideTraitors(bool o) { overrideTraitors = o; @@ -167,6 +179,16 @@ namespace Barotrauma allowWifiChat = o; } + public void OverrideSignalRadio(bool o) + { + overrideSignalRadio = o; + } + + public void DisableSpamFilter(bool o) + { + disableSpamFilter = o; + } + public static void Log(string message, ServerLog.MessageType type) { GameServer.Log(message, type); @@ -259,6 +281,16 @@ namespace Barotrauma return null; } + public static WifiComponent GetWifiComponent(Item item) + { + return item.GetComponent(); + } + + public static LightComponent GetLightComponent(Item item) + { + return item.GetComponent(); + } + public static void DispatchRespawnSub() { GameMain.Server.RespawnManager.DispatchShuttle(); @@ -279,6 +311,11 @@ namespace Barotrauma { GameMain.Server.StartGame(); } + + public static Signal CreateSignal(string value, int stepsTaken = 1, Character sender = null, Item source = null, float power = 0, float strength = 1) + { + return new Signal(value, stepsTaken, sender, source, power, strength); + } } diff --git a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs index 06d3284b7..93aa0e782 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Lua/LuaSetup.cs @@ -6,6 +6,7 @@ using Barotrauma.Networking; using MoonSharp.Interpreter; using Microsoft.Xna.Framework; using System.Threading.Tasks; +using Barotrauma.Items.Components; namespace Barotrauma { @@ -139,9 +140,18 @@ namespace Barotrauma UserData.RegisterType(); UserData.RegisterType(); UserData.RegisterType(); + UserData.RegisterType(); + UserData.RegisterType(); + UserData.RegisterType(); + UserData.RegisterType(); + UserData.RegisterType(); + UserData.RegisterType(); + UserData.RegisterType(); + UserData.RegisterType(); + UserData.RegisterType(); lua = new Script(CoreModules.Preset_SoftSandbox | CoreModules.LoadMethods); - + lua.Options.DebugPrint = PrintMessage; lua.Options.ScriptLoader = luaScriptLoader; @@ -169,14 +179,14 @@ namespace Barotrauma lua.Globals["TraitorMessageType"] = UserData.CreateStatic(); lua.Globals["CauseOfDeathType"] = UserData.CreateStatic(); lua.Globals["AfflictionPrefab"] = UserData.CreateStatic(); - lua.Globals["CharacterTeamType"] = UserData.CreateStatic(); - + lua.Globals["CharacterTeamType"] = UserData.CreateStatic(); lua.Globals["Vector2"] = UserData.CreateStatic(); lua.Globals["Vector3"] = UserData.CreateStatic(); lua.Globals["Vector4"] = UserData.CreateStatic(); lua.Globals["CreateVector2"] = (Func)CreateVector2; lua.Globals["CreateVector3"] = (Func)CreateVector3; lua.Globals["CreateVector4"] = (Func)CreateVector4; + lua.Globals["ChatMessage"] = UserData.CreateStatic(); foreach (string d in Directory.GetDirectories("Mods")) { diff --git a/Barotrauma/BarotraumaServer/ServerSource/Networking/ChatMessage.cs b/Barotrauma/BarotraumaServer/ServerSource/Networking/ChatMessage.cs index bbb1d8aed..938881052 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Networking/ChatMessage.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Networking/ChatMessage.cs @@ -88,7 +88,7 @@ namespace Barotrauma.Networking bool isOwner = GameMain.Server.OwnerConnection != null && c.Connection == GameMain.Server.OwnerConnection; - if (similarity + c.ChatSpamSpeed > 5.0f && !isOwner) + if (similarity + c.ChatSpamSpeed > 5.0f && !isOwner && !GameMain.Lua.game.disableSpamFilter) { GameMain.Server.KarmaManager.OnSpamFilterTriggered(c); diff --git a/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs b/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs index acee62a65..e54427268 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Networking/GameServer.cs @@ -11,6 +11,7 @@ using System.Diagnostics; using System.Linq; using System.Threading; using System.Xml.Linq; +using MoonSharp.Interpreter; namespace Barotrauma.Networking { @@ -3095,13 +3096,20 @@ namespace Barotrauma.Networking senderName = null; senderCharacter = null; } - else if (type == ChatMessageType.Radio) + else if (type == ChatMessageType.Radio && !GameMain.Lua.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.Lua.hook.Call("modifyChatMessage", new DynValue[] { UserData.Create(hookChatMsg), LuaSetup.CreateUserDataSafe(senderRadio) }); + + if (should != null && should.CastToBool()) + return; + //check which clients can receive the message and apply distance effects foreach (Client client in ConnectedClients) { @@ -3134,6 +3142,7 @@ namespace Barotrauma.Networking break; } + var chatMsg = ChatMessage.Create( senderName, modifiedMessage, @@ -3141,7 +3150,7 @@ namespace Barotrauma.Networking senderCharacter, senderClient, changeType); - + SendDirectChatMessage(chatMsg, client); } diff --git a/Barotrauma/BarotraumaServer/ServerSource/Networking/Voip/VoipServer.cs b/Barotrauma/BarotraumaServer/ServerSource/Networking/Voip/VoipServer.cs index 4fcdc6f73..39547a704 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Networking/Voip/VoipServer.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Networking/Voip/VoipServer.cs @@ -3,6 +3,7 @@ using Microsoft.Xna.Framework; using System; using System.Collections.Generic; using System.Text; +using MoonSharp.Interpreter; namespace Barotrauma.Networking { @@ -93,6 +94,11 @@ namespace Barotrauma.Networking ChatMessage.CanUseRadio(sender.Character, out WifiComponent senderRadio) && ChatMessage.CanUseRadio(recipient.Character, out WifiComponent recipientRadio)) { + var should = GameMain.Lua.hook.Call("canUseVoiceRadio", new DynValue[] { UserData.Create(sender), LuaSetup.CreateUserDataSafe(recipient) }); + + if (should != null) + return should.CastToBool(); + if (recipientRadio.CanReceive(senderRadio)) { return true; } } diff --git a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/ItemComponent.cs b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/ItemComponent.cs index 8365d479f..82ef95bcc 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/ItemComponent.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/ItemComponent.cs @@ -5,6 +5,8 @@ using System.Linq; using System.Reflection; using System.Xml.Linq; using Barotrauma.Extensions; +using Barotrauma; +using MoonSharp.Interpreter; #if CLIENT using Microsoft.Xna.Framework.Graphics; using Barotrauma.Sounds; @@ -432,8 +434,18 @@ namespace Barotrauma.Items.Components //called then the item is dropped or dragged out of a "limbslot" public virtual void Unequip(Character character) { } + + Dictionary lastSignal = new Dictionary(); public virtual void ReceiveSignal(Signal signal, Connection connection) { +#if SERVER + if (!lastSignal.ContainsValue(connection.Name) || lastSignal[connection.Name] != signal.value) + { + GameMain.Lua.hook.Call("signalReceived", new DynValue[] { UserData.Create(signal), UserData.Create(connection) }); + + lastSignal[connection.Name] = signal.value; + } +#endif switch (connection.Name) { case "activate": diff --git a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Signal/Signal.cs b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Signal/Signal.cs index 6680d82ff..12f5d80ce 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Signal/Signal.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Signal/Signal.cs @@ -1,13 +1,13 @@ namespace Barotrauma.Items.Components { - public struct Signal + struct Signal { - internal string value; - internal int stepsTaken; - internal Character sender; - internal Item source; - internal float power; - internal float strength; + public string value; + public int stepsTaken; + public Character sender; + public Item source; + public float power; + public float strength; internal Signal(string value, int stepsTaken = 0, Character sender = null, Item source = null, float power = 0.0f, float strength = 1.0f) diff --git a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Signal/WifiComponent.cs b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Signal/WifiComponent.cs index 79c26f871..7547d590c 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Signal/WifiComponent.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Signal/WifiComponent.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Xml.Linq; +using MoonSharp.Interpreter; namespace Barotrauma.Items.Components { @@ -185,6 +186,13 @@ namespace Barotrauma.Items.Components var senderComponent = signal.source?.GetComponent(); if (senderComponent != null && !CanReceive(senderComponent)) { return; } +#if SERVER + var should = GameMain.Lua.hook.Call("wifiSignalTransmitted", new DynValue[] { UserData.Create(this), UserData.Create(signal), DynValue.NewBoolean(sentFromChat) }); + + if (should != null && should.CastToBool()) + return; +#endif + bool chatMsgSent = false; var receivers = GetReceiversInRange(); @@ -243,6 +251,7 @@ namespace Barotrauma.Items.Components Client recipientClient = GameMain.Server.ConnectedClients.Find(c => c.Character == wifiComp.item.ParentInventory.Owner); if (recipientClient != null) { + GameMain.Server.SendDirectChatMessage( ChatMessage.Create(signal.source?.Name ?? "", chatMsg, ChatMessageType.Radio, null), recipientClient); } diff --git a/Barotrauma/BarotraumaShared/SharedSource/Map/Gap.cs b/Barotrauma/BarotraumaShared/SharedSource/Map/Gap.cs index 068076ada..3b164563a 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Map/Gap.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Map/Gap.cs @@ -5,6 +5,7 @@ using Microsoft.Xna.Framework; using System; using System.Collections.Generic; using System.Xml.Linq; +using MoonSharp.Interpreter; namespace Barotrauma { @@ -648,6 +649,13 @@ namespace Barotrauma if (Math.Max(hull1.WorldSurface + hull1.WaveY[hull1.WaveY.Length - 1], hull2.WorldSurface + hull2.WaveY[0]) > WorldRect.Y) { return; } } +#if SERVER + var should = GameMain.Lua.hook.Call("gapOxygenUpdate", new DynValue[] { UserData.Create(this), UserData.Create(hull1), UserData.Create(hull2) }); + + if (should != null && should.CastToBool()) + return; +#endif + float totalOxygen = hull1.Oxygen + hull2.Oxygen; float totalVolume = (hull1.Volume + hull2.Volume); diff --git a/Barotrauma/BarotraumaShared/SharedSource/Networking/ChatMessage.cs b/Barotrauma/BarotraumaShared/SharedSource/Networking/ChatMessage.cs index c60de64dd..15efecf08 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Networking/ChatMessage.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Networking/ChatMessage.cs @@ -47,7 +47,7 @@ namespace Barotrauma.Networking new Color(255, 128, 0) //order }; - public readonly string Text; + public string Text; private string translatedText; public string TranslatedText @@ -74,8 +74,8 @@ namespace Barotrauma.Networking public PlayerConnectionChangeType ChangeType; public string IconStyle; - public readonly Character Sender; - public readonly Client SenderClient; + public Character Sender; + public Client SenderClient; public readonly string SenderName;