ranks/agreed.txt now uses the standard ranks player list format, instead of its own hardcoded special way.

This commit is contained in:
UnknownShadow200 2016-06-16 23:01:28 +10:00
parent a793a164ba
commit 482e62d6a7
6 changed files with 64 additions and 68 deletions

View File

@ -30,40 +30,26 @@ namespace MCGalaxy.Commands
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
public CmdAgree() { } public CmdAgree() { }
public override void Use(Player p, string message) public override void Use(Player p, string message) {
{
if (Player.IsSuper(p)) { MessageInGameOnly(p); return; } if (Player.IsSuper(p)) { MessageInGameOnly(p); return; }
if (Server.agreetorulesonentry == false) if (!Server.agreetorulesonentry) {
{ Player.Message(p, "This command can only be used if agree-to-rules-on-entry is enabled."); return;
Player.Message(p, "This command can only be used if agree-to-rules-on-entry is enabled!");
return;
} }
var agreed = File.ReadAllText("ranks/agreed.txt");
if (p.hasreadrules == false) if (!p.hasreadrules) {
{ Player.Message(p, "&9You must read /rules before agreeing!"); return;
Player.Message(p, "&9You must read /rules before agreeing!");
return;
} }
if ((agreed+" ").Contains(" " + p.name.ToLower() + " ")) //Edited to prevent inner names from working. if (Server.agreed.Contains(p.name)) {
{ Player.Message(p, "You have already agreed to the rules!"); return;
Player.Message(p, "You have already agreed to the rules!");
return;
} }
p.agreed = true; p.agreed = true;
Player.Message(p, "Thank you for agreeing to follow the rules. You may now build and use commands!"); Player.Message(p, "Thank you for agreeing to follow the rules. You may now build and use commands!");
string playerspath = "ranks/agreed.txt"; Server.agreed.Add(p.name);
if (File.Exists(playerspath)) Server.agreed.Save(false);
{
//We don't want player "test" to have already agreed if "nate" and "stew" agrred.
// the preveious one, though, would put "natesteve" which also allows test
//There is a better way, namely regular expressions, but I'll worry about that later.
File.AppendAllText(playerspath, " " + p.name.ToLower()); //Ensures every name is seperated by a space.
} }
} public override void Help(Player p) {
public override void Help(Player p)
{
Player.Message(p, "/agree - Agree to the rules when entering the server"); Player.Message(p, "/agree - Agree to the rules when entering the server");
} }
} }

View File

@ -17,10 +17,8 @@
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.
*/ */
namespace MCGalaxy.Commands namespace MCGalaxy.Commands {
{ public sealed class CmdDisagree : Command {
public sealed class CmdDisagree : Command
{
public override string name { get { return "disagree"; } } public override string name { get { return "disagree"; } }
public override string shortcut { get { return ""; } } public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Other; } } public override string type { get { return CommandTypes.Other; } }
@ -28,24 +26,19 @@ namespace MCGalaxy.Commands
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
public CmdDisagree() { } public CmdDisagree() { }
public override void Use(Player p, string message) public override void Use(Player p, string message) {
{
if (Player.IsSuper(p)) { MessageInGameOnly(p); return; } if (Player.IsSuper(p)) { MessageInGameOnly(p); return; }
if (!Server.agreetorulesonentry) if (!Server.agreetorulesonentry) {
{
Player.Message(p, "This command can only be used if agree-to-rules-on-entry is enabled in the console!"); Player.Message(p, "This command can only be used if agree-to-rules-on-entry is enabled in the console!");
return; return;
} }
if (p.group.Permission > LevelPermission.Guest) if (p.group.Permission > LevelPermission.Guest) {
{ Player.Message(p, "Your awesomeness prevents you from using this command"); return;
Player.Message(p, "Your awesomeness prevents you from using this command");
return;
} }
p.Leave("If you don't agree with the rules, consider playing elsewhere."); p.Leave("If you don't agree with the rules, consider playing elsewhere.");
} }
public override void Help(Player p) public override void Help(Player p) {
{
Player.Message(p, "/disagree - Disagree to the rules when entering the server"); Player.Message(p, "/disagree - Disagree to the rules when entering the server");
} }
} }

View File

@ -552,15 +552,10 @@ namespace MCGalaxy {
CheckLoginJailed(); CheckLoginJailed();
CheckReviewList(); CheckReviewList();
if (Server.agreetorulesonentry) { if (Server.agreetorulesonentry && group.Permission == LevelPermission.Guest && !Server.agreed.Contains(name)) {
if (!File.Exists("ranks/agreed.txt"))
File.WriteAllText("ranks/agreed.txt", "");
var agreedFile = File.ReadAllText("ranks/agreed.txt");
if (group.Permission == LevelPermission.Guest && !agreedFile.Contains(this.name.ToLower())) {
SendMessage("&9You must read the &c/rules&9 and &c/agree&9 to them before you can build and use commands!"); SendMessage("&9You must read the &c/rules&9 and &c/agree&9 to them before you can build and use commands!");
agreed = false; agreed = false;
} }
}
if (Server.verifyadmins && group.Permission >= Server.verifyadminsrank) { if (Server.verifyadmins && group.Permission >= Server.verifyadminsrank) {
if (!Directory.Exists("extra/passwords") || !File.Exists("extra/passwords/" + this.name + ".dat")) if (!Directory.Exists("extra/passwords") || !File.Exists("extra/passwords/" + this.name + ".dat"))

View File

@ -27,6 +27,9 @@ namespace MCGalaxy {
List<string> players = new List<string>(); List<string> players = new List<string>();
readonly object locker = new object(); readonly object locker = new object();
public PlayerList() { }
public PlayerList(string file) { this.file = file; }
public void Add(string p) { public void Add(string p) {
lock (locker) lock (locker)
players.Add(p.ToLower()); players.Add(p.ToLower());
@ -76,10 +79,8 @@ namespace MCGalaxy {
public static PlayerList Load(string path) { public static PlayerList Load(string path) {
if (!Directory.Exists("ranks")) if (!Directory.Exists("ranks"))
Directory.CreateDirectory("ranks"); Directory.CreateDirectory("ranks");
PlayerList list = new PlayerList(); PlayerList list = new PlayerList(path);
list.file = path;
path = "ranks/" + path; path = "ranks/" + path;
if (!File.Exists(path)) { if (!File.Exists(path)) {
File.Create(path).Close(); File.Create(path).Close();
Server.s.Log("CREATED NEW: " + list.file); Server.s.Log("CREATED NEW: " + list.file);

View File

@ -66,6 +66,14 @@ namespace MCGalaxy {
} }
void LoadPlayerLists() { void LoadPlayerLists() {
agreed = new PlayerList("ranks/agreed.txt");
try {
CheckOldAgreed();
agreed = PlayerList.Load("agreed.txt");
} catch (Exception ex) {
Server.ErrorLog(ex);
}
bannedIP = PlayerList.Load("banned-ip.txt"); bannedIP = PlayerList.Load("banned-ip.txt");
ircControllers = PlayerList.Load("IRC_Controllers.txt"); ircControllers = PlayerList.Load("IRC_Controllers.txt");
muted = PlayerList.Load("muted.txt"); muted = PlayerList.Load("muted.txt");
@ -81,6 +89,19 @@ namespace MCGalaxy {
whiteList = PlayerList.Load("whitelist.txt"); whiteList = PlayerList.Load("whitelist.txt");
} }
void CheckOldAgreed() {
// agreed.txt format used to be names separated by spaces, we need to fix that up.
if (!File.Exists("ranks/agreed.txt")) return;
string data = null;
using (FileStream fs = File.OpenRead("ranks/agreed.txt")) {
if (fs.ReadByte() != ' ') return;
data = new StreamReader(fs).ReadToEnd();
data = data.Replace(" ", Environment.NewLine);
}
File.WriteAllText("ranks/agreed.txt", data);
}
void LoadAutoloadCommands() { void LoadAutoloadCommands() {
if (File.Exists("text/autoload.txt")) { if (File.Exists("text/autoload.txt")) {
try { try {

View File

@ -99,7 +99,7 @@ namespace MCGalaxy
public static bool UseCTF = false; public static bool UseCTF = false;
public static bool ServerSetupFinished = false; public static bool ServerSetupFinished = false;
public static Auto_CTF ctf = null; public static Auto_CTF ctf = null;
public static PlayerList bannedIP, whiteList, ircControllers, muted, ignored, frozen, hidden; public static PlayerList bannedIP, whiteList, ircControllers, muted, ignored, frozen, hidden, agreed;
public static PlayerExtList jailed, models, skins; public static PlayerExtList jailed, models, skins;
public static readonly List<string> Devs = new List<string>(), Mods = new List<string>(); public static readonly List<string> Devs = new List<string>(), Mods = new List<string>();