diff --git a/BSBshared/BotTypes/BasicBot.cs b/BSBshared/BotTypes/BasicBot.cs index 0e3ab64..88260ed 100644 --- a/BSBshared/BotTypes/BasicBot.cs +++ b/BSBshared/BotTypes/BasicBot.cs @@ -16,7 +16,7 @@ namespace BetterSecondBotShared.bottypes LastStatusMessage = "No status"; } protected List SubMasters = new List(); - public bool is_avatar_master(string name) + public bool Is_avatar_master(string name) { if (name == myconfig.Security_MasterUsername) { @@ -202,7 +202,7 @@ namespace BetterSecondBotShared.bottypes { name = "" + name + " " + stage1[1].FirstCharToUpper() + ""; } - if(is_avatar_master(name) == true) + if(Is_avatar_master(name) == true) { GroupInvitationEventArgs G = new GroupInvitationEventArgs(e.Simulator, e.IM.FromAgentID, e.IM.FromAgentName, e.IM.Message); Client.Self.GroupInviteRespond(G.AgentID, e.IM.IMSessionID, true); @@ -211,7 +211,7 @@ namespace BetterSecondBotShared.bottypes } protected virtual void FriendshipOffer(UUID IMSessionID, string FromAgentName, UUID FromAgentID) { - if (is_avatar_master(FromAgentName) == true) + if (Is_avatar_master(FromAgentName) == true) { Client.Friends.AcceptFriendship(FromAgentID, IMSessionID); } @@ -219,14 +219,14 @@ namespace BetterSecondBotShared.bottypes protected virtual void RequestLure(UUID IMSessionID, string FromAgentName, UUID FromAgentID) { - if (is_avatar_master(FromAgentName) == true) + if (Is_avatar_master(FromAgentName) == true) { Client.Self.SendTeleportLure(FromAgentID); } } protected List accept_next_teleport_from = new List(); - public void add_uuid_to_teleport_list(UUID avatar) + public void Add_uuid_to_teleport_list(UUID avatar) { if (accept_next_teleport_from.Contains(avatar) == false) { @@ -237,7 +237,7 @@ namespace BetterSecondBotShared.bottypes protected virtual void RequestTeleport(UUID IMSessionID, string FromAgentName, UUID FromAgentID) { bool allow = false; - if (is_avatar_master(FromAgentName) == true) + if (Is_avatar_master(FromAgentName) == true) { allow = true; } diff --git a/BSBshared/Json/JsonConfigApi.cs b/BSBshared/Json/JsonConfigApi.cs index 6d6e743..a35d984 100644 --- a/BSBshared/Json/JsonConfigApi.cs +++ b/BSBshared/Json/JsonConfigApi.cs @@ -359,7 +359,7 @@ namespace BetterSecondBotShared.Json } - protected JsonConfig process_prop(JsonConfig reply,string arg,string arg_value_default) + protected JsonConfig Process_prop(JsonConfig reply,string arg,string arg_value_default) { string arg_type = GetCommandArgTypes(arg).First(); if (arg_type != "") @@ -378,7 +378,7 @@ namespace BetterSecondBotShared.Json return reply; } - public static JsonConfig http_config_check(JsonConfig jsonConfig) + public static JsonConfig Http_config_check(JsonConfig jsonConfig) { if (helpers.notempty(jsonConfig.Security_WebUIKey) == true) { @@ -437,7 +437,7 @@ namespace BetterSecondBotShared.Json arg_value_default = arg_value_default.Replace("]", ""); arg_value_default = arg_value_default.Replace("\"", ""); } - reply = process_prop(reply, arg, arg_value_default); + reply = Process_prop(reply, arg, arg_value_default); } return reply; } diff --git a/BSBshared/Staic/LogFormater.cs b/BSBshared/Staic/LogFormater.cs index 0812387..64bd626 100644 --- a/BSBshared/Staic/LogFormater.cs +++ b/BSBshared/Staic/LogFormater.cs @@ -31,7 +31,7 @@ namespace BetterSecondBotShared.logs } public static string Debug(string message, bool send_to_console) { - return Add(message, ConsoleLogLogLevel.Debug, true); + return Add(message, ConsoleLogLogLevel.Debug, send_to_console); } public static string Warn(string message) { diff --git a/CLI/CliDocker.cs b/CLI/CliDocker.cs index 98e3ec5..18f6fe5 100644 --- a/CLI/CliDocker.cs +++ b/CLI/CliDocker.cs @@ -16,7 +16,7 @@ namespace BetterSecondBot Thread.Sleep(3000); LogFormater.Status("-> Getting config from Docker"); JsonConfig Config = MakeJsonConfig.FromENV(); - Config = MakeJsonConfig.http_config_check(Config); + Config = MakeJsonConfig.Http_config_check(Config); new CliExitOnLogout(Config); } } diff --git a/CLI/CliHardware.cs b/CLI/CliHardware.cs index d677637..84dbd0f 100644 --- a/CLI/CliHardware.cs +++ b/CLI/CliHardware.cs @@ -76,7 +76,7 @@ namespace BetterSecondBot } if(ok_to_try_start == true) { - Config = MakeJsonConfig.http_config_check(Config); + Config = MakeJsonConfig.Http_config_check(Config); new CliExitOnLogout(Config); } } diff --git a/CLI/HttpServer/SecondBotHttpServer.cs b/CLI/HttpServer/SecondBotHttpServer.cs index 33ff3a5..ec64309 100644 --- a/CLI/HttpServer/SecondBotHttpServer.cs +++ b/CLI/HttpServer/SecondBotHttpServer.cs @@ -19,7 +19,7 @@ using System.Web; namespace BetterSecondBot.HttpServer { - public class json_http_reply + public class Json_http_reply { public bool status; public string message; @@ -100,7 +100,7 @@ namespace BetterSecondBot.HttpServer protected async Task HandleIncomingConnections() { - webui myUI = new webui(Config,Bot); + Webui myUI = new Webui(Config,Bot); while (Bot.KillMe == false) { HttpListenerContext ctx = await listener.GetContextAsync().ConfigureAwait(true); @@ -114,22 +114,20 @@ namespace BetterSecondBot.HttpServer test = test.Replace(Config.Http_PublicUrl, ""); //rproxy weirdness - string use_http_url = Config.Http_PublicUrl.Replace("http://", ""); - use_http_url = Config.Http_PublicUrl.Replace("https://", ""); - test = test.Replace(":" + Config.Http_Port.ToString(), ""); - test = test.Replace(use_http_url, ""); - test = test.Replace("https://", ""); - test = test.Replace("http://", ""); - + test = test.Replace(Config.Http_PublicUrl, ""); + Config.Http_PublicUrl = Config.Http_PublicUrl.Replace("http://", ""); + Config.Http_PublicUrl = Config.Http_PublicUrl.Replace("https://", ""); + test = test.Replace(Config.Http_PublicUrl, ""); + test = test.Replace(":" + Config.Http_Port.ToString(), ""); } - json_http_reply reply = new json_http_reply(); + Json_http_reply reply = new Json_http_reply(); List http_args = test.Split('/', StringSplitOptions.RemoveEmptyEntries).ToList(); byte[] data; resp.StatusCode = 200; resp.ContentType = "text/html"; if (req.HttpMethod == "GET") { - KeyValuePair replydata = myUI.Get_Process(req, resp, http_args); + KeyValuePair replydata = myUI.Get_Process(resp, http_args); if (replydata.Value != null) { resp.ContentType = replydata.Key; @@ -166,7 +164,7 @@ namespace BetterSecondBot.HttpServer } } resp.StatusCode = 200; - if (myUI.Post_process(reply, req, resp, http_args, post_args) == true) + if (myUI.Post_process(reply, resp, http_args, post_args) == true) { bool accept_request = false; string why_request_failed = "Bad signing request"; diff --git a/CLI/HttpWebUi/webui.cs b/CLI/HttpWebUi/webui.cs index 66e925d..a58463d 100644 --- a/CLI/HttpWebUi/webui.cs +++ b/CLI/HttpWebUi/webui.cs @@ -15,27 +15,26 @@ using System.Threading; namespace BetterSecondBot.HttpWebUi { - public class webui + public class Webui { - JsonConfig siteconfig; - SecondBot bot; - Dictionary vaildlogincookies = new Dictionary(); - public webui(JsonConfig setconfig, SecondBot setbot) + private JsonConfig siteconfig; + private SecondBot bot; + private Dictionary vaildlogincookies = new Dictionary(); + public Webui(JsonConfig setconfig, SecondBot setbot) { bot = setbot; siteconfig = setconfig; } - protected KeyValuePair logincookievaild(HttpListenerRequest reqs, HttpListenerResponse resp) + protected KeyValuePair Logincookievaild(HttpListenerResponse resp) { - return logincookievaild(reqs, resp, false); + return Logincookievaild(resp, false); } - protected KeyValuePair logincookievaild(HttpListenerRequest reqs, HttpListenerResponse resp, bool force_logout) + protected KeyValuePair Logincookievaild(HttpListenerResponse resp, bool force_logout) { foreach (Cookie C in resp.Cookies) { if (C.Name == "logincookie") { - Cookie old = C; if (force_logout == true) { if (vaildlogincookies.ContainsKey(C.Value) == true) @@ -61,7 +60,7 @@ namespace BetterSecondBot.HttpWebUi } return new KeyValuePair(false, false); } - public bool Post_process(json_http_reply reply, HttpListenerRequest reqs, HttpListenerResponse resp, List args, Dictionary post_args) + public bool Post_process(Json_http_reply reply, HttpListenerResponse resp, List args, Dictionary post_args) { bool processed = false; if (args != null) @@ -82,7 +81,7 @@ namespace BetterSecondBot.HttpWebUi { area = args[2]; } - KeyValuePair logincheck = logincookievaild(reqs, resp); + KeyValuePair logincheck = Logincookievaild(resp); if (logincheck.Key == false) { @@ -99,9 +98,11 @@ namespace BetterSecondBot.HttpWebUi newcookiecode = helpers.GetSHA1(siteconfig.Security_WebUIKey + helpers.UnixTimeNow().ToString() + new Random().Next(12345).ToString()); } vaildlogincookies.Add(newcookiecode, helpers.UnixTimeNow() + (5 * 60)); // auto logout after 5 mins - Cookie logincookie = new Cookie("logincookie", newcookiecode); - logincookie.Expires = DateTime.Now.AddDays(1); - logincookie.Path = "/"; + Cookie logincookie = new Cookie("logincookie", newcookiecode) + { + Expires = DateTime.Now.AddDays(1), + Path = "/" + }; resp.Cookies.Add(logincookie); Console.WriteLine("Cookie created: " + logincookie.Value + " <=> " + newcookiecode + ""); reply.message = "ok"; @@ -133,7 +134,7 @@ namespace BetterSecondBot.HttpWebUi // logged in if (mod == "logout") { - logincookievaild(reqs, resp, true); + Logincookievaild(resp, true); reply.message = "logged-out"; reply.redirect = "/"; reply.status = false; @@ -356,7 +357,7 @@ namespace BetterSecondBot.HttpWebUi // login expired reply.message = "login-expired"; reply.redirect = "/"; - logincookievaild(reqs, resp, true); + Logincookievaild(resp, true); } } } @@ -364,7 +365,7 @@ namespace BetterSecondBot.HttpWebUi } return !processed; } - public string html_logged_in(string mod, string area) + public string Html_logged_in(string mod, string area) { string layout = helpers.ReadResourceFile(Assembly.GetExecutingAssembly(), "sidemenu.layout"); Dictionary swaps = new Dictionary(); @@ -387,7 +388,6 @@ namespace BetterSecondBot.HttpWebUi loop++; } swaps.Add("html_menu", menu); - menu = ""; if (mod == "none") { pagecontent = "

Please select a menu item on the left

"; @@ -428,7 +428,7 @@ namespace BetterSecondBot.HttpWebUi } return layout; } - public string html_logged_out() + public string Html_logged_out() { string layout = helpers.ReadResourceFile(Assembly.GetExecutingAssembly(), "full.layout"); layout = layout.Replace("[[page_content]]", helpers.ReadResourceFile(Assembly.GetExecutingAssembly(), "login.block")); @@ -438,7 +438,7 @@ namespace BetterSecondBot.HttpWebUi layout = layout.Replace("[[html_title]]", siteconfig.Basic_BotUserName); return layout; } - public KeyValuePair Get_Process(HttpListenerRequest reqs, HttpListenerResponse resp, List args) + public KeyValuePair Get_Process(HttpListenerResponse resp, List args) { // get content @@ -467,18 +467,18 @@ namespace BetterSecondBot.HttpWebUi } } // get display - KeyValuePair logincheck = logincookievaild(reqs, resp); + KeyValuePair logincheck = Logincookievaild(resp); if (logincheck.Key == true) { if (logincheck.Value == false) { - logincookievaild(reqs, resp, true); + Logincookievaild(resp, true); } } - string reply_with = ""; + string reply_with; if (logincheck.Value == false) { - reply_with = html_logged_out(); + reply_with = Html_logged_out(); } else { @@ -495,13 +495,13 @@ namespace BetterSecondBot.HttpWebUi if (mod == "logout") { - logincookievaild(reqs, resp, true); - reply_with = html_logged_out(); + Logincookievaild(resp, true); + reply_with = Html_logged_out(); } else { // logged in - reply_with = html_logged_in(mod, area); + reply_with = Html_logged_in(mod, area); } } reply_with = reply_with.Replace("[[url_base]]", siteconfig.Http_PublicUrl); diff --git a/Core/Commands/Group/GroupAddRole.cs b/Core/Commands/Group/GroupAddRole.cs index 8c49196..1589060 100644 --- a/Core/Commands/Group/GroupAddRole.cs +++ b/Core/Commands/Group/GroupAddRole.cs @@ -65,9 +65,9 @@ namespace BSB.Commands.Group { if (UUID.TryParse(args[0], out UUID target_group) == true) { - if (UUID.TryParse(args[1], out UUID target_avatar) == true) + if (UUID.TryParse(args[1], out UUID _) == true) { - if (UUID.TryParse(args[2], out UUID target_role) == true) + if (UUID.TryParse(args[2], out UUID _) == true) { if (bot.MyGroups.ContainsKey(target_group) == true) { diff --git a/Core/Commands/Movement/RequestTeleport.cs b/Core/Commands/Movement/RequestTeleport.cs index e4a3ac8..eb347a3 100644 --- a/Core/Commands/Movement/RequestTeleport.cs +++ b/Core/Commands/Movement/RequestTeleport.cs @@ -14,7 +14,7 @@ namespace BSB.Commands.Movement { if(UUID.TryParse(args[0],out UUID avatar) == true) { - bot.add_uuid_to_teleport_list(avatar); + bot.Add_uuid_to_teleport_list(avatar); bot.GetClient.Self.SendTeleportLureRequest(avatar, "I would like to teleport to you"); return true; } diff --git a/Core/bottypes/Log2FileBot.cs b/Core/bottypes/Log2FileBot.cs index 040f1ed..b154555 100644 --- a/Core/bottypes/Log2FileBot.cs +++ b/Core/bottypes/Log2FileBot.cs @@ -45,10 +45,8 @@ namespace BSB.bottypes Rotate(logFilePath); - using (var sw = File.AppendText(logFilePath)) - { - sw.WriteLine(message); - } + using var sw = File.AppendText(logFilePath); + sw.WriteLine(message); } private void Rotate(string filePath) diff --git a/Core/bottypes/MessageSwitcherBot.cs b/Core/bottypes/MessageSwitcherBot.cs index 81c84d7..faa9baa 100644 --- a/Core/bottypes/MessageSwitcherBot.cs +++ b/Core/bottypes/MessageSwitcherBot.cs @@ -8,7 +8,7 @@ namespace BSB.bottypes { public abstract class MessageSwitcherBot : EventsBot { - string[] hard_blocked_agents = new string[] { "secondlife", "second life"}; + readonly string[] hard_blocked_agents = new string[] { "secondlife", "second life"}; protected override void ChatInputHandler(object sender, ChatEventArgs e) { bool fromme = false; @@ -90,8 +90,10 @@ namespace BSB.bottypes if (bits.Count > 2) { arg_signed_with = "|||"; - List newbits = new List(); - newbits.Add(bits[0]); + List newbits = new List + { + bits[0] + }; StringBuilder B = new StringBuilder(); int loop = 1; string addon = ""; @@ -111,7 +113,7 @@ namespace BSB.bottypes } else { - if (is_avatar_master(sender_name) == true) + if (Is_avatar_master(sender_name) == true) { CoreCommandLib(sender_uuid, true, bits.ElementAt(0), bits.ElementAt(1), "", arg_signed_with); }