Ejemplo n.º 1
0
 public bool Contains(SmartCoin coin)
 {
     lock (StateLock)
     {
         return(WaitingList.Contains(coin) || Rounds.Any(x => x.CoinsRegistered.Contains(coin)));
     }
 }
Ejemplo n.º 2
0
 public void RemoveCoinFromWaitingList(SmartCoin coin)
 {
     lock (StateLock)
     {
         if (WaitingList.Contains(coin))
         {
             WaitingList.Remove(coin);
             Logger.LogInfo <CcjClientState>($"Coin removed from the waiting list: {coin.Index}:{coin.TransactionId}.");
         }
     }
 }
Ejemplo n.º 3
0
 public void AddCoinToWaitingList(SmartCoin coin)
 {
     lock (StateLock)
     {
         if (!(WaitingList.Contains(coin) || Rounds.Any(x => x.CoinsRegistered.Contains(coin))))
         {
             WaitingList.Add(coin);
             Logger.LogInfo <CcjClientState>($"Coin added to the waiting list: {coin.Index}:{coin.TransactionId}.");
         }
     }
 }
Ejemplo n.º 4
0
        private void Executor_StatusChanged(object sender, EventArgs e)
        {
            try
            {
                ExecutorClass            Executor = (ExecutorClass)sender;
                RequestedSubProgramClass root     = Executor.RequestedRecipe.RequestedSubProgram;
                switch (Executor.Status)
                {
                case ExecutorStatus.Ready:
                    WaitingList.Remove(root);
                    ReadyList.Add(root);
                    break;

                case ExecutorStatus.Executing:
                    ReadyList.Remove(root);
                    RunningList.Add(root);
                    break;

                case ExecutorStatus.Completed:
                    RunningList.Remove(root);
                    if (root.RequestedRecipes.Count == 1)
                    {
                        CompletedList.Add(root);
                    }
                    else if (root.RequestedRecipes.Count > 1)
                    {
                        WaitingList.Insert(0, root);
                    }
                    break;

                case ExecutorStatus.Abandoned:
                    if (ReadyList.Contains(root))
                    {
                        ReadyList.Remove(root);
                    }
                    else if (WaitingList.Contains(root))
                    {
                        WaitingList.Remove(root);
                    }
                    else if (RunningList.Contains(root))
                    {
                        RunningList.Remove(root);
                    }
                    else if (CompletedList.Contains(root))
                    {
                        CompletedList.Remove(root);
                    }
                    break;

                case ExecutorStatus.Invalid:
                    Executor.RequestedRecipe.AddExecutor();
                    if (CompletedList.Contains(root))
                    {
                        CompletedList.Remove(root);
                        WaitingList.Insert(0, root);        //back to the top by default
                    }
                    else if (RunningList.Contains(root))
                    {
                        RunningList.Remove(root);
                        WaitingList.Insert(0, root);        //back to the top by default
                    }
                    break;
                }
            }
            catch
            {
                //sender is not a ExecutorClass type
                return;
            }
        }
        //private static List<TcpClient> GatherPlayerSocketList(List<PlayerModel> p)
        //{
        //    List<TcpClient> temp = new List<TcpClient>();

        //    // Once two players have connected, start the game with the two players.
        //    foreach (PlayerModel item in p)
        //    {
        //        TcpClient socket = GetSocketByPlayerID(item.PlayerID);
        //        Console.WriteLine("...... " + item.Name + " is " + item.IDType);
        //        item.Socket = socket;  // save the socket reference for the game
        //        temp.Add(socket);
        //    }

        //    return temp;
        //}

        public override void Update()
        {
            var temp = ConnectedClientModelList;

            ReversiClientModel client = (ReversiClientModel)GetOldestClientModelFromConnectedList();

            Console.WriteLine(client.ClientPlayer.DisplayPlayerInfo());


            if (!WaitingList.Contains(client))
            {
                WaitingList.Add(client);
                RemoveClientModelFromServer(client);
            }

            // If insufficient players have joined, add to wait list...
            if (WaitingList.Count < ReversiSettings.ReversiPlayersPerGame)
            {
                // Do nothing here
            }


            // If two players and no running game, start the game
            if ((WaitingList.Count == ReversiSettings.ReversiPlayersPerGame) && RunningGames.Count == 0)
            {
                Console.WriteLine("-- GameServer: Creating 1st game");

                MovePlayersFromWaitingToStaging();

                // Create the game thread to handle this matchup and
                // Populate the players
                Thread gameThread = new Thread(InitializeMatchup);

                // Start the game
                gameThread.Start(StagingArea);
            }

            // If a game is already running, add the player to the waiting list...
            if (RunningGames.Count > 0)
            {
                Console.WriteLine("-- GameServer:  A game is already running so add client to waiting list");
            }

            // If someone already in the waiting list, and another player joins, allow option for players to start their own game...
            if (WaitingList.Count == ReversiSettings.ReversiPlayersPerGame)
            {
                Console.WriteLine("-- Sending option to Wait List for additional games to be created...");
                // TODO:  Send choice to waiting list about whether to keep waiting or to start a new game...
                // Continue waiting...
                // Or start a game with waiting list
            }

            string str = string.Empty;

            str += "-------------------------------\n";
            foreach (ReversiClientModel item in WaitingList)
            {
                str += item.ClientPlayer.PlayerId + " -- " + item.ClientPlayer.Name + "\n";
            }
            str += "-------------------------------\n";
            Console.WriteLine(str);
        }