public static FriendInviteR ( |
||
client | ||
result | FriendInviteResult | |
friend | Aura.Msgr.Database.Friend | Required for success, otherwise can be left null. |
return | void |
public void PlayerBlock(MsgrClient client, Packet packet) { var characterName = packet.GetString(); var serverName = packet.GetString(); // Get user var friend = MsgrServer.Instance.Database.GetFriendFromUser(characterName, serverName); if (friend == null) { Send.FriendInviteR(client, FriendInviteResult.UserNotFound); return; } // Check account if (friend.AccountId == client.User.AccountId) { Send.FriendInviteR(client, FriendInviteResult.OwnAccount); return; } // Check existing friends if (client.User.Friends.Exists(a => a.Id == friend.Id)) { Send.FriendInviteR(client, FriendInviteResult.AlreadyFriends); return; } // Check max friends var max = MsgrServer.Instance.Conf.Msgr.MaxFriends; if (max != 0 && client.User.Friends.Count >= max) { Send.FriendInviteR(client, FriendInviteResult.MaxReached); return; } friend.FriendshipStatus = FriendshipStatus.Blacklist; // Add client.User.Friends.Add(friend); MsgrServer.Instance.Database.Blacklist(client.User.Id, friend.Id); Send.FriendInviteR(client, FriendInviteResult.Success, friend); }
public void FriendInvite(MsgrClient client, Packet packet) { var characterName = packet.GetString(); var serverName = packet.GetString(); // Get user var friend = MsgrServer.Instance.Database.GetFriendFromUser(characterName, serverName); if (friend == null) { Send.FriendInviteR(client, FriendInviteResult.UserNotFound); return; } // Check account if (friend.AccountId == client.User.AccountId) { Send.FriendInviteR(client, FriendInviteResult.OwnAccount); return; } // Check blacklist, don't let people add someone who blacklisted them if (MsgrServer.Instance.Database.IsBlacklisted(friend.Id, client.User.Id)) { Send.FriendInviteR(client, FriendInviteResult.UnknownError); return; } // Check existing friends if (client.User.Friends.Exists(a => a.Id == friend.Id)) { Send.FriendInviteR(client, FriendInviteResult.AlreadyFriends); return; } // Check max friends var max = MsgrServer.Instance.Conf.Msgr.MaxFriends; if (max != 0 && client.User.Friends.Count >= max) { Send.FriendInviteR(client, FriendInviteResult.MaxReached); return; } // Check friend's max friends var count = MsgrServer.Instance.Database.CountFriends(friend.Id); if (max != 0 && count >= max) { Send.FriendInviteR(client, FriendInviteResult.UserMaxReached); return; } friend.FriendshipStatus = FriendshipStatus.Inviting; // Add client.User.Friends.Add(friend); MsgrServer.Instance.Database.InviteFriend(client.User.Id, friend.Id); Send.FriendInviteR(client, FriendInviteResult.Success, friend); // Notify friend var friendUser = MsgrServer.Instance.UserManager.Get(friend.Id); if (friendUser != null) { // Get user as friend object to add to friend's friends, // otherwise the relation check in the live answer will fail. // TODO: I hate this, the current Friend concept sucks, // they're not even *really* needed... remove them. var userAsFriend = MsgrServer.Instance.Database.GetFriendFromUser(client.User.Name, client.User.Server); if (userAsFriend == null) { Log.Error("FriendInvite: Failed to query user as friend for new friend's friends. Friends friends friends."); } else { userAsFriend.FriendshipStatus = FriendshipStatus.Invited; friendUser.Friends.Add(userAsFriend); Send.FriendConfirm(friendUser, client.User); } } }