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

@ -2,20 +2,20 @@
* Written By Jack1312
Copyright 2011 MCForge
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
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;
@ -30,40 +30,26 @@ namespace MCGalaxy.Commands
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
public CmdAgree() { }
public override void Use(Player p, string message)
{
if (Player.IsSuper(p)) { MessageInGameOnly(p); return; }
if (Server.agreetorulesonentry == false)
{
Player.Message(p, "This command can only be used if agree-to-rules-on-entry is enabled!");
return;
public override void Use(Player p, string message) {
if (Player.IsSuper(p)) { MessageInGameOnly(p); return; }
if (!Server.agreetorulesonentry) {
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)
{
Player.Message(p, "&9You must read /rules before agreeing!");
return;
if (!p.hasreadrules) {
Player.Message(p, "&9You must read /rules before agreeing!"); return;
}
if ((agreed+" ").Contains(" " + p.name.ToLower() + " ")) //Edited to prevent inner names from working.
{
Player.Message(p, "You have already agreed to the rules!");
return;
if (Server.agreed.Contains(p.name)) {
Player.Message(p, "You have already agreed to the rules!"); return;
}
p.agreed = true;
Player.Message(p, "Thank you for agreeing to follow the rules. You may now build and use commands!");
string playerspath = "ranks/agreed.txt";
if (File.Exists(playerspath))
{
//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.
}
Server.agreed.Add(p.name);
Server.agreed.Save(false);
}
public override void Help(Player p)
{
public override void Help(Player p) {
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
permissions and limitations under the Licenses.
*/
namespace MCGalaxy.Commands
{
public sealed class CmdDisagree : Command
{
namespace MCGalaxy.Commands {
public sealed class CmdDisagree : Command {
public override string name { get { return "disagree"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Other; } }
@ -28,24 +26,19 @@ namespace MCGalaxy.Commands
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
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 (!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!");
return;
}
if (p.group.Permission > LevelPermission.Guest)
{
Player.Message(p, "Your awesomeness prevents you from using this command");
return;
if (p.group.Permission > LevelPermission.Guest) {
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.");
}
public override void Help(Player p)
{
public override void Help(Player p) {
Player.Message(p, "/disagree - Disagree to the rules when entering the server");
}
}

View File

@ -552,14 +552,9 @@ namespace MCGalaxy {
CheckLoginJailed();
CheckReviewList();
if (Server.agreetorulesonentry) {
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!");
agreed = false;
}
if (Server.agreetorulesonentry && group.Permission == LevelPermission.Guest && !Server.agreed.Contains(name)) {
SendMessage("&9You must read the &c/rules&9 and &c/agree&9 to them before you can build and use commands!");
agreed = false;
}
if (Server.verifyadmins && group.Permission >= Server.verifyadminsrank) {

View File

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

View File

@ -66,11 +66,19 @@ namespace MCGalaxy {
}
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");
ircControllers = PlayerList.Load("IRC_Controllers.txt");
muted = PlayerList.Load("muted.txt");
frozen = PlayerList.Load("frozen.txt");
hidden = PlayerList.Load("hidden.txt");
hidden = PlayerList.Load("hidden.txt");
jailed = PlayerExtList.Load("ranks/jailed.txt");
models = PlayerExtList.Load("extra/models.txt");
skins = PlayerExtList.Load("extra/skins.txt");
@ -81,6 +89,19 @@ namespace MCGalaxy {
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() {
if (File.Exists("text/autoload.txt")) {
try {

View File

@ -99,7 +99,7 @@ namespace MCGalaxy
public static bool UseCTF = false;
public static bool ServerSetupFinished = false;
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 readonly List<string> Devs = new List<string>(), Mods = new List<string>();