Allow adding/removing/listing IRC controllers from in game only. (Thanks Rollir025)

This commit is contained in:
UnknownShadow200 2016-01-30 09:10:40 +11:00
parent 3133384af9
commit 42c32f6057
7 changed files with 149 additions and 93 deletions

View File

@ -132,6 +132,7 @@ namespace MCGalaxy
all.Add(new CmdInfected());
all.Add(new CmdInfo());
all.Add(new CmdInvincible());
all.Add(new CmdIrcControllers());
all.Add(new CmdJail());
all.Add(new CmdJoker());
all.Add(new CmdKick());

View File

@ -0,0 +1,74 @@
/*
Copyright 2015 MCGalaxy
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using System.Collections.Generic;
namespace MCGalaxy.Commands {
public sealed class CmdIrcControllers : Command {
public override string name { get { return "irccontrollers"; } }
public override string shortcut { get { return "ircctrl"; } }
public override string type { get { return CommandTypes.Moderation; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public CmdIrcControllers() { }
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }
string[] parts = message.Split(' ');
switch (parts[0].ToLower()) {
case "reload":
Server.ircControllers = PlayerList.Load("IRC_Controllers.txt", null);
Player.SendMessage(p, "IRC Controllers reloaded!");
break;
case "add":
if (parts.Length < 2) { Player.SendMessage(p, "You need to provide a name to add."); return; }
if (Server.ircControllers.Contains(parts[1])) {
Player.SendMessage(p, parts[1] + " is already an IRC controller."); return;
}
Server.ircControllers.Add(parts[1]);
Server.ircControllers.Save("IRC_Controllers.txt", true);
Player.SendMessage(p, parts[1] + " added to the IRC controller list.");
break;
case "remove":
if (parts.Length < 2) { Player.SendMessage(p, "You need to provide a name to remove."); return; }
if (!Server.ircControllers.Contains(parts[1])) {
Player.SendMessage(p, parts[1] + " is not an IRC controller."); return;
}
Server.ircControllers.Remove(parts[1]);
Server.ircControllers.Save("IRC_Controllers.txt", true);
Player.SendMessage(p, parts[1] + " removed from the IRC controller list.");
break;
case "list":
List<string> players = Server.ircControllers.All();
string names = String.Join(", ", players);
Player.SendMessage(p, "IRC controllers list:");
Player.SendMessage(p, names);
break;
}
}
public override void Help(Player p) {
Player.SendMessage(p, "/ircctrl <reload/add/remove/list> [name]");
}
}
}

View File

@ -1,39 +0,0 @@
/*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
namespace MCGalaxy.Commands
{
public sealed class CmdReloadControllers : Command
{
public override string name { get { return "reloadcontrollers"; } }
public override string shortcut { get { return "rlctl"; } }
public override string type { get { return CommandTypes.Moderation; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public CmdReloadControllers() { }
public override void Use(Player p, string message)
{
Server.ircControllers = PlayerList.Load("IRC_Controllers.txt", null);
Player.SendMessage(p, "IRC Controllers reloaded!");
}
public override void Help(Player p)
{
Player.SendMessage(p, "/reloadcontrollers - Reloads IRC Controllers.");
}
}
}

View File

@ -46,7 +46,7 @@ namespace MCGalaxy.Commands
}
Server.whiteList.Add(player);
Chat.GlobalMessageOps(p.color + p.prefix + p.name + Server.DefaultColor + " added &f" + player + Server.DefaultColor + " to the whitelist.");
Server.whiteList.Save("whitelist.txt");
Server.whiteList.Save("whitelist.txt", true);
Server.s.Log("WHITELIST: Added " + player);
break;
case "del":
@ -57,7 +57,7 @@ namespace MCGalaxy.Commands
}
Server.whiteList.Remove(player);
Chat.GlobalMessageOps(p.color + p.prefix + p.name + Server.DefaultColor + " removed &f" + player + Server.DefaultColor + " from the whitelist.");
Server.whiteList.Save("whitelist.txt");
Server.whiteList.Save("whitelist.txt", true);
Server.s.Log("WHITELIST: Removed " + player);
break;
case "list":

View File

@ -42,7 +42,10 @@ namespace MCGalaxy {
this.channel = channel.Trim(); this.opchannel = opchannel.Trim(); this.nick = nick.Replace(" ", ""); this.server = server;
banCmd = new List<string>();
banCmd.Add("resetbot");
banCmd.Add("resetirc");
banCmd.Add("oprules");
banCmd.Add("irccontrollers");
banCmd.Add("ircctrl");
if (Server.irc) {
@ -167,7 +170,7 @@ namespace MCGalaxy {
void Listener_OnPrivate(UserInfo user, string message) {
message = Colors.IrcToMinecraftColors(message);
message = CP437Reader.ConvertToRaw(message);
string[] parts = message.Split(trimChars, 3);
string[] parts = message.Split(trimChars, 2);
string ircCmd = parts[0].ToLower();
if (ircCmd == ".who" || ircCmd == ".players") {
try {
@ -179,14 +182,14 @@ namespace MCGalaxy {
}
if (!Server.ircControllers.Contains(user.Nick)) { Pm(user.Nick, "You are not an IRC controller!"); return; }
if (message.Split(' ')[0] == "resetbot" || banCmd.Contains(message.Split(' ')[0])) { Pm(user.Nick, "You cannot use this command from IRC!"); return; }
if (banCmd.Contains(ircCmd)) { Pm(user.Nick, "You cannot use this command from IRC!"); return; }
if (Player.CommandHasBadColourCodes(null, message)) { Pm(user.Nick, "Your command had invalid color codes!"); return; }
Command cmd = Command.all.Find(message.Split(' ')[0]);
Command cmd = Command.all.Find(ircCmd);
if (cmd != null) {
Server.s.Log("IRC Command: /" + message);
usedCmd = user.Nick;
try { cmd.Use(new Player("IRC"), message.Split(' ').Length > 1 ? message.Substring(message.IndexOf(' ')).Trim() : ""); }
try { cmd.Use(new Player("IRC"), parts.Length > 1 ? parts[1] : ""); }
catch { Pm(user.Nick, "Failed command!"); }
usedCmd = "";
}
@ -195,8 +198,8 @@ namespace MCGalaxy {
}
void Listener_OnPublic(UserInfo user, string channel, string message) {
message = Colors.IrcToMinecraftColors(message);
message = CP437Reader.ConvertToRaw(message);
message = Colors.IrcToMinecraftColors(message);
message = CP437Reader.ConvertToRaw(message);
string[] parts = message.Split(trimChars, 3);
string ircCmd = parts[0].ToLower();
if (ircCmd == ".who" || ircCmd == ".players") {
@ -223,7 +226,7 @@ namespace MCGalaxy {
Server.IRC.Say("You must be at least a half-op on the channel to use commands from IRC."); return;
}
string cmdName = parts.Length >= 2 ? parts[1] : "";
string cmdName = parts.Length >= 2 ? parts[1].ToLower() : "";
if (banCmd.Contains(cmdName)) {
Server.IRC.Say("You are not allowed to use this command from IRC."); return;
}

View File

@ -246,6 +246,7 @@
<Compile Include="Commands\Moderation\CmdHacks.cs" />
<Compile Include="Commands\Moderation\CmdHide.cs" />
<Compile Include="Commands\Moderation\CmdHighlight.cs" />
<Compile Include="Commands\Moderation\CmdIrcControllers.cs" />
<Compile Include="Commands\Moderation\CmdJail.cs" />
<Compile Include="Commands\Moderation\CmdJoker.cs" />
<Compile Include="Commands\Moderation\CmdKick.cs" />
@ -269,7 +270,6 @@
<Compile Include="Commands\Moderation\CmdPUnload.cs" />
<Compile Include="Commands\Moderation\CmdRankInfo.cs" />
<Compile Include="Commands\Moderation\CmdReferee.cs" />
<Compile Include="Commands\Moderation\CmdReloadControllers.cs" />
<Compile Include="Commands\Moderation\CmdRenameLvl.cs" />
<Compile Include="Commands\Moderation\CmdResetBot.cs" />
<Compile Include="Commands\Moderation\CmdRestart.cs" />

View File

@ -1,62 +1,79 @@
/*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System.IO;
using System.Collections.Generic;
namespace MCGalaxy
{
public sealed class PlayerList
{
//public string name;
namespace MCGalaxy {
public sealed class PlayerList {
public Group group;
List<string> players = new List<string>();
readonly object locker = new object();
public PlayerList() { }
public void Add(string p) { players.Add(p.ToLower()); }
public bool Remove(string p)
{
return players.Remove(p.ToLower());
public void Add(string p) {
lock (locker)
players.Add(p.ToLower());
}
public bool Contains(string p) { return players.Contains(p.ToLower()); }
public List<string> All() { return new List<string>(players); }
public void Save(string path) { Save(path, true); }
public void Save() {
Save(group.fileName);
public bool Remove(string p) {
lock (locker)
return players.Remove(p.ToLower());
}
public void Save(string path, bool console)
{
StreamWriter file = File.CreateText("ranks/" + path);
players.ForEach(delegate(string p) { file.WriteLine(p); });
file.Close(); if (console) { Server.s.Log("SAVED: " + path); }
public bool Contains(string p) {
lock (locker)
return players.Contains(p.ToLower());
}
public static PlayerList Load(string path, Group groupName)
{
if (!Directory.Exists("ranks")) { Directory.CreateDirectory("ranks"); }
public List<string> All() {
lock (locker)
return new List<string>(players);
}
public void Save() { Save(group.fileName, true); }
public void Save(string path, bool console) {
using (StreamWriter w = File.CreateText("ranks/" + path)) {
lock (locker) {
foreach (string p in players)
w.WriteLine(p);
}
}
if (console)
Server.s.Log("SAVED: " + path);
}
public static PlayerList Load(string path, Group groupName) {
if (!Directory.Exists("ranks"))
Directory.CreateDirectory("ranks");
path = "ranks/" + path;
PlayerList list = new PlayerList();
list.group = groupName;
if (File.Exists(path))
{
if (File.Exists(path)) {
foreach (string line in File.ReadAllLines(path)) { list.Add(line); }
}
else
{
} else {
File.Create(path).Close();
Server.s.Log("CREATED NEW: " + path);
} return list;
}
return list;
}
}
}