Exemplo n.º 1
0
        public void Initialize()
        {
            MyProcessInfo = new ProcessInfo()
            {
                Status = ProcessInfo.StatusCode.Initializing,
                Type = ProcessInfo.ProcessType.BalloonStore,
                Label = Options.Label
            };

            RegistryEndPoint = new PublicEndPoint(Options.Registry);
            GameManagerEndPoint = new PublicEndPoint(Options.GameManagerEndPoint);

            Identity = new IdentityInfo()
            {
                Alias = Options.Alias,
                ANumber = Options.ANumber,
                FirstName = Options.FirstName,
                LastName = Options.LastName
            };

            SetupCommSubsystem(new BalloonStoreConversationFactory()
            {
                DefaultMaxRetries = Options.Retries,
                DefaultTimeout = Options.Timeout,
                Process = this
            }, minPort: Options.MinPort, maxPort: Options.MaxPort);

            Game = new GameInfo();
            PennyBankPublicKey = new PublicKey();
            WaterSources = new List<GameProcessData>();
            BalloonStores = new List<GameProcessData>();
            UmbrellaSuppliers = new List<GameProcessData>();
            Players = new List<GameProcessData>();
            Balloons = new ResourceSet<Balloon>();
            CachedPennies = new List<Penny>();

            rsa = new RSACryptoServiceProvider();
            rsaSigner = new RSAPKCS1SignatureFormatter(rsa);
            rsaSigner.SetHashAlgorithm("SHA1");
            Hasher = new SHA1Managed();
            RSAParameters parameters = rsa.ExportParameters(false);
            PublicKey = new PublicKey()
            {
                Exponent = parameters.Exponent,
                Modulus = parameters.Modulus
            };

            NextId = 0;
            NumIds = 0;
    }
        public void GameListReply_TestEverything()
        {
            ProcessInfo gm1 = new ProcessInfo()
                {
                    ProcessId=1,
                    Label="Game Manager 1",
                    EndPoint = new PublicEndPoint() { Host = "buzz.serv.usu.edu", Port = 20011 }
                };
            ProcessInfo gm2 = new ProcessInfo()
                {
                    ProcessId=2,
                    Label="Game Manager 2",
                    EndPoint = new PublicEndPoint() { Host = "buzz.serv.usu.edu", Port = 20022 }
                };

            GameInfo g1 = new GameInfo()
            {
                GameManager = gm1,
                GameId = 10,
                Label = "Test Game #1",
                MinPlayers = 3,
                MaxPlayers = 5,
                Status = GameInfo.StatusCode.Available
            };

            GameInfo g2 = new GameInfo()
            {
                GameManager = gm2,
                GameId = 12,
                Label = "Test Game #2",
                MinPlayers = 3,
                MaxPlayers = 5,
                Status = GameInfo.StatusCode.Available
            };

            GameListReply r1 = new GameListReply() { Success = true, Note = "Test note", GameInfo = new GameInfo[] { g1, g2 } };

            byte[] bytes = r1.Encode();
            string tmp = ASCIIEncoding.ASCII.GetString(bytes);

            GameListReply r2 = Message.Decode(bytes) as GameListReply;
            Assert.IsNotNull(r2);
        }
Exemplo n.º 3
0
        public void GameInfo_TestEverything()
        {
            GameInfo g1 = new GameInfo();
            Assert.AreEqual(0, g1.GameId);
            Assert.IsNull(g1.Label);
            Assert.AreEqual(GameInfo.StatusCode.NotInitialized, g1.Status);
            Assert.AreEqual(2, g1.MinPlayers);
            Assert.AreEqual(20, g1.MaxPlayers);
            Assert.IsNull(g1.GameManager);
            Assert.AreEqual(0, g1.StartingNumberOfPlayers);
            Assert.IsNull(g1.CurrentProcesses);
            Assert.AreEqual(0, g1.Winner);

            PublicEndPoint ep1 = new PublicEndPoint() { Host = "buzz.serv.usu.edu", Port = 20011 };
            PublicEndPoint ep2 = new PublicEndPoint() { Host = "buzz.serv.usu.edu", Port = 20012 };
            PublicEndPoint ep3 = new PublicEndPoint() { Host = "buzz.serv.usu.edu", Port = 20013 };

            ProcessInfo gm1 = new ProcessInfo()
                            {
                                ProcessId = 2,
                                Type= ProcessInfo.ProcessType.GameManager,
                                Label = "Game Manager 1",
                                EndPoint = ep1, Status = ProcessInfo.StatusCode.Registered,
                                AliveTimestamp = DateTime.Now
                            };

            ProcessInfo player1 = new ProcessInfo()
            {
                ProcessId = 11,
                Type = ProcessInfo.ProcessType.Player,
                Label = "Player 1",
                EndPoint = ep2,
                Status = ProcessInfo.StatusCode.Registered,
                AliveTimestamp = DateTime.Now
            };

            ProcessInfo player2 = new ProcessInfo()
            {
                ProcessId = 12,
                Type = ProcessInfo.ProcessType.Player,
                Label = "Player 3",
                EndPoint = ep3,
                Status = ProcessInfo.StatusCode.Registered,
                AliveTimestamp = DateTime.Now
            };

            GameInfo g2 = new GameInfo()
                            {
                                GameId = 10,
                                Label="Test Game",
                                MinPlayers = 2,
                                MaxPlayers = 5,
                                Status = GameInfo.StatusCode.NotInitialized,
                                GameManager = gm1,
                                StartingNumberOfPlayers = 3,
                                CurrentProcesses = new ProcessInfo[] { player1, player2 },
                                Winner = player1.ProcessId
                            };

            Assert.AreEqual(10, g2.GameId);
            Assert.AreEqual("Test Game", g2.Label);
            Assert.AreEqual(2, g2.MinPlayers);
            Assert.AreEqual(5, g2.MaxPlayers);
            Assert.AreEqual(GameInfo.StatusCode.NotInitialized, g2.Status);
            Assert.AreSame(gm1, g2.GameManager);
            Assert.AreEqual(3, g2.StartingNumberOfPlayers);
            Assert.AreEqual(2, g2.CurrentProcesses.Length);
            Assert.AreSame(player1, g2.CurrentProcesses[0]);
            Assert.AreSame(player2, g2.CurrentProcesses[1]);
            Assert.AreEqual(player1.ProcessId, g2.Winner);

            GameInfo g3 = g2.Clone();
            Assert.IsNotNull(g3);
            Assert.AreNotSame(g2, g3);
            Assert.AreEqual(10, g3.GameId);
            Assert.AreEqual("Test Game", g3.Label);
            Assert.AreEqual(2, g3.MinPlayers);
            Assert.AreEqual(5, g3.MaxPlayers);
            Assert.AreEqual(GameInfo.StatusCode.NotInitialized, g3.Status);
            Assert.AreEqual(2, g3.GameManager.ProcessId);
            Assert.AreEqual(ep1, g3.GameManager.EndPoint);
            Assert.AreEqual(2, g2.CurrentProcesses.Length);
            Assert.AreEqual(player1.ProcessId, g2.CurrentProcesses[0].ProcessId);
            Assert.AreEqual(player2.ProcessId, g2.CurrentProcesses[1].ProcessId);
            Assert.AreEqual(player1.ProcessId, g2.Winner);
        }
Exemplo n.º 4
0
 public override void CleanupSession()
 {
     PotentialGames = new List<GameInfo>();
     Pennies = new ConcurrentStack<Penny>();
     Balloons = new ConcurrentQueue<Balloon>();
     Game = new GameInfo();
     GameData = new GameProcessData();
     PennyBankPublicKey = new PublicKey();
     WaterSources = new List<GameProcessData>();
     BalloonStores = new List<GameProcessData>();
     UmbrellaSuppliers = new List<GameProcessData>();
     OtherPlayers = new List<GameProcessData>();
     Umbrella = null;
     UmbrellaRaised = false;
 }
Exemplo n.º 5
0
        public void BalloonStore_TestGameStatusNotification()
        {
            Communicator mockRegistry = new Communicator() { MinPort = 13000, MaxPort = 13050 };

            mockRegistry.Start();
            PublicEndPoint mockEp = new PublicEndPoint(String.Format("127.0.0.1:{0}", mockRegistry.Port));

            balloonStore.MyProcessInfo.Status = ProcessInfo.StatusCode.Initializing;
            balloonStore.RegistryEndPoint = mockEp;
            balloonStore.GetConversation().Launch(); // launch a bogus conversation in order to get the balloon store endpoint

            Envelope env = mockRegistry.Receive(1000);

            IPEndPoint balloonStoreEp = env.IPEndPoint;

            balloonStore.MyProcessInfo.Status = ProcessInfo.StatusCode.JoinedGame;

            GameInfo gameEnding = new GameInfo()
            {
                Status = GameInfo.StatusCode.Ending
            };
            
            GameInfo gameComplete = new GameInfo()
            {
                Status = GameInfo.StatusCode.Complete
            };

            GameInfo gameInProgress = new GameInfo()
            {
                Status = GameInfo.StatusCode.InProgress
            };

            // test game ending
            balloonStore.MyProcessInfo.Status = ProcessInfo.StatusCode.PlayingGame;
            env = new Envelope()
            {
                IPEndPoint = balloonStoreEp,
                Message = new GameStatusNotification()
                {
                    ConvId = new MessageNumber() { Pid = 1, Seq = 1 },
                    MsgId = new MessageNumber() { Pid = 1, Seq = 1 },
                    Game = gameEnding
                }
            };

            mockRegistry.Send(env);

            Thread.Sleep(2000);

            Assert.That(balloonStore.MyProcessInfo.Status, Is.EqualTo(ProcessInfo.StatusCode.LeavingGame));

            // test game complete
            balloonStore.MyProcessInfo.Status = ProcessInfo.StatusCode.PlayingGame;
            env = new Envelope()
            {
                IPEndPoint = balloonStoreEp,
                Message = new GameStatusNotification()
                {
                    ConvId = new MessageNumber() { Pid = 1, Seq = 2 },
                    MsgId = new MessageNumber() { Pid = 1, Seq = 2 },
                    Game = gameComplete
                }
            };

            mockRegistry.Send(env);

            Thread.Sleep(2000);

            Assert.That(balloonStore.MyProcessInfo.Status, Is.EqualTo(ProcessInfo.StatusCode.LeavingGame));

            // test game in progress
            balloonStore.MyProcessInfo.Status = ProcessInfo.StatusCode.JoinedGame;
            env = new Envelope()
            {
                IPEndPoint = balloonStoreEp,
                Message = new GameStatusNotification()
                {
                    ConvId = new MessageNumber() { Pid = 1, Seq = 3 },
                    MsgId = new MessageNumber() { Pid = 1, Seq = 3 },
                    Game = gameInProgress
                }
            };

            mockRegistry.Send(env);

            Thread.Sleep(2000);

            Assert.That(balloonStore.MyProcessInfo.Status, Is.EqualTo(ProcessInfo.StatusCode.PlayingGame));
            
            mockRegistry.Stop();
        }