private List <string> GenerateGameData(bool FullPackageData) { List <string> ReturnList; if (FullPackageData) { ReturnList = new List <string> { GameMode, isGameJoltPlayer.Tobool().ToString(), isGameJoltPlayer ? GameJoltID.ToString() : "", DecimalSeparator, Name, LevelFile, Position.ConvertStringCulture(this), Facing.ToString(), Moving.Tobool().ToString(), Skin, BusyType.ToString(), PokemonVisible.Tobool().ToString(), PokemonPosition.ConvertStringCulture(this), PokemonSkin, PokemonFacing.ToString() }; } else { ReturnList = new List <string> { "", "", "", "", "", LastValidGameData[0] == LevelFile ? "" : LevelFile, LastValidGameData[1] == Position ? "" : Position.ConvertStringCulture(this), LastValidGameData[2] == Facing.ToString() ? "" : Facing.ToString(), LastValidGameData[3] == Moving.Tobool().ToString() ? "" : Moving.Tobool().ToString(), LastValidGameData[4] == Skin ? "" : Skin, LastValidGameData[5] == BusyType.ToString() ? "" : BusyType.ToString(), LastValidGameData[6] == PokemonVisible.Tobool().ToString() ? "" : PokemonVisible.Tobool().ToString(), LastValidGameData[7] == PokemonPosition ? "" : PokemonPosition.ConvertStringCulture(this), LastValidGameData[8] == PokemonSkin ? "" : PokemonSkin, LastValidGameData[9] == PokemonFacing.ToString() ? "" : PokemonFacing.ToString() }; } return(ReturnList); }
/// <summary> /// New Player (Update Player) /// </summary> /// <param name="p">Package</param> /// <param name="ID">Player ID</param> public Player(Package p, int ID) { this.ID = ID; Network = new Networking(p.Client); Update(p, false); if (isGameJoltPlayer) { Core.Setting.OnlineSettingListData.Add(new OnlineSetting(Name, GameJoltID)); } Core.Player.Add(this); Core.Player.SentToPlayer(new Package(Package.PackageTypes.ID, ID.ToString(), p.Client)); for (int i = 0; i < Core.Player.Count; i++) { if (Core.Player[i].ID != ID) { Core.Player.SentToPlayer(new Package(Package.PackageTypes.CreatePlayer, Core.Player[i].ID.ToString(), p.Client)); Core.Player.SentToPlayer(new Package(Package.PackageTypes.GameData, Core.Player[i].ID, Core.Player[i].GenerateGameData(true), p.Client)); } } Core.Player.SendToAllPlayer(new Package(Package.PackageTypes.CreatePlayer, ID.ToString(), null)); Core.Player.SendToAllPlayer(new Package(Package.PackageTypes.GameData, ID, GenerateGameData(true), null)); if (Core.Setting.WelcomeMessage != null) { Core.Player.SentToPlayer(new Package(Package.PackageTypes.ChatMessage, Core.Setting.WelcomeMessage, p.Client)); } Core.Player.SendToAllPlayer(new Package(Package.PackageTypes.ChatMessage, isGameJoltPlayer ? Core.Setting.Token("SERVER_GAMEJOLT", Name, GameJoltID.ToString(), "join the game!") : Core.Setting.Token("SERVER_NOGAMEJOLT", Name, "join the game!"), null)); Core.Logger.Log(isGameJoltPlayer ? Core.Setting.Token("SERVER_GAMEJOLT", Name, GameJoltID.ToString(), "join the game!") : Core.Setting.Token("SERVER_NOGAMEJOLT", Name, "join the game!"), Logger.LogTypes.Info, p.Client); if (Core.Listener.TimeLeft() != null) { Core.Player.SentToPlayer(new Package(Package.PackageTypes.ChatMessage, Core.Setting.Token("SERVER_RESTARTWARNING", Core.Listener.TimeLeft()), p.Client)); } if (Core.Setting.AllowChatChannels) { Core.Player.SentToPlayer(new Package(Package.PackageTypes.ChatMessage, Core.Setting.Token("SERVER_CURRENTCHATCHANNEL", CC_CurrentChatChannel), p.Client)); } }
private DataItems GenerateDataItems() { return(new DataItems( GameMode, IsGameJoltPlayer ? "1" : "0", GameJoltID.ToString(CultureInfo), DecimalSeparator.ToString(), Name, LevelFile, Position.ToP3DString(DecimalSeparator, CultureInfo), Facing.ToString(CultureInfo), Moving ? "1" : "0", Skin, BusyType, PokemonVisible ? "1" : "0", PokemonPosition.ToP3DString(DecimalSeparator, CultureInfo), PokemonSkin, PokemonFacing.ToString(CultureInfo))); }
private void Load() { if (HaveSettingFile(GameJoltID)) { try { using (JsonTextReader Reader = new JsonTextReader(new StringReader(File.ReadAllText(Core.Setting.ApplicationDirectory + "\\Data\\OnlineSetting\\" + GameJoltID.ToString() + ".json")))) { Reader.DateParseHandling = DateParseHandling.DateTime; Reader.FloatParseHandling = FloatParseHandling.Double; int StartObjectDepth = -1; string ObjectPropertyName = null; string PropertyName = null; string TempPropertyName = null; string Name = null; int GameJoltID = -1; string Reason = null; DateTime StartTime = DateTime.Now; int Duration = 0; while (Reader.Read()) { if (Reader.TokenType == JsonToken.StartObject) { StartObjectDepth++; if (TempPropertyName != null && TempPropertyName != ObjectPropertyName) { ObjectPropertyName = TempPropertyName; TempPropertyName = null; } } else if (Reader.TokenType == JsonToken.EndObject) { if (StartObjectDepth == 1 && string.Equals(ObjectPropertyName, "MuteListData", StringComparison.OrdinalIgnoreCase)) { MuteListData.Add(new MuteList(Name, GameJoltID, Reason, StartTime, Duration)); Name = null; GameJoltID = -1; Reason = null; StartTime = DateTime.Now; Duration = 0; } StartObjectDepth--; } if (Reader.TokenType == JsonToken.PropertyName) { TempPropertyName = Reader.Value.ToString(); } else if (Reader.TokenType == JsonToken.Boolean || Reader.TokenType == JsonToken.Bytes || Reader.TokenType == JsonToken.Date || Reader.TokenType == JsonToken.Float || Reader.TokenType == JsonToken.Integer || Reader.TokenType == JsonToken.Null || Reader.TokenType == JsonToken.String) { PropertyName = TempPropertyName; TempPropertyName = null; } if (StartObjectDepth == 1 && string.Equals(ObjectPropertyName, "World Property", StringComparison.OrdinalIgnoreCase)) { if (Reader.TokenType == JsonToken.Boolean || Reader.TokenType == JsonToken.Bytes || Reader.TokenType == JsonToken.Date || Reader.TokenType == JsonToken.Float || Reader.TokenType == JsonToken.Integer || Reader.TokenType == JsonToken.Null || Reader.TokenType == JsonToken.String) { if (string.Equals(PropertyName, "Season", StringComparison.OrdinalIgnoreCase)) { if (Reader.TokenType == JsonToken.Integer) { Season = Reader.Value.ToString().ToInt(); } else { Core.Logger.Log("OnlineSetting.cs: Player " + this.GameJoltID.ToString() + ": World Property.Season does not match the require type. Default value will be used.", Logger.LogTypes.Warning); } } else if (string.Equals(PropertyName, "Weather", StringComparison.OrdinalIgnoreCase)) { if (Reader.TokenType == JsonToken.Integer) { Weather = Reader.Value.ToString().ToInt(); } else { Core.Logger.Log("OnlineSetting.cs: Player " + this.GameJoltID.ToString() + ": World Property.Weather does not match the require type. Default value will be used.", Logger.LogTypes.Warning); } } } } else if (StartObjectDepth == 1 && string.Equals(ObjectPropertyName, "MuteListData", StringComparison.OrdinalIgnoreCase)) { if (Reader.TokenType == JsonToken.Boolean || Reader.TokenType == JsonToken.Bytes || Reader.TokenType == JsonToken.Date || Reader.TokenType == JsonToken.Float || Reader.TokenType == JsonToken.Integer || Reader.TokenType == JsonToken.Null || Reader.TokenType == JsonToken.String) { if (string.Equals(PropertyName, "Name", StringComparison.OrdinalIgnoreCase)) { if (Reader.TokenType == JsonToken.String) { Name = Reader.Value.ToString(); } else { Core.Logger.Log("OnlineSetting.cs: Player " + this.GameJoltID.ToString() + ": MuteListData.Name does not match the require type. Default value will be used.", Logger.LogTypes.Warning); } } else if (string.Equals(PropertyName, "GameJoltID", StringComparison.OrdinalIgnoreCase)) { if (Reader.TokenType == JsonToken.Integer) { GameJoltID = Reader.Value.ToString().ToInt(); } else { Core.Logger.Log("OnlineSetting.cs: Player " + this.GameJoltID.ToString() + ": MuteListData.GameJoltID does not match the require type. Default value will be used.", Logger.LogTypes.Warning); } } else if (string.Equals(PropertyName, "Reason", StringComparison.OrdinalIgnoreCase)) { if (Reader.TokenType == JsonToken.String) { Reason = Reader.Value.ToString(); } else { Core.Logger.Log("OnlineSetting.cs: Player " + this.GameJoltID.ToString() + ": MuteListData.Reason does not match the require type. Default value will be used.", Logger.LogTypes.Warning); } } else if (string.Equals(PropertyName, "StartTime", StringComparison.OrdinalIgnoreCase)) { if (Reader.TokenType == JsonToken.Date) { StartTime = (DateTime)Reader.Value; } else { Core.Logger.Log("OnlineSetting.cs: Player " + this.GameJoltID.ToString() + ": MuteListData.StartTime does not match the require type. Default value will be used.", Logger.LogTypes.Warning); } } else if (string.Equals(PropertyName, "Duration", StringComparison.OrdinalIgnoreCase)) { if (Reader.TokenType == JsonToken.Integer) { Duration = Reader.Value.ToString().ToInt(); } else { Core.Logger.Log("OnlineSetting.cs: Player " + this.GameJoltID.ToString() + ": MuteListData.Duration does not match the require type. Default value will be used.", Logger.LogTypes.Warning); } } } } } } } catch (Exception ex) { ex.CatchError(); } } }
/// <summary> /// Save Player Online Setting /// </summary> public void Save() { try { if (!Directory.Exists(Core.Setting.ApplicationDirectory + "\\Data\\UserSetting")) { Directory.CreateDirectory(Core.Setting.ApplicationDirectory + "\\Data\\UserSetting"); } string ReturnString = ""; if (MuteListData.Count > 0) { foreach (MuteList Data in MuteListData) { ReturnString += string.Format(@" {{ ""Name"": ""{0}"", ""GameJoltID"": {1}, ""Reason"": ""{2}"", ""StartTime"": ""{3}"", ""MuteDuration"": {4} }},", Data.Name, Data.GameJoltID.ToString(), Data.Reason, Data.StartTime.ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffffffK"), Data.Duration.ToString()); } } File.WriteAllText(Core.Setting.ApplicationDirectory + "\\Data\\UserSetting\\" + GameJoltID.ToString() + ".json", string.Format(@"{{ ""Pokémon 3D Server Client Setting File"": {{ ""Name"": ""{0}"", ""GameJoltID"": {1}, ""LastUpdate"": ""{2}"" }}, ""World Property"": {{ ""Season"": {3}, ""Weather"": {4} }} ""MuteListData"": [ {5} ] }}", Name, GameJoltID.ToString(), LastUpdated.ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffffffK"), Season.ToString(), Weather.ToString(), ReturnString), Encoding.UTF8); } catch (Exception ex) { ex.CatchError(); } }
/// <summary> /// Get Player Status. GUI use only. /// </summary> public override string ToString() { return(isGameJoltPlayer ? string.Format("ID: {3} | {0} ({1}) {2}", Name, GameJoltID.ToString(), GetPlayerBusyType(), ID.ToString()) : string.Format("ID: {2} | {0} {1}", Name, GetPlayerBusyType(), ID.ToString())); }