Make /ban /unban and /setrank use the same rank changing method.

This commit is contained in:
UnknownShadow200 2016-08-02 20:17:43 +10:00
parent c2a318ea1d
commit 93b70cbebc
5 changed files with 85 additions and 71 deletions

View File

@ -60,18 +60,12 @@ namespace MCGalaxy.Commands.Moderation {
banMsg = who.ColoredName + " %Swas &8banned %Sby " + banner + "%S." + banReason;
Player.GlobalMessage(banMsg);
}
Entities.DespawnEntities(who, false);
who.group = Group.findPerm(LevelPermission.Banned);
who.color = who.group.color;
Entities.SpawnEntities(who, false);
who.color = "";
}
Ban.DeleteBan(target.ToLower());
string oldgroup = group.name;
Group.findPerm(LevelPermission.Banned).playerList.Add(target);
Ban.BanPlayer(p, target, reason, stealth, oldgroup);
Group.findPerm(LevelPermission.Banned).playerList.Save();
Ban.DeleteBan(target);
Ban.BanPlayer(p, target, reason, stealth, group.name);
RankCmd.ChangeRank(target, group, Group.findPerm(LevelPermission.Banned), who);
if (args.Length == 1) Player.AddNote(target, p, "B");
else Player.AddNote(target, p, "B", args[1]);
@ -86,9 +80,6 @@ namespace MCGalaxy.Commands.Moderation {
if (p != null && group.Permission >= p.Rank) {
MessageTooHighRank(p, "ban", false); return false;
}
group.playerList.Remove(name);
group.playerList.Save();
return true;
}

View File

@ -42,71 +42,53 @@ namespace MCGalaxy.Commands.Moderation {
string reason = args.Length > 2 ? args[2] : null, rankMsg = null;
Player who = PlayerInfo.Find(name);
if (who == null) {
Group group = Group.findPlayerGroup(name);
Group newRank = TargetRank(p, rank.ToLower(), group);
if (newRank == null) return;
if (who == p && who != null) { Player.Message(p, "Cannot change your own rank."); return; }
if (who != null) name = who.name;
if (!ChangeRank(name, group, newRank, null, p, ref reason)) return;
Group curRank = who != null ? who.group : PlayerInfo.GetGroup(name);
Group newRank = TargetRank(p, rank.ToLower(), curRank);
if (newRank == null) return;
if (!ChangeRank(name, curRank, newRank, who, p, ref reason)) return;
if (who == null) {
rankMsg = name + " &f(offline)%S's rank was set to " + newRank.ColoredName + "%S. (" + reason + "%S)";
Player.GlobalMessage(rankMsg);
} else if (who == p) {
Player.Message(p, "Cannot change your own rank."); return;
} else {
Group newRank = TargetRank(p, rank.ToLower(), who.group);
if (newRank == null) return;
if (!ChangeRank(who.name, who.group, newRank, who, p, ref reason)) return;
rankMsg = who.ColoredName + "%S's rank was set to " + newRank.ColoredName + "%S. (" + reason + "%S)";
Player.GlobalMessage(rankMsg);
Entities.DespawnEntities(who, false);
if (who.color == "" || who.color == who.group.color)
who.color = newRank.color;
who.group = newRank;
who.SetPrefix();
who.SendMessage("You are now ranked " + newRank.ColoredName + "%S, type /help for your new set of commands.");
who.SendUserType(Block.canPlace(who.Rank, Block.blackrock));
Entities.SpawnEntities(who, false);
}
RankCmd.ChangeRank(name, curRank, newRank, who);
WriteRankInfo(p, name, newRank, curRank, reason);
Server.IRC.Say(rankMsg);
}
bool ChangeRank(string name, Group group, Group newRank, Player who, Player p, ref string reason) {
bool ChangeRank(string name, Group curRank, Group newRank,
Player who, Player p, ref string reason) {
Group banned = Group.findPerm(LevelPermission.Banned);
if (reason == null) {
reason = newRank.Permission >= group.Permission ?
reason = newRank.Permission >= curRank.Permission ?
Server.defaultPromoteMessage : Server.defaultDemoteMessage;
}
if (group == banned || newRank == banned) {
Player.Message(p, "Cannot change the rank to or from \"" + banned.name + "\"."); return false;
if (curRank == banned || newRank == banned) {
Player.Message(p, "Cannot change the rank to or from \"{0}\".", banned.name); return false;
}
if (p != null && (group.Permission >= p.Rank || newRank.Permission >= p.Rank)) {
if (p != null && (curRank.Permission >= p.Rank || newRank.Permission >= p.Rank)) {
MessageTooHighRank(p, "change the rank of", false); return false;
}
if (p != null && (newRank.Permission >= p.Rank)) {
if (p != null && newRank.Permission >= p.Rank) {
Player.Message(p, "Cannot change the rank of a player to a rank equal or higher to yours."); return false;
}
if (who != null) {
Group.because(who, newRank);
if (Group.cancelrank) {
Group.cancelrank = false; return false;
}
}
Server.reviewlist.Remove(name);
group.playerList.Remove(name);
group.playerList.Save();
newRank.playerList.Add(name);
newRank.playerList.Save();
WriteRankInfo(p, name, newRank, group, reason);
if (who == null) return true;
Group.because(who, newRank);
if (Group.cancelrank) { Group.cancelrank = false; return false; }
return true;
}
static void WriteRankInfo(Player p, string name, Group newRank, Group group, string reason) {
static void WriteRankInfo(Player p, string name, Group newRank, Group oldRank, string reason) {
string year = DateTime.Now.Year.ToString();
string month = DateTime.Now.Month.ToString();
string day = DateTime.Now.Day.ToString();
@ -115,18 +97,18 @@ namespace MCGalaxy.Commands.Moderation {
string assigner = p == null ? "(console)" : p.name;
string line = name + " " + assigner + " " + minute + " " + hour + " " + day + " " + month
+ " " + year + " " + newRank.name + " " + group.name + " " + reason.Replace(" ", "%20");
+ " " + year + " " + newRank.name + " " + oldRank.name + " " + reason.Replace(" ", "%20");
Server.RankInfo.Append(line);
}
static Group TargetRank(Player p, string name, Group curGroup) {
if (name == "+up") return NextRankUp(p, curGroup);
if (name == "-down") return NextRankDown(p, curGroup);
static Group TargetRank(Player p, string name, Group curRank) {
if (name == "+up") return NextRankUp(p, curRank);
if (name == "-down") return NextRankDown(p, curRank);
return Group.FindMatches(p, name);
}
static Group NextRankDown(Player p, Group curGroup) {
int index = Group.GroupList.IndexOf(curGroup);
static Group NextRankDown(Player p, Group curRank) {
int index = Group.GroupList.IndexOf(curRank);
if (index > 0) {
Group next = Group.GroupList[index - 1];
if (next.Permission > LevelPermission.Banned) return next;
@ -134,8 +116,8 @@ namespace MCGalaxy.Commands.Moderation {
Player.Message(p, "No lower ranks exist"); return null;
}
static Group NextRankUp(Player p, Group curGroup) {
int index = Group.GroupList.IndexOf(curGroup);
static Group NextRankUp(Player p, Group curRank) {
int index = Group.GroupList.IndexOf(curRank);
if (index < Group.GroupList.Count - 1) {
Group next = Group.GroupList[index + 1];
if (next.Permission < LevelPermission.Nobody) return next;

View File

@ -1,7 +1,7 @@
/*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
Dual-licensed under the Educational Community License, Version 2.0 and
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
@ -15,7 +15,7 @@
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
namespace MCGalaxy.Commands {
namespace MCGalaxy.Commands.Moderation {
public sealed class CmdUnban : Command {
public override string name { get { return "unban"; } }
public override string shortcut { get { return ""; } }
@ -65,15 +65,9 @@ namespace MCGalaxy.Commands {
Server.IRC.Say(name + " was unbanned by " + src + ".");
Ban.UnbanPlayer(p, name, reason);
Group.findPerm(LevelPermission.Banned).playerList.Remove(name);
Group.findPerm(LevelPermission.Banned).playerList.Save();
Group banned = Group.findPerm(LevelPermission.Banned);
Player who = PlayerInfo.Find(name);
if (who != null) {
who.group = Group.standard; who.color = who.group.color;
Entities.GlobalDespawn(who, true);
Entities.GlobalSpawn(who, true);
}
RankCmd.ChangeRank(name, banned, Group.standard, who, false);
string ip = PlayerInfo.FindIP(name);
if (ip != null && Server.bannedIP.Contains(ip))

View File

@ -0,0 +1,46 @@
/*
Copyright 2015 MCGalaxy team
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.IO;
namespace MCGalaxy.Commands.Moderation {
internal static class RankCmd {
internal static void ChangeRank(string name, Group oldRank, Group newRank,
Player who, bool saveToNewRank = true) {
Server.reviewlist.Remove(name);
oldRank.playerList.Remove(name);
oldRank.playerList.Save();
if (saveToNewRank) {
newRank.playerList.Add(name);
newRank.playerList.Save();
}
if (who == null) return;
Entities.DespawnEntities(who, false);
if (who.color == "" || who.color == who.group.color)
who.color = newRank.color;
who.group = newRank;
who.SetPrefix();
who.SendUserType(Block.canPlace(who.Rank, Block.blackrock));
Entities.SpawnEntities(who, false);
}
}
}

View File

@ -331,6 +331,7 @@
<Compile Include="Commands\Moderation\CmdXJail.cs" />
<Compile Include="Commands\Moderation\CmdXmute.cs" />
<Compile Include="Commands\Moderation\CmdZone.cs" />
<Compile Include="Commands\Moderation\RankCmd.cs" />
<Compile Include="Commands\other\CmdAgree.cs" />
<Compile Include="Commands\other\CmdAscend.cs" />
<Compile Include="Commands\other\CmdBack.cs" />