Make jail/xjail less awful and actually work.

This commit is contained in:
UnknownShadow200 2016-06-08 20:01:33 +10:00
parent 451ba124e8
commit bfb0f9493f
8 changed files with 175 additions and 97 deletions

View File

@ -48,17 +48,18 @@ namespace MCGalaxy.Commands
Entities.GlobalSpawn(who, (ushort)who.level.jailx, (ushort)who.level.jaily, (ushort)who.level.jailz,
who.level.jailrotx, who.level.jailroty, true);
Server.Jailed.DeleteContains(who.name.ToLower());
Server.Jailed.Append(who.name.ToLower() + " " + who.level.name);
Server.jailed.Remove(who.name);
Server.jailed.Add(who.name, who.level.name);
Player.SendChatFrom(who, who.ColoredName + " %Swas &8jailed", false);
Player.AddNote(who.name, p, "J");
} else {
Server.Jailed.DeleteContains(who.name.ToLower());
Server.jailed.Remove(who.name);
who.jailed = false;
Command.all.Find("spawn").Use(who, "");
Player.Message(p, "You freed " + who.name + " from jail");
Player.SendChatFrom(who, who.ColoredName + " %Swas &afreed %Sfrom jail", false);
}
Server.jailed.Save();
}
public override void Help(Player p) {

View File

@ -17,8 +17,8 @@
*/
using System.IO;
namespace MCGalaxy.Commands {
public sealed class CmdXJail : Command {
public override string name { get { return "xjail"; } }
public override string shortcut { get { return "xj"; } }
public override string type { get { return CommandTypes.Other; } }
@ -26,65 +26,49 @@ namespace MCGalaxy.Commands {
public override bool museumUsable { get { return true; } }
public override void Use(Player p, string message) {
string dir = "extra/jail/";
string jailMapFile = dir + "xjail.map.xjail";
if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); }
if (!File.Exists(jailMapFile)) {
using (StreamWriter SW = new StreamWriter(jailMapFile))
SW.WriteLine(Server.mainLevel.name);
string xjailMap = Server.xjailLevel;
if (xjailMap == "(main)") xjailMap = Server.mainLevel.name;
if (message == "") { Help(p); return; }
Command jail = Command.all.Find("jail");
if (message == "set") {
if (!p.level.IsMuseum) {
jail.Use(p, "set");
Server.xjailLevel = p.level.name;
SrvProperties.Save();
Player.Message(p, "The xjail map was set from '" + xjailMap + "' to '" + p.level.name + "'");
} else {
Player.Message(p, "You are in a museum!");
}
return;
}
if (message == "") { Help(p); return; }
using (StreamReader SR = new StreamReader(jailMapFile)) {
string xjailMap = SR.ReadLine();
SR.Close();
Command jail = Command.all.Find("jail");
if (message == "set") {
if (!p.level.IsMuseum) {
jail.Use(p, "create");
using (StreamWriter SW = new StreamWriter(jailMapFile))
SW.WriteLine(p.level.name);
Player.Message(p, "The xjail map was set from '" + xjailMap + "' to '" + p.level.name + "'");
} else {
Player.Message(p, "You are in a museum!");
}
return;
}
Player pl = PlayerInfo.FindOrShowMatches(p, message);
if (pl == null) return;
Player pl = PlayerInfo.FindOrShowMatches(p, message);
if (pl == null) return;
Command move = Command.all.Find("move");
Command spawn = Command.all.Find("spawn");
Command freeze = Command.all.Find("freeze");
Command mute = Command.all.Find("mute");
string playerFile = dir + pl.name + "_temp.xjail";
Command spawn = Command.all.Find("spawn");
Command freeze = Command.all.Find("freeze");
Command mute = Command.all.Find("mute");
string data = Server.jailed.Find(pl.name);
if (data == null) {
if (!pl.muted) mute.Use(p, message);
if (!pl.frozen) freeze.Use(p, message);
if (!File.Exists(playerFile)) {
using (StreamWriter writeFile = new StreamWriter(playerFile))
writeFile.WriteLine(pl.level.name);
if (!pl.muted) { mute.Use(p, message); }
if (!pl.frozen) { freeze.Use(p, message); }
move.Use(p, message + " " + xjailMap);
pl.BlockUntilLoad(10);
if (!pl.jailed) { jail.Use(p, message); }
Player.GlobalMessage(pl.ColoredName + " %Swas XJailed!");
} else {
using (StreamReader readFile = new StreamReader(playerFile)) {
string playerMap = readFile.ReadLine();
readFile.Close();
File.Delete(playerFile);
move.Use(p, message + " " + playerMap);
pl.BlockUntilLoad(10);
mute.Use(p, message);
jail.Use(p, message);
freeze.Use(p, message);
spawn.Use(pl, "");
Player.GlobalMessage(pl.ColoredName + " %Swas released from XJail!");
}
}
PlayerActions.ChangeMap(pl, xjailMap);
pl.BlockUntilLoad(10);
jail.Use(p, message);
Player.GlobalMessage(pl.ColoredName + " %Swas XJailed!");
} else {
if (pl.muted) mute.Use(p, message);
if (pl.frozen) freeze.Use(p, message);
PlayerActions.ChangeMap(pl, Server.mainLevel.name);
pl.BlockUntilLoad(10);
jail.Use(p, message);
spawn.Use(pl, "");
Player.GlobalMessage(pl.ColoredName + " %Swas released from XJail!");
}
}
@ -92,6 +76,6 @@ namespace MCGalaxy.Commands {
Player.Message(p, "/xjail <player> - Mutes <player>, freezes <player> and sends <player> to the XJail map (shortcut = /xj)");
Player.Message(p, "If <player> is already jailed, <player> will be spawned, unfrozen and unmuted");
Player.Message(p, "/xjail set - Sets the map to be used for xjail to your current map and sets jail to current location");
}
}
}
}

View File

@ -521,6 +521,7 @@
<Compile Include="Player\Group\GroupProperties.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" />

View File

@ -663,30 +663,18 @@ namespace MCGalaxy {
}
void CheckLoginJailed() {
//very very sloppy, yes I know.. but works for the time
try {
if (!File.Exists("ranks/jailed.txt")) {
File.Create("ranks/jailed.txt").Close(); return;
}
using (StreamReader reader = new StreamReader("ranks/jailed.txt")) {
string line;
while ((line = reader.ReadLine()) != null) {
string[] parts = line.Split();
if (!parts[0].CaselessEq(name)) continue;
reader.Dispose();
try {
PlayerActions.ChangeMap(this, parts[1]);
Command.all.Find("jail").Use(null, parts[0]);
} catch (Exception ex) {
Kick("Error occured");
Server.ErrorLog(ex);
}
return;
}
}
} catch {
string line = Server.jailed.Find(name);
if (line == null) return;
int space = line.IndexOf(' ');
if (space == -1) return;
string level = line.Substring(space + 1);
try {
PlayerActions.ChangeMap(this, level);
Command.all.Find("jail").Use(null, name);
} catch (Exception ex) {
Kick("Error occured");
Server.ErrorLog(ex);
}
}

106
Player/PlayerExtList.cs Normal file
View File

@ -0,0 +1,106 @@
/*
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) {
lock (locker) {
players.Add(p.ToLower());
lines.Add(p.ToLower() + " " + data.ToLower());
}
}
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 string Find(string p) {
lock (locker) {
int idx = players.IndexOf(p.ToLower());
if (idx == -1) return null;
return lines[idx];
}
}
public int Count { get {
lock (locker)
return players.Count;
} }
public void Save() { Save(path, true); }
public void Save(string path, bool console) {
using (StreamWriter w = File.CreateText(path)) {
lock (locker) {
foreach (string line in lines)
w.WriteLine(line);
}
}
if (console)
Server.s.Log("SAVED: " + path);
}
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) {
// 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.lines.Add(line);
int space = line.IndexOf(' ');
string name = space >= 0 ? line.Substring(0, space) : line;
list.players.Add(line);
}
}
return list;
}
}
}

View File

@ -15,15 +15,14 @@
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace MCGalaxy {
public sealed class PlayerList {
public sealed class PlayerList {
string file;
List<string> players = new List<string>();
readonly object locker = new object();

View File

@ -71,8 +71,7 @@ namespace MCGalaxy {
muted = PlayerList.Load("muted.txt");
frozen = PlayerList.Load("frozen.txt");
hidden = PlayerList.Load("hidden.txt");
//jailed = PlayerList.Load("jailed.txt");
if (!File.Exists("ranks/jailed.txt")) { File.Create("ranks/jailed.txt").Close(); Server.s.Log("CREATED NEW: ranks/jailed.txt"); }
jailed = PlayerExtList.Load("ranks/jailed.txt");
foreach (Group grp in Group.GroupList)
grp.playerList = PlayerList.Load(grp.fileName);

View File

@ -68,7 +68,6 @@ namespace MCGalaxy
public static PlayersFile AutoloadMaps = new PlayersFile("text/autoload.txt");
public static PlayersFile RankInfo = new PlayersFile("text/rankinfo.txt");
public static PlayersFile Jailed = new PlayersFile("ranks/jailed.txt");
public static PlayersFile TempRanks = new PlayersFile("text/tempranks.txt");
public static PlayersFile Notes = new PlayersFile("text/notes.txt");
public static PlayersFile Skins = new PlayersFile("extra/skins.txt");
@ -101,9 +100,9 @@ namespace MCGalaxy
public static bool ServerSetupFinished = false;
public static Auto_CTF ctf = null;
public static PlayerList bannedIP, whiteList, ircControllers, muted, ignored, frozen, hidden;
public static PlayerExtList jailed;
public static readonly List<string> Devs = new List<string>();
public static readonly List<string> Mods = new List<string>();
public static readonly List<string> Devs = new List<string>(), Mods = new List<string>();
internal static readonly List<string> opstats = new List<string>(new [] { "ban", "tempban", "kick", "warn", "mute", "freeze", "undo", "kickban", "demote", "promote" });
public static List<string> Opstats { get { return new List<string>(opstats); } }
@ -118,7 +117,6 @@ namespace MCGalaxy
public static List<Level> levels;
//reviewlist intitialize
public static List<string> reviewlist = new List<string>();
public static List<string> ircafkset = new List<string>();
public static List<string> messages = new List<string>();
@ -209,6 +207,8 @@ namespace MCGalaxy
[ConfigString("main-name", "General", null, "main", false, "._+")]
public static string level = "main";
[ConfigString("xjail-map-name", "Other", null, "(main)", false, "()._+")]
public static string xjailLevel = "(main)";
public static string errlog = "error.log";
[ConfigBool("report-back", "Error handling", null, true)]