internal void OnCompilationSucceeded(Oxide.Plugins.CompiledAssembly compiledAssembly) { if (this.timeoutTimer == null) { Interface.Oxide.LogWarning(string.Concat("Ignored unexpected plugin compilation: ", this.Name), Array.Empty <object>()); return; } Oxide.Core.Libraries.Timer.TimerInstance timerInstance = this.timeoutTimer; if (timerInstance != null) { timerInstance.Destroy(); } else { } this.timeoutTimer = null; this.IsCompilationNeeded = false; this.CompilationQueuedAt = 0f; this.CompiledAssembly = compiledAssembly; Action <bool> compileCallback = this.CompileCallback; if (compileCallback == null) { return; } compileCallback(true); }
internal void OnCompilationFailed() { if (this.timeoutTimer == null) { Interface.Oxide.LogWarning(string.Concat("Ignored unexpected plugin compilation failure: ", this.Name), Array.Empty <object>()); return; } Oxide.Core.Libraries.Timer.TimerInstance timerInstance = this.timeoutTimer; if (timerInstance != null) { timerInstance.Destroy(); } else { } this.timeoutTimer = null; this.CompilationQueuedAt = 0f; this.LastCompiledAt = new DateTime(); Action <bool> compileCallback = this.CompileCallback; if (compileCallback != null) { compileCallback(false); } else { } this.IsCompilationNeeded = false; }
void myOnServerInitialized() { DateTime configTime; DateTime mainTime = DateTime.UtcNow; if (Config["Status"].ToString() == DisabledStr) { PrintShutdownStatus(); return; } // Set up timer for server save and shutdown try { configTime = DateTime.ParseExact(Config["UTC_Time"].ToString(), TimeFormat, null); } catch (Exception e) { PrintShutdownStatus(); return; } DateTime shutdownTime = new DateTime(mainTime.Year, mainTime.Month, mainTime.Day, configTime.Hour, configTime.Minute, configTime.Second, DateTimeKind.Utc); if (mainTime > shutdownTime) { shutdownTime = shutdownTime.AddDays(1); } long shutdownInterval = Convert.ToInt64((shutdownTime - mainTime).TotalSeconds); // schedule the server save command. Oxide.Core.Libraries.Timer.TimerInstance newTimer = MainTimer.Once(shutdownInterval, () => ConsoleSystem.Run.Server.Normal("server.save")); Timers.Add(newTimer); // schedule the restart command. Restart simply shuts down the server after a 60-second countdown newTimer = MainTimer.Once(shutdownInterval, () => ConsoleSystem.Run.Server.Normal("restart")); Timers.Add(newTimer); PrintShutdownStatus(); }
void CalculateTimers() { foreach (KeyValuePair <string, object> pair in (Dictionary <string, object>)Config["HappyHours"]) { string[] Hour = pair.Key.Split(':'); long CurrentTime = MainTime.GetUnixTimestamp(); DateTime EventTimeData = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, Convert.ToInt32(Hour[0]), Convert.ToInt32(Hour[1]), Convert.ToInt32(Hour[2]), DateTimeKind.Utc); long EventTime = Convert.ToInt64((EventTimeData - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds); if (CurrentTime > EventTime) { EventTimeData = EventTimeData.AddDays(1); EventTime = Convert.ToInt64((EventTimeData - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds); } Dictionary <string, object> Event = (Dictionary <string, object>)pair.Value; Event["NextEvent"] = EventTime.ToString(); List <ItemDefinition> AllItems = ItemManager.GetItemDefinitions(); Dictionary <string, object> Items = (Dictionary <string, object>)Event["Items"]; foreach (KeyValuePair <string, object> zItem in (Dictionary <string, object>)Items) { Dictionary <string, object> CurrentItem = (Dictionary <string, object>)zItem.Value; foreach (ItemDefinition SearchItem in AllItems) { if (SearchItem.displayName.english == zItem.Key.ToString()) { CurrentItem["ID"] = SearchItem.shortname.ToString(); } } } Oxide.Core.Libraries.Timer.TimerInstance newTimer = MainTimer.Once(EventTime - CurrentTime, () => HappyHours(this, pair), this); Timers.Add(newTimer); WriteConsole(string.Format("Happy Hour : Added happy hour @ UTC {0} : Next occurrence with server timezone {1}.", pair.Key.ToString(), EventTimeData.ToLocalTime().ToString())); } SaveConfig(); }
internal virtual void OnCompilationStarted() { this.LastCompiledAt = this.LastModifiedAt; Oxide.Core.Libraries.Timer.TimerInstance timerInstance1 = this.timeoutTimer; if (timerInstance1 != null) { timerInstance1.Destroy(); } else { } this.timeoutTimer = null; Interface.Oxide.NextTick(() => { Oxide.Core.Libraries.Timer.TimerInstance timerInstance = this.timeoutTimer; if (timerInstance != null) { timerInstance.Destroy(); } else { } this.timeoutTimer = CompilableFile.timer.Once(60f, new Action(this.OnCompilationTimeout), null); }); }
private bool CheckCompiler() { PluginCompiler.CheckCompilerBinary(); Oxide.Core.Libraries.Timer.TimerInstance timerInstance = this.idleTimer; if (timerInstance != null) { timerInstance.Destroy(); } else { } if (PluginCompiler.BinaryPath == null) { return(false); } if (this.process != null && this.process.Handle != IntPtr.Zero && !this.process.HasExited) { return(true); } PluginCompiler.SetCompilerVersion(); PluginCompiler.PurgeOldLogs(); this.Shutdown(); string[] strArrays = new string[] { "/service", string.Concat("/logPath:", PluginCompiler.EscapePath(Interface.Oxide.LogDirectory)) }; try { Process process = new Process(); process.StartInfo.FileName = PluginCompiler.BinaryPath; process.StartInfo.Arguments = string.Join(" ", strArrays); process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.EnableRaisingEvents = true; this.process = process; switch (Environment.OSVersion.Platform) { case PlatformID.Win32S: case PlatformID.Win32Windows: case PlatformID.Win32NT: { string environmentVariable = Environment.GetEnvironmentVariable("PATH"); Environment.SetEnvironmentVariable("PATH", string.Concat(environmentVariable, ";", Path.Combine(Interface.Oxide.ExtensionDirectory, "x86"))); goto case PlatformID.Xbox; } case PlatformID.WinCE: case PlatformID.Xbox: { this.process.Exited += new EventHandler(this.OnProcessExited); this.process.Start(); break; } case PlatformID.Unix: case PlatformID.MacOSX: { string str = Environment.GetEnvironmentVariable("LD_LIBRARY_PATH"); this.process.StartInfo.EnvironmentVariables["LD_LIBRARY_PATH"] = Path.Combine(Interface.Oxide.ExtensionDirectory, (IntPtr.Size == 8 ? "x64" : "x86")); Environment.SetEnvironmentVariable("LD_LIBRARY_PATH", string.Concat(str, ":", Path.Combine(Interface.Oxide.ExtensionDirectory, (IntPtr.Size == 8 ? "x64" : "x86")))); goto case PlatformID.Xbox; } default: { goto case PlatformID.Xbox; } } } catch (Exception exception1) { Exception exception = exception1; Process process1 = this.process; if (process1 != null) { process1.Dispose(); } else { } this.process = null; Interface.Oxide.LogException(string.Concat("Exception while starting compiler version ", PluginCompiler.CompilerVersion, ": "), exception); if (PluginCompiler.BinaryPath.Contains("'")) { Interface.Oxide.LogWarning("Server directory path contains an apostrophe, compiler will not work until path is renamed", Array.Empty <object>()); } else if (Environment.OSVersion.Platform == PlatformID.Unix) { Interface.Oxide.LogWarning("Compiler may not be set as executable; chmod +x or 0744/0755 required", Array.Empty <object>()); } if (exception.GetBaseException() != exception) { Interface.Oxide.LogException("BaseException: ", exception.GetBaseException()); } Win32Exception win32Exception = exception as Win32Exception; if (win32Exception != null) { Interface.Oxide.LogError("Win32 NativeErrorCode: {0} ErrorCode: {1} HelpLink: {2}", new object[] { win32Exception.NativeErrorCode, win32Exception.ErrorCode, win32Exception.HelpLink }); } } if (this.process == null) { return(false); } this.client = new ObjectStreamClient <CompilerMessage>(this.process.StandardOutput.BaseStream, this.process.StandardInput.BaseStream); this.client.Message += new ConnectionMessageEventHandler <CompilerMessage, CompilerMessage>(this.OnMessage); this.client.Error += new StreamExceptionEventHandler(PluginCompiler.OnError); this.client.Start(); return(true); }
private void OnMessage(ObjectStreamConnection <CompilerMessage, CompilerMessage> connection, CompilerMessage message) { Func <string, bool> func = null; if (message == null) { Interface.Oxide.NextTick(() => { this.OnCompilerFailed(string.Concat("compiler version ", PluginCompiler.CompilerVersion, " disconnected")); this.DependencyTrace(); this.Shutdown(); }); return; } switch (message.Type) { case CompilerMessageType.Assembly: { Compilation item = this.compilations[message.Id]; if (item == null) { Interface.Oxide.LogWarning("Compiler compiled an unknown assembly", Array.Empty <object>()); return; } item.endedAt = Interface.Oxide.Now; string extraData = (string)message.ExtraData; if (extraData != null) { string[] strArrays = extraData.Split(new char[] { '\r', '\n' }); for (int i = 0; i < (int)strArrays.Length; i++) { string str = strArrays[i]; Match match = this.fileErrorRegex.Match(str.Trim()); for (int j = 1; j < match.Groups.Count; j++) { string value = match.Groups[j].Value; if (value.Trim() != string.Empty) { string str1 = value.Basename(null); string str2 = str1.Substring(0, str1.Length - 3); CompilablePlugin compilablePlugin = item.plugins.SingleOrDefault <CompilablePlugin>((CompilablePlugin pl) => pl.ScriptName == str2); if (compilablePlugin != null) { HashSet <string> requires = compilablePlugin.Requires; Func <string, bool> func1 = func; if (func1 == null) { Func <string, bool> func2 = (string name) => !item.IncludesRequiredPlugin(name); Func <string, bool> func3 = func2; func = func2; func1 = func3; } IEnumerable <string> strs = requires.Where <string>(func1); if (!strs.Any <string>()) { string str3 = str.Trim(); string pluginDirectory = Interface.Oxide.PluginDirectory; char directorySeparatorChar = Path.DirectorySeparatorChar; compilablePlugin.CompilerErrors = str3.Replace(string.Concat(pluginDirectory, directorySeparatorChar.ToString()), string.Empty); } else { compilablePlugin.CompilerErrors = string.Concat("Missing dependencies: ", strs.ToSentence <string>()); } } else { Interface.Oxide.LogError(string.Concat("Unable to resolve script error to plugin: ", str), Array.Empty <object>()); } } } } } item.Completed((byte[])message.Data); this.compilations.Remove(message.Id); Oxide.Core.Libraries.Timer.TimerInstance timerInstance1 = this.idleTimer; if (timerInstance1 != null) { timerInstance1.Destroy(); } else { } if (!PluginCompiler.AutoShutdown) { return; } Interface.Oxide.NextTick(() => { Oxide.Core.Libraries.Timer.TimerInstance timerInstance = this.idleTimer; if (timerInstance != null) { timerInstance.Destroy(); } else { } if (PluginCompiler.AutoShutdown) { this.idleTimer = Interface.Oxide.GetLibrary <Oxide.Core.Libraries.Timer>(null).Once(60f, new Action(this.Shutdown), null); } }); return; } case CompilerMessageType.Compile: case CompilerMessageType.Exit: { return; } case CompilerMessageType.Error: { Interface.Oxide.LogError("Compilation error: {0}", new object[] { message.Data }); this.compilations[message.Id].Completed(null); this.compilations.Remove(message.Id); Oxide.Core.Libraries.Timer.TimerInstance timerInstance2 = this.idleTimer; if (timerInstance2 != null) { timerInstance2.Destroy(); } else { } if (!PluginCompiler.AutoShutdown) { return; } Interface.Oxide.NextTick(() => { Oxide.Core.Libraries.Timer.TimerInstance timerInstance = this.idleTimer; if (timerInstance != null) { timerInstance.Destroy(); } else { } this.idleTimer = Interface.Oxide.GetLibrary <Oxide.Core.Libraries.Timer>(null).Once(60f, new Action(this.Shutdown), null); }); return; } case CompilerMessageType.Ready: { connection.PushMessage(message); if (this.ready) { return; } this.ready = true; while (this.messageQueue.Count > 0) { connection.PushMessage(this.messageQueue.Dequeue()); } return; } default: { return; } } }
private void HappyHours(object sender, object PairObj) { HappyHour myPlugin = (HappyHour)sender; KeyValuePair <string, object> pair = (KeyValuePair <string, object>)PairObj; long CurrentTime = MainTime.GetUnixTimestamp(); Dictionary <string, object> Event = (Dictionary <string, object>)pair.Value; if (CurrentTime < (Convert.ToInt64(Event["NextEvent"].ToString()) + Convert.ToInt64(myPlugin.Config["Time"].ToString()))) { foreach (BasePlayer Player in BasePlayer.activePlayerList) { if (myPlugin.Users.ContainsKey(Player.userID.ToString()) == false) { myPlugin.myPrintToChat(Player, Event["Message"].ToString()); Dictionary <string, object> Items = (Dictionary <string, object>)Event["Items"]; foreach (KeyValuePair <string, object> zItem in (Dictionary <string, object>)Items) { Dictionary <string, object> ItemVars = (Dictionary <string, object>)zItem.Value; Item newItem = ItemManager.CreateByName(ItemVars["ID"].ToString(), Convert.ToInt32(ItemVars["Amount"].ToString())); ItemContainer Cont = null; switch (ItemVars["Amount"].ToString()) { case "Belt": Cont = Player.inventory.containerBelt; break; case "Wear": Cont = Player.inventory.containerWear; break; default: Cont = Player.inventory.containerMain; break; } Player.inventory.GiveItem(newItem, Cont); } myPlugin.Users.Add(Player.userID.ToString(), CurrentTime.ToString()); } } myPlugin.mySaveData(); Oxide.Core.Libraries.Timer.TimerInstance newTimer = MainTimer.Once(1, () => HappyHours(sender, PairObj), (Plugin)sender); Timers.Add(newTimer); } else { myPlugin.WriteConsole(string.Format("Happy Hour : Happy Hour ended @ {0}", DateTime.Now.ToString())); string[] Hour = pair.Key.Split(':'); DateTime EventTimeData = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, Convert.ToInt32(Hour[0]), Convert.ToInt32(Hour[1]), Convert.ToInt32(Hour[2]), DateTimeKind.Utc); long EventTime = Convert.ToInt64((EventTimeData - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds); if (CurrentTime > EventTime) { EventTimeData = EventTimeData.AddDays(1); EventTime = Convert.ToInt64((EventTimeData - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds); } Event["NextEvent"] = EventTime.ToString(); myPlugin.WriteConsole(string.Format("Happy Hour : User List cleared @ {0}", DateTime.Now.ToString())); myPlugin.WriteConsole(string.Format("Happy Hour : Same event will occur again @ {0}", EventTimeData.ToLocalTime().ToString())); myPlugin.Users.Clear(); myPlugin.mySaveData(); Oxide.Core.Libraries.Timer.TimerInstance newTimer = MainTimer.Once((EventTime - CurrentTime), () => HappyHours(sender, PairObj), (Plugin)sender); Timers.Add(newTimer); } }
public Timer(Oxide.Core.Libraries.Timer.TimerInstance instance) { this.instance = instance; }