Exemple #1
0
 private void Do()
 {
     while (Run)
     {
         EventRequest eventRequest = null;
         EventRequests.TryDequeue(out eventRequest);
         if (eventRequest != null)
         {
             DispatchEventRequest(eventRequest);
         }
     }
 }
        public void SendMessage(int userId, string message)
        {
            var requestObject = new Dictionary <string, string> {
                { "userId", userId.ToString() }, { "message", message }
            };
            var request = new EventRequest
            {
                RequestType   = EventRequestType.SendMessage,
                RequestObject = requestObject
            };

            AddRequest(request);
        }
        private async void HandleAcceptInvitation(EventRequest eventRequest)
        {
            try {
                Invitation inv = (Invitation)eventRequest.RequestObject;
                if (inv != null)
                {
                    inv = await QuoridorWebService.AcceptInvitation(inv);

                    var handler = StartGame;
                    handler?.Invoke(this, new InvitationHandshake {
                        Invitation = inv, EventMessage = ""
                    });
                }
            } catch (Exception ex) {
                Debug.WriteLine("Failed to handle invitation acceptance:" + ex.Message);
            }
        }
        private async void HandleSendingInvitation(EventRequest eventRequest)
        {
            try {
                String invitedPlayerId = (String)eventRequest.RequestObject;
                if (invitedPlayerId != null)
                {
                    Invitation inv = await QuoridorWebService.InvitePlayer(invitedPlayerId);

                    await Task.Delay(NextCallDelay);

                    AddRequest(new EventRequest {
                        RequestType = EventRequestType.CheckAcceptedInvitation, RequestObject = inv
                    });
                }
            } catch (Exception ex) {
                Debug.WriteLine("Failed to send invitation:" + ex.Message);
            }
        }
        protected override void DispatchEventRequest(EventRequest eventRequest)
        {
            switch (eventRequest.RequestType)
            {
            case EventRequestType.LogIn:
                HandleLogInRequest(eventRequest);
                break;

//                case EventRequestType.CheckMessages:
//                    HandleCheckMessagesRequest();
//                    break;
            case EventRequestType.GetLoggedUsers:
                HandleGetLoggedUsers();
                break;

            case EventRequestType.CheckGameEvents:
                HandleCheckGameEvents();
                break;

            case EventRequestType.SendMessage:
                HandleSendMessage(eventRequest);
                break;

            case EventRequestType.CheckAwaitingInvitation:
                HandleAwaitingInvitations(eventRequest);
                break;

            case EventRequestType.Invite:
                HandleSendingInvitation(eventRequest);
                break;

            case EventRequestType.AcceptInvitation:
                HandleAcceptInvitation(eventRequest);
                break;

            case EventRequestType.CheckAcceptedInvitation:
                HandleAcceptedInvitation(eventRequest);
                break;

            case EventRequestType.SendGameEvent:
                break;
            }
        }
        public void LogIn(string username, string password)
        {
            if (!IsRunning())
            {
                Start();
            }

            var credentials = new Dictionary <string, string>();

            credentials.Add("username", username);
            credentials.Add("password", password);
            var request = new EventRequest
            {
                RequestType   = EventRequestType.LogIn,
                RequestObject = credentials
            };

            AddRequest(request);
        }
Exemple #7
0
 protected abstract void DispatchEventRequest(EventRequest eventRequest);
Exemple #8
0
 public void AddRequest(EventRequest eventRequest)
 {
     EventRequests.Enqueue(eventRequest);
 }
 private void HandleSendMessage(EventRequest eventRequest)
 {
     var requestObject = (Dictionary <string, string>)eventRequest.RequestObject;
     // QuoridorWebService.SendMessage(requestObject["userId"], requestObject["message"]);
 }