IEnumerator AddFriend(string friendName, string groupName, LobbyMessageInfo info)
    {
        LobbyPlayer player = LobbyServer.GetLobbyPlayer(info);

        LogManager.General.Log(string.Format("'{0}' added '{1}' to friend list group '{2}'", player.name, friendName, groupName));

        // Find friends group
        var selectedGroup = player.friends.GetGroupByName(groupName);

        // Get account ID
        string friendAccountId = null;

        yield return(LobbyGameDB.GetAccountIdByPlayerName(friendName, data => {
            friendAccountId = data;
        }));

        // Error getting account ID?
        if (friendAccountId == null)
        {
            Lobby.RPC("FriendAddPlayerDoesntExistError", info.sender, friendName);
            yield break;
        }

        // Trying to add yourself?
        if (friendAccountId == player.accountId)
        {
            Lobby.RPC("FriendAddCantAddYourselfError", info.sender, friendName);
            yield break;
        }

        // Already in friends list?
        if (!player.friends.CanAdd(friendAccountId))
        {
            Lobby.RPC("FriendAddAlreadyExistsError", info.sender, friendName);
            yield break;
        }

        // Add player to the group
        selectedGroup.friends.Add(new Friend(friendAccountId));

        // Send new friends list
        player.OnFriendsListLoaded();

        // Save friends list in database
        yield return(FriendsDB.SetFriends(
                         player.accountId,
                         player.friends,
                         null
                         ));
    }
示例#2
0
    // --------------------------------------------------------------------------------
    // AccountToFriends
    // --------------------------------------------------------------------------------

    // Get friends
    public static Coroutine GetFriends(LobbyPlayer player)
    {
        return(GameDB.instance.StartCoroutine(GameDB.Get <FriendsList>(
                                                  "AccountToFriends",
                                                  player.accountId,
                                                  data => {
            if (data != null)
            {
                player.friends = data;
            }
            else
            {
                player.friends = new FriendsList();
            }

            // Send new friends list
            player.OnFriendsListLoaded();
        }
                                                  )));
    }
    IEnumerator RemoveFriend(string friendName, string groupName, LobbyMessageInfo info)
    {
        LobbyPlayer player = LobbyServer.GetLobbyPlayer(info);

        LogManager.General.Log(string.Format("'{0}' removed '{1}' from friend list group '{2}'", player.name, friendName, groupName));

        // Find friends group
        var selectedGroup = player.friends.GetGroupByName(groupName);

        // Get account ID
        string friendAccountId = null;

        yield return(LobbyGameDB.GetAccountIdByPlayerName(friendName, data => {
            friendAccountId = data;
        }));

        // Error getting account ID?
        if (friendAccountId == null)
        {
            Lobby.RPC("FriendRemovePlayerDoesntExistError", info.sender, friendName);
            yield break;
        }

        // Remove player from the group
        selectedGroup.friends.RemoveAll(friend => friend.accountId == friendAccountId);

        // Send new friends list
        player.OnFriendsListLoaded();

        // Save friends list in database
        yield return(FriendsDB.SetFriends(
                         player.accountId,
                         player.friends,
                         null
                         ));
    }