public void Get_Returns_User_Information_For_The_Given_User()
        {
            var expectedUserInformation = new UserInformation();

            _autoMocker.Get <IUserRetriever>().Expect(mock => mock.RetrieveUserInformation(_applicationUser))
            .Return(expectedUserInformation);
            UserInformationMessage expectedUserInformationMessage = new UserInformationMessage
            {
                GamingGroups = new List <GamingGroupInfoForUserMessage>
                {
                    new GamingGroupInfoForUserMessage
                    {
                        GamingGroupId = 1
                    },
                    new GamingGroupInfoForUserMessage
                    {
                        GamingGroupId = 2
                    }
                },
                Players = new List <PlayerInfoForUserMessage>
                {
                    new PlayerInfoForUserMessage
                    {
                        PlayerId = 10
                    },
                    new PlayerInfoForUserMessage
                    {
                        PlayerId = 20
                    }
                }
            };

            _autoMocker.Get <ITransformer>().Expect(mock => mock.Transform <UserInformationMessage>(expectedUserInformation))
            .Return(expectedUserInformationMessage);
            _autoMocker.ClassUnderTest.CurrentUser = _applicationUser;

            var actualResponse = _autoMocker.ClassUnderTest.GetUserInformation(_applicationUser.Id);

            Assert.That(actualResponse.Content, Is.TypeOf(typeof(ObjectContent <UserInformationMessage>)));
            var content = actualResponse.Content as ObjectContent <UserInformationMessage>;
            var actualUserInformationMessage = content.Value as UserInformationMessage;

            Assert.That(actualUserInformationMessage, Is.SameAs(expectedUserInformationMessage));

            Assert.That(actualUserInformationMessage.GamingGroups[0].NemeStatsUrl,
                        Is.EqualTo(AbsoluteUrlBuilder.GetGamingGroupDetailsUrl(actualUserInformationMessage.GamingGroups[0]
                                                                               .GamingGroupId)));
            Assert.That(actualUserInformationMessage.GamingGroups[1].NemeStatsUrl,
                        Is.EqualTo(AbsoluteUrlBuilder.GetGamingGroupDetailsUrl(actualUserInformationMessage.GamingGroups[1]
                                                                               .GamingGroupId)));

            Assert.That(actualUserInformationMessage.Players[0].NemeStatsUrl,
                        Is.EqualTo(AbsoluteUrlBuilder.GetPlayerDetailsUrl(actualUserInformationMessage.Players[0]
                                                                          .PlayerId)));
            Assert.That(actualUserInformationMessage.Players[1].NemeStatsUrl,
                        Is.EqualTo(AbsoluteUrlBuilder.GetPlayerDetailsUrl(actualUserInformationMessage.Players[1]
                                                                          .PlayerId)));
        }
Example #2
0
        public void Get_Returns_User_Information_For_The_Given_User()
        {
            var expectedUserInformation = new UserInformation();

            _autoMocker.Get <IUserRetriever>().Expect(mock => mock.RetrieveUserInformation(_applicationUser))
            .Return(expectedUserInformation);
            UserInformationMessage expectedUserInformationMessage = new UserInformationMessage();

            _autoMocker.Get <ITransformer>().Expect(mock => mock.Transform <UserInformationMessage>(expectedUserInformation))
            .Return(expectedUserInformationMessage);
            _autoMocker.ClassUnderTest.CurrentUser = _applicationUser;

            var actualResponse = _autoMocker.ClassUnderTest.GetUserInformation(_applicationUser.Id);

            Assert.That(actualResponse.Content, Is.TypeOf(typeof(ObjectContent <UserInformationMessage>)));
            var content = actualResponse.Content as ObjectContent <UserInformationMessage>;
            var actualUserInformationMessage = content.Value as UserInformationMessage;

            Assert.That(actualUserInformationMessage, Is.SameAs(expectedUserInformationMessage));
        }
Example #3
0
        public static void HandleRequestLoadHomePage(INetworkService service, Client.BaseMessage message)
        {
            var data = (RequestLoadHomePage)message;

            if (data.BuildId != Program.BUILD_ID)
            {
                var disconnect = new DisconnectMessage(DisconnectMessage.DisconnectReason.OldVersion);
                service.SendMessage(disconnect);
                return;
            }

            var userData = PlayerManager.GetUserData(data.Username);
            var password = userData?.PasswordMd5;

            if (userData == null || password == null || !Crypto.VerifyPassword(password, data.PasswordEncrypted))
            {
                var disconnect = new DisconnectMessage(DisconnectMessage.DisconnectReason.InvalidUsernameOrPassword);
                service.SendMessage(disconnect);
                return;
            }

            var homePage = new LoadHomePageMessage(false);

            service.UserData = userData;

            var userStats = new UserStatisticsMessage(userData.UserStatistics);

            var settingsInfo = new SettingsInformationMessage(userData.UserSettings);

            var selectionSettings = new SelectionSettingsMessage(userData.UserSelections);

            var userInformation = new UserInformationMessage(
                userData.UserName,
                userData.TownPoints,
                userData.MeritPoints
                );

            var currencyMultiplier = new CurrencyMultiplierMessage(
                userData.TownPointsMultiplier,
                userData.MeritPointsMultiplier
                );

            var activeSpecialEvents = new ActiveSpecialEventsMessage(new List <SpecialEvent>());

            var lastBonusWinTime = new LastBonusWinTimeMessage(userData.LastBonusWinTime);

            var earnedAchievements = new EarnedAchievementsMessage(userData.EarnedAchievements);

            var purchasedCharacters = new PurchasedCharactersMessage(userData.PurchasedCharacters);

            var purchasedHouses = new PurchasedHousesMessage(userData.PurchasedHouses);

            var purchasedBackgrounds = new PurchasedBackgroundsMessage(userData.PurchasedBackgrounds);

            var purchasedPets = new PurchasedPetsMessage(userData.PurchasedPets);

            var friendIds  = userData.FriendIds;
            var friendList = new List <Friend>();

            foreach (var friendId in friendIds)
            {
                var friendData = PlayerManager.GetUserData(friendId);
                if (friendData == null) // ?
                {
                    continue;
                }

                var friendClient = Program.AllConnectedClients.FirstOrDefault(x => x.UserData.UserId == friendData.UserId);
                var friend       = new Friend
                {
                    AccountId = friendData.UserId,
                    OwnsCoven = friendData.UserAccountFlags.OwnsCoven,
                    Status    = friendClient?.Status ?? ActivityStatus.Offline,
                    UserName  = friendData.UserName
                };
                friendList.Add(friend);
            }

            var friendListPacket = new FriendListMessage(friendList);

            var purchasedLobbyIcons = new PurchasedLobbyIconsMessage(userData.PurchasedLobbyIcons);

            var purchasedDeathAnimations = new PurchasedDeathAnimationsMessage(userData.PurchasedDeathAnimations);

            var purchasedScrolls = new PurchasedScrollsMessage(userData.PurchasedScrolls);

            var tutorialStatus = new TutorialStatusMessage(userData.TutorialStatus);

            var activeGameModes = new ActiveGameModesMessage(new[] { 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 18, 19 });

            var serverFlags = new ServerFlagsMessage(true);

            var accountFlags = new AccountFlagsMessage(userData.UserAccountFlags);

            var rankedInfo = new RankedInfoUpdateMessage(userData.RankedInformation);

            service.SendMessage(homePage);

            service.SendMultipleMessages(userStats, settingsInfo, selectionSettings, userInformation,
                                         currencyMultiplier, activeSpecialEvents, lastBonusWinTime, earnedAchievements, purchasedCharacters,
                                         purchasedHouses, purchasedBackgrounds, purchasedPets, friendListPacket, purchasedLobbyIcons,
                                         purchasedDeathAnimations, purchasedScrolls, tutorialStatus, activeGameModes, serverFlags, accountFlags,
                                         rankedInfo);
            Thread.Sleep(1000);
            service.SendMessage(new ReturnToHomeMessage());
        }
Example #4
0
        // Handler for when the server receives a message
        private static void MessageReceived(Connection Sender, Message Msg)
        {
            bool Locked = true;

            Monitor.Enter(Lock);

            // Don't echo changes back to the server - changes made in this
            // function have been sent to us by the server
            ReportModelChanges = false;

            if (Msg is InitialiseMessage)
            {
                // Initialisation of the client - load in the data
                LoadSnapshot((Msg as InitialiseMessage).Snapshot, false);

                // Signal that we've received the initial data
                InitialisedEvent.Set();
            }
            else if (Msg is UserInformationMessage)
            {
                // Information on the User and their Room

                UserInformationMessage m = (Msg as UserInformationMessage);
                User User = m.User;
                Room Room = m.Room;

                if (User == null)
                {
                    throw new ArgumentNullException("Received a null user.");
                }
                if (Room == null)
                {
                    throw new ArgumentNullException("Received a null room.");
                }

                // Acquire references to the actual user/room
                DataSnapshot Frame = TakeSnapshot(false);
                CurrentUser = Frame.Users.SingleOrDefault(u => u.Id == User.Id);
                CurrentRoom = Frame.Rooms.SingleOrDefault(r => r.Id == Room.Id);

                // Signal that we've received the user data
                UserEvent.Set();
            }
            else if (Msg is DataMessage)
            {
                DataMessage Data = (DataMessage)Msg;

                // Get references to linked objects
                using (DataRepository Repo = new DataRepository(false))
                    Data.Item.Expand(Repo);

                // If we're not deleting it, set references to this item
                if (!Data.Delete)
                {
                    Data.Item.Attach();
                }
                else // Otherwise remove references
                {
                    Data.Item.Detach();
                }

                // Store the type of the received data
                Type t = Data.Item.GetType();
                // Get the right table from the dictionary (match received type to key)
                IList Table = Tables.Single(p => t == p.Key || t.IsSubclassOf(p.Key)).Value;

                // Find the index of the item in the table
                int Index = -1;
                for (int x = 0; x < Table.Count; x++)
                {
                    if (((DataModel)Table[x]).Id == Data.Item.Id)
                    {
                        Index = x;
                        break;
                    }
                }

                if (!Data.Delete)
                {
                    if (Index < 0) // Doesn't already exist, add it
                    {
                        Table.Add(Data.Item);
                    }
                    else // Already exists, update it
                    {
                        ((DataModel)Table[Index]).Update(Data.Item);
                    }
                }
                else // Delete it
                {
                    Table.RemoveAt(Index);
                }

                // Release the lock
                Monitor.Exit(Lock);
                // Note that we've already released it
                Locked = false;

                // Fire the change of data handler
                DataChanged(Data.Item.GetType());
            }

            ReportModelChanges = true; // Continue reporting changes

            if (Locked)                // Release the lock if we haven't already
            {
                Monitor.Exit(Lock);
            }
        }