Make loginmsg/logoutmsg require an extra permission to change loginmsg/logoutmsg of other players. (Thanks goodlyay)

This commit is contained in:
UnknownShadow200 2016-09-10 22:10:37 +10:00
parent e2404c46fa
commit bd81627611
7 changed files with 73 additions and 70 deletions

View File

@ -29,8 +29,7 @@ namespace MCGalaxy.Commands {
}
public override CommandAlias[] Aliases {
get { return new[] { new CommandAlias("colour"), new CommandAlias("xcolor", "-own") }; }
}
}
public override void Use(Player p, string message) { UseBotOrPlayer(p, message, "color"); }
protected override void SetBotData(Player p, PlayerBot bot, string[] args) {

View File

@ -1,6 +1,4 @@
/*
Written By Jack1312
Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and
@ -20,32 +18,31 @@
using System.IO;
namespace MCGalaxy.Commands {
public sealed class CmdLoginMessage : Command {
public sealed class CmdLoginMessage : EntityPropertyCmd {
public override string name { get { return "loginmessage"; } }
public override string shortcut { get { return "loginmsg"; } }
public override string type { get { return CommandTypes.Chat; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public CmdLoginMessage() { }
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }
string[] args = message.SplitSpaces(2);
if (args.Length < 2) { Help(p); return; }
string target = PlayerInfo.FindMatchesPreferOnline(p, args[0]);
if (target == null) return;
PlayerDB.SetLoginMessage(target, args[1]);
Player.Message(p, "The login message of {0} %Shas been changed to: {1}",
PlayerInfo.GetColoredName(p, target), args[1]);
string changer = p == null ? "(console)" : p.name;
Server.s.Log(changer + " changed " + target + "'s login message to: " + args[1]);
public override CommandPerm[] ExtraPerms {
get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the login message of others") }; }
}
public override void Use(Player p, string message) { UsePlayer(p, message, "login message"); }
protected override void SetPlayerData(Player p, Player who, string[] args) {
if (args.Length == 1) {
string path = PlayerDB.LoginPath(who.name);
if (File.Exists(path)) File.Delete(path);
Player.Message(p, "The login message of {0} %Shas been removed.",
who.ColoredName);
} else {
PlayerDB.SetLoginMessage(who.name, args[1]);
Player.Message(p, "The login message of {0} %Shas been changed to: {1}",
who.ColoredName, args[1]);
}
}
public override void Help(Player p) {
Player.Message(p, "%T/loginmessage [Player] [Message]");
Player.Message(p, "%T/loginmessage [player] [message]");
Player.Message(p, "%HSets the login message shown for that player.");
}
}

View File

@ -1,6 +1,4 @@
/*
Written By Jack1312
Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and
@ -16,37 +14,36 @@
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;
namespace MCGalaxy.Commands {
public sealed class CmdLogoutMessage : Command {
public sealed class CmdLogoutMessage : EntityPropertyCmd {
public override string name { get { return "logoutmessage"; } }
public override string shortcut { get { return "logoutmsg"; } }
public override string type { get { return CommandTypes.Chat; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public CmdLogoutMessage() { }
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }
string[] args = message.SplitSpaces(2);
if (args.Length < 2) { Help(p); return; }
string target = PlayerInfo.FindMatchesPreferOnline(p, args[0]);
if (target == null) return;
PlayerDB.SetLogoutMessage(target, args[1]);
Player.Message(p, "The logout message of {0} %Shas been changed to: {1}",
PlayerInfo.GetColoredName(p, target), args[1]);
string changer = p == null ? "(console)" : p.name;
Server.s.Log(changer + " changed " + name + "'s logout message to:");
public override CommandPerm[] ExtraPerms {
get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the logout message of others") }; }
}
public override void Use(Player p, string message) { UsePlayer(p, message, "logout message"); }
protected override void SetPlayerData(Player p, Player who, string[] args) {
if (args.Length == 1) {
string path = PlayerDB.LogoutPath(who.name);
if (File.Exists(path)) File.Delete(path);
Player.Message(p, "The logout message of {0} %Shas been removed.",
who.ColoredName);
} else {
PlayerDB.SetLogoutMessage(who.name, args[1]);
Player.Message(p, "The logout message of {0} %Shas been changed to: {1}",
who.ColoredName, args[1]);
}
}
public override void Help(Player p) {
Player.Message(p, "%T/logoutmessage [Player] [Message]");
public override void Help(Player p) {
Player.Message(p, "%T/logoutmessage [player] [message]");
Player.Message(p, "%HSets the logout message shown for that player.");
}
}
}
}

View File

@ -35,11 +35,8 @@ namespace MCGalaxy.Commands {
Group grp = Group.FindMatches(p, rank);
if (grp == null) return;
Player[] players = PlayerInfo.Online.Items;
string toSend = p.color + p.name + ": %S" + text.Trim();
foreach (Player pl in players) {
if (pl.group.name == grp.name) pl.SendMessage(toSend);
}
Chat.MessageWhere("{0}: %S{1}", pl => pl.group == grp,
p.DisplayName, text.Trim());
}
public override void Help(Player p) {

View File

@ -17,7 +17,7 @@
*/
using MCGalaxy.SQL;
namespace MCGalaxy.Commands {
namespace MCGalaxy.Commands {
public class CmdTColor : EntityPropertyCmd {
public override string name { get { return "tcolor"; } }
public override string shortcut { get { return ""; } }
@ -29,22 +29,21 @@ namespace MCGalaxy.Commands {
public override CommandAlias[] Aliases {
get { return new[] { new CommandAlias("tcolour"), new CommandAlias("xtcolor", "-own") }; }
}
public override void Use(Player p, string message) { UsePlayer(p, message, "title color"); }
protected override void SetPlayerData(Player p, Player who, string[] args) {
if (args.Length == 1) {
string color = "";
if (args.Length == 1) {
Player.SendChatFrom(who, who.ColoredName + " %Shad their title color removed.", false);
who.titlecolor = "";
Database.Execute("UPDATE Players SET title_color = '' WHERE Name = @0", who.name);
} else {
string color = Colors.Parse(args[1]);
color = Colors.Parse(args[1]);
if (color == "") { Player.Message(p, "There is no color \"" + args[1] + "\"."); return; }
else if (color == who.titlecolor) { Player.Message(p, who.DisplayName + " %Salready has that title color."); return; }
Player.SendChatFrom(who, who.ColoredName + " %Shad their title color changed to " + color + Colors.Name(color) + "%S.", false);
who.titlecolor = color;
Database.Execute("UPDATE Players SET title_color = @1 WHERE Name = @0", who.name, color);
Player.SendChatFrom(who, who.ColoredName + " %Shad their title color changed to " + color + Colors.Name(color) + "%S.", false);
}
who.titlecolor = color;
Database.Execute("UPDATE Players SET title_color = @1 WHERE Name = @0", who.name, color);
who.SetPrefix();
}

View File

@ -29,7 +29,6 @@ namespace MCGalaxy.Commands {
public override CommandAlias[] Aliases {
get { return new[] { new CommandAlias("xtitle", "-own") }; }
}
public override void Use(Player p, string message) { UsePlayer(p, message, "title"); }
protected override void SetPlayerData(Player p, Player who, string[] args) {

View File

@ -6,6 +6,19 @@ namespace MCGalaxy {
public static class PlayerDB {
public static string LoginPath(string name) {
return "text/login/" + name.ToLower() + ".txt";
}
public static string LogoutPath(string name) {
return "text/logout/" + name.ToLower() + ".txt";
}
public static string InfectPath(string name) {
return "text/infect/" + name.ToLower() + ".txt";
}
static char[] trimChars = {'='};
public static bool Load( Player p ) {
if (!File.Exists("players/" + p.name + "DB.txt")) return false;
@ -30,8 +43,9 @@ namespace MCGalaxy {
public static string GetLoginMessage(Player p) {
if (!Directory.Exists("text/login"))
Directory.CreateDirectory("text/login");
string path = "text/login/" + p.name.ToLower() + ".txt";
Directory.CreateDirectory("text/login");
string path = LoginPath(p.name);
if (File.Exists(path)) return CP437Reader.ReadAllText(path);
// Unix is case sensitive (older files used correct casing of name)
path = "text/login/" + p.name + ".txt";
@ -41,8 +55,9 @@ namespace MCGalaxy {
public static string GetLogoutMessage(Player p) {
if (p.name == null) return "disconnected";
if (!Directory.Exists("text/logout"))
Directory.CreateDirectory("text/logout");
string path = "text/logout/" + p.name.ToLower() + ".txt";
Directory.CreateDirectory("text/logout");
string path = LogoutPath(p.name);
if (File.Exists(path)) return CP437Reader.ReadAllText(path);
path = "text/logout/" + p.name + ".txt";
@ -50,23 +65,23 @@ namespace MCGalaxy {
}
public static void SetLoginMessage(string name, string value) {
CP437Writer.WriteAllText("text/login/" + name.ToLower() + ".txt", value);
CP437Writer.WriteAllText(LoginPath(name), value);
}
public static void SetLogoutMessage(string name, string value) {
CP437Writer.WriteAllText("text/logout/" + name.ToLower() + ".txt", value);
CP437Writer.WriteAllText(LogoutPath(name), value);
}
public static List<string> GetInfectMessages(Player p) {
if (p.name == null || !Directory.Exists("text/infect")) return null;
string path = "text/infect/" + p.name.ToLower() + ".txt";
string path = InfectPath(p.name);
return File.Exists(path) ? CP437Reader.ReadAllLines(path) : null;
}
public static void AppendInfectMessage(string name, string value) {
if (!Directory.Exists("text/infect"))
Directory.CreateDirectory("text/infect");
CP437Writer.AppendLine("text/infect/" + name.ToLower() + ".txt", value);
CP437Writer.AppendLine(InfectPath(name), value);
}
}
}