Add 'add buddy'?

This commit is contained in:
SilicaAndPina 2021-03-05 15:29:31 +13:00
parent 362f8a1490
commit b686afed61
10 changed files with 88 additions and 48 deletions

View file

@ -40,7 +40,7 @@ namespace HISP.Server
public static DateTime UnixTimeStampToDateTime(double unixTimeStamp)
{
// Unix timestamp is seconds past epoch
System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToLocalTime();
return dtDateTime;
}

View file

@ -24,7 +24,7 @@ namespace HISP.Server
string UserTable = "CREATE TABLE IF NOT EXISTS 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 IF NOT EXISTS UserExt(Id INT, X INT, Y INT, LastLogin INT, Money INT, QuestPoints INT, BankBalance DOUBLE, BankInterest DOUBLE, ProfilePage Text(1028),IpAddress 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 IF NOT EXISTS Mailbox(RandomId INT, IdTo INT, IdFrom INT, Subject TEXT(128), Message Text(1028), TimeSent INT, BeenRead TEXT(3))";
string BuddyTable = "CREATE TABLE IF NOT EXISTS BuddyList(Id INT, IdFriend INT, Pending TEXT(3))";
string BuddyTable = "CREATE TABLE IF NOT EXISTS BuddyList(Id INT, IdFriend INT)";
string WorldTable = "CREATE TABLE World(Time INT, Day INT, Year INT, StartTime INT)";
string WeatherTable = "CREATE TABLE IF NOT EXISTS Weather(Area TEXT(1028), Weather TEXT(64))";
string InventoryTable = "CREATE TABLE IF NOT EXISTS Inventory(PlayerID INT, RandomID INT, ItemID INT, Data INT)";
@ -4292,7 +4292,7 @@ namespace HISP.Server
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "SELECT COUNT(1) FROM BuddyList WHERE Id=@id OR IdFriend=@id AND Pending='NO'";
sqlCommand.CommandText = "SELECT COUNT(1) FROM BuddyList WHERE Id=@id OR IdFriend=@id";
sqlCommand.Parameters.AddWithValue("@id", id);
sqlCommand.Prepare();
@ -4314,7 +4314,7 @@ namespace HISP.Server
List<int> BuddyList = new List<int>();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "SELECT Id,IdFriend FROM BuddyList WHERE Id=@id OR IdFriend=@id AND Pending='NO'";
sqlCommand.CommandText = "SELECT Id,IdFriend FROM BuddyList WHERE Id=@id OR IdFriend=@id";
sqlCommand.Parameters.AddWithValue("@id", id);
sqlCommand.Prepare();
MySqlDataReader dataReader = sqlCommand.ExecuteReader();
@ -4326,7 +4326,7 @@ namespace HISP.Server
if (adder != id)
BuddyList.Add(adder);
else if (friend != id)
BuddyList.Add(adder);
BuddyList.Add(friend);
}
sqlCommand.Dispose();
@ -4334,23 +4334,6 @@ namespace HISP.Server
}
}
public static bool IsPendingBuddyRequestExist(int id, int friendId)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "SELECT COUNT(1) FROM BuddyList WHERE (Id=@id AND IdFriend=@friendId) OR (Id=@friendid AND IdFriend=@Id) AND Pending='YES'";
sqlCommand.Parameters.AddWithValue("@id", id);
sqlCommand.Parameters.AddWithValue("@friendId", friendId);
sqlCommand.Prepare();
Int32 count = Convert.ToInt32(sqlCommand.ExecuteScalar());
sqlCommand.Dispose();
return count >= 1;
}
}
public static void RemoveBuddy(int id, int friendId)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
@ -4365,27 +4348,14 @@ namespace HISP.Server
sqlCommand.Dispose();
}
}
public static void AcceptBuddyRequest(int id, int friendId)
public static void AddBuddy(int id, int friendId)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "UPDATE BuddyList SET Pending=false WHERE (Id=@id AND IdFriend=@friendId) OR (Id=@friendid AND IdFriend=@Id)";
sqlCommand.Parameters.AddWithValue("@id", id);
sqlCommand.Parameters.AddWithValue("@friendId", friendId);
sqlCommand.Prepare();
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
}
}
public static void AddPendingBuddyRequest(int id, int friendId)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "INSERT INTO BuddyList VALUES(@id,@friendId,'YES')";
sqlCommand.CommandText = "INSERT INTO BuddyList VALUES(@id,@friendId)";
sqlCommand.Parameters.AddWithValue("@id", id);
sqlCommand.Parameters.AddWithValue("@friendId", friendId);
sqlCommand.Prepare();

View file

@ -835,7 +835,7 @@ namespace HISP.Server
Map.NewUserStartY = gameData.messages.new_user.starting_y;
// Warp Command
Messages.SuccessfullyWarpedToPlayer = gameData.messages.commands.warp.player;
Messages.SuccessfullyWarpedToLocation = gameData.messages.commands.warp.location;
Messages.OnlyUnicornCanWarp = gameData.messages.commands.warp.only_unicorn;
@ -847,12 +847,20 @@ namespace HISP.Server
Map.ModIsleX = gameData.messages.commands.mod_isle.x;
Map.ModIsleY = gameData.messages.commands.mod_isle.y;
// Add Buddy
Messages.AddBuddyPending = gameData.messages.meta.player_interaction.add_buddy.add_pending;
Messages.AddBuddyOtherPendingFormat = gameData.messages.meta.player_interaction.add_buddy.other_pending;
Messages.AddBuddyYourNowBuddiesFormat = gameData.messages.meta.player_interaction.add_buddy.add_confirmed;
// Socials
Messages.SocialButton = gameData.messages.meta.player_interaction.socials.socials_button;
Messages.SocialMessageFormat = gameData.messages.meta.player_interaction.socials.socials_message;
Messages.SocialTypeFormat = gameData.messages.meta.player_interaction.socials.socials_menu_type;
// Trade
Messages.TradeWithPlayerFormat = gameData.messages.meta.player_interaction.trade.trading_with;
Messages.TradeWaitingForOtherDone = gameData.messages.meta.player_interaction.trade.trade_wait_for_done;

View file

@ -263,6 +263,25 @@ namespace HISP.Server
sender.SendPacket(metaTag);
}
break;
case PacketBuilder.PLAYER_INTERACTION_ADD_BUDDY:
packetStr = Encoding.UTF8.GetString(packet);
playerIdStr = packetStr.Substring(2, packetStr.Length - 4);
playerId = -1;
try
{
playerId = int.Parse(playerIdStr);
}
catch (FormatException)
{
Logger.ErrorPrint(sender.LoggedinUser.Username + " tried to trade with User ID NaN.");
break;
}
if (IsUserOnline(playerId))
{
User userToAdd = GetUserById(playerId);
sender.LoggedinUser.Friends.AddFriend(userToAdd);
}
break;
case PacketBuilder.PLAYER_INTERACTION_ADD_ITEM:
if (sender.LoggedinUser.TradingWith == null)
break;
@ -4288,6 +4307,7 @@ namespace HISP.Server
if (loggedInUser.TradingWith != null)
loggedInUser.TradingWith.CancelTradeMoved();
loggedInUser.PendingBuddyRequestTo = null;
byte[] moveResponse = PacketBuilder.CreateMovementPacket(loggedInUser.X, loggedInUser.Y, loggedInUser.CharacterId, loggedInUser.Facing, direction, true);
sender.SendPacket(moveResponse);
@ -6242,6 +6262,7 @@ namespace HISP.Server
if (!client.LoggedinUser.MuteLogins && !client.LoggedinUser.MuteAll)
if (client.LoggedinUser.Id != sender.LoggedinUser.Id)
client.SendPacket(logoutMessageBytes);
// Tell clients of diconnect (remove from chat)
byte[] playerRemovePacket = PacketBuilder.CreatePlayerLeavePacket(sender.LoggedinUser.Username);
foreach (GameClient client in ConnectedClients)

View file

@ -61,6 +61,7 @@ namespace HISP.Server
public const byte PLAYER_INTERACTION_ADD_ITEM = 0x29;
public const byte PLAYER_INTERACTION_ACCEPT = 0x2A;
public const byte PLAYER_INTERACTION_TRADE_REJECT = 0x2B;
public const byte PLAYER_INTERACTION_ADD_BUDDY = 0x1E;
public const byte AUCTION_BID_100 = 0x29;
public const byte AUCTION_BID_1K = 0x2A;