Exemplo n.º 1
0
        public void Start()
        {
            // reset state
            GameServer.Stop();
            unityServer = Substitute.For <IUnityServer>();

            unityServer.StartServer().Returns(false);
            Assert.Throws <Exception>(() => GameServer.Start(unityServer));
            unityServer.Received(10).StartServer();

            unityServer.ClearReceivedCalls();
            unityServer.StartServer().Returns(true);
            GameServer.Start(unityServer);
            unityServer.Received(1).StartServer();
            Assert.Throws <Exception>(() => GameServer.Start(unityServer));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Starts the server with the dependencies this singleton needs. This should only ever be called once,
        /// as it will throw an exception if it get called again.
        /// </summary>
        public static void Start(IUnityServer server)
        {
            if (instance == null)
            {
                instance = new GameServer(server);
                for (var i = 0; i < maxStartRetries; i++)
                {
                    instance.SelectPort();
                    if (Instance.server.StartServer())
                    {
                        instance.Register();
                        return;
                    }
                }

                Stop();
                throw new Exception(string.Format("Error starting server after {0} retries", maxStartRetries));
            }

            throw new Exception(string.Format("{0} Can only be started once!",
                                              typeof(GameServer).FullName));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Constructor, sets the server
 /// </summary>
 /// <param name="server"></param>
 public GameServer(IUnityServer server)
 {
     rnd         = new Random();
     this.server = server;
 }
Exemplo n.º 4
0
 public void Setup()
 {
     unityServer = Substitute.For <IUnityServer>();
     unityServer.StartServer().Returns(true);
     GameServer.Start(unityServer);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Constructor, sets the server
 /// </summary>
 /// <param name="server"></param>
 public GameServer(IUnityServer server)
 {
     rnd         = new Random();
     this.server = server;
     players     = new List <GameObject>();
 }