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);
            }
        }
        public void EventCache_RemoveUsingActorIdAndEventCode()
        {
            UnifiedTestClient client1 = null;
            UnifiedTestClient client2 = null;
            UnifiedTestClient client3 = null;
            UnifiedTestClient client4 = null;

            try
            {
                var roomName = this.GenerateRandomizedRoomName(MethodBase.GetCurrentMethod().Name);

                // create room
                client1 = this.CreateMasterClientAndAuthenticate(this.Player1);

                var createGameRequest = new CreateGameRequest
                {
                    GameId          = roomName,
                    CheckUserOnJoin = !string.IsNullOrEmpty(this.Player1),
                };

                var createGameResponse = client1.CreateGame(createGameRequest);

                this.ConnectAndAuthenticate(client1, createGameResponse.Address);

                // creation on GS
                client1.CreateGame(createGameRequest);


                // second player joins and check that there is no removed event
                client2 = this.CreateMasterClientAndAuthenticate(this.Player2);
                client3 = this.CreateMasterClientAndAuthenticate(this.Player3);

                this.ConnectClientToGame(client2, roomName);
                this.ConnectClientToGame(client3, roomName);

                var eventsData = new Hashtable {
                    { 1, 1 }
                };
                AddEventCacheData(client1, client2, client3, eventsData);

                client2.Disconnect();
                client3.Disconnect();

                // remove cached message
                client1.SendRequest(new OperationRequest
                {
                    OperationCode = OperationCode.RaiseEvent,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { ParameterCode.ActorList, new int[] { 3 } },
                        { ParameterCode.Cache, (byte)EventCaching.RemoveFromRoomCache },
                        { ParameterCode.Code, (byte)4 },
                    }
                });


                client4 = this.CreateMasterClientAndAuthenticate("Player4");
                this.ConnectClientToGame(client4, roomName);

                client4.WaitForEvent(EventCode.Join);
                client4.CheckThereIsEvent(1);
                client4.CheckThereIsEvent(2);

                client4.CheckThereIsEvent(3);
                client4.CheckThereIsNoEvent(4);
            }
            finally
            {
                DisposeClients(client1, client2, client3, client4);
            }
        }
        public void EventCache_AddGlobalEventRemoveUsingEventIdOnly()
        {
            UnifiedTestClient client1 = null;
            UnifiedTestClient client2 = null;

            try
            {
                var roomName = this.GenerateRandomizedRoomName(MethodBase.GetCurrentMethod().Name);

                // create room
                client1 = this.CreateMasterClientAndAuthenticate(this.Player1);

                var createGameRequest = new CreateGameRequest
                {
                    GameId          = roomName,
                    CheckUserOnJoin = !string.IsNullOrEmpty(this.Player1),
                };

                var createGameResponse = client1.CreateGame(createGameRequest);

                this.ConnectAndAuthenticate(client1, createGameResponse.Address);

                // creation on GS
                client1.CreateGame(createGameRequest);

                // add cached message
                client1.SendRequest(new OperationRequest
                {
                    OperationCode = OperationCode.RaiseEvent,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { ParameterCode.Code, (byte)1 },
                        { ParameterCode.Cache, (byte)EventCaching.AddToRoomCacheGlobal },
                    }
                });

                // add cached message
                client1.SendRequest(new OperationRequest
                {
                    OperationCode = OperationCode.RaiseEvent,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { ParameterCode.Code, (byte)2 },
                        { ParameterCode.Cache, (byte)EventCaching.AddToRoomCacheGlobal },
                    }
                });

                // remove cached message
                client1.SendRequest(new OperationRequest
                {
                    OperationCode = OperationCode.RaiseEvent,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { ParameterCode.Code, (byte)1 },
                        { ParameterCode.Cache, (byte)EventCaching.RemoveFromRoomCache },
                    }
                });

                // second player joins and check that there is no removed event
                client2 = this.CreateMasterClientAndAuthenticate(this.Player2);

                this.ConnectClientToGame(client2, roomName);

                client2.WaitForEvent(EventCode.Join);

                client2.CheckThereIsNoEvent(1);
                client2.CheckThereIsEvent(2);
            }
            finally
            {
                DisposeClients(client1, client2);
            }
        }
        public void EventCache_ActorReplaceData()
        {
            UnifiedTestClient client1 = null;
            UnifiedTestClient client2 = null;
            UnifiedTestClient client3 = null;
            UnifiedTestClient client4 = null;

            try
            {
                var roomName = this.GenerateRandomizedRoomName(MethodBase.GetCurrentMethod().Name);

                // create room
                client1 = this.CreateMasterClientAndAuthenticate(this.Player1);

                var createGameRequest = new CreateGameRequest
                {
                    GameId          = roomName,
                    CheckUserOnJoin = !string.IsNullOrEmpty(this.Player1),
                };

                var createGameResponse = client1.CreateGame(createGameRequest);

                this.ConnectAndAuthenticate(client1, createGameResponse.Address);

                // creation on GS
                client1.CreateGame(createGameRequest);


                // second player joins and check that there is no removed event
                client2 = this.CreateMasterClientAndAuthenticate(this.Player2);
                client3 = this.CreateMasterClientAndAuthenticate(this.Player3);

                this.ConnectClientToGame(client2, roomName);
                this.ConnectClientToGame(client3, roomName);

                var eventsData = new Hashtable {
                    { 1, 1 }
                };
                var eventsData2 = new Hashtable
                {
                    { 2, 2 }
                };
                AddActorEventCacheData(client1, client2, client3, eventsData);

                client2.Disconnect();
                client3.Disconnect();

                // update cached message
                client1.SendRequest(new OperationRequest
                {
                    OperationCode = OperationCode.RaiseEvent,
                    Parameters    = new Dictionary <byte, object>
                    {
                        { ParameterCode.Data, eventsData2 },
                        { ParameterCode.Cache, (byte)EventCaching.ReplaceCache },
                        { ParameterCode.Code, (byte)1 },
                    }
                });


                client4 = this.CreateMasterClientAndAuthenticate("Player4");
                this.ConnectClientToGame(client4, roomName);

                client4.WaitForEvent(EventCode.Join);

                EventData ev;
                Assert.That(client4.TryWaitEvent(1, this.WaitTimeout, out ev), Is.True);

                Assert.That(ev[(byte)ParameterKey.Data], Is.EqualTo(eventsData2));
                client4.CheckThereIsEvent(2);
                client4.CheckThereIsEvent(3);
            }
            finally
            {
                DisposeClients(client1, client2, client3, client4);
            }
        }
示例#5
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);
            }
        }
示例#6
0
        public void A_Group_PluginHttpCallSyncAfterContinueTests()
        {
            const string config = "HttpCallSyncAfterContinue";

            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 }
                          } }
                    }
                });

                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);

                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);

                client2.SendRequestAndWaitForResponse(new OperationRequest
                {
                    OperationCode = OperationCode.Leave,
                    Parameters    = new Dictionary <byte, object> {
                        { ParameterCode.IsInactive, true }
                    }
                });

                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);
            }
        }