private static void HandleSendRequest(GameSession session, PacketReader packet) { string otherPlayerName = packet.ReadUnicodeString(); string message = packet.ReadUnicodeString(); Player targetPlayer = GameServer.Storage.GetPlayerByName(otherPlayerName); if (targetPlayer == null) // TODO: Change this so it checks if player exists { return; } if (targetPlayer == session.Player) { session.Send(BuddyPacket.Notice((byte)BuddyNotice.CannotAddSelf, targetPlayer.Name)); return; } if ((byte)session.Player.BuddyList.Count(b => !b.Blocked) >= 100) // 100 is friend limit { session.Send(BuddyPacket.Notice((byte)BuddyNotice.CannotAddFriends, targetPlayer.Name)); } if ((byte)targetPlayer.BuddyList.Count(b => !b.Blocked) >= 100) { session.Send(BuddyPacket.Notice((byte)BuddyNotice.OtherUserCannotAddFriends, targetPlayer.Name)); return; } if (BuddyManager.IsBlocked(session.Player, targetPlayer)) { session.Send(BuddyPacket.Notice((byte)BuddyNotice.DeclinedRequest, targetPlayer.Name)); return; } if (BuddyManager.IsFriend(session.Player, targetPlayer)) { session.Send(BuddyPacket.Notice((byte)BuddyNotice.AlreadyFriends, targetPlayer.Name)); } long id = GuidGenerator.Long(); Buddy buddy = new Buddy(id, targetPlayer, session.Player, message, true, false); Buddy buddyTargetPlayer = new Buddy(id, session.Player, targetPlayer, message, false, true); GameServer.BuddyManager.AddBuddy(buddy); GameServer.BuddyManager.AddBuddy(buddyTargetPlayer); session.Send(BuddyPacket.Notice((byte)BuddyNotice.RequestSent, targetPlayer.Name)); if (targetPlayer != null) // TODO: Change this to only send if player exists { session.Send(BuddyPacket.AddToList(buddy)); } if (targetPlayer != null) // TODO: Change to send if online { targetPlayer.Session.Send(BuddyPacket.AddToList(buddyTargetPlayer)); return; } }
private static void HandleBlock(GameSession session, PacketReader packet) { long buddyId = packet.ReadLong(); string targetName = packet.ReadUnicodeString(); string message = packet.ReadUnicodeString(); if (session.Player.BuddyList.Count(b => b.Blocked) >= 100) // 100 is block limit { session.Send(BuddyPacket.Notice((byte)BuddyNotice.CannotBlock, targetName)); return; } if (!DatabaseManager.Characters.NameExists(targetName)) { session.Send(BuddyPacket.Notice((byte)BuddyNotice.CharacterNotFound, targetName)); return; } Player targetPlayer = GameServer.PlayerManager.GetPlayerByName(targetName); if (targetPlayer == null) // If the player is not online, get player data from database { targetPlayer = DatabaseManager.Characters.FindPartialPlayerByName(targetName); targetPlayer.BuddyList = GameServer.BuddyManager.GetBuddies(targetPlayer.CharacterId); } if (buddyId == 0) // if buddy doesn't exist, create Buddy { long id = GuidGenerator.Long(); Buddy buddy = new(id, session.Player.CharacterId, targetPlayer, message, false, false, true); GameServer.BuddyManager.AddBuddy(buddy); session.Player.BuddyList.Add(buddy); session.Send(BuddyPacket.AddToList(buddy)); session.Send(BuddyPacket.Block(buddy)); } else { Buddy buddy = GameServer.BuddyManager.GetBuddyByPlayerAndId(session.Player, buddyId); Buddy buddyFriend = GameServer.BuddyManager.GetBuddyByPlayerAndId(buddy.Friend, buddyId); if (targetPlayer.Session != null && targetPlayer.Session.Connected()) { targetPlayer.BuddyList.Remove(buddyFriend); targetPlayer.Session.Send(BuddyPacket.RemoveFromList(buddyFriend)); } GameServer.BuddyManager.RemoveBuddy(buddyFriend); buddy.BlockReason = message; buddy.Blocked = true; session.Send(BuddyPacket.UpdateBuddy(buddy)); session.Send(BuddyPacket.Block(buddy)); DatabaseManager.Buddies.Update(buddy); DatabaseManager.Buddies.Delete(buddyFriend.Id); } }
private static void HandleBlock(GameSession session, PacketReader packet) { long buddyId = packet.ReadLong(); string target = packet.ReadUnicodeString(); string message = packet.ReadUnicodeString(); if ((byte)session.Player.BuddyList.Count(b => b.Blocked) >= 100) // 100 is block limit { session.Send(BuddyPacket.Notice((byte)BuddyNotice.CannotBlock, target)); return; } Player targetPlayer = GameServer.Storage.GetPlayerByName(target); if (buddyId == 0) // if buddy doesn't exist, create Buddy { long id = GuidGenerator.Long(); Buddy buddy = new Buddy(id, targetPlayer, session.Player, message, false, false, true); GameServer.BuddyManager.AddBuddy(buddy); session.Send(BuddyPacket.AddToList(buddy)); session.Send(BuddyPacket.Block(buddy)); } else { Buddy buddy = GameServer.BuddyManager.GetBuddyByPlayerAndId(session.Player, buddyId); Buddy buddyFriend = GameServer.BuddyManager.GetBuddyByPlayerAndId(buddy.Friend, buddyId); if (buddy.Friend != null) // TODO: Change to send if online { buddy.Friend.Session.Send(BuddyPacket.RemoveFromList(buddyFriend)); } GameServer.BuddyManager.RemoveBuddy(buddyFriend); buddy.Friend.BuddyList.Remove(buddyFriend); buddy.BlockReason = message; buddy.Blocked = true; session.Send(BuddyPacket.UpdateBuddy(buddy)); session.Send(BuddyPacket.Block(buddy)); } }
private static void HandleSendRequest(GameSession session, PacketReader packet) { string otherPlayerName = packet.ReadUnicodeString(); string message = packet.ReadUnicodeString(); if (!DatabaseManager.Characters.NameExists(otherPlayerName)) { session.Send(BuddyPacket.Notice((byte)BuddyNotice.CharacterNotFound, otherPlayerName)); return; } Player targetPlayer = GameServer.PlayerManager.GetPlayerByName(otherPlayerName); if (targetPlayer == null) // If the player is not online, get player data from database { targetPlayer = DatabaseManager.Characters.FindPartialPlayerByName(otherPlayerName); targetPlayer.BuddyList = GameServer.BuddyManager.GetBuddies(targetPlayer.CharacterId); } if (targetPlayer.CharacterId == session.Player.CharacterId) { session.Send(BuddyPacket.Notice((byte)BuddyNotice.CannotAddSelf, targetPlayer.Name)); return; } if (session.Player.BuddyList.Count(b => !b.Blocked) >= 100) // 100 is friend limit { session.Send(BuddyPacket.Notice((byte)BuddyNotice.CannotAddFriends, targetPlayer.Name)); return; } if (targetPlayer.BuddyList.Count(b => !b.Blocked) >= 100) { session.Send(BuddyPacket.Notice((byte)BuddyNotice.OtherUserCannotAddFriends, targetPlayer.Name)); return; } if (BuddyManager.IsBlocked(session.Player, targetPlayer)) { session.Send(BuddyPacket.Notice((byte)BuddyNotice.DeclinedRequest, targetPlayer.Name)); return; } if (BuddyManager.IsFriend(session.Player, targetPlayer)) { session.Send(BuddyPacket.Notice((byte)BuddyNotice.AlreadyFriends, targetPlayer.Name)); return; } long id = GuidGenerator.Long(); Buddy buddy = new(id, session.Player.CharacterId, targetPlayer, message, true, false); Buddy buddyTargetPlayer = new(id, targetPlayer.CharacterId, session.Player, message, false, true); GameServer.BuddyManager.AddBuddy(buddy); GameServer.BuddyManager.AddBuddy(buddyTargetPlayer); session.Player.BuddyList.Add(buddy); session.Send(BuddyPacket.Notice((byte)BuddyNotice.RequestSent, targetPlayer.Name)); session.Send(BuddyPacket.AddToList(buddy)); if (targetPlayer.Session != null && targetPlayer.Session.Connected()) { targetPlayer.BuddyList.Add(buddyTargetPlayer); targetPlayer.Session.Send(BuddyPacket.AddToList(buddyTargetPlayer)); } }