Interaction logic for ServerPage.xaml
Inheritance: System.Windows.Controls.Page
Ejemplo n.º 1
0
        private void _startServer()
        {
            LobbyServiceImpl gameService = null;
            ServiceHost host = null;
            IPAddress serverIp = tab1IpAddresses.SelectedItem as IPAddress;
            if (serverIp == null)
            {
                _Warn("Please select an IP address");
                return;
            }
            int portNumber;
            if (!int.TryParse(tab1Port.Text, out portNumber))
            {
                _Warn("Please enter a legal port number");
                return;
            }
            busyIndicator.BusyContent = Resources["Busy.LaunchServer"];
            busyIndicator.IsBusy = true;

            //client.Start(isReplay, FileStream = file.open(...))
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += (o, ea) =>
            {
                try
                {
                    ea.Result = false;
                    gameService = new LobbyServiceImpl();
                    gameService.HostingIp = serverIp;

                    host = new ServiceHost(gameService);
                    //, new Uri[] { new Uri(string.Format("net.tcp://{0}:{1}/GameService", serverIp, portNumber)) });
                    var binding = new NetTcpBinding();

                    binding.Security.Mode = SecurityMode.None;
                    binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
                    binding.Security.Transport.ProtectionLevel = ProtectionLevel.None;
                    binding.Security.Message.ClientCredentialType = MessageCredentialType.None;

                    host.AddServiceEndpoint(typeof(ILobbyService), binding, string.Format("net.tcp://{0}:{1}/GameService", serverIp, portNumber));

                    host.Open();
                    ea.Result = true;
                }
                catch (Exception)
                {
                }
            };

            worker.RunWorkerCompleted += (o, ea) =>
            {
                busyIndicator.IsBusy = false;
                if ((bool)ea.Result)
                {
                    ServerPage serverPage = new ServerPage();
                    serverPage.Host = host;
                    serverPage.GameService = gameService;
                    this.NavigationService.Navigate(serverPage);
                    return;
                }
                else
                {
                    MessageBox.Show("Failed to launch server");
                }
            };

            worker.RunWorkerAsync();
        }
Ejemplo n.º 2
0
        private void _startServer()
        {
            LobbyServiceImpl gameService = null;
            ServiceHost      host        = null;
            IPAddress        serverIp    = tab1IpAddresses.SelectedItem as IPAddress;

            if (serverIp == null)
            {
                _Warn("Please select an IP address");
                return;
            }
            int portNumber;

            if (!int.TryParse(tab1Port.Text, out portNumber))
            {
                _Warn("Please enter a legal port number");
                return;
            }
            busyIndicator.BusyContent = Resources["Busy.LaunchServer"];
            busyIndicator.IsBusy      = true;

            //client.Start(isReplay, FileStream = file.open(...))
            BackgroundWorker worker      = new BackgroundWorker();
            bool             hasDatabase = (tab1EnableDb.IsChecked == true);

            worker.DoWork += (o, ea) =>
            {
                try
                {
                    ea.Result = false;
                    if (hasDatabase)
                    {
                        LobbyServiceImpl.EnableDatabase();
                    }
                    LobbyServiceImpl.HostingIp = serverIp;

                    host = new ServiceHost(typeof(LobbyServiceImpl));
                    //, new Uri[] { new Uri(string.Format("net.tcp://{0}:{1}/GameService", serverIp, portNumber)) });
                    var binding = new NetTcpBinding();
                    binding.Security.Mode = SecurityMode.None;
                    binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
                    binding.Security.Transport.ProtectionLevel      = ProtectionLevel.None;
                    binding.Security.Message.ClientCredentialType   = MessageCredentialType.None;
                    binding.MaxBufferPoolSize      = Misc.MaxBugReportSize;
                    binding.MaxBufferSize          = Misc.MaxBugReportSize;
                    binding.MaxReceivedMessageSize = Misc.MaxBugReportSize;
                    host.AddServiceEndpoint(typeof(ILobbyService), binding, string.Format("net.tcp://{0}:{1}/GameService", serverIp, portNumber));
                    host.Open();
                    ea.Result = true;
                }
                catch (Exception)
                {
                }
            };

            worker.RunWorkerCompleted += (o, ea) =>
            {
                busyIndicator.IsBusy = false;
                if ((bool)ea.Result)
                {
                    ServerPage serverPage = new ServerPage();
                    serverPage.Host        = host;
                    serverPage.GameService = gameService;
                    this.NavigationService.Navigate(serverPage);
                }
                else
                {
                    MessageBox.Show("Failed to launch server");
                }
                startButton.IsEnabled = true;
            };

            worker.RunWorkerAsync();
        }