-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cs
153 lines (125 loc) · 6.35 KB
/
Main.cs
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using Average.Server.Data;
using CitizenFX.Core;
using CitizenFX.Core.Native;
using SDK.Server.Diagnostics;
using System;
using System.Reflection;
using System.Threading.Tasks;
using Average.Server.Managers;
using Newtonsoft.Json.Linq;
using SDK.Server.Rpc;
using SDK.Shared.Rpc;
namespace Average.Server
{
internal class Main : BaseScript
{
internal static SQL sql;
internal static RpcRequest rpc;
internal static Action<Func<Task>> attachCallback;
internal static Action<Func<Task>> detachCallback;
internal static EventHandlerDictionary eventHandlers;
internal static PlayerList players;
internal static PluginLoader loader;
#region Internal Scripts
internal static readonly CharacterManager character = new CharacterManager();
internal static readonly CommandManager command = new CommandManager();
internal static readonly EventManager evnt = new EventManager();
internal static readonly ExportManager export = new ExportManager();
internal static readonly PermissionManager permission = new PermissionManager();
internal static readonly RequestManager request = new RequestManager();
internal static readonly RequestInternalManager requestInternal = new RequestInternalManager();
internal static readonly SaveManager save = new SaveManager();
internal static readonly SyncManager sync = new SyncManager();
internal static readonly ThreadManager thread = new ThreadManager();
internal static readonly UserManager user = new UserManager();
internal static readonly JobManager job = new JobManager();
internal static readonly DoorManager door = new DoorManager();
internal static readonly CfxManager cfx = new CfxManager();
internal static readonly StorageManager storage = new StorageManager();
internal static readonly EnterpriseManager enterprise = new EnterpriseManager();
#endregion
public readonly bool isDebugEnabled;
private readonly JObject _baseConfig;
public Main()
{
_baseConfig = SDK.Server.Configuration.Parse("config.json");
isDebugEnabled = (bool)_baseConfig["IsDebugModeEnabled"];
Log.IsDebug = isDebugEnabled;
eventHandlers = EventHandlers;
players = Players;
rpc = new RpcRequest(new RpcHandler(eventHandlers), new RpcTrigger(players), new RpcSerializer());
attachCallback = c => Tick += c;
detachCallback = c => Tick -= c;
Log.Clear();
Watermark();
// rpc = new RpcRequest(new RpcHandler(EventHandlers), new RpcTrigger(Players), new RpcSerializer());
sql = new SQL();
sql.Connect();
loader = new PluginLoader();
// loader.Preload();
LoadInternalScript(request);
LoadInternalScript(permission);
LoadInternalScript(evnt);
LoadInternalScript(export);
LoadInternalScript(thread);
LoadInternalScript(command);
LoadInternalScript(sync);
LoadInternalScript(save);
LoadInternalScript(user);
LoadInternalScript(job);
LoadInternalScript(character);
LoadInternalScript(storage);
LoadInternalScript(door);
LoadInternalScript(cfx);
LoadInternalScript(enterprise);
// Plugin Loader
loader.Load();
}
#region Console Command
[Command("clear")]
private void ClearCommand()
{
Console.Clear();
}
#endregion
internal void LoadInternalScript(InternalPlugin script)
{
try
{
script.SetDependencies(sql, Players, new RpcRequest(new RpcHandler(eventHandlers), new RpcTrigger(Players), new RpcSerializer()), thread, character, command, evnt, export, permission, save, sync, user, request, requestInternal, job, door, storage, enterprise);
loader.RegisterThreads(script.GetType(), script);
loader.RegisterEvents(script.GetType(), script);
loader.RegisterExports(script.GetType(), script);
loader.RegisterSyncs(script.GetType(), script);
loader.RegisterGetSyncs(script.GetType(), script);
loader.RegisterCommands(script.GetType(), script);
loader.RegisterInternalPlugin(script);
script.OnInitialized();
Log.Write("Internal", $"% {script.Name} % registered successfully.", new Log.TextColor(ConsoleColor.Blue, ConsoleColor.White));
}
catch (Exception ex)
{
Log.Error($"Unable to loading script: {script.Name}. Error: {ex.Message}\n{ex.StackTrace}.");
}
}
internal void Watermark()
{
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine(" AAAAAAAA VVVVV VVVVV GGGGGGGGGGGGGG");
Console.WriteLine(" AAAAAAAAA VVVVV VVVVV GGGGGGGGGGGGGGGGGGG");
Console.WriteLine(" AAAAAAAAAA VVVVV VVVVV GGGGGGG GGGGGGGG");
Console.WriteLine(" AAAAA AAAAA VVVVV VVVVV GGGGGGG GGGGGGG");
Console.WriteLine(" AAAAA AAAAA VVVVV VVVVV GGGGGGGGGGG GGGGGGG");
Console.WriteLine(" AAAAA AAAAA VVVVV VVVVV GGGGGGGGGGGGG GGGGGGG");
Console.WriteLine(" AAAAA AAAAA VVVVV VVVVV GGGGGGGGG");
Console.WriteLine(" AAAAA AAAAA VVVVVVVVVV GGGGGGGGGGGGGGGGGGGG");
Console.WriteLine(" AAAAA AAAAA VVVVVVVVV GGGGGGGGGGGGGGGGGGGG");
Console.WriteLine(" AAAAA AAAAA VVVVVVVV GGGGGGGGGGGGGGGGG");
Console.WriteLine(" --------------------------------------------------------");
Console.WriteLine($" | VERSION {Assembly.GetExecutingAssembly().GetName().Version} | EARLY BUILD | {API.GetConvar("sv_maxclients", "")} SLOTS |");
Console.WriteLine(" --------------------------------------------------------");
Console.WriteLine("");
}
}
}