forked from RocketMod/Rocket.Unturned
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathU.cs
224 lines (197 loc) · 9.91 KB
/
U.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
using Rocket.API;
using Rocket.API.Collections;
using Rocket.API.Extensions;
using Rocket.Core;
using Rocket.Core.Assets;
using Rocket.Core.Extensions;
using Rocket.Core.Logging;
using Rocket.Core.Plugins;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Effects;
using Rocket.Unturned.Events;
using Rocket.Unturned.Permissions;
using Rocket.Unturned.Plugins;
using Rocket.Unturned.Serialisation;
using Rocket.Unturned.Utils;
using SDG.Unturned;
using Steamworks;
using System;
using System.Linq;
using System.Reflection;
using UnityEngine;
namespace Rocket.Unturned
{
public class U : MonoBehaviour, IRocketImplementation
{
private static GameObject rocketGameObject;
public static U Instance;
private static readonly TranslationList defaultTranslations = new TranslationList(){
{ "command_generic_failed_find_player","Failed to find player"},
{ "command_generic_invalid_parameter","Invalid Parameter"},
{ "command_generic_target_player_not_found","Target player not found"},
{ "command_generic_teleport_while_driving_error","You cannot teleport while driving or riding in a vehicle."},
{ "command_god_enable_console","{0} enabled Godmode"},
{ "command_god_enable_private","You can feel the strength now..."},
{ "command_god_disable_console","{0} disabled Godmode"},
{ "command_god_disable_private","The godly powers left you..."},
{ "command_vanish_enable_console","{0} enabled Vanishmode"},
{ "command_vanish_enable_private","You are vanished now..."},
{ "command_vanish_disable_console","{0} disabled Vanishmode"},
{ "command_vanish_disable_private","You are no longer vanished..."},
{ "command_duty_enable_console","{0} is in duty"},
{ "command_duty_enable_private","You are in duty now..."},
{ "command_duty_disable_console","{0} is no longer in duty"},
{ "command_duty_disable_private","You are no longer in duty..."},
{ "command_bed_no_bed_found_private","You do not have a bed to teleport to."},
{ "command_i_giving_console","Giving {0} item {1}:{2}"},
{ "command_i_giving_private","Giving you item {0}x {1} ({2})"},
{ "command_z_giving_console","Spawning {1} zombies near {0}"},
{ "command_z_giving_private","Spawning {0} zombies nearby"},
{ "command_i_giving_failed_private","Failed giving you item {0}x {1} ({2})"},
{ "command_v_giving_console","Giving {0} vehicle {1}"},
{ "command_v_giving_private","Giving you a {0} ({1})"},
{ "command_v_giving_failed_private","Failed giving you a {0} ({1})"},
{ "command_tps_tps","TPS: {0}"},
{ "command_tps_running_since","Running since: {0} UTC"},
{ "command_p_reload_private","Reloaded permissions"},
{ "command_p_groups_private","{0} groups are: {1}"},
{ "command_p_permissions_private","{0} permissions are: {1}"},
{ "command_tp_teleport_console","{0} teleported to {1}"},
{ "command_tp_teleport_private","Teleported to {0}"},
{ "command_tp_failed_find_destination","Failed to find destination"},
{ "command_tphere_teleport_console","{0} was teleported to {1}"},
{ "command_tphere_teleport_from_private","Teleported {0} to you"},
{ "command_tphere_teleport_to_private","You were teleported to {0}"},
{ "command_clear_error","There was an error clearing {0} inventory."},
{ "command_clear_private","Your inventory was cleared!"},
{ "command_clear_other","Your inventory was cleared by {0}!"},
{ "command_clear_other_success","You successfully cleared {0} inventory."},
{ "command_investigate_private","{0} SteamID64 is {1}"},
{ "command_heal_success_me","{0} was successfully healed"},
{ "command_heal_success_other","You were healed by {0}"},
{ "command_heal_success","You were healed"},
{ "command_compass_facing_private","You are facing {0}"},
{ "command_compass_north","N"},
{ "command_compass_east","E"},
{ "command_compass_south","S"},
{ "command_compass_west","W"},
{ "command_compass_northwest","NW"},
{ "command_compass_northeast","NE"},
{ "command_compass_southwest","SW"},
{ "command_compass_southeast","SE"},
{ "command_rocket_plugins_loaded","Loaded: {0}"},
{ "command_rocket_plugins_unloaded","Unloaded: {0}"},
{ "command_rocket_plugins_failure","Failure: {0}"},
{ "command_rocket_plugins_cancelled","Cancelled: {0}"},
{ "command_rocket_reload_plugin","Reloading {0}"},
{ "command_rocket_not_loaded","The plugin {0} is not loaded"},
{ "command_rocket_unload_plugin","Unloading {0}"},
{ "command_rocket_load_plugin","Loading {0}"},
{ "command_rocket_already_loaded","The plugin {0} is already loaded"},
{ "command_rocket_reload","Reloading Rocket"},
{ "command_p_group_not_found","Group not found"},
{ "command_p_group_assigned","{0} was assigned to the group {1}"},
{ "command_rocket_plugin_not_found","Plugin {0} not found"},
{ "command_clear_success","You successfully cleared {0} items"}
};
public static XMLFileAsset<UnturnedSettings> Settings;
public static XMLFileAsset<TranslationList> Translations;
public IRocketImplementationEvents ImplementationEvents { get { return Events; } }
public static UnturnedEvents Events;
public event RocketImplementationInitialized OnRocketImplementationInitialized;
public static string Translate(string translationKey, params object[] placeholder)
{
return Translations.Instance.Translate(translationKey, placeholder);
}
#if LINUX
public static UnturnedConsole Console;
#endif
internal static void Splash()
{
rocketGameObject = new GameObject("Rocket");
DontDestroyOnLoad(rocketGameObject);
#if LINUX
Console = rocketGameObject.AddComponent<UnturnedConsole>();
#endif
System.Console.Clear();
System.Console.ForegroundColor = ConsoleColor.Cyan;
System.Console.WriteLine("Rocket Unturned v" + Assembly.GetExecutingAssembly().GetName().Version.ToString() + " for Unturned v" + Steam.Version + "\n");
R.OnRockedInitialized += () =>
{
Instance.Initialize();
};
Steam.OnServerHosted += () =>
{
rocketGameObject.TryAddComponent<U>();
rocketGameObject.TryAddComponent<R>();
};
}
private void Awake()
{
Instance = this;
Environment.Initialize();
}
internal void Initialize()
{
try
{
Settings = new XMLFileAsset<UnturnedSettings>(Environment.SettingsFile);
Translations = new XMLFileAsset<TranslationList>(String.Format(Environment.TranslationFile, Core.R.Settings.Instance.LanguageCode), new Type[] { typeof(TranslationList), typeof(TranslationListEntry) }, defaultTranslations);
Events = gameObject.TryAddComponent<UnturnedEvents>();
gameObject.TryAddComponent<UnturnedEffectManager>();
gameObject.TryAddComponent<UnturnedPermissions>();
gameObject.TryAddComponent<UnturnedChat>();
gameObject.TryAddComponent<AutomaticSaveWatchdog>();
RocketPlugin.OnPluginLoading += (IRocketPlugin plugin, ref bool cancelLoading) =>
{
try
{
plugin.TryAddComponent<PluginUnturnedPlayerComponentManager>();
plugin.TryAddComponent<PluginCommandManager>();
}
catch (Exception ex)
{
Logger.LogException(ex, "Failed to load plugin " + plugin.Name + ".");
cancelLoading = true;
}
};
RocketPlugin.OnPluginUnloading += (IRocketPlugin plugin) =>
{
plugin.TryRemoveComponent<PluginUnturnedPlayerComponentManager>();
plugin.TryRemoveComponent<PluginCommandManager>();
};
PluginCommandManager.RegisterFromAssembly(Assembly.GetExecutingAssembly());
R.Plugins.OnPluginsLoaded += () =>
{
SteamGameServer.SetKeyValue("rocketplugins", String.Join(",", R.Plugins.GetPlugins().Select(p => p.Name).ToArray()));
};
SteamGameServer.SetKeyValue("rocket", Assembly.GetExecutingAssembly().GetName().Version.ToString());
SteamGameServer.SetBotPlayerCount(1);
OnRocketImplementationInitialized.TryInvoke();
}
catch (Exception ex)
{
Logger.LogException(ex);
}
}
public void Reload()
{
Translations.Reload();
Settings.Reload();
}
public void Shutdown()
{
Steam.shutdown();
}
public void Execute(IRocketPlayer player, string command)
{
ulong i = 0;
UInt64.TryParse(player.Id, out i);
Commander.execute(new CSteamID(i), command);
}
public string InstanceId
{
get { return Steam.InstanceName; }
}
}
}