private static void ShowPackageDetails(List <string> args, CmdIO.TTY io, UUID limitedToScene) { PackageDescription desc; if (limitedToScene != UUID.Zero) { io.Write("Not supported from limited console"); } else if (args[0] == "help" || args.Count < 3) { io.Write("show package <pkgname> - Show package details"); } else if (CoreUpdater.Instance.TryGetPackageDetails(args[2], out desc)) { var sb = new StringBuilder(); sb.AppendFormat("Package {0}\n", desc.Name); sb.Append("---------------------------------------------------------\n"); sb.AppendFormat("License: {0}\n", desc.License); sb.AppendFormat("Description:\n{0}\n", desc.Description); if (CoreUpdater.Instance.TryGetInstalledPackageDetails(args[2], out desc)) { sb.AppendFormat("Installed Version: {0}\n", desc.Version); } if (CoreUpdater.Instance.TryGetAvailablePackageDetails(args[2], out desc)) { sb.AppendFormat("Available Feed Version: {0}\n", desc.Version); } io.Write(sb.ToString()); } else { io.WriteFormatted("Package {0} not found.\n", args[2]); } }
private void ShowServerParamsCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { var sb = new StringBuilder(); var resList = new Dictionary <string, ServerParamAttribute>(); foreach (KeyValuePair <string, ServerParamAttribute> kvp in ServerParams) { ServerParamAttribute paraType; if (!resList.TryGetValue(kvp.Key, out paraType) || paraType.Type == ServerParamType.GlobalOnly) { resList[kvp.Key] = kvp.Value; } } sb.Append("Server Params:\n-------------------------------------------------\n"); foreach (KeyValuePair <string, ServerParamAttribute> kvp in resList) { sb.AppendFormat(kvp.Value.Type == ServerParamType.GlobalOnly ? "{0} - global only\n" : "{0} - global and region\n", kvp.Key); if (!string.IsNullOrEmpty(kvp.Value.Description)) { sb.AppendFormat("- {0}\n", kvp.Value.Description); } } io.Write(sb.ToString()); }
public void ExecuteCommand(List <string> args, TTY io, UUID limitedToScene) { Action <List <string>, TTY, UUID> del; if (args.Count == 0) { return; } else if (args[0] == "help") { if (args.Count == 1) { var commands = new StringBuilder("Command list:\n"); SortedDictionary <string, Action <List <string>, TTY, UUID> > sorted = new SortedDictionary <string, Action <List <string>, TTY, UUID> >(Commands); foreach (string cmd in sorted.Keys) { commands.AppendFormat("{0}\n", cmd); } io.Write(commands.ToString()); return; } else { try { del = Commands[args[1]]; args.RemoveAt(1); } catch (Exception) { io.WriteFormatted("Invalid command '{0}' for help", args[1]); return; } } } else { try { del = Commands[args[0]]; } catch (Exception) { io.WriteFormatted("Invalid command '{0}'", args[0]); return; } } try { del(args, io, limitedToScene); } catch (Exception e) { io.WriteFormatted("Command execution error {0}: {1}", e.GetType().ToString(), e.ToString()); } }
private void ShowModulesCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (args[0] == "help") { io.Write("show modules [<searchstring>] - Show currently loaded modules"); } else { string searchstring = string.Empty; if (args.Count > 2) { searchstring = args[2].ToLower(); } var output = new StringBuilder("Module List:\n----------------------------------------------"); if (!string.IsNullOrEmpty(searchstring)) { output.AppendFormat("\n<limited to modules containing \"{0}\">\n", searchstring); } foreach (KeyValuePair <string, IPlugin> moduledesc in PluginInstances) { var desc = (DescriptionAttribute)Attribute.GetCustomAttribute(moduledesc.Value.GetType(), typeof(DescriptionAttribute)); if (!string.IsNullOrEmpty(searchstring) && !moduledesc.Key.ToLower().Contains(searchstring)) { continue; } output.AppendFormat("\nModule {0}:", moduledesc.Key); if (desc != null) { output.Append("\n Description: "); output.Append(desc.Description); } foreach (KeyValuePair <Type, string> kvp in FeaturesTable) { if (kvp.Key.IsInterface) { if (moduledesc.Value.GetType().GetInterfaces().Contains(kvp.Key)) { output.Append("\n - "); output.Append(kvp.Value); } } else if (kvp.Key.IsAssignableFrom(moduledesc.Value.GetType())) { output.Append("\n - "); output.Append(kvp.Value); } } output.Append("\n"); } io.Write(output.ToString()); } }
private void ShowXmlRpcHandlersCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { var sb = new StringBuilder("XMLRPC Handlers:\n----------------------------------------------\n"); HttpXmlRpcHandler server = XmlRpcServer; foreach (KeyValuePair <string, Func <XmlRpc.XmlRpcRequest, XmlRpc.XmlRpcResponse> > kvp in server.XmlRpcMethods) { sb.AppendFormat("Method: {0}\n", kvp.Key); } io.Write(sb.ToString()); }
private void ShowJson20RpcHandlersCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { var sb = new StringBuilder("JSON2.0RPC Handlers:\n----------------------------------------------\n"); HttpJson20RpcHandler server = Json20RpcServer; foreach (KeyValuePair <string, Func <string, IValue, IValue> > kvp in server.Json20RpcMethods) { sb.AppendFormat("Method: {0}\n", kvp.Key); } io.Write(sb.ToString()); }
private static void UpdateFeed(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (limitedToScene != UUID.Zero) { io.Write("Not supported from limited console"); } else if (args[0] == "help") { io.Write("load package-feed - Updates package-feed"); } else { CoreUpdater.Instance.UpdatePackageFeed(); } }
public void ShowIssuesCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (UUID.Zero != limitedToScene) { io.Write("show issues not allowed on limited console"); } else if (args[0] == "help") { io.Write("show issues"); } else { io.Write("Known Configuration Issues:\n" + string.Join("\n", KnownConfigurationIssues)); } }
private static void InstallPackageCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (limitedToScene != UUID.Zero) { io.Write("Not supported from limited console"); } else if (args.Count < 2 || args[0] == "help") { io.Write("install <package> - Installs a package"); } else { CoreUpdater.Instance.InstallPackage(args[1]); } }
private void ShowHttpHandlersCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { BaseHttpServer http = HttpServer; var sb = new StringBuilder("HTTP Handlers: (" + http.ServerURI + ")\n----------------------------------------------\n"); ListHttpHandlers(sb, http); BaseHttpServer https; if (TryGetHttpsServer(out https)) { sb.AppendFormat("\nHTTPS Handlers: ({0})\n----------------------------------------------\n", https.ServerURI); ListHttpHandlers(sb, https); } io.Write(sb.ToString()); }
private void ShowCapsHandlersCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { var sb = new StringBuilder("Caps Handlers:\n----------------------------------------------\n"); CapsHttpRedirector redirector = CapsRedirector; foreach (KeyValuePair <string, RwLockedDictionary <UUID, Action <HttpRequest> > > kvp in redirector.Caps) { sb.AppendFormat("Capability: {0}\n", kvp.Key); foreach (KeyValuePair <UUID, Action <HttpRequest> > kvpInner in kvp.Value) { sb.AppendFormat("- ID: {0}\n", kvpInner.Key); } sb.AppendLine(); } io.Write(sb.ToString()); }
private void ShowCachedDnsCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (args[0] == "help") { io.Write("Shows currently cached DNS entries"); } else { var output = new StringBuilder("Cached DNS entries:\n----------------------------------------------"); foreach (string dns in DnsNameCache.GetCachedDnsEntries()) { output.Append("\n"); output.Append(dns); } io.Write(output.ToString()); } }
private void RemoveCachedDnsCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (args[0] == "help" || args.Count < 3) { io.Write("delete cacheddns <host>\nRemoves a DNS cache entry"); } else { if (DnsNameCache.RemoveCachedDnsEntry(args[2])) { io.WriteFormatted("DNS Entry {0} removed", args[2]); } else { io.WriteFormatted("DNS Entry {0} not found", args[2]); } } }
private void GetServerParamCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (args[0] == "help" || args.Count < 3 || args.Count > 4) { io.Write("get serverparam <regionid> <param>\nget serverparam <param>"); } else if (limitedToScene != UUID.Zero) { io.Write("get serverparam is not possible with limited console"); } else if (args.Count == 3) { try { io.Write("=" + GetServerParamStorage()[UUID.Zero, args[2]]); } catch { io.Write("Server parameter not available"); } } else if (args.Count == 4) { UUID regionId; if (!UUID.TryParse(args[2], out regionId)) { SceneInterface scene; if (!Scenes.TryGetValue(args[2], out scene)) { io.Write("regionid is not a UUID nor a region name"); return; } regionId = scene.ID; } try { io.Write("=" + GetServerParamStorage()[regionId, args[3]]); } catch { io.Write("Server parameter not available"); } } }
private void SetServerParamCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (args[0] == "help" || args.Count < 4 || args.Count > 5) { io.Write("set serverparam <regionid> <param> <value>\nset serverparam <regionname> <param> <value>\nset serverparam <param> <value>"); } else if (limitedToScene != UUID.Zero) { io.Write("set serverparam is not possible with limited console"); } else if (args.Count == 4) { try { GetServerParamStorage()[UUID.Zero, args[2]] = args[3]; } catch (Exception e) { io.Write(e.Message); } } else if (args.Count == 5) { UUID regionId; if (!UUID.TryParse(args[2], out regionId)) { SceneInterface scene; if (!Scenes.TryGetValue(args[2], out scene)) { io.Write("regionid is not a UUID nor a region name"); return; } regionId = scene.ID; } try { GetServerParamStorage()[regionId, args[3]] = args[4]; } catch (Exception e) { io.Write(e.Message); } } }
private static void ShowTimeSourcesCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (args[0] == "help") { io.Write("Show time sources"); } else { FormattedListBuilder fb = new FormattedListBuilder() .AddColumn("Source", 20) .AddColumn("Elapsed time (s)", 20) .AddColumn("Ticks per secs", 20) .AddHeader() .AddSeparator(); fb.AddData("Stopwatch", TimeProvider.StopWatch.TicksToSecs(TimeProvider.StopWatch.TickCount).ToString("N3"), TimeProvider.StopWatch.Frequency); fb.AddData("Environment", TimeProvider.Environment.TicksToSecs(TimeProvider.Environment.TickCount).ToString("N3"), TimeProvider.Environment.Frequency); io.Write(fb.ToString()); } }
private static void UninstallPackageCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (limitedToScene != UUID.Zero) { io.Write("Not supported from limited console"); } else if (args.Count < 2 || args[0] == "help") { io.Write("uninstall <package> - Uninstalls a package"); } else if (!CoreUpdater.Instance.InstalledPackages.ContainsKey(args[1])) { io.WriteFormatted("Package {0} is not installed.", args[1]); } else { CoreUpdater.Instance.UninstallPackage(args[1]); } }
public void Command_Handler(List <string> args, TTY io, UUID limitedToScene) { Action <List <string>, TTY, UUID> del; if (args.Count < 3) { if (args[0] == "help") { var commands = new StringBuilder(m_Command + " command list:\n"); var sorted = new SortedDictionary <string, Action <List <string>, TTY, UUID> >(m_Dict); foreach (string cmd in sorted.Keys) { commands.AppendFormat("{0} {1}\n", m_Command, cmd); } io.Write(commands.ToString()); } else { io.Write("Invalid " + m_Command + " command"); } return; } try { del = m_Dict[args[2]]; } catch (Exception) { io.WriteFormatted("Unsupported {1} command '{0}'", args[1], m_Command); return; } try { del(args, io, limitedToScene); } catch (Exception e) { io.WriteFormatted("Command execution error {0}: {1}", e.GetType().ToString(), e.ToString()); } }
private void ShowThreadsCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (UUID.Zero != limitedToScene) { io.Write("Not allowed on limited console"); } else if (args[0] == "help") { io.Write("Show existing threads"); } else { var sb = new StringBuilder("Threads:\n----------------------------------------------\n"); foreach (Thread t in ThreadManager.Threads) { sb.AppendFormat("Thread({0}): {1}\n", t.ManagedThreadId, t.Name); sb.AppendFormat("- State: {0}\n", t.ThreadState.ToString()); } io.Write(sb.ToString()); } }
private static void ShowAvailablePackages(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (limitedToScene != UUID.Zero) { io.Write("Not supported from limited console"); } else if (args[0] == "help") { io.Write("show available-packages - Show installed packages"); } else { StringBuilder sb = new StringBuilder(); sb.Append("Available Packages\n"); sb.Append("---------------------------------------------------------\n"); foreach (KeyValuePair <string, string> kvp in CoreUpdater.Instance.AvailablePackages) { sb.AppendFormat("{0}: {1}\n", kvp.Key, kvp.Value); } io.Write(sb.ToString()); } }
private static void CheckForUpdatesCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (limitedToScene != UUID.Zero) { io.Write("Not supported from limited console"); } else if (args[0] == "help") { io.Write("get updates-available - Show whether updates are available"); } else { CoreUpdater.Instance.UpdatePackageFeed(); if (CoreUpdater.Instance.AreUpdatesAvailable) { io.Write("Updates are available"); } else { io.Write("Current installation is up to date"); } } }
private static void ShowThreadCountCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (args[0] == "help") { io.Write("Show current thread count"); } else { int maxWorkerThreads; int maxCompletionThreads; int availWorkerThreads; int availCompletionThreads; ThreadPool.GetMaxThreads(out maxWorkerThreads, out maxCompletionThreads); ThreadPool.GetAvailableThreads(out availWorkerThreads, out availCompletionThreads); io.WriteFormatted("Threads: {0}\n\nSystem Threadpool:\nActive worker threads: {1} of {2}\nActive completion port threads: {3} of {4}", Process.GetCurrentProcess().Threads.Count, maxWorkerThreads - availWorkerThreads, maxWorkerThreads, maxCompletionThreads - availCompletionThreads, maxCompletionThreads); } }
private static void ShowMemoryCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (args[0] == "help") { io.Write("Shows current memory usage by simulator"); } else { Process p = Process.GetCurrentProcess(); FormattedListBuilder b = new FormattedListBuilder(); const long MB_DIV = 1048576; b.AddColumn("", 20); b.AddColumn("Current (MB)", 15); b.AddColumn("Peak (MB)", 15); b.AddHeader(); b.AddSeparator(); b.AddData("GC Heap", (GC.GetTotalMemory(false) + MB_DIV - 1) / MB_DIV, ""); b.AddData("Process memory", (p.WorkingSet64 + MB_DIV - 1) / MB_DIV, (p.PeakWorkingSet64 + MB_DIV - 1) / MB_DIV); io.WriteFormatted(b.ToString()); } }
private static void UpdateInstalledPackages(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (limitedToScene != UUID.Zero) { io.Write("Not supported from limited console"); } else if (args[0] == "help") { io.Write("get updates - Update installed packages"); } else { var relay = new UpdateLogRelay(io); CoreUpdater.Instance.OnUpdateLog += relay.LogEvent; try { CoreUpdater.Instance.CheckForUpdates(); } finally { CoreUpdater.Instance.OnUpdateLog -= relay.LogEvent; } } }
private void ShowQueuesCommand(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (args[0] == "help") { io.Write("Show queue stats on instance"); } else if (UUID.Zero != limitedToScene) { io.Write("Not allowed on limited console"); } else { var sb = new StringBuilder("Queue List:\n----------------------------------------------"); foreach (KeyValuePair <string, IQueueStatsAccess> kvp in GetServices <IQueueStatsAccess>()) { foreach (QueueStatAccessor accessors in kvp.Value.QueueStats) { QueueStat stat = accessors.GetData(); sb.AppendFormat("\n{0}: {1}:\n- Status: {2}\n- Count: {3}\n- Processed: {4}\n", kvp.Key, accessors.Name, stat.Status, stat.Count, stat.Processed); } } io.Write(sb.ToString()); } }
public void ExecuteCommandString(string cmd, TTY io, UUID limitedToScene) => ExecuteCommand(TTY.GetCmdLine(cmd), io, limitedToScene);
public void ExecuteCommand(List <string> args, TTY io) { ExecuteCommand(args, io, UUID.Zero); }
public void ExecuteCommandString(string cmd, TTY io) => ExecuteCommand(TTY.GetCmdLine(cmd), io);
private void ShowConnectivity(List <string> args, CmdIO.TTY io, UUID limitedToScene) { if (args[0] == "help") { io.Write("Show network connectivity"); } else { string hostname = ExternalHostNameService.ExternalHostName; IPAddress address; var sb = new StringBuilder($"Hostname={hostname}"); try { address = DnsNameCache.GetHostAddresses(hostname, true)[0]; sb.Append("\nIP=").Append(address); } catch { sb.Append("\nExternallyAccessible=False"); io.Write(sb.ToString()); return; } bool overallsuccess = true; if (SystemIPv4Service.IsAddressOnInterface(address)) { sb.Append("\nNAT=False"); if (SystemIPv4Service.IsPrivateIPAddress(address) || IPAddress.IsLoopback(address)) { sb.Append("\nPublicIP=False\nExternallyAccessible=False"); } else if (SystemIPv4Service.IsCGNAT(address)) { sb.Append("\nCGNAT=True\nPublicIP=False\nExternallyAccessible=False"); } else { sb.Append("\nPublicIP=True\nExternallyAccessible=True"); } } else { bool success; sb.Append("\nNAT=True"); if (SystemIPv4Service.IsPrivateIPAddress(address) || IPAddress.IsLoopback(address)) { sb.Append("\nPublicIP=False"); overallsuccess = false; } else if (SystemIPv4Service.IsCGNAT(address)) { sb.Append("\nCGNAT=True\nPublicIP=False"); overallsuccess = false; } else { sb.Append("\nPublicIP=True"); } try { new HttpClient.Head($"http://{address}:{HttpServer.Port}/diag-ping-external") { ConnectionMode = HttpClient.ConnectionModeEnum.SingleRequest }.ExecuteRequest(); success = true; if (m_DetectedCallerIP != address.ToString()) { sb.Append("\nHTTPOnAddressDetectedCaller=").Append(m_DetectedCallerIP); success = false; } } catch { success = false; } sb.Append("\nHTTPOnAddress=").Append(success); overallsuccess = overallsuccess && success; try { new HttpClient.Head($"http://{HttpServer.ExternalHostName}:{HttpServer.Port}/diag-ping-external") { ConnectionMode = HttpClient.ConnectionModeEnum.SingleRequest }.ExecuteRequest(); success = true; if (m_DetectedCallerIP != address.ToString()) { sb.Append("\nHTTPOnHostnameDetectedCaller=").Append(m_DetectedCallerIP); success = false; } } catch { success = false; } sb.Append("\nHTTPOnHostname=").Append(success); overallsuccess = overallsuccess && success; BaseHttpServer https; if (TryGetHttpsServer(out https)) { try { new HttpClient.Head($"https://{address}:{https.Port}/diag-ping-external") { ConnectionMode = HttpClient.ConnectionModeEnum.SingleRequest }.ExecuteRequest(); success = true; if (m_DetectedCallerIP != address.ToString()) { sb.Append("\nHTTPSOnAddressDetectedCaller=").Append(m_DetectedCallerIP); success = false; } } catch (Exception e) { success = false; sb.Append("\nHTTPSOnAddressError=").Append(e.Message); } sb.Append("\nHTTPSOnAddress=").Append(success); overallsuccess = overallsuccess && success; try { new HttpClient.Head($"https://{https.ExternalHostName}:{https.Port}/diag-ping-external") { ConnectionMode = HttpClient.ConnectionModeEnum.SingleRequest }.ExecuteRequest(); success = true; if (m_DetectedCallerIP != address.ToString()) { sb.Append("\nHTTPSOnHostnameDetectedCaller=").Append(m_DetectedCallerIP); success = false; } } catch (Exception e) { success = false; sb.Append("\nHTTPSOnHostnameError=").Append(e.Message); } sb.Append("\nHTTPSOnHostname=").Append(success); overallsuccess = overallsuccess && success; } lock (m_NetTestLock) { var circuits = new Dictionary <int, IUDPCircuitsManager>(); m_ReceivedAddressesOnUDP.Clear(); foreach (SceneInterface scene in Scenes.Values) { IUDPCircuitsManager circuit = scene.UDPServer; circuits.Add(circuit.LocalPort, circuit); circuit.OnNetTest += NetTestResponse; } foreach (IUDPCircuitsManager circuit in circuits.Values) { circuit.SendNetTest(address); } Thread.Sleep(1000); foreach (IUDPCircuitsManager circuit in circuits.Values) { circuit.OnNetTest -= NetTestResponse; } foreach (IUDPCircuitsManager circuit in circuits.Values) { IPAddress detectedSender; if (m_ReceivedAddressesOnUDP.TryGetValue(circuit.LocalPort, out detectedSender)) { if (detectedSender.Equals(address)) { sb.Append("\nUDP").Append(circuit.LocalPort).Append("=True"); } else { sb.Append("\nUDP").Append(circuit.LocalPort).Append("=False\nUDP").Append(circuit.LocalPort).Append("DetectedAddress=").Append(detectedSender); } } else { sb.Append("\nUDP").Append(circuit.LocalPort).Append("=False"); overallsuccess = false; } } } sb.Append("\nExternallyAccessible=").Append(overallsuccess); } io.Write(sb.ToString()); } }
public void ExecuteCommand(List <string> args, CmdIO.TTY io) { m_ConfigLoader.CommandRegistry.ExecuteCommand(args, io, UUID.Zero); }