Skip to content

Commit 44619c7

Browse files
committed
Added db_waitForResult
1 parent 8af53ad commit 44619c7

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

intercept

src/res.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <mariadb++/result_set.hpp>
33

44
using namespace intercept::client;
5-
5+
extern auto_array<ref<GameDataDBAsyncResult>> asyncWork;
66

77
game_data* createGameDataDBResult(param_archive* ar) {
88
auto x = new GameDataDBResult();
@@ -75,6 +75,24 @@ game_value Result::cmd_bindCallback(uintptr_t, game_value_parameter left, game_v
7575
return {};
7676
}
7777

78+
game_value Result::cmd_waitForResult(uintptr_t, game_value_parameter right) {
79+
auto& res = right.get_as<GameDataDBAsyncResult>();
80+
81+
res->data->res.wait();
82+
83+
for (int i = 0; i < asyncWork.size(); ++i) {
84+
if (asyncWork[i] == res) {
85+
asyncWork.erase(i);
86+
break;
87+
}
88+
}
89+
90+
auto gd_res = new GameDataDBResult();
91+
gd_res->res = res->data->res.get();
92+
sqf::call(res->data->callback, { gd_res, res->data->callbackArgs });
93+
return gd_res;
94+
}
95+
7896
void ::Result::initCommands() {
7997

8098
auto dbType = host::register_sqf_type("DBRES"sv, "databaseResult"sv, "TODO"sv, "databaseResult"sv, createGameDataDBResult);
@@ -89,6 +107,7 @@ void ::Result::initCommands() {
89107
handle_cmd_lastInsertId = client::host::register_sqf_command("db_resultLastInsertId", "TODO", Result::cmd_lastInsertId, game_data_type::SCALAR, GameDataDBResult_typeE);
90108
handle_cmd_toArray = client::host::register_sqf_command("db_resultToArray", "TODO", Result::cmd_toArray, game_data_type::ARRAY, GameDataDBResult_typeE);
91109
handle_cmd_bindCallback = client::host::register_sqf_command("db_bindCallback", "TODO", Result::cmd_bindCallback, game_data_type::NOTHING, GameDataDBAsyncResult_typeE, game_data_type::ARRAY);
110+
handle_cmd_waitForResult = client::host::register_sqf_command("db_waitForResult", "TODO", Result::cmd_waitForResult, GameDataDBResult_typeE, GameDataDBAsyncResult_typeE);
92111

93112

94113
}

src/res.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Result {
1414
static game_value cmd_lastInsertId(uintptr_t, game_value_parameter right);
1515
static game_value cmd_toArray(uintptr_t, game_value_parameter right);
1616
static game_value cmd_bindCallback(uintptr_t, game_value_parameter left, game_value_parameter right);
17+
static game_value cmd_waitForResult(uintptr_t, game_value_parameter right);
1718

1819
static void initCommands();
1920
static inline sqf_script_type GameDataDBResult_type;
@@ -25,6 +26,7 @@ class Result {
2526
static inline types::registered_sqf_function handle_cmd_lastInsertId;
2627
static inline types::registered_sqf_function handle_cmd_toArray;
2728
static inline types::registered_sqf_function handle_cmd_bindCallback;
29+
static inline types::registered_sqf_function handle_cmd_waitForResult;
2830
};
2931

3032

0 commit comments

Comments
 (0)