Esempio n. 1
0
        private void login(object sender, RoutedEventArgs e)
        {
            try
            {
                DuplexChannelFactory <IFishService> channel;
                string hostName = Dns.GetHostName();
                string myIP     = Dns.GetHostByName(hostName).AddressList[0].ToString();
                if (endpoint_box.Text != "")
                {
                    myIP = endpoint_box.Text;
                }
                string endpointStr = "net.tcp://" + myIP + ":13200/CardsLibrary/FishService";
                //channel = new DuplexChannelFactory<IFishService>(this, "FishService", new EndpointAddress( endpointStr));
                //channel.Endpoint.ListenUri = new Uri(endpointStr);
                NetTcpBinding binding = new NetTcpBinding();
                binding.Security.Mode = SecurityMode.None;
                binding.Name          = "FishService";

                channel = new DuplexChannelFactory <IFishService>(this, binding,
                                                                  new EndpointAddress(endpointStr));
                // Activate a MessageBoard object
                fishService = channel.CreateChannel();
            }
            catch (Exception ex)
            {
                ErrorWindow win2 = new ErrorWindow(ex.Message);
                win2.Show();
            }
            try
            {
                if (fishService.AddPlayer(login_box.Text))
                {
                    ViewGameList();

                    user.Username = login_box.Text;
                }
                else
                {
                    ErrorWindow win2 = new ErrorWindow("The username selected is allready in use. Please select another username");
                    win2.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                ErrorWindow win2 = new ErrorWindow(ex.Message);
                win2.Show();
            }
        }
Esempio n. 2
0
        public int createGame(string name)
        {
            int status = fishService.AddGame(name, user.Username);

            if (status == 0)
            {
                fishService.JoinGame(user.Username, name);
                currentScreen = Screen.lobby;
                activateScreen();
                //Console.WriteLine(gameLobby.name);
            }
            else if (status == 1)
            {
                ErrorWindow win2 = new ErrorWindow("A game with that name already exists. Please select a different name");
                win2.ShowDialog();
            }
            else
            {
                ErrorWindow win2 = new ErrorWindow("An error has occured. Please try again.");
                win2.ShowDialog();
            }
            return(status);
        }