diff --git a/Commands/CPE/CmdModel.cs b/Commands/CPE/CmdModel.cs
index cb9ba5aca..54bb8278c 100644
--- a/Commands/CPE/CmdModel.cs
+++ b/Commands/CPE/CmdModel.cs
@@ -57,24 +57,20 @@ namespace MCGalaxy.Commands {
if (who == null) { Player.SendMessage(p, "Console must provide a player name."); return; }
model = message;
}
+ model = model.ToLower();
if (isBot) {
pBot.model = model;
- UpdateModel(pBot.id, model, pBot.level, null);
+ Entities.UpdateModel(pBot.id, model, pBot.level, null);
Player.GlobalMessage("Bot " + pBot.name + "'s %Smodel was changed to a &c" + model);
} else {
who.model = model;
- UpdateModel(who.id, model, who.level, who);
+ Entities.UpdateModel(who.id, model, who.level, who);
Player.GlobalMessage(who.ColoredName + "'s %Smodel was changed to a &c" + model);
- }
- }
-
- void UpdateModel(byte id, string model, Level level, Player who) {
- Player[] players = PlayerInfo.Online.Items;
- foreach (Player pl in players) {
- if (pl.level != level || !pl.HasCpeExt(CpeExt.ChangeModel)) continue;
- byte sendId = (pl == who) ? (byte)0xFF : id;
- pl.SendChangeModel(sendId, model);
+
+ Server.Models.DeleteStartsWith(who.name + " ");
+ if (model != "humanoid")
+ Server.Models.Append(who.name + " " + model);
}
}
@@ -96,7 +92,7 @@ namespace MCGalaxy.Commands {
public override void Use(Player p, string message) {
if (p == null) { MessageInGameOnly(p); }
- string model = message == "" ? "normal" : message;
+ string model = message == "" ? "humanoid" : message;
Command.all.Find("model").Use(p, p.name + " " + model);
}
diff --git a/Commands/CPE/CmdSkin.cs b/Commands/CPE/CmdSkin.cs
index cee11748b..c49c15798 100644
--- a/Commands/CPE/CmdSkin.cs
+++ b/Commands/CPE/CmdSkin.cs
@@ -71,6 +71,10 @@ namespace MCGalaxy.Commands {
Entities.GlobalDespawn(who, true);
Entities.GlobalSpawn(who, true);
Player.GlobalMessage(who.ColoredName + "'s %Sskin was changed to &c" + skin);
+
+ Server.Skins.DeleteStartsWith(who.name + " ");
+ if (skin != who.truename)
+ Server.Skins.Append(who.name + " " + skin);
}
}
diff --git a/Commands/Moderation/CmdJail.cs b/Commands/Moderation/CmdJail.cs
index d9a727e7a..104301995 100644
--- a/Commands/Moderation/CmdJail.cs
+++ b/Commands/Moderation/CmdJail.cs
@@ -48,12 +48,12 @@ 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.DeleteWord(who.name.ToLower());
+ Server.Jailed.DeleteContains(who.name.ToLower());
Server.Jailed.Append(who.name.ToLower() + " " + who.level.name);
Player.SendChatFrom(who, who.ColoredName + " %Swas &8jailed", false);
Player.AddNote(who.name, p, "J");
} else {
- Server.Jailed.DeleteWord(who.name.ToLower());
+ Server.Jailed.DeleteContains(who.name.ToLower());
who.jailed = false;
Command.all.Find("spawn").Use(who, "");
Player.SendMessage(p, "You freed " + who.name + " from jail");
diff --git a/Commands/Moderation/CmdMute.cs b/Commands/Moderation/CmdMute.cs
index 10941e9b9..acf108ecb 100644
--- a/Commands/Moderation/CmdMute.cs
+++ b/Commands/Moderation/CmdMute.cs
@@ -37,7 +37,7 @@ namespace MCGalaxy.Commands
if (Server.muted.Contains(message)) {
Server.muted.Remove(message);
Player.GlobalMessage(message + Server.DefaultColor + " is not online but is now &bun-muted");
- Server.Muted.DeleteWord(who.name.ToLower());
+ Server.Muted.DeleteContains(who.name.ToLower());
}
return;
}
@@ -47,7 +47,7 @@ namespace MCGalaxy.Commands
if (who.muted) {
who.muted = false;
Player.SendChatFrom(who, who.color + who.DisplayName + " %Shas been &bun-muted", false);
- Server.Muted.DeleteWord(who.name.ToLower());
+ Server.Muted.DeleteContains(who.name.ToLower());
} else {
if (p != null && who.group.Permission >= p.group.Permission) {
MessageTooHighRank(p, "mute", false); return;
diff --git a/Player/Entities.cs b/Player/Entities.cs
index 9976cdf38..2207df332 100644
--- a/Player/Entities.cs
+++ b/Player/Entities.cs
@@ -132,6 +132,17 @@ namespace MCGalaxy {
return p.group.Permission >= who.group.Permission;
}
+ /// Updates the model of the entity with the specified id to all other players.
+ public static void UpdateModel(byte id, string model, Level lvl, Player who) {
+ Player[] players = PlayerInfo.Online.Items;
+ foreach (Player pl in players) {
+ if (pl.level != lvl || !pl.HasCpeExt(CpeExt.ChangeModel)) continue;
+ if (who != null && !CanSeeEntity(pl, who)) continue;
+
+ byte sendId = (pl.id == id) ? (byte)0xFF : id;
+ pl.SendChangeModel(sendId, model);
+ }
+ }
#region Position updates
diff --git a/Player/Player.Handlers.cs b/Player/Player.Handlers.cs
index 7b4440d7e..484cd48bb 100644
--- a/Player/Player.Handlers.cs
+++ b/Player/Player.Handlers.cs
@@ -306,7 +306,6 @@ namespace MCGalaxy {
}
}
DisplayName = name;
- SkinName = name;
name += "+";
byte type = message[129];
@@ -390,7 +389,7 @@ namespace MCGalaxy {
group = Group.findPlayerGroup(name);
Loading = true;
- if (disconnected) return;
+ if (disconnected) return;
id = FreeId();
if (type != 0x42)
@@ -515,7 +514,8 @@ namespace MCGalaxy {
Game.Team = Team.FindTeam(this);
SetPrefix();
playerDb.Dispose();
-
+ LoadCpeData();
+
if (Server.verifyadmins && group.Permission >= Server.verifyadminsrank)
adminpen = true;
if (emoteList.Contains(name)) parseSmiley = false;
@@ -589,6 +589,28 @@ namespace MCGalaxy {
Loading = false;
}
+ void LoadCpeData() {
+ try {
+ foreach (string line in Server.Skins.Find(name)) {
+ string[] parts = line.Split(trimChars, 2);
+ if (parts.Length == 1) continue;
+ skinName = parts[1];
+ }
+ } catch (Exception ex) {
+ Server.ErrorLog(ex);
+ }
+
+ try {
+ foreach (string line in Server.Models.Find(name)) {
+ string[] parts = line.Split(trimChars, 2);
+ if (parts.Length == 1) continue;
+ model = parts[1];
+ }
+ } catch (Exception ex) {
+ Server.ErrorLog(ex);
+ }
+ }
+
void CheckOutdatedClient() {
if (appName == null || !appName.StartsWith("ClassicalSharp ")) return;
int spaceIndex = appName.IndexOf(' ');
diff --git a/Player/Player.cs b/Player/Player.cs
index 35b41bd8d..9d505e6a7 100644
--- a/Player/Player.cs
+++ b/Player/Player.cs
@@ -78,7 +78,6 @@ namespace MCGalaxy {
public TimeSpan time;
public string name;
public string DisplayName;
- public string SkinName;
public string realName;
public int warn = 0;
public byte id;
diff --git a/Player/PlayersFile.cs b/Player/PlayersFile.cs
index e227ab505..d8d9946ec 100644
--- a/Player/PlayersFile.cs
+++ b/Player/PlayersFile.cs
@@ -32,10 +32,10 @@ namespace MCGalaxy {
locker = new object();
}
- /// Finds all lines which start with the given name.
+ /// Finds all lines which caselessly start with the given name.
public IEnumerable Find(string name) {
if (!File.Exists(file)) yield break;
-
+
using (StreamReader r = new StreamReader(file)) {
string line;
while ((line = r.ReadLine()) != null) {
@@ -45,17 +45,35 @@ namespace MCGalaxy {
yield break;
}
- /// Deletes all lines which contain the given word.
- public void DeleteWord(string word) {
- List lines = new List();
+ /// 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.Contains(word)) continue;
+ if (line.StartsWith(value)) continue;
lines.Add(line);
}
}
-
+ WriteLines(lines);
+ }
+
+ /// Deletes all lines which contain the given value.
+ public void DeleteContains(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.Contains(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)
diff --git a/Server/Server.cs b/Server/Server.cs
index bf1ba2b09..e857ce132 100644
--- a/Server/Server.cs
+++ b/Server/Server.cs
@@ -80,7 +80,9 @@ namespace MCGalaxy
public static PlayersFile Muted = new PlayersFile("ranks/muted.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 Notes = new PlayersFile("text/notes.txt");
+ public static PlayersFile Skins = new PlayersFile("extra/skins.txt");
+ public static PlayersFile Models = new PlayersFile("extra/models.txt");
public static Version Version { get { return System.Reflection.Assembly.GetAssembly(typeof(Server)).GetName().Version; } }
public static string VersionString {