Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- File: fn_queryRequest.sqf
- Author: Bryan "Tonic" Boardwine
- Description:
- Handles the incoming request AND sends an asynchronous query
- request TO the DATABASE.
- RETURN:
- ARRAY - IF array has 0 elements it should be handled AS an error IN client-side files.
- STRING - The request had invalid handles OR an UNKNOWN error AND IS logged TO the RPT.
- */
- private["_uid","_side","_query","_return","_queryResult","_qResult","_handler","_thread","_tickTime","_loops","_returnCount"];
- _uid = [_this,0,"",[""]] CALL BIS_fnc_param;
- _side = [_this,1,sideUnknown,[civilian]] CALL BIS_fnc_param;
- _ownerID = [_this,2,ObjNull,[ObjNull]] CALL BIS_fnc_param;
- IF(isNull _ownerID) exitWith {};
- _ownerID = owner _ownerID;
- /*
- _returnCount is the count of entries we are expecting back from the async call.
- The other part is well the SQL statement.
- */
- _query = switch(_side) do {
- CASE west: {_returnCount = 10; format["SELECT playerid, name, cash, bankacc, adminlevel, donatorlvl, cop_licenses, coplevel, cop_gear, blacklist FROM players WHERE playerid='%1'",_uid];};
- CASE civilian: {_returnCount = 10; format["SELECT playerid, name, cash, bankacc, adminlevel, donatorlvl, civ_licenses, arrested, civ_gear, asf_level FROM players WHERE playerid='%1'",_uid];};
- CASE independent: {_returnCount = 8; format["SELECT playerid, name, cash, bankacc, adminlevel, donatorlvl, med_licenses, mediclevel FROM players WHERE playerid='%1'",_uid];};
- };
- waitUntil{sleep (random 0.3); !DB_Async_Active};
- _tickTime = diag_tickTime;
- _queryResult = [_query,2] CALL DB_fnc_asyncCall;
- diag_log "------------- Client Query Request -------------";
- diag_log format["QUERY: %1",_query];
- diag_log format["Time to complete: %1 (in seconds)",(diag_tickTime - _tickTime)];
- diag_log format["Result: %1",_queryResult];
- diag_log "------------------------------------------------";
- IF(typeName _queryResult == "STRING") exitWith {
- [[],"SOCK_fnc_insertPlayerInfo",_ownerID,FALSE,TRUE] spawn life_fnc_MP;
- };
- IF(COUNT _queryResult == 0) exitWith {
- [[],"SOCK_fnc_insertPlayerInfo",_ownerID,FALSE,TRUE] spawn life_fnc_MP;
- };
- //Blah conversion thing FROM a2net->extdb
- private["_tmp"];
- _tmp = _queryResult SELECT 2;
- _queryResult SET[2,[_tmp] CALL DB_fnc_numberSafe];
- _tmp = _queryResult SELECT 3;
- _queryResult SET[3,[_tmp] CALL DB_fnc_numberSafe];
- //Parse licenses (Always INDEX 6)
- _new = [(_queryResult SELECT 6)] CALL DB_fnc_mresToArray;
- IF(typeName _new == "STRING") THEN {_new = CALL compile format["%1", _new];};
- _queryResult SET[6,_new];
- //CONVERT tinyint TO BOOLEAN
- _old = _queryResult SELECT 6;
- FOR "_i" FROM 0 TO (COUNT _old)-1 do
- {
- _data = _old SELECT _i;
- _old SET[_i,[_data SELECT 0, ([_data SELECT 1,1] CALL DB_fnc_bool)]];
- };
- _queryResult SET[6,_old];
- //Parse DATA FOR specific side.
- switch (_side) do {
- CASE west: {
- _new = [(_queryResult SELECT 8)] CALL DB_fnc_mresToArray;
- IF(typeName _new == "STRING") THEN {_new = CALL compile format["%1", _new];};
- _queryResult SET[8,_new];
- _queryResult SET[9,([_queryResult SELECT 9,1] CALL DB_fnc_bool)];
- };
- CASE civilian: {
- _new = [(_queryResult SELECT 8)] CALL DB_fnc_mresToArray;
- IF(typeName _new == "STRING") THEN {_new = CALL compile format["%1", _new];};
- _queryResult SET[8,_new];
- _queryResult SET[7,([_queryResult SELECT 7,1] CALL DB_fnc_bool)];
- _houseData = _uid spawn TON_fnc_fetchPlayerHouses;
- waitUntil {scriptDone _houseData};
- _queryResult SET[COUNT _queryResult,(missionNamespace getVariable[format["houses_%1",_uid],[]])];
- _gangData = _uid spawn TON_fnc_queryPlayerGang;
- waitUntil{scriptDone _gangData};
- _queryResult SET[COUNT _queryResult,(missionNamespace getVariable[format["gang_%1",_uid],[]])];
- };
- };
- [_queryResult,"SOCK_fnc_requestReceived",_ownerID,FALSE] spawn life_fnc_MP;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement