public GameObject GetPlayerFromConnectedPlayers(string _playerID) { if (ConnectedPlayers.ContainsKey(_playerID)) { return(ConnectedPlayers[_playerID]); } return(null); }
public void RemovePlayerFromConnectedPlayers(string _playerID) { if (ConnectedPlayers.ContainsKey(_playerID)) { ConnectedPlayers.Remove(_playerID); NumConnectedPlayers--; } }
public void AddPlayerToConnectedPlayers(string _playerID, GameObject _playerObject) { if (!ConnectedPlayers.ContainsKey(_playerID)) { ConnectedPlayers.Add(_playerID, _playerObject); NumConnectedPlayers++; } }
public bool Register(string nick) { if (ConnectedPlayers.ContainsKey(nick)) { return(false); } ConnectedPlayers.Add(nick, new PlayingClient(ClientCallback)); return(true); }
protected override void Load() { try { var stopwatch = Stopwatch.StartNew(); Instance = this; R.Plugins.OnPluginsLoaded += OverrideCommands; TaskExecutor = new EssentialsTaskExecutor(); SteamGameServer.SetKeyValue("essversion", PLUGIN_VERSION); Logger = new ConsoleLogger("[uEssentials] "); _consoleTraceListener = new EssentialsConsoleTraceListener(); Debug.Listeners.Add(_consoleTraceListener); Provider.onServerDisconnected += PlayerDisconnectCallback; Provider.onServerConnected += PlayerConnectCallback; Logger.LogInfo("Enabling uEssentials..."); new [] { "Plugin version: ~white~" + PLUGIN_VERSION + BUILD_INFO, "Recommended Rocket version: ~white~" + ROCKET_VERSION, "Recommended Unturned version: ~white~" + UNTURNED_VERSION, "Author: ~white~leonardosnt", "Wiki: ~white~uessentials.github.io", }.ForEach(text => Logger.LogInfo(text, true)); // This is true when the plugin is reloaded. if (Provider.clients.Count > 0) { Provider.clients.ForEach(p => { var steamID = p.playerID.steamID.m_SteamID; if (!ConnectedPlayers.ContainsKey(steamID)) { ConnectedPlayers.Add(steamID, new UPlayer(UnturnedPlayer.FromSteamPlayer(p))); } }); } _folder = Rocket.Core.Environment.PluginsDirectory + "/uEssentials/"; _translationFolder = Folder + "translations/"; _dataFolder = Folder + "data/"; _modulesFolder = Folder + "modules/"; CommandOptions = new CommandOptions(); Updater = new GithubUpdater(); EventManager = new EventManager(); CommandManager = new CommandManager(); ModuleManager = new ModuleManager(); HookManager = new HookManager(); WebResources = new WebResources(); Config = new EssConfig(); var webResourcesPath = Path.Combine(Folder, WebResources.FileName); var configPath = Path.Combine(Folder, Config.FileName); WebResources.Load(webResourcesPath); // Sync web config with local config.json if (WebResources.Loaded.ContainsKey("Config")) { File.WriteAllText(configPath, WebResources.Loaded["Config"]); } Config.Load(configPath); CommandOptions.Load(Path.Combine(Folder, CommandOptions.FileName)); EssLang.Load(); EventManager.RegisterAll(GetType().Assembly); // Register all commands from namespace Essentials.Commands CommandManager.RegisterAll("Essentials.Commands"); HookManager.RegisterAll(); HookManager.LoadAll(); // Load after EventManager because we relies on it inside this routine. ConfigPostLoad(); LoadNativeModules(); Logger.LogInfo("Loading modules..."); ModuleManager.LoadAll(ModulesFolder); Logger.LogInfo($"Loaded {ModuleManager.RunningModules.Count(t => !(t is NativeModule))} modules"); // We log it here because the modules being loaded above can // register commands. Logger.LogInfo($"Loaded {CommandManager.Commands.Count()} commands"); #if EXPERIMENTAL Logger.LogWarning("THIS IS AN EXPERIMENTAL BUILD, IT CAN BE BUGGY."); Logger.LogWarning("THIS IS AN EXPERIMENTAL BUILD, IT CAN BE BUGGY."); #endif // Delete useless files generated by Rocket Task.Create() .Id("Delete Xml Files") .Delay(TimeSpan.FromSeconds(1)) .Async() .Action(() => { File.Delete($"{Folder}uEssentials.en.translation.xml"); File.Delete($"{Folder}uEssentials.configuration.xml"); }) .Submit(); // If _wasLoadedBefore, then it means that uEssentials is // being reloaded, and it also means that R.Plugins.OnPluginsLoaded will not be called, // consequently OverrideCommands will not be called too // so we need to call it here. if (_wasLoadedBefore) { OverrideCommands(); } _wasLoadedBefore = true; CommandWindow.input.onInputText += ReloadCallback; Logger.LogInfo($"Enabled ({stopwatch.ElapsedMilliseconds} ms)"); } catch (Exception e) { string[] messages = { "An error occurred while enabling uEssentials.", "If this error is not related with wrong configuration, please report", "it here https://github.com/uEssentials/uEssentials/issues", "Error: " + e }; if (Logger == null) { Console.BackgroundColor = ConsoleColor.Red; messages.ForEach(Console.WriteLine); Console.BackgroundColor = ConsoleColor.White; } else { messages.ForEach(m => Logger.LogError(m)); } } #if !DEV Analytics.SendEvent($"ServerInit"); #endif #if DEV Console.Title = "Unturned Server"; #else CheckUpdates(); #endif }