Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.64 KB | None | 0 0
  1. #define DEBUG_MODE_FULL
  2. #include "\x\cba\addons\main\script_macros.hpp"
  3. //#include "definitions.sqf"
  4. disableSerialization;
  5.  
  6. //http://community.bistudio.com/wiki/isServer
  7. if (isServer) then
  8. {
  9. //Register all the CBA event handlers for the server to run in order to connect to the plugin
  10. //https://dev-heaven.net/projects/cca/wiki/Custom_Events_System
  11. //Here's some information on locality of variables in Arma
  12. //http://forums.bistudio.com/showthread.php?124663-Locality-of-Variables-Between-Client-Server
  13.  
  14. //http://community.bistudio.com/wiki/Variables
  15. //Mutex variable that we will use to ensure the server can only be running one query at a time.
  16. //This should be a Global variable and only have scope on the server.
  17. serverRunningQuery = false;
  18. TRACE_1("serverRunningQuery: ", serverRunningQuery);
  19.  
  20. //TODO: check the return result for each callExtension to make sure the result was run successfully
  21. //1) The data being sent was not too long
  22. //2) An error wasn't returned
  23. //If something bad happens, log it via the CBA TRACE method
  24.  
  25. ["po_get_loadout", {
  26. _unit = _this select 0;
  27. //_puid = _this select 1;
  28. _name = _this select 1;
  29. //http://community.bistudio.com/wiki/owner
  30. _owner = owner _unit;
  31. _query = format ["SELECT name, ammo, weapons, items, assignitems, headgear, goggles, vest, vestitems, uniform, uniformitems, backpack, packitems, handgunitems, primarywep, secondarywep, isMedic, selectWeapon FROM po_loadout WHERE name = '%1'", _name];
  32. TRACE_1("Query: ",_query);
  33. while{!isNil("serverRunningQuery") && serverRunningQuery} do { //busy wait
  34. };
  35. serverRunningQuery = true;
  36. _get = nil;
  37. while {isNil("_get")} do {
  38. _get = "Arma2Net.Unmanaged" callExtension format ["Arma2NETMySQLCommandAsync ['adminsystem', '%1']", _query];
  39. //TRACE_1("Returned Select with: ",_get);
  40. if (_get == "") then {
  41. _get = nil;
  42. };
  43. sleep 0.5; //sleep for a half-second so we don't thrash the server with callExtension calls
  44. };
  45. serverRunningQuery = false;
  46.  
  47. //return the result back to the specific user that called this event
  48. //http://forums.bistudio.com/showthread.php?136494-ARMA-2-OA-beta-build-94209-%281-60-MP-compatible-build-post-1-60-release%29&p=2179795&viewfull=1#post2179795
  49. ReturnedDatabaseLoadOuts = _get;
  50. _owner publicVariableClient "ReturnedDatabaseLoadOuts";
  51. //Technically, this variable is kind of like a mutex for the client side
  52. }
  53. ] call CBA_fnc_addEventHandler;
  54.  
  55. fnc_maeh_fill_crate = {
  56. _get = _this select 0;
  57. _crateName = _this select 1;
  58. //This converts the string to an array
  59. _get = call compile _get;
  60.  
  61. //TODO: this may change in the future??
  62. //only select the inner array, throw away this outer array shell
  63. _get = _get select 0;
  64. _get = _get select 0;
  65.  
  66. //Initialize some empty arrays
  67. _additem = [];
  68. _addbackpack = [];
  69. _addweapon = [];
  70. _addmagazine = [];
  71.  
  72. //https://dev-heaven.net/docs/cba/files/strings/fnc_find-sqf.html
  73. if ((_get select 1) != "") then {
  74. if ([(_get select 1), ";"] call CBA_fnc_find > 0) then {
  75. _additem = [(_get select 1), ";"] call CBA_fnc_split;
  76. } else {
  77. _additem set [0, (_get select 1)];
  78. };
  79. };
  80.  
  81. if ((_get select 2) != "") then {
  82. if ([(_get select 2), ";"] call CBA_fnc_find > 0) then {
  83. _addbackpack = [(_get select 2), ";"] call CBA_fnc_split;
  84. } else {
  85. _addbackpack set [0, (_get select 2)];
  86. };
  87. };
  88.  
  89. if ((_get select 3) != "") then {
  90. if ([(_get select 3), ";"] call CBA_fnc_find > 0) then {
  91. _addweapon = [(_get select 3), ";"] call CBA_fnc_split;
  92. } else {
  93. _addweapon set [0, (_get select 3)];
  94. };
  95. };
  96.  
  97. if ((_get select 4) != "") then {
  98. if ([(_get select 4), ";"] call CBA_fnc_find > 0) then {
  99. _addmagazine = [(_get select 4), ";"] call CBA_fnc_split;
  100. } else {
  101. _addmagazine set [0, (_get select 4)];
  102. };
  103. };
  104.  
  105. //Clear out everything so we can assign it
  106. clearMagazineCargoGlobal _crateName;
  107. clearWeaponCargoGlobal _crateName;
  108. clearItemCargoGlobal _crateName;
  109. clearBackpackCargoGlobal _crateName;
  110.  
  111. [_additem, _crateName] spawn {
  112. _additem = _this select 0;
  113. _crateName = _this select 1;
  114. _IndexClassname = 0;
  115. _IndexAnzahl = 1;
  116. for [{_x=1},{_x<=(count _additem)},{_x=_x+2}] do {
  117. _classname = (_additem select _IndexClassname);
  118. _classname = format ["%1",_classname];
  119. _itemcount = (_additem select _IndexAnzahl);
  120. _itemcount = parseNumber _itemcount;
  121. _crateName addItemCargoGlobal [_classname, _itemcount];
  122. _IndexClassname = _IndexClassname + 2;
  123. _IndexAnzahl = _IndexAnzahl + 2;
  124. sleep 0.5;
  125. };
  126. };
  127.  
  128. [_addbackpack, _crateName] spawn {
  129. _addbackpack = _this select 0;
  130. _crateName = _this select 1;
  131. _IndexClassname = 0;
  132. _IndexAnzahl = 1;
  133. for [{_x=1},{_x<=(count _addbackpack)},{_x=_x+2}] do {
  134. _classname = (_addbackpack select _IndexClassname);
  135. _classname = format ["%1",_classname];
  136. _itemcount = (_addbackpack select _IndexAnzahl);
  137. _itemcount = parseNumber _itemcount;
  138. _crateName addBackpackCargoGlobal [_classname, _itemcount];
  139. _IndexClassname = _IndexClassname + 2;
  140. _IndexAnzahl = _IndexAnzahl + 2;
  141. sleep 0.5;
  142. };
  143. };
  144.  
  145. [_addweapon, _crateName] spawn {
  146. _addweapon = _this select 0;
  147. _crateName = _this select 1;
  148. _IndexClassname = 0;
  149. _IndexAnzahl = 1;
  150. for [{_x=1},{_x<=(count _addweapon)},{_x=_x+2}] do {
  151. _classname = (_addweapon select _IndexClassname);
  152. _classname = format ["%1",_classname];
  153. _itemcount = (_addweapon select _IndexAnzahl);
  154. _itemcount = parseNumber _itemcount;
  155. _crateName addWeaponCargoGlobal [_classname, _itemcount];
  156. _IndexClassname = _IndexClassname + 2;
  157. _IndexAnzahl = _IndexAnzahl + 2;
  158. sleep 0.5;
  159. };
  160. };
  161.  
  162. [_addmagazine, _crateName] spawn {
  163. _addmagazine = _this select 0;
  164. _crateName = _this select 1;
  165. _IndexClassname = 0;
  166. _IndexAnzahl = 1;
  167. for [{_x=1},{_x<=(count _addmagazine)},{_x=_x+2}] do {
  168. _classname = (_addmagazine select _IndexClassname);
  169. _classname = format ["%1",_classname];
  170. _itemcount = (_addmagazine select _IndexAnzahl);
  171. _itemcount = parseNumber _itemcount;
  172. _crateName addMagazineCargoGlobal [_classname, _itemcount];
  173. _IndexClassname = _IndexClassname + 2;
  174. _IndexAnzahl = _IndexAnzahl + 2;
  175. sleep 0.5;
  176. };
  177. };
  178. };
  179.  
  180. ["po_get_crate_inventory", {
  181. _crateName = _this select 0;
  182. //_puid = _this select 1;
  183. _crateInventory = _this select 1;
  184. //http://community.bistudio.com/wiki/owner
  185. _owner = owner _crateName;
  186. _query = format ["SELECT name, additem, addbackpack, addweapon, addmagazine FROM po_crates WHERE name = '%1'", _crateInventory];
  187. TRACE_1("Query: ",_query);
  188. while{!isNil("serverRunningQuery") && serverRunningQuery} do { //busy wait
  189. };
  190. serverRunningQuery = true;
  191. _get = nil;
  192. while {isNil("_get")} do {
  193. _get = "Arma2Net.Unmanaged" callExtension format ["Arma2NETMySQLCommandAsync ['adminsystem', '%1']", _query];
  194. //TRACE_1("Returned Select with: ",_get);
  195. if (_get == "") then {
  196. _get = nil;
  197. };
  198. sleep 0.5; //sleep for a half-second so we don't thrash the server with callExtension calls
  199. };
  200.  
  201. [_get,_crateName] spawn fnc_maeh_fill_crate;
  202.  
  203. serverRunningQuery = false;
  204.  
  205. //return the result back to the specific user that called this event
  206. //http://forums.bistudio.com/showthread.php?136494-ARMA-2-OA-beta-build-94209-%281-60-MP-compatible-build-post-1-60-release%29&p=2179795&viewfull=1#post2179795
  207. //ReturnedDatabaseLoadOuts = _get;
  208. //_owner publicVariableClient "ReturnedDatabaseLoadOuts";
  209. //Technically, this variable is kind of like a mutex for the client side
  210. }
  211. ] call CBA_fnc_addEventHandler;
  212. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement