-
-
Notifications
You must be signed in to change notification settings - Fork 4
Update SteamStatisticFactory.cs #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,44 +17,46 @@ public static class SteamStatisticFactory | |
/// </returns> | ||
/// <exception cref="ArgumentNullException">Occurs when the <paramref name="client"/>, <paramref name="stat"/>, or the <paramref name="stat"/> <see cref="StatInfoBase.Id"/> is <see langword="null"/> or empty.</exception> | ||
/// <exception cref="ArgumentOutOfRangeException">Occurs when an unkown <paramref name="stat"/> type is supplied.</exception> | ||
public static SteamStatisticBase CreateStat(Client client, StatInfoBase stat) | ||
public static SteamStatisticBase CreateStat(Client client, StatInfoBase stat) | ||
{ | ||
if (client == null) throw new ArgumentNullException(nameof(client)); | ||
if (string.IsNullOrEmpty(stat?.Id)) throw new ArgumentNullException(nameof(stat)); | ||
|
||
switch (stat) | ||
{ | ||
if (client == null) throw new ArgumentNullException(nameof(client)); | ||
if (string.IsNullOrEmpty(stat?.Id)) throw new ArgumentNullException(nameof(stat)); | ||
// STAT_INT | ||
case IntegerStatInfo intDefinition: | ||
{ | ||
if (!client.SteamUserStats.GetStatValue(intDefinition.Id, out int value)) break; | ||
|
||
switch (stat) | ||
intDefinition.Value = value; | ||
|
||
return new IntegerSteamStatistic(intDefinition); | ||
} | ||
// STAT_AVGRATE | ||
case AvgRateStatInfo avgRateDefinition: | ||
{ | ||
// STAT_INT | ||
case IntegerStatInfo intDefinition: | ||
{ | ||
if (!client.SteamUserStats.GetStatValue(intDefinition.Id, out int value)) break; | ||
|
||
intDefinition.Value = value; | ||
|
||
return new IntegerSteamStatistic(intDefinition); | ||
} | ||
// STAT_AVGRATE | ||
case AvgRateStatInfo avgRateDefinition: | ||
{ | ||
if (!client.SteamUserStats.GetStatValue(avgRateDefinition.Id, out float value)) break; | ||
|
||
avgRateDefinition.Value = value; | ||
|
||
// NOTE: average rate stats are always treated as floats | ||
return new FloatSteamStatistic(avgRateDefinition); | ||
} | ||
// STAT_FLOAT | ||
case FloatStatInfo floatDefinition: | ||
{ | ||
if (!client.SteamUserStats.GetStatValue(floatDefinition.Id, out float value)) break; | ||
|
||
floatDefinition.Value = value; | ||
|
||
return new FloatSteamStatistic(floatDefinition); | ||
} | ||
if (!client.SteamUserStats.GetStatValue(avgRateDefinition.Id, out float value)) break; | ||
|
||
avgRateDefinition.Value = value; | ||
|
||
// NOTE: average rate stats are always treated as floats | ||
return new FloatSteamStatistic(avgRateDefinition); | ||
} | ||
// STAT_FLOAT | ||
case FloatStatInfo floatDefinition: | ||
{ | ||
if (!client.SteamUserStats.GetStatValue(floatDefinition.Id, out float value)) break; | ||
|
||
throw new ArgumentOutOfRangeException(nameof(stat)); | ||
floatDefinition.Value = value; | ||
|
||
return new FloatSteamStatistic(floatDefinition); | ||
} | ||
default: | ||
// Log the type of the unhandled stat | ||
Console.WriteLine($"Unhandled stat type: {stat.GetType()} with ID: {stat.Id}"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this to private static readonly ILog log = LogManager.GetLogger(nameof(SteamStatisticFactory)); You'll need this namespace at the top too. using log4net; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That var sb = new StringBuilder();
sb.Append($"Unable to create user stat '{stat.Id}' in {client.AppId}. ");
sb.Append($"Stat '{stat.Id}' is type '{stat.UserStatType}' ({stat.UserStatType:D})");
// log the permissions flags if present
if (!string.IsNullOrEmpty(stat.Extra))
{
sb.Append($" with permissions '{stat.Extra}'");
}
sb.Append(".");
log.Error(sb); That should be enough info to figure out what's going on. I am guessing it's either a protected stat or something weird. I need to buy a game that has the issue so I can try and |
||
break; | ||
} | ||
|
||
throw new ArgumentOutOfRangeException(nameof(stat), $"Unhandled stat type: {stat?.GetType()} with ID: {stat?.Id}"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you fix this indentation, please?