Example #1
0
        /// <summary>
        /// This one can be called from the in memory worker thread.
        /// Internally it creates a task on the default scheduler.
        /// After this the scheduler should jump back.
        /// </summary>
        /// <param name="answerer_permanent_id"></param>
        /// <returns></returns>
        internal Task <bool> AnswerFriendRequest(Player answerer, long from_permanent_id, bool accepted)
        {
            if (disposedValue)
            {
                Log.Warning("Tried to answer friend request while player auth is disposing.");
                return(Task.FromResult(false));
            }

            return(Task.Run(async() =>
            {
                if (!await db.AnswerFriendRequest(answerer.permanent_id, from_permanent_id, accepted))
                {
                    return false;
                }

                Player player;
                if (permanent_id_mapped_players.TryGetValue(answerer.permanent_id, out player)) //TODO: Am I sending the event here?
                {
                    var ev = new Event
                    {
                        FriendAcceptedRequest = new Event_FriendAcceptedRequest
                        {
                            PlayerInfo = player.BasicPlayerInfo()
                        }
                    };
                    player.event_stream.Enqueue(ev);

                    in_memory_worker.Schedule(() => BasicPlayerInfoOps.RemoveOne(player.pending_friend_requests_outgoing, answerer.BasicPlayerInfo()));
                }

                return true;
            }));
        }