Skip to content

Commit ddb54b9

Browse files
committed
Add config option to disable dynamic queries
1 parent a12e450 commit ddb54b9

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

addons/config.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
global:
2+
enableDynamicQueries: true #Allow queries to be created from SQF, if false only statements from config are allowed
3+
4+
accounts:
5+
maindb: #production db, don't break things here!
6+
ip: stuff
7+
username: root
8+
password: pw
9+
database: db
10+
port: 3306 #optional
11+
12+
statements:
13+
#getMissionName: SELECT intel_missionen.`name` FROM intel_missionen WHERE intel_missionen.id > ?
14+
getMissionName: SELECT 1
15+
16+
#DB_query = dbPrepareQueryConfig ["getMissionName", [400]];
17+
#DB_connection = dbCreateConnection "maindb";
18+
#DB_query = dbPrepareQueryConfig "getMissionName";
19+
#DB_connection dbExecuteAsync DB_query;

src/config.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ void Config::reloadConfig() {
6161
statements[stmtName] = it.second.as<r_string>();
6262
}
6363

64+
if (!config["global"].IsMap()) throw std::runtime_error("Config Global entry is not a map");
65+
66+
dynamicQueriesEnabled = config["global"]["enableDynamicQueries"].as<bool>(true);
67+
68+
69+
6470

6571
}
6672

src/config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@ class Config : public intercept::singleton<Config> {
2222
return found->second;
2323
}
2424

25+
bool areDynamicQueriesEnabled() const {
26+
return dynamicQueriesEnabled;
27+
}
28+
2529
static void initCommands();
2630
static inline registered_sqf_function handle_cmd_reloadConfig;
2731
static inline registered_sqf_function handle_cmd_version;
2832

2933
private:
3034
std::map<intercept::types::r_string, mariadb::account_ref> accounts;
3135
std::map<intercept::types::r_string, intercept::types::r_string> statements;
36+
bool dynamicQueriesEnabled = true;
3237

3338

3439

src/query.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ game_data* createGameDataDBQuery(param_archive* ar) {
1212
}
1313

1414

15-
game_value Query::cmd_prepareQuery(game_state&, game_value_parameter right) {
15+
game_value Query::cmd_prepareQuery(game_state& gs, game_value_parameter right) {
16+
if (!Config::get().areDynamicQueriesEnabled()) {
17+
gs.set_script_error(game_state::game_evaluator::evaluator_error_type::div_zero,
18+
"Dynamic queries have been disabled in config"sv);
19+
return {};
20+
}
1621
auto query = new GameDataDBQuery();
1722

1823
query->queryString = right;
@@ -21,6 +26,11 @@ game_value Query::cmd_prepareQuery(game_state&, game_value_parameter right) {
2126
}
2227

2328
game_value Query::cmd_prepareQueryAr(game_state& gs, game_value_parameter right) {
29+
if (!Config::get().areDynamicQueriesEnabled()) {
30+
gs.set_script_error(game_state::game_evaluator::evaluator_error_type::div_zero,
31+
"Dynamic queries have been disabled in config"sv);
32+
return {};
33+
}
2434
if (right.size() < 1) {
2535
gs.set_script_error(game_state::game_evaluator::evaluator_error_type::dim,
2636
"Not enough arguments provided, expected 2 but got 0"sv);

0 commit comments

Comments
 (0)