public async Task DoesntTryToDiscoverServerWithCustomIpAddressIfSet()
            {
                var settings = new UserSettings {
                    ServerAddress = "192.168.1.3"
                };

                bool discoverServerSubscribed = false;

                var messenger = Substitute.For <INetworkMessenger>();

                messenger.DiscoverServerAsync(Arg.Any <string>(), Arg.Any <int>())
                .Returns(Observable.Defer(() => Observable.Start(() => discoverServerSubscribed = true).Select(_ => string.Empty)));
                messenger.ConnectAsync(Arg.Any <string>(), Arg.Any <int>(), Arg.Any <Guid>(), Arg.Any <string>())
                .Returns(Task.FromResult(new ConnectionResultContainer(ConnectionResult.Successful, NetworkAccessPermission.Admin, new Version("99.99.99"))));

                NetworkMessenger.Override(messenger);

                ConnectionViewModel vm = Helpers.CreateDefaultConnectionViewModel(settings);

                vm.Activator.Activate();

                await vm.ConnectCommand.ExecuteAsync();

                Assert.False(discoverServerSubscribed);
            }
Ejemplo n.º 2
0
 // Use this for initialization
 void Start()
 {
     networker = gameObject.GetComponent<NetworkMessenger>();
     if (!isServer)
     {
         if (isLocalPlayer)
         {
             Transform spawnedClient = (Transform)GameObject.Instantiate(client, transform.position, Quaternion.identity);
             spawnedClient.parent = transform;
             DontDestroyOnLoad(gameObject);
             Application.LoadLevel("clientScene");
             networker.InitializeOnClient();
         }
         else
         {
             GameObject.Destroy(gameObject);
         }
     }
     else
     {
         Transform spawnedPlayer = (Transform)GameObject.Instantiate(player, transform.position, Quaternion.identity);
         spawnedPlayer.parent = transform;
         networker.InitializeOnServer();
         if (isLocalPlayer)
         {
             //if we are the server and spawned a local client, use this as a tester
             //TO DO:
             //Make sure the compoenent goes on correct game object, possibly the child
             gameObject.AddComponent<DesktopController>();
         }
     }
 }
            public async Task SmokeTest()
            {
                var messenger = Substitute.For <INetworkMessenger>();

                messenger.IsConnected.Returns(false);
                messenger.ConnectAsync(Arg.Any <string>(), Arg.Any <int>(), Arg.Any <Guid>(), Arg.Any <string>())
                .Returns(Task.FromResult(new ConnectionResultContainer(ConnectionResult.Successful, NetworkAccessPermission.Admin, new Version("99.99.99"))));
                messenger.DiscoverServerAsync(Arg.Any <string>(), Arg.Any <int>()).Returns(Observable.Return("192.168.1.1"));
                NetworkMessenger.Override(messenger);

                ConnectionViewModel vm = Helpers.CreateDefaultConnectionViewModel();

                vm.Activator.Activate();

                Assert.True(vm.ConnectCommand.CanExecute(null));

                await vm.ConnectCommand.ExecuteAsync();

                messenger.IsConnected.Returns(true);
                messenger.PropertyChanged += Raise.Event <PropertyChangedEventHandler>(messenger, new PropertyChangedEventArgs("IsConnected"));

                Assert.False(vm.ConnectCommand.CanExecute(null));

                messenger.Received(1).ConnectAsync("192.168.1.1", NetworkConstants.DefaultPort, Arg.Any <Guid>(), null);
            }
            public async Task IsFalseWhileConnectCommandExecutesWithPassword()
            {
                var messenger = Substitute.For <INetworkMessenger>();

                messenger.ConnectAsync(Arg.Any <string>(), Arg.Any <int>(), Arg.Any <Guid>(), Arg.Any <string>())
                .Returns(x =>
                {
                    messenger.IsConnected.Returns(true);
                    messenger.PropertyChanged += Raise.Event <PropertyChangedEventHandler>(messenger, new PropertyChangedEventArgs("IsConnected"));
                    return(new ConnectionResultContainer(ConnectionResult.Successful, NetworkAccessPermission.Admin, new Version("99.99.99")).ToTaskResult());
                });
                messenger.IsConnected.Returns(false);
                messenger.DiscoverServerAsync(Arg.Any <string>(), Arg.Any <int>()).Returns(Observable.Return("192.168.1.1"));

                NetworkMessenger.Override(messenger);

                var settings = new UserSettings {
                    AdministratorPassword = "******"
                };

                ConnectionViewModel vm = Helpers.CreateDefaultConnectionViewModel(settings);

                vm.Activator.Activate();

                var coll = messenger.WhenAnyValue(x => x.IsConnected).CreateCollection();

                await vm.ConnectCommand.ExecuteAsync();

                Assert.Equal(new[] { false, true }, coll);
            }
            public void AppDoeNotDieWhenDeactivatingViewModelBeforeCommandThrows()
            {
                var settings = new UserSettings {
                    ServerAddress = "192.168.1.1"
                };

                var messenger = Substitute.For <INetworkMessenger>();

                messenger.ConnectAsync(Arg.Any <string>(), Arg.Any <int>(), Arg.Any <Guid>(), Arg.Any <string>())
                .Returns(Observable.Never <ConnectionResultContainer>().ToTask());
                messenger.IsConnected.Returns(false);

                NetworkMessenger.Override(messenger);

                new TestScheduler().With(sched =>
                {
                    ConnectionViewModel vm = Helpers.CreateDefaultConnectionViewModel(settings);
                    vm.Activator.Activate();

                    vm.ConnectCommand.Execute(null);

                    vm.Activator.Deactivate();

                    sched.AdvanceByMs(ConnectionViewModel.ConnectCommandTimeout.TotalMilliseconds + 10);
                });
            }
            public void ThrottlesTimeChangesToNetworkByTime()
            {
                var messenger = CreateDefaultPlaylistMessenger();

                NetworkMessenger.Override(messenger);

                new TestScheduler().With(sched =>
                {
                    var vm = new PlaylistViewModel();
                    vm.Activator.Activate();

                    vm.CurrentTimeSeconds = 10;

                    sched.AdvanceByMs(1);

                    vm.CurrentTimeSeconds = 20;

                    sched.AdvanceByMs(1);

                    vm.CurrentTimeSeconds = 30;

                    sched.AdvanceByMs(PlaylistViewModel.TimeThrottleDuration.TotalMilliseconds + 1);

                    messenger.ReceivedWithAnyArgs(2).SetCurrentTime(Arg.Any <TimeSpan>());
                    messenger.Received(1).SetCurrentTime(TimeSpan.FromSeconds(10));
                    messenger.Received(1).SetCurrentTime(TimeSpan.FromSeconds(30));
                });
            }
            public async Task ConnectsWithCustomIpAddressIfSet()
            {
                var settings = new UserSettings {
                    ServerAddress = "192.168.1.3"
                };

                var messenger = Substitute.For <INetworkMessenger>();

                messenger.ConnectAsync(Arg.Any <string>(), Arg.Any <int>(), Arg.Any <Guid>(), Arg.Any <string>())
                .Returns(Task.FromResult(new ConnectionResultContainer(ConnectionResult.Successful, NetworkAccessPermission.Admin, new Version("99.99.99"))));

                NetworkMessenger.Override(messenger);

                ConnectionViewModel vm = Helpers.CreateDefaultConnectionViewModel(settings);

                vm.Activator.Activate();

                ConnectionResultContainer result = await vm.ConnectCommand.ExecuteAsync();

                Assert.Equal(ConnectionResult.Successful, result.ConnectionResult);
                Assert.Equal(new Version("99.99.99"), result.ServerVersion);;

                messenger.Received(1).ConnectAsync(settings.ServerAddress, NetworkConstants.DefaultPort,
                                                   settings.UniqueIdentifier, null);
            }
            public async Task IgnoresPasswordIfNotPremium()
            {
                var messenger = Substitute.For <INetworkMessenger>();

                messenger.DiscoverServerAsync(Arg.Any <string>(), Arg.Any <int>()).Returns(Observable.Return("192.168.1.1"));
                messenger.ConnectAsync(Arg.Any <string>(), Arg.Any <int>(), Arg.Any <Guid>(), Arg.Any <string>())
                .Returns(Task.FromResult(new ConnectionResultContainer(ConnectionResult.Successful, NetworkAccessPermission.Admin, new Version("99.99.99"))));

                NetworkMessenger.Override(messenger);

                var settings = new UserSettings
                {
                    AdministratorPassword = "******",
                    IsPremium             = false
                };

                // We're not in the trial period
                var installationDateFetcher = Substitute.For <IInstallationDateFetcher>();

                installationDateFetcher.GetInstallationDate().Returns(DateTimeOffset.MinValue);
                var clock = Substitute.For <IClock>();

                clock.Now.Returns(DateTimeOffset.MinValue + AppConstants.TrialTime);

                var vm = new ConnectionViewModel(settings, () => "192.168.1.2", installationDateFetcher, clock);

                vm.Activator.Activate();

                await vm.ConnectCommand.ExecuteAsync();

                messenger.Received().ConnectAsync("192.168.1.1", settings.Port, new Guid(), null);
            }
Ejemplo n.º 9
0
 private void HandleChatLine(string line)
 {
     NetworkMessenger.Broadcast(new ChatInputMessage {
         ChatLine = string.Format(line)
     });
     UIManager.Instance.ChatInput.text = string.Empty;
 }
Ejemplo n.º 10
0
 //A server has connected tot he client
 public override void OnClientConnect(NetworkConnection conn)
 {
     ClientsNetworkConnection = conn;
     Debug.Log("A server has connected to the client");
     NetworkMessenger.Broadcast(new TestMessage {
         TestInt = 1337
     });
 }
 public LiveSessionPublisher(NetworkMessenger messenger, LocalServerDiscoveryFile discoveryFile)
     : this(messenger, new NetworkConnectionOptions()
 {
     HostName = IPAddress.Loopback.ToString(),
     Port = discoveryFile.PublisherPort
 })
 {
     m_DiscoveryFile = discoveryFile;
 }
        /// <summary>
        /// Create a new connection with the specified options
        /// </summary>
        public LiveSessionPublisher(NetworkMessenger messenger, NetworkConnectionOptions options, int majorVersion, int minorVersion)
            : base(options, true, majorVersion, minorVersion)
        {
            if (!Log.SilentMode)
            {
                Log.Write(LogMessageSeverity.Verbose, LogCategory, "New live sessions publisher being created", "Configuration:\r\n{0}", options);
            }

            lock (m_Lock) //since we promptly access these variables from another thread, I'm adding this as paranoia to ensure they get synchronized.
            {
                m_Messenger = messenger;
            }
        }
Ejemplo n.º 13
0
 public void Update()
 {
     if (Input.GetMouseButton(0) && !EventSystem.current.IsPointerOverGameObject())
     {
         var        inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast(inputRay, out hit))
         {
             Debug.Log("Sending hex update broadcast.");
             NetworkMessenger.Broadcast(new HexUpdateMessage {
                 color = Color.red, hitPoint = hit.point
             });
         }
     }
 }
        private static INetworkMessenger CreateDefaultPlaylistMessenger()
        {
            var messenger = Substitute.For <INetworkMessenger>();

            messenger.GuestSystemInfo.Returns(new GuestSystemInfo {
                IsEnabled = false
            });

            messenger.PlaybackStateChanged.Returns(Observable.Never <NetworkPlaybackState>());
            messenger.PlaylistChanged.Returns(Observable.Never <NetworkPlaylist>());
            messenger.AccessPermission.Returns(NetworkAccessPermission.Admin);

            NetworkMessenger.Override(messenger);

            return(messenger);
        }
Ejemplo n.º 15
0
        public static void Main(string[] args)
        {
            // -- Start database connection
            databaseManager = new DatabaseManager();

            // -- Run web server
            webServer = new WebServer();

            // -- Set up debugging
            NetworkManager.isUnity = false;

            // -- Set up network messenger
            networkMessenger = NetworkMessenger.GetInstance();

            // -- Set up client manager
            clientManager = new ClientManager(4);

            // -- Set up message processor
            messageProcessor = new MessageProcessorServer();

            // -- Set up game manager
            gameManager = new GameManager();

            // -- Open local socket for sending and receiving
            networkMessenger.OpenClient(11999);

            // -- Start listening
            networkMessenger.Listen(IPAddress.Any, messageProcessor);

            // -- Build server world
            BuildServerWorld();

            // -- Start ping
            Ping();

            // -- Start update
            Update();

            // -- Start tick
            Tick();

            // -- Wait for exit command
            CommandLoop();

            // -- Close all
            networkMessenger.Close();
        }
            public void SendsFirstTimeImmediatelyToNetwork()
            {
                var messenger = CreateDefaultPlaylistMessenger();

                NetworkMessenger.Override(messenger);

                new TestScheduler().With(sched =>
                {
                    var vm = new PlaylistViewModel();
                    vm.Activator.Activate();

                    vm.CurrentTimeSeconds = 60;

                    sched.AdvanceByMs(1);

                    messenger.Received().SetCurrentTime(TimeSpan.FromSeconds(60));
                });
            }
            public async Task SmokeTest()
            {
                var messenger = Substitute.For <INetworkMessenger>();

                messenger.GuestSystemInfo.Returns(new GuestSystemInfo());
                messenger.AddSongToPlaylistAsync(Arg.Any <Guid>()).Returns(new ResponseInfo().ToTaskResult());
                NetworkMessenger.Override(messenger);
                var songs = Helpers.SetupSongs(4).ToList();

                var vm = new RemoteSongsViewModel(songs);

                vm.Activator.Activate();
                vm.SelectedSong = vm.Songs[2];

                await vm.AddToPlaylistCommand.ExecuteAsync();

                messenger.Received().AddSongToPlaylistAsync(songs[2].Guid);
            }
            public void ThrottlesTimeChangesToNetworkByCount()
            {
                var messenger = CreateDefaultPlaylistMessenger();

                NetworkMessenger.Override(messenger);

                var vm = new PlaylistViewModel();

                vm.Activator.Activate();

                for (int i = 1; i < PlaylistViewModel.TimeThrottleCount + 1; i++)
                {
                    vm.CurrentTimeSeconds = i;
                }

                messenger.ReceivedWithAnyArgs(2).SetCurrentTime(Arg.Any <TimeSpan>());
                messenger.Received(1).SetCurrentTime(TimeSpan.FromSeconds(1));
                messenger.Received(1).SetCurrentTime(TimeSpan.FromSeconds(PlaylistViewModel.TimeThrottleCount));
            }
Ejemplo n.º 19
0
        public override void OnStartServer()
        {
            NetworkMessenger.AddListener <HexUpdateMessage>(OnHexUpdated);

            //Load persistant data here.
            hexGridDimensions = new HexGridDimensions
            {
                Width  = 12,
                Height = 12
            };

            for (var z = 0; z < hexGridDimensions.Height; z++)
            {
                for (var x = 0; x < hexGridDimensions.Width; x++)
                {
                    CreateCell(x, z);
                }
            }
        }
            public async Task SmokeTest()
            {
                var messenger = Substitute.For <INetworkMessenger>();

                messenger.GuestSystemInfo.Returns(new GuestSystemInfo());
                NetworkMessenger.Override(messenger);
                var songs = Helpers.SetupSongs(4).ToList();

                var vm = new RemoteSongsViewModel(songs);

                vm.Activator.Activate();
                vm.SelectedSong = vm.Songs[2];

                await vm.PlaySongsCommand.ExecuteAsync();

                var guids = new[] { songs[2].Guid, songs[3].Guid };

                messenger.Received().PlaySongsAsync(Arg.Is <IEnumerable <Guid> >(x => x.SequenceEqual(guids)));
            }
            public void SendsTimeToNetworkOnlyIfChangedInWindow()
            {
                var messenger = CreateDefaultPlaylistMessenger();

                NetworkMessenger.Override(messenger);

                new TestScheduler().With(sched =>
                {
                    var vm = new PlaylistViewModel();
                    vm.Activator.Activate();

                    vm.CurrentTimeSeconds = 60;
                    vm.CurrentTimeSeconds = 60;

                    sched.AdvanceByMs(PlaylistViewModel.TimeThrottleDuration.TotalMilliseconds + 1);

                    messenger.Received(1).SetCurrentTime(TimeSpan.FromSeconds(60));
                });
            }
            public async Task ChecksMinimumServerVersion()
            {
                var messenger = Substitute.For <INetworkMessenger>();

                messenger.IsConnected.Returns(true);
                messenger.ConnectAsync(Arg.Any <string>(), Arg.Any <int>(), Arg.Any <Guid>(), Arg.Any <string>())
                .Returns(Task.FromResult(new ConnectionResultContainer(ConnectionResult.ServerVersionToLow, serverVersion: new Version("0.1.0"))));
                messenger.DiscoverServerAsync(Arg.Any <string>(), Arg.Any <int>()).Returns(Observable.Return("192.168.1.1"));

                NetworkMessenger.Override(messenger);

                ConnectionViewModel vm = Helpers.CreateDefaultConnectionViewModel();

                vm.Activator.Activate();

                ConnectionResultContainer result = await vm.ConnectCommand.ExecuteAsync();

                Assert.Equal(ConnectionResult.ServerVersionToLow, result.ConnectionResult);
                Assert.Equal(new Version("0.1.0"), result.ServerVersion);
            }
Ejemplo n.º 23
0
    void StartDB()
    {
        FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://bcgj2020p10.firebaseio.com/");
        dbReference = FirebaseDatabase.DefaultInstance.RootReference;

        if (dbReference != null)
        {
            Debug.Log("CONNECTED");
        }

        if (PlayerPrefs.HasKey("PlayerID"))
        {
            PlayerID = PlayerPrefs.GetString("PlayerID");
        }
        else
        {
            SetPlayerUniqueID();
        }

        networkMessenger = this.GetComponent <NetworkMessenger>();
    }
Ejemplo n.º 24
0
    // Use this for initialization
    void Start()
    {
        GameObject manager = GameObject.Find("NetworkMessenger");

        this.msger = manager.GetComponent <NetworkMessenger>();

        // we can use this.msger.games[0].entities  for now to draw all entities!
        for (int i = 0; i < this.msger.games[0].entities.Length; i++)
        {
            Entity e = this.msger.games [0].entities [i];
            if (e.EType == 3)
            {
                Transform tree = (Transform)Instantiate(this.treePrefab, new Vector3(e.X, 0, e.Y), Quaternion.identity);
                tree.localScale = new Vector3(e.Height, e.Height, e.Width);
                tree.name       = "tree" + e.ID.ToString();
            }
            else if (e.EType == 4)
            {
                // TODO: move player here!
            }
        }
    }
            public void TimeoutTriggersConnectionFailed()
            {
                var messenger = Substitute.For <INetworkMessenger>();

                messenger.ConnectAsync(Arg.Any <string>(), Arg.Any <int>(), Arg.Any <Guid>(), Arg.Any <string>())
                .Returns(Observable.Never <ConnectionResultContainer>().ToTask());
                messenger.IsConnected.Returns(false);
                messenger.DiscoverServerAsync(Arg.Any <string>(), Arg.Any <int>()).Returns(Observable.Return("192.168.1.1"));

                NetworkMessenger.Override(messenger);

                ConnectionViewModel vm = Helpers.CreateDefaultConnectionViewModel();

                vm.Activator.Activate();

                (new TestScheduler()).With(scheduler =>
                {
                    var connectTask = vm.ConnectCommand.ExecuteAsyncTask();
                    scheduler.AdvanceByMs(ConnectionViewModel.ConnectCommandTimeout.TotalMilliseconds + 1);

                    Assert.Equal(ConnectionResult.Timeout, connectTask.Result.ConnectionResult);
                });
            }
            public async Task WrongPasswordTriggersConnectionFailed()
            {
                var messenger = Substitute.For <INetworkMessenger>();

                messenger.IsConnected.Returns(false);
                messenger.ConnectAsync(Arg.Any <string>(), Arg.Any <int>(), Arg.Any <Guid>(), Arg.Any <string>())
                .Returns(new ConnectionResultContainer(ConnectionResult.WrongPassword).ToTaskResult());
                messenger.DiscoverServerAsync(Arg.Any <string>(), Arg.Any <int>()).Returns(Observable.Return("192.168.1.1"));

                NetworkMessenger.Override(messenger);

                var settings = new UserSettings
                {
                    AdministratorPassword = "******",
                    IsPremium             = true
                };

                ConnectionViewModel vm = Helpers.CreateDefaultConnectionViewModel(settings);

                vm.Activator.Activate();

                Assert.Equal(ConnectionResult.WrongPassword, (await vm.ConnectCommand.ExecuteAsync()).ConnectionResult);
            }
            public async Task SmokeTest()
            {
                var messenger = Substitute.For <INetworkMessenger>();

                messenger.IsConnected.Returns(true);

                NetworkMessenger.Override(messenger);

                ConnectionViewModel vm = Helpers.CreateDefaultConnectionViewModel();

                vm.Activator.Activate();

                Assert.True(vm.DisconnectCommand.CanExecute(true));

                await vm.DisconnectCommand.ExecuteAsync();

                messenger.IsConnected.Returns(false);
                messenger.PropertyChanged += Raise.Event <PropertyChangedEventHandler>(messenger, new PropertyChangedEventArgs("IsConnected"));

                Assert.False(vm.DisconnectCommand.CanExecute(null));

                messenger.Received(1).Disconnect();
            }
Ejemplo n.º 28
0
 // Use this for initialization
 void Start()
 {
     playerMovement = ClientNetworkToolbox.Instance.GetNetworkMessenger();
 }
Ejemplo n.º 29
0
    // Use this for initialization
    void Start()
    {
        GameObject managerobj = GameObject.Find("NetworkMessenger");

        this.msger = managerobj.GetComponent <NetworkMessenger>();
    }
Ejemplo n.º 30
0
 //A client has connected to the server.
 public override void OnServerConnect(NetworkConnection conn)
 {
     //Possible issue where this is called twice :( https://issuetracker.unity3d.com/issues/onserverconnect-function-is-called-twice
     Debug.Log(string.Format("A client has connected to the server with id: {0}, host id: {1}", conn.connectionId, conn.hostId));
     NetworkMessenger.AddListener <TestMessage>(Handler);
 }
Ejemplo n.º 31
0
 // Use this for initialization
 void Start()
 {
     currentState = State.Normal;
     cooldownDuration = stunDuration;
     myMovement =GetComponent<Server.PlayerMovement>();
     myRenderer = GetComponent<SpriteRenderer>();
     networker = transform.parent.GetComponent<NetworkMessenger>();
 }
Ejemplo n.º 32
0
 // Use this for initialization
 void Start()
 {
     networker = ClientNetworkToolbox.Instance.GetNetworkMessenger();
 }
Ejemplo n.º 33
0
    public void Awake()
    {
        GameObject manager = GameObject.Find("NetworkMessenger");

        this.msger = manager.GetComponent <NetworkMessenger>();
    }
 /// <summary>
 /// Create a new connection with the specified options
 /// </summary>
 public LiveSessionPublisher(NetworkMessenger messenger, NetworkConnectionOptions options)
     : this(messenger, options, FileHeader.DefaultMajorVersion, FileHeader.DefaultMinorVersion)
 {
 }