Clean up /temprank and /deltemprank, make them work with offline players.

This commit is contained in:
UnknownShadow200 2016-03-09 14:43:40 +11:00
parent 3fc5bb1b75
commit 166e5dfadf
5 changed files with 50 additions and 41 deletions

View File

@ -12,6 +12,7 @@ BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using System;
using System.IO; using System.IO;
using System.Text; using System.Text;
@ -23,27 +24,27 @@ namespace MCGalaxy.Commands {
public override string type { get { return CommandTypes.Moderation; } } public override string type { get { return CommandTypes.Moderation; } }
public override bool museumUsable { get { return true; } } public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
const StringComparison comp = StringComparison.OrdinalIgnoreCase;
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
string alltext = File.ReadAllText("text/tempranks.txt"); bool assigned = false;
if (!alltext.Contains(message)) { StringBuilder all = new StringBuilder();
Player.SendMessage(p, "&cPlayer &a" + message + "&c Has not been assigned a temporary rank. Cannot unnasign."); Player who = PlayerInfo.Find(message);
return;
foreach (string line in File.ReadAllLines("text/tempranks.txt")) {
if (!line.StartsWith(message, comp)) { all.AppendLine(line); continue; }
string[] parts = line.Split(' ');
Group newgroup = Group.Find(parts[2]);
Command.all.Find("setrank").Use(null, message + " " + newgroup.name + " temp rank unassigned");
Player.SendMessage(p, "&eTemp rank of &a" + message + "&e has been unassigned");
if (who != null)
Player.SendMessage(who, "&eYour temp rank has been unassigned");
assigned = true;
} }
StringBuilder all = new StringBuilder(); if (!assigned) {
Player who = Player.Find(message); Player.SendMessage(p, "&a" + message + "&c has not been assigned a temp rank."); return;
foreach (string line in File.ReadAllLines("text/tempranks.txt")) {
if (line.Contains(message)) {
string group = line.Split(' ')[2];
Group newgroup = Group.Find(group);
Command.all.Find("setrank").Use(null, message + " " + newgroup.name + " temp rank unassigned");
Player.SendMessage(p, "&eTemporary rank of &a" + message + "&e has been unassigned");
if (who != null)
Player.SendMessage(who, "&eYour temporary rank has been unassigned");
} else {
all.AppendLine(line);
}
} }
File.WriteAllText("text/tempranks.txt", all.ToString()); File.WriteAllText("text/tempranks.txt", all.ToString());
} }

View File

@ -24,51 +24,58 @@ namespace MCGalaxy.Commands {
public override string type { get { return CommandTypes.Moderation; } } public override string type { get { return CommandTypes.Moderation; } }
public override bool museumUsable { get { return true; } } public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
const StringComparison comp = StringComparison.OrdinalIgnoreCase;
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
string[] args = message.Split(' '); string[] args = message.Split(' ');
if (args.Length < 3) { Help(p); return; } if (args.Length < 3) { Help(p); return; }
string player = args[0], rank = args[1], period = args[2]; string player = args[0], rank = args[1], period = args[2];
Player who = PlayerInfo.Find(player); Player who = PlayerInfo.Find(player);
if (who == null) { Player.SendMessage(p, "&cPlayer &a" + player + "&c not found."); return; } if (who == null) {
OfflinePlayer pInfo = PlayerInfo.FindOffline(player);
Group newRank = Group.Find(rank); if (pInfo == null) { Player.SendMessage(p, "&cPlayer &a" + player + "&c not found."); return; }
if (newRank == null) { player = pInfo.name;
Player.SendMessage(p, "&cRank &a" + rank + "&c does not exist."); return; } else {
player = who.name;
} }
Group group = Group.Find(rank);
if (group == null) { Player.SendMessage(p, "&cRank &a" + rank + "&c does not exist."); return; }
int periodTime; int periodTime;
if (!Int32.TryParse(period, out periodTime)) { if (!Int32.TryParse(period, out periodTime)) {
Player.SendMessage(p, "&cThe period needs to be a number."); return; Player.SendMessage(p, "&cThe period needs to be a number."); return;
} }
string tempRanks = File.ReadAllText("text/tempranks.txt"); foreach (string line in File.ReadAllLines("text/tempranks.txt")) {
if (tempRanks.Contains(player)) { if (line.StartsWith(player, comp)) {
Player.SendMessage(p, "&cThe player already has a temporary rank assigned!"); return; Player.SendMessage(p, "&cThe player already has a temporary rank assigned!"); return;
}
} }
if (p != null && p == who) {
if (p != null && who != null && p == who) {
Player.SendMessage(p, "&cYou cannot assign yourself a temporary rank."); return; Player.SendMessage(p, "&cYou cannot assign yourself a temporary rank."); return;
} }
if (p != null && who.group.Permission >= p.group.Permission) { Group pGroup = who != null ? who.group : Group.findPlayerGroup(player);
if (p != null && pGroup.Permission >= p.group.Permission) {
Player.SendMessage(p, "Cannot change the temporary rank of someone equal or higher to yourself."); return; Player.SendMessage(p, "Cannot change the temporary rank of someone equal or higher to yourself."); return;
} }
if (p != null && newRank.Permission >= p.group.Permission) { if (p != null && group.Permission >= p.group.Permission) {
Player.SendMessage(p, "Cannot change the temporary rank to a higher rank than yourself."); return; Player.SendMessage(p, "Cannot change the temporary rank to a higher rank than yourself."); return;
} }
DateTime now = DateTime.Now; DateTime now = DateTime.Now;
string oldrank = who.group.name;
string assigner = p == null ? "Console" : p.name; string assigner = p == null ? "Console" : p.name;
using (StreamWriter sw = new StreamWriter("text/tempranks.txt", true)) using (StreamWriter sw = new StreamWriter("text/tempranks.txt", true))
sw.WriteLine(who.name + " " + rank + " " + oldrank + " " + period + " " + now.Minute + " " + sw.WriteLine(player + " " + rank + " " + pGroup.name + " " + period + " " + now.Minute + " " +
now.Hour + " " + now.Day + " " + now.Month + " " + now.Year + " " + assigner); now.Hour + " " + now.Day + " " + now.Month + " " + now.Year + " " + assigner);
Command.all.Find("setrank").Use(null, who.name + " " + newRank.name + " assigning temp rank"); Command.all.Find("setrank").Use(null, who.name + " " + group.name + " assigning temp rank");
Player.SendMessage(p, "Temporary rank (" + rank + ") assigned succesfully to " + player + " for " + period + " hours"); Player.SendMessage(p, "Temporary rank (" + rank + ") assigned succesfully to " + player + " for " + period + " hours");
Player.SendMessage(who, "Your Temporary rank (" + rank + ") is assigned succesfully for " + period + " hours"); Player.SendMessage(who, "Your Temporary rank (" + rank + ") is assigned succesfully for " + period + " hours");
} }
public override void Help(Player p) { public override void Help(Player p) {
Player.SendMessage(p, "/temprank <player> <rank> <period(hours)> - Sets a temporary rank for the specified player."); Player.SendMessage(p, "/temprank <player> <rank> <period(hours)> - Sets a temporary rank for the specified player.");
} }
} }
} }

View File

@ -1,7 +1,7 @@
/* /*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) 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 the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at

View File

@ -213,9 +213,9 @@ namespace MCGalaxy {
Server.s.Log("Iterations = " + numIterations); Server.s.Log("Iterations = " + numIterations);
for (int iter = 0; iter < numIterations; iter++) { for (int iter = 0; iter < numIterations; iter++) {
float theta = (float)(rand.NextDouble() * 360); float phi = (float)(rand.NextDouble() * 360);
float cosPhi = (float)Math.Cos(theta); float cosPhi = (float)Math.Cos(phi);
float sinPhi = (float)Math.Sin(theta); float sinPhi = (float)Math.Sin(phi);
float c = ((float)rand.NextDouble()) * 2 * d - d; float c = ((float)rand.NextDouble()) * 2 * d - d;
int index = 0; int index = 0;

View File

@ -16,10 +16,11 @@ permiusing MCGalaxy;ssions and limitations under the Licenses.
using System.IO; using System.IO;
namespace MCGalaxy { namespace MCGalaxy {
public static class Checktimer { public static class Checktimer {
static System.Timers.Timer t; static System.Timers.Timer t;
const StringComparison comp = StringComparison.OrdinalIgnoreCase;
public static void StartTimer() { public static void StartTimer() {
t = new System.Timers.Timer(); t = new System.Timers.Timer();
t.AutoReset = false; t.AutoReset = false;
@ -40,10 +41,10 @@ namespace MCGalaxy {
} }
public static void TRExpiryCheck() { public static void TRExpiryCheck() {
Player[] players = PlayerInfo.Online; Player[] players = PlayerInfo.Online;
foreach (Player p in players) { foreach (Player p in players) {
foreach (string line in File.ReadAllLines("text/tempranks.txt")) { foreach (string line in File.ReadAllLines("text/tempranks.txt")) {
if (!line.Contains(p.name)) continue; if (line.IndexOf(p.name, comp) < 0) continue;
string[] args = line.Split(' '); string[] args = line.Split(' ');
int period = Convert.ToInt32(args[3]); int period = Convert.ToInt32(args[3]);
@ -55,7 +56,7 @@ namespace MCGalaxy {
Player who = PlayerInfo.Find(args[0]); Player who = PlayerInfo.Find(args[0]);
DateTime expire = new DateTime(years, months, days, hours, minutes, 0) DateTime expire = new DateTime(years, months, days, hours, minutes, 0)
.AddHours(Convert.ToDouble(period)); .AddHours(Convert.ToDouble(period));
if (DateTime.Now >= expire) if (DateTime.Now >= expire)
Command.all.Find("deltemprank").Use(null, who.name); Command.all.Find("deltemprank").Use(null, who.name);
} }