mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Make /vip actually work and get rid of the pointlessly duplicated code.
This commit is contained in:
parent
f35dcbd827
commit
ef1cebaee7
@ -1,81 +1,78 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2011 MCForge
|
Copyright 2011 MCForge
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
http://www.opensource.org/licenses/ecl2.php
|
http://www.opensource.org/licenses/ecl2.php
|
||||||
http://www.gnu.org/licenses/gpl-3.0.html
|
http://www.gnu.org/licenses/gpl-3.0.html
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing,
|
Unless required by applicable law or agreed to in writing,
|
||||||
software distributed under the Licenses are distributed on an "AS IS"
|
software distributed under the Licenses are distributed on an "AS IS"
|
||||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
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.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
|
||||||
namespace MCGalaxy.Commands
|
namespace MCGalaxy.Commands {
|
||||||
{
|
public sealed class CmdVIP : Command {
|
||||||
public sealed class CmdVIP : Command
|
|
||||||
{
|
|
||||||
public override string name { get { return "vip"; } }
|
public override string name { get { return "vip"; } }
|
||||||
public override string shortcut { get { return ""; } }
|
public override string shortcut { get { return ""; } }
|
||||||
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.Admin; } }
|
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
|
||||||
public CmdVIP() { }
|
public CmdVIP() { }
|
||||||
|
|
||||||
public override void Use(Player p, string message)
|
public override void Use(Player p, string message) {
|
||||||
{
|
|
||||||
if (message == "") { Help(p); return; }
|
if (message == "") { Help(p); return; }
|
||||||
string[] split = message.Split(' ');
|
string[] args = message.Split(' ');
|
||||||
if (split[0] == "add")
|
|
||||||
{
|
if (args[0] == "add") {
|
||||||
if (split.Length < 2) { Help(p); return; }
|
if (args.Length < 2) { Help(p); return; }
|
||||||
Player pl = PlayerInfo.Find(split[1]);
|
Player pl = PlayerInfo.Find(args[1]);
|
||||||
if (pl != null) split[1] = pl.name;
|
if (pl != null) args[1] = pl.name;
|
||||||
if (VIP.Find(split[1])) Player.Message(p, (pl == null ? "" : pl.color) + split[1] + " is already a VIP!");
|
|
||||||
else
|
if (Server.vip.Contains(args[1])) {
|
||||||
{
|
Player.Message(p, Name(pl, args[1]) + " %Sis already a VIP.");
|
||||||
VIP.Add(split[1]);
|
} else {
|
||||||
Player.Message(p, (pl == null ? "" : pl.color) + split[1] + " is now a VIP.");
|
Server.vip.Add(args[1]);
|
||||||
|
Server.vip.Save(false);
|
||||||
|
Player.Message(p, Name(pl, args[1]) + " %Sis now a VIP.");
|
||||||
if (pl != null) Player.Message(pl, "You are now a VIP!");
|
if (pl != null) Player.Message(pl, "You are now a VIP!");
|
||||||
}
|
}
|
||||||
}
|
} else if (args[0] == "remove") {
|
||||||
else if (split[0] == "remove")
|
if (args.Length < 2) { Help(p); return; }
|
||||||
{
|
Player pl = PlayerInfo.Find(args[1]);
|
||||||
if (split.Length < 2) { Help(p); return; }
|
if (pl != null) args[1] = pl.name;
|
||||||
Player pl = PlayerInfo.Find(split[1]);
|
|
||||||
if (pl != null) split[1] = pl.name;
|
if (Server.vip.Contains(args[1])) {
|
||||||
if (!VIP.Find(split[1])) Player.Message(p, (pl == null ? "" : pl.color) + split[1] + " is not a VIP!");
|
Player.Message(p, Name(pl, args[1]) + " %Sis not a VIP.");
|
||||||
else
|
} else {
|
||||||
{
|
Server.vip.Remove(args[1]);
|
||||||
VIP.Remove(split[1]);
|
Server.vip.Save(false);
|
||||||
Player.Message(p, (pl == null ? "" : pl.color) + split[1] + " is no longer a VIP.");
|
Player.Message(p, Name(pl, args[1]) + " %Sis no longer a VIP.");
|
||||||
if (pl != null) Player.Message(pl, "You are no longer a VIP!");
|
if (pl != null) Player.Message(pl, "You are no longer a VIP!");
|
||||||
}
|
}
|
||||||
}
|
} else if (args[0] == "list") {
|
||||||
else if (split[0] == "list")
|
List<string> list = Server.vip.All();
|
||||||
{
|
if (list.Count == 0) {
|
||||||
List<string> list = VIP.GetAll();
|
Player.Message(p, "There are no VIPs.");
|
||||||
if (list.Count < 1) Player.Message(p, "There are no VIPs.");
|
} else {
|
||||||
else {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
foreach (string name in list)
|
|
||||||
sb.Append(name).Append(", ");
|
|
||||||
|
|
||||||
string count = list.Count > 1 ? "is 1" : "are " + list.Count;
|
string count = list.Count > 1 ? "is 1" : "are " + list.Count;
|
||||||
Player.Message(p, "There " + count + " VIPs:");
|
Player.Message(p, "There " + count + " VIPs:");
|
||||||
Player.Message(p, sb.Remove(sb.Length - 2, 2).ToString());
|
Player.Message(p, list.Concatenate(", "));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Help(p);
|
||||||
}
|
}
|
||||||
else Help(p);
|
|
||||||
}
|
}
|
||||||
public override void Help(Player p)
|
|
||||||
{
|
static string Name(Player pl, string name) { return pl == null ? name : pl.ColoredName; }
|
||||||
|
|
||||||
|
public override void Help(Player p) {
|
||||||
Player.Message(p, "VIPs are players who can join regardless of the player limit.");
|
Player.Message(p, "VIPs are players who can join regardless of the player limit.");
|
||||||
Player.Message(p, "/vip add <name> - Add a VIP.");
|
Player.Message(p, "/vip add <name> - Add a VIP.");
|
||||||
Player.Message(p, "/vip remove <name> - Remove a VIP.");
|
Player.Message(p, "/vip remove <name> - Remove a VIP.");
|
||||||
|
@ -36,7 +36,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string src = args[0], dst = args[1];
|
string src = args[0], dst = args[1];
|
||||||
if (!p.group.CanExecute("newlvl")) {
|
if (p != null && !p.group.CanExecute("newlvl")) {
|
||||||
Player.Message(p, "You cannot use /copylvl as you cannot use /newlvl."); return;
|
Player.Message(p, "You cannot use /copylvl as you cannot use /newlvl."); return;
|
||||||
}
|
}
|
||||||
src = LevelInfo.FindMapMatches(p, src);
|
src = LevelInfo.FindMapMatches(p, src);
|
||||||
|
@ -576,7 +576,6 @@
|
|||||||
<Compile Include="Server\Server.Tasks.cs" />
|
<Compile Include="Server\Server.Tasks.cs" />
|
||||||
<Compile Include="Server\Server.Threads.cs" />
|
<Compile Include="Server\Server.Threads.cs" />
|
||||||
<Compile Include="Server\Updater.cs" />
|
<Compile Include="Server\Updater.cs" />
|
||||||
<Compile Include="Player\VIP.cs" />
|
|
||||||
<Compile Include="API\WebServer.cs" />
|
<Compile Include="API\WebServer.cs" />
|
||||||
<Compile Include="util\FastList.cs" />
|
<Compile Include="util\FastList.cs" />
|
||||||
<Compile Include="util\App.cs" />
|
<Compile Include="util\App.cs" />
|
||||||
|
@ -88,7 +88,7 @@ namespace MCGalaxy
|
|||||||
fileName = file;
|
fileName = file;
|
||||||
OverseerMaps = maps;
|
OverseerMaps = maps;
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
playerList = name != "nobody" ? PlayerList.Load(fileName, this) : new PlayerList();
|
playerList = name != "nobody" ? PlayerList.Load(fileName) : new PlayerList();
|
||||||
if (OnGroupLoaded != null)
|
if (OnGroupLoaded != null)
|
||||||
OnGroupLoaded(this);
|
OnGroupLoaded(this);
|
||||||
OnGroupLoadedEvent.Call(this);
|
OnGroupLoadedEvent.Call(this);
|
||||||
|
@ -393,7 +393,7 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool CheckPlayersCount(Group foundGrp) {
|
bool CheckPlayersCount(Group foundGrp) {
|
||||||
if (VIP.Find(this)) return true;
|
if (Server.vip.Contains(name)) return true;
|
||||||
|
|
||||||
Player[] online = PlayerInfo.Online.Items;
|
Player[] online = PlayerInfo.Online.Items;
|
||||||
if (online.Length >= Server.players && !IPInPrivateRange(ip)) { Leave("Server full!", true); return false; }
|
if (online.Length >= Server.players && !IPInPrivateRange(ip)) { Leave("Server full!", true); return false; }
|
||||||
|
@ -22,13 +22,12 @@ using System.Text;
|
|||||||
|
|
||||||
namespace MCGalaxy {
|
namespace MCGalaxy {
|
||||||
public sealed class PlayerList {
|
public sealed class PlayerList {
|
||||||
|
string path;
|
||||||
string file;
|
|
||||||
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() { }
|
||||||
public PlayerList(string file) { this.file = file; }
|
public PlayerList(string path) { this.path = path; }
|
||||||
|
|
||||||
public void Add(string p) {
|
public void Add(string p) {
|
||||||
lock (locker)
|
lock (locker)
|
||||||
@ -62,32 +61,30 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Save() { Save(file, true); }
|
public void Save() { Save(true); }
|
||||||
public void Save(bool console) { Save(file, console); }
|
public void Save(bool console) {
|
||||||
|
using (StreamWriter w = new StreamWriter(path)) {
|
||||||
public void Save(string file, bool console) {
|
|
||||||
using (StreamWriter w = new StreamWriter("ranks/" + file)) {
|
|
||||||
lock (locker) {
|
lock (locker) {
|
||||||
foreach (string p in players)
|
foreach (string p in players)
|
||||||
w.WriteLine(p);
|
w.WriteLine(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (console)
|
if (console) Server.s.Log("SAVED: " + path, true);
|
||||||
Server.s.Log("SAVED: " + file, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlayerList Load(string path) {
|
public static PlayerList Load(string file) {
|
||||||
if (!Directory.Exists("ranks"))
|
if (!Directory.Exists("ranks")) Directory.CreateDirectory("ranks");
|
||||||
Directory.CreateDirectory("ranks");
|
PlayerList list = new PlayerList(file);
|
||||||
PlayerList list = new PlayerList(path);
|
if (file.IndexOf('/') == -1) file = "ranks/" + file;
|
||||||
path = "ranks/" + path;
|
list.path = file;
|
||||||
if (!File.Exists(path)) {
|
|
||||||
File.Create(path).Close();
|
if (!File.Exists(list.path)) {
|
||||||
Server.s.Log("CREATED NEW: " + list.file);
|
File.Create(list.path).Close();
|
||||||
|
Server.s.Log("CREATED NEW: " + list.path);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
using (StreamReader r = new StreamReader(path, Encoding.UTF8)) {
|
using (StreamReader r = new StreamReader(list.path, Encoding.UTF8)) {
|
||||||
string line = null;
|
string line = null;
|
||||||
while ((line = r.ReadLine()) != null) {
|
while ((line = r.ReadLine()) != null) {
|
||||||
// Need to convert uppercase to lowercase, in case user added in entries.
|
// Need to convert uppercase to lowercase, in case user added in entries.
|
||||||
|
@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
namespace MCGalaxy
|
|
||||||
{
|
|
||||||
public static class VIP
|
|
||||||
{
|
|
||||||
public static readonly string file = "text/vips.txt"; //this file is never even created anywhere..
|
|
||||||
|
|
||||||
public static void Add(string name)
|
|
||||||
{
|
|
||||||
if (!File.Exists(file)) return;
|
|
||||||
name = name.Trim().ToLower();
|
|
||||||
List<string> list = new List<string>(File.ReadAllLines(file));
|
|
||||||
list.Add(name);
|
|
||||||
File.WriteAllLines(file, list.ToArray());
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Adds a Player to VIP's
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="p">the Player to add</param>
|
|
||||||
public static void Add(Player p)
|
|
||||||
{
|
|
||||||
Add(p.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Remove(string name)
|
|
||||||
{
|
|
||||||
if (!File.Exists(file)) return;
|
|
||||||
name = name.Trim().ToLower();
|
|
||||||
List<string> list = new List<string>();
|
|
||||||
foreach (string line in File.ReadAllLines(file))
|
|
||||||
if (line.Trim().ToLower() != name)
|
|
||||||
list.Add(line);
|
|
||||||
File.WriteAllLines(file, list.ToArray());
|
|
||||||
}
|
|
||||||
public static void Remove(Player p)
|
|
||||||
{
|
|
||||||
Remove(p.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool Find(string name)
|
|
||||||
{
|
|
||||||
if (!File.Exists(file)) return false;
|
|
||||||
name = name.Trim().ToLower();
|
|
||||||
foreach (string line in File.ReadAllLines(file))
|
|
||||||
if (line.Trim().ToLower() == name)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
public static bool Find(Player p)
|
|
||||||
{
|
|
||||||
return Find(p.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<string> GetAll()
|
|
||||||
{
|
|
||||||
if (File.Exists(file))
|
|
||||||
return new List<string>(File.ReadAllLines(file));
|
|
||||||
return new List<string>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -79,6 +79,7 @@ namespace MCGalaxy {
|
|||||||
muted = PlayerList.Load("muted.txt");
|
muted = PlayerList.Load("muted.txt");
|
||||||
frozen = PlayerList.Load("frozen.txt");
|
frozen = PlayerList.Load("frozen.txt");
|
||||||
hidden = PlayerList.Load("hidden.txt");
|
hidden = PlayerList.Load("hidden.txt");
|
||||||
|
vip = PlayerList.Load("text/vip.txt");
|
||||||
jailed = PlayerExtList.Load("ranks/jailed.txt");
|
jailed = PlayerExtList.Load("ranks/jailed.txt");
|
||||||
models = PlayerExtList.Load("extra/models.txt");
|
models = PlayerExtList.Load("extra/models.txt");
|
||||||
skins = PlayerExtList.Load("extra/skins.txt");
|
skins = PlayerExtList.Load("extra/skins.txt");
|
||||||
|
@ -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, agreed;
|
public static PlayerList bannedIP, whiteList, ircControllers, muted, ignored, frozen, hidden, agreed, vip;
|
||||||
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>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user