plenty of new things

This commit is contained in:
Evil Factory
2021-08-15 17:17:49 -03:00
parent 06f40fa368
commit a2cb256aa6
10 changed files with 109 additions and 18 deletions

View File

@@ -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<WifiComponent>();
}
public static LightComponent GetLightComponent(Item item)
{
return item.GetComponent<LightComponent>();
}
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);
}
}

View File

@@ -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<MapEntity>();
UserData.RegisterType<CauseOfDeath>();
UserData.RegisterType<CharacterTeamType>();
UserData.RegisterType<Signal>();
UserData.RegisterType<Connection>();
UserData.RegisterType<ItemComponent>();
UserData.RegisterType<WifiComponent>();
UserData.RegisterType<LightComponent>();
UserData.RegisterType<Inventory>();
UserData.RegisterType<CharacterInventory>();
UserData.RegisterType<Hull>();
UserData.RegisterType<Gap>();
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<TraitorMessageType>();
lua.Globals["CauseOfDeathType"] = UserData.CreateStatic<CauseOfDeathType>();
lua.Globals["AfflictionPrefab"] = UserData.CreateStatic<AfflictionPrefab>();
lua.Globals["CharacterTeamType"] = UserData.CreateStatic<CharacterTeamType>();
lua.Globals["CharacterTeamType"] = UserData.CreateStatic<CharacterTeamType>();
lua.Globals["Vector2"] = UserData.CreateStatic<Vector2>();
lua.Globals["Vector3"] = UserData.CreateStatic<Vector3>();
lua.Globals["Vector4"] = UserData.CreateStatic<Vector3>();
lua.Globals["CreateVector2"] = (Func<float, float, Vector2>)CreateVector2;
lua.Globals["CreateVector3"] = (Func<float, float, float, Vector3>)CreateVector3;
lua.Globals["CreateVector4"] = (Func<float, float, float, float, Vector4>)CreateVector4;
lua.Globals["ChatMessage"] = UserData.CreateStatic<ChatMessage>();
foreach (string d in Directory.GetDirectories("Mods"))
{

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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; }
}

View File

@@ -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<string, string> lastSignal = new Dictionary<string, string>();
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":

View File

@@ -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)

View File

@@ -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<WifiComponent>();
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);
}

View File

@@ -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);

View File

@@ -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;