STEAMID STEAM%:0:512440915 System.FormatException: The input string 'STEAM1:0:512440915'…
- User
STEAMID STEAM_%:0:512440915 System.FormatException: The input string 'STEAM_1:0:512440915' was not in a correct format. at System.Number.ThrowFormatException[TChar](ReadOnlySpan`1 value) at System.String.System.IConvertible.ToInt32(IFormatProvider provider) at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) at Deserializebda1d3d7-e56e-4d0c-943b-8e3d207f9055(DbDataReader) at Dapper.SqlMapper.QueryRowAsync[T](IDbConnection cnn, Row row, Type effectiveType, CommandDefinition command) in /_/Dapper/SqlMapper.Async.cs:line 496 at LK.LKPlugin.LoadPlayerData(LkPlayer player, SteamID steamId, String username) in C:\Users\zoro8\RiderProjects\LK\LK\LKPlugin.cs:line 143 [#2429984652 UDP steamid:76561198985147558@31.148.251.28:10497 'phantom'] closed by peer (2054): NETWORK_DISCONNECT_LOOPSHUTDOWN Steam Net connection #2429984652 UDP steamid:76561198985147558@31.148.251.28:10497 'phantom' closed by peer, reason 2054: NETWORK_DISCONNECT_LOOPSHUTDOWN в чем ошибка? private async Task LoadPlayerData(LkPlayer player, SteamID steamId, string username) { try { using var conn = await DatabaseProvider.OpenConnection(); var steamId2 = ConvertSteamId2(steamId.SteamId2); Console.WriteLine("SELECT * FROM lk WHERE auth LIKE '{steamId2}'");
if (data == null) { await conn.ExecuteAsync($@"INSERT INTO `lk` (`auth`, `name`, `cash`, `all_cash`) VALUES ('{steamId.SteamId2}', '{username}', 0, 0)"); player.TotalDonated = 0; player.Balance = 0; return; } player.TotalDonated = data.Value.all_cash; player.Balance = data.Value.cash; } catch (Exception e) { Console.WriteLine(e); throw; } } private string? ConvertSteamId2(string? steamId2) { if (steamId2 == null) return steamId2; var charArray = steamId2.ToCharArray(); charArray[6] = '%'; steamId2 = new string(charArray); return steamId2; } - Assistant
Based on the error message and the stack trace you've provided, it seems like the issue is with the handling and conversion of a SteamID format within your
LoadPlayerDatamethod, combined with the custom logic present inConvertSteamId2. The errorSystem.FormatException: The input string 'STEAM_1:0:512440915' was not in a correct format.suggests that somewhere in your code, there's an attempt to convert a part of this SteamID string into anInt32, which fails because the format of the string does not match any expected numeric format.The actual exception and its stack trace do not directly point to your provided code doing such conversion; hence, this might be happening indirectly, perhaps within the
Dapperlibrary calls or due to database schema expectations versus the provided input.Key Points of Attention:
-
Database Query String Construction: You're directly inserting variables into SQL queries; this is generally a bad practice due to SQL injection vulnerabilities. Instead, use parameterized queries to prevent this. It doesn't seem to be the cause of the issue here, but it's an important security aspect to address.
-
SteamID Handling and Conversion:
- Your method
ConvertSteamId2replaces a character in a SteamID to attempt to create a proper query condition. However, there's no clear indication that the conversion you're applying (charArray[6] = '%') has a straightforward purpose or correctness in the context of SteamID formats. - The
ConvertSteamId2might be an attempt to handle or patch a specific scenario, but it's important to note that SteamID formats are generally consistent, and applying arbitrary conversions might not be the best approach.
- Your method
Attempted Fix:
- Ensure that if you're manipulating or transforming SteamID formats, you're doing so according to the expected formatting rules. For instance, converting between SteamID3 ([U:1:IDNUMBER], SteamID64 (765...), and SteamID2 (STEAM_0:1:IDNUMBER)) should be done following Valve's official SteamID conventions.
- Investigate the stack trace further to identify where the conversion attempt to
Int32is being made. The error might lie in how the SteamID or part of it is being handled or processed for database storage or retrieval. - Review the database schema for column types and ensure they match the expected types in your queries. For Dapper to correctly map data to your model or tuple in
QuerySingleOrDefaultAsync, the types in the SQL query need to match your model.
For further debugging, you might want to:
- Directly inspect the output and manipulation of
steamId.SteamId2and its converted format to understand what's being passed into the query. - Ensure that your database interaction logic is robust against various formats or unexpected inputs, especially when dealing with external data like SteamIDs.
Note from the provided code: The problematic conversion does not seem evident in the visible snippet. The exact cause might be buried in how the
steamId.SteamId2is utilized within your database operations or an unrelated section of code attempting to manipulate the SteamID or a portion of it as an integer. -