begin code overhauls
This commit is contained in:
parent
9969e466d8
commit
eb1026f8f4
14 changed files with 544 additions and 197 deletions
|
@ -7,7 +7,7 @@ namespace Bot.Assemble
|
|||
public class ASMInfo
|
||||
{
|
||||
public static string BotName = "ZBotCore";
|
||||
public static double BotVer = 5.2;
|
||||
public static double BotVer = 5.33;
|
||||
public static string GitPassword
|
||||
{
|
||||
get
|
||||
|
|
|
@ -34,10 +34,14 @@ namespace Bot
|
|||
|
||||
|
||||
public GridClient grid { get; set; }
|
||||
public SysOut Logger { get; set; }
|
||||
public Logger Logger { get; set; }
|
||||
public MessageHandler.MessageHandleEvent MHE;
|
||||
public MessageHandler MH;
|
||||
|
||||
public MainConfiguration ConfigurationHandle;
|
||||
public MainConfiguration ConfigurationHandle {
|
||||
get {
|
||||
return MainConfiguration.Instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
156
CommandSystem/CommandManager.cs
Normal file
156
CommandSystem/CommandManager.cs
Normal file
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
|
||||
Copyright © 2019 Tara Piccari (Aria; Tashia Redrose)
|
||||
Licensed under the GPLv2
|
||||
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Bot;
|
||||
using Bot.CommandSystem;
|
||||
using Bot.NonCommands;
|
||||
using Newtonsoft.Json;
|
||||
using OpenMetaverse;
|
||||
|
||||
namespace Bot.CommandSystem
|
||||
{
|
||||
public class CommandManager
|
||||
{
|
||||
public CommandRegistry register;
|
||||
public GridClient cl;
|
||||
public Logger Log = BotSession.Instance.Logger;
|
||||
public string newReply;
|
||||
public bool RunChatCommand(string cmdData, GridClient client, MessageHandler.MessageHandleEvent MHE, CommandRegistry registry)
|
||||
{
|
||||
register = registry;
|
||||
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 = client;
|
||||
|
||||
MessageHandler.Destinations sourceLoc = new MessageHandler.Destinations();
|
||||
if (parameters.type == "chat") sourceLoc = MessageHandler.Destinations.DEST_LOCAL;
|
||||
else if (parameters.type == "group") sourceLoc = MessageHandler.Destinations.DEST_GROUP;
|
||||
else if (parameters.type == "im") sourceLoc = MessageHandler.Destinations.DEST_AGENT;
|
||||
else sourceLoc = MessageHandler.Destinations.DEST_LOCAL;
|
||||
|
||||
string agentName = parameters.fromName;
|
||||
if (sourceLoc == MessageHandler.Destinations.DEST_GROUP)
|
||||
{
|
||||
agentKey = fromID;
|
||||
fromID = sessID;
|
||||
|
||||
// Initiate group log saver
|
||||
string GroupName = client.Groups.GroupName2KeyCache[fromID];
|
||||
|
||||
GroupLog.Instance.WriteLogEntry(GroupName, "secondlife:///app/agent/" + agentKey.ToString() + "/about (" + agentName + ") : " + request);
|
||||
}
|
||||
else { agentKey = fromID; }
|
||||
|
||||
if (request.Substring(0, 1) != "!")
|
||||
{
|
||||
// Check if active bug or feature report session. If not- return.
|
||||
nRegistry.Dispatch(request, agentKey, 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, MHE, sourceLoc, agentKey, agentName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
string Msg = e.Message;
|
||||
Msg = Msg.Replace("ZNI", "");
|
||||
MHE(MessageHandler.Destinations.DEST_LOCAL, UUID.Zero, "Exception caught in OpenCollarBot.dll: [" + Msg + "]\n \n[STACK] " + e.StackTrace.Replace("ZNI", ""));
|
||||
// do nothing here.
|
||||
}
|
||||
Log.info(log:"Leaving command parser");
|
||||
return false;
|
||||
}
|
||||
|
||||
public CommandManager(Logger _Log, GridClient cl, MessageHandler.MessageHandleEvent MHE)
|
||||
{
|
||||
this.cl = cl;
|
||||
Log = _Log;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -57,7 +57,7 @@ namespace Bot.CommandSystem
|
|||
// Define the registry
|
||||
public Dictionary<string, CommandGroup> Cmds = new Dictionary<string, CommandGroup>();
|
||||
public GridClient client;
|
||||
public SysOut Log;
|
||||
public Logger Log;
|
||||
public IConfig config;
|
||||
public MessageHandler.MessageHandleEvent MHEx;
|
||||
public void LocateCommands()
|
||||
|
@ -110,7 +110,7 @@ namespace Bot.CommandSystem
|
|||
|
||||
if (Cmds.ContainsKey(CG.Command) == false)
|
||||
{
|
||||
Console.WriteLine("DISCOVER: " + CG.Command);
|
||||
Log.info(true, "DISCOVER: " + CG.Command);
|
||||
Cmds.Add(CG.Command, CG);
|
||||
}
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ namespace Bot.CommandSystem
|
|||
}
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Discovered " + Cmds.Count.ToString() + " total commands");
|
||||
Log.info(log:"Discovered " + Cmds.Count.ToString() + " total commands");
|
||||
}
|
||||
catch (ReflectionTypeLoadException e)
|
||||
{
|
||||
|
|
|
@ -4,12 +4,37 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
using OpenMetaverse;
|
||||
|
||||
namespace Bot
|
||||
{
|
||||
[Serializable()]
|
||||
public class MainConfiguration : IConfig
|
||||
public sealed class MainConfiguration : IConfig
|
||||
{
|
||||
private static readonly object lck = new object();
|
||||
private static MainConfiguration inst = null;
|
||||
|
||||
static MainConfiguration() { }
|
||||
|
||||
public static MainConfiguration Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if(inst == null)
|
||||
{
|
||||
lock (lck)
|
||||
{
|
||||
inst = new MainConfiguration();
|
||||
inst.Load();
|
||||
return inst;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return inst;
|
||||
}
|
||||
}
|
||||
}
|
||||
public float ConfigVersion
|
||||
{
|
||||
get; set;
|
||||
|
@ -20,34 +45,40 @@ namespace Bot
|
|||
get; set;
|
||||
}
|
||||
|
||||
public string MainProgramDLL;
|
||||
public string first { get; set; }
|
||||
public string last { get; set; }
|
||||
public string password { get; set; }
|
||||
public string MainProgramDLL = "BlankBot.dll";
|
||||
public string first { get; set; } = "";
|
||||
public string last { get; set; } = "";
|
||||
public string password { get; set; } = "";
|
||||
|
||||
//public License LicenseKey { get; set; }
|
||||
public string ActivationCode { get; set; }
|
||||
public string ActivationCode { get; set; } = "";
|
||||
|
||||
public string GitPassword { get; set; }
|
||||
public string GitPassword { get; set; } = "NOT_SET";
|
||||
|
||||
public MainConfiguration()
|
||||
{
|
||||
public Dictionary<UUID, int> BotAdmins { get; set; } = new Dictionary<UUID, int>();
|
||||
|
||||
}
|
||||
|
||||
public static MainConfiguration Load()
|
||||
public void Load()
|
||||
{
|
||||
MainConfiguration X = new MainConfiguration();
|
||||
SerialManager sm = new SerialManager();
|
||||
try
|
||||
{
|
||||
X = sm.Read<MainConfiguration>("Main");
|
||||
return X;
|
||||
|
||||
MainProgramDLL = X.MainProgramDLL;
|
||||
first = X.first;
|
||||
last = X.last;
|
||||
ActivationCode = X.ActivationCode;
|
||||
password = X.password;
|
||||
GitPassword = X.GitPassword;
|
||||
BotAdmins = X.BotAdmins;
|
||||
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
Console.WriteLine("Main.json was not found");
|
||||
return new MainConfiguration();
|
||||
BotSession.Instance.Logger.info(true, "Main.json does not exist");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
96
GroupLog.cs
Normal file
96
GroupLog.cs
Normal file
|
@ -0,0 +1,96 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using Bot.CommandSystem;
|
||||
using OpenMetaverse;
|
||||
|
||||
|
||||
|
||||
namespace Bot
|
||||
{
|
||||
public sealed class GroupLog
|
||||
{
|
||||
|
||||
private static readonly object _lock = new object();
|
||||
private static GroupLog _in;
|
||||
private static readonly object _writeLock = new object();
|
||||
|
||||
static GroupLog() { }
|
||||
|
||||
public static GroupLog Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (_in == null) _in = new GroupLog();
|
||||
return _in;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteLogEntry(string LogName, string ToAppend)
|
||||
{
|
||||
// Log filename will ALWAYS contain the date
|
||||
try
|
||||
{
|
||||
lock (_writeLock)
|
||||
{
|
||||
|
||||
string date = DateTime.Now.ToString("M-d-yyyy");
|
||||
date += " " + LogName + ".log";
|
||||
|
||||
if (!Directory.Exists("GroupChatLogs")) Directory.CreateDirectory("GroupChatLogs");
|
||||
|
||||
date = "GroupChatLogs/" + date;
|
||||
|
||||
File.AppendAllText(date, "[" + DateTime.Now.ToString("hh:mm:ss") + "]: " + ToAppend + "\n");
|
||||
}
|
||||
}
|
||||
catch (Exception e) { }
|
||||
}
|
||||
|
||||
private static readonly object _fileRead = new object();
|
||||
[CommandGroupMaster("Logging")]
|
||||
[CommandGroup("search_log", 5, 2, "search_log [groupName] [search_term] - Searches for the search term in all logs relating to the group name (Use a underscore to show where spaces are!). The search term may also include the pipe (|) delimiter to include more than 1 word.", Bot.MessageHandler.Destinations.DEST_AGENT | Bot.MessageHandler.Destinations.DEST_LOCAL)]
|
||||
public void search_log(UUID client, int level, GridClient grid, string[] additionalArgs,
|
||||
MessageHandler.MessageHandleEvent MHE, MessageHandler.Destinations source,
|
||||
CommandRegistry registry, UUID agentKey, string agentName)
|
||||
{
|
||||
string GrpName = additionalArgs[0].Replace('_', ' ');
|
||||
string[] search = additionalArgs[1].Split('|');
|
||||
|
||||
DirectoryInfo di = new DirectoryInfo("GroupChatLogs");
|
||||
foreach (FileInfo fi in di.GetFiles())
|
||||
{
|
||||
// check if filename contains the group name
|
||||
string onlyName = Path.GetFileNameWithoutExtension(fi.Name);
|
||||
|
||||
if (onlyName.Contains(GrpName))
|
||||
{
|
||||
// read file
|
||||
lock (_fileRead)
|
||||
{
|
||||
foreach (string S in File.ReadLines("GroupChatLogs/" + onlyName + ".log"))
|
||||
{
|
||||
foreach (string V in search)
|
||||
{
|
||||
if (S.Contains(V, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
|
||||
MHE(source, client, "{[https://zontreck.dev:35591/viewlog/" + Uri.EscapeUriString(onlyName) + " " + onlyName + "]} " + S);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MHE(source, client, ".\n \n[Search Completed]");
|
||||
}
|
||||
}
|
||||
}
|
102
Logger.cs
Normal file
102
Logger.cs
Normal file
|
@ -0,0 +1,102 @@
|
|||
using System;
|
||||
|
||||
namespace Bot
|
||||
{
|
||||
public class Logger
|
||||
{
|
||||
string LogName;
|
||||
public Logger(string Name)
|
||||
{
|
||||
LogName = Name;
|
||||
info(log: "Logger initialized for " + Name);
|
||||
BotSession.Instance.Logger = this;
|
||||
}
|
||||
|
||||
string InputData = ""; // Data entered into the console
|
||||
string ReturnData = "";
|
||||
|
||||
public void info(bool Restore = true, params string[] log)
|
||||
{
|
||||
foreach (string val in log)
|
||||
{
|
||||
string pad = "";
|
||||
if (InputData.Length > 0)
|
||||
{
|
||||
foreach (char v in InputData)
|
||||
{
|
||||
pad += " ";
|
||||
}
|
||||
}
|
||||
Console.Write($"\r{pad} \r[{LogName}] [INFO] : {val}\n");
|
||||
if (InputData.Length > 0 && Restore)
|
||||
Console.Write("\r> " + InputData);
|
||||
else
|
||||
Console.Write("\r> ");
|
||||
}
|
||||
}
|
||||
|
||||
public void DoPrompt()
|
||||
{
|
||||
var newKey = Console.ReadKey();
|
||||
switch (newKey.Key)
|
||||
{
|
||||
case ConsoleKey.Enter:
|
||||
{
|
||||
ReturnData = InputData;
|
||||
InputData = "";
|
||||
if (ReturnData.Length > 0)
|
||||
Console.WriteLine();
|
||||
else Console.Write("\r> ");
|
||||
break;
|
||||
}
|
||||
case ConsoleKey.Escape:
|
||||
{
|
||||
ReturnData = "";
|
||||
info(Restore: false, "Cmd Canceled");
|
||||
InputData = "";
|
||||
break;
|
||||
}
|
||||
case ConsoleKey.Backspace:
|
||||
{
|
||||
string pad = " ";
|
||||
foreach (char v in InputData)
|
||||
{
|
||||
pad += " ";
|
||||
}
|
||||
Console.Write("\r" + pad);
|
||||
if (InputData.Length > 0)
|
||||
InputData = InputData.Substring(0, InputData.Length - 1);
|
||||
Console.Write("\r> " + InputData);
|
||||
|
||||
break;
|
||||
}
|
||||
case ConsoleKey.Tab:
|
||||
{
|
||||
InputData += "\t";
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
|
||||
InputData += newKey.KeyChar;
|
||||
break;
|
||||
}
|
||||
}
|
||||
DoPrompt();
|
||||
}
|
||||
|
||||
public string CheckForNewCmd()
|
||||
{
|
||||
if (ReturnData.Length != 0)
|
||||
{
|
||||
string Tmp = new string(ReturnData);
|
||||
ReturnData = "";
|
||||
return Tmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Data not yet available");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@ namespace Bot
|
|||
private List<ActionPacket> ActionQueue = new List<ActionPacket>();
|
||||
private List<DiscordAction> DiscordQueue = new List<DiscordAction>();
|
||||
public ManualResetEvent GroupJoinWaiter = new ManualResetEvent(false);
|
||||
private SysOut Log = SysOut.Instance;
|
||||
private Logger Log = BotSession.Instance.Logger;
|
||||
|
||||
|
||||
[Flags]
|
||||
|
@ -26,10 +26,9 @@ namespace Bot
|
|||
DEST_AGENT = 1,
|
||||
DEST_GROUP = 2,
|
||||
DEST_LOCAL = 4,
|
||||
DEST_CONSOLE_DEBUG = 8,
|
||||
DEST_CONSOLE_INFO = 16,
|
||||
DEST_ACTION = 32,
|
||||
DEST_DISCORD = 64
|
||||
DEST_CONSOLE_INFO = 8,
|
||||
DEST_ACTION = 16,
|
||||
DEST_DISCORD = 32
|
||||
};
|
||||
|
||||
public struct MessageQueuePacket
|
||||
|
@ -102,13 +101,9 @@ namespace Bot
|
|||
{
|
||||
client.Self.InstantMessage(pkt.DestID, "[" + MSGQueue.Count.ToString() + "] " + pkt.Msg);
|
||||
}
|
||||
else if (pkt.Dest == Destinations.DEST_CONSOLE_DEBUG)
|
||||
{
|
||||
Log.debug("[" + MSGQueue.Count.ToString() + "] " + pkt.Msg);
|
||||
}
|
||||
else if (pkt.Dest == Destinations.DEST_CONSOLE_INFO)
|
||||
{
|
||||
Log.info("[" + MSGQueue.Count.ToString() + "] " + pkt.Msg);
|
||||
Log.info(Restore:true, "[" + MSGQueue.Count.ToString() + "] " + pkt.Msg);
|
||||
}
|
||||
else if (pkt.Dest == Destinations.DEST_GROUP)
|
||||
{
|
||||
|
|
15
NonCommands/NotCommand.cs
Normal file
15
NonCommands/NotCommand.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Bot.NonCommands
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
|
||||
public class NotCommand : Attribute
|
||||
{
|
||||
public NotCommand()
|
||||
{
|
||||
// Not Command, this just marks a class
|
||||
}
|
||||
}
|
||||
}
|
14
NonCommands/nCMD.cs
Normal file
14
NonCommands/nCMD.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using OpenMetaverse;
|
||||
|
||||
|
||||
|
||||
namespace Bot.NonCommands
|
||||
{
|
||||
public interface nCMD
|
||||
{
|
||||
public void handle(string text, UUID User, string agentName, MessageHandler.Destinations src, UUID originator);
|
||||
}
|
||||
}
|
41
NonCommands/nRegistry.cs
Normal file
41
NonCommands/nRegistry.cs
Normal file
|
@ -0,0 +1,41 @@
|
|||
using OpenMetaverse;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
namespace Bot.NonCommands
|
||||
{
|
||||
public class nRegistry
|
||||
{
|
||||
public static void Dispatch(string request, UUID agentKey, string agentName, MessageHandler.Destinations sourceLoc, UUID originator)
|
||||
{
|
||||
|
||||
foreach(Assembly a in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
foreach(Type t in a.GetTypes())
|
||||
{
|
||||
if (t.IsClass)
|
||||
{
|
||||
foreach (NotCommand NC in (NotCommand[])t.GetCustomAttributes(false))
|
||||
{
|
||||
MethodInfo mi = t.GetMethod("handle");
|
||||
|
||||
ThreadStart work = delegate
|
||||
{
|
||||
mi.Invoke(Activator.CreateInstance(mi.DeclaringType), new object[] { request, agentKey, agentName, sourceLoc, originator });
|
||||
};
|
||||
Thread T = new Thread(work);
|
||||
|
||||
|
||||
// _mi.Invoke(Activator.CreateInstance(_mi.DeclaringType), new object[] { });
|
||||
T.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
80
Program.cs
80
Program.cs
|
@ -17,7 +17,7 @@ namespace Bot
|
|||
{
|
||||
public class Program
|
||||
{
|
||||
public static SysOut Log = SysOut.Instance;
|
||||
public static Logger Log = new Logger("Core5");
|
||||
public static double BotVer = ASMInfo.BotVer;
|
||||
public static string BotStr = ASMInfo.BotName; // internal identifier for linden
|
||||
public static MainConfiguration conf;
|
||||
|
@ -43,9 +43,8 @@ namespace Bot
|
|||
ZHash.Instance.NewKey();
|
||||
ZHash.Instance.Key = "Test";
|
||||
Console.WriteLine("ZHash (Test): " + ZHash.Instance.Key);
|
||||
conf = MainConfiguration.Load();
|
||||
conf = MainConfiguration.Instance;
|
||||
//MasterObjectCaches = ObjectCaches.Instance;
|
||||
Log.debugf(true, "main", args);
|
||||
|
||||
if (args.Length == 2)
|
||||
{
|
||||
|
@ -162,12 +161,12 @@ namespace Bot
|
|||
if (args.Length == 0)
|
||||
{
|
||||
|
||||
Log.info("Please enter your avatar's first name: ");
|
||||
Log.info(true, "Please enter your avatar's first name: ");
|
||||
fna = Console.ReadLine();
|
||||
|
||||
Log.info("Please enter the last name: ");
|
||||
Log.info(true, "Please enter the last name: ");
|
||||
lna = Console.ReadLine();
|
||||
Log.info("Now enter your password: ");
|
||||
Log.info(true, "Now enter your password: ");
|
||||
pwd = Console.ReadLine();
|
||||
|
||||
conf.MainProgramDLL = DefaultProgram;
|
||||
|
@ -177,8 +176,8 @@ namespace Bot
|
|||
}
|
||||
else
|
||||
{
|
||||
Log.info("Loading...");
|
||||
Log.info("FirstName: " + args[0]);
|
||||
Log.info(true, "Loading...");
|
||||
Log.info(true, "FirstName: " + args[0]);
|
||||
fna = args[0];
|
||||
lna = args[1];
|
||||
pwd = args[2];
|
||||
|
@ -189,7 +188,6 @@ namespace Bot
|
|||
conf.last = lna;
|
||||
conf.password = pwd;
|
||||
SM.Write<MainConfiguration>("Main", conf);
|
||||
Log.debug("FirstName in Config: " + conf.first);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -220,6 +218,10 @@ namespace Bot
|
|||
client.Throttle.Land = 100000;
|
||||
client.Throttle.Task = 100000;
|
||||
client.Throttle.Total = 100000;
|
||||
client.Settings.LOG_RESENDS = false;
|
||||
client.Settings.LOG_ALL_CAPS_ERRORS = false;
|
||||
client.Settings.LOG_DISKCACHE = false;
|
||||
|
||||
|
||||
client.Settings.ALWAYS_REQUEST_OBJECTS = true;
|
||||
|
||||
|
@ -243,16 +245,45 @@ namespace Bot
|
|||
File.Delete("XUP");
|
||||
MH.callbacks(MessageHandler.Destinations.DEST_LOCAL, UUID.Zero, "Updated to version " + BotStr + " - "+BotVer.ToString());
|
||||
}
|
||||
Log.debugf(true, "SL_NET", new[] { "logged_in" });
|
||||
|
||||
// Setup BotSession Singleton!
|
||||
BotSession.Instance.grid = client;
|
||||
BotSession.Instance.Logger = Log;
|
||||
BotSession.Instance.MHE = MH.callbacks;
|
||||
BotSession.Instance.MH = MH;
|
||||
BotSession.Instance.ConfigurationHandle = conf;
|
||||
|
||||
Thread prompter = new Thread(() => {
|
||||
BotSession.Instance.Logger.DoPrompt();
|
||||
});
|
||||
|
||||
prompter.Start();
|
||||
while (g_iIsRunning)
|
||||
{
|
||||
string consoleCmd = "N/A";
|
||||
try
|
||||
{
|
||||
consoleCmd = BotSession.Instance.Logger.CheckForNewCmd();
|
||||
}catch(Exception e)
|
||||
{
|
||||
// no command is set yet!
|
||||
}
|
||||
|
||||
switch (consoleCmd)
|
||||
{
|
||||
case "N/A":
|
||||
{
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
// Run command!
|
||||
MessageHandler.Destinations src = MessageHandler.Destinations.DEST_CONSOLE_INFO;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Pass to the command handlers
|
||||
|
||||
client.Self.RetrieveInstantMessages();
|
||||
if (client.Network.Connected == false) g_iIsRunning = false; // Quit the program and restart immediately!
|
||||
Thread.Sleep(2000);
|
||||
|
@ -291,17 +322,17 @@ namespace Bot
|
|||
// Check MainConfiguration for a mainProgram handle
|
||||
if (conf.MainProgramDLL == null)
|
||||
{
|
||||
Log.info("Setting main program library");
|
||||
Log.info(true, "Setting main program library");
|
||||
conf.MainProgramDLL = DefaultProgram;
|
||||
SM.Write<MainConfiguration>("Main", conf);
|
||||
|
||||
}
|
||||
if (File.Exists(conf.MainProgramDLL) == false)
|
||||
{
|
||||
Log.info("MainProgram Library: " + conf.MainProgramDLL + " does not exist");
|
||||
Log.info(true, "MainProgram Library: " + conf.MainProgramDLL + " does not exist");
|
||||
if (conf.MainProgramDLL == DefaultProgram)
|
||||
{
|
||||
Log.info("FATAL: BlankBot.dll must exist to proceed");
|
||||
Log.info(true, "FATAL: BlankBot.dll must exist to proceed");
|
||||
msg(MessageHandler.Destinations.DEST_LOCAL, UUID.Zero, "BlankBot.dll does not exist. Please place the blank bot program into the same folder as 'Bot.dll'. Load cannot proceed any further Terminating");
|
||||
|
||||
}
|
||||
|
@ -313,7 +344,7 @@ namespace Bot
|
|||
{
|
||||
registry = CommandRegistry.Instance;
|
||||
//ReloadGroupsCache();
|
||||
Log.info("MainProgram exists");
|
||||
Log.info(true, "MainProgram exists");
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -330,12 +361,12 @@ namespace Bot
|
|||
client.Self.IM += plugin.onIMEvent;
|
||||
programCount++;
|
||||
|
||||
Log.debug("Plugin: " + plugin.ProgramName + " [" + PA.LoadedASM.FullName + "] added to g_ZPrograms");
|
||||
Log.info(true, "Plugin: " + plugin.ProgramName + " [" + PA.LoadedASM.FullName + "] added to g_ZPrograms");
|
||||
if (File.Exists(plugin.ProgramName + ".bdf"))
|
||||
plugin.LoadConfiguration(); // will throw an error if BlankBot tries to load config
|
||||
}
|
||||
|
||||
Log.debug(g_ZPrograms.Count.ToString() + " programs linked");
|
||||
Log.info(true, g_ZPrograms.Count.ToString() + " programs linked");
|
||||
if (g_ZPrograms.Count > 0) msg(MessageHandler.Destinations.DEST_LOCAL, UUID.Zero, "Default Program [" + conf.MainProgramDLL + "] has been loaded, " + programCount.ToString() + " plugin(s) loaded");
|
||||
registry.LocateCommands();
|
||||
|
||||
|
@ -347,7 +378,7 @@ namespace Bot
|
|||
string Msg = E.Message;
|
||||
string STACK = E.StackTrace.Replace("ZNI", "");
|
||||
Msg = Msg.Replace("ZNI", "");
|
||||
Log.debug("Generic Exception Caught: " + Msg + " [0x0A]");
|
||||
Log.info(true, "Generic Exception Caught: " + Msg + " [0x0A]");
|
||||
int i;
|
||||
int* ptr = &i;
|
||||
IntPtr addr = (IntPtr)ptr;
|
||||
|
@ -375,9 +406,7 @@ namespace Bot
|
|||
}
|
||||
else
|
||||
{
|
||||
Log.debug("TICK REPLY: " + jsonReply);
|
||||
dynamic jsonObj = JsonConvert.DeserializeObject(jsonReply);
|
||||
Log.debug("TYPE: " + jsonObj.type);
|
||||
string tp = jsonObj.type;
|
||||
switch (tp)
|
||||
{
|
||||
|
@ -402,7 +431,7 @@ namespace Bot
|
|||
case "exit":
|
||||
{
|
||||
|
||||
Log.info("Logging off!");
|
||||
Log.info(false, "Logging off!");
|
||||
g_iIsRunning = false;
|
||||
break;
|
||||
}
|
||||
|
@ -430,7 +459,7 @@ namespace Bot
|
|||
g_ZPrograms.Add(plugin);
|
||||
client.Self.IM += plugin.onIMEvent;
|
||||
programCount++;
|
||||
Log.debug("Plugin: " + plugin.ProgramName + " [" + Plugs.LoadedASM.FullName + "] added to g_ZPrograms");
|
||||
Log.info(true, "Plugin: " + plugin.ProgramName + " [" + Plugs.LoadedASM.FullName + "] added to g_ZPrograms");
|
||||
if (File.Exists(plugin.ProgramName + ".bdf"))
|
||||
plugin.LoadConfiguration(); // will throw an error if BlankBot tries to load config
|
||||
}
|
||||
|
@ -450,7 +479,7 @@ namespace Bot
|
|||
default:
|
||||
{
|
||||
|
||||
Log.debug("Unknown response code");
|
||||
Log.info(true, "Unknown response code");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -469,13 +498,12 @@ namespace Bot
|
|||
//}
|
||||
}
|
||||
|
||||
Log.debugf(false, "SL_NET", new[] { "" });
|
||||
|
||||
prompter.Abort();
|
||||
client.Network.Logout();
|
||||
}
|
||||
|
||||
Environment.Exit(0);
|
||||
|
||||
Log.debugf(false, "main", args);
|
||||
//System.Console.WriteLine("PAUSING. PRESS ANY KEY TO EXIT");
|
||||
//System.Console.ReadKey();
|
||||
}
|
||||
|
|
|
@ -74,7 +74,8 @@ namespace Bot
|
|||
File.WriteAllText(Name + ".json", Json);
|
||||
} catch(Exception E)
|
||||
{
|
||||
Console.WriteLine(E.Message);
|
||||
BotSession.Instance.Logger.info(true, E.Message);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,14 +92,16 @@ namespace Bot
|
|||
string serial = File.ReadAllText(Name + ".json");
|
||||
|
||||
obj = (T)JsonConvert.DeserializeObject<T>(serial);
|
||||
Console.WriteLine("Returning class object");
|
||||
BotSession.Instance.Logger.info(true, "Returning class object");
|
||||
|
||||
|
||||
if (obj == null) obj = default(T);
|
||||
return obj;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
BotSession.Instance.Logger.info(true, e.Message);
|
||||
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
}
|
||||
|
|
138
SysOut.cs
138
SysOut.cs
|
@ -1,138 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Bot
|
||||
{
|
||||
public sealed class SysOut
|
||||
{
|
||||
|
||||
private static SysOut _Inst = null;
|
||||
private static readonly object instloc = new object();
|
||||
|
||||
static SysOut() { }
|
||||
|
||||
public static SysOut Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (instloc)
|
||||
{
|
||||
if(_Inst == null)
|
||||
{
|
||||
_Inst = new SysOut();
|
||||
_Inst.FLAVOR = "Bot";
|
||||
}
|
||||
return _Inst;
|
||||
}
|
||||
}
|
||||
}
|
||||
public int tabs = 0;
|
||||
string FLAVOR;
|
||||
|
||||
private static readonly object Locks = new object();
|
||||
|
||||
|
||||
public void info(string msg)
|
||||
{
|
||||
lock (Locks)
|
||||
{
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
System.Console.Write("[");
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
System.Console.Write("INFO");
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
System.Console.Write("] [");
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
System.Console.Write(FLAVOR);
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
System.Console.Write("] ");
|
||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||
for (int i = 0; i < tabs; i++) { Console.Write("\t|"); }
|
||||
System.Console.Write(msg);
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
System.Console.Write("\n");
|
||||
}
|
||||
}
|
||||
|
||||
public void debugf(bool enter, string label, string[] debugParams)
|
||||
{
|
||||
lock (Locks)
|
||||
{
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
System.Console.Write("[");
|
||||
Console.ForegroundColor = ConsoleColor.DarkRed;
|
||||
System.Console.Write("DEBUG");
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
System.Console.Write("] [");
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
System.Console.Write(FLAVOR);
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
System.Console.Write("] ");
|
||||
Console.ForegroundColor = ConsoleColor.Magenta;
|
||||
|
||||
if (enter)
|
||||
{
|
||||
for (int i = 0; i < tabs; i++) { System.Console.Write("\t"); }
|
||||
System.Console.Write("ENTER ");
|
||||
tabs++;
|
||||
Console.BackgroundColor = ConsoleColor.Cyan;
|
||||
System.Console.Write(label);
|
||||
Console.BackgroundColor = ConsoleColor.Black;
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.Write(" ");
|
||||
}
|
||||
else
|
||||
{
|
||||
tabs--;
|
||||
for (int i = 0; i < tabs; i++) { System.Console.Write("\t"); }
|
||||
System.Console.Write("LEAVE ");
|
||||
Console.BackgroundColor = ConsoleColor.Cyan;
|
||||
System.Console.Write(label);
|
||||
Console.BackgroundColor = ConsoleColor.Black;
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.Write(" ");
|
||||
}
|
||||
Console.Write("[");
|
||||
for (int i = 0; i < debugParams.Length; i++)
|
||||
{
|
||||
Console.Write(debugParams[i] + ", ");
|
||||
}
|
||||
Console.Write("]");
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
System.Console.Write("\n");
|
||||
Console.ResetColor();
|
||||
}
|
||||
}
|
||||
|
||||
public void debug(string m)
|
||||
{
|
||||
lock (Locks)
|
||||
{
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
System.Console.Write("[");
|
||||
Console.ForegroundColor = ConsoleColor.DarkRed;
|
||||
System.Console.Write("DEBUG");
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
System.Console.Write("] [");
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
System.Console.Write(FLAVOR);
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
System.Console.Write("] ");
|
||||
Console.ForegroundColor = ConsoleColor.Magenta;
|
||||
|
||||
for (int i = 0; i < tabs; i++)
|
||||
{
|
||||
Console.Write("\t|");
|
||||
}
|
||||
Console.Write(" " + m);
|
||||
Console.Write("\n");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue