private void HandleFiendFriends(PeerBase peer, FindFriendsRequest request, SendParameters sendParameters)
        {
            try
            {
                var onlineList = new bool[request.UserList.Length];
                var gameIds    = new string[request.UserList.Length];

                for (int i = 0; i < request.UserList.Length; i++)
                {
                    gameIds[i] = string.Empty;
                    PlayerState playerState;
                    if (this.playerDict.TryGetValue(request.UserList[i], out playerState))
                    {
                        onlineList[i] = true;
                        if (playerState.ActiveGame != null)
                        {
                            if ((request.OperationOptions & FindFriendsOptions.CreatedOnGS) == FindFriendsOptions.CreatedOnGS)
                            {
                                if (!playerState.ActiveGame.HasBeenCreatedOnGameServer)
                                {
                                    continue;
                                }
                            }

                            if ((request.OperationOptions & FindFriendsOptions.Visible) == FindFriendsOptions.Visible)
                            {
                                if (!playerState.ActiveGame.IsVisible)
                                {
                                    continue;
                                }
                            }

                            if ((request.OperationOptions & FindFriendsOptions.Open) == FindFriendsOptions.Open)
                            {
                                if (!playerState.ActiveGame.IsOpen)
                                {
                                    continue;
                                }
                            }
                            gameIds[i] = playerState.ActiveGame.Id;
                        }
                    }
                }

                var response = new FindFriendsResponse {
                    IsOnline = onlineList, UserStates = gameIds
                };
                var opResponse = new OperationResponse((byte)OperationCode.FindFriends, response);
                peer.SendOperationResponse(opResponse, sendParameters);
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }
Example #2
0
        private void HandleFiendFriends(PeerBase peer, FindFriendsRequest request, SendParameters sendParameters)
        {
            try
            {
                var onlineList = new bool[request.UserList.Length];
                var gameIds    = new string[request.UserList.Length];

                for (int i = 0; i < request.UserList.Length; i++)
                {
                    PlayerState playerState;
                    if (this.playerDict.TryGetValue(request.UserList[i], out playerState))
                    {
                        onlineList[i] = true;
                        if (playerState.Game != null)
                        {
                            gameIds[i] = playerState.Game.Id;
                        }
                        else
                        {
                            gameIds[i] = string.Empty;
                        }
                    }
                    else
                    {
                        gameIds[i] = string.Empty;
                    }
                }

                var response = new FindFriendsResponse {
                    IsOnline = onlineList, UserStates = gameIds
                };
                var opResponse = new OperationResponse((byte)OperationCode.FiendFriends, response);
                peer.SendOperationResponse(opResponse, sendParameters);
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }