예제 #1
0
파일: LobbyRoot.cs 프로젝트: gormel/rts
        void Start()
        {
            if (GameUtils.CurrentMode == GameMode.Client)
            {
                mChannel = new Channel(GameUtils.IP.ToString(), GameUtils.LobbyPort, ChannelCredentials.Insecure);
                mClient  = new LobbyService.LobbyServiceClient(mChannel);
                ListenStates();
                ListenStart();
                StartGameButton.SetActive(false);
            }

            if (GameUtils.CurrentMode == GameMode.Server)
            {
                mServer = new Server();
                mServer.Ports.Add(new ServerPort(IPAddress.Any.ToString(), GameUtils.LobbyPort, ServerCredentials.Insecure));
                mService = new LobbyServiceImpl(GameUtils.Nickname);
                mServer.Services.Add(LobbyService.BindService(mService));
                mService.OnUserStateChanged += ServiceOnOnUserStateChanged;
                mServer.Start();
                StartGameButton.SetActive(true);
                ServiceOnOnUserStateChanged(GameUtils.Nickname, true);
            }
        }
예제 #2
0
파일: Login.xaml.cs 프로젝트: kradchen/sgs
 private void tab1ClearDb_Click(object sender, System.Windows.RoutedEventArgs e)
 {
     LobbyServiceImpl.WipeDatabase();
 }
예제 #3
0
파일: Login.xaml.cs 프로젝트: kradchen/sgs
        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();
        }