Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 3.75 KB | None | 0 0
  1.     File: fn_queryRequest.sqf
  2.     Author: Bryan "Tonic" Boardwine
  3.    
  4.     Description:
  5.     Handles the incoming request AND sends an asynchronous query
  6.     request TO the DATABASE.
  7.    
  8.     RETURN:
  9.     ARRAY - IF array has 0 elements it should be handled AS an error IN client-side files.
  10.     STRING - The request had invalid handles OR an UNKNOWN error AND IS logged TO the RPT.
  11. */
  12. private["_uid","_side","_query","_return","_queryResult","_qResult","_handler","_thread","_tickTime","_loops","_returnCount"];
  13. _uid = [_this,0,"",[""]] CALL BIS_fnc_param;
  14. _side = [_this,1,sideUnknown,[civilian]] CALL BIS_fnc_param;
  15. _ownerID = [_this,2,ObjNull,[ObjNull]] CALL BIS_fnc_param;
  16.  
  17. IF(isNull _ownerID) exitWith {};
  18. _ownerID = owner _ownerID;
  19.  
  20. /*
  21.     _returnCount is the count of entries we are expecting back from the async call.
  22.     The other part is well the SQL statement.
  23. */
  24. _query = switch(_side) do {
  25.     CASE west: {_returnCount = 10; format["SELECT playerid, name, cash, bankacc, adminlevel, donatorlvl, cop_licenses, coplevel, cop_gear, blacklist FROM players WHERE playerid='%1'",_uid];};
  26.     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];};
  27.     CASE independent: {_returnCount = 8; format["SELECT playerid, name, cash, bankacc, adminlevel, donatorlvl, med_licenses, mediclevel FROM players WHERE playerid='%1'",_uid];};
  28. };
  29.  
  30. waitUntil{sleep (random 0.3); !DB_Async_Active};
  31. _tickTime = diag_tickTime;
  32. _queryResult = [_query,2] CALL DB_fnc_asyncCall;
  33.  
  34. diag_log "------------- Client Query Request -------------";
  35. diag_log format["QUERY: %1",_query];
  36. diag_log format["Time to complete: %1 (in seconds)",(diag_tickTime - _tickTime)];
  37. diag_log format["Result: %1",_queryResult];
  38. diag_log "------------------------------------------------";
  39.  
  40. IF(typeName _queryResult == "STRING") exitWith {
  41.     [[],"SOCK_fnc_insertPlayerInfo",_ownerID,FALSE,TRUE] spawn life_fnc_MP;
  42. };
  43.  
  44. IF(COUNT _queryResult == 0) exitWith {
  45.     [[],"SOCK_fnc_insertPlayerInfo",_ownerID,FALSE,TRUE] spawn life_fnc_MP;
  46. };
  47.  
  48. //Blah conversion thing FROM a2net->extdb
  49. private["_tmp"];
  50. _tmp = _queryResult SELECT 2;
  51. _queryResult SET[2,[_tmp] CALL DB_fnc_numberSafe];
  52. _tmp = _queryResult SELECT 3;
  53. _queryResult SET[3,[_tmp] CALL DB_fnc_numberSafe];
  54.  
  55. //Parse licenses (Always INDEX 6)
  56. _new = [(_queryResult SELECT 6)] CALL DB_fnc_mresToArray;
  57. IF(typeName _new == "STRING") THEN {_new = CALL compile format["%1", _new];};
  58. _queryResult SET[6,_new];
  59.  
  60. //CONVERT tinyint TO BOOLEAN
  61. _old = _queryResult SELECT 6;
  62. FOR "_i" FROM 0 TO (COUNT _old)-1 do
  63. {
  64.     _data = _old SELECT _i;
  65.     _old SET[_i,[_data SELECT 0, ([_data SELECT 1,1] CALL DB_fnc_bool)]];
  66. };
  67.  
  68. _queryResult SET[6,_old];
  69. //Parse DATA FOR specific side.
  70. switch (_side) do {
  71.     CASE west: {
  72.         _new = [(_queryResult SELECT 8)] CALL DB_fnc_mresToArray;
  73.         IF(typeName _new == "STRING") THEN {_new = CALL compile format["%1", _new];};
  74.         _queryResult SET[8,_new];
  75.         _queryResult SET[9,([_queryResult SELECT 9,1] CALL DB_fnc_bool)];
  76.     };
  77.    
  78.     CASE civilian: {
  79.         _new = [(_queryResult SELECT 8)] CALL DB_fnc_mresToArray;
  80.         IF(typeName _new == "STRING") THEN {_new = CALL compile format["%1", _new];};
  81.         _queryResult SET[8,_new];
  82.         _queryResult SET[7,([_queryResult SELECT 7,1] CALL DB_fnc_bool)];
  83.         _houseData = _uid spawn TON_fnc_fetchPlayerHouses;
  84.         waitUntil {scriptDone _houseData};
  85.         _queryResult SET[COUNT _queryResult,(missionNamespace getVariable[format["houses_%1",_uid],[]])];
  86.         _gangData = _uid spawn TON_fnc_queryPlayerGang;
  87.         waitUntil{scriptDone _gangData};
  88.         _queryResult SET[COUNT _queryResult,(missionNamespace getVariable[format["gang_%1",_uid],[]])];
  89.     };
  90. };
  91.  
  92. [_queryResult,"SOCK_fnc_requestReceived",_ownerID,FALSE] spawn life_fnc_MP;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement