Add BBCODE to Horse Descriptions, Player Descriptions and Ranch Descriptions.

This commit is contained in:
SilicaAndPina 2021-02-13 17:47:28 +13:00
parent bdebe4d84a
commit 72bc81d900
14 changed files with 142 additions and 40 deletions

View file

@ -1,4 +1,49 @@
{ {
"bbcode":[
{"tag":"[b]", "meta":"<b>"},
{"tag":"[/b]", "meta":"</b>"},
{"tag":"[i]", "meta":"<i>"},
{"tag":"[/i]", "meta":"</i>"},
{"tag":"[u]", "meta":"<u>"},
{"tag":"[/u]", "meta":"</u>"},
{"tag":"[silver]", "meta":"<font color='#C0C0C0'>"},
{"tag":"[grey]", "meta":"<font color='#808080'>"},
{"tag":"[black]", "meta":"<font color='#000000'>"},
{"tag":"[maroon]", "meta":"<font color='#800000'>"},
{"tag":"[brown]", "meta":"<font color='#A52A2A'>"},
{"tag":"[red]", "meta":"<font color='#FF0000'>"},
{"tag":"[orange]", "meta":"<font color='#FFA500'>"},
{"tag":"[yellow]", "meta":"<font color='#FFFF00'>"},
{"tag":"[lime]", "meta":"<font color='#00FF00'>"},
{"tag":"[green]", "meta":"<font color='#008800'>"},
{"tag":"[olive]", "meta":"<font color='#808000'>"},
{"tag":"[teal]", "meta":"<font color='#008080'>"},
{"tag":"[aqua]", "meta":"<font color='#00FFFF'>"},
{"tag":"[blue]", "meta":"<font color='#0000FF'>"},
{"tag":"[navy]", "meta":"<font color='#000080'>"},
{"tag":"[purple]", "meta":"<font color='#800080'>"},
{"tag":"[fuchsia]", "meta":"<font color='#FF00FF'>"},
{"tag":"[pink]", "meta":"<font color='#FFC0CB'>"},
{"tag":"[turquoise]", "meta":"<font color='#18af8d'>"},
{"tag":"[gold]", "meta":"<font color='#FFD700'>"},
{"tag":"[azure]", "meta":"<font color='#99cdea'>"},
{"tag":"[lilac]", "meta":"<font color='#a986bf'>"},
{"tag":"[umber]", "meta":"<font color='#8a530c'>"},
{"tag":"[rose]", "meta":"<font color='#c65367'>"},
{"tag":"[forest]", "meta":"<font color='#639627'>"},
{"tag":"[beige]", "meta":"<font color='#d6bc97'>"},
{"tag":"[charcoal]", "meta":"<font color='#43413f'>"},
{"tag":"[violet]", "meta":"<font color='#622571'>"},
{"tag":"[mint]", "meta":"<font color='#8cc28c'>"},
{"tag":"[beryl]", "meta":"<font color='#026581'>"},
{"tag":"[apricot]", "meta":"<font color='#eac47e'>"},
{"tag":"[mauve]", "meta":"<font color='#d4c6ec'>"},
{"tag":"[blush]", "meta":"<font color='#d4afb8'>"},
{"tag":"[coral]", "meta":"<font color='#FF7256'>"},
{"tag":"[marigold]", "meta":"<font color='#fcc006'>"},
{"tag":"[chestnut]", "meta":"<font color='#b97a08'>"},
],
"messages":{ "messages":{
"welcome_format":"Welcome to the land of Horse Isle, %USERNAME%!!", "welcome_format":"Welcome to the land of Horse Isle, %USERNAME%!!",
"motd_format":"<FONT COLOR='#FF0000'><B>Today's Note:</B> %MOTD%</FONT>", "motd_format":"<FONT COLOR='#FF0000'><B>Today's Note:</B> %MOTD%</FONT>",
@ -201,6 +246,7 @@
"training_pen":"<BR>^T6You can train all your horses via the Pen^D13|TRAIN ALL^R1", "training_pen":"<BR>^T6You can train all your horses via the Pen^D13|TRAIN ALL^R1",
"train_all":"You attempt to train all of your horses:", "train_all":"You attempt to train all of your horses:",
"train_success":"<BR>Training <B>%HORSENAME%</B>: +%SPEED%SP +%STRENGTH%ST +%CONFORMATION%CO +%AGILITY%AG +%ENDURANCE%EN +%EXP%exp", "train_success":"<BR>Training <B>%HORSENAME%</B>: +%SPEED%SP +%STRENGTH%ST +%CONFORMATION%CO +%AGILITY%AG +%ENDURANCE%EN +%EXP%exp",
"train_bad_mood":"<BR>Training <B>%HORSENAME%</B>: Horse is in way too bad a mood.",
"train_cant_train":"<BR><B>%HORSENAME%</B>: Horse needs to rest %TIME% game minutes.", "train_cant_train":"<BR><B>%HORSENAME%</B>: Horse needs to rest %TIME% game minutes.",
"fully_rested":"<BR>You have a Barn. All of your horses are fully relaxed now.", "fully_rested":"<BR>You have a Barn. All of your horses are fully relaxed now.",
"wagon_used":"Your wagon dropped you off at the nearest station." "wagon_used":"Your wagon dropped you off at the nearest station."
@ -632,7 +678,7 @@
"tired_stat_name":"tired", "tired_stat_name":"tired",
"player_stats":[ "player_stats":[
"not at all %STAT%","a tiny bit %STAT%","a little bit %STAT%", "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%" "desperately %STAT%","incredibly %STAT%","unbearably %STAT%"
], ],
"msg":{ "msg":{

View file

@ -348,7 +348,7 @@ namespace HISP.Game.Chat
foreach(Correction correct in CorrectedWords) foreach(Correction correct in CorrectedWords)
message = message.Replace(correct.FilteredWord, correct.ReplacedWord); message = message.Replace(correct.FilteredWord, correct.ReplacedWord);
return message; return message.Trim();
} }
public static string EscapeMessage(string message) public static string EscapeMessage(string message)
{ {

View file

@ -98,7 +98,7 @@ namespace HISP.Game.Horse
} }
set set
{ {
name = value; name = value.Trim();
Database.SetHorseName(this.RandomId, name); Database.SetHorseName(this.RandomId, name);
} }
} }
@ -110,8 +110,8 @@ namespace HISP.Game.Horse
} }
set set
{ {
description = value; description = value.Trim();
Database.SetHorseDescription(this.RandomId, value); Database.SetHorseDescription(this.RandomId, description);
} }
} }
public string Sex; public string Sex;

View file

@ -61,11 +61,6 @@ namespace HISP.Game.Items
foreach (DroppedItem droppedItem in items) foreach (DroppedItem droppedItem in items)
droppedItemsList.Add(droppedItem); droppedItemsList.Add(droppedItem);
} }
public static void Update()
{
DespawnItems();
GenerateItems(false);
}
public static void RemoveDroppedItem(DroppedItem item) public static void RemoveDroppedItem(DroppedItem item)
{ {
int randomId = item.Instance.RandomId; int randomId = item.Instance.RandomId;
@ -110,12 +105,12 @@ namespace HISP.Game.Items
{ {
Database.DecrementDroppedItemDespawnTimer(); 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. if (droppedItemsList[i] == null) // Item removed in another thread.
continue; continue;
droppedItemsList[i].DespawnTimer--; droppedItemsList[i].DespawnTimer-=5;
if(droppedItemsList[i].DespawnTimer <= 0) 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 if (GameServer.GetUsersAt(droppedItemsList[i].X, droppedItemsList[i].Y, true, true).Length > 0) // Dont despawn items players are standing on

View file

@ -32,7 +32,9 @@ namespace HISP.Game
{ {
int pos = ((x * Height) + y); 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; return 1;
else if (overlay && Treasure.IsTileBuiredTreasure(x, y)) else if (overlay && Treasure.IsTileBuiredTreasure(x, y))
return 193; // Burried Treasure tile. return 193; // Burried Treasure tile.

View file

@ -1,4 +1,5 @@
using HISP.Server; using HISP.Security;
using HISP.Server;
using System; using System;
using System.Drawing; using System.Drawing;
using System.Globalization; using System.Globalization;
@ -70,7 +71,8 @@ namespace HISP.Game
public static string RanchTrainAllAttempt; public static string RanchTrainAllAttempt;
public static string RanchTrainSuccessFormat; public static string RanchTrainSuccessFormat;
public static string RanchTrainCantTrain; public static string RanchTrainBadMoodFormat;
public static string RanchTrainCantTrainFormat;
public static string RanchHorsesFullyRested; public static string RanchHorsesFullyRested;
public static string RanchWagonDroppedYouOff; public static string RanchWagonDroppedYouOff;
@ -756,7 +758,11 @@ namespace HISP.Game
public static string FormatRanchTrainFail(string horseName, int timeout) 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) 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) public static string FormatRanchDescOthers(string description)
{ {
return RanchDescriptionOthersFormat.Replace("%DESCRIPTION%", description); return RanchDescriptionOthersFormat.Replace("%DESCRIPTION%", BBCode.EncodeBBCodeToMeta(description));
} }
public static string FormatRanchSoldMessage(int price) public static string FormatRanchSoldMessage(int price)
{ {
@ -792,7 +798,7 @@ namespace HISP.Game
} }
public static string FormatRanchYoursDescription(string description) 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) public static string FormatBuildingEntry(string name, int price, int buildingId)
{ {
@ -848,7 +854,7 @@ namespace HISP.Game
} }
public static string FormatCantTrain(string horseName) public static string FormatCantTrain(string horseName)
{ {
return RanchTrainCantTrain.Replace("%HORSENAME%", horseName); return RanchTrainCantTrainFormat.Replace("%HORSENAME%", horseName);
} }
public static string FormatRiddlerRiddle(string riddle) public static string FormatRiddlerRiddle(string riddle)
{ {
@ -1160,7 +1166,7 @@ namespace HISP.Game
} }
public static string FormatHorseDescription(string Description) 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) 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) public static string FormatPlayerDescriptionForStatsMenu(string description)
{ {
return StatsDescriptionFormat.Replace("%PLAYERDESC%", description); return StatsDescriptionFormat.Replace("%PLAYERDESC%", BBCode.EncodeBBCodeToMeta(description));
} }
public static string FormatExperience(int expPoints) public static string FormatExperience(int expPoints)

View file

@ -646,6 +646,10 @@ namespace HISP.Game
message += Messages.RanchTrainAllAttempt; message += Messages.RanchTrainAllAttempt;
foreach(HorseInstance horse in user.HorseInventory.HorseList) foreach(HorseInstance horse in user.HorseInventory.HorseList)
{ {
if(horse.BasicStats.Mood < 200)
{
message += Messages.FormatRanchTrainBadMood(horse.Name);
}
if(horse.TrainTimer == 0) if(horse.TrainTimer == 0)
{ {
horse.AdvancedStats.Speed += 1; horse.AdvancedStats.Speed += 1;

View file

@ -192,8 +192,8 @@ namespace HISP.Game
} }
set set
{ {
title = value; title = value.Trim();
Database.SetRanchTitle(Id, value); Database.SetRanchTitle(Id, title);
} }
} }
public string Description public string Description
@ -204,7 +204,7 @@ namespace HISP.Game
} }
set set
{ {
description = value; description = value.Trim();
Database.SetRanchDescription(Id, value); Database.SetRanchDescription(Id, value);
} }
} }

View file

@ -217,8 +217,9 @@ namespace HISP.Player
set set
{ {
Database.SetPlayerNotes(Id, value); privateNotes = value.Trim();
privateNotes = value; Database.SetPlayerNotes(Id, privateNotes);
} }
} }
public string ProfilePage { public string ProfilePage {
@ -227,10 +228,9 @@ namespace HISP.Player
return profilePage; return profilePage;
} }
set set
{ {
profilePage = value.TrimEnd();
Database.SetPlayerProfile(value, Id); Database.SetPlayerProfile(profilePage, Id);
profilePage = value;
} }
} }

View file

@ -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<BBCode> bbcodeTranslations = new List<BBCode>();
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;
}
}
}

View file

@ -9,11 +9,6 @@ namespace HISP.Server
private static int getHexVal(char hex) private static int getHexVal(char hex)
{ {
int val = (int)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)); return val - (val < 58 ? 48 : (val < 97 ? 55 : 87));
} }
public static byte[] StringToByteArray(string hex) public static byte[] StringToByteArray(string hex)
@ -31,6 +26,8 @@ namespace HISP.Server
return arr; return arr;
} }
public static Double PointsToDistance(int x1, int y1, int x2, int y2) 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)); return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));

View file

@ -3753,7 +3753,7 @@ namespace HISP.Server
MySqlCommand sqlCommand = db.CreateCommand(); MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "UPDATE DroppedItems SET DespawnTimer=DespawnTimer-1"; sqlCommand.CommandText = "UPDATE DroppedItems SET DespawnTimer=DespawnTimer-5";
sqlCommand.ExecuteNonQuery(); sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose(); sqlCommand.Dispose();

View file

@ -9,6 +9,7 @@ using HISP.Game.SwfModules;
using HISP.Game.Horse; using HISP.Game.Horse;
using HISP.Game.Items; using HISP.Game.Items;
using System.Globalization; using System.Globalization;
using HISP.Security;
namespace HISP.Server 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<string[]>(); HorseInfo.HorseNames = gameData.horses.names.ToObject<string[]>();
Item.Present = gameData.item.special.present; Item.Present = gameData.item.special.present;
@ -769,7 +780,8 @@ namespace HISP.Server
Messages.RanchTrainAllAttempt = gameData.messages.meta.ranch.special.train_all; Messages.RanchTrainAllAttempt = gameData.messages.meta.ranch.special.train_all;
Messages.RanchTrainSuccessFormat = gameData.messages.meta.ranch.special.train_success; 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.RanchHorsesFullyRested = gameData.messages.meta.ranch.special.fully_rested;
Messages.RanchWagonDroppedYouOff = gameData.messages.meta.ranch.special.wagon_used; Messages.RanchWagonDroppedYouOff = gameData.messages.meta.ranch.special.wagon_used;

View file

@ -89,7 +89,14 @@ namespace HISP.Server
Treasure.AddValue(); Treasure.AddValue();
Database.IncPlayerTirednessForOfflineUsers(); Database.IncPlayerTirednessForOfflineUsers();
DroppedItems.Update();
if (totalMinutesElapsed % 5 == 0)
{
DroppedItems.DespawnItems();
DroppedItems.GenerateItems(false);
}
WildHorse.Update(); WildHorse.Update();
Npc.WanderNpcs(); Npc.WanderNpcs();
minuteTimer.Change(oneMinute, oneMinute); minuteTimer.Change(oneMinute, oneMinute);
@ -2581,8 +2588,6 @@ namespace HISP.Server
string profilePage = packetStr.Split('|')[1]; string profilePage = packetStr.Split('|')[1];
profilePage = profilePage.Substring(0, profilePage.Length - 2); profilePage = profilePage.Substring(0, profilePage.Length - 2);
profilePage = profilePage.Replace("[", "<");
profilePage = profilePage.Replace("]", ">");
sender.LoggedinUser.CharacterId = characterId; sender.LoggedinUser.CharacterId = characterId;
sender.LoggedinUser.ProfilePage = profilePage; sender.LoggedinUser.ProfilePage = profilePage;