示例#1
0
        public void ProcessRequest(int uid, bool isAccepted, Player arrivedFrom = null)
        {
            Request request;
            lock (RequestsLock)
            {
                if (!WorldRequests.ContainsKey(uid))
                    return;

                request = WorldRequests[uid];
                request.InProgress = true;
            }

            // Someone tried to accept/decline request that don't belongs to him
           if ((request.Target != null && request.Target != arrivedFrom) 
                || (request.Target == null && !request.Owner.Party.PartyMembers.Contains(arrivedFrom)))
                return;
            
            IRequestAction action = null;
            switch (request.Type)
            {
                case RequestType.PartyInvite:
                    action = new PartyAction(request);
                    break;
                case RequestType.DuelInvite:
                    action = new DuelAction(request);
                    break;
                case RequestType.GuildCreate:
                        action = new GuildAction(request, arrivedFrom);
                    break;
                case RequestType.GuildInvite:
                    action = new GuildInviteAction(request);
                    break;
                case RequestType.TradeStart:
                    action = new TradeAction(request);
                    break;
            }

            // process request
            try
            {
                if(action == null)
                    return;

                if (isAccepted)
                    action.Accepted();
                else
                    action.Declined();
            }
            catch(Exception e)
            {
                Log.Error("Process request#{0} exception: {1}", (int)request.Type, e.ToString());
            }
            finally
            {
                // Ensure that we remove request, no matter what happens
                if (!request.Blocking)
                    lock (RequestsLock)
                        UnregisterRequest(request);
            }
        }
示例#2
0
        public void ProcessRequest(int uid, bool isAccepted, Player arrivedFrom = null)
        {
            Request request;

            lock (RequestsLock)
            {
                if (!WorldRequests.ContainsKey(uid))
                {
                    return;
                }

                request            = WorldRequests[uid];
                request.InProgress = true;
            }

            // Someone tried to accept/decline request that don't belongs to him
            if ((request.Target != null && request.Target != arrivedFrom) ||
                (request.Target == null && !request.Owner.Party.PartyMembers.Contains(arrivedFrom)))
            {
                return;
            }

            IRequestAction action = null;

            switch (request.Type)
            {
            case RequestType.PartyInvite:
                action = new PartyAction(request);
                break;

            case RequestType.DuelInvite:
                action = new DuelAction(request);
                break;

            case RequestType.GuildCreate:
                action = new GuildAction(request, arrivedFrom);
                break;

            case RequestType.GuildInvite:
                action = new GuildInviteAction(request);
                break;

            case RequestType.TradeStart:
                action = new TradeAction(request);
                break;
            }

            // process request
            try
            {
                if (action == null)
                {
                    return;
                }

                if (isAccepted)
                {
                    action.Accepted();
                }
                else
                {
                    action.Declined();
                }
            }
            catch (Exception e)
            {
                Logger.WriteLine(LogState.Error, "Process request#{0} exception: {1}", (int)request.Type, e.ToString());
            }
            finally
            {
                // Ensure that we remove request, no matter what happens
                if (!request.Blocking)
                {
                    lock (RequestsLock)
                        UnregisterRequest(request);
                }
            }
        }