mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-26 14:54:12 -04:00
Persist custom set skins and models (Thanks goodlyay), closes #142.
This commit is contained in:
parent
0258839aae
commit
9eaa14593a
@ -57,24 +57,20 @@ namespace MCGalaxy.Commands {
|
|||||||
if (who == null) { Player.SendMessage(p, "Console must provide a player name."); return; }
|
if (who == null) { Player.SendMessage(p, "Console must provide a player name."); return; }
|
||||||
model = message;
|
model = message;
|
||||||
}
|
}
|
||||||
|
model = model.ToLower();
|
||||||
|
|
||||||
if (isBot) {
|
if (isBot) {
|
||||||
pBot.model = model;
|
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);
|
Player.GlobalMessage("Bot " + pBot.name + "'s %Smodel was changed to a &c" + model);
|
||||||
} else {
|
} else {
|
||||||
who.model = model;
|
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);
|
Player.GlobalMessage(who.ColoredName + "'s %Smodel was changed to a &c" + model);
|
||||||
}
|
|
||||||
}
|
Server.Models.DeleteStartsWith(who.name + " ");
|
||||||
|
if (model != "humanoid")
|
||||||
void UpdateModel(byte id, string model, Level level, Player who) {
|
Server.Models.Append(who.name + " " + model);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +92,7 @@ namespace MCGalaxy.Commands {
|
|||||||
|
|
||||||
public override void Use(Player p, string message) {
|
public override void Use(Player p, string message) {
|
||||||
if (p == null) { MessageInGameOnly(p); }
|
if (p == null) { MessageInGameOnly(p); }
|
||||||
string model = message == "" ? "normal" : message;
|
string model = message == "" ? "humanoid" : message;
|
||||||
Command.all.Find("model").Use(p, p.name + " " + model);
|
Command.all.Find("model").Use(p, p.name + " " + model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +71,10 @@ namespace MCGalaxy.Commands {
|
|||||||
Entities.GlobalDespawn(who, true);
|
Entities.GlobalDespawn(who, true);
|
||||||
Entities.GlobalSpawn(who, true);
|
Entities.GlobalSpawn(who, true);
|
||||||
Player.GlobalMessage(who.ColoredName + "'s %Sskin was changed to &c" + skin);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,12 +48,12 @@ namespace MCGalaxy.Commands
|
|||||||
Entities.GlobalSpawn(who, (ushort)who.level.jailx, (ushort)who.level.jaily, (ushort)who.level.jailz,
|
Entities.GlobalSpawn(who, (ushort)who.level.jailx, (ushort)who.level.jaily, (ushort)who.level.jailz,
|
||||||
who.level.jailrotx, who.level.jailroty, true);
|
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);
|
Server.Jailed.Append(who.name.ToLower() + " " + who.level.name);
|
||||||
Player.SendChatFrom(who, who.ColoredName + " %Swas &8jailed", false);
|
Player.SendChatFrom(who, who.ColoredName + " %Swas &8jailed", false);
|
||||||
Player.AddNote(who.name, p, "J");
|
Player.AddNote(who.name, p, "J");
|
||||||
} else {
|
} else {
|
||||||
Server.Jailed.DeleteWord(who.name.ToLower());
|
Server.Jailed.DeleteContains(who.name.ToLower());
|
||||||
who.jailed = false;
|
who.jailed = false;
|
||||||
Command.all.Find("spawn").Use(who, "");
|
Command.all.Find("spawn").Use(who, "");
|
||||||
Player.SendMessage(p, "You freed " + who.name + " from jail");
|
Player.SendMessage(p, "You freed " + who.name + " from jail");
|
||||||
|
@ -37,7 +37,7 @@ namespace MCGalaxy.Commands
|
|||||||
if (Server.muted.Contains(message)) {
|
if (Server.muted.Contains(message)) {
|
||||||
Server.muted.Remove(message);
|
Server.muted.Remove(message);
|
||||||
Player.GlobalMessage(message + Server.DefaultColor + " is not online but is now &bun-muted");
|
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;
|
return;
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ namespace MCGalaxy.Commands
|
|||||||
if (who.muted) {
|
if (who.muted) {
|
||||||
who.muted = false;
|
who.muted = false;
|
||||||
Player.SendChatFrom(who, who.color + who.DisplayName + " %Shas been &bun-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 {
|
} else {
|
||||||
if (p != null && who.group.Permission >= p.group.Permission) {
|
if (p != null && who.group.Permission >= p.group.Permission) {
|
||||||
MessageTooHighRank(p, "mute", false); return;
|
MessageTooHighRank(p, "mute", false); return;
|
||||||
|
@ -132,6 +132,17 @@ namespace MCGalaxy {
|
|||||||
return p.group.Permission >= who.group.Permission;
|
return p.group.Permission >= who.group.Permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Updates the model of the entity with the specified id to all other players. </summary>
|
||||||
|
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
|
#region Position updates
|
||||||
|
|
||||||
|
@ -306,7 +306,6 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DisplayName = name;
|
DisplayName = name;
|
||||||
SkinName = name;
|
|
||||||
name += "+";
|
name += "+";
|
||||||
byte type = message[129];
|
byte type = message[129];
|
||||||
|
|
||||||
@ -390,7 +389,7 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
group = Group.findPlayerGroup(name);
|
group = Group.findPlayerGroup(name);
|
||||||
Loading = true;
|
Loading = true;
|
||||||
if (disconnected) return;
|
if (disconnected) return;
|
||||||
id = FreeId();
|
id = FreeId();
|
||||||
|
|
||||||
if (type != 0x42)
|
if (type != 0x42)
|
||||||
@ -515,7 +514,8 @@ namespace MCGalaxy {
|
|||||||
Game.Team = Team.FindTeam(this);
|
Game.Team = Team.FindTeam(this);
|
||||||
SetPrefix();
|
SetPrefix();
|
||||||
playerDb.Dispose();
|
playerDb.Dispose();
|
||||||
|
LoadCpeData();
|
||||||
|
|
||||||
if (Server.verifyadmins && group.Permission >= Server.verifyadminsrank)
|
if (Server.verifyadmins && group.Permission >= Server.verifyadminsrank)
|
||||||
adminpen = true;
|
adminpen = true;
|
||||||
if (emoteList.Contains(name)) parseSmiley = false;
|
if (emoteList.Contains(name)) parseSmiley = false;
|
||||||
@ -589,6 +589,28 @@ namespace MCGalaxy {
|
|||||||
Loading = false;
|
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() {
|
void CheckOutdatedClient() {
|
||||||
if (appName == null || !appName.StartsWith("ClassicalSharp ")) return;
|
if (appName == null || !appName.StartsWith("ClassicalSharp ")) return;
|
||||||
int spaceIndex = appName.IndexOf(' ');
|
int spaceIndex = appName.IndexOf(' ');
|
||||||
|
@ -78,7 +78,6 @@ namespace MCGalaxy {
|
|||||||
public TimeSpan time;
|
public TimeSpan time;
|
||||||
public string name;
|
public string name;
|
||||||
public string DisplayName;
|
public string DisplayName;
|
||||||
public string SkinName;
|
|
||||||
public string realName;
|
public string realName;
|
||||||
public int warn = 0;
|
public int warn = 0;
|
||||||
public byte id;
|
public byte id;
|
||||||
|
@ -32,10 +32,10 @@ namespace MCGalaxy {
|
|||||||
locker = new object();
|
locker = new object();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Finds all lines which start with the given name. </summary>
|
/// <summary> Finds all lines which caselessly start with the given name. </summary>
|
||||||
public IEnumerable<string> Find(string name) {
|
public IEnumerable<string> Find(string name) {
|
||||||
if (!File.Exists(file)) yield break;
|
if (!File.Exists(file)) yield break;
|
||||||
|
|
||||||
using (StreamReader r = new StreamReader(file)) {
|
using (StreamReader r = new StreamReader(file)) {
|
||||||
string line;
|
string line;
|
||||||
while ((line = r.ReadLine()) != null) {
|
while ((line = r.ReadLine()) != null) {
|
||||||
@ -45,17 +45,35 @@ namespace MCGalaxy {
|
|||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Deletes all lines which contain the given word. </summary>
|
/// <summary> Deletes all lines which start with the given value. </summary>
|
||||||
public void DeleteWord(string word) {
|
public void DeleteStartsWith(string value) {
|
||||||
List<string> lines = new List<string>();
|
if (!File.Exists(file)) return;
|
||||||
|
List<string> lines = new List<string>();
|
||||||
using (StreamReader r = new StreamReader(file)) {
|
using (StreamReader r = new StreamReader(file)) {
|
||||||
string line;
|
string line;
|
||||||
while ((line = r.ReadLine()) != null) {
|
while ((line = r.ReadLine()) != null) {
|
||||||
if (line.Contains(word)) continue;
|
if (line.StartsWith(value)) continue;
|
||||||
lines.Add(line);
|
lines.Add(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
WriteLines(lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Deletes all lines which contain the given value. </summary>
|
||||||
|
public void DeleteContains(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.Contains(value)) continue;
|
||||||
|
lines.Add(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WriteLines(lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WriteLines(List<string> lines) {
|
||||||
lock (locker) {
|
lock (locker) {
|
||||||
using (StreamWriter w = new StreamWriter(file, false)) {
|
using (StreamWriter w = new StreamWriter(file, false)) {
|
||||||
foreach (string line in lines)
|
foreach (string line in lines)
|
||||||
|
@ -80,7 +80,9 @@ namespace MCGalaxy
|
|||||||
public static PlayersFile Muted = new PlayersFile("ranks/muted.txt");
|
public static PlayersFile Muted = new PlayersFile("ranks/muted.txt");
|
||||||
public static PlayersFile Jailed = new PlayersFile("ranks/jailed.txt");
|
public static PlayersFile Jailed = new PlayersFile("ranks/jailed.txt");
|
||||||
public static PlayersFile TempRanks = new PlayersFile("text/tempranks.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 Version Version { get { return System.Reflection.Assembly.GetAssembly(typeof(Server)).GetName().Version; } }
|
||||||
|
|
||||||
public static string VersionString {
|
public static string VersionString {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user