aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS_TheReturn')
-rw-r--r--ShiftOS_TheReturn/Localization.cs4
-rw-r--r--ShiftOS_TheReturn/Server.cs40
-rw-r--r--ShiftOS_TheReturn/ServerManager.cs62
-rw-r--r--ShiftOS_TheReturn/ShiftOS.Engine.csproj1
-rw-r--r--ShiftOS_TheReturn/TerminalBackend.cs9
5 files changed, 111 insertions, 5 deletions
diff --git a/ShiftOS_TheReturn/Localization.cs b/ShiftOS_TheReturn/Localization.cs
index 2c701c9..5d848b0 100644
--- a/ShiftOS_TheReturn/Localization.cs
+++ b/ShiftOS_TheReturn/Localization.cs
@@ -117,10 +117,6 @@ namespace ShiftOS.Engine
}
List<string> orphaned = new List<string>();
- if (Utils.FileExists("0:/dev_orphaned_lang.txt"))
- {
- orphaned = JsonConvert.DeserializeObject<List<string>>(Utils.ReadAllText("0:/dev_orphaned_lang.txt")); // if this file exists read from it and put in list orphaned
- }
int start_index = 0;
diff --git a/ShiftOS_TheReturn/Server.cs b/ShiftOS_TheReturn/Server.cs
new file mode 100644
index 0000000..ddbd15b
--- /dev/null
+++ b/ShiftOS_TheReturn/Server.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ShiftOS.Objects;
+
+namespace ShiftOS.Engine
+{
+ public interface Server
+ {
+ /// <summary>
+ /// Occurs when someone sends a message to the server.
+ /// </summary>
+ /// <param name="msg">The message from the client.</param>
+ void MessageReceived(ServerMessage msg);
+ }
+
+ [AttributeUsage(AttributeTargets.Class, AllowMultiple=false)]
+ public class ServerAttribute : Attribute
+ {
+ public ServerAttribute(string name, int port)
+ {
+ Name = name;
+ Port = port;
+ }
+
+
+ /// <summary>
+ /// Gets the name of the server.
+ /// </summary>
+ public string Name { get; }
+
+ /// <summary>
+ /// Gets the port of the server.
+ /// </summary>
+ public int Port { get; }
+
+ }
+}
diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs
index 95e86e9..217b9ee 100644
--- a/ShiftOS_TheReturn/ServerManager.cs
+++ b/ShiftOS_TheReturn/ServerManager.cs
@@ -36,6 +36,8 @@ using static ShiftOS.Engine.SaveSystem;
using Newtonsoft.Json;
using System.Net.Sockets;
using System.Diagnostics;
+using System.IO;
+using System.Reflection;
namespace ShiftOS.Engine
{
@@ -104,6 +106,43 @@ Ping: {ServerManager.DigitalSocietyPing} ms
/// </summary>
public static event Action<string> GUIDReceived;
+ private static void delegateToServer(ServerMessage msg)
+ {
+ string[] split = msg.GUID.Split('|');
+ bool finished = false;
+ foreach (var exec in Directory.GetFiles(Environment.CurrentDirectory))
+ {
+ if(exec.ToLower().EndsWith(".exe") || exec.ToLower().EndsWith(".dll"))
+ {
+ try
+ {
+ var asm = Assembly.LoadFile(exec);
+ foreach(var type in asm.GetTypes().Where(x => x.GetInterfaces().Contains(typeof(Server))))
+ {
+ var attrib = type.GetCustomAttributes().FirstOrDefault(x => x is ServerAttribute) as ServerAttribute;
+ if(attrib != null)
+ {
+ if(split[0] == SaveSystem.CurrentSave.SystemName && split[1] == attrib.Port.ToString())
+ {
+ if (Shiftorium.UpgradeAttributesUnlocked(type))
+ {
+ type.GetMethods(BindingFlags.Public | BindingFlags.Instance).FirstOrDefault(x => x.Name == "MessageReceived")?.Invoke(Activator.CreateInstance(type), null);
+ finished = true;
+ }
+ }
+ }
+ }
+ }
+ catch { }
+ }
+ }
+ if (finished == false)
+ {
+ Forward(split[2], "Error", $"{split[0]}:{split[1]}: connection refused");
+ }
+ }
+
+
private static void ServerManager_MessageReceived(ServerMessage msg)
{
switch(msg.Name)
@@ -119,12 +158,35 @@ Ping: {ServerManager.DigitalSocietyPing} ms
}));
}
break;
+ case "msgtosys":
+ try
+ {
+ var m = JsonConvert.DeserializeObject<ServerMessage>(msg.Contents);
+ if(m.GUID.Split('|')[2] != thisGuid.ToString())
+ {
+ delegateToServer(m);
+ }
+ }
+ catch { }
+ break;
case "getguid_reply":
GUIDReceived?.Invoke(msg.Contents);
break;
}
}
+ public static void SendMessageToIngameServer(string sysname, int port, string title, string contents)
+ {
+ var smsg = new ServerMessage
+ {
+ Name = title,
+ GUID = $"{sysname}|{port}|{thisGuid.ToString()}",
+ Contents = contents
+ };
+ Forward("all", "msgtosys", JsonConvert.SerializeObject(smsg));
+
+ }
+
public static void Detach_ServerManager_MessageReceived()
{
MessageReceived -= new ServerMessageReceived(ServerManager_MessageReceived);
diff --git a/ShiftOS_TheReturn/ShiftOS.Engine.csproj b/ShiftOS_TheReturn/ShiftOS.Engine.csproj
index 8b48023..9d7d696 100644
--- a/ShiftOS_TheReturn/ShiftOS.Engine.csproj
+++ b/ShiftOS_TheReturn/ShiftOS.Engine.csproj
@@ -124,6 +124,7 @@
</Compile>
<Compile Include="SaveSystem.cs" />
<Compile Include="Scripting.cs" />
+ <Compile Include="Server.cs" />
<Compile Include="ServerManager.cs" />
<Compile Include="ShiftnetSite.cs" />
<Compile Include="Shiftorium.cs" />
diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs
index c8619b5..b18e27c 100644
--- a/ShiftOS_TheReturn/TerminalBackend.cs
+++ b/ShiftOS_TheReturn/TerminalBackend.cs
@@ -85,6 +85,11 @@ namespace ShiftOS.Engine
public static string LastCommand = "";
/// <summary>
+ /// Gets the output of the last command.
+ /// </summary>
+ public static string LastCommandBuffer { get; private set; }
+
+ /// <summary>
/// Invokes a ShiftOS terminal command.
/// </summary>
/// <param name="ns">The command's namespace.</param>
@@ -395,8 +400,10 @@ namespace ShiftOS.Engine
}
string buffer = tw.ToString();
+ LastCommandBuffer = buffer;
Console.SetOut(new TerminalTextWriter());
- Console.Write(buffer);
+ if(!isRemote)
+ Console.Write(buffer);
}