diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj
index b30d90125..9c86bf8f5 100644
--- a/MCGalaxy_.csproj
+++ b/MCGalaxy_.csproj
@@ -518,11 +518,12 @@
+
+
+
-
-
@@ -567,7 +568,6 @@
-
Code
@@ -694,6 +694,7 @@
+
diff --git a/Player/Ban.cs b/Player/Ban.cs
index e0047427f..88c77bb10 100644
--- a/Player/Ban.cs
+++ b/Player/Ban.cs
@@ -25,8 +25,8 @@ namespace MCGalaxy {
/// and add / remove someone to the baninfo (NOT THE BANNED.TXT !)
public static class Ban {
- static PlayersFile bans = new PlayersFile("text/bans.txt");
- static PlayersFile unbans = new PlayersFile("text/unbans.txt");
+ static PlayerMetaList bans = new PlayerMetaList("text/bans.txt");
+ static PlayerMetaList unbans = new PlayerMetaList("text/unbans.txt");
public static void EnsureExists() {
bans.EnsureExists();
@@ -108,7 +108,7 @@ namespace MCGalaxy {
/// Deletes the unban information about the user.
public static bool DeleteUnban(string name) { return DeleteInfo(name, unbans); }
- static bool DeleteInfo(string name, PlayersFile list) {
+ static bool DeleteInfo(string name, PlayerMetaList list) {
name = name.ToLower();
bool success = false;
StringBuilder sb = new StringBuilder();
@@ -135,7 +135,7 @@ namespace MCGalaxy {
return ChangeReason(who, reason, unbans);
}
- static bool ChangeReason(string who, string reason, PlayersFile list) {
+ static bool ChangeReason(string who, string reason, PlayerMetaList list) {
who = who.ToLower();
reason = reason.Replace(" ", "%20");
bool success = false;
diff --git a/Player/PlayersFile.cs b/Player/List/PlayerMetaList.cs
similarity index 94%
rename from Player/PlayersFile.cs
rename to Player/List/PlayerMetaList.cs
index 860b40531..8f9d35504 100644
--- a/Player/PlayersFile.cs
+++ b/Player/List/PlayerMetaList.cs
@@ -22,12 +22,12 @@ using System.IO;
namespace MCGalaxy {
/// Represents a list of metadata about players. (such as rank info, ban info, notes).
- public sealed class PlayersFile {
+ public sealed class PlayerMetaList {
public readonly string file;
readonly object locker;
- public PlayersFile(string file) {
+ public PlayerMetaList(string file) {
this.file = file;
locker = new object();
}
diff --git a/Player/List/PlayersFile.cs b/Player/List/PlayersFile.cs
deleted file mode 100644
index c0c66d63e..000000000
--- a/Player/List/PlayersFile.cs
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- Copyright 2015 MCGalaxy
-
- 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.Collections.Generic;
-using System.IO;
-
-namespace MCGalaxy {
-
- /// Represents a list of extended metadata about players. (such as rank info, ban info, notes).
- public sealed class PlayerMetaList {
-
- public readonly string file;
- readonly object locker;
-
- public PlayerMetaList(string file) {
- this.file = file;
- locker = new object();
- }
-
- public void EnsureExists() {
- if (!File.Exists(file))
- File.Create(file).Dispose();
- }
-
- /// Finds all lines which caselessly start with the given name.
- public IEnumerable Find(string name) {
- if (!File.Exists(file)) yield break;
- name += " ";
-
- using (StreamReader r = new StreamReader(file)) {
- string line;
- while ((line = r.ReadLine()) != null) {
- if (line.CaselessStarts(name)) yield return line;
- }
- }
- yield break;
- }
-
- /// Deletes all lines which start with the given value.
- public void DeleteStartsWith(string value) {
- if (!File.Exists(file)) return;
- List lines = new List();
- using (StreamReader r = new StreamReader(file)) {
- string line;
- while ((line = r.ReadLine()) != null) {
- if (line.StartsWith(value)) continue;
- lines.Add(line);
- }
- }
- WriteLines(lines);
- }
-
- void WriteLines(List lines) {
- lock (locker) {
- using (StreamWriter w = new StreamWriter(file, false)) {
- foreach (string line in lines)
- w.WriteLine(line);
- }
- }
- }
-
- /// Adds the given line to the end of the file.
- public void Append(string data) {
- string line = CP437Writer.ConvertToUnicode(data);
- lock (locker) {
- using (StreamWriter w = new StreamWriter(file, true))
- w.WriteLine(line);
- }
- }
- }
-}
diff --git a/Player/PlayerExtList.cs b/Player/PlayerExtList.cs
deleted file mode 100644
index f2f28b208..000000000
--- a/Player/PlayerExtList.cs
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- Copyright 2015 MCGalaxy
-
- 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.Collections.Generic;
-using System.IO;
-using System.Text;
-
-namespace MCGalaxy {
- public sealed class PlayerExtList {
-
- string path;
- List players = new List();
- List lines = new List();
- readonly object locker = new object();
-
- public void Add(string p, string data) {
- p = p.ToLower();
- lock (locker) {
- players.Add(p); lines.Add(p + " " + data);
- }
- }
-
- public bool Remove(string p) {
- lock (locker) {
- int idx = players.IndexOf(p.ToLower());
- if (idx == -1) return false;
-
- players.RemoveAt(idx);
- lines.RemoveAt(idx);
- return true;
- }
- }
-
- public void AddOrReplace(string p, string data) {
- p = p.ToLower();
- lock (locker) {
- int idx = players.IndexOf(p);
- if (idx == -1) {
- players.Add(p); lines.Add(p + " " + data);
- } else {
- lines[idx] = p + " " + data;
- }
- }
- }
-
- public string Find(string p) {
- lock (locker) {
- int idx = players.IndexOf(p.ToLower());
- return idx == -1 ? null : lines[idx];
- }
- }
-
- public int Count { get { lock (locker) return players.Count; } }
-
-
- public void Save(bool console = false) {
- using (StreamWriter w = new StreamWriter(path)) {
- lock (locker) {
- foreach (string line in lines)
- w.WriteLine(line);
- }
- }
- if (console) Server.s.Log("SAVED: " + path, true);
- }
-
- public static PlayerExtList Load(string path) {
- PlayerExtList list = new PlayerExtList();
- list.path = path;
-
- if (!File.Exists(path)) {
- File.Create(path).Close();
- Server.s.Log("CREATED NEW: " + path);
- return list;
- }
-
- using (StreamReader r = new StreamReader(path, Encoding.UTF8)) {
- string line = null;
- while ((line = r.ReadLine()) != null) {
- list.lines.Add(line);
- int space = line.IndexOf(' ');
- string name = space >= 0 ? line.Substring(0, space) : line;
-
- // Need to convert uppercase to lowercase, in case user added in entries.
- bool anyUpper = false;
- for (int i = 0; i < name.Length; i++) {
- char c = line[i];
- anyUpper |= (c >= 'A' && c <= 'Z');
- }
- if (anyUpper) name = name.ToLower();
- list.players.Add(name);
- }
- }
- return list;
- }
- }
-}
\ No newline at end of file
diff --git a/Player/PlayerList.cs b/Player/PlayerList.cs
deleted file mode 100644
index 229e43dc5..000000000
--- a/Player/PlayerList.cs
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
-
- 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.Collections.Generic;
-using System.IO;
-using System.Text;
-
-namespace MCGalaxy {
- public sealed class PlayerList {
- string path;
- List players = new List();
- readonly object locker = new object();
-
- public PlayerList() { }
- public PlayerList(string path) { this.path = path; }
-
- public void Add(string p) {
- lock (locker)
- players.Add(p.ToLower());
- }
-
- public bool Remove(string p) {
- lock (locker)
- return players.Remove(p.ToLower());
- }
-
- public bool Contains(string p) {
- lock (locker)
- return players.Contains(p.ToLower());
- }
-
- public List All() {
- lock (locker)
- return new List(players);
- }
-
- public int Count { get { lock (locker) return players.Count; } }
-
- public void AddOrReplace(string p) {
- p = p.ToLower();
- lock (locker) {
- int idx = players.IndexOf(p);
- if (idx >= 0) return;
- players.Add(p);
- }
- }
-
-
- public void Save() { Save(true); }
- public void Save(bool console) {
- using (StreamWriter w = new StreamWriter(path)) {
- lock (locker) {
- foreach (string p in players)
- w.WriteLine(p);
- }
- }
- if (console) Server.s.Log("SAVED: " + path, true);
- }
-
- public static PlayerList Load(string file) {
- if (!Directory.Exists("ranks")) Directory.CreateDirectory("ranks");
- PlayerList list = new PlayerList(file);
- if (file.IndexOf('/') == -1) file = "ranks/" + file;
- list.path = file;
-
- if (!File.Exists(list.path)) {
- File.Create(list.path).Close();
- Server.s.Log("CREATED NEW: " + list.path);
- return list;
- }
-
- using (StreamReader r = new StreamReader(list.path, Encoding.UTF8)) {
- string line = null;
- while ((line = r.ReadLine()) != null) {
- // Need to convert uppercase to lowercase, in case user added in entries.
- bool anyUpper = false;
- for (int i = 0; i < line.Length; i++) {
- char c = line[i];
- anyUpper |= (c >= 'A' && c <= 'Z');
- }
-
- if (anyUpper) line = line.ToLower();
- list.players.Add(line);
- }
- }
- return list;
- }
-
- [Obsolete("Group parameter is completely ignored.")]
- public static PlayerList Load(string path, Group grp) { return Load(path); }
- }
-}
\ No newline at end of file
diff --git a/Server/Server.cs b/Server/Server.cs
index 74e50f352..6f75e7957 100644
--- a/Server/Server.cs
+++ b/Server/Server.cs
@@ -68,10 +68,10 @@ namespace MCGalaxy
[ConfigBool("classicube-account-plus", "Server", null, true)]
public static bool ClassicubeAccountPlus = true;
- public static PlayersFile AutoloadMaps = new PlayersFile("text/autoload.txt");
- public static PlayersFile RankInfo = new PlayersFile("text/rankinfo.txt");
- public static PlayersFile TempRanks = new PlayersFile("text/tempranks.txt");
- public static PlayersFile Notes = new PlayersFile("text/notes.txt");
+ public static PlayerMetaList AutoloadMaps = new PlayerMetaList("text/autoload.txt");
+ public static PlayerMetaList RankInfo = new PlayerMetaList("text/rankinfo.txt");
+ public static PlayerMetaList TempRanks = new PlayerMetaList("text/tempranks.txt");
+ public static PlayerMetaList Notes = new PlayerMetaList("text/notes.txt");
public static Version Version { get { return System.Reflection.Assembly.GetAssembly(typeof(Server)).GetName().Version; } }
public static string VersionString {