Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. #include "\life_server\script_macros.hpp"
  2. /*
  3. File: fn_queryRequest.sqf
  4. Author: Bryan "Tonic" Boardwine
  5.  
  6. Description:
  7. Handles the incoming request and sends an asynchronous query
  8. request to the database.
  9.  
  10. Return:
  11. ARRAY - If array has 0 elements it should be handled as an error in client-side files.
  12. STRING - The request had invalid handles or an unknown error and is logged to the RPT.
  13. */
  14. private["_uid","_side","_query","_return","_queryResult","_qResult","_handler","_thread","_tickTime","_loops","_returnCount"];
  15. _uid = [_this,0,"",[""]] call BIS_fnc_param;
  16. _side = [_this,1,sideUnknown,[civilian]] call BIS_fnc_param;
  17. _ownerID = [_this,2,ObjNull,[ObjNull]] call BIS_fnc_param;
  18.  
  19. if(isNull _ownerID) exitWith {};
  20. _ownerID = owner _ownerID;
  21.  
  22. /*
  23. _returnCount is the count of entries we are expecting back from the async call.
  24. The other part is well the SQL statement.
  25. */
  26. _query = switch(_side) do {
  27. case west: {_returnCount = 11; format["SELECT playerid, name, cash, bankacc, adminlevel, donatorlvl, cop_licenses, coplevel, cop_gear, blacklist, cop_stats, banking_pin FROM players WHERE playerid='%1'",_uid];
  28.  
  29. _tmp = _queryResult select 12;
  30. _queryResult set[16,[_tmp] call DB_fnc_numberSafe];
  31.  
  32.  
  33. };
  34.  
  35.  
  36. case civilian: {_returnCount = 10; format["SELECT playerid, name, cash, bankacc, adminlevel, donatorlvl, civ_licenses, arrested, civ_gear, civ_stats, banking_pin FROM players WHERE playerid='%1'",_uid];
  37.  
  38. _tmp = _queryResult select 13;
  39. _queryResult set[16,[_tmp] call DB_fnc_numberSafe];
  40.  
  41. };
  42.  
  43.  
  44. case independent: {_returnCount = 10; format["SELECT playerid, name, cash, bankacc, adminlevel, donatorlvl, med_licenses, mediclevel, med_gear, med_stats, banking_pin FROM players WHERE playerid='%1'",_uid];
  45.  
  46.  
  47. _tmp = _queryResult select 11;
  48. _queryResult set[16,[_tmp] call DB_fnc_numberSafe];
  49. };
  50. };
  51.  
  52.  
  53. _tickTime = diag_tickTime;
  54. _queryResult = [_query,2] call DB_fnc_asyncCall;
  55.  
  56. if(EXTDB_SETTING(getNumber,"DebugMode") == 1) then {
  57. diag_log "------------- Client Query Request -------------";
  58. diag_log format["QUERY: %1",_query];
  59. diag_log format["Time to complete: %1 (in seconds)",(diag_tickTime - _tickTime)];
  60. diag_log format["Result: %1",_queryResult];
  61. diag_log "------------------------------------------------";
  62. };
  63.  
  64. if(typeName _queryResult == "STRING") exitWith {
  65. [] remoteExecCall ["SOCK_fnc_insertPlayerInfo",_ownerID];
  66. };
  67.  
  68. if(count _queryResult == 0) exitWith {
  69. [] remoteExecCall ["SOCK_fnc_insertPlayerInfo",_ownerID];
  70. };
  71.  
  72. //Blah conversion thing from a2net->extdb
  73. private["_tmp"];
  74. _tmp = _queryResult select 2;
  75. _queryResult set[2,[_tmp] call DB_fnc_numberSafe];
  76. _tmp = _queryResult select 3;
  77. _queryResult set[3,[_tmp] call DB_fnc_numberSafe];
  78.  
  79. //Parse licenses (Always index 6)
  80. _new = [(_queryResult select 6)] call DB_fnc_mresToArray;
  81. if(typeName _new == "STRING") then {_new = call compile format["%1", _new];};
  82. _queryResult set[6,_new];
  83.  
  84. //Convert tinyint to boolean
  85. _old = _queryResult select 6;
  86. for "_i" from 0 to (count _old)-1 do
  87. {
  88. _data = _old select _i;
  89. _old set[_i,[_data select 0, ([_data select 1,1] call DB_fnc_bool)]];
  90. };
  91.  
  92. _queryResult set[6,_old];
  93.  
  94. _new = [(_queryResult select 8)] call DB_fnc_mresToArray;
  95. if(typeName _new == "STRING") then {_new = call compile format["%1", _new];};
  96. _queryResult set[8,_new];
  97. //Parse data for specific side.
  98. switch (_side) do {
  99. case west: {
  100. _queryResult set[9,([_queryResult select 9,1] call DB_fnc_bool)];
  101.  
  102. //Parse Stats
  103. _new = [(_queryResult select 10)] call DB_fnc_mresToArray;
  104. if(typeName _new == "STRING") then {_new = call compile format["%1", _new];};
  105. _queryResult set[10,_new];
  106. };
  107.  
  108. case civilian: {
  109. _queryResult set[7,([_queryResult select 7,1] call DB_fnc_bool)];
  110.  
  111. //Parse Stats
  112. _new = [(_queryResult select 9)] call DB_fnc_mresToArray;
  113. if(typeName _new == "STRING") then {_new = call compile format["%1", _new];};
  114. _queryResult set[9,_new];
  115.  
  116. _houseData = [_uid] spawn TON_fnc_fetchPlayerHouses;
  117. waitUntil {scriptDone _houseData};
  118. _queryResult pushBack (missionNamespace getVariable[format["houses_%1",_uid],[]]);
  119. _gangData = _uid spawn TON_fnc_queryPlayerGang;
  120. waitUntil{scriptDone _gangData};
  121. _queryResult pushBack (missionNamespace getVariable[format["gang_%1",_uid],[]]);
  122. };
  123.  
  124. case independent: {
  125. //Parse Stats
  126. _new = [(_queryResult select 9)] call DB_fnc_mresToArray;
  127. if(typeName _new == "STRING") then {_new = call compile format["%1", _new];};
  128. _queryResult set[9,_new];
  129. };
  130. };
  131.  
  132. _keyArr = missionNamespace getVariable [format["%1_KEYS_%2",_uid,_side],[]];
  133. _queryResult set[13,_keyArr];
  134.  
  135. _queryResult remoteExec ["SOCK_fnc_requestReceived",_ownerID];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement