From 72bc81d9002b5d30bfd7e8f81439c124ef81a3f1 Mon Sep 17 00:00:00 2001 From: SilicaAndPina Date: Sat, 13 Feb 2021 17:47:28 +1300 Subject: [PATCH] Add BBCODE to Horse Descriptions, Player Descriptions and Ranch Descriptions. --- DataCollection/gamedata.json | 48 ++++++++++++++++++- .../HorseIsleServer/Game/Chat/Chat.cs | 2 +- .../Game/Horse/HorseInstance.cs | 6 +-- .../Game/Items/DroppedItems.cs | 9 +--- Horse Isle Server/HorseIsleServer/Game/Map.cs | 4 +- .../HorseIsleServer/Game/Messages.cs | 22 +++++---- .../HorseIsleServer/Game/Meta.cs | 4 ++ .../HorseIsleServer/Game/Ranch.cs | 6 +-- .../HorseIsleServer/Player/User.cs | 12 ++--- .../HorseIsleServer/Security/BBCode.cs | 35 ++++++++++++++ .../HorseIsleServer/Server/Converters.cs | 7 +-- .../HorseIsleServer/Server/Database.cs | 2 +- .../HorseIsleServer/Server/GameDataJson.cs | 14 +++++- .../HorseIsleServer/Server/GameServer.cs | 11 +++-- 14 files changed, 142 insertions(+), 40 deletions(-) create mode 100644 Horse Isle Server/HorseIsleServer/Security/BBCode.cs diff --git a/DataCollection/gamedata.json b/DataCollection/gamedata.json index 996bad1..5b04155 100755 --- a/DataCollection/gamedata.json +++ b/DataCollection/gamedata.json @@ -1,4 +1,49 @@ { + "bbcode":[ + {"tag":"[b]", "meta":""}, + {"tag":"[/b]", "meta":""}, + {"tag":"[i]", "meta":""}, + {"tag":"[/i]", "meta":""}, + {"tag":"[u]", "meta":""}, + {"tag":"[/u]", "meta":""}, + {"tag":"[silver]", "meta":""}, + {"tag":"[grey]", "meta":""}, + {"tag":"[black]", "meta":""}, + {"tag":"[maroon]", "meta":""}, + {"tag":"[brown]", "meta":""}, + {"tag":"[red]", "meta":""}, + {"tag":"[orange]", "meta":""}, + {"tag":"[yellow]", "meta":""}, + {"tag":"[lime]", "meta":""}, + {"tag":"[green]", "meta":""}, + {"tag":"[olive]", "meta":""}, + {"tag":"[teal]", "meta":""}, + {"tag":"[aqua]", "meta":""}, + {"tag":"[blue]", "meta":""}, + {"tag":"[navy]", "meta":""}, + {"tag":"[purple]", "meta":""}, + {"tag":"[fuchsia]", "meta":""}, + {"tag":"[pink]", "meta":""}, + {"tag":"[turquoise]", "meta":""}, + {"tag":"[gold]", "meta":""}, + {"tag":"[azure]", "meta":""}, + {"tag":"[lilac]", "meta":""}, + {"tag":"[umber]", "meta":""}, + {"tag":"[rose]", "meta":""}, + {"tag":"[forest]", "meta":""}, + {"tag":"[beige]", "meta":""}, + {"tag":"[charcoal]", "meta":""}, + {"tag":"[violet]", "meta":""}, + {"tag":"[mint]", "meta":""}, + {"tag":"[beryl]", "meta":""}, + {"tag":"[apricot]", "meta":""}, + {"tag":"[mauve]", "meta":""}, + {"tag":"[blush]", "meta":""}, + {"tag":"[coral]", "meta":""}, + {"tag":"[marigold]", "meta":""}, + {"tag":"[chestnut]", "meta":""}, + + ], "messages":{ "welcome_format":"Welcome to the land of Horse Isle, %USERNAME%!!", "motd_format":"Today's Note: %MOTD%", @@ -201,6 +246,7 @@ "training_pen":"
^T6You can train all your horses via the Pen^D13|TRAIN ALL^R1", "train_all":"You attempt to train all of your horses:", "train_success":"
Training %HORSENAME%: +%SPEED%SP +%STRENGTH%ST +%CONFORMATION%CO +%AGILITY%AG +%ENDURANCE%EN +%EXP%exp", + "train_bad_mood":"
Training %HORSENAME%: Horse is in way too bad a mood.", "train_cant_train":"
%HORSENAME%: Horse needs to rest %TIME% game minutes.", "fully_rested":"
You have a Barn. All of your horses are fully relaxed now.", "wagon_used":"Your wagon dropped you off at the nearest station." @@ -632,7 +678,7 @@ "tired_stat_name":"tired", "player_stats":[ "not at all %STAT%","a tiny bit %STAT%","a little bit %STAT%", - "kind of %STAT","%STAT%","really %STAT%","seriously %STAT%", + "kind of %STAT%","%STAT%","really %STAT%","seriously %STAT%", "desperately %STAT%","incredibly %STAT%","unbearably %STAT%" ], "msg":{ diff --git a/Horse Isle Server/HorseIsleServer/Game/Chat/Chat.cs b/Horse Isle Server/HorseIsleServer/Game/Chat/Chat.cs index 6919e19..508492d 100755 --- a/Horse Isle Server/HorseIsleServer/Game/Chat/Chat.cs +++ b/Horse Isle Server/HorseIsleServer/Game/Chat/Chat.cs @@ -348,7 +348,7 @@ namespace HISP.Game.Chat foreach(Correction correct in CorrectedWords) message = message.Replace(correct.FilteredWord, correct.ReplacedWord); - return message; + return message.Trim(); } public static string EscapeMessage(string message) { diff --git a/Horse Isle Server/HorseIsleServer/Game/Horse/HorseInstance.cs b/Horse Isle Server/HorseIsleServer/Game/Horse/HorseInstance.cs index 4c5cfe2..619f0a8 100755 --- a/Horse Isle Server/HorseIsleServer/Game/Horse/HorseInstance.cs +++ b/Horse Isle Server/HorseIsleServer/Game/Horse/HorseInstance.cs @@ -98,7 +98,7 @@ namespace HISP.Game.Horse } set { - name = value; + name = value.Trim(); Database.SetHorseName(this.RandomId, name); } } @@ -110,8 +110,8 @@ namespace HISP.Game.Horse } set { - description = value; - Database.SetHorseDescription(this.RandomId, value); + description = value.Trim(); + Database.SetHorseDescription(this.RandomId, description); } } public string Sex; diff --git a/Horse Isle Server/HorseIsleServer/Game/Items/DroppedItems.cs b/Horse Isle Server/HorseIsleServer/Game/Items/DroppedItems.cs index b509493..5b88bfb 100755 --- a/Horse Isle Server/HorseIsleServer/Game/Items/DroppedItems.cs +++ b/Horse Isle Server/HorseIsleServer/Game/Items/DroppedItems.cs @@ -61,11 +61,6 @@ namespace HISP.Game.Items foreach (DroppedItem droppedItem in items) droppedItemsList.Add(droppedItem); } - public static void Update() - { - DespawnItems(); - GenerateItems(false); - } public static void RemoveDroppedItem(DroppedItem item) { int randomId = item.Instance.RandomId; @@ -110,12 +105,12 @@ namespace HISP.Game.Items { Database.DecrementDroppedItemDespawnTimer(); - for(int i = 0; i < droppedItemsList.Count; i++) + for (int i = 0; i < droppedItemsList.Count; i++) { if (droppedItemsList[i] == null) // Item removed in another thread. continue; - droppedItemsList[i].DespawnTimer--; + droppedItemsList[i].DespawnTimer-=5; if(droppedItemsList[i].DespawnTimer <= 0) { if (GameServer.GetUsersAt(droppedItemsList[i].X, droppedItemsList[i].Y, true, true).Length > 0) // Dont despawn items players are standing on diff --git a/Horse Isle Server/HorseIsleServer/Game/Map.cs b/Horse Isle Server/HorseIsleServer/Game/Map.cs index 4fe9e8a..43bb53d 100755 --- a/Horse Isle Server/HorseIsleServer/Game/Map.cs +++ b/Horse Isle Server/HorseIsleServer/Game/Map.cs @@ -32,7 +32,9 @@ namespace HISP.Game { int pos = ((x * Height) + y); - if (pos >= oMapData.Length && overlay) + if ((pos <= 0 || pos >= oMapData.Length) && overlay) + return 1; + else if ((pos <= 0 || pos >= MapData.Length) && !overlay) return 1; else if (overlay && Treasure.IsTileBuiredTreasure(x, y)) return 193; // Burried Treasure tile. diff --git a/Horse Isle Server/HorseIsleServer/Game/Messages.cs b/Horse Isle Server/HorseIsleServer/Game/Messages.cs index bca73e8..b5bb486 100755 --- a/Horse Isle Server/HorseIsleServer/Game/Messages.cs +++ b/Horse Isle Server/HorseIsleServer/Game/Messages.cs @@ -1,4 +1,5 @@ -using HISP.Server; +using HISP.Security; +using HISP.Server; using System; using System.Drawing; using System.Globalization; @@ -70,7 +71,8 @@ namespace HISP.Game public static string RanchTrainAllAttempt; public static string RanchTrainSuccessFormat; - public static string RanchTrainCantTrain; + public static string RanchTrainBadMoodFormat; + public static string RanchTrainCantTrainFormat; public static string RanchHorsesFullyRested; public static string RanchWagonDroppedYouOff; @@ -756,7 +758,11 @@ namespace HISP.Game public static string FormatRanchTrainFail(string horseName, int timeout) { - return RanchTrainCantTrain.Replace("%HORSENAME%", horseName).Replace("%TIME%", timeout.ToString()); + return RanchTrainCantTrainFormat.Replace("%HORSENAME%", horseName).Replace("%TIME%", timeout.ToString()); + } + public static string FormatRanchTrainBadMood(string horseName) + { + return RanchTrainBadMoodFormat.Replace("%HORSENAME%", horseName); } public static string FormatRanchTrain(string horseName, int speed, int strength, int conformation, int agility, int endurance, int exp) { @@ -764,7 +770,7 @@ namespace HISP.Game } public static string FormatRanchDescOthers(string description) { - return RanchDescriptionOthersFormat.Replace("%DESCRIPTION%", description); + return RanchDescriptionOthersFormat.Replace("%DESCRIPTION%", BBCode.EncodeBBCodeToMeta(description)); } public static string FormatRanchSoldMessage(int price) { @@ -792,7 +798,7 @@ namespace HISP.Game } public static string FormatRanchYoursDescription(string description) { - return RanchYourDescriptionFormat.Replace("%DESCRIPTION%", description); + return RanchYourDescriptionFormat.Replace("%DESCRIPTION%", BBCode.EncodeBBCodeToMeta(description)); } public static string FormatBuildingEntry(string name, int price, int buildingId) { @@ -848,7 +854,7 @@ namespace HISP.Game } public static string FormatCantTrain(string horseName) { - return RanchTrainCantTrain.Replace("%HORSENAME%", horseName); + return RanchTrainCantTrainFormat.Replace("%HORSENAME%", horseName); } public static string FormatRiddlerRiddle(string riddle) { @@ -1160,7 +1166,7 @@ namespace HISP.Game } public static string FormatHorseDescription(string Description) { - return HorseDescriptionFormat.Replace("%DESCRIPTION%", Description); + return HorseDescriptionFormat.Replace("%DESCRIPTION%", BBCode.EncodeBBCodeToMeta(Description)); } public static string FormatHorseHandsHigh(string color, string breed,string sex, double handsHigh) { @@ -1515,7 +1521,7 @@ namespace HISP.Game } public static string FormatPlayerDescriptionForStatsMenu(string description) { - return StatsDescriptionFormat.Replace("%PLAYERDESC%", description); + return StatsDescriptionFormat.Replace("%PLAYERDESC%", BBCode.EncodeBBCodeToMeta(description)); } public static string FormatExperience(int expPoints) diff --git a/Horse Isle Server/HorseIsleServer/Game/Meta.cs b/Horse Isle Server/HorseIsleServer/Game/Meta.cs index 272d577..61eddc8 100755 --- a/Horse Isle Server/HorseIsleServer/Game/Meta.cs +++ b/Horse Isle Server/HorseIsleServer/Game/Meta.cs @@ -646,6 +646,10 @@ namespace HISP.Game message += Messages.RanchTrainAllAttempt; foreach(HorseInstance horse in user.HorseInventory.HorseList) { + if(horse.BasicStats.Mood < 200) + { + message += Messages.FormatRanchTrainBadMood(horse.Name); + } if(horse.TrainTimer == 0) { horse.AdvancedStats.Speed += 1; diff --git a/Horse Isle Server/HorseIsleServer/Game/Ranch.cs b/Horse Isle Server/HorseIsleServer/Game/Ranch.cs index 111d17d..04ccbf8 100644 --- a/Horse Isle Server/HorseIsleServer/Game/Ranch.cs +++ b/Horse Isle Server/HorseIsleServer/Game/Ranch.cs @@ -192,8 +192,8 @@ namespace HISP.Game } set { - title = value; - Database.SetRanchTitle(Id, value); + title = value.Trim(); + Database.SetRanchTitle(Id, title); } } public string Description @@ -204,7 +204,7 @@ namespace HISP.Game } set { - description = value; + description = value.Trim(); Database.SetRanchDescription(Id, value); } } diff --git a/Horse Isle Server/HorseIsleServer/Player/User.cs b/Horse Isle Server/HorseIsleServer/Player/User.cs index a7a8f4a..3fe45a7 100755 --- a/Horse Isle Server/HorseIsleServer/Player/User.cs +++ b/Horse Isle Server/HorseIsleServer/Player/User.cs @@ -217,8 +217,9 @@ namespace HISP.Player set { - Database.SetPlayerNotes(Id, value); - privateNotes = value; + privateNotes = value.Trim(); + Database.SetPlayerNotes(Id, privateNotes); + } } public string ProfilePage { @@ -227,10 +228,9 @@ namespace HISP.Player return profilePage; } set - { - - Database.SetPlayerProfile(value, Id); - profilePage = value; + { + profilePage = value.TrimEnd(); + Database.SetPlayerProfile(profilePage, Id); } } diff --git a/Horse Isle Server/HorseIsleServer/Security/BBCode.cs b/Horse Isle Server/HorseIsleServer/Security/BBCode.cs new file mode 100644 index 0000000..2bef3f9 --- /dev/null +++ b/Horse Isle Server/HorseIsleServer/Security/BBCode.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; + +namespace HISP.Security +{ + public class BBCode + { + public BBCode(string tag, string meta) + { + this.Tag = tag; + this.MetaTranslation = meta; + bbcodeTranslations.Add(this); + } + private static List bbcodeTranslations = new List(); + public string Tag; + public string MetaTranslation; + + public static string EncodeMetaToBBCode(string message) + { + foreach (BBCode code in bbcodeTranslations) + { + message = message.Replace(code.MetaTranslation, code.Tag); + } + return message; + } + public static string EncodeBBCodeToMeta(string message) + { + foreach(BBCode code in bbcodeTranslations) + { + message = message.Replace(code.Tag, code.MetaTranslation); + message = message.Replace(code.Tag.ToUpper(), code.MetaTranslation); + } + return message; + } + } +} diff --git a/Horse Isle Server/HorseIsleServer/Server/Converters.cs b/Horse Isle Server/HorseIsleServer/Server/Converters.cs index 802d3b3..286040c 100755 --- a/Horse Isle Server/HorseIsleServer/Server/Converters.cs +++ b/Horse Isle Server/HorseIsleServer/Server/Converters.cs @@ -9,11 +9,6 @@ namespace HISP.Server private static int getHexVal(char hex) { int val = (int)hex; - //For uppercase A-F letters: - //return val - (val < 58 ? 48 : 55); - //For lowercase a-f letters: - //return val - (val < 58 ? 48 : 87); - //Or the two combined, but a bit slower: return val - (val < 58 ? 48 : (val < 97 ? 55 : 87)); } public static byte[] StringToByteArray(string hex) @@ -31,6 +26,8 @@ namespace HISP.Server return arr; } + + public static Double PointsToDistance(int x1, int y1, int x2, int y2) { return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2)); diff --git a/Horse Isle Server/HorseIsleServer/Server/Database.cs b/Horse Isle Server/HorseIsleServer/Server/Database.cs index a6149eb..ff9d69f 100755 --- a/Horse Isle Server/HorseIsleServer/Server/Database.cs +++ b/Horse Isle Server/HorseIsleServer/Server/Database.cs @@ -3753,7 +3753,7 @@ namespace HISP.Server MySqlCommand sqlCommand = db.CreateCommand(); - sqlCommand.CommandText = "UPDATE DroppedItems SET DespawnTimer=DespawnTimer-1"; + sqlCommand.CommandText = "UPDATE DroppedItems SET DespawnTimer=DespawnTimer-5"; sqlCommand.ExecuteNonQuery(); sqlCommand.Dispose(); diff --git a/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs b/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs index bc7bab8..d9eeccb 100755 --- a/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs +++ b/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs @@ -9,6 +9,7 @@ using HISP.Game.SwfModules; using HISP.Game.Horse; using HISP.Game.Items; using System.Globalization; +using HISP.Security; namespace HISP.Server { @@ -687,6 +688,16 @@ namespace HISP.Server } + // Register BBCODE + int totalBBocdes = gameData.bbcode.Count; + for(int i = 0; i < totalBBocdes; i++) + { + string tag = gameData.bbcode[i].tag; + string meta = gameData.bbcode[i].meta; + BBCode code = new BBCode(tag, meta); + Logger.DebugPrint("Registered BBCODE: " + code.Tag + " to " + code.MetaTranslation); + } + HorseInfo.HorseNames = gameData.horses.names.ToObject(); Item.Present = gameData.item.special.present; @@ -769,7 +780,8 @@ namespace HISP.Server Messages.RanchTrainAllAttempt = gameData.messages.meta.ranch.special.train_all; Messages.RanchTrainSuccessFormat = gameData.messages.meta.ranch.special.train_success; - Messages.RanchTrainCantTrain = gameData.messages.meta.ranch.special.train_cant_train; + Messages.RanchTrainCantTrainFormat = gameData.messages.meta.ranch.special.train_cant_train; + Messages.RanchTrainBadMoodFormat = gameData.messages.meta.ranch.special.train_bad_mood; Messages.RanchHorsesFullyRested = gameData.messages.meta.ranch.special.fully_rested; Messages.RanchWagonDroppedYouOff = gameData.messages.meta.ranch.special.wagon_used; diff --git a/Horse Isle Server/HorseIsleServer/Server/GameServer.cs b/Horse Isle Server/HorseIsleServer/Server/GameServer.cs index 2d97d8a..8e038c1 100755 --- a/Horse Isle Server/HorseIsleServer/Server/GameServer.cs +++ b/Horse Isle Server/HorseIsleServer/Server/GameServer.cs @@ -89,7 +89,14 @@ namespace HISP.Server Treasure.AddValue(); Database.IncPlayerTirednessForOfflineUsers(); - DroppedItems.Update(); + + + if (totalMinutesElapsed % 5 == 0) + { + DroppedItems.DespawnItems(); + DroppedItems.GenerateItems(false); + } + WildHorse.Update(); Npc.WanderNpcs(); minuteTimer.Change(oneMinute, oneMinute); @@ -2581,8 +2588,6 @@ namespace HISP.Server string profilePage = packetStr.Split('|')[1]; profilePage = profilePage.Substring(0, profilePage.Length - 2); - profilePage = profilePage.Replace("[", "<"); - profilePage = profilePage.Replace("]", ">"); sender.LoggedinUser.CharacterId = characterId; sender.LoggedinUser.ProfilePage = profilePage;