Skip to content
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

Handle json file read errors #14

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions scripting/player_prefs.sma
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public plugin_init() {
register_plugin("Player preferences", "1.1.1", "ufame");

CreateForwards();
ReadDbCreadentials();
ReadDbCredentials();

g_bDebugMode = bool: (plugin_flags() & AMX_FLAG_DEBUG);
}
Expand Down Expand Up @@ -382,8 +382,23 @@ public ThreadQuery_Handler(iFailState, Handle: hQuery, szError[], iError, szData
}
}

ReadDbCreadentials() {
new JSON: credsConfig = json_parse(CONFIG_FILE, true);
ReadDbCredentials() {
if (!file_exists(CONFIG_FILE)) {
abort(AMX_ERR_GENERAL, "[PP] DB credentials file not found (%s).", CONFIG_FILE);
return;
}

new JSON: credsConfig = json_parse(CONFIG_FILE, true, true);

if (credsConfig == Invalid_JSON) {
abort(AMX_ERR_GENERAL, "[PP] JSON synax error in DB credentials file (%s).", CONFIG_FILE);
return;
}

if (!json_is_object(credsConfig)) {
abort(AMX_ERR_GENERAL, "[PP] DB credentials file must contain a JSON-object (%s).", CONFIG_FILE);
return;
}

json_object_get_string(credsConfig, "host", g_szSqlHost, charsmax(g_szSqlHost));
json_object_get_string(credsConfig, "user", g_szSqlUser, charsmax(g_szSqlUser));
Expand Down
Loading