diff --git a/IRC/ForgeBot.cs b/IRC/ForgeBot.cs index bf9f5f703..f7512d904 100644 --- a/IRC/ForgeBot.cs +++ b/IRC/ForgeBot.cs @@ -35,7 +35,6 @@ namespace MCGalaxy { private string server; private bool reset = false; private byte retries = 0; - public string usedCmd = ""; Dictionary> users = new Dictionary>(); static char[] trimChars = { ' ' }; @@ -285,14 +284,15 @@ namespace MCGalaxy { Command cmd = Command.all.Find(ircCmd); if (cmd != null) { Server.s.Log("IRC Command: /" + message + " (by " + user.Nick + ")"); - usedCmd = user.Nick; string args = parts.Length > 1 ? parts[1] : ""; + Player p = MakeIRCPlayer(user.Nick); + try { - cmd.Use(new Player("IRC"), args); + if (!p.group.CanExecute(cmd)) { cmd.MessageCannotUse(p); return; } + cmd.Use(p, args); } catch (Exception e) { Pm(user.Nick, "CMD Error: " + e.ToString()); } - usedCmd = ""; } else Pm(user.Nick, "Unknown command!"); @@ -325,14 +325,15 @@ namespace MCGalaxy { Command cmd = Command.all.Find(cmdName); if (cmdName != "" && cmd != null) { Server.s.Log("IRC Command: /" + message.Replace(".x ", "") + " (by " + user.Nick + ")"); - usedCmd = ""; string args = parts.Length > 2 ? parts[2] : ""; + Player p = MakeIRCPlayer("#@public@#"); + try { - cmd.Use(new Player("IRC"), args); + if (!p.group.CanExecute(cmd)) { cmd.MessageCannotUse(p); return; } + cmd.Use(p, args); } catch (Exception e) { Say("CMD Error: " + e.ToString()); } - usedCmd = ""; } else { Say("Unknown command!"); } @@ -367,6 +368,15 @@ namespace MCGalaxy { return true; } + static Player MakeIRCPlayer(string ircNick) { + Player p = new Player("IRC"); + p.group = Group.findPerm(Server.ircControllerRank); + if (p.group == null) + p.group = Group.findPerm(LevelPermission.Nobody); + p.ircNick = ircNick; + p.color = "&a"; return p; + } + void Listener_OnRegistered() { Server.s.Log("Connected to IRC!"); reset = false; diff --git a/Network/Player.Networking.cs b/Network/Player.Networking.cs index 22680dd87..c81d4a91f 100644 --- a/Network/Player.Networking.cs +++ b/Network/Player.Networking.cs @@ -183,11 +183,11 @@ namespace MCGalaxy { storedHelp += message + "\r\n"; else Server.s.Log(message); - } else if (p.name == "IRC") { - if (String.IsNullOrEmpty(Server.IRC.usedCmd)) + } else if (p.ircNick != null) { + if (p.ircNick == "#@public@#") Server.IRC.Say(message, false, true); else - Server.IRC.Pm(Server.IRC.usedCmd, message); + Server.IRC.Pm(p.ircNick, message); } else { p.SendMessage(0, Server.DefaultColor + message, colorParse); } diff --git a/Player/Player.cs b/Player/Player.cs index c7b3fbb4d..5955f9aad 100644 --- a/Player/Player.cs +++ b/Player/Player.cs @@ -119,6 +119,7 @@ namespace MCGalaxy { public DateTime NextReviewTime, NextEat; public float ReachDistance = 5; public bool hackrank; + internal string ircNick; public string FullName { get { return color + prefix + DisplayName; } } @@ -167,8 +168,6 @@ namespace MCGalaxy { public int totalKicked = 0; public int overallDeath = 0; - public string savedcolor = ""; - public bool staticCommands = false; internal bool outdatedClient = false; // for ClassicalSharp 0.98.5, which didn't reload map for BlockDefinitions @@ -341,8 +340,9 @@ namespace MCGalaxy { //They would still have to do p.Dispose().. public Player(string playername) { name = playername; + truename = playername; + DisplayName = playername; SessionID = Interlocked.Increment(ref sessionCounter); - if (playername == "IRC") { group = Group.Find("nobody"); color = Colors.lime; } } public Player(Socket s) { @@ -350,15 +350,9 @@ namespace MCGalaxy { socket = s; ip = socket.RemoteEndPoint.ToString().Split(':')[0]; SessionID = Interlocked.Increment(ref sessionCounter); - - /*if (IPInPrivateRange(ip)) - exIP = ResolveExternalIP(ip); - else - exIP = ip;*/ - Server.s.Log(ip + " connected to the server."); - for ( byte i = 0; i < 128; ++i ) bindings[i] = i; + for (byte i = 0; i < 128; i++) bindings[i] = i; socket.BeginReceive(tempbuffer, 0, tempbuffer.Length, SocketFlags.None, new AsyncCallback(Receive), this); InitTimers(); diff --git a/Server/Server.cs b/Server/Server.cs index 92a3d231a..a23af2e1b 100644 --- a/Server/Server.cs +++ b/Server/Server.cs @@ -255,13 +255,15 @@ namespace MCGalaxy public static string ircPassword = ""; [ConfigEnum("irc-controller-verify", "IRC bot", null, IRCControllerVerify.HalfOp, typeof(IRCControllerVerify))] public static IRCControllerVerify IRCVerify = IRCControllerVerify.HalfOp; + [ConfigPerm("irc-controller-rank", "IRC bot", null, LevelPermission.Nobody)] + public static LevelPermission ircControllerRank = LevelPermission.Nobody; [ConfigBool("admin-verification", "Admin", null, true)] public static bool verifyadmins = true; [ConfigPerm("verify-admin-perm", "Admin", null, LevelPermission.Operator)] public static LevelPermission verifyadminsrank = LevelPermission.Operator; - [ConfigBool("restart-on-error", "Error handling", null, true)] + [ConfigBool("restart-on-error", "Error handling", null, true)] public static bool restartOnError = true; [ConfigInt("rplimit", "Other", null, 500, 0, 50000)] public static int rpLimit = 500;