Exemplo n.º 1
0
        private void CloseRoom_Click(object sender, RoutedEventArgs e)
        {
            JoinRoomRequest joinRoomRequest = new JoinRoomRequest
            {
                roomId = Communicator.roomId
            };
            string req  = JsonConvert.SerializeObject(joinRoomRequest);
            byte   code = isAdmin ? (byte)ReqCode.CLOSEROOM : (byte)ReqCode.LEAVEROOM;

            Communicator.Send(req, code);
            NavigationService.Navigate(new AfterLogging());
            MainWindow.openedRoom = false;
            gameStarted           = true; // to stop checking
        }
Exemplo n.º 2
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (openedRoom) // then close the room
     {
         JoinRoomRequest joinRoomRequest = new JoinRoomRequest
         {
             roomId = Communicator.roomId
         };
         string req = JsonConvert.SerializeObject(joinRoomRequest);
         Communicator.Send(req, (byte)ReqCode.CLOSEROOM);
     }
     if (isLoggedIn) // then logout
     {
         Communicator.Send("", (byte)ReqCode.LOGOUT);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Joins a room
        /// </summary>
        /// <returns>
        /// None
        /// </returns>
        /// <param name="roomId">The id of the room</param>
        private async void JoinRoom(int roomId)
        {
            JoinRoomRequest req = new JoinRoomRequest
            {
                roomId = roomId
            };

            byte[]           buf = null;
            JoinRoomResponse res;

            await DialogHost.Show(new Dialogs.LoadingDialog(), async delegate(object s, DialogOpenedEventArgs eventArgs)
            {
                // If already got a result
                if (buf != null)
                {
                    return;
                }

                // Send the join room request to the server
                await Client.Send(JoinRoomRequest.CODE, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(req)));

                // Get the response from the server and deserialize it
                buf = await Client.Recv();
                res = JsonConvert.DeserializeObject <JoinRoomResponse>(Encoding.UTF8.GetString(buf));

                // If joined room successfully, show it
                if (res.status == 0)
                {
                    // Close the dialog
                    eventArgs.Session.Close();

                    // Close this window and show the room member window
                    new RoomMemberWindow
                    {
                        room = Rooms[roomsList.SelectedIndex]
                    }.Show();
                    Close();
                }
                else
                {
                    // Show the error dialog
                    eventArgs.Session.UpdateContent((new Dialogs.MessageDialog {
                        Message = "Unable to join the wanted room!"
                    }));
                }
            });
        }