public unsafe bool RunChatCommand(string cmdData) { register = CommandRegistry.Instance; Dictionary <UUID, int> BotAdmins = MainConfiguration.Instance.BotAdmins; dynamic parameters = JsonConvert.DeserializeObject(cmdData); string request = parameters.request; if (parameters.source == "sys") { return(false); } string[] para = request.Split(new[] { ' ' }); Dictionary <string, string> dstuf = new Dictionary <string, string>(); UUID fromID = UUID.Zero; try { string ID = parameters.from; fromID = UUID.Parse(ID); } catch (Exception e) { Log.info(log: e.Message); } int userLevel = 0; if (BotAdmins.ContainsKey(fromID) && BotAdmins.Count > 0) { userLevel = BotAdmins[fromID]; } else if (BotAdmins.Count == 0) { userLevel = 5; } UUID agentKey = UUID.Zero; UUID sessID = UUID.Zero; string sess = parameters.from_sess; if (sess != "") { sessID = UUID.Parse(sess); } cl = BotSession.Instance.grid; Destinations sourceLoc = new Destinations(); if (parameters.type == "chat") { sourceLoc = Destinations.DEST_LOCAL; } else if (parameters.type == "group") { sourceLoc = Destinations.DEST_GROUP; } else if (parameters.type == "im") { sourceLoc = Destinations.DEST_AGENT; } else if (parameters.type == "discord") { sourceLoc = Destinations.DEST_DISCORD; } else { sourceLoc = Destinations.DEST_LOCAL; } string agentName = parameters.fromName; if (sourceLoc == Destinations.DEST_LOCAL) { GroupLog.Instance.WriteLogEntry(true, false, agentName, agentKey, request); } else if (sourceLoc == Destinations.DEST_AGENT) { GroupLog.Instance.WriteLogEntry(false, true, agentName, agentKey, request); } if (sourceLoc == Destinations.DEST_GROUP) { agentKey = fromID; fromID = sessID; // Initiate group log saver string GroupName = cl.Groups.GroupName2KeyCache[fromID]; GroupLog.Instance.WriteLogEntry(GroupName, "secondlife:///app/agent/" + agentKey.ToString() + "/about (" + agentName + ") : " + request); if (agentKey == cl.Self.AgentID) { return(false); } } else { agentKey = fromID; if (agentKey == cl.Self.AgentID) { return(false); } } if (request.Substring(0, 1) != "!") { // Check if active bug or feature report session. If not- return. nRegistry.Dispatch(request, agentKey, ((parameters.source == "obj") ? "Object" : agentName), sourceLoc, fromID); /* * if (ocb.ActiveReportSessions.ContainsKey(agentKey) && ocb.ActiveReportSessions.Count > 0) * { * // Send report response to GitCommands * GitCommands gc = new GitCommands(); * gc.BugResponse(fromID, agentKey, ocb.ActiveReportSessions[agentKey].ReportStage, request, sourceLoc, MHE, agentName); * return false; * } * * if (ocb.ActiveFeatureSessions.ContainsKey(agentKey) && ocb.ActiveFeatureSessions.Count > 0) * { * GitCommands gc = new GitCommands(); * gc.FeatureResponse(fromID, agentKey, ocb.ActiveFeatureSessions[agentKey].ReportStage, request, sourceLoc, MHE, agentName); * return false; * } * * if (ocb.ActiveCommentSessions.ContainsKey(agentKey) && ocb.ActiveCommentSessions.Count > 0) * { * GitCommands gc = new GitCommands(); * gc.comment(fromID, agentKey, ocb.ActiveCommentSessions[agentKey].ReportStage, request, sourceLoc, MHE, agentName); * return false; * } * * if (ocb.NoticeSessions.ContainsKey(agentKey) && ocb.NoticeSessions.Count > 0) * { * GroupSystem gs = new GroupSystem(); * gs.update_notice_sess(fromID, agentKey, request, sourceLoc, MHE, agentName); * return false; * } * * if (ocb.MailingLists.Count > 0) * { * // Scan all mailing lists for a session and agentKey that match. * foreach (string sML in ocb.MailingLists.Keys) * { * OCBotMemory.MailList ML = ocb.MailingLists[sML]; * if (ML.PrepFrom == agentKey && ML.PrepState == 1) * { * MailingLists.MailingLists cML = new MailingLists.MailingLists(); * cML.HandleMailListData(agentKey, fromID, sourceLoc, MHE, sML, request); * return false; * } * } * }*/ return(false); } else { request = request.Substring(1); para = request.Split(' '); } try { register.RunCommand(request, fromID, userLevel, sourceLoc, agentKey, agentName); } catch (Exception e) { string Msg = e.Message; Msg = Msg.Replace("ZNI", ""); int i; int * ptr = &i; IntPtr addr = (IntPtr)ptr; MessageFactory.Post(Destinations.DEST_LOCAL, "Exception caught: [" + Msg + "]\n \n[STACK] " + e.StackTrace.Replace("ZNI", "") + "\nMemory Position: 0x" + addr.ToString("x") + "\nCommand: " + request + $"\nMisc Details: {fromID}, {userLevel}, {sourceLoc}, {agentKey}, {agentName}", UUID.Zero); // do nothing here. } Log.info(log: "Leaving command parser"); return(false); }
public WebhookRegistry.HTTPResponseData showHelp(List <string> arguments, string body, string method, NameValueCollection headers) { WebhookRegistry.HTTPResponseData httpReply = new WebhookRegistry.HTTPResponseData(); CommandRegistry reg = CommandRegistry.Instance; string Final = "<body bgcolor='black'><style type='text/css'>table.HelpTable { border: 5px solid #1C6EA4;" + " background - color: #000000; " + " width: 100 %; text - align: left; border - collapse: collapse;" + " } table.HelpTable td, table.HelpTable th { border: 3px solid #AAAAAA;" + " padding: 3px 2px; } table.HelpTable tbody td { font-size: 19px; color: #69FAF7;" + "} table.HelpTable tr:nth-child(even) { background: #000000;} table.HelpTable thead" + " { background: #26A486; background: -moz-linear-gradient(top, #5cbba4 0%, #3bad92 66%, #26A486 100%);" + " background: -webkit-linear-gradient(top, #5cbba4 0%, #3bad92 66%, #26A486 100%);" + " background: linear-gradient(to bottom, #5cbba4 0%, #3bad92 66%, #26A486 100%);" + " border-bottom: 2px solid #444444;} table.HelpTable thead th { font-size: 25px;" + " font-weight: bold; color: #FFFFFF; text-align: center; border-left: 2px solid #D0E4F5;" + "}table.HelpTable thead th:first-child { border-left: none;}table.HelpTable tfoot td { font-size: 14px;" + "}table.HelpTable tfoot.links{ text-align: right;}table.HelpTable tfoot.links a{display: inline - block;" + "background: #1C6EA4; color: #FFFFFF; padding: 2px 8px; border - radius: 5px;}</style>"; Final += "<table class='HelpTable'><thead><tr><th>Bot Version</th><th>" + ASMInfo.BotVer + "</th></tr></table><br/>"; Final += "<table class='HelpTable'><thead><tr><th>Command</th><th>Minimum Level Required</th><th>Usage</th><th>Allowed Sources</th></thead><tbody>"; foreach (KeyValuePair <string, CommandGroup> cmd in reg.Cmds) { // Command Final += "<tr><td>" + cmd.Value.Command + "</td>"; // Level Final += "<td>" + cmd.Value.minLevel.ToString() + "</td>"; // Usage Final += "<td>" + cmd.Value.cmdUsage.RawUsage() + "</td>"; // Allowed Sources Final += "<td>" + cmd.Value.CommandSource + "</td>"; } Final += "</tbody></table>"; Final += "<table class='HelpTable'><thead><tr><th>Hook Path</th><tr></thead><tbody>"; WebhookRegistry regx = WebhookRegistry.Instance; foreach (KeyValuePair <string, WebhookAttribs> hooks in regx.hooks) { Final += "<tr><td>" + hooks.Value.Path + "</td></tr>"; } Final += "</tbody></table>"; Final += "<br/><table class='HelpTable'><thead><tr><th>Assembly</th><th>Version</th><th># Of Commands</th><th>Total Classes</th></tr></thead><tbody>"; foreach (Assembly A in AppDomain.CurrentDomain.GetAssemblies()) { Final += "<tr><td>" + A.GetName().Name + "</td><td>" + A.GetName().Version + "</td>"; int TotalCommandsContained = 0; int TotalClasses = 0; foreach (Type T in A.GetTypes()) { if (T.IsClass) { TotalClasses++; foreach (MethodInfo MI in T.GetMethods()) { CommandGroup[] CG = (CommandGroup[])MI.GetCustomAttributes(typeof(CommandGroup), false); TotalCommandsContained += CG.Length; } } } Final += "<td>" + TotalCommandsContained.ToString() + "</td><td>" + TotalClasses.ToString() + "</td></tr>"; } Final += "</tbody></table>"; httpReply.ReplyString = Final; httpReply.Status = 200; httpReply.ReturnContentType = "text/html"; return(httpReply); }