Skip to content

Commit

Permalink
* Finished implementing the Self Updater beta Version
Browse files Browse the repository at this point in the history
 * Pushing Working directory
  • Loading branch information
generalwrex committed Nov 8, 2017
1 parent b61a0a7 commit 5d9f51f
Show file tree
Hide file tree
Showing 14 changed files with 883 additions and 386 deletions.
309 changes: 140 additions & 169 deletions HellionExtendedServer/HESGui.Designer.cs

Large diffs are not rendered by default.

245 changes: 183 additions & 62 deletions HellionExtendedServer/HESGui.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion HellionExtendedServer/HellionExtendedServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
<Folder Include="API\Chat\" />
<Folder Include="API\Players\" />
<Folder Include="API\Vessels\" />
<Folder Include="Controllers\" />
<Folder Include="GUI\Tabs\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
Expand Down
9 changes: 4 additions & 5 deletions HellionExtendedServer/Managers/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ namespace HellionExtendedServer.Managers
public class NetworkManager
{
#region Fields

private static NetworkManager m_networkManager;
internal NetworkController m_network;
private static readonly Logger chatlogger = LogManager.GetCurrentClassLogger();

#endregion Fields

#region Properties
Expand All @@ -41,10 +39,11 @@ public NetworkManager(NetworkController networkController)
networkController.EventSystem.AddListener(typeof(PlayerSpawnRequest), new EventSystem.NetworkDataDelegate(PlayerSpawnRequestListener));
Log.Instance.Info("Player Spawns Listener Added.");

// [IN TEST] Could be used to detect when the player is physicly in the server
// [IN TEST] Could be used to detect when the player is physically in the server
networkController.EventSystem.AddListener(typeof(PlayersOnServerRequest), new EventSystem.NetworkDataDelegate(PlayerOnServerListener));
Log.Instance.Info("Player On Server Listener Added.");

// Getting when a player disconnects from the server
networkController.EventSystem.AddListener(typeof(LogOutRequest), new EventSystem.NetworkDataDelegate(LogOutRequestListener));
Log.Instance.Info("Log Out Request Listener Added.");

Expand Down Expand Up @@ -128,7 +127,7 @@ public void MessageAllClients(string msg, bool sendAsServer = true, bool printTo
TextChatMessage textChatMessage = new TextChatMessage();

textChatMessage.GUID = BitConverter.ToInt64(guid, 0);
textChatMessage.Name = (sendAsServer ? "Server: " : "");
textChatMessage.Name = (sendAsServer ? "Server" : "");
textChatMessage.MessageText = msg;
try
{
Expand All @@ -145,7 +144,7 @@ public void MessageAllClients(string msg, bool sendAsServer = true, bool printTo

if (!printToConsole)
return;
chatlogger.Info((string)textChatMessage.Name + " : " + msg);
chatlogger.Info((string)textChatMessage.Name + ": " + msg);


}
Expand Down
58 changes: 58 additions & 0 deletions HellionExtendedServer/Managers/Plugins/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,46 @@ public void ShutdownPlugin(String Plugin)
}
}

public List<Assembly> LoadPluginReferences(string pluginFolder)
{
List<Assembly> pluginReferences = new List<Assembly>();

try
{
string[] subDirectories = Directory.GetDirectories(pluginFolder);
foreach (string path in subDirectories)
{
string[] files = Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories);
foreach (string file in files)
{
try
{
if (IsValidAssembly(file))
{
Assembly pluginreference = Assembly.UnsafeLoadFrom(file);
pluginReferences.Add(pluginreference);
}
else
{
Console.WriteLine($"WARNING: '{Path.GetFileName(file)}' is not valid for plugin '{Path.GetDirectoryName(pluginFolder)}' Reference will not be loaded.");
}
}
catch (Exception ex)
{
Console.WriteLine($"Failed to load plugin reference assembly '{Path.GetFileName(file)}' for plugin '{Path.GetDirectoryName(pluginFolder)}' Error: " + ex.ToString());
}
}
}
return pluginReferences;
}
catch (Exception ex)
{
Console.WriteLine($"Failed to load plugin references for {Path.GetDirectoryName(pluginFolder)} Error: " + ex.ToString());
}

return null;
}

public List<PluginInfo> FindAllPlugins()
{
List<PluginInfo> foundPlugins = new List<PluginInfo>();
Expand All @@ -178,6 +218,10 @@ public List<PluginInfo> FindAllPlugins()

foreach (String subDirectory in subDirectories)
{
// We want to load the plugins references into memory before loading the
// actual plugin to avoid setting off the assembly resolver for hes
LoadPluginReferences(subDirectory);

PluginInfo Plugin = FindPlugin(subDirectory);

if (Plugin != null)
Expand Down Expand Up @@ -213,6 +257,7 @@ private PluginInfo ValidatePlugin(String library)
Assembly libraryAssembly;
try
{

Console.WriteLine("Loading Plugin Located at " + library);
bytes = File.ReadAllBytes(library);
libraryAssembly = Assembly.Load(bytes);
Expand Down Expand Up @@ -315,6 +360,19 @@ public PluginInfo HandelEvent(MethodInfo method, PluginInfo plugin, EventID eid)
return plugin;
}

// Utility method for loading plugin references
public bool IsValidAssembly(string path)
{
try
{
var assembly = AssemblyName.GetAssemblyName(path);
return true;
}
catch (Exception)
{
return false;
}
}
#endregion Methods
}
}
29 changes: 10 additions & 19 deletions HellionExtendedServer/Managers/ServerInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class ServerInstance
private DateTime m_launchedTime;
private Server m_server;
private ServerWrapper m_serverWrapper;
//private GameServerProperties m_gameServerProperties;
private GameServerIni m_gameServerIni;
private PluginManager m_pluginManager = null;
private CommandManager m_commandManager;
Expand All @@ -50,14 +49,12 @@ public class ServerInstance
public TimeSpan Uptime { get { return DateTime.Now - m_launchedTime; } }
public Assembly Assembly { get { return m_assembly; } }
public Server Server { get { return m_server; } }
//public GameServerProperties GameServerProperties { get { return m_gameServerProperties; } }
public GameServerIni GameServerConfig => m_gameServerIni;
public PluginManager PluginManager { get { return m_pluginManager; } }
public CommandManager CommandManager { get { return m_commandManager; } }
public EventHelper EventHelper { get { return m_eventhelper; } }
public PermissionManager PermissionManager { get { return m_permissionmanager; } }


public static ServerInstance Instance { get { return m_serverInstance; } }

public Boolean IsRunning
Expand All @@ -72,17 +69,11 @@ public Boolean IsRunning
m_isRunning = value;
if (m_isRunning)
{
if (OnServerRunning != null)
{
OnServerRunning(m_server);
}
OnServerRunning?.Invoke(m_server);
}
else
{
if (OnServerStopped != null)
{
OnServerStopped(m_server);
}
OnServerStopped?.Invoke(m_server);
}
}
}
Expand Down Expand Up @@ -170,15 +161,11 @@ public void Save(bool showToPLayer = false)
// Test method, please don't change ;)
public void Test()
{



foreach ( SpaceObjectVessel vessel in m_server.AllVessels)
{
Console.WriteLine(String.Format("Ship ({0}) Pos: {1} | Angles: {2} | Velocity: {3} | AngularVelocity: {4} ",vessel.GUID, vessel.Position.ToString(), vessel.Rotation.ToString(),vessel.Velocity, vessel.AngularVelocity));

}

}

/// <summary>
Expand All @@ -204,12 +191,11 @@ public void Start(int wait = 0)
};

m_serverThread = ServerWrapper.HellionDedi.StartServer(serverArgs);

m_serverWrapper.Init();

Thread.Sleep(5000);

m_server = ServerWrapper.HellionDedi.Server;
OnServerRunning?.Invoke(m_server);

if (IsRunning)
{
Expand All @@ -223,6 +209,8 @@ public void Start(int wait = 0)

Console.WriteLine(string.Format(HES.Localization.Sentences["ServerDesc"], DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss.ffff"), (Server.NetworkController.ServerID <= 0L ? "Not yet assigned" : string.Concat(Server.NetworkController.ServerID)), 64, num, (64 > num ? " WARNING: Server ticks is larger than max tick" : ""), Server.ServerName));
}


Server.NetworkController.EventSystem.RemoveListener(typeof(TextChatMessage), new EventSystem.NetworkDataDelegate(Server.TextChatMessageListener));//Deletes Old Listener
Server.NetworkController.EventSystem.AddListener(typeof(TextChatMessage), new EventSystem.NetworkDataDelegate(this.TextChatMessageListener));//Referances New Listener

Expand All @@ -248,7 +236,10 @@ public void Start(int wait = 0)

public void Stop()
{
PluginManager.ShutdownAllPlugins();
if(PluginManager.LoadedPlugins != null)
foreach (var plugin in PluginManager.LoadedPlugins)
PluginManager.ShutdownPlugin(plugin);

ServerWrapper.HellionDedi.StopServer();
m_serverThread.Join(60000);
m_serverThread.Abort();
Expand Down
Loading

0 comments on commit 5d9f51f

Please sign in to comment.