Пример #1
0
 private void GenerateDemoEntries()
 {
     WaitingList.Add(new Transportation()
     {
         Countdown   = 5,
         Destination = "Vienna",
         Source      = "Linz",
         Cargo       = new List <CargoItem>()
         {
             new CargoItem()
             {
                 Description = "Manna Schnitten",
                 Amount      = 1000,
                 Weight      = 2
             },
             new CargoItem()
             {
                 Description = "Auer Torten Ecken",
                 Amount      = 2000,
                 Weight      = 3
             }
         }
     });
     DispatcherTimer timer = new DispatcherTimer();
 }
Пример #2
0
        public void UpdateCoin(SmartCoin coin)
        {
            lock (StateLock)
            {
                SmartCoin found = WaitingList.Keys.Concat(Rounds.SelectMany(x => x.CoinsRegistered)).FirstOrDefault(x => x == coin);
                if (found != default)
                {
                    if (WaitingList.Keys.Contains(coin))
                    {
                        coin.CoinJoinInProgress = true;
                        WaitingList.Remove(found);
                        WaitingList.Add(coin, DateTimeOffset.UtcNow);
                        return;
                    }

                    foreach (CcjClientRound round in Rounds)
                    {
                        if (round.CoinsRegistered.Contains(coin))
                        {
                            coin.CoinJoinInProgress = true;
                            round.CoinsRegistered.Remove(found);
                            round.CoinsRegistered.Add(coin);
                            return;
                        }
                    }
                }
            }
        }
Пример #3
0
 public void AddCoinToWaitingList(SmartCoin coin)
 {
     lock (StateLock)
     {
         if (!(WaitingList.ContainsKey(coin) || Rounds.Any(x => x.CoinsRegistered.Contains(coin))))
         {
             WaitingList.Add(coin, DateTimeOffset.UtcNow);
             Logger.LogInfo <CcjClientState>($"Coin added to the waiting list: {coin.Index}:{coin.TransactionId}.");
         }
     }
 }
Пример #4
0
 public void ImportTasks(List <RequestedSubProgramClass> newlist)
 {
     foreach (var sp in newlist)
     {
         foreach (var RequestedRecipe in sp.RequestedRecipes)
         {
             RequestedRecipe.ValidExecutor.StatusChanged += new EventHandler(Executor_StatusChanged);
         }
         WaitingList.Add(sp);
     }
     //WaitingList.AddRange(newlist);
 }
Пример #5
0
        private void GenerateDemoEntries()
        {
            WaitingList.Add(new Transportation(CounterEllapsedInformer) //constructur used to provide instance of Informer delegate to Transportation object
            {
                Countdown   = 10,
                Destination = "Vienna",
                Source      = "Linz",
                Cargo       = new ObservableCollection <CargoItem>()
                {
                    new CargoItem()
                    {
                        Description = "Manna Schnitten",
                        Amount      = 1000,
                        Weight      = 2
                    },
                    new CargoItem()
                    {
                        Description = "Auer Torten Ecken",
                        Amount      = 2000,
                        Weight      = 3
                    }
                }
            });
            WaitingList.Last().StartCountDown();


            WaitingList.Add(new Transportation(CounterEllapsedInformer)
            {
                Countdown   = 3,
                Destination = "Innsbruck",
                Source      = "bregenz",
                Cargo       = new ObservableCollection <CargoItem>()
                {
                    new CargoItem()
                    {
                        Description = "Käse ecken",
                        Amount      = 1000,
                        Weight      = 2
                    },
                    new CargoItem()
                    {
                        Description = "Mozartkugeln",
                        Amount      = 3000,
                        Weight      = 500
                    }
                }
            });
            WaitingList.Last().StartCountDown();
        }
Пример #6
0
 public void ClearRoundRegistration(long roundId)
 {
     lock (StateLock)
     {
         foreach (var round in Rounds.Where(x => x.State.RoundId == roundId))
         {
             foreach (var coin in round.CoinsRegistered)
             {
                 WaitingList.Add(coin, DateTimeOffset.UtcNow);
                 Logger.LogInfo <CcjClientState>($"Coin added to the waiting list: {coin.Index}:{coin.TransactionId}.");
             }
             round.ClearRegistration();
             Logger.LogInfo <CcjClientState>($"Round ({round.State.RoundId}) registration is cleared.");
         }
     }
 }
Пример #7
0
        public void UpdateRoundsByStates(ConcurrentDictionary <TxoRef, IEnumerable <HdPubKeyBlindedPair> > exposedLinks, params CcjRunningRoundState[] allRunningRoundsStates)
        {
            Guard.NotNullOrEmpty(nameof(allRunningRoundsStates), allRunningRoundsStates);
            IsInErrorState = false;
            lock (StateLock)
            {
                // Find the rounds those aren't running anymore
                //	Put their coins back to the waiting list
                //	Remove them
                // Find the rounds those needs to be updated
                //	Update them

                IEnumerable <long> roundsToRemove = Rounds.Select(x => x.State.RoundId).Where(y => !allRunningRoundsStates.Select(z => z.RoundId).Contains(y));

                foreach (CcjClientRound round in Rounds.Where(x => roundsToRemove.Contains(x.State.RoundId)))
                {
                    var  newSuccessfulRoundCount = allRunningRoundsStates.FirstOrDefault()?.SuccessfulRoundCount;
                    bool roundFailed             = newSuccessfulRoundCount != null && round.State.SuccessfulRoundCount == newSuccessfulRoundCount;
                    if (roundFailed)
                    {
                        IsInErrorState = true;
                    }

                    foreach (SmartCoin coin in round.CoinsRegistered)
                    {
                        if (round.Registration.IsPhaseActionsComleted(CcjRoundPhase.Signing))
                        {
                            var delayRegistration = TimeSpan.FromSeconds(60);
                            WaitingList.Add(coin, DateTimeOffset.UtcNow + delayRegistration);
                            Logger.LogInfo <CcjClientState>($"Coin added to the waiting list: {coin.Index}:{coin.TransactionId}, but its registration is not allowed till {delayRegistration.TotalSeconds} seconds, because this coin might already be spent.");

                            if (roundFailed)
                            {
                                // Cleanup non-exposed links.
                                foreach (TxoRef input in round.Registration.CoinsRegistered.Select(x => x.GetTxoRef()))
                                {
                                    if (exposedLinks.ContainsKey(input))                                     // This should always be the case.
                                    {
                                        exposedLinks[input] = exposedLinks[input].Where(x => !x.IsBlinded);
                                    }
                                }
                            }
                        }
                        else
                        {
                            WaitingList.Add(coin, DateTimeOffset.UtcNow);
                            Logger.LogInfo <CcjClientState>($"Coin added to the waiting list: {coin.Index}:{coin.TransactionId}.");
                        }
                    }

                    round?.Registration?.AliceClient?.Dispose();

                    Logger.LogInfo <CcjClientState>($"Round ({round.State.RoundId}) removed. Reason: It's not running anymore.");
                }
                Rounds.RemoveAll(x => roundsToRemove.Contains(x.State.RoundId));

                foreach (CcjClientRound round in Rounds)
                {
                    if (allRunningRoundsStates.Select(x => x.RoundId).Contains(round.State.RoundId))
                    {
                        round.State = allRunningRoundsStates.Single(x => x.RoundId == round.State.RoundId);
                    }
                }

                foreach (CcjRunningRoundState state in allRunningRoundsStates)
                {
                    if (!Rounds.Select(x => x.State.RoundId).Contains(state.RoundId))
                    {
                        var r = new CcjClientRound(state);
                        Rounds.Add(r);
                        Logger.LogInfo <CcjClientState>($"Round ({r.State.RoundId}) added.");
                    }
                }
            }
        }
        //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);
        }
Пример #9
0
 private void AddmWaitLoadList(BaseBundle _bundle)
 {
     mWaitLoadBundleList.Add(_bundle);
 }