-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBootstrap.cs
More file actions
110 lines (86 loc) · 2.63 KB
/
Bootstrap.cs
File metadata and controls
110 lines (86 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
namespace Pluton.Core
{
using System;
using System.IO;
using System.Timers;
using UnityEngine;
using System.Linq;
public class Bootstrap : MonoBehaviour
{
public static string Version => System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
public static ServerTimers timers;
public static bool PlutonLoaded = false;
public static void AttachBootstrap()
{
try {
var path = ((Environment.OSVersion.Platform == PlatformID.Unix) ? Path.DirectorySeparatorChar.ToString() : "") + System.Reflection.Assembly.GetExecutingAssembly().Location.Replace(Path.DirectorySeparatorChar + "Pluton.Core.dll", "");
foreach (var file in Directory.GetFiles(path, "Pluton.*.dll")) {
if (!file.EndsWith("Pluton.Core.dll")) {
System.Reflection.Assembly module = System.Reflection.Assembly.LoadFile(file);
foreach (var type in module.GetTypes()) {
if (type.ToString() == file.Split(Path.DirectorySeparatorChar).Last().Replace("dll", "Bootstrap")) {
module.CreateInstance(type.ToString());
}
}
}
}
DirectoryConfig.GetInstance();
CoreConfig.GetInstance();
Config.GetInstance();
Init();
PlutonLoaded = true;
Console.WriteLine($"[v.{Version}] Pluton loaded!");
} catch (Exception ex) {
Debug.LogException(ex);
Debug.Log("[Bootstarp] Error while loading Pluton!");
}
}
public static void SaveAll(object x = null)
{
try {
DataStore.GetInstance().Save();
} catch (Exception ex) {
Logger.LogDebug("[Bootstrap] Failed to save the server!");
Logger.LogException(ex);
}
}
public static void ReloadTimers()
{
if (timers != null)
timers.Dispose();
var saver = Config.GetInstance().GetValue("Config", "saveInterval", "180000");
if (saver != null) {
double save = Double.Parse(saver);
timers = new ServerTimers(save);
timers.Start();
}
}
public static void Init()
{
if (!Directory.Exists(Util.GetInstance().GetPublicFolder()))
Directory.CreateDirectory(Util.GetInstance().GetPublicFolder());
Logger.Init();
CryptoExtensions.Init();
DataStore.GetInstance().Load();
ReloadTimers();
}
public class ServerTimers
{
public readonly Timer _savetimer;
public ServerTimers(double save)
{
_savetimer = new Timer(save);
Debug.Log("Server timers started!");
_savetimer.Elapsed += _savetimer_Elapsed;
}
public void Dispose()
{
Stop();
_savetimer.Dispose();
}
public void Start() => _savetimer.Start();
public void Stop() => _savetimer.Stop();
private void _savetimer_Elapsed(object sender, ElapsedEventArgs e) => SaveAll();
}
}
}