Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define DEBUG_MODE_FULL
- #include "\x\cba\addons\main\script_macros.hpp"
- //#include "definitions.sqf"
- disableSerialization;
- //http://community.bistudio.com/wiki/isServer
- if (isServer) then
- {
- //Register all the CBA event handlers for the server to run in order to connect to the plugin
- //https://dev-heaven.net/projects/cca/wiki/Custom_Events_System
- //Here's some information on locality of variables in Arma
- //http://forums.bistudio.com/showthread.php?124663-Locality-of-Variables-Between-Client-Server
- //http://community.bistudio.com/wiki/Variables
- //Mutex variable that we will use to ensure the server can only be running one query at a time.
- //This should be a Global variable and only have scope on the server.
- serverRunningQuery = false;
- TRACE_1("serverRunningQuery: ", serverRunningQuery);
- //TODO: check the return result for each callExtension to make sure the result was run successfully
- //1) The data being sent was not too long
- //2) An error wasn't returned
- //If something bad happens, log it via the CBA TRACE method
- ["po_get_loadout", {
- _unit = _this select 0;
- //_puid = _this select 1;
- _name = _this select 1;
- //http://community.bistudio.com/wiki/owner
- _owner = owner _unit;
- _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];
- TRACE_1("Query: ",_query);
- while{!isNil("serverRunningQuery") && serverRunningQuery} do { //busy wait
- };
- serverRunningQuery = true;
- _get = nil;
- while {isNil("_get")} do {
- _get = "Arma2Net.Unmanaged" callExtension format ["Arma2NETMySQLCommandAsync ['adminsystem', '%1']", _query];
- //TRACE_1("Returned Select with: ",_get);
- if (_get == "") then {
- _get = nil;
- };
- sleep 0.5; //sleep for a half-second so we don't thrash the server with callExtension calls
- };
- serverRunningQuery = false;
- //return the result back to the specific user that called this event
- //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
- ReturnedDatabaseLoadOuts = _get;
- _owner publicVariableClient "ReturnedDatabaseLoadOuts";
- //Technically, this variable is kind of like a mutex for the client side
- }
- ] call CBA_fnc_addEventHandler;
- fnc_maeh_fill_crate = {
- _get = _this select 0;
- _crateName = _this select 1;
- //This converts the string to an array
- _get = call compile _get;
- //TODO: this may change in the future??
- //only select the inner array, throw away this outer array shell
- _get = _get select 0;
- _get = _get select 0;
- //Initialize some empty arrays
- _additem = [];
- _addbackpack = [];
- _addweapon = [];
- _addmagazine = [];
- //https://dev-heaven.net/docs/cba/files/strings/fnc_find-sqf.html
- if ((_get select 1) != "") then {
- if ([(_get select 1), ";"] call CBA_fnc_find > 0) then {
- _additem = [(_get select 1), ";"] call CBA_fnc_split;
- } else {
- _additem set [0, (_get select 1)];
- };
- };
- if ((_get select 2) != "") then {
- if ([(_get select 2), ";"] call CBA_fnc_find > 0) then {
- _addbackpack = [(_get select 2), ";"] call CBA_fnc_split;
- } else {
- _addbackpack set [0, (_get select 2)];
- };
- };
- if ((_get select 3) != "") then {
- if ([(_get select 3), ";"] call CBA_fnc_find > 0) then {
- _addweapon = [(_get select 3), ";"] call CBA_fnc_split;
- } else {
- _addweapon set [0, (_get select 3)];
- };
- };
- if ((_get select 4) != "") then {
- if ([(_get select 4), ";"] call CBA_fnc_find > 0) then {
- _addmagazine = [(_get select 4), ";"] call CBA_fnc_split;
- } else {
- _addmagazine set [0, (_get select 4)];
- };
- };
- //Clear out everything so we can assign it
- clearMagazineCargoGlobal _crateName;
- clearWeaponCargoGlobal _crateName;
- clearItemCargoGlobal _crateName;
- clearBackpackCargoGlobal _crateName;
- [_additem, _crateName] spawn {
- _additem = _this select 0;
- _crateName = _this select 1;
- _IndexClassname = 0;
- _IndexAnzahl = 1;
- for [{_x=1},{_x<=(count _additem)},{_x=_x+2}] do {
- _classname = (_additem select _IndexClassname);
- _classname = format ["%1",_classname];
- _itemcount = (_additem select _IndexAnzahl);
- _itemcount = parseNumber _itemcount;
- _crateName addItemCargoGlobal [_classname, _itemcount];
- _IndexClassname = _IndexClassname + 2;
- _IndexAnzahl = _IndexAnzahl + 2;
- sleep 0.5;
- };
- };
- [_addbackpack, _crateName] spawn {
- _addbackpack = _this select 0;
- _crateName = _this select 1;
- _IndexClassname = 0;
- _IndexAnzahl = 1;
- for [{_x=1},{_x<=(count _addbackpack)},{_x=_x+2}] do {
- _classname = (_addbackpack select _IndexClassname);
- _classname = format ["%1",_classname];
- _itemcount = (_addbackpack select _IndexAnzahl);
- _itemcount = parseNumber _itemcount;
- _crateName addBackpackCargoGlobal [_classname, _itemcount];
- _IndexClassname = _IndexClassname + 2;
- _IndexAnzahl = _IndexAnzahl + 2;
- sleep 0.5;
- };
- };
- [_addweapon, _crateName] spawn {
- _addweapon = _this select 0;
- _crateName = _this select 1;
- _IndexClassname = 0;
- _IndexAnzahl = 1;
- for [{_x=1},{_x<=(count _addweapon)},{_x=_x+2}] do {
- _classname = (_addweapon select _IndexClassname);
- _classname = format ["%1",_classname];
- _itemcount = (_addweapon select _IndexAnzahl);
- _itemcount = parseNumber _itemcount;
- _crateName addWeaponCargoGlobal [_classname, _itemcount];
- _IndexClassname = _IndexClassname + 2;
- _IndexAnzahl = _IndexAnzahl + 2;
- sleep 0.5;
- };
- };
- [_addmagazine, _crateName] spawn {
- _addmagazine = _this select 0;
- _crateName = _this select 1;
- _IndexClassname = 0;
- _IndexAnzahl = 1;
- for [{_x=1},{_x<=(count _addmagazine)},{_x=_x+2}] do {
- _classname = (_addmagazine select _IndexClassname);
- _classname = format ["%1",_classname];
- _itemcount = (_addmagazine select _IndexAnzahl);
- _itemcount = parseNumber _itemcount;
- _crateName addMagazineCargoGlobal [_classname, _itemcount];
- _IndexClassname = _IndexClassname + 2;
- _IndexAnzahl = _IndexAnzahl + 2;
- sleep 0.5;
- };
- };
- };
- ["po_get_crate_inventory", {
- _crateName = _this select 0;
- //_puid = _this select 1;
- _crateInventory = _this select 1;
- //http://community.bistudio.com/wiki/owner
- _owner = owner _crateName;
- _query = format ["SELECT name, additem, addbackpack, addweapon, addmagazine FROM po_crates WHERE name = '%1'", _crateInventory];
- TRACE_1("Query: ",_query);
- while{!isNil("serverRunningQuery") && serverRunningQuery} do { //busy wait
- };
- serverRunningQuery = true;
- _get = nil;
- while {isNil("_get")} do {
- _get = "Arma2Net.Unmanaged" callExtension format ["Arma2NETMySQLCommandAsync ['adminsystem', '%1']", _query];
- //TRACE_1("Returned Select with: ",_get);
- if (_get == "") then {
- _get = nil;
- };
- sleep 0.5; //sleep for a half-second so we don't thrash the server with callExtension calls
- };
- [_get,_crateName] spawn fnc_maeh_fill_crate;
- serverRunningQuery = false;
- //return the result back to the specific user that called this event
- //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
- //ReturnedDatabaseLoadOuts = _get;
- //_owner publicVariableClient "ReturnedDatabaseLoadOuts";
- //Technically, this variable is kind of like a mutex for the client side
- }
- ] call CBA_fnc_addEventHandler;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement