protected virtual OperationResponse ConnectAndAuthenticate(UnifiedTestClient client, string address,
                                                                   string userName, Dictionary <byte, object> authParameter = null, bool reuseToken = false, short expectedErrorCode = 0)
        {
            if (client.Connected)
            {
                client.Disconnect();
            }

            if (!reuseToken &&
                address == this.MasterAddress
#pragma warning disable CS0618 // Type or member is obsolete
                && this.authPolicy == AuthPolicy.AuthOnMaster)
#pragma warning restore CS0618 // Type or member is obsolete
            {
                client.Token = string.Empty;
            }

            client.OperationResponseQueueClear();
            client.EventQueueClear();

            if (authParameter == null)
            {
                authParameter = new Dictionary <byte, object>();
            }

            if (this.authPolicy != AuthPolicy.UseAuthOnce ||
                this.NameServerAddress == address)
            {
                ConnectToServer(client, address);
                if (this.authPolicy != AuthPolicy.UseAuthOnce)
                {
                    return(client.Authenticate(userName, authParameter, expectedErrorCode));
                }

                return(client.AuthOnce(userName, authParameter, expectedErrorCode));
            }

            client.ConnectWithAuthOnce(address, expectedErrorCode);
            return(null);
        }
        public virtual void ConnectAndAuthenticate(UnifiedTestClient client, string address, string userName, Dictionary<byte, object> authParameter = null, bool reuseToken  = false)
        {
            if (client.Connected)
            {
                client.Disconnect();
            }

            if (!reuseToken && address == this.MasterAddress)
            {
                client.Token = String.Empty;
            }

            client.OperationResponseQueueClear();
            client.EventQueueClear();

            this.ConnectToServer(client, address);

            if (authParameter == null)
            {
                authParameter = new Dictionary<byte, object>();
            }

            client.Authenticate(userName, authParameter);
        }
Ejemplo n.º 3
0
        public virtual void ConnectAndAuthenticate(UnifiedTestClient client, string address, string userName, Dictionary <byte, object> authParameter = null, bool reuseToken = false)
        {
            if (client.Connected)
            {
                client.Disconnect();
            }

            if (!reuseToken && address == this.MasterAddress)
            {
                client.Token = String.Empty;
            }

            client.OperationResponseQueueClear();
            client.EventQueueClear();

            this.ConnectToServer(client, address);

            if (authParameter == null)
            {
                authParameter = new Dictionary <byte, object>();
            }

            client.Authenticate(userName, authParameter);
        }
        public void RoomFlags_BroadcastOnChange([Values("ToAll", "ToOthers")] string policy)
        {
            UnifiedTestClient masterClient1 = null;
            UnifiedTestClient masterClient2 = null;

            try
            {
                // create game on the game server
                string roomName = this.GenerateRandomizedRoomName(MethodBase.GetCurrentMethod().Name);

                var gameProperties = new Hashtable();
                gameProperties["P1"] = 1;
                gameProperties["P2"] = 2;
                gameProperties["L1"] = 1;
                gameProperties["L2"] = 2;
                gameProperties["L3"] = 3;

                var createGameRequest = new CreateGameRequest
                {
                    GameId         = roomName,
                    GameProperties = gameProperties,
                    RoomFlags      = policy == "ToAll" ? RoomOptionFlags.BroadcastPropsChangeToAll : 0,
                };

                masterClient1 = this.CreateMasterClientAndAuthenticate(Player1);
                var cgResponse = masterClient1.CreateGame(createGameRequest);
                this.ConnectAndAuthenticate(masterClient1, cgResponse.Address);
                masterClient1.CreateGame(createGameRequest);

                masterClient2 = this.CreateMasterClientAndAuthenticate(Player2);

                var joinRequest = new JoinGameRequest()
                {
                    GameId = roomName,
                };
                var jgResponse = masterClient2.JoinGame(joinRequest, ErrorCode.Ok);
                this.ConnectAndAuthenticate(masterClient2, jgResponse.Address);
                masterClient2.JoinGame(joinRequest);


                masterClient1.EventQueueClear();
                masterClient1.SendRequest(new OperationRequest()
                {
                    OperationCode = OperationCode.SetProperties,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { (byte)ParameterKey.Properties, new Hashtable {
                              { "P2", 22 }
                          } },
                        { (byte)ParameterKey.Broadcast, true }
                    }
                });

                masterClient2.CheckThereIsEvent(EventCode.PropertiesChanged, this.WaitTimeout);
                if (policy == "ToOthers")
                {
                    masterClient1.CheckThereIsNoEvent(EventCode.PropertiesChanged, this.WaitTimeout);
                }
                else
                {
                    masterClient1.CheckThereIsEvent(EventCode.PropertiesChanged, this.WaitTimeout);
                }
            }
            finally
            {
                DisposeClients(masterClient1, masterClient2);
            }
        }
Ejemplo n.º 5
0
        public void GetGameUpdate_PluginSetStateOnCreation([Values(LobbyType.Default, LobbyType.SqlLobby)] LobbyType lobbyType)
        {
            if (!this.UsePlugins)
            {
                Assert.Ignore("This test needs plugins");
            }

            UnifiedTestClient client1 = null;
            UnifiedTestClient client2 = null;

            var lobbyFilterCase = LobbyFilterContent.LobbyFilterNonEmpty;
            var lobbyName       = this.GenerateRandomizedRoomName(MethodBase.GetCurrentMethod().Name + "_Lobby");
            var lobbyFilter     = SetupLobbyFilter(lobbyFilterCase);

            try
            {
                // authenticate client and check if the Lobbystats event will be received
                // Remarks: The event cannot be checked for a specific lobby count because
                // previous tests may have created lobbies.
                client1 = this.CreateMasterClientAndAuthenticate(this.Player1);

                if (string.IsNullOrEmpty(this.Player1) || client1.Token == null)
                {
                    Assert.Ignore("This test does not work correctly for old clients without userId and token");
                }

                client1.JoinLobby(lobbyName, (byte)lobbyType);

                // create a new game for the lobby
                var gameName = this.GenerateRandomizedRoomName(MethodBase.GetCurrentMethod().Name);
                var request  = new CreateGameRequest
                {
                    GameId    = gameName,
                    LobbyType = (byte)lobbyType,
                    LobbyName = lobbyName,
                    Plugins   = new [] { "SaveLoadStateTestPlugin" },

                    GameProperties = new Hashtable
                    {
                        { "xxx", 1 },
                        { "yyy", 2 },
                        { GameParameter.LobbyProperties, new [] { "xxx" } }
                    },
                };

                var createGameResponse = client1.CreateGame(request);

                this.ConnectAndAuthenticate(client1, createGameResponse.Address, client1.UserId);
                client1.CreateGame(request);

                // give the game server some time to report the game to the master server
                Thread.Sleep(100);

                client1.Disconnect();// after disconnect game state is saved

                Thread.Sleep(100);

                var authParameter = new Dictionary <byte, object> {
                    { (byte)Operations.ParameterCode.LobbyStats, true }
                };
                // check if new game is listed in lobby statistics
                client2 = this.CreateMasterClientAndAuthenticate(this.Player2, authParameter);
                if (this.AuthPolicy == AuthPolicy.UseAuthOnce) // in this case we should send OpSettings to master
                {
                    client2.SendRequest(new OperationRequest
                    {
                        OperationCode = (byte)OperationCode.ServerSettings,
                        Parameters    = new Dictionary <byte, object> {
                            { SettingsRequestParameters.LobbyStats, true }
                        },
                    });
                }

                client2.JoinLobby(lobbyName, (byte)lobbyType);
                Thread.Sleep(3000);
                client2.EventQueueClear();


                var joinRequest = new JoinGameRequest
                {
                    GameId    = gameName,
                    LobbyType = (byte)lobbyType,
                    LobbyName = lobbyName,
                    Plugins   = new string[] { "SaveLoadStateTestPlugin" },
                    JoinMode  = (byte)JoinMode.JoinOrRejoin,
                };

                this.ConnectAndAuthenticate(client1, this.MasterAddress);
                var jgResponse = client1.JoinGame(joinRequest);

                this.ConnectAndAuthenticate(client1, jgResponse.Address);
                client1.JoinGame(joinRequest);

                EventData eventData;
                Assert.That(client2.TryWaitForEvent((byte)Events.EventCode.GameListUpdate, this.WaitTimeout, out eventData));

                Assert.That(eventData.Parameters.Count > 0);

                var gameList     = (Hashtable)eventData.Parameters[(byte)ParameterKey.GameList];
                var propertyList = (Hashtable)gameList[gameName];

                Assert.That(propertyList["xxx"], Is.EqualTo(1));
            }
            finally
            {
                DisposeClients(client1, client2);
            }
        }
Ejemplo n.º 6
0
        public void GetGameUpdate_WellKnownPropertyChange(
            [Values(GameParameter.IsVisible, GameParameter.IsOpen)] GameParameter gameParameter,
            [Values(LobbyType.Default, LobbyType.SqlLobby)] LobbyType lobbyType)
        {
            UnifiedTestClient client1 = null;
            UnifiedTestClient client2 = null;

            var lobbyFilterCase = LobbyFilterContent.LobbyFilterNonEmpty;
            var lobbyName       = this.GenerateRandomizedRoomName(MethodBase.GetCurrentMethod().Name + "_Lobby");
            var lobbyFilter     = SetupLobbyFilter(lobbyFilterCase);

            try
            {
                // authenticate client and check if the Lobbystats event will be received
                // Remarks: The event cannot be checked for a specific lobby count because
                // previous tests may have created lobbies.
                client1 = this.CreateMasterClientAndAuthenticate(this.Player1);

                if (string.IsNullOrEmpty(this.Player1) || client1.Token == null)
                {
                    Assert.Ignore("This test does not work correctly for old clients without userId and token");
                }

                client1.JoinLobby(lobbyName, (byte)lobbyType);

                // create a new game for the lobby
                var gameName           = this.GenerateRandomizedRoomName(MethodBase.GetCurrentMethod().Name);
                var createGameResponse = client1.CreateGame(gameName, true, true, 0, new Hashtable()
                {
                    { "z", "w" }
                }, lobbyFilter, null);

                this.ConnectAndAuthenticate(client1, createGameResponse.Address, client1.UserId);
                client1.CreateGame(gameName, true, true, 0, new Hashtable()
                {
                    { "z", "w" }
                }, lobbyFilter, null);

                // give the game server some time to report the game to the master server
                Thread.Sleep(100);

                var authParameter = new Dictionary <byte, object> {
                    { (byte)Operations.ParameterCode.LobbyStats, true }
                };
                // check if new game is listed in lobby statistics
                client2 = this.CreateMasterClientAndAuthenticate(this.Player2, authParameter);
                if (this.AuthPolicy == AuthPolicy.UseAuthOnce) // in this case we should send OpSettings to master
                {
                    client2.SendRequest(new OperationRequest
                    {
                        OperationCode = (byte)OperationCode.ServerSettings,
                        Parameters    = new Dictionary <byte, object> {
                            { SettingsRequestParameters.LobbyStats, true }
                        },
                    });
                }

                client2.JoinLobby(lobbyName, (byte)lobbyType);
                Thread.Sleep(3000);
                client2.EventQueueClear();

                client1.SendRequest(new OperationRequest
                {
                    OperationCode = OperationCode.SetProperties,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { ParameterCode.Properties, new Hashtable {
                              { (byte)gameParameter, false }
                          } },
                    }
                });

                client2.CheckThereIsEvent((byte)Events.EventCode.GameListUpdate, this.WaitTimeout);

                // we send same value again
                client1.SendRequest(new OperationRequest
                {
                    OperationCode = OperationCode.SetProperties,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { ParameterCode.Properties, new Hashtable {
                              { (byte)gameParameter, false }
                          } },
                    }
                });

                client2.CheckThereIsNoEvent((byte)Events.EventCode.GameListUpdate, this.WaitTimeout);
            }
            finally
            {
                DisposeClients(client1, client2);
            }
        }
Ejemplo n.º 7
0
        public void A_Group_PluginHttpCallSyncBeforeContinueTests()
        {
            const string      config  = "HttpCallSyncBeforeContinue";
            UnifiedTestClient client  = null;
            UnifiedTestClient client2 = null;
            var GameName = RandomizeString(MethodBase.GetCurrentMethod().Name);

            try
            {
                client = this.CreateMasterClientAndAuthenticate("User1");

                var request = new OperationRequest
                {
                    OperationCode = OperationCode.CreateGame,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { ParameterCode.RoomName, GameName },
                        { ParameterCode.EmptyRoomTTL, 0 },
                        { ParameterCode.PlayerTTL, 0 },
                        { ParameterCode.CheckUserOnJoin, false },
                        { ParameterCode.CleanupCacheOnLeave, false },
                        { ParameterCode.SuppressRoomEvents, false },
                        { ParameterCode.LobbyName, "Default" },
                        { ParameterCode.LobbyType, (byte)0 },
                        {
                            ParameterCode.GameProperties, new Hashtable {
                                { "config", config }
                            }
                        },
                        { ParameterCode.Plugins, new string[] { "AllMethosCallHttpTestPlugin" } },
                    }
                };

                var response = client.SendRequestAndWaitForResponse(request);

                this.ConnectAndAuthenticate(client, (string)response[ParameterCode.Address], client.UserId);

                client.SendRequestAndWaitForResponse(request);

                client.CheckThereIsEvent(123, this.WaitTimeout);

                client.SendRequestAndWaitForResponse(new OperationRequest
                {
                    OperationCode = OperationCode.SetProperties,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { ParameterCode.Properties, new Hashtable {
                              { GamePropertyKey.IsOpen, true }
                          } }
                    }
                }, ErrorCode.PluginReportedError);

                client.CheckThereIsErrorInfoEvent(this.WaitTimeout);
                client.CheckThereIsEvent(123, this.WaitTimeout);

                request = new OperationRequest
                {
                    OperationCode = OperationCode.JoinGame,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { ParameterCode.RoomName, GameName },
                        { ParameterCode.PlayerProperties, new Hashtable {
                              { "Actor2Property", "Actor2PropertyValue" }
                          } },
                        { ParameterCode.GameProperties, new Hashtable() },
                        { ParameterCode.UserId, "User2" },
                        { ParameterCode.LobbyName, "Default" },
                    },
                };

                client2  = this.CreateMasterClientAndAuthenticate("User2");
                response = client2.SendRequestAndWaitForResponse(request);

                this.ConnectAndAuthenticate(client2, (string)response[ParameterCode.Address], client2.UserId);
                client2.SendRequestAndWaitForResponse(request, ErrorCode.PluginReportedError);

                client.CheckThereIsErrorInfoEvent(this.WaitTimeout);
                client.CheckThereIsEvent(123, this.WaitTimeout);

                request = new OperationRequest
                {
                    OperationCode = OperationCode.RaiseEvent,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { ParameterCode.Code, (byte)1 },
                    }
                };

                client.SendRequest(request);

                client.CheckThereIsEvent(123, this.WaitTimeout);

                client.EventQueueClear();

                client2.Disconnect();

                client.CheckThereIsNoErrorInfoEvent();

                client.Disconnect();
            }
            finally
            {
                if (client != null && client.Connected)
                {
                    client.Disconnect();
                    client.Dispose();
                }

                if (client2 != null && client2.Connected)
                {
                    client2.Disconnect();
                    client2.Dispose();
                }

                this.CheckGameIsClosed(GameName, this.WaitTimeout);
            }
        }