SHOW:
|
|
- or go back to the newest paste.
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","_queryResult","_tickTime","_tmp"]; | |
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 | _query = switch (_side) do { | |
23 | - | // West - 12 entries returned |
23 | + | // West - 13 entries returned |
24 | case west: {format ["SELECT pid, name, cash, bankacc, adminlevel, donorlevel, cop_licenses, coplevel, cop_gear, blacklist, cop_stats, playtime, banking_pin FROM players WHERE pid='%1'",_uid];}; | |
25 | - | //East - 12 entries returned |
25 | + | //East - 12 entries returned |
26 | - | case east: {format["SELECT pid, name, cash, bankacc, adminlevel, donorlevel, adac_licenses, adaclevel, adac_gear, adac_stats, banking_pin, playtime, banking_pin FROM players WHERE pid='%1'",_uid];}; |
26 | + | case east: {format["SELECT pid, name, cash, bankacc, adminlevel, donorlevel, adac_licenses, adaclevel, adac_gear, adac_stats, playtime, banking_pin FROM players WHERE pid='%1'",_uid];}; |
27 | - | // Civilian - 13 entries returned |
27 | + | // Civilian - 14 entries returned |
28 | case civilian: {format ["SELECT pid, name, cash, bankacc, adminlevel, donorlevel, civ_licenses, arrested, civ_gear, civ_stats, civ_alive, civ_position, playtime, banking_pin FROM players WHERE pid='%1'",_uid];}; | |
29 | - | // Independent - 11 entries returned |
29 | + | // Independent - 12 entries returned |
30 | case independent: {format ["SELECT pid, name, cash, bankacc, adminlevel, donorlevel, med_licenses, mediclevel, med_gear, med_stats, playtime, banking_pin FROM players WHERE pid='%1'",_uid];}; | |
31 | }; | |
32 | ||
33 | _tickTime = diag_tickTime; | |
34 | _queryResult = [_query,2] call DB_fnc_asyncCall; | |
35 | ||
36 | if (EXTDB_SETTING(getNumber,"DebugMode") isEqualTo 1) then { | |
37 | diag_log "------------- Client Query Request -------------"; | |
38 | diag_log format ["QUERY: %1",_query]; | |
39 | diag_log format ["Time to complete: %1 (in seconds)",(diag_tickTime - _tickTime)]; | |
40 | diag_log format ["Result: %1",_queryResult]; | |
41 | diag_log "------------------------------------------------"; | |
42 | }; | |
43 | ||
44 | if (_queryResult isEqualType "") exitWith { | |
45 | [] remoteExecCall ["SOCK_fnc_insertPlayerInfo",_ownerID]; | |
46 | }; | |
47 | ||
48 | if (count _queryResult isEqualTo 0) exitWith { | |
49 | [] remoteExecCall ["SOCK_fnc_insertPlayerInfo",_ownerID]; | |
50 | }; | |
51 | ||
52 | //Blah conversion thing from a2net->extdb | |
53 | _tmp = _queryResult select 2; | |
54 | _queryResult set[2,[_tmp] call DB_fnc_numberSafe]; | |
55 | _tmp = _queryResult select 3; | |
56 | _queryResult set[3,[_tmp] call DB_fnc_numberSafe]; | |
57 | ||
58 | //Parse licenses (Always index 6) | |
59 | _new = [(_queryResult select 6)] call DB_fnc_mresToArray; | |
60 | if (_new isEqualType "") then {_new = call compile format ["%1", _new];}; | |
61 | _queryResult set[6,_new]; | |
62 | ||
63 | //Convert tinyint to boolean | |
64 | _old = _queryResult select 6; | |
65 | for "_i" from 0 to (count _old)-1 do { | |
66 | _data = _old select _i; | |
67 | _old set[_i,[_data select 0, ([_data select 1,1] call DB_fnc_bool)]]; | |
68 | }; | |
69 | ||
70 | _queryResult set[6,_old]; | |
71 | ||
72 | _new = [(_queryResult select 8)] call DB_fnc_mresToArray; | |
73 | if (_new isEqualType "") then {_new = call compile format ["%1", _new];}; | |
74 | _queryResult set[8,_new]; | |
75 | //Parse data for specific side. | |
76 | switch (_side) do { | |
77 | case west: { | |
78 | //=[ITGH]-- Banking Pin | |
79 | _queryResult set[16,([_queryResult select 12] call DB_fnc_numberSafe)]; | |
80 | ||
81 | _queryResult set[9,([_queryResult select 9,1] call DB_fnc_bool)]; | |
82 | ||
83 | //Parse Stats | |
84 | _new = [(_queryResult select 10)] call DB_fnc_mresToArray; | |
85 | if (_new isEqualType "") then {_new = call compile format ["%1", _new];}; | |
86 | _queryResult set[10,_new]; | |
87 | ||
88 | //Playtime | |
89 | _new = [(_queryResult select 11)] call DB_fnc_mresToArray; | |
90 | if (_new isEqualType "") then {_new = call compile format ["%1", _new];}; | |
91 | _index = TON_fnc_playtime_values_request find [_uid, _new]; | |
92 | if (_index != -1) then { | |
93 | TON_fnc_playtime_values_request set[_index,-1]; | |
94 | TON_fnc_playtime_values_request = TON_fnc_playtime_values_request - [-1]; | |
95 | TON_fnc_playtime_values_request pushBack [_uid, _new]; | |
96 | } else { | |
97 | TON_fnc_playtime_values_request pushBack [_uid, _new]; | |
98 | }; | |
99 | [_uid,_new select 0] call TON_fnc_setPlayTime; | |
100 | }; | |
101 | ||
102 | case civilian: { | |
103 | //=[ITGH]-- Banking Pin | |
104 | _queryResult set[16,([_queryResult select 13] call DB_fnc_numberSafe)]; | |
105 | ||
106 | _queryResult set[7,([_queryResult select 7,1] call DB_fnc_bool)]; | |
107 | ||
108 | //Parse Stats | |
109 | _new = [(_queryResult select 9)] call DB_fnc_mresToArray; | |
110 | if (_new isEqualType "") then {_new = call compile format ["%1", _new];}; | |
111 | _queryResult set[9,_new]; | |
112 | ||
113 | //Position | |
114 | _queryResult set[10,([_queryResult select 10,1] call DB_fnc_bool)]; | |
115 | _new = [(_queryResult select 11)] call DB_fnc_mresToArray; | |
116 | if (_new isEqualType "") then {_new = call compile format ["%1", _new];}; | |
117 | _queryResult set[11,_new]; | |
118 | ||
119 | //Playtime | |
120 | _new = [(_queryResult select 12)] call DB_fnc_mresToArray; | |
121 | if (_new isEqualType "") then {_new = call compile format ["%1", _new];}; | |
122 | _index = TON_fnc_playtime_values_request find [_uid, _new]; | |
123 | if (_index != -1) then { | |
124 | TON_fnc_playtime_values_request set[_index,-1]; | |
125 | TON_fnc_playtime_values_request = TON_fnc_playtime_values_request - [-1]; | |
126 | TON_fnc_playtime_values_request pushBack [_uid, _new]; | |
127 | } else { | |
128 | TON_fnc_playtime_values_request pushBack [_uid, _new]; | |
129 | }; | |
130 | [_uid,_new select 2] call TON_fnc_setPlayTime; | |
131 | ||
132 | /* Make sure nothing else is added under here */ | |
133 | _houseData = _uid spawn TON_fnc_fetchPlayerHouses; | |
134 | waitUntil {scriptDone _houseData}; | |
135 | _queryResult pushBack (missionNamespace getVariable [format ["houses_%1",_uid],[]]); | |
136 | _gangData = _uid spawn TON_fnc_queryPlayerGang; | |
137 | waitUntil{scriptDone _gangData}; | |
138 | _queryResult pushBack (missionNamespace getVariable [format ["gang_%1",_uid],[]]); | |
139 | ||
140 | }; | |
141 | ||
142 | case independent: { | |
143 | //=[ITGH]-- Banking Pin | |
144 | _queryResult set[16,([_queryResult select 11] call DB_fnc_numberSafe)]; | |
145 | ||
146 | //Parse Stats | |
147 | _new = [(_queryResult select 9)] call DB_fnc_mresToArray; | |
148 | if (_new isEqualType "") then {_new = call compile format ["%1", _new];}; | |
149 | _queryResult set[9,_new]; | |
150 | ||
151 | //Playtime | |
152 | _new = [(_queryResult select 10)] call DB_fnc_mresToArray; | |
153 | if (_new isEqualType "") then {_new = call compile format ["%1", _new];}; | |
154 | _index = TON_fnc_playtime_values_request find [_uid, _new]; | |
155 | if !(_index isEqualTo -1) then { | |
156 | TON_fnc_playtime_values_request set[_index,-1]; | |
157 | TON_fnc_playtime_values_request = TON_fnc_playtime_values_request - [-1]; | |
158 | TON_fnc_playtime_values_request pushBack [_uid, _new]; | |
159 | } else { | |
160 | TON_fnc_playtime_values_request pushBack [_uid, _new]; | |
161 | }; | |
162 | [_uid,_new select 1] call TON_fnc_setPlayTime; | |
163 | }; | |
164 | ||
165 | case east: { | |
166 | //=[ITGH]-- Banking Pin | |
167 | _queryResult set[16,([_queryResult select 11] call DB_fnc_numberSafe)]; | |
168 | ||
169 | //Parse Stats | |
170 | _new = [(_queryResult select 9)] call DB_fnc_mresToArray; | |
171 | if (_new isEqualType "") then {_new = call compile format["%1", _new];}; | |
172 | _queryResult set[9,_new]; | |
173 | ||
174 | //Playtime | |
175 | _new = [(_queryResult select 10)] call DB_fnc_mresToArray; | |
176 | if (_new isEqualType "") then {_new = call compile format["%1", _new];}; | |
177 | _index = TON_fnc_playtime_values_request find [_uid, _new]; | |
178 | if (_index != -1) then { | |
179 | TON_fnc_playtime_values_request set[_index,-1]; | |
180 | TON_fnc_playtime_values_request = TON_fnc_playtime_values_request - [-1]; | |
181 | TON_fnc_playtime_values_request pushBack [_uid, _new]; | |
182 | } else { | |
183 | TON_fnc_playtime_values_request pushBack [_uid, _new]; | |
184 | }; | |
185 | [_uid,_new select 1] call TON_fnc_setPlayTime; | |
186 | }; | |
187 | }; | |
188 | ||
189 | publicVariable "TON_fnc_playtime_values_request"; | |
190 | ||
191 | _keyArr = missionNamespace getVariable [format ["%1_KEYS_%2",_uid,_side],[]]; | |
192 | _queryResult pushBack _keyArr; | |
193 | ||
194 | _queryResult remoteExec ["SOCK_fnc_requestReceived",_ownerID]; |