// Called first time when starting a new session public void InitPlayer(Player player) { Debug.Assert(FieldPlayer == null, "Not allowed to reinitialize player."); FieldManager = FieldManagerFactory.GetManager(player); FieldPlayer = FieldManager.RequestFieldObject(player); GameServer.Storage.AddPlayer(player); GameServer.BuddyManager.SetFriendSessions(player); Party party = GameServer.PartyManager.GetPartyByMember(player.CharacterId); if (party != null) { party.BroadcastPacketParty(PartyPacket.LoginNotice(player), this); } player.BuddyList.ForEach(buddy => { if (buddy.Friend?.Session?.Connected() ?? false) { Buddy myBuddy = GameServer.BuddyManager.GetBuddyByPlayerAndId(buddy.Friend, buddy.SharedId); buddy.Friend.Session.Send(BuddyPacket.LoginLogoutNotification(myBuddy)); buddy.Friend.Session.Send(BuddyPacket.UpdateBuddy(myBuddy)); } }); }
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 HandleAccept(GameSession session, PacketReader packet) { long buddyId = packet.ReadLong(); Buddy buddy = GameServer.BuddyManager.GetBuddyByPlayerAndId(session.Player, buddyId); Buddy buddyFriend = GameServer.BuddyManager.GetBuddyByPlayerAndId(buddy.Friend, buddyId); buddy.IsFriendRequest = false; buddyFriend.IsPending = false; session.Send(BuddyPacket.AcceptRequest(buddy)); session.Send(BuddyPacket.UpdateBuddy(buddy)); session.Send(BuddyPacket.LoginLogoutNotifcation(buddy)); if (buddy.Friend != null) // TODO: Change to send if online { buddy.Friend.Session.Send(BuddyPacket.UpdateBuddy(buddyFriend)); buddy.Friend.Session.Send(BuddyPacket.AcceptNotification(buddyFriend)); } }
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)); } }
public override void EndSession() { Player.Session = null; GameServer.BuddyManager.SetFriendSessions(Player); FieldManager.RemovePlayer(this, FieldPlayer); GameServer.Storage.RemovePlayer(FieldPlayer.Value); // Should we Join the thread to wait for it to complete? if (Player.Party != null) { Player.Party.CheckOffineParty(Player); } Player.BuddyList.ForEach(buddy => { if (buddy.Friend?.Session?.Connected() ?? false) { Buddy myBuddy = GameServer.BuddyManager.GetBuddyByPlayerAndId(buddy.Friend, buddy.SharedId); buddy.Friend.Session.Send(BuddyPacket.LoginLogoutNotification(myBuddy)); buddy.Friend.Session.Send(BuddyPacket.UpdateBuddy(myBuddy)); } }); }
private static void HandleAccept(GameSession session, PacketReader packet) { long buddyId = packet.ReadLong(); Buddy buddy = GameServer.BuddyManager.GetBuddyByPlayerAndId(session.Player, buddyId); Buddy buddyFriend = GameServer.BuddyManager.GetBuddyByPlayerAndId(buddy.Friend, buddyId); buddy.IsFriendRequest = false; buddyFriend.IsPending = false; session.Send(BuddyPacket.AcceptRequest(buddy)); session.Send(BuddyPacket.UpdateBuddy(buddy)); session.Send(BuddyPacket.LoginLogoutNotification(buddy)); DatabaseManager.Buddies.Update(buddy); DatabaseManager.Buddies.Update(buddyFriend); Player otherPlayer = GameServer.PlayerManager.GetPlayerByName(buddy.Friend.Name); if (otherPlayer != null) { otherPlayer.Session.Send(BuddyPacket.UpdateBuddy(buddyFriend)); otherPlayer.Session.Send(BuddyPacket.AcceptNotification(buddyFriend)); } }