Example #1
0
 protected virtual void LoadCommandsList()
 {
     foreach (var com in GetAPICommandClasses())
     {
         if (com != null)
         {
             if (com.IsAbstract == false)
             {
                 API_interface D = (API_interface)Activator.CreateInstance(com);
                 if (D != null)
                 {
                     string name = D.CommandName;
                     if (subtype_map.ContainsKey(name) == false)
                     {
                         string worknamespace = com.Namespace;
                         worknamespace = worknamespace.Replace("BetterSecondBot.Commands.", "");
                         worknamespace = worknamespace.Replace("BetterSecondBot.RLV.", "");
                         worknamespace = worknamespace.Replace("BetterSecondbot.HttpServer.View.", "");
                         worknamespace = worknamespace.Replace("BetterSecondbot.HttpServer.view.", "");
                         worknamespace = worknamespace.Replace("BetterSecondbot.HttpServer.Control.", "");
                         worknamespace = worknamespace.Replace("BetterSecondbot.HttpServer.control.", "");
                         worknamespace = worknamespace.Replace("CMD_", "");
                         subtype_map.Add(name, D.GetType());
                         subtype_workspace_map.Add(name, worknamespace);
                     }
                     else
                     {
                         LogFormater.Crit("[CMD] command: " + D.CommandName + " already defined!");
                     }
                 }
             }
         }
     }
 }
Example #2
0
        protected JsonConfig MakeDefault()
        {
            string[]   args  = this.GetCommandsList();
            JsonConfig reply = new JsonConfig();

            foreach (string arg in args)
            {
                string arg_type          = GetCommandArgTypes(arg).First();
                string arg_value_default = null;
                if (arg_type != "")
                {
                    string[] ArgHints = GetCommandArgHints(arg);
                    if (ArgHints.Length > 0)
                    {
                        arg_value_default = ArgHints[0];
                        arg_value_default = arg_value_default.Replace("[", "");
                        arg_value_default = arg_value_default.Replace("]", "");
                        arg_value_default = arg_value_default.Replace("\"", "");
                    }
                    else
                    {
                        LogFormater.Debug("[Notice] No args hint found for " + arg + "");
                    }
                }
                if (arg_value_default != null)
                {
                    Type         Dtype = reply.GetType();
                    PropertyInfo prop  = Dtype.GetProperty(arg, BindingFlags.Public | BindingFlags.Instance);
                    SetPropTypeAndValue(reply, prop, arg, arg_type, arg_value_default);
                }
            }
            return(reply);
        }
Example #3
0
 protected void SetupMonitor()
 {
     string[] skipped = new string[] { "None", "" };
     foreach (OnEvent E in Events)
     {
         if (E.Enabled == false)
         {
             continue;
         }
         if ((E.Monitor == "None") || (E.Monitor == ""))
         {
             continue;
         }
         UUID checking = UUID.Zero;
         if (UUID.TryParse(E.Monitor, out checking) == false)
         {
             continue;
         }
         if (checking == UUID.Zero)
         {
             continue;
         }
         if (group_membership_update_q.ContainsKey(checking) == true)
         {
             continue;
         }
         if (DebugWhere == true)
         {
             LogFormater.Info("OnEvent - attaching to group membership: " + checking.ToString(), true);
         }
         group_membership_update_q.Add(checking, new KeyValuePair <long, int>(helpers.UnixTimeNow(), 45));
     }
 }
Example #4
0
 public BetterAtHome(Cli setcontroler, JsonConfig configfile)
 {
     controler       = setcontroler;
     this.configfile = configfile;
     attach_events();
     SetBetterAtHomeAction("Standby");
     foreach (string a in configfile.Basic_HomeRegions)
     {
         string[] bits = helpers.ParseSLurl(a);
         homeRegions.Add(bits[0]);
         LogFormater.Info("Added home region: " + bits[0]);
     }
     if (configfile.Basic_AvoidRestartRegions != null)
     {
         foreach (string a in configfile.Basic_AvoidRestartRegions)
         {
             string[] bits = helpers.ParseSLurl(a);
             avoidRestartRegions.Add(bits[0]);
             LogFormater.Info("Added restart region: " + bits[0]);
         }
     }
     else
     {
         LogFormater.Warn("Config is old - please update");
     }
 }
Example #5
0
        protected void loadFromDockerEnv()
        {
            LogFormater.Info("Loading onEvents from ENV", true);
            int  loop  = 1;
            bool found = true;

            while (found == true)
            {
                string title = getEnv("event_" + loop.ToString() + "_title");
                if (helpers.notempty(title) == true)
                {
                    OnEvent config = new OnEvent();
                    bool.TryParse(getEnv("event_" + loop.ToString() + "_enabled"), out bool enabled);
                    config.Enabled = enabled;
                    if (enabled == true)
                    {
                        config.title   = title;
                        config.Monitor = getEnv("event_" + loop.ToString() + "_monitor");
                        config.On      = getEnv("event_" + loop.ToString() + "_on");

                        int           loop2       = 1;
                        bool          found2      = true;
                        List <string> wherefields = new List <string>();
                        while (found2 == true)
                        {
                            found2 = false;
                            string wherefield = getEnv("event_" + loop.ToString() + "_where_" + loop2.ToString());
                            if (helpers.notempty(wherefield) == true)
                            {
                                found2 = true;
                                wherefields.Add(wherefield);
                            }
                            loop2++;
                        }
                        config.Where = wherefields.ToArray();
                        loop2        = 1;
                        found2       = true;
                        List <string> actionfields = new List <string>();
                        while (found2 == true)
                        {
                            found2 = false;
                            string actionfield = getEnv("event_" + loop.ToString() + "_action_" + loop2.ToString());
                            if (helpers.notempty(actionfield) == true)
                            {
                                found2 = true;
                                actionfields.Add(actionfield);
                            }
                            loop2++;
                        }
                        config.Actions = actionfields.ToArray();
                        Events.Add(config);
                    }
                }
                else
                {
                    found = false;
                }
                loop++;
            }
        }
Example #6
0
 protected void TriggerAdvert(int advertID)
 {
     LogFormater.Info("Processing advert: " + (advertID + 1).ToString(), true);
     foreach (UUID group in groups[advertID])
     {
         if (asNotice[advertID] == true)
         {
             if (attachments[advertID] != UUID.Zero)
             {
                 controler.getBot().CallAPI(
                     "GroupnoticeWithAttachment",
                     new[] { group.ToString(), titles[advertID], content[advertID], attachments[advertID].ToString() }
                     );
             }
             else
             {
                 controler.getBot().CallAPI(
                     "Groupnotice",
                     new[] { group.ToString(), titles[advertID], content[advertID] }
                     );
             }
         }
         else
         {
             controler.getBot().CallAPI(
                 "Groupchat",
                 new[] { group.ToString(), content[advertID] }
                 );
         }
     }
 }
Example #7
0
        protected void JsonChatControler(string message, string sender_name, UUID sender_uuid, bool avatar, bool group, UUID group_uuid, bool localchat, bool fromme)
        {
            if ((group == true) || (localchat == true) || (fromme == true))
            {
                return;
            }
            try
            {
                bool frommaster = true;
                if (sender_uuid != master_uuid)
                {
                    frommaster = false;
                }
                if (frommaster == true)
                {
                    if (message == "fakerestart")
                    {
                        AlertMessageEventArgs Alertargs = new AlertMessageEventArgs("this is a fake restart message", new Random().Next(99999).ToString(), new OpenMetaverse.StructuredData.OSDMap());
                        AlertEvent(this, Alertargs);
                        return;
                    }
                }
                JsonApiDefine APIE = JsonConvert.DeserializeObject <JsonApiDefine>(message);

                CoreCommandLib(sender_uuid, frommaster, APIE.cmd, APIE.args, APIE.signing, APIE.reply);
            }
            catch (Exception e)
            {
                LogFormater.Crit("[CoreCommandLib] exploded: " + e.Message + "");
            }
        }
Example #8
0
        protected void HTTPWiki()
        {
            mdWiki.AppendLine("View as [HTML](https://wiki.blackatom.live/files/Commands.html)");
            mdWiki.AppendLine(" ");
            mdWiki.AppendLine("Host it yourself: [+Docker image](https://hub.docker.com/r/madpeter/secondbot_wiki)");
            mdWiki.AppendLine(" ");
            mdWiki.AppendLine("---");
            mdWiki.AppendLine("# Commands list");

            LogFormater.Info("[WIKI] Starting area HTTP endpoint");
            HTTPendpoint HTTP = new HTTPendpoint();

            HTTPmenu("Commands", HTTP);

            // create workspaces
            HTTPWorkspaces("Commands", HTTP);

            // create commands
            HTTPCommands("Commands", HTTP);

            io.WriteFile("../commands.md", mdWiki.ToString());

            HTTP = null;
            LogFormater.Info("[WIKI] Done with area");
        }
Example #9
0
        public Cli(JsonConfig Config, bool as_docker, bool use_self_keep_alive, string loadingFromFolder)
        {
            exitBot    = false;
            use_folder = loadingFromFolder;
            LogFormater.Info("Starting cli");
            if (helpers.botRequired(Config) == true)
            {
                Bot = new SecondBot();
                Bot.setFolder(use_folder);
                Bot.Setup(Config, AssemblyInfo.GetGitHash());

                if (as_docker == true)
                {
                    Bot.AsDocker();
                }

                Bot.Start(false);

                attachEventListenerObjects(Config, as_docker);
                if (use_self_keep_alive == true)
                {
                    keep_alive();
                }
            }
            else
            {
                LogFormater.Warn("Required settings missing");
            }
            if (use_self_keep_alive == true)
            {
                exitBot = true;
            }
        }
Example #10
0
        protected void ApplyRelayConfig(string sourcename, string sourcevalue, string targetname, string targetvalue, bool jsonEncoded)
        {
            relay_config relay = new relay_config();

            relay.encode_as_json = jsonEncoded;
            relay.sourcename     = sourcename;
            relay.sourcevalue    = sourcevalue;
            relay.targetname     = targetname;
            relay.targetvalue    = targetvalue;
            LogFormater.Info("Attaching relay: " + relay.sourcename + " to " + relay.targetname);
            if (relay.sourcename == "localchat")
            {
                LocalchatRelay.Add(relay);
            }
            else if (relay.sourcename == "groupchat")
            {
                GroupChatRelay.Add(relay);
            }
            else if (relay.sourcename == "avatarim")
            {
                AvatarIMRelay.Add(relay);
            }
            else if (relay.sourcename == "objectim")
            {
                ObjectIMRelay.Add(relay);
            }
            else if (relay.sourcename == "discord")
            {
                DiscordRelay.Add(relay);
            }
        }
Example #11
0
 protected void SetPropTypeAndValue(JsonConfig reply, PropertyInfo prop, string arg, string arg_type, string arg_value_default)
 {
     if (prop != null)
     {
         if (prop.CanWrite == true)
         {
             if (arg_type == "Number")
             {
                 if (int.TryParse(arg_value_default, out int result) == true)
                 {
                     prop.SetValue(reply, result, null);
                 }
             }
             else if (arg_type == "Text")
             {
                 prop.SetValue(reply, arg_value_default, null);
             }
             else if (arg_type == "True|False")
             {
                 if (bool.TryParse(arg_value_default, out bool result) == true)
                 {
                     prop.SetValue(reply, result, null);
                 }
             }
             else if (arg_type == "Collection")
             {
                 prop.SetValue(reply, arg_value_default.Split(','), null);
             }
             else if (arg_type == "BigNumber")
             {
                 if (ulong.TryParse(arg_value_default, out ulong result) == true)
                 {
                     prop.SetValue(reply, result, null);
                 }
             }
             else if (arg_type == "Float")
             {
                 if (float.TryParse(arg_value_default, out float result) == true)
                 {
                     prop.SetValue(reply, result, null);
                 }
             }
             else
             {
                 LogFormater.Debug("unsupported arg_type: " + arg_type + " for " + arg + "");
             }
         }
         else
         {
             LogFormater.Warn("Unable to write to " + arg + "");
         }
     }
     else
     {
         LogFormater.Crit("unknown prop " + arg + "");
     }
 }
Example #12
0
        public CliDocker()
        {
            Thread.Sleep(3000);
            LogFormater.Status("-> Getting config from Docker");
            JsonConfig Config = MakeJsonConfig.FromENV();

            Config = MakeJsonConfig.Http_config_check(Config);
            new Discord_super(Config, true, "");
        }
Example #13
0
        protected void SmartCommandReply(bool run_status, string target, string output, string command)
        {
            string mode           = "CHAT";
            UUID   target_avatar  = UUID.Zero;
            int    target_channel = 0;

            if (target.StartsWith("http://"))
            {
                mode = "HTTP";
            }
            else if (UUID.TryParse(target, out target_avatar) == true)
            {
                mode = "IM";
            }
            else
            {
                if (int.TryParse(target, out target_channel) == false)
                {
                    mode = "None";
                }
            }
            if (mode == "CHAT")
            {
                if (target_channel >= 0)
                {
                    Client.Self.Chat(output, target_channel, ChatType.Normal);
                }
                else
                {
                    run_status = false;
                    LogFormater.Crit("[SmartReply] output Channel must be zero or higher");
                }
            }
            else if (mode == "IM")
            {
                Client.Self.InstantMessage(target_avatar, output);
            }
            else if (mode == "HTTP")
            {
                Dictionary <string, string> values = new Dictionary <string, string>
                {
                    { "reply", output },
                    { "command", command },
                };

                var content = new FormUrlEncodedContent(values);
                try
                {
                    HTTPclient.PostAsync(target, content);
                }
                catch (Exception e)
                {
                    LogFormater.Crit("[SmartReply] HTTP failed: " + e.Message + "");
                }
            }
        }
Example #14
0
 protected override Task DiscordClientLoggedOut()
 {
     LogFormater.Info("Discord has logged out", true);
     ReconnectTimer           = new Timer();
     ReconnectTimer.Interval  = 10000;
     ReconnectTimer.Elapsed  += ReconnectTimerEvent;
     ReconnectTimer.AutoReset = false;
     ReconnectTimer.Enabled   = false;
     return(Task.CompletedTask);
 }
Example #15
0
        protected void loadFromDisk()
        {
            LogFormater.Info("Loading adverts from Disk", true);
            advertsBlob  loadedAdverts = new advertsBlob();
            advertConfig demoAdvert    = new advertConfig();

            demoAdvert.attachment = UUID.Zero.ToString();
            demoAdvert.content    = "Content";
            demoAdvert.title      = "Title";
            demoAdvert.groups     = new[] { UUID.Zero.ToString(), UUID.Zero.ToString() };
            demoAdvert.days       = "0,1,2,3,4,5,6";
            demoAdvert.hour       = "12";
            demoAdvert.min        = "30";
            demoAdvert.notice     = "false";
            demoAdvert.enabled    = "false";
            loadedAdverts.adverts = new advertConfig[] { demoAdvert };


            string   targetfile = "adverts.json";
            SimpleIO io         = new SimpleIO();

            io.ChangeRoot(controler.getFolderUsed());
            if (SimpleIO.FileType(targetfile, "json") == false)
            {
                LogFormater.Status("Creating new adverts file", true);
                io.WriteJsonAdverts(loadedAdverts, targetfile);
                return;
            }
            if (io.Exists(targetfile) == false)
            {
                LogFormater.Status("Creating new adverts file", true);
                io.WriteJsonAdverts(loadedAdverts, targetfile);
                return;
            }
            string json = io.ReadFile(targetfile);

            if (json.Length > 0)
            {
                try
                {
                    loadedAdverts = JsonConvert.DeserializeObject <advertsBlob>(json);
                    foreach (advertConfig loaded in loadedAdverts.adverts)
                    {
                        Unpack(loaded);
                    }
                }
                catch
                {
                    io.MarkOld(targetfile);
                    io.WriteJsonAdverts(loadedAdverts, targetfile);
                }
                return;
            }
        }
Example #16
0
        public void Format_MessageIsNotNull_CurrentDateIsFirstThingInMessage()
        {
            var timeService = new FakeTimeService();
            var current = new DateTime(2012, 08, 28, 12, 0, 0);
            timeService.CurrentDateTime = current;
            var message = new InfoMessage("infomessage");
            var formatter = new LogFormater(timeService);

            var formattedMessage = formatter.Format(message);

            Assert.IsTrue(formattedMessage.StartsWith("[28.08.2012 12:00]"));
        }
Example #17
0
 public void unattach_events()
 {
     LogFormater.Info("Relay - disconnecting");
     if (superV != null)
     {
         superV.MessageEvent -= DiscordMessageHandler;
     }
     if (controler.getBot() != null)
     {
         controler.getBot().MessageEvent -= SLMessageHandler;
     }
 }
Example #18
0
        public object SetParcelFlag([FormField] string escapedflagdata, string token)
        {
            KeyValuePair <bool, string> tests = SetupCurrentParcel(token, "parcel", "SetParcelFlag");

            if (tests.Key == false)
            {
                return(Failure(tests.Value, "SetParcelFlag", new [] { escapedflagdata }));
            }
            List <string> acceptablewords          = new List <string>();
            Dictionary <string, ParcelFlags> flags = parcel_static.get_flags_list();

            acceptablewords.AddRange(new[] { "True", "False" });

            Dictionary <string, bool> setflags = new Dictionary <string, bool>();

            string[] args = escapedflagdata.Split(":::");
            foreach (string a in args)
            {
                string[] parts = a.Split('=', StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length != 2)
                {
                    LogFormater.Warn("Flag: " + a + " missing \"=\"");
                    continue;
                }
                if (flags.ContainsKey(parts[0]) == false)
                {
                    LogFormater.Warn("Flag: " + parts[0] + " is unknown");
                    continue;
                }
                if (acceptablewords.Contains(parts[1]) == false)
                {
                    LogFormater.Crit("Unable to set flag " + parts[0] + " to : " + parts[1] + "");
                }
                setflags.Add(parts[0], Convert.ToBoolean(parts[1]));
            }
            if (setflags.Count == 0)
            {
                return(Failure("No accepted flags", "SetParcelFlag", new [] { escapedflagdata }));
            }
            if (parcel_static.has_parcel_perm(targetparcel, bot) == false)
            {
                return(Failure("Incorrect perms to control parcel", "SetParcelFlag", new [] { escapedflagdata }));
            }
            foreach (KeyValuePair <string, bool> cfg in setflags)
            {
                if (flags.ContainsKey(cfg.Key) == true)
                {
                    parcel_static.ParcelSetFlag(flags[cfg.Key], targetparcel, cfg.Value);
                }
            }
            targetparcel.Update(bot.GetClient.Network.CurrentSim, false);
            return(BasicReply("Applying perms", "SetParcelFlag", new [] { escapedflagdata }));
        }
Example #19
0
        protected virtual async Task <Task> DicordClientLoggedin()
        {
            LogFormater.Info("Discord has logged in", true);
            await DiscordClient.StartAsync().ConfigureAwait(false);

            ReconnectTimer           = new Timer();
            ReconnectTimer.Interval  = 10000;
            ReconnectTimer.Elapsed  += ReconnectTimerEvent;
            ReconnectTimer.AutoReset = false;
            ReconnectTimer.Enabled   = false;
            return(Task.CompletedTask);
        }
Example #20
0
        public void Format_MessageIsInfo_MessageContainsExplanatoryMessage()
        {
            var timeService = new FakeTimeService();
            var current = new DateTime(2012, 08, 28, 12, 0, 0);
            timeService.CurrentDateTime = current;
            var message = new InfoMessage("User Arthur Dent just logged into his account");
            var formatter = new LogFormater(timeService);

            var formattedMessage = formatter.Format(message);

            Assert.IsTrue(formattedMessage.StartsWith("[28.08.2012 12:00][Info] User Arthur Dent just logged into his account"));
        }
Example #21
0
        public void Format_MessageIsException_InfoIsWrittenAfterDateInMessage()
        {
            var timeService = new FakeTimeService();
            var current = new DateTime(2012, 08, 28, 12, 0, 0);
            timeService.CurrentDateTime = current;
            var message = new ExceptionMessage();
            var formatter = new LogFormater(timeService);

            var formattedMessage = formatter.Format(message);

            Assert.IsTrue(formattedMessage.StartsWith("[28.08.2012 12:00][Exception]"));
        }
Example #22
0
        protected void InterfaceWiki(string area, API_supported_interface shared_interface, bool track_commands = false)
        {
            LogFormater.Info("[WIKI] Starting area " + area + "");
            // create index
            InterfaceIndex(area, shared_interface);

            // create workspaces
            InterfaceWorkspaces(area, shared_interface);

            // create commands
            InterfaceCommands(area, shared_interface, track_commands);
            LogFormater.Info("[WIKI] Done with area");
        }
Example #23
0
 public advertsService(Cli Master, bool LoadFromDocker)
 {
     controler = Master;
     LogFormater.Info("Starting adverts service", true);
     if (LoadFromDocker == true)
     {
         loadFromDockerEnv();
     }
     else
     {
         loadFromDisk();
     }
     controler.getBot().StatusMessageEvent += StatusPing;
 }
Example #24
0
        protected void Unpack(advertConfig config)
        {
            titles.Add(config.title);
            UUID attachment = UUID.Zero;

            UUID.TryParse(config.attachment, out attachment);
            attachments.Add(attachment);
            content.Add(config.content);
            bool asGroupNotice = false;

            bool.TryParse(config.notice, out asGroupNotice);
            asNotice.Add(asGroupNotice);
            string[]   unpackDays   = config.days.Split(',');
            List <int> activeondays = new List <int>();

            foreach (string Uday in unpackDays)
            {
                if (int.TryParse(Uday, out int dayid) == true)
                {
                    activeondays.Add(dayid);
                }
            }
            activeDays.Add(activeondays);
            int activeHourid = -2;

            int.TryParse(config.hour, out activeHourid);
            activeHours.Add(activeHourid);
            int activeMinid = -2;

            int.TryParse(config.min, out activeMinid);
            activeMins.Add(activeMinid);
            bool asEnabled = false;

            bool.TryParse(config.enabled, out asEnabled);
            enabled.Add(asEnabled);
            List <UUID> selectedGroups = new List <UUID>();

            foreach (string groupA in config.groups)
            {
                UUID groupUUID = UUID.Zero;
                UUID.TryParse(groupA, out groupUUID);
                if (groupUUID != UUID.Zero)
                {
                    selectedGroups.Add(groupUUID);
                }
            }
            groups.Add(selectedGroups);
            LogFormater.Info("Loaded advert: (" + config.enabled + ") " + config.title + " " + config.days + " | " + config.hour + "h " + config.min + "m", true);
        }
Example #25
0
 public onevent(Cli master, bool LoadFromDocker)
 {
     controler = master;
     LogFormater.Info("{onEvents} starting", true);
     if (LoadFromDocker == true)
     {
         loadFromDockerEnv();
     }
     else
     {
         loadFromDisk();
     }
     controler.getBot().StatusMessageEvent += statusMessage;
     LogFormater.Info("{onEvents} ready", true);
 }
Example #26
0
 protected virtual async Task StartDiscordClientService()
 {
     DiscordClient                  = new DiscordSocketClient();
     DiscordClient.Ready           += DiscordClientReady;
     DiscordClient.LoggedOut       += DiscordClientLoggedOut;
     DiscordClient.LoggedIn        += DicordClientLoggedin;
     DiscordClient.MessageReceived += DiscordClientMessageReceived;
     ReconnectTimer                 = new Timer();
     ReconnectTimer.Interval        = 10000;
     ReconnectTimer.Elapsed        += ReconnectTimerEvent;
     ReconnectTimer.AutoReset       = false;
     ReconnectTimer.Enabled         = false;
     LogFormater.Info("Discord is starting", true);
     await DiscordClient.LoginAsync(TokenType.Bot, myconfig.DiscordFull_Token);
 }
Example #27
0
 public void attachEventListenerObjects(JsonConfig Config, bool as_docker)
 {
     LogFormater.Info("HTTP service requested:" + Config.Http_Enable.ToString());
     if (Config.Http_Enable == true)
     {
         new Thread(() =>
         {
             new HttpAsService(Bot, Config, as_docker);
         }).Start();
     }
     Adverts             = new advertsService(this, as_docker);
     Events              = new onevent(this, as_docker);
     betterAtHomeService = new BetterAtHome(this, Config);
     betterTracking      = new BetterTracking(this);
     datastorage         = new Datastorage(this);
 }
Example #28
0
        static void Main(string[] args)
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.UnhandledException += new UnhandledExceptionEventHandler(PanicMode);
            if (helpers.notempty(Environment.GetEnvironmentVariable("Basic_BotUserName")) == true)
            {
                new CliDocker();
            }
            else
            {
                new CliHardware(args);
            }
            LogFormater.Status("- Exiting in 5 secs -");
            Thread.Sleep(5000);
        }
Example #29
0
        protected void loadRelayConfigFromFile()
        {
            JsonCustomRelays Demo = new JsonCustomRelays()
            {
                sourceFilter = "all", sourceType = "localchat", targetType = "groupchat", targetConfig = UUID.Zero.ToString()
            };
            JsonCustomRelaysSet LoadedRelays = new JsonCustomRelaysSet
            {
                Entrys = new JsonCustomRelays[] { Demo }
            };
            string   targetfile = "customrelays.json";
            SimpleIO io         = new SimpleIO();

            io.ChangeRoot(controler.getFolderUsed());
            if (SimpleIO.FileType(targetfile, "json") == false)
            {
                io.WriteJsonRelays(LoadedRelays, targetfile);
                return;
            }
            if (io.Exists(targetfile) == false)
            {
                io.WriteJsonRelays(LoadedRelays, targetfile);
                return;
            }
            string json = io.ReadFile(targetfile);

            if (json.Length > 0)
            {
                try
                {
                    LoadedRelays = JsonConvert.DeserializeObject <JsonCustomRelaysSet>(json);
                    int loop = 1;
                    foreach (JsonCustomRelays loaded in LoadedRelays.Entrys)
                    {
                        LogFormater.Info("Relay " + loop.ToString() + " [OK] sending to attach");
                        ApplyRelayConfig(loaded.sourceType, loaded.sourceFilter, loaded.targetType, loaded.targetConfig, loaded.encodeJson);
                        loop++;
                    }
                }
                catch
                {
                    io.MarkOld(targetfile);
                    io.WriteJsonRelays(LoadedRelays, targetfile);
                }
                return;
            }
        }
Example #30
0
        protected override void GroupInvite(InstantMessageEventArgs e)
        {
            string[] stage1 = e.IM.FromAgentName.ToLowerInvariant().Split('.');
            if (stage1.Length == 1)
            {
                stage1 = e.IM.FromAgentName.ToLowerInvariant().Split(" ");
            }
            string name = "" + stage1[0].FirstCharToUpper() + "";

            if (stage1.Length == 1)
            {
                name = " Resident";
            }
            else
            {
                name = "" + name + " " + stage1[1].FirstCharToUpper() + "";
            }
            bool   accept_invite;
            string whyAccept = "";

            if (Is_avatar_master(name) == true)
            {
                accept_invite = true;
                whyAccept     = "Master";
            }
            else
            {
                name          = name.ToLowerInvariant();
                accept_invite = Accept_action_from_name("group", name);
                if (accept_invite == true)
                {
                    whyAccept = "Action auth";
                    Remove_action_from_name("group", name);
                }
            }
            if (accept_invite == true)
            {
                LogFormater.Info("Group invite event from: " + e.IM.FromAgentName + " Accepted - " + whyAccept);
                GroupInvitationEventArgs G = new GroupInvitationEventArgs(e.Simulator, e.IM.FromAgentID, e.IM.FromAgentName, e.IM.Message);
                Client.Self.GroupInviteRespond(G.AgentID, e.IM.IMSessionID, true);
                Client.Groups.RequestCurrentGroups();
            }
            else
            {
                LogFormater.Info("Group invite event from: " + e.IM.FromAgentName + " Rejected");
            }
        }
Example #31
0
        protected void SendHTTPData(object data)
        {
            Dictionary <string, string> values = new Dictionary <string, string>
            {
                { "reply", data.ToString() },
            };
            var content = new FormUrlEncodedContent(values);

            try
            {
                HTTPclient.PostAsync(controler.getBot().getMyConfig.Setting_Tracker, content);
            }
            catch (Exception e)
            {
                LogFormater.Crit("[Tracker] HTTP failed: " + e.Message + "");
            }
        }
Example #32
0
        protected void loadFromDisk()
        {
            LogFormater.Info("Loading onEvents from Disk", true);
            try
            {
                OnEventBlob DemoloadedEvents = new OnEventBlob();
                OnEvent     demoEvent        = new OnEvent();
                demoEvent.Enabled           = false;
                demoEvent.Actions           = new string[] { "Say|||0~#~hi mom im on TV!" };
                demoEvent.title             = "demo";
                demoEvent.On                = "Clock";
                demoEvent.Where             = new string[] { "59 23 * * 7 {CRON} true" };
                demoEvent.Monitor           = "None";
                DemoloadedEvents.listEvents = new OnEvent[] { demoEvent };

                string   targetfile = "events.json";
                SimpleIO io         = new SimpleIO();
                io.ChangeRoot(controler.getFolderUsed());
                if (io.Exists(targetfile) == false)
                {
                    LogFormater.Status("Creating new events file", true);
                    io.WriteJsonEvents(DemoloadedEvents, targetfile);
                    return;
                }
                string json = io.ReadFile(targetfile);
                if (json.Length > 0)
                {
                    try
                    {
                        OnEventBlob loadedEvents = JsonConvert.DeserializeObject <OnEventBlob>(json);
                        foreach (OnEvent loaded in loadedEvents.listEvents)
                        {
                            Events.Add(loaded);
                        }
                    }
                    catch
                    {
                        LogFormater.Info("error loading events from " + targetfile + " skipping", true);
                    }
                    return;
                }
            }
            catch
            {
            }
        }
Example #33
0
 public static bool botRequired(JsonConfig test)
 {
     if (helpers.notempty(test.Basic_BotUserName) && helpers.notempty(test.Basic_BotPassword) && helpers.notempty(test.Security_MasterUsername) && helpers.notempty(test.Security_SignedCommandkey))
     {
         // required values are set
         MakeJsonConfig Testing             = new MakeJsonConfig();
         string[]       testingfor          = new[] { "Basic_BotUserName", "Basic_BotPassword", "Security_SignedCommandkey", "Security_WebUIKey" };
         bool           default_value_found = false;
         foreach (string a in testingfor)
         {
             if (Testing.GetCommandArgTypes(a).First() == MakeJsonConfig.GetProp(test, a))
             {
                 LogFormater.Warn("" + a + " is currently set to the default");
                 default_value_found = true;
                 break;
             }
         }
         if (default_value_found == false)
         {
             LogFormater.Status("User => " + test.Basic_BotUserName);
             LogFormater.Status("Master => " + test.Security_MasterUsername);
         }
         return(!default_value_found);
     }
     else
     {
         if (helpers.notempty(test.Basic_BotUserName) == false)
         {
             LogFormater.Warn("Basic_BotUserName is null or empty");
         }
         if (helpers.notempty(test.Basic_BotPassword) == false)
         {
             LogFormater.Warn("Basic_BotPassword is null or empty");
         }
         if (helpers.notempty(test.Security_MasterUsername) == false)
         {
             LogFormater.Warn("Security_MasterUsername is null or empty");
         }
         if (helpers.notempty(test.Security_SignedCommandkey) == false)
         {
             LogFormater.Warn("Security_SignedCommandkey is null or empty");
         }
         return(false);
     }
 }