public CreateLobbyViewModel()
        {
            IsPageEnabled = true;

            NumberOfColours = new ObservableCollection <int>();
            SetNumberOfColours(2);

            NumberOfPlayers = new int[MAX_PLAYERS - 1];
            for (int i = 0; i < MAX_PLAYERS - 1; i++)
            {
                NumberOfPlayers[i] = i + 2;
            }

            ReadyCommand      = new CommandHandler(Ready);
            CancelCommand     = new CommandHandler(Cancel);
            StartCommand      = new CommandHandler(Start);
            BackCommand       = new CommandHandler(Back);
            DisconnectCommand = new CommandHandler(Disconnect);

            bots = new Dictionary <BotDifficulty, int>();
            bots[BotDifficulty.EASY]   = 0;
            bots[BotDifficulty.MEDIUM] = 0;
            bots[BotDifficulty.HARD]   = 0;

            IncreaseBotCommand = new ParameterizedCommandHandler(IncreaseBot, IsIncreaseBotEnabled);
            DecreaseBotCommand = new ParameterizedCommandHandler(DecreaseBot, IsDecreaseBotEnabled);

            connectedPlayerAdapter = new List <Player>();
            connectedPlayers       = new ObservableCollection <Player>();

            lobbyServer = ClientProxyManager.Instance;
        }
Beispiel #2
0
        public ConnectLobbyViewModel()
        {
            IsPageEnabled = true;

            availableLobbyProvider = ClientProxyManager.Instance;
            BackCommand            = new CommandHandler(Back);
            RefreshCommand         = new CommandHandler(Refresh);
            ConnectCommand         = new CommandHandler(Connect);

            lobbyServer = ClientProxyManager.Instance;
        }
Beispiel #3
0
 private void btnCreateLobby_Click(object sender, EventArgs e)
 {
     if (this.joinedLobby == null && this.createdLobby == null && !this.connectingToLobby)
     {
         this.createdLobby = this.network.CreateLobby(8, this);
         if (this.createdLobby != null)
         {
             this.connectingToLobby = true;
             this.createdLobby.StartAnnouncing();
             UpdateControls();
         }
     }
 }
        /// <summary>
        /// Creates a new DSS-lobby with the given maximum number of operators.
        /// </summary>
        /// <param name="opCount">The maximum number of operators in the DSS (including the host itself).</param>
        /// <param name="network">The network interface that is used to connect.</param>
        /// <param name="simulatorIface">Interface of the local simulator implemented by the client module.</param>
        /// <param name="setupIface">Interface of the setup manager object implemented by the client module.</param>
        /// <remarks>The caller thread will be blocked during the whole lifetime of the DSS.</remarks>
        public static void CreateDSS(int opCount, INetwork network, ISimulator simulatorIface, IDssHostSetup setupIface)
        {
            if (opCount < 2)
            {
                throw new ArgumentOutOfRangeException("opCount");
            }
            if (network == null)
            {
                throw new ArgumentNullException("network");
            }
            if (simulatorIface == null)
            {
                throw new ArgumentNullException("simulatorIface");
            }
            if (setupIface == null)
            {
                throw new ArgumentNullException("setupIface");
            }

            dssActive.WaitOne();

            try
            {
                DssHostRoot      hostRoot = new DssHostRoot(simulatorIface, setupIface, opCount);
                HostEventHandler eventHdl = new HostEventHandler(hostRoot);
                hostRoot.EventQueue.RegisterHandler(eventHdl);

                ILobbyServer server = network.CreateLobby(opCount, hostRoot.EventQueue);
                if (server == null)
                {
                    throw new DssException("Cannot create the lobby under the DSS!");
                }
                server.StartAnnouncing(); /// TODO: add ILobbyCustomDataProvider if necessary
                hostRoot.Lobby = server;
                hostRoot.EventQueue.EventLoop();
                server.Shutdown();

                hostRoot.Dispose();
            }
            catch (Exception ex)
            {
                TraceManager.WriteExceptionAllTrace(ex, false);
            }
            finally
            {
                dssActive.Release();
            }
        }
Beispiel #5
0
 /// <see cref="ILobbyListener.LobbyLost"/>
 public void LobbyLost()
 {
     if (this.InvokeRequired)
     {
         /// Invoke this function from the UI thread.
         this.Invoke(new LobbyLostCallback(this.LobbyLost));
     }
     else
     {
         /// Normal invoke.
         this.joinedLobby           = null;
         this.createdLobby          = null;
         this.lastKnownLineStates   = null;
         this.lastKnownIdOfThisPeer = -1;
         this.connectingToLobby     = false;
         UpdateControls();
     }
 }
Beispiel #6
0
 private void btnShutdownDisconnectLobby_Click(object sender, EventArgs e)
 {
     if (this.joinedLobby != null && this.createdLobby == null && !this.connectingToLobby)
     {
         this.joinedLobby.Disconnect();
         this.connectingToLobby     = false;
         this.joinedLobby           = null;
         this.createdLobby          = null;
         this.lastKnownLineStates   = null;
         this.lastKnownIdOfThisPeer = -1;
         this.connectingToLobby     = false;
         UpdateControls();
     }
     else if (this.joinedLobby == null && this.createdLobby != null && !this.connectingToLobby)
     {
         this.createdLobby.Shutdown();
         this.joinedLobby           = null;
         this.createdLobby          = null;
         this.lastKnownLineStates   = null;
         this.lastKnownIdOfThisPeer = -1;
         this.connectingToLobby     = false;
         UpdateControls();
     }
 }