Exemple #1
0
        public void ShouldCreateDeathmatchLobby([Values("1v1", "2v2v4", "3v3auto")] string lobbyType)
        {
            var lobbyName = TestContext.CurrentContext.Test.Name;
            var done      = new AutoResetEvent(false);

            var lobbyCreator = new SpeedDateClient();

            lobbyCreator.Started += () =>
            {
                lobbyCreator.GetPlugin <AuthPlugin>().LogInAsGuest(info =>
                {
                    lobbyCreator.GetPlugin <LobbyPlugin>().CreateAndJoin(lobbyType, new Dictionary <string, string>
                    {
                        {
                            OptionKeys.LobbyName, lobbyName
                        }
                    }, lobby =>
                    {
                        lobby.Data.GameMaster.ShouldBe(info.Username);
                        lobby.Members.ShouldContainKey(info.Username);

                        lobby.LobbyName.ShouldBe(lobbyName);
                        lobby.State.ShouldBe(LobbyState.Preparations);
                        lobby.Id.ShouldBeGreaterThanOrEqualTo(0);
                        done.Set();
                    }, error => throw new Exception(error));
                }, error => throw new Exception(error));
            };

            lobbyCreator.Start(new DefaultConfigProvider(
                                   new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                                   PluginsConfig.DefaultPeerPlugins)); //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();     //Wait for lobbby-created
        }
Exemple #2
0
        public void StopServer_ShouldAlsoStopClient()
        {
            var done = new AutoResetEvent(false);

            //A new server is created so other tests are not affected
            var server = new SpeedDateServer();

            var client = new SpeedDateClient();

            client.Started += () => done.Set();

            server.Started += () =>
            {
                client.Start(new DefaultConfigProvider(
                                 new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort + 1), //Connect to port
                                 PluginsConfig.DefaultPeerPlugins));                                  //Load peer-plugins only
            };

            server.Start(new DefaultConfigProvider(
                             new NetworkConfig("0.0.0.0", SetUp.MasterServerPort + 1), //Listen in port
                             PluginsConfig.DefaultServerPlugins)                       //Load server-plugins only
                         );

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();

            client.IsConnected.ShouldBeTrue();
            client.Stopped += () => done.Set();

            server.Stop();
            server.Dispose();

            done.WaitOne(TimeSpan.FromSeconds(10)).ShouldBeTrue();

            client.IsConnected.ShouldBeFalse();
        }
Exemple #3
0
        public void EchoFromMultipleClients_ShouldBeEchoed()
        {
            var numberOfClients = 50;

            var done = new AutoResetEvent(false);

            for (var clientNumber = 0; clientNumber < numberOfClients; clientNumber++)
            {
                ThreadPool.QueueUserWorkItem(index =>
                {
                    var client      = new SpeedDateClient();
                    client.Started += () =>
                    {
                        client.GetPlugin <EchoPlugin>().Send("Hello from " + index,
                                                             echo =>
                        {
                            echo.ShouldBe("Hello from " + index);

                            if (Interlocked.Decrement(ref numberOfClients) == 0)
                            {
                                done.Set();
                            }
                        },
                                                             error => throw new Exception(error));
                    };

                    client.Start(new DefaultConfigProvider(
                                     new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                                     PluginsConfig.DefaultPeerPlugins)); //Load peer-plugins only
                }, clientNumber);
            }

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();
        }
Exemple #4
0
        public void LoginAsGuest_ShouldGenerateGuestUsername()
        {
            var done = new AutoResetEvent(false);

            var client = new SpeedDateClient();

            client.Started += () =>
            {
                client.IsConnected.ShouldBeTrue();
                client.GetPlugin <AuthPlugin>().LogInAsGuest(info =>
                {
                    client.IsConnected.ShouldBeTrue();
                    client.GetPlugin <AuthPlugin>().IsLoggedIn.ShouldBeTrue();

                    info.ShouldNotBeNull();
                    info.IsGuest.ShouldBeTrue();
                    info.IsAdmin.ShouldBeFalse();
                    info.Username.ShouldStartWith(SetUp.GuestPrefix);

                    done.Set();
                },
                                                             error =>
                {
                    throw new Exception(error);
                });
            };

            client.Start(new DefaultConfigProvider(
                             new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort), //Connect to port
                             PluginsConfig.DefaultPeerPlugins));                              //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();                            //Should be signaled
        }
Exemple #5
0
        public void Echo_ShouldBeEchoed()
        {
            const string message = "MyTestMessage12345";

            var done = new AutoResetEvent(false);

            var client = new SpeedDateClient();

            client.Started += () =>
            {
                client.GetPlugin <EchoPlugin>().Send(message,
                                                     echo =>
                {
                    echo.ShouldBe(message);
                    done.Set();
                },
                                                     error => throw new Exception(error));
            };

            client.Start(new DefaultConfigProvider(
                             new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                             PluginsConfig.DefaultPeerPlugins)); //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();
        }
Exemple #6
0
        public void Reconnect_ShouldRaiseStopped()
        {
            var done = new AutoResetEvent(false);

            void SetAutoResetEvent()
            {
                done.Set();
            }

            var client = new SpeedDateClient();

            client.Started += SetAutoResetEvent;

            client.Start(new DefaultConfigProvider(
                             new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort), //Connect to port
                             PluginsConfig.DefaultPeerPlugins));                              //Load peer-plugins only


            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();

            client.Started -= SetAutoResetEvent;

            client.Stopped += SetAutoResetEvent;
            client.Reconnect();

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();
        }
Exemple #7
0
        public void SendPrivateMessage_ShouldBeNotLoggedInError()
        {
            const string channelName = "MyChannel";
            const string message     = "MyTest123";

            var done = new AutoResetEvent(false);

            //Join Channel with slave-client
            var slaveClient = new SpeedDateClient();

            slaveClient.Started += () =>
            {
                slaveClient.GetPlugin <ChatPlugin>().SendPrivateMessage(channelName, message, () => { },
                                                                        error =>
                {
                    error.ShouldNotBeNullOrEmpty("SendPrivateMessage without logging in");
                    done.Set();
                });
            };

            slaveClient.Start(new DefaultConfigProvider(
                                  new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort), //Connect to port
                                  PluginsConfig.DefaultPeerPlugins));                              //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();                                 //Should be signaled inside slaveClient.SendPrivateMessage
        }
Exemple #8
0
        public void GetJoinedChannels_ShouldContainJoinedChannel()
        {
            const string channelName = "General";

            var done = new AutoResetEvent(false);

            var client = new SpeedDateClient();

            client.Started += () =>
            {
                client.GetPlugin <AuthPlugin>().LogInAsGuest(info =>
                {
                    client.GetPlugin <ChatPlugin>().JoinChannel(channelName, () =>
                    {
                        client.GetPlugin <ChatPlugin>().GetJoinedChannels(channels =>
                        {
                            channels.ShouldNotBeNull();
                            channels.Count.ShouldBe(1);
                            channels.ShouldContain(channelName);

                            done.Set();
                        }, error => { throw new Exception(error); });
                    }, error => { throw new Exception(error); });
                }, error => { throw new Exception(error); });
            };

            client.Start(new DefaultConfigProvider(
                             new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort), //Connect to port
                             PluginsConfig.DefaultPeerPlugins));                              //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();                            //Should be signaled inside GetJoinedChannels
        }
Exemple #9
0
        public void ShouldLogOut()
        {
            var done = new AutoResetEvent(false);

            var client = new SpeedDateClient();

            client.Started += () =>
            {
                done.Set();
            };

            client.Start(new DefaultConfigProvider(
                             new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort), //Connect to port
                             PluginsConfig.DefaultPeerPlugins));                              //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();                            //Should be signaled

            client.GetPlugin <AuthPlugin>().LogInAsGuest(info =>
            {
                done.Set();
            },
                                                         error => throw new Exception(error));

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();

            client.GetPlugin <AuthPlugin>().LogOut();
            client.GetPlugin <AuthPlugin>().IsLoggedIn.ShouldBeFalse();

            //LogOut will raise "Started"-event
            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();

            client.IsConnected.ShouldBeTrue();
        }
Exemple #10
0
        public void ShouldNotGetLobbyRoomAccessWithoutJoiningLobbyFirst()
        {
            var lobbyName = TestContext.CurrentContext.Test.Name;
            var done      = new AutoResetEvent(false);

            var lobbyCreator = new SpeedDateClient();

            lobbyCreator.Started += () =>
            {
                lobbyCreator.GetPlugin <AuthPlugin>().LogInAsGuest(info =>
                {
                    lobbyCreator.GetPlugin <LobbyPlugin>().GetLobbyRoomAccess(new Dictionary <string, string>
                    {
                        {
                            OptionKeys.LobbyName, lobbyName
                        }
                    },
                                                                              lobby => throw new Exception("Got Lobby access without joining a lobby"),
                                                                              error =>
                    {
                        error.ShouldNotBeNullOrEmpty();
                        done.Set();
                    });
                }, error => throw new Exception(error));
            };

            lobbyCreator.Start(new DefaultConfigProvider(
                                   new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                                   PluginsConfig.DefaultPeerPlugins)); //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();     //Wait for lobbby-created
        }
Exemple #11
0
        public void FindGames_ShouldContainLobby([Values("1v1", "2v2v4", "3v3auto")] string lobbyType)
        {
            var lobbyName = TestContext.CurrentContext.Test.Name;
            var lobbyId   = -1;

            var done = new AutoResetEvent(false);

            var lobbyCreator = new SpeedDateClient();

            lobbyCreator.Started += () =>
            {
                lobbyCreator.GetPlugin <AuthPlugin>().LogInAsGuest(info =>
                {
                    lobbyCreator.GetPlugin <LobbyPlugin>().CreateAndJoin("2v2v4", new Dictionary <string, string>
                    {
                        {
                            OptionKeys.LobbyName, lobbyName
                        }
                    }, lobby =>
                    {
                        lobbyId = lobby.Id;
                        done.Set();
                    }, error => throw new Exception(error));
                }, error => throw new Exception(error));
            };

            lobbyCreator.Start(new DefaultConfigProvider(
                                   new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                                   PluginsConfig.DefaultPeerPlugins)); //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();     //Wait for lobbby-created

            var lobbyJoiner = new SpeedDateClient();

            lobbyJoiner.Started += () =>
            {
                lobbyJoiner.GetPlugin <AuthPlugin>().LogInAsGuest(info =>
                {
                    lobbyJoiner.GetPlugin <MatchmakerPlugin>().FindGames(new Dictionary <string, string>(), games =>
                    {
                        games.ShouldContain(packet => packet.Id.Equals(lobbyId));

                        var lobby = games.First(packet => packet.Id.Equals(lobbyId));
                        lobby.Type.ShouldBe(GameInfoType.Lobby);
                        lobby.Name.ShouldBe(lobbyName);
                        lobby.OnlinePlayers.ShouldBe(1);

                        done.Set();
                    }, error => throw new Exception(error));
                }, error => throw new Exception(error));
            };

            lobbyJoiner.Start(new DefaultConfigProvider(
                                  new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                                  PluginsConfig.DefaultPeerPlugins)); //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();    //Wait for lobbby-joined
        }
Exemple #12
0
        public void RegisterRoom_ShouldApplyOptions()
        {
            var done = new AutoResetEvent(false);

            var roomOptions = new RoomOptions
            {
                IsPublic   = true,
                MaxPlayers = 8,
                Name       = "Testroom",
                Password   = "******",
                RoomIp     = "127.42.42.42",
                RoomPort   = 424242,
                AllowUsersRequestAccess = true,
                AccessTimeoutPeriod     = 10f,
                Properties = new Dictionary <string, string> {
                    { "MyRoomOption", "123" }
                }
            };

            //GameServer's client to Masterserver
            var gameServer = new SpeedDateClient();

            gameServer.Started += () =>
            {
                gameServer.IsConnected.ShouldBeTrue();
                gameServer.GetPlugin <RoomsPlugin>().RegisterRoom(
                    roomOptions,
                    info =>
                {
                    info.Options.IsPublic.ShouldBe(roomOptions.IsPublic);
                    info.Options.MaxPlayers.ShouldBe(roomOptions.MaxPlayers);
                    info.Options.Name.ShouldBe(roomOptions.Name);
                    info.Options.Password.ShouldBe(roomOptions.Password);
                    info.Options.RoomIp.ShouldBe(roomOptions.RoomIp);
                    info.Options.RoomPort.ShouldBe(roomOptions.RoomPort);
                    info.Options.AllowUsersRequestAccess.ShouldBe(roomOptions.AllowUsersRequestAccess);
                    info.Options.Properties.Count.ShouldBe(1);
                    info.Options.Properties.ShouldContainKeyAndValue("MyRoomOption", "123");

                    gameServer.GetPlugin <RoomsPlugin>().GetLocallyCreatedRooms().ShouldContain(info);
                    gameServer.GetPlugin <RoomsPlugin>().GetRoomController(info.RoomId).ShouldBe(info);

                    done.Set();
                },
                    error =>
                {
                    throw new Exception(error);
                });
            };

            gameServer.Start(new DefaultConfigProvider(
                                 new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort), //Connect to port
                                 PluginsConfig.DefaultGameServerPlugins));                        //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();                                //Should be signaled inside GetJoinedChannels
        }
Exemple #13
0
        public void JoinLobby_ShouldIncreaseMembersCount([Values("1v1", "2v2v4", "3v3auto")] string lobbyType)
        {
            var lobbyName = TestContext.CurrentContext.Test.Name;
            var lobbyId   = -1;

            var done = new AutoResetEvent(false);

            var lobbyCreator = new SpeedDateClient();

            lobbyCreator.Started += () =>
            {
                lobbyCreator.GetPlugin <AuthPlugin>().LogInAsGuest(info =>
                {
                    lobbyCreator.GetPlugin <LobbyPlugin>().CreateAndJoin(lobbyType, new Dictionary <string, string>
                    {
                        {
                            OptionKeys.LobbyName, lobbyName
                        }
                    }, lobby =>
                    {
                        lobbyId = lobby.Id;
                        done.Set();
                    }, error => throw new Exception(error));
                }, error => throw new Exception(error));
            };

            lobbyCreator.Start(new DefaultConfigProvider(
                                   new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                                   PluginsConfig.DefaultPeerPlugins)); //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();     //Wait for lobbby-created

            var lobbyJoiner = new SpeedDateClient();

            lobbyJoiner.Started += () =>
            {
                lobbyJoiner.GetPlugin <AuthPlugin>().LogInAsGuest(info =>
                {
                    lobbyJoiner.GetPlugin <LobbyPlugin>().JoinLobby(lobbyId, joinedLobby =>
                    {
                        joinedLobby.Id.ShouldBe(lobbyId);
                        joinedLobby.Members.Count.ShouldBe(2);
                        joinedLobby.Members.ShouldContainKey(info.Username);

                        done.Set();
                    }, error => throw new Exception(error));
                }, error => throw new Exception(error));
            };

            lobbyJoiner.Start(new DefaultConfigProvider(
                                  new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                                  PluginsConfig.DefaultPeerPlugins)); //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();    //Wait for lobbby-joined
        }
Exemple #14
0
        public void GetPlugin_ShouldReturnSameObject()
        {
            using (var client = new SpeedDateClient())
            {
                client.Start(new DefaultConfigProvider(              //Start loads the plugins
                                 new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                                 PluginsConfig.DefaultPeerPlugins)); //Load peer-plugins only

                var a = client.GetPlugin <AuthPlugin>();
                var b = client.GetPlugin <AuthPlugin>();

                a.ShouldBe(b);

                client.Stop();
            }
        }
Exemple #15
0
        public void SimultaneousGuestLogins_ShouldGenerateDistinctUsernames()
        {
            var numberOfClients = 20;
            IProducerConsumerCollection <string> generatedUsernames = new ConcurrentBag <string>();

            var done = new ManualResetEvent(false);

            for (var clientNumber = 0; clientNumber < numberOfClients; clientNumber++)
            {
                ThreadPool.QueueUserWorkItem(state =>
                {
                    var client      = new SpeedDateClient();
                    client.Started += () =>
                    {
                        client.IsConnected.ShouldBeTrue();
                        client.GetPlugin <AuthPlugin>().LogInAsGuest(info =>
                        {
                            client.IsConnected.ShouldBeTrue();
                            client.GetPlugin <AuthPlugin>().IsLoggedIn.ShouldBeTrue();

                            info.ShouldNotBeNull();
                            info.IsGuest.ShouldBeTrue();
                            info.IsAdmin.ShouldBeFalse();
                            info.Username.ShouldStartWith(SetUp.GuestPrefix);

                            generatedUsernames.TryAdd(info.Username).ShouldBeTrue();

                            //Set done after all clients are logged in
                            if (Interlocked.Decrement(ref numberOfClients) == 0)
                            {
                                done.Set();
                            }
                        },
                                                                     error =>
                        {
                            throw new Exception(error);
                        });
                    };

                    client.Start(new DefaultConfigProvider(
                                     new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort), //Connect to port
                                     PluginsConfig.DefaultPeerPlugins));                              //Load peer-plugins only
                }, clientNumber);
            }

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue(); //Should be signaled
        }
Exemple #16
0
        public void GetPlugin_ShouldResolvePeerPlugins()
        {
            using (var client = new SpeedDateClient())
            {
                client.Start(new DefaultConfigProvider(              //Start loads the plugins
                                 new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                                 PluginsConfig.DefaultPeerPlugins)); //Load peer-plugins only

                client.GetPlugin <AuthPlugin>().ShouldNotBeNull();
                client.GetPlugin <ChatPlugin>().ShouldNotBeNull();
                client.GetPlugin <LobbyPlugin>().ShouldNotBeNull();
                client.GetPlugin <MatchmakerPlugin>().ShouldNotBeNull();
                client.GetPlugin <ProfilePlugin>().ShouldNotBeNull();
                client.GetPlugin <RoomPlugin>().ShouldNotBeNull();
                client.GetPlugin <SecurityPlugin>().ShouldNotBeNull();
                client.GetPlugin <SpawnRequestPlugin>().ShouldNotBeNull();

                client.Stop();
            }
        }
Exemple #17
0
        public void SpawnRequestWithoutLogin_ShouldNotBeAuthorized()
        {
            var spawnerRegionName = TestContext.CurrentContext.Test.Name;
            var done = new AutoResetEvent(false);

            var client = new SpeedDateClient();

            client.Started += () =>
            {
                client.GetPlugin <SpawnRequestPlugin>().RequestSpawn(new Dictionary <string, string>(),
                                                                     spawnerRegionName,
                                                                     controller => throw new Exception("Should not be authorized"), error => done.Set());
            };

            client.Start(new DefaultConfigProvider(
                             new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                             PluginsConfig.DefaultPeerPlugins)); //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();
        }
Exemple #18
0
        public void ShouldReLogin()
        {
            var done = new AutoResetEvent(false);

            var client = new SpeedDateClient();

            client.Started += () =>
            {
                done.Set();
            };

            client.Start(new DefaultConfigProvider(
                             new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort), //Connect to port
                             PluginsConfig.DefaultPeerPlugins));                              //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();                            //Should be signaled by Started

            client.GetPlugin <AuthPlugin>().LogIn(SetUp.TestAccount.Username, SetUp.TestAccountPassword, info =>
            {
                done.Set();
            },
                                                  error => throw new Exception(error));

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue(); //Should be signaled by Login

            client.GetPlugin <AuthPlugin>().LogOut();

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();

            client.GetPlugin <AuthPlugin>().LogIn(SetUp.TestAccount.Username, SetUp.TestAccountPassword, info =>
            {
                done.Set();
            },
                                                  error => throw new Exception(error));

            done.WaitOne(TimeSpan.FromSeconds(5)).ShouldBeTrue();

            client.GetPlugin <AuthPlugin>().LogOut();

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();
        }
Exemple #19
0
        public void MakeRoomPublic_ShouldMakePublic()
        {
            var done = new AutoResetEvent(false);

            var roomOptions = new RoomOptions
            {
                IsPublic = false,
            };

            //GameServer's client to Masterserver
            var gameServer = new SpeedDateClient();

            gameServer.Started += () =>
            {
                gameServer.IsConnected.ShouldBeTrue();
                gameServer.GetPlugin <RoomsPlugin>().RegisterRoom(
                    roomOptions,
                    info =>
                {
                    info.Options.IsPublic.ShouldBe(false);

                    info.MakePublic(() =>
                    {
                        info.Options.IsPublic.ShouldBe(true);
                        done.Set();
                    });
                },
                    error =>
                {
                    throw new Exception(error);
                });
            };

            gameServer.Start(new DefaultConfigProvider(
                                 new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort), //Connect to port
                                 PluginsConfig.DefaultGameServerPlugins));                        //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();                                //Should be signaled inside GetJoinedChannels
        }
Exemple #20
0
        public void RegisterSpawner_ShouldGenerateSpawnerId()
        {
            var done = new AutoResetEvent(false);

            var spawner = new SpeedDateClient();

            spawner.Started += () =>
            {
                spawner.GetPlugin <SpawnerPlugin>().Register(
                    spawnerId =>
                {
                    spawnerId.ShouldBeGreaterThanOrEqualTo(0);
                    done.Set();
                },
                    error => throw new Exception(error));
            };

            spawner.Start(new DefaultConfigProvider(
                              new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                              PluginsConfig.DefaultSpawnerPlugins)); //Load spawner-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();
        }
Exemple #21
0
        public void ShouldReturnLobbyTypes()
        {
            var done = new AutoResetEvent(false);

            var client = new SpeedDateClient();

            client.Started += () =>
            {
                client.GetPlugin <LobbyPlugin>().GetLobbyTypes(types =>
                {
                    types.ShouldContain("1v1");
                    types.ShouldContain("2v2v4");
                    types.ShouldContain("3v3auto");
                    done.Set();
                }, error => throw new Exception(error));
            };

            client.Start(new DefaultConfigProvider(
                             new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                             PluginsConfig.DefaultPeerPlugins));   //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue(); //Should be signaled, wait for lobbby-types
        }
Exemple #22
0
        public void RegisterRandomSpawnedProcess_ShouldError()
        {
            var done = new AutoResetEvent(false);

            //Start the gameserver - by default this is done by the spawner-handler
            var evilClient = new SpeedDateClient();

            evilClient.Started += () =>
            {
                //By default, the spawn-data is passed via commandline-arguments
                evilClient.GetPlugin <RoomsPlugin>().RegisterSpawnedProcess(
                    spawnId: Util.CreateRandomInt(0, 100),
                    spawnCode: Util.CreateRandomString(10),
                    callback: controller => { },
                    errorCallback: error => { done.Set(); }
                    );
            };

            evilClient.Start(new DefaultConfigProvider(
                                 new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                                 PluginsConfig.DefaultGameServerPlugins)); //Load gameserver-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();         //Error occured
        }
Exemple #23
0
 public GameServer()
 {
     _client = new SpeedDateClient();
 }
Exemple #24
0
        public void RequestSpawnWithInvalidSpawnerSettings_ShouldAbort()
        {
            //The default spawnerRequestdelegate would start a new process. Since the executable cannot be found (in this test-context), the request will fail
            //  and the spawn-task will be killed
            var spawnerRegionName = TestContext.CurrentContext.Test.Name;
            var done = new AutoResetEvent(false);

            //Register a spawner
            var spawner = new SpeedDateClient();

            spawner.Started += () =>
            {
                spawner.GetPlugin <SpawnerPlugin>().Register(
                    spawnerId =>
                {
                    spawnerId.ShouldBeGreaterThanOrEqualTo(0);
                    done.Set();
                },
                    error => throw new Exception(error));
            };

            spawner.Start(new DefaultConfigProvider(
                              new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                              PluginsConfig.DefaultSpawnerPlugins, //Load spawner-plugins only
                              new IConfig[]
            {
                new SpawnerConfig
                {
                    Region = spawnerRegionName
                }
            }));

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue(); //Spawner is registered

            var client = new SpeedDateClient();

            client.Started += () =>
            {
                client.GetPlugin <AuthPlugin>().LogInAsGuest(info =>
                {
                    client.GetPlugin <SpawnRequestPlugin>().RequestSpawn(new Dictionary <string, string>(),
                                                                         spawnerRegionName,
                                                                         controller =>
                    {
                        controller.ShouldNotBeNull();
                        controller.Status.ShouldBe(SpawnStatus.None);
                        controller.StatusChanged += status =>
                        {
                            if (status == SpawnStatus.Killed)
                            {
                                done.Set();
                            }
                        };
                    }, error => throw new Exception(error));
                }, error => throw new Exception(error));
            };

            client.Start(new DefaultConfigProvider(
                             new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                             PluginsConfig.DefaultPeerPlugins)); //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();
        }
Exemple #25
0
        public void SendChannelMessage_ShouldBeReceived()
        {
            const string channelName = "MyChannel";
            const string message     = "MyTest123";

            var usernameSlaveClient = string.Empty;

            var done = new AutoResetEvent(false);

            //Create Channel with MasterClient
            var masterClient = new SpeedDateClient();

            masterClient.Started += () =>
            {
                masterClient.GetPlugin <ChatPlugin>().MessageReceived += packet =>
                {
                    packet.Type.ShouldBe(ChatMessagePacket.ChannelMessage);
                    packet.Sender.ShouldBe(usernameSlaveClient);
                    packet.Receiver.ShouldBe(channelName);
                    packet.Message.ShouldBe(message);
                    done.Set();
                };

                masterClient.GetPlugin <AuthPlugin>().LogInAsGuest(info =>
                {
                    masterClient.GetPlugin <ChatPlugin>().JoinChannel(channelName, () =>
                    {
                        done.Set();
                    }, error => { throw new Exception(error); });
                }, error => { throw new Exception(error); });
            };

            masterClient.Start(new DefaultConfigProvider(
                                   new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort), //Connect to port
                                   PluginsConfig.DefaultPeerPlugins));                              //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();                                  //Should be signaled inside masterClient.GetJoinedChannels

            //Join Channel with slave-client
            var slaveClient = new SpeedDateClient();

            slaveClient.Started += () =>
            {
                slaveClient.GetPlugin <AuthPlugin>().LogInAsGuest(info =>
                {
                    usernameSlaveClient = info.Username;
                    slaveClient.GetPlugin <ChatPlugin>().JoinChannel(channelName, () =>
                    {
                        done.Set();
                    }, error => { throw new Exception(error); });
                }, error => { throw new Exception(error); });
            };

            slaveClient.Start(new DefaultConfigProvider(
                                  new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort), //Connect to port
                                  PluginsConfig.DefaultPeerPlugins));                              //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();                                 //Should be signaled inside slaveClient.Started

            usernameSlaveClient.ShouldNotBeNullOrEmpty();

            slaveClient.GetPlugin <ChatPlugin>().SendChannelMessage(channelName, message, () => { }, error => { throw new Exception(error); });

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue(); //Should be signaled inside masterClient.MessageReceived
        }
Exemple #26
0
        public void IsConnected_ShouldBeFalse()
        {
            var client = new SpeedDateClient();

            client.IsConnected.ShouldBeFalse();
        }
Exemple #27
0
 public GameClient()
 {
     client          = new SpeedDateClient();
     client.Started += () => Connected?.Invoke();
 }
Exemple #28
0
        public void ShouldRegisterRoomBeforeFinalizingSpawnTask_AndThen_ShouldReceiveAccessToRoomAsClient()
        {
            var done = new AutoResetEvent(false);

            var spawnId           = -1;
            var spawnCode         = string.Empty;
            var spawnerRegionName = TestContext.CurrentContext.Test.Name;

            //------------------------------------------------------
            //
            // Test-Setup
            //
            // -----------------------------------------------------

            //Fakes spawning a process after receiving a SpawnRequest
            var spawnerDelegateMock = new Mock <ISpawnerRequestsDelegate>();

            spawnerDelegateMock.Setup(mock => mock.HandleSpawnRequest(
                                          It.IsAny <IIncommingMessage>(),
                                          It.Is <SpawnRequestPacket>(packet =>
                                                                     packet.SpawnId >= 0 && !string.IsNullOrEmpty(packet.SpawnCode))))
            .Callback((IIncommingMessage message, SpawnRequestPacket data) =>
            {
                //By default, the spawn-data is passed via commandline-arguments
                spawnId   = data.SpawnId;
                spawnCode = data.SpawnCode;

                message.Respond(ResponseStatus.Success);
                message.Peer.SendMessage((ushort)OpCodes.ProcessStarted, data.SpawnId);
            });

            //------------------------------------------------------
            //
            // On Spawner:
            //
            // Register itself
            //
            // -----------------------------------------------------
            var spawner = new SpeedDateClient();

            spawner.Started += () =>
            {
                spawner.GetPlugin <SpawnerPlugin>().SetSpawnerRequestsDelegate(spawnerDelegateMock.Object);
                spawner.GetPlugin <SpawnerPlugin>().Register(
                    callback: spawnerId =>
                {
                    spawnerId.ShouldBeGreaterThanOrEqualTo(0);
                    done.Set();
                },
                    errorCallback: error => throw new Exception(error));
            };

            spawner.Start(new DefaultConfigProvider(
                              new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                              PluginsConfig.DefaultSpawnerPlugins, //Load spawner-plugins only
                              new IConfig[]
            {
                new SpawnerConfig
                {
                    Region = spawnerRegionName
                }
            }));

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue(); //The spawner has been registered to master

            //------------------------------------------------------
            //
            // On Client:
            //
            // Connect to the master and request to spawn a new process
            //
            // -----------------------------------------------------
            var client = new SpeedDateClient();

            client.Started += () =>
            {
                client.GetPlugin <AuthPlugin>().LogInAsGuest(info =>
                {
                    client.GetPlugin <SpawnRequestPlugin>().RequestSpawn(new Dictionary <string, string>(),
                                                                         spawnerRegionName,
                                                                         controller =>
                    {
                        controller.ShouldNotBeNull();
                        controller.SpawnId.ShouldBeGreaterThanOrEqualTo(0);
                        controller.Status.ShouldBe(SpawnStatus.None);
                        controller.StatusChanged += status =>
                        {
                            switch (status)
                            {
                            case SpawnStatus.WaitingForProcess:
                            case SpawnStatus.Finalized:
                                done.Set();
                                break;
                            }
                        };
                        spawnId = controller.SpawnId;
                    }, error => throw new Exception(error));
                }, error => throw new Exception(error));
            };

            client.Start(new DefaultConfigProvider(
                             new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                             PluginsConfig.DefaultPeerPlugins)); //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30))
            .ShouldBeTrue();     //The SpawnRequest has been handled and is now waiting for the process to start

            //------------------------------------------------------
            //
            // On Gameserver (which - by default - is started by the spawner):
            //
            // The spawned process now registers itself at the master, starts a new server and then creates a new room
            //
            // -----------------------------------------------------

            var gameserver = new SpeedDateClient();

            gameserver.Started += () =>
            {
                //By default, the spawn-data is passed via commandline-arguments
                gameserver.GetPlugin <RoomsPlugin>().RegisterSpawnedProcess(spawnId, spawnCode,
                                                                            controller =>
                {
                    //By default, these values are passed via commandline-arguments
                    var roomOptions = new RoomOptions
                    {
                        RoomIp   = "127.0.0.1",
                        RoomPort = 20000
                    };
                    gameserver.GetPlugin <RoomsPlugin>().RegisterRoom(roomOptions, roomController =>
                    {
                        controller.FinalizeTask(new Dictionary <string, string>
                        {
                            { OptionKeys.RoomId, roomController.RoomId.ToString() },
                            { OptionKeys.RoomPassword, roomController.Options.Password }
                        }, () =>
                        {
                            //StatusChanged => SpawnStatus.Finalized will signal done
                        });
                    }, error => throw new Exception(error));
                }, error => throw new Exception(error));
            };

            gameserver.Start(new DefaultConfigProvider(
                                 new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                                 PluginsConfig.DefaultGameServerPlugins)); //Load gameserver-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30))
            .ShouldBeTrue();     //The SpawnRequest has been finalized ('done' is set by StatusChanged.Finalized (see above))

            //------------------------------------------------------
            //
            // On Client:
            //
            // Receive an access-token and connect to the gameserver
            //
            // -----------------------------------------------------
            RoomAccessPacket roomAccess = null;

            client.GetPlugin <SpawnRequestPlugin>().GetRequestController(spawnId).ShouldNotBeNull();
            client.GetPlugin <SpawnRequestPlugin>().GetRequestController(spawnId).GetFinalizationData(data =>
            {
                data.ShouldNotBeNull();
                data.ShouldContainKey(OptionKeys.RoomId);
                data.ShouldContainKey(OptionKeys.RoomPassword);

                client.GetPlugin <RoomPlugin>().GetAccess(
                    roomId: Convert.ToInt32(data[OptionKeys.RoomId]),
                    password: data[OptionKeys.RoomPassword],
                    properties: new Dictionary <string, string>(),
                    callback: access =>
                {
                    roomAccess = access;
                    done.Set();
                },
                    errorCallback: error => throw new Exception(error));
            },
                                                                                                      error => throw new Exception(error));

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue(); //Client received RoomAccess

            //------------------------------------------------------
            //
            // Now the client has to connect to the gameserver and transmit the token.
            // How this is done is out of SpeedDate's scope. You may use UNET, LiteNetLib, TcpListener, another SpeedDate server or any other custom solution.
            //
            // This test simply uses the same access-object on the server and the client
            //
            // -----------------------------------------------------

            gameserver.GetPlugin <RoomsPlugin>().ValidateAccess(roomAccess.RoomId, roomAccess.Token, id =>
            {
                id.PeerId.ShouldBe(client.PeerId);
                done.Set();
            }, error => throw new Exception(error));
            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue(); //Gameserver validated access
        }
Exemple #29
0
        public void ShouldPassFinalizationData()
        {
            var done = new AutoResetEvent(false);

            var spawnId           = -1;
            var spawnCode         = string.Empty;
            var spawnerRegionName = TestContext.CurrentContext.Test.Name;
            var testData          = new KeyValuePair <string, string>("Hello", "World");

            //Fakes spawning a process after receiving a SpawnRequest
            var spawnerDelegateMock = new Mock <ISpawnerRequestsDelegate>();

            spawnerDelegateMock.Setup(mock => mock.HandleSpawnRequest(
                                          It.IsAny <IIncommingMessage>(),
                                          It.Is <SpawnRequestPacket>(packet =>
                                                                     packet.SpawnId >= 0 && !string.IsNullOrEmpty(packet.SpawnCode))))
            .Callback((IIncommingMessage message, SpawnRequestPacket data) =>
            {
                //By default, the spawn-data is passed via commandline-arguments
                spawnId   = data.SpawnId;
                spawnCode = data.SpawnCode;

                message.Respond(ResponseStatus.Success);
                message.Peer.SendMessage((ushort)OpCodes.ProcessStarted, data.SpawnId);
            });

            //Register a spawner
            var spawner = new SpeedDateClient();

            spawner.Started += () =>
            {
                spawner.GetPlugin <SpawnerPlugin>().SetSpawnerRequestsDelegate(spawnerDelegateMock.Object);
                spawner.GetPlugin <SpawnerPlugin>().Register(
                    callback: spawnerId =>
                {
                    spawnerId.ShouldBeGreaterThanOrEqualTo(0);
                    done.Set();
                },
                    errorCallback: error => throw new Exception(error));
            };

            spawner.Start(new DefaultConfigProvider(
                              new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                              PluginsConfig.DefaultSpawnerPlugins, //Load spawner-plugins only
                              new IConfig[]
            {
                new SpawnerConfig
                {
                    Region = spawnerRegionName
                }
            }));

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue(); //The spawner has been registered to master

            var client = new SpeedDateClient();

            client.Started += () =>
            {
                client.GetPlugin <AuthPlugin>().LogInAsGuest(info =>
                {
                    client.GetPlugin <SpawnRequestPlugin>().RequestSpawn(new Dictionary <string, string>(),
                                                                         spawnerRegionName,
                                                                         controller =>
                    {
                        controller.ShouldNotBeNull();
                        controller.SpawnId.ShouldBeGreaterThanOrEqualTo(0);
                        controller.Status.ShouldBe(SpawnStatus.None);
                        controller.StatusChanged += status =>
                        {
                            switch (status)
                            {
                            case SpawnStatus.WaitingForProcess:
                            case SpawnStatus.ProcessRegistered:
                            case SpawnStatus.Finalized:
                                done.Set();
                                break;
                            }
                        };

                        spawnId = controller.SpawnId;
                    }, error => throw new Exception(error));
                }, error => throw new Exception(error));
            };

            client.Start(new DefaultConfigProvider(
                             new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                             PluginsConfig.DefaultPeerPlugins)); //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30))
            .ShouldBeTrue();     //The SpawnRequest has been handled and is now waiting for the process to start

            //Start the gameserver - by default this is done by the spawner-handler
            var gameserver = new SpeedDateClient();

            gameserver.Started += () =>
            {
                //By default, the spawn-data is passed via commandline-arguments
                gameserver.GetPlugin <RoomsPlugin>().RegisterSpawnedProcess(spawnId, spawnCode, controller =>
                {
                    //StatusChanged => SpawnStatus.ProcessRegistered will signal done
                    controller.FinalizeTask(new Dictionary <string, string> {
                        { testData.Key, testData.Value }
                    }, () =>
                    {
                        //StatusChanged => SpawnStatus.Finalized will signal done
                    });
                }, error => throw new Exception(error));
            };

            gameserver.Start(new DefaultConfigProvider(
                                 new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                                 PluginsConfig.DefaultGameServerPlugins)); //Load gameserver-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();         //The Process has been registered

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();         //The SpawnRequest has been finalized

            client.GetPlugin <SpawnRequestPlugin>().GetRequestController(spawnId).ShouldNotBeNull();
            client.GetPlugin <SpawnRequestPlugin>().GetRequestController(spawnId).GetFinalizationData(data =>
            {
                data.ShouldNotBeNull();
                data.ShouldContainKeyAndValue(testData.Key, testData.Value);
                done.Set();
            },
                                                                                                      error => throw new Exception(error));

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue(); //FinalizationData was correct
        }
Exemple #30
0
        public void WrongPeerWithCorrectSpawnIdRegisterSpawnedProcess_ShouldNotBeAuthorized()
        {
            var done = new AutoResetEvent(false);

            var spawnId           = -1;
            var spawnerRegionName = TestContext.CurrentContext.Test.Name;

            //Fakes spawning a process after receiving a SpawnRequest
            var spawnerDelegateMock = new Mock <ISpawnerRequestsDelegate>();

            spawnerDelegateMock.Setup(mock => mock.HandleSpawnRequest(
                                          It.IsAny <IIncommingMessage>(),
                                          It.Is <SpawnRequestPacket>(packet =>
                                                                     packet.SpawnId >= 0 && !string.IsNullOrEmpty(packet.SpawnCode))))
            .Callback((IIncommingMessage message, SpawnRequestPacket data) =>
            {
                //By default, the spawn-data is passed via commandline-arguments
                spawnId = data.SpawnId;
                message.Respond(ResponseStatus.Success);
                message.Peer.SendMessage((ushort)OpCodes.ProcessStarted, data.SpawnId);
            });

            //Register a spawner
            var spawner = new SpeedDateClient();

            spawner.Started += () =>
            {
                spawner.GetPlugin <SpawnerPlugin>().SetSpawnerRequestsDelegate(spawnerDelegateMock.Object);
                spawner.GetPlugin <SpawnerPlugin>().Register(
                    spawnerId =>
                {
                    spawnerId.ShouldBeGreaterThanOrEqualTo(0);
                    done.Set();
                },
                    error => throw new Exception(error));
            };

            spawner.Start(new DefaultConfigProvider(
                              new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                              PluginsConfig.DefaultSpawnerPlugins, //Load spawner-plugins only
                              new IConfig[]
            {
                new SpawnerConfig
                {
                    Region = spawnerRegionName
                }
            }));

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue(); //The spawner has been registered to master

            var client = new SpeedDateClient();

            client.Started += () =>
            {
                client.GetPlugin <AuthPlugin>().LogInAsGuest(info =>
                {
                    client.GetPlugin <SpawnRequestPlugin>().RequestSpawn(new Dictionary <string, string>(),
                                                                         spawnerRegionName,
                                                                         controller =>
                    {
                        controller.StatusChanged += status =>
                        {
                            switch (status)
                            {
                            case SpawnStatus.WaitingForProcess:
                            case SpawnStatus.ProcessRegistered:
                                done.Set();
                                break;
                            }
                        };

                        spawnId = controller.SpawnId;
                    }, error => throw new Exception(error));
                }, error => throw new Exception(error));
            };

            client.Start(new DefaultConfigProvider(
                             new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                             PluginsConfig.DefaultPeerPlugins)); //Load peer-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30))
            .ShouldBeTrue();     //The SpawnRequest has been handled and is now waiting for the process to start

            var evilClient = new SpeedDateClient();

            evilClient.Started += () =>
            {
                evilClient.GetPlugin <RoomsPlugin>()
                .FinalizeSpawnedProcess(spawnId, () => { },
                                        error => done.Set()); //Not authorized without registering with correct SpawnCode first
            };

            evilClient.Start(new DefaultConfigProvider(
                                 new NetworkConfig(SetUp.MasterServerIp, SetUp.MasterServerPort),
                                 PluginsConfig.DefaultGameServerPlugins)); //Load gameserver-plugins only

            done.WaitOne(TimeSpan.FromSeconds(30)).ShouldBeTrue();         //Finalize returned an error
        }