mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 12:42:22 -04:00
Fix last commit.
This commit is contained in:
parent
8449a791b2
commit
2e34abbf9e
@ -518,11 +518,12 @@
|
||||
<Compile Include="Player\Group\Group.cs" />
|
||||
<Compile Include="Player\Group\GroupCommands.cs" />
|
||||
<Compile Include="Player\Group\GroupProperties.cs" />
|
||||
<Compile Include="Player\List\PlayerExtList.cs" />
|
||||
<Compile Include="Player\List\PlayerList.cs" />
|
||||
<Compile Include="Player\List\PlayerMetaList.cs" />
|
||||
<Compile Include="Player\Player.Handlers.cs" />
|
||||
<Compile Include="Player\PlayerActions.cs" />
|
||||
<Compile Include="Player\PlayerExtList.cs" />
|
||||
<Compile Include="Player\PlayerInfo.cs" />
|
||||
<Compile Include="Player\PlayersFile.cs" />
|
||||
<Compile Include="Player\TabList.cs" />
|
||||
<Compile Include="Player\Undo\UndoCache.cs" />
|
||||
<Compile Include="Player\Undo\UndoFileCBin.cs" />
|
||||
@ -567,7 +568,6 @@
|
||||
<Compile Include="Server\Extra\Heart.cs" />
|
||||
<Compile Include="Server\Logger.cs" />
|
||||
<Compile Include="Player\Player.cs" />
|
||||
<Compile Include="Player\PlayerList.cs" />
|
||||
<Compile Include="Server\Extra\ProfanityFilter.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
@ -694,6 +694,7 @@
|
||||
<Folder Include="Bots" />
|
||||
<Folder Include="Events" />
|
||||
<Folder Include="Player\Group" />
|
||||
<Folder Include="Player\List" />
|
||||
<Folder Include="Player\Undo" />
|
||||
<Folder Include="Plugins" />
|
||||
<Folder Include="Plugins\Events" />
|
||||
|
@ -25,8 +25,8 @@ namespace MCGalaxy {
|
||||
/// and add / remove someone to the baninfo (NOT THE BANNED.TXT !) </summary>
|
||||
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 {
|
||||
/// <summary> Deletes the unban information about the user. </summary>
|
||||
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;
|
||||
|
@ -22,12 +22,12 @@ using System.IO;
|
||||
namespace MCGalaxy {
|
||||
|
||||
/// <summary> Represents a list of metadata about players. (such as rank info, ban info, notes). </summary>
|
||||
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();
|
||||
}
|
@ -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 {
|
||||
|
||||
/// <summary> Represents a list of extended metadata about players. (such as rank info, ban info, notes). </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary> Finds all lines which caselessly start with the given name. </summary>
|
||||
public IEnumerable<string> 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;
|
||||
}
|
||||
|
||||
/// <summary> Deletes all lines which start with the given value. </summary>
|
||||
public void DeleteStartsWith(string value) {
|
||||
if (!File.Exists(file)) return;
|
||||
List<string> lines = new List<string>();
|
||||
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<string> lines) {
|
||||
lock (locker) {
|
||||
using (StreamWriter w = new StreamWriter(file, false)) {
|
||||
foreach (string line in lines)
|
||||
w.WriteLine(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Adds the given line to the end of the file. </summary>
|
||||
public void Append(string data) {
|
||||
string line = CP437Writer.ConvertToUnicode(data);
|
||||
lock (locker) {
|
||||
using (StreamWriter w = new StreamWriter(file, true))
|
||||
w.WriteLine(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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<string> players = new List<string>();
|
||||
List<string> lines = new List<string>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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<string> players = new List<string>();
|
||||
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<string> All() {
|
||||
lock (locker)
|
||||
return new List<string>(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); }
|
||||
}
|
||||
}
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user