public void BanPlayerID(string id, string name = "1", string reason = "You were banned.", string adminname = "Unknown") { bool cancel = Hooks.OnBanEventHandler(new BanEvent(id, name, reason, adminname, true)); if (cancel) { return; } File.AppendAllText(Path.Combine(Util.GetRootFolder(), "Save\\BanLog.log"), "[" + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToString("HH:mm:ss") + "] " + name + "|" + id + "|" + adminname + "|" + reason + "\r\n"); DataStore.GetInstance().Add("Ids", id, name); }
public void BanPlayer(Fougerite.Player player, string Banner = "Console", string reason = "Te han baneado.", Fougerite.Player Sender = null, bool AnnounceToServer = false) { bool cancel = Hooks.OnBanEventHandler(new BanEvent(player, Banner, reason, Sender)); if (cancel) { return; } string red = "[color #FF0000]"; string green = "[color #009900]"; string white = "[color #FFFFFF]"; if (player.IsOnline && !player.IsDisconnecting) { player.SendClientMessage(red + " " + reason); player.SendClientMessage(red + " Baneado por: " + Banner); player.Disconnect(); } if (Sender != null) { Sender.SendClientMessage("Baneaste a " + player.Name); Sender.SendClientMessage("IP: " + player.IP); Sender.SendClientMessage("ID: " + player.SteamID); } if (!AnnounceToServer) { foreach (Fougerite.Player pl in Players.Where(pl => pl.Admin || pl.Moderator)) { pl.SendClientMessage(red + player.Name + white + " fue baneado por: " + green + Banner); pl.SendClientMessage(red + " Motivo: " + reason); } } else { Broadcast(red + player.Name + white + " fue baneado por: " + green + Banner); Broadcast(red + " Motivo: " + reason); } BanPlayerIPandID(player.IP, player.SteamID, player.Name, reason, Banner); }
public void AirdropAt(Vector3 target, int rep = 1) { Vector3 original = target; System.Random rand = new System.Random(); int r, reset; r = reset = 20; for (int i = 0; i < rep; i++) { r--; if (r == 0) { r = reset; target = original; } target.y = original.y + rand.Next(-5, 20) * 20; SupplyDropZone.CallAirDropAt(target); Hooks.Airdrop(target); Jitter(ref target); } }
internal static void LoadModules() { Logger.Log("[Modules] Loading modules..."); string IgnoredPluginsFilePath = Path.Combine(ModulesFolder, "ignoredmodules.txt"); List <string> IgnoredModules = new List <string>(); if (File.Exists(IgnoredPluginsFilePath)) { IgnoredModules.AddRange(File.ReadAllLines(IgnoredPluginsFilePath)); } DirectoryInfo[] DirectoryInfos = new DirectoryInfo(ModulesFolder).GetDirectories(); foreach (DirectoryInfo DirInfo in DirectoryInfos) { FileInfo FileInfo = new FileInfo(Path.Combine(DirInfo.FullName, DirInfo.Name + ".dll")); if (!FileInfo.Exists) { continue; } if (Array.IndexOf(Config.FougeriteConfig.EnumSection("Modules"), DirInfo.Name) == -1) { Logger.LogDebug(string.Format("[Modules] {0} is not configured to be loaded.", DirInfo.Name)); continue; } Logger.LogDebug("[Modules] Module Found: " + FileInfo.Name); string FileNameWithoutExtension = Path.GetFileNameWithoutExtension(FileInfo.Name); if (IgnoredModules.Contains(FileNameWithoutExtension)) { Logger.LogWarning(string.Format("[Modules] {0} was ignored from being loaded.", FileNameWithoutExtension)); continue; } try { Logger.LogDebug("[Modules] Loading assembly: " + FileInfo.Name); Assembly Assembly; // The plugin assembly might have been resolved by another plugin assembly already, so no use to // load it again, but we do still have to verify it and create plugin instances. if (!LoadedAssemblies.TryGetValue(FileNameWithoutExtension, out Assembly)) { Assembly = Assembly.Load(File.ReadAllBytes(FileInfo.FullName)); LoadedAssemblies.Add(FileNameWithoutExtension, Assembly); } foreach (Type Type in Assembly.GetExportedTypes()) { if (!Type.IsSubclassOf(typeof(Module)) || !Type.IsPublic || Type.IsAbstract) { continue; } Logger.LogDebug("[Modules] Checked " + Type.FullName); Module PluginInstance = null; try { PluginInstance = (Module)Activator.CreateInstance(Type); Logger.LogDebug("[Modules] Instance created: " + Type.FullName); } catch (Exception ex) { // Broken plugins better stop the entire server init. Logger.LogError(string.Format("[Modules] Could not create an instance of plugin class \"{0}\". {1}", Type.FullName, ex)); } if (PluginInstance != null) { ModuleContainer Container = new ModuleContainer(PluginInstance); Container.Plugin.ModuleFolder = Path.Combine(PublicFolder, Config.GetValue("Modules", DirInfo.Name).TrimStart(new char[] { '\\', '/' }).Trim()); Modules.Add(Container); GlobalPluginCollector.GetPluginCollector().AddPlugin(Container.Plugin.Name, Container, "C#"); Logger.LogDebug("[Modules] Module added: " + FileInfo.Name); break; } } } catch (Exception ex) { // Broken assemblies better stop the entire server init. Logger.LogError(string.Format("[Modules] Failed to load assembly \"{0}\". {1}", FileInfo.Name, ex)); } } IOrderedEnumerable <ModuleContainer> OrderedModuleSelector = from x in Plugins orderby x.Plugin.Order, x.Plugin.Name select x; foreach (ModuleContainer CurrentModule in OrderedModuleSelector) { try { CurrentModule.Initialize(); } catch (Exception ex) { // Broken modules better stop the entire server init. Logger.LogError(string.Format( "[Modules] Module \"{0}\" has thrown an exception during initialization. {1}", CurrentModule.Plugin.Name, ex)); } Logger.Log(string.Format( "[Modules] Module {0} v{1} (by {2}) initiated.", CurrentModule.Plugin.Name, CurrentModule.Plugin.Version, CurrentModule.Plugin.Author)); } Hooks.ModulesLoaded(); }
// funcoes normais private void SaveServer(object sender, DoWorkEventArgs e) { Logger.Log("SaveServer"); try { Logger.Log("SaveScene..."); SaveScene(ref builder); Logger.Log("SaveInstances..."); SaveInstances(ref builder); Logger.Log("Next saves..."); timestamp2.Stop(); timestamp3 = SystemTimestamp.Restart; fsave = builder.Build(); timestamp3.Stop(); int num = fsave.SceneObjectCount + fsave.InstanceObjectCount; Logger.Log("Salvando arquivo..." + path + " e seus backup."); SystemTimestamp timestamp5 = timestamp4 = SystemTimestamp.Restart; using (FileStream stream2 = File.Open(path + ".new", FileMode.Create, FileAccess.Write)) { fsave.WriteTo(stream2); stream2.Flush(); } timestamp4.Stop(); if (File.Exists(path + ".old." + (SaveCopies + 1))) { File.Delete(path + ".old." + (SaveCopies + 1)); } for (int i = SaveCopies; i >= 0; i--) { if (File.Exists(path + ".old." + i)) { File.Move(path + ".old." + i, path + ".old." + (i + 1)); } } if (File.Exists(path)) { File.Move(path, path + ".old.0"); } if (File.Exists(path + ".new")) { File.Move(path + ".new", path); } timestamp5.Stop(); restart.Stop(); if (Hooks.IsShuttingDown) { ServerIsSaving = false; Logger.Log(string.Concat(new object[] { " Saved ", num, " Object(s). Took ", restart.ElapsedSeconds, " seconds." })); //ProjectX.ProjectX.BroadCast(ProjectX.ProjectX.configServer.NameServer, "O servidor salvou [color green]" + num + "[/color] Objetos do mapa"); return; } Loom.QueueOnMainThread(() => { if (save.profile) { object[] args = new object[] { num, timestamp2.ElapsedSeconds, timestamp2.ElapsedSeconds / restart.ElapsedSeconds, timestamp3.ElapsedSeconds, timestamp3.ElapsedSeconds / restart.ElapsedSeconds, timestamp4.ElapsedSeconds, timestamp4.ElapsedSeconds / restart.ElapsedSeconds, timestamp5.ElapsedSeconds, timestamp5.ElapsedSeconds / restart.ElapsedSeconds, restart.ElapsedSeconds, restart.ElapsedSeconds / restart.ElapsedSeconds }; Logger.Log(string.Format(" Saved {0} Object(s) [times below are in elapsed seconds]\r\n Logic:\t{1,-16:0.000000}\t{2,7:0.00%}\r\n Build:\t{3,-16:0.000000}\t{4,7:0.00%}\r\n Stream:\t{5,-16:0.000000}\t{6,7:0.00%}\r\n All IO:\t{7,-16:0.000000}\t{8,7:0.00%}\r\n Total:\t{9,-16:0.000000}\t{10,7:0.00%}", args)); } else { Logger.Log(string.Concat(new object[] { " Saved ", num, " Object(s). Took ", restart.ElapsedSeconds, " seconds." })); //ProjectX.ProjectX.BroadCast(ProjectX.ProjectX.configServer.NameServer, "O servidor salvou [color green]" + num + "[/color] Objetos do mapa"); } Hooks.OnServerSaveEvent(num, restart.ElapsedSeconds); ServerIsSaving = false; LastSaveTime = DateTime.Now; // Process the unprocessed hashset values here without causing HashSet modified error. List <ServerSave> RemovableKeys = new List <ServerSave>(); foreach (ServerSave x in UnProcessedSaves.Keys) { try { if (UnProcessedSaves.ContainsKey(x)) { byte value = UnProcessedSaves[x]; if (value == 1) { if (ServerSaveManager.Instances.registers.Add(x)) { ServerSaveManager.Instances.ordered.Add(x); } ServerSaveManager.Instances.ordered.Add(x); } else { if (ServerSaveManager.Instances.registers.Remove(x)) { ServerSaveManager.Instances.ordered.Remove(x); } } RemovableKeys.Add(x); } } catch (KeyNotFoundException ex) { Logger.LogError("[RegisterHook KeyNotFoundException] " + ex); } catch (Exception ex) { Logger.LogError("[RegisterHook Error] " + ex); } } foreach (var x in RemovableKeys) { UnProcessedSaves.Remove(x); } }); } catch (Exception ex) { Logger.LogError("[ServerSaveHandler Error 0x2] " + ex); ServerIsSaving = false; LastSaveTime = DateTime.Now; NextServerSaveTime = LastSaveTime.AddMinutes(ServerSaveTime); if (StopServerOnSaveFail) { Logger.LogWarning("[Fougerite WorldSave] We have caught an error. Killing server as requested."); Process.GetCurrentProcess().Kill(); } } finally { if (e != null && sender != null) { Invoke(nameof(SalvarMapaComBackgroundWorker), ServerSaveTime * 60); } } }