Advertisement
Guest User

fn_mresToArray.sqf

a guest
Feb 5th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 4.04 KB | None | 0 0
  1. /*
  2.     File: fn_mresToArray.sqf
  3.     Author: Bryan "Tonic" Boardwine";
  4.  
  5.     Description:
  6.     Acts as a mres (MySQL Real Escape) for arrays so they
  7.     can be properly inserted into the database without causing
  8.     any problems. The return method is 'hacky' but it's effective.
  9. */
  10. private["_array"];
  11. _array = [_this,0,"",[""]] call BIS_fnc_param;
  12. if (_array isEqualTo "") exitWith {[]};
  13. _array = toArray(_array);
  14.  
  15. for "_i" from 0 to (count _array)-1 do
  16. {
  17.     _sel = _array select _i;
  18.     if (_sel == 96) then
  19.     {
  20.         _array set[_i,39];
  21.     };
  22. };
  23.  
  24. _array = toString(_array);
  25. _array = call compile format["%1", _array];
  26. _array;
  27.  
  28. //-------------------------------------------------------------------------------------------------------------
  29. /*
  30.     File: fn_updateRequest.sqf
  31.     Author: Bryan "Tonic" Boardwine
  32.  
  33.     Description:
  34.     Updates ALL player information in the database.
  35.     Information gets passed here from the client side file: core\session\fn_updateRequest.sqf
  36. */
  37. private["_uid","_side","_cash","_bank","_licenses","_gear","_stats","_name","_alive","_position","_query","_thread"];
  38. _uid = [_this,0,"",[""]] call BIS_fnc_param;
  39. _name = [_this,1,"",[""]] call BIS_fnc_param;
  40. _side = [_this,2,sideUnknown,[civilian]] call BIS_fnc_param;
  41. _cash = [_this,3,0,[0]] call BIS_fnc_param;
  42. _bank = [_this,4,5000,[0]] call BIS_fnc_param;
  43. _licenses = [_this,5,[],[[]]] call BIS_fnc_param;
  44. _gear = [_this,6,[],[[]]] call BIS_fnc_param;
  45. _stats = [_this,7,[100,100],[[]]] call BIS_fnc_param;
  46. _alive = [_this,9,0,[0]] call BIS_fnc_param;
  47. _position = [_this,10,[],[[]]] call BIS_fnc_param;
  48. private ["_debitCiv","_debit"];
  49. _debitCiv = [_this,11,false,[true]] call BIS_fnc_param;
  50. _debit = [_this,8,false,[true]] call BIS_fnc_param;
  51. //Get to those error checks.
  52. if ((_uid isEqualTo "") || (_name isEqualTo "")) exitWith {};
  53.  
  54. //Parse and setup some data.
  55. _name = [_name] call DB_fnc_mresString;
  56. _gear = [_gear] call DB_fnc_mresArray;
  57. _stats = [_stats] call DB_fnc_mresArray;
  58. _cash = [_cash] call DB_fnc_numberSafe;
  59. _bank = [_bank] call DB_fnc_numberSafe;
  60. _position = if (_side isEqualTo civilian) then {[_position] call DB_fnc_mresArray} else {[]};
  61.  
  62. //Does something license related but I can't remember I only know it's important?
  63. for "_i" from 0 to count(_licenses)-1 do {
  64.     _bool = [(_licenses select _i) select 1] call DB_fnc_bool;
  65.     _licenses set[_i,[(_licenses select _i) select 0,_bool]];
  66. };
  67.  
  68. _licenses = [_licenses] call DB_fnc_mresArray;
  69.  
  70. //PLAYTIME
  71. _playtime = [_uid] call TON_fnc_getPlayTime;
  72. _playtime_update = [];
  73. {
  74.     if ((_x select 0) isEqualTo _uid) exitWith
  75.     {
  76.         _playtime_update pushBack [_x select 1];
  77.     };
  78. } forEach TON_fnc_playtime_values_request;
  79. _playtime_update = (_playtime_update select 0) select 0;
  80. switch (_side) do {
  81.     case west: {_playtime_update set[0,_playtime];};
  82.     case civilian: {_playtime_update set[2,_playtime];};
  83.     case independent: {_playtime_update set[1,_playtime];};
  84. };
  85. _playtime_update = [_playtime_update] call DB_fnc_mresArray;
  86.  
  87. switch (_side) do {
  88.     case west: {_query = format["UPDATE players SET name='%1', cash='%2', bankacc='%3', cop_gear='%4', cop_licenses='%5', cop_stats='%6', playtime='%7', debit='%8' WHERE playerid='%9'",_name,_cash,_bank,_gear,_licenses,_stats,_playtime_update,[_debit] call DB_fnc_bool,_uid];};
  89.     case civilian: {_query = format["UPDATE players SET name='%1', cash='%2', bankacc='%3', civ_licenses='%4', civ_gear='%5', arrested='%6', civ_stats='%7', civ_alive='%8', civ_position='%9', playtime='%10', debit='%11' WHERE playerid='%12'",_name,_cash,_bank,_licenses,_gear,[_this select 8] call DB_fnc_bool,_stats,[_this select 9] call DB_fnc_bool,_position,_playtime_update,[_debitCiv] call DB_fnc_bool,_uid];};
  90.     case independent: {_query = format["UPDATE players SET name='%1', cash='%2', bankacc='%3', med_licenses='%4', med_gear='%5', med_stats='%6', playtime='%7', debit='%8' WHERE playerid='%9'",_name,_cash,_bank,_licenses,_gear,_stats,_playtime_update,[_debit] call DB_fnc_bool,_uid];};
  91. };
  92.  
  93.  
  94. _queryResult = [_query,1] call DB_fnc_asyncCall;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement