Half-implemented private notes.

This commit is contained in:
SilicaAndPina 2020-12-24 23:00:54 +13:00
parent 1c051433dd
commit 08336c07af
73 changed files with 5554 additions and 36 deletions

View file

@ -40,11 +40,11 @@ namespace HISP.Game
public static string CompetitionGearLegsFormat;
public static string CompetitionGearFeetFormat;
public static string StatsPrivateNotes;
public static string StatsQuests;
public static string StatsMinigameRanking;
public static string StatsAwards;
public static string StatsMisc;
public static string StatsPrivateNotesButton;
public static string StatsQuestsButton;
public static string StatsMinigameRankingButton;
public static string StatsAwardsButton;
public static string StatsMiscButton;
public static string NoJewerlyEquipped;
public static string NoCompetitionGear;
@ -67,6 +67,8 @@ namespace HISP.Game
// Records
public static string ProfileSavedMessage;
public static string PrivateNotesSavedMessage;
public static string PrivateNotesMetaFormat;
// Hay Pile
public static string HasPitchforkMeta;
@ -214,7 +216,10 @@ namespace HISP.Game
// Click
public static string NothingInterestingHere;
public static string FormatPrivateNotes(string privateNotes)
{
return PrivateNotesMetaFormat.Replace("%PRIVATENOTES%", privateNotes);
}
public static string FormatRandomMovementMessage(string statName)
{
return RandomMovement.Replace("%STAT%", statName);

View file

@ -226,7 +226,7 @@ namespace HISP.Game
}
public static string EvenUserStatDistribution(int statValue)
public static string SelectPlayerStatFormat(int statValue)
{
int curValue = 1000;
int devisibleBy = Convert.ToInt32(Math.Floor((decimal)curValue / Messages.StatPlayerFormats.Length));
@ -240,6 +240,16 @@ namespace HISP.Game
}
throw new Exception("A mathematically impossible error occured. please check wether the laws of physics still apply.");
}
public static string BuildPrivateNotes(User user)
{
string message = "";
message += Messages.FormatPrivateNotes(user.PrivateNotes);
message += Messages.ExitThisPlace;
message += Messages.MetaTerminator;
return message;
}
public static string BuildNpcInfo(Npc.NpcEntry npcInfo)
{
string message = "";
@ -282,17 +292,17 @@ namespace HISP.Game
message += Messages.FormatFreeTime(user.FreeMinutes);
message += Messages.FormatPlayerDescriptionForStatsMenu(user.ProfilePage);
message += Messages.FormatExperience(user.Experience);
message += Messages.FormatHungryStat(Messages.FormatPlayerStat(EvenUserStatDistribution(user.Hunger), Messages.StatHunger));
message += Messages.FormatThirstStat(Messages.FormatPlayerStat(EvenUserStatDistribution(user.Thirst), Messages.StatThirst));
message += Messages.FormatTiredStat(Messages.FormatPlayerStat(EvenUserStatDistribution(user.Thirst), Messages.StatTired));
message += Messages.FormatHungryStat(Messages.FormatPlayerStat(SelectPlayerStatFormat(user.Hunger), Messages.StatHunger));
message += Messages.FormatThirstStat(Messages.FormatPlayerStat(SelectPlayerStatFormat(user.Thirst), Messages.StatThirst));
message += Messages.FormatTiredStat(Messages.FormatPlayerStat(SelectPlayerStatFormat(user.Thirst), Messages.StatTired));
message += Messages.FormatGenderStat(user.Gender);
message += Messages.FormatJewelryStat(buildWornJewelery(user));
message += Messages.FormatCompetitionGearStat(buildEquippedCompetitionGear(user));
message += Messages.StatsPrivateNotes;
message += Messages.StatsQuests;
message += Messages.StatsMinigameRanking;
message += Messages.StatsAwards;
message += Messages.StatsMisc;
message += Messages.StatsPrivateNotesButton;
message += Messages.StatsQuestsButton;
message += Messages.StatsMinigameRankingButton;
message += Messages.StatsAwardsButton;
message += Messages.StatsMiscButton;
message += Messages.BackToMap;
message += Messages.MetaTerminator;

View file

@ -38,6 +38,9 @@
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="MySqlConnector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d33d3e53aa5f8c92, processorArchitecture=MSIL">
@ -130,6 +133,9 @@
<ItemGroup>
<None Include="Resources\default_cross_domain.xml" />
</ItemGroup>
<ItemGroup>
<Content Include="icon.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy "$(SolutionDir)..\DataCollection\GameData.json" "$(TargetDir)GameData.json" /Y

View file

@ -107,6 +107,19 @@ namespace HISP.Player
}
}
public string PrivateNotes
{
get
{
return privateNotes;
}
set
{
Database.SetPlayerNotes(Id, value);
privateNotes = value;
}
}
public string ProfilePage {
get
{
@ -269,6 +282,7 @@ namespace HISP.Player
private int subscribedUntil;
private bool subscribed;
private string profilePage;
private string privateNotes;
private int x;
private bool stealth = false;
private int y;
@ -351,7 +365,7 @@ namespace HISP.Player
subscribed = Database.IsUserSubscribed(UserId);
subscribedUntil = Database.GetUserSubscriptionExpireDate(UserId);
profilePage = Database.GetPlayerProfile(UserId);
privateNotes = Database.GetPlayerNotes(UserId);
hunger = Database.GetPlayerHunger(UserId);
thirst = Database.GetPlayerThirst(UserId);
tired = Database.GetPlayerTiredness(UserId);

View file

@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using System.Reflection;
using HISP.Game;
using HISP.Security;
@ -9,7 +10,7 @@ namespace HISP
{
static void Main(string[] args)
{
Console.Title = "HISP - Horse Isle Server Emulator";
Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));
ConfigReader.OpenConfig();
CrossDomainPolicy.GetPolicy();

View file

@ -16,7 +16,7 @@ namespace HISP.Server
{
db.Open();
string UserTable = "CREATE TABLE Users(Id INT, Username TEXT(16),Email TEXT(128),Country TEXT(128),SecurityQuestion Text(128),SecurityAnswerHash TEXT(128),Age INT,PassHash TEXT(128), Salt TEXT(128),Gender TEXT(16), Admin TEXT(3), Moderator TEXT(3))";
string ExtTable = "CREATE TABLE UserExt(Id INT, X INT, Y INT, Money INT, QuestPoints INT, BankBalance BIGINT,ProfilePage Text(1028), CharId INT, ChatViolations INT,Subscriber TEXT(3), SubscribedUntil INT, Experience INT, Tiredness INT, Hunger INT, Thirst INT, FreeMinutes INT)";
string ExtTable = "CREATE TABLE UserExt(Id INT, X INT, Y INT, Money INT, QuestPoints INT, BankBalance BIGINT,ProfilePage Text(1028),PrivateNotes Text(1028), CharId INT, ChatViolations INT,Subscriber TEXT(3), SubscribedUntil INT, Experience INT, Tiredness INT, Hunger INT, Thirst INT, FreeMinutes INT)";
string MailTable = "CREATE TABLE Mailbox(IdTo INT, PlayerFrom TEXT(16),Subject TEXT(128), Message Text(1028), TimeSent INT)";
string BuddyTable = "CREATE TABLE BuddyList(Id INT, IdFriend INT, Pending BOOL)";
string WorldTable = "CREATE TABLE World(Time INT,Day INT, Year INT, Weather TEXT(64))";
@ -207,7 +207,6 @@ namespace HISP.Server
}
public static void SetServerTime(int time, int day, int year)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
@ -262,6 +261,10 @@ namespace HISP.Server
return creationTime;
}
}
public static string GetWorldWeather()
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
@ -1337,7 +1340,7 @@ namespace HISP.Server
throw new Exception("Userid " + id + " Allready in userext.");
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "INSERT INTO UserExt VALUES(@id,@x,@y,0,0,0,'',0,0,'NO',0,0,1000,1000,1000, 360)";
sqlCommand.CommandText = "INSERT INTO UserExt VALUES(@id,@x,@y,0,0,0,'','',0,0,'NO',0,0,1000,1000,1000, 360)";
sqlCommand.Parameters.AddWithValue("@id", id);
sqlCommand.Parameters.AddWithValue("@x", Map.NewUserStartX);
sqlCommand.Parameters.AddWithValue("@y", Map.NewUserStartY);
@ -1371,6 +1374,53 @@ namespace HISP.Server
}
}
public static string GetPlayerNotes(int userId)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
if (CheckUserExtExists(userId))
{
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "SELECT PrivateNotes FROM UserExt WHERE Id=@id";
sqlCommand.Parameters.AddWithValue("@id", userId);
sqlCommand.Prepare();
string privateNotes = sqlCommand.ExecuteScalar().ToString();
sqlCommand.Dispose();
return privateNotes;
}
else
{
throw new KeyNotFoundException("Id " + userId + " not found in database.");
}
}
}
public static void SetPlayerNotes(int id, string notes)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
if (CheckUserExist(id))
{
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "UPDATE UserExt SET PrivateNotes=@notes WHERE Id=@id";
sqlCommand.Parameters.AddWithValue("@notes", notes);
sqlCommand.Parameters.AddWithValue("@id", id);
sqlCommand.Prepare();
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
}
else
{
throw new KeyNotFoundException("Id " + id + " not found in database.");
}
}
}
public static int GetPlayerCharId(int userId)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))

View file

@ -218,6 +218,12 @@ namespace HISP.Server
case PacketBuilder.PACKET_INVENTORY:
GameServer.OnInventoryRequested(this, Packet);
break;
case PacketBuilder.PACKET_DYNAMIC_BUTTON:
GameServer.OnDynamicButtonPressed(this, Packet);
break;
case PacketBuilder.PACKET_DYNAMIC_INPUT:
GameServer.OnDynamicInputReceived(this, Packet);
break;
case PacketBuilder.PACKET_ITEM_INTERACTION:
GameServer.OnItemInteraction(this,Packet);
break;

View file

@ -384,11 +384,15 @@ namespace HISP.Server
Map.NewUserStartX = gameData.new_user.starting_x;
Map.NewUserStartY = gameData.new_user.starting_y;
// Records
Messages.ProfileSavedMessage = gameData.messages.profile_save;
Messages.PrivateNotesSavedMessage = gameData.messages.private_notes_save;
Messages.PrivateNotesMetaFormat = gameData.messages.meta.private_notes_format;
// Announcements
Messages.WelcomeFormat = gameData.messages.welcome_format;
Messages.MotdFormat = gameData.messages.motd_format;
Messages.ProfileSavedMessage = gameData.messages.profile_save;
Messages.LoginMessageFormat = gameData.messages.login_format;
Messages.LogoutMessageFormat = gameData.messages.logout_format;
@ -417,11 +421,11 @@ namespace HISP.Server
Messages.CompetitionGearLegsFormat = gameData.messages.meta.stats_page.competition_gear.legs_format;
Messages.CompetitionGearFeetFormat = gameData.messages.meta.stats_page.competition_gear.feet_format;
Messages.StatsPrivateNotes = gameData.messages.meta.stats_page.stats_private_notes;
Messages.StatsQuests = gameData.messages.meta.stats_page.stats_quests;
Messages.StatsMinigameRanking = gameData.messages.meta.stats_page.stats_minigame_ranking;
Messages.StatsAwards = gameData.messages.meta.stats_page.stats_awards;
Messages.StatsMisc = gameData.messages.meta.stats_page.stats_misc;
Messages.StatsPrivateNotesButton = gameData.messages.meta.stats_page.stats_private_notes;
Messages.StatsQuestsButton = gameData.messages.meta.stats_page.stats_quests;
Messages.StatsMinigameRankingButton = gameData.messages.meta.stats_page.stats_minigame_ranking;
Messages.StatsAwardsButton = gameData.messages.meta.stats_page.stats_awards;
Messages.StatsMiscButton = gameData.messages.meta.stats_page.stats_misc;
Messages.JewelrySelected = gameData.messages.meta.stats_page.msg.jewelry_selected;
Messages.NoJewerlyEquipped = gameData.messages.meta.stats_page.msg.no_jewelry_equipped;

View file

@ -17,7 +17,7 @@ namespace HISP.Server
{
public static Socket ServerSocket;
public static GameClient[] ConnectedClients // Done to prevent Enumerator Changed errors.
{
get {
@ -35,7 +35,7 @@ namespace HISP.Server
*/
private static int gameTickSpeed = 4320; // Changing this to ANYTHING else will cause desync with the client.
private static int totalMinutesElapsed = 0;
private static int oneMinute = 1000 * 60;
private static int oneMinute = 1000 * 60;
private static List<GameClient> connectedClients = new List<GameClient>();
private static Timer gameTimer; // Controls in-game time.
private static Timer minuteTimer; // ticks every real world minute.
@ -49,7 +49,7 @@ namespace HISP.Server
{
totalMinutesElapsed++;
if(totalMinutesElapsed % 8 == 0)
if (totalMinutesElapsed % 8 == 0)
{
Database.IncAllUsersFreeTime(1);
}
@ -62,15 +62,96 @@ namespace HISP.Server
* This section is where all the event handlers live,
* eg: OnMovementPacket is whenever the server receies a movement request from the client.
*/
public static void OnCrossdomainPolicyRequest(GameClient sender)
{
Logger.DebugPrint("Cross-Domain-Policy request received from: " + sender.RemoteIp);
byte[] crossDomainPolicyResponse = CrossDomainPolicy.GetPolicy();
byte[] crossDomainPolicyResponse = CrossDomainPolicy.GetPolicy();
sender.SendPacket(crossDomainPolicyResponse);
}
public static void OnDynamicInputReceived(GameClient sender, byte[] packet)
{
if (!sender.LoggedIn)
{
Logger.ErrorPrint(sender.RemoteIp + " Sent dyamic input when not logged in.");
return;
}
string packetStr = Encoding.UTF8.GetString(packet);
string dynamicInputStr = packetStr.Substring(1, packetStr.Length - 2);
if(dynamicInputStr.Contains("|"))
{
string[] dynamicInput = dynamicInputStr.Split('|');
if(dynamicInput.Length >= 1)
{
int inputId = 0;
try
{
inputId = int.Parse(dynamicInput[0]);
}
catch (FormatException)
{
Logger.ErrorPrint(sender.LoggedinUser.Username + " Tried to send a invalid dynamic input ");
return;
}
if(inputId == 7) // Private Notes
{
if(dynamicInput.Length >= 2)
{
sender.LoggedinUser.PrivateNotes = dynamicInput[1];
byte[] chatPacket = PacketBuilder.CreateChat(Messages.PrivateNotesSavedMessage, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(chatPacket);
return;
}
else
{
Logger.ErrorPrint(sender.LoggedinUser.Username + " Tried to send a invalid dynamic input (private notes, wrong size)");
return;
}
}
}
else
{
Logger.ErrorPrint(sender.LoggedinUser.Username + " Tried to send a invalid dynamic input (wrong size)");
return;
}
}
}
public static void OnDynamicButtonPressed(GameClient sender, byte[] packet)
{
if (!sender.LoggedIn)
{
Logger.ErrorPrint(sender.RemoteIp + " Clicked dyamic button when not logged in.");
return;
}
string packetStr = Encoding.UTF8.GetString(packet);
// Determine which button it is
int buttonId = 0;
string buttonIdStr = packetStr.Substring(1, packetStr.Length - 2);
try
{
buttonId = int.Parse(buttonIdStr);
}
catch (FormatException)
{
Logger.ErrorPrint(sender.LoggedinUser.Username + " Tried to click a invalid dynamic button");
return;
}
if(buttonId == 21) // Private Notes
{
byte[] metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildPrivateNotes(sender.LoggedinUser));
sender.SendPacket(metaPacket);
}
}
public static void OnUserInfoRequest(GameClient sender, byte[] packet)
{
if (!sender.LoggedIn)

View file

@ -27,6 +27,8 @@ namespace HISP.Server
public const byte PACKET_TILE_FLAGS = 0x75;
public const byte PACKET_PLAYSOUND = 0x23;
public const byte PACKET_KEEP_ALIVE = 0x7C;
public const byte PACKET_DYNAMIC_BUTTON = 0x45;
public const byte PACKET_DYNAMIC_INPUT = 0x46;
public const byte PACKET_PLAYER = 0x18;
public const byte PACKET_INVENTORY = 0x17;
public const byte PACKET_TRANSPORT = 0x29;

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB