public StatisticValue GetStatistic(XboxLiveUser user, string statName) { if (user == null) { throw new ArgumentNullException("user"); } // Allocates memory for returned objects IntPtr cStatValue; IntPtr cErrMessage; IntPtr cStatName = MarshalingHelpers.StringToHGlobalUtf8(statName); // Invokes the c method XSAPI_RESULT errCode = StatsManagerGetStat(user.Impl.XboxLiveUserPtr, cStatName, out cStatValue, out cErrMessage); Marshal.FreeHGlobal(cStatName); if (errCode != XSAPI_RESULT.XSAPI_RESULT_OK) { throw new XboxException(errCode, cErrMessage); } // Does local work StatisticValue statValue = new StatisticValue(cStatValue); return(statValue); }
public StatisticValue GetStatistic(XboxLiveUser user, string statName) { if (user == null) { throw new ArgumentNullException("user"); } // Allocates memory for returned objects IntPtr cStatValue = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>()); IntPtr cErrMessage = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>()); IntPtr cStatName = Marshal.StringToHGlobalAnsi(statName); // Invokes the c method XSAPI_RESULT errCode = StatsManagerGetStat(user.Impl.XboxLiveUserPtr, cStatName, cStatValue, cErrMessage); // Handles error string errMessage = Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(cErrMessage)); Marshal.FreeHGlobal(cErrMessage); if (errCode != XSAPI_RESULT.XSAPI_RESULT_OK) { // todo do something } // Handles returned objects StatisticValue statValue = new StatisticValue(Marshal.ReadIntPtr(cStatValue)); Marshal.FreeHGlobal(cStatValue); return(statValue); }
public void GetLeaderboard(XboxLiveUser user, string statName, LeaderboardQuery query) { if (!LocalUsers.Contains(user)) { throw new ArgumentException("Local User needs to be added."); } if (!mStats.ContainsKey(statName)) { mStats[statName] = new StatisticValue() { Name = statName, AsInteger = 300, AsNumber = 300, DataType = StatisticDataType.Number }; } StatisticValue stat = mStats[statName]; List <LeaderboardRow> rows = new List <LeaderboardRow>(); uint maxScore = query.MaxItems * 100; uint rankOffset = query.SkipResultToRank == 0 ? 1 : query.SkipResultToRank; bool userDisplayed = false; for (uint i = 0; i < query.MaxItems; i++) { uint score = maxScore - i * 100; LeaderboardRow row; if (!userDisplayed && stat.DataType == StatisticDataType.Number && (stat.AsNumber >= score || stat.AsInteger >= score)) { userDisplayed = true; row = new LeaderboardRow(new List <string> { stat.AsNumber.ToString() }, i + rankOffset, 0.8, user.XboxUserId, user.Gamertag); } else { row = new LeaderboardRow(new List <string> { score.ToString() }, i + rankOffset, 0.8, string.Format("{0}{0}{0}{0}{0}{0}{0}{0}", i), string.Format("Gamertag {0}", i)); } rows.Add(row); } List <LeaderboardColumn> cols = new List <LeaderboardColumn>(); cols.Add(new LeaderboardColumn(stat.DataType == StatisticDataType.String ? LeaderboardStatType.String : LeaderboardStatType.Integer, "")); LeaderboardResult result = new LeaderboardResult(rows, cols, query.MaxItems); LeaderboardResultEventArgs args = new LeaderboardResultEventArgs(result); mStatEventList.Add(new StatisticEvent(StatisticEventType.GetLeaderboardComplete, user, args)); }