Пример #1
0
        private static void GetTokenAndSignatureComplete(XSAPI_RESULT_INFO result, XSAPI_TOKEN_AND_SIGNATURE_RESULT payload, IntPtr context)
        {
            int contextKey = context.ToInt32();

            XsapiCallbackContext <UserImpl, GetTokenAndSignatureResult> contextObject;

            if (XsapiCallbackContext <UserImpl, GetTokenAndSignatureResult> .TryRemove(contextKey, out contextObject))
            {
                if (result.errorCode == XSAPI_RESULT.XSAPI_RESULT_OK)
                {
                    contextObject.TaskCompletionSource.SetResult(new GetTokenAndSignatureResult
                    {
                        WebAccountId = MarshalingHelpers.Utf8ToString(payload.WebAccountId),
                        Privileges   = MarshalingHelpers.Utf8ToString(payload.Privileges),
                        AgeGroup     = MarshalingHelpers.Utf8ToString(payload.AgeGroup),
                        Gamertag     = MarshalingHelpers.Utf8ToString(payload.Gamertag),
                        XboxUserId   = MarshalingHelpers.Utf8ToString(payload.XboxUserId),
                        Signature    = MarshalingHelpers.Utf8ToString(payload.Signature),
                        Token        = MarshalingHelpers.Utf8ToString(payload.Token)
                    });
                }
                else
                {
                    contextObject.TaskCompletionSource.SetException(new XboxException(result));
                }
                contextObject.Dispose();
            }
        }
        internal LeaderboardColumn(IntPtr leaderboardColumnPtr)
        {
            LEADERBOARD_COLUMN cColumn = MarshalingHelpers.PtrToStructure <LEADERBOARD_COLUMN>(leaderboardColumnPtr);

            StatisticType = cColumn.StatType;
            StatisticName = MarshalingHelpers.Utf8ToString(cColumn.StatName);
        }
Пример #3
0
        internal PermissionDenyReason(IntPtr structPtr)
        {
            var permissionDenyReasonStruct = MarshalingHelpers.PtrToStructure <XSAPI_PRIVACY_PERMISSION_DENY_REASON>(structPtr);

            Reason            = MarshalingHelpers.Utf8ToString(permissionDenyReasonStruct.reason);
            RestrictedSetting = MarshalingHelpers.Utf8ToString(permissionDenyReasonStruct.restrictedSetting);
        }
 /// <summary>
 /// Initialze a TitleStorageQuota from the corresponding C object
 /// </summary>
 internal TitleStorageQuota(XSAPI_TITLE_STORAGE_QUOTA quotaStruct)
 {
     QuotaBytes             = quotaStruct.QuotaBytes;
     UsedBytes              = quotaStruct.UsedBytes;
     StorageType            = quotaStruct.storageType;
     XboxUserId             = MarshalingHelpers.Utf8ToString(quotaStruct.XboxUserId);
     ServiceConfigurationId = MarshalingHelpers.Utf8ToString(quotaStruct.ServiceConfigurationId);
 }
        internal PreferredColor(IntPtr preferredColorPtr)
        {
            PREFERRED_COLOR cPreferredColor = MarshalingHelpers.PtrToStructure <PREFERRED_COLOR>(preferredColorPtr);

            PrimaryColor   = MarshalingHelpers.Utf8ToString(cPreferredColor.PrimaryColor);
            SecondaryColor = MarshalingHelpers.Utf8ToString(cPreferredColor.SecondaryColor);
            TertiaryColor  = MarshalingHelpers.Utf8ToString(cPreferredColor.TertiaryColor);
        }
        // todo For perf consider if we need an init method and a refresh method seperate
        internal void Refresh()
        {
            var cSocialUserGroup = Marshal.PtrToStructure <XBOX_SOCIAL_USER_GROUP>(m_socialUserGroupPtr);

            // Properties
            SocialUserGroupType       = cSocialUserGroup.SocialUserGroupType;
            PresenceFilterOfGroup     = cSocialUserGroup.PresenceFilterOfGroup;
            RelationshipFilterOfGroup = cSocialUserGroup.RelationshipFilterOfGroup;

            // Local User
            if (LocalUser == null)
            {
                var manager = (SocialManager)XboxLive.Instance.SocialManager;
                LocalUser = manager.GetUser(cSocialUserGroup.LocalUser);
            }
            LocalUser.Impl.UpdatePropertiesFromXboxLiveUserPtr();

            // Users

            // todo: for perf consider not removing everthing, but updating certain things and deleting the rest
            m_users.Clear();

            if (cSocialUserGroup.UsersCount > 0)
            {
                IntPtr[] cUsersArray = new IntPtr[cSocialUserGroup.UsersCount];

                Marshal.Copy(cSocialUserGroup.Users, cUsersArray, 0, (int)cSocialUserGroup.UsersCount);


                for (int i = 0; i < cUsersArray.Count(); i++)
                {
                    var socialUser = new XboxSocialUser(cUsersArray[i]);
                    m_users[socialUser.XboxUserId] = socialUser;
                }
            }

            // Users Tracked

            // todo: for perf consider whether this list is static or dynamic
            m_trackedUsers.Clear();

            if (cSocialUserGroup.UsersTrackedBySocialUserGroupCount > 0)
            {
                IntPtr[] cTrackedUsers = new IntPtr[cSocialUserGroup.UsersTrackedBySocialUserGroupCount];

                Marshal.Copy(cSocialUserGroup.UsersTrackedBySocialUserGroup, cTrackedUsers, 0, (int)cSocialUserGroup.UsersTrackedBySocialUserGroupCount);


                for (int i = 0; i < cTrackedUsers.Count(); i++)
                {
                    var    cSocialUser = Marshal.PtrToStructure <SocialManager.XBOX_USER_ID_CONTAINER>(cTrackedUsers[i]);
                    string xuid        = MarshalingHelpers.Utf8ToString(cSocialUser.XboxUserId);
                    m_trackedUsers.Add(xuid);
                }
            }
        }
Пример #7
0
        internal StatisticValue(IntPtr statValuePtr)
        {
            STATISTIC_VALUE cStatValue = MarshalingHelpers.PtrToStructure <STATISTIC_VALUE>(statValuePtr);

            Name      = MarshalingHelpers.Utf8ToString(cStatValue.Name);
            AsNumber  = cStatValue.AsNumber;
            AsInteger = cStatValue.AsInteger;
            AsString  = MarshalingHelpers.Utf8ToString(cStatValue.AsString);
            DataType  = cStatValue.DataType;
        }
        internal SocialManagerPresenceTitleRecord(IntPtr titleRecordPtr)
        {
            SOCIAL_MANAGER_PRESENCE_TITLE_RECORD cTitleRecord = MarshalingHelpers.PtrToStructure <SOCIAL_MANAGER_PRESENCE_TITLE_RECORD>(titleRecordPtr);

            IsTitleActive  = cTitleRecord.IsTitleActive;
            IsBroadcasting = cTitleRecord.IsBroadcasting;
            Device         = cTitleRecord.DeviceType;
            TitleId        = cTitleRecord.TitleId;
            PresenceText   = MarshalingHelpers.Utf8ToString(cTitleRecord.PresenceText);
        }
Пример #9
0
        internal void Refresh()
        {
            var CStruct = MarshalingHelpers.PtrToStructure <XSAPI_TITLE_STORAGE_BLOB_METADATA>(this.metadataPtr);

            this.ServiceConfigurationId = MarshalingHelpers.Utf8ToString(CStruct.serviceConfigurationId);
            this.BlobPath    = MarshalingHelpers.Utf8ToString(CStruct.blobPath);
            this.BlobType    = CStruct.blobType;
            this.StorageType = CStruct.storageType;
            this.DisplayName = MarshalingHelpers.Utf8ToString(CStruct.displayName);
            this.ETag        = MarshalingHelpers.Utf8ToString(CStruct.ETag);
            this.Length      = CStruct.length;
            this.XboxUserId  = MarshalingHelpers.Utf8ToString(CStruct.xboxUserId);
        }
Пример #10
0
        public LeaderboardQueryImpl(IntPtr ptr, LeaderboardQuery query)
        {
            m_leaderboardQueryPtr = ptr;

            LEADERBOARD_QUERY cLeaderboardQuery = MarshalingHelpers.PtrToStructure <LEADERBOARD_QUERY>(m_leaderboardQueryPtr);

            m_skipResultToMe   = cLeaderboardQuery.SkipResultToMe;
            m_skipResultToRank = cLeaderboardQuery.SkipResultToRank;
            m_maxItems         = cLeaderboardQuery.MaxItems;
            m_order            = cLeaderboardQuery.Order;
            query.StatName     = MarshalingHelpers.Utf8ToString(cLeaderboardQuery.StatName);
            query.SocialGroup  = MarshalingHelpers.Utf8ToString(cLeaderboardQuery.SocialGroup);
            query.HasNext      = cLeaderboardQuery.HasNext;
        }
Пример #11
0
        internal PermissionCheckResult(XSAPI_PRIVACY_PERMISSION_CHECK_RESULT permissionCheckResultStruct)
        {
            IsAllowed           = permissionCheckResultStruct.isAllowed;
            PermissionRequested = MarshalingHelpers.Utf8ToString(permissionCheckResultStruct.permissionRequested);

            Reasons = new List <PermissionDenyReason>((int)permissionCheckResultStruct.denyReasonsCount);

            int    size          = MarshalingHelpers.SizeOf <XSAPI_PRIVACY_PERMISSION_DENY_REASON>();
            IntPtr denyReasonPtr = permissionCheckResultStruct.denyReasons;

            for (ulong i = 0; i < permissionCheckResultStruct.denyReasonsCount; ++i)
            {
                Reasons.Add(new PermissionDenyReason(denyReasonPtr));
                denyReasonPtr = denyReasonPtr.Increment(size);
            }
        }
        internal SocialEvent(IntPtr socialEventPtr, IList <XboxSocialUserGroup> groups)
        {
            SOCIAL_EVENT cSocialEvent = Marshal.PtrToStructure <SOCIAL_EVENT>(socialEventPtr);

            EventType = cSocialEvent.EventType;

            var manager = (SocialManager)XboxLive.Instance.SocialManager;

            User = manager.GetUser(cSocialEvent.User);

            try
            {
                SocialManager.SOCIAL_USER_GROUP_LOADED_ARGS cArgs = Marshal.PtrToStructure <SocialManager.SOCIAL_USER_GROUP_LOADED_ARGS>(cSocialEvent.EventArgs);

                foreach (XboxSocialUserGroup group in groups)
                {
                    if (cArgs.SocialUserGroup == group.GetPtr())
                    {
                        EventArgs = new SocialUserGroupLoadedEventArgs(group);
                        break;
                    }
                }
            }
            catch (Exception)
            {
                // Event args weren't SocialUserGroupLoadedArgs
            }

            List <string> usersAffected = new List <string>();

            if (cSocialEvent.UsersAffectedCount > 0)
            {
                IntPtr[] cUsersAffected = new IntPtr[cSocialEvent.UsersAffectedCount];
                Marshal.Copy(cSocialEvent.UsersAffected, cUsersAffected, 0, (int)cSocialEvent.UsersAffectedCount);
                foreach (IntPtr cXuidPtr in cUsersAffected)
                {
                    SocialManager.XBOX_USER_ID_CONTAINER cXuid = Marshal.PtrToStructure <SocialManager.XBOX_USER_ID_CONTAINER>(cXuidPtr);
                    string xuid = MarshalingHelpers.Utf8ToString(cXuid.XboxUserId);
                    usersAffected.Add(xuid);
                }
            }
            UsersAffected = usersAffected.AsReadOnly();

            ErrorCode   = cSocialEvent.ErrorCode;
            ErrorMessge = MarshalingHelpers.Utf8ToString(cSocialEvent.ErrorMessage);
        }
        internal MultiplePermissionsCheckResult(IntPtr multiplePermissionsStructPtr)
        {
            var multiplePermissionsStruct = MarshalingHelpers.PtrToStructure <XSAPI_PRIVACY_MULTIPLE_PERMISSIONS_CHECK_RESULT>(multiplePermissionsStructPtr);

            XboxUserId = MarshalingHelpers.Utf8ToString(multiplePermissionsStruct.xboxUserId);

            Items = new List <PermissionCheckResult>((int)multiplePermissionsStruct.itemsCount);

            int    size = MarshalingHelpers.SizeOf <XSAPI_PRIVACY_PERMISSION_CHECK_RESULT>();
            IntPtr permissionStructPtr = multiplePermissionsStruct.items;

            for (ulong i = 0; i < multiplePermissionsStruct.itemsCount; ++i)
            {
                var permissionCheckResultStruct = MarshalingHelpers.PtrToStructure <XSAPI_PRIVACY_PERMISSION_CHECK_RESULT>(permissionStructPtr);
                Items.Add(new PermissionCheckResult(permissionCheckResultStruct));
                permissionStructPtr = permissionStructPtr.Increment(size);
            }
        }
Пример #14
0
        internal void UpdatePropertiesFromXboxLiveUserPtr()
        {
            var xboxLiveUserStruct = Marshal.PtrToStructure <XSAPI_XBOX_LIVE_USER>(XboxLiveUserPtr);

            this.XboxUserId   = MarshalingHelpers.Utf8ToString(xboxLiveUserStruct.XboxUserId);
            this.Gamertag     = MarshalingHelpers.Utf8ToString(xboxLiveUserStruct.Gamertag);
            this.AgeGroup     = MarshalingHelpers.Utf8ToString(xboxLiveUserStruct.AgeGroup);
            this.Privileges   = MarshalingHelpers.Utf8ToString(xboxLiveUserStruct.Privileges);
            this.IsSignedIn   = Convert.ToBoolean(xboxLiveUserStruct.IsSignedIn);
            this.WebAccountId = MarshalingHelpers.Utf8ToString(xboxLiveUserStruct.WebAccountId);

            if (xboxLiveUserStruct.WindowsSystemUser != IntPtr.Zero)
            {
                var user = Marshal.GetObjectForIUnknown(xboxLiveUserStruct.WindowsSystemUser);
                if (user is Windows.System.User)
                {
                    this.CreationContext = user as User;
                }
            }
        }
        internal StatisticEvent(IntPtr statEventPtr)
        {
            STATISTIC_EVENT cStatEvent = Marshal.PtrToStructure <STATISTIC_EVENT>(statEventPtr);

            EventType = cStatEvent.EventType;

            try
            {
                EventArgs = new LeaderboardResultEventArgs(cStatEvent.EventArgs);
            }
            catch (Exception)
            {
                // not LeaderboardResultEventArgs
            }

            User = new XboxLiveUser(cStatEvent.LocalUser);

            ErrorCode    = cStatEvent.ErrorCode;
            ErrorMessage = MarshalingHelpers.Utf8ToString(cStatEvent.ErrorMessage);
        }
Пример #16
0
        private void UpdatePropertiesFromXboxLiveUser_c()
        {
            var xboxLiveUser_c = Marshal.PtrToStructure <XboxLiveUser_c>(m_xboxLiveUser_c);

            this.XboxUserId   = MarshalingHelpers.Utf8ToString(xboxLiveUser_c.XboxUserId);
            this.Gamertag     = MarshalingHelpers.Utf8ToString(xboxLiveUser_c.Gamertag);
            this.AgeGroup     = MarshalingHelpers.Utf8ToString(xboxLiveUser_c.AgeGroup);
            this.Privileges   = MarshalingHelpers.Utf8ToString(xboxLiveUser_c.Privileges);
            this.IsSignedIn   = Convert.ToBoolean(xboxLiveUser_c.IsSignedIn);
            this.WebAccountId = MarshalingHelpers.Utf8ToString(xboxLiveUser_c.WebAccountId);

            if (xboxLiveUser_c.WindowsSystemUser != IntPtr.Zero)
            {
                var user = Marshal.GetObjectForIUnknown(xboxLiveUser_c.WindowsSystemUser);
                if (user is Windows.System.User)
                {
                    this.CreationContext = user as User;
                }
            }
        }
Пример #17
0
        internal LeaderboardRow(IntPtr leaderboardRowPtr)
        {
            LEADERBOARD_ROW cRow = MarshalingHelpers.PtrToStructure <LEADERBOARD_ROW>(leaderboardRowPtr);

            Rank       = cRow.Rank;
            Percentile = cRow.Percentile;
            XboxUserId = MarshalingHelpers.Utf8ToString(cRow.XboxUserId);
            Gamertag   = MarshalingHelpers.Utf8ToString(cRow.Gamertag);

            Values = new List <string>();
            if (cRow.ColumnValuesCount > 0)
            {
                IntPtr[] cValues = new IntPtr[cRow.ColumnValuesCount];
                Marshal.Copy(cRow.ColumnValues, cValues, 0, (int)cRow.ColumnValuesCount);
                for (uint i = 0; i < cRow.ColumnValuesCount; i++)
                {
                    Values.Add(Marshal.PtrToStringAnsi(cValues[i]));
                }
            }
        }
        internal XboxSocialUser(IntPtr xboxSocialUserPtr)
        {
            XBOX_SOCIAL_USER cXboxSocialUser = Marshal.PtrToStructure <XBOX_SOCIAL_USER>(xboxSocialUserPtr);

            XboxUserId         = MarshalingHelpers.Utf8ToString(cXboxSocialUser.XboxUserId);
            DisplayName        = MarshalingHelpers.Utf8ToString(cXboxSocialUser.DisplayName);
            RealName           = MarshalingHelpers.Utf8ToString(cXboxSocialUser.RealName);
            DisplayPicRaw      = MarshalingHelpers.Utf8ToString(cXboxSocialUser.DisplayPicUrlRaw);
            UseAvatar          = cXboxSocialUser.UseAvatar;
            Gamertag           = MarshalingHelpers.Utf8ToString(cXboxSocialUser.Gamertag);
            Gamerscore         = MarshalingHelpers.Utf8ToString(cXboxSocialUser.Gamerscore);
            PreferredColor     = new PreferredColor(cXboxSocialUser.PreferredColor);
            IsFollowedByCaller = cXboxSocialUser.IsFollowedByCaller;
            IsFollowingUser    = cXboxSocialUser.IsFollowingUser;
            IsFavorite         = cXboxSocialUser.IsFavorite;

            PresenceRecord = new SocialManagerPresenceRecord(cXboxSocialUser.PresenceRecord);

            TitleHistory = new TitleHistory(cXboxSocialUser.TitleHistory);
        }