Advertisement
zapatahacks

Untitled

Sep 9th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.33 KB | None | 0 0
  1. #include "script_macros.hpp"
  2. /*
  3. File: init.sqf
  4. Author: Bryan "Tonic" Boardwine
  5.  
  6. Edit: Nanou for HeadlessClient optimization.
  7. Please read support for more informations.
  8.  
  9. Description:
  10. Initialize the server and required systems.
  11. */
  12. private ["_dome","_rsb","_timeStamp","_extDBNotLoaded"];
  13. DB_Async_Active = false;
  14. DB_Async_ExtraLock = false;
  15. life_serverFunctionsReady = false;
  16. TON_fnc_receiveFunctions =
  17. compileFinal "
  18. {
  19. _name = _x select 0;
  20. _code = _x select 1;
  21. missionNamespace setVariable [_name,_code];
  22. }forEach allFunctions;
  23. life_serverFunctionsReady = true;
  24. ";
  25. publicVariable "TON_fnc_receiveFunctions";
  26. [] spawn {
  27. ["server"] remoteExec ["TON_fnc_initFunctions",2];
  28. waitUntil {life_serverFunctionsReady};
  29. };
  30. _extDBNotLoaded = "";
  31. serv_sv_use = [];
  32. publicVariable "life_server_isReady";
  33. life_save_civilian_position = if (LIFE_SETTINGS(getNumber,"save_civilian_position") isEqualTo 0) then {false} else {true};
  34. fn_whoDoneIt = compile preprocessFileLineNumbers "\life_server\Functions\Systems\fn_whoDoneIt.sqf";
  35.  
  36. /*
  37. Prepare the headless client.
  38. */
  39. life_HC_isActive = false;
  40. publicVariable "life_HC_isActive";
  41. HC_Life = false;
  42. publicVariable "HC_Life";
  43.  
  44. if (EXTDB_SETTING(getNumber,"HeadlessSupport") isEqualTo 1) then {
  45. [] execVM "\life_server\initHC.sqf";
  46. };
  47.  
  48. /*
  49. Prepare extDB before starting the initialization process
  50. for the server.
  51. */
  52.  
  53. if (isNil {uiNamespace getVariable "life_sql_id"}) then {
  54. life_sql_id = round(random(9999));
  55. CONSTVAR(life_sql_id);
  56. uiNamespace setVariable ["life_sql_id",life_sql_id];
  57. try {
  58. _result = EXTDB format ["9:ADD_DATABASE:%1",EXTDB_SETTING(getText,"DatabaseName")];
  59. if (!(_result isEqualTo "[1]")) then {throw "extDB3: Error with Database Connection"};
  60. _result = EXTDB format ["9:ADD_DATABASE_PROTOCOL:%2:SQL:%1:TEXT2",FETCH_CONST(life_sql_id),EXTDB_SETTING(getText,"DatabaseName")];
  61. if (!(_result isEqualTo "[1]")) then {throw "extDB3: Error with Database Connection"};
  62. } catch {
  63. diag_log _exception;
  64. _extDBNotLoaded = [true, _exception];
  65. };
  66. if (_extDBNotLoaded isEqualType []) exitWith {};
  67. EXTDB "9:LOCK";
  68. diag_log "extDB3: Connected to Database";
  69. } else {
  70. life_sql_id = uiNamespace getVariable "life_sql_id";
  71. CONSTVAR(life_sql_id);
  72. diag_log "extDB3: Still Connected to Database";
  73. };
  74.  
  75.  
  76. if (_extDBNotLoaded isEqualType []) exitWith {
  77. life_server_extDB_notLoaded = true;
  78. publicVariable "life_server_extDB_notLoaded";
  79. };
  80. life_server_extDB_notLoaded = false;
  81. publicVariable "life_server_extDB_notLoaded";
  82.  
  83. /* Run stored procedures for SQL side cleanup */
  84. ["CALL resetLifeVehicles",1] call DB_fnc_asyncCall;
  85. ["CALL deleteDeadVehicles",1] call DB_fnc_asyncCall;
  86. ["CALL deleteOldHouses",1] call DB_fnc_asyncCall;
  87. ["CALL deleteOldGangs",1] call DB_fnc_asyncCall;
  88.  
  89. _timeStamp = diag_tickTime;
  90. diag_log "----------------------------------------------------------------------------------------------------";
  91. diag_log "---------------------------------- Starting Altis Life Server Init ---------------------------------";
  92. diag_log "------------------------------------------ Version 5.0.0 -------------------------------------------";
  93. diag_log "----------------------------------------------------------------------------------------------------";
  94.  
  95. if (LIFE_SETTINGS(getNumber,"save_civilian_position_restart") isEqualTo 1) then {
  96. [] spawn {
  97. _query = "UPDATE players SET civ_alive = '0' WHERE civ_alive = '1'";
  98. [_query,1] call DB_fnc_asyncCall;
  99. };
  100. };
  101.  
  102. /* Map-based server side initialization. */
  103. master_group attachTo[bank_obj,[0,0,0]];
  104.  
  105. {
  106. _hs = createVehicle ["Land_Hospital_main_F", [0,0,0], [], 0, "NONE"];
  107. _hs setDir (markerDir _x);
  108. _hs setPosATL (getMarkerPos _x);
  109. _var = createVehicle ["Land_Hospital_side1_F", [0,0,0], [], 0, "NONE"];
  110. _var attachTo [_hs, [4.69775,32.6045,-0.1125]];
  111. detach _var;
  112. _var = createVehicle ["Land_Hospital_side2_F", [0,0,0], [], 0, "NONE"];
  113. _var attachTo [_hs, [-28.0336,-10.0317,0.0889387]];
  114. detach _var;
  115. if (worldName isEqualTo "Tanoa") then {
  116. if (_forEachIndex isEqualTo 0) then {
  117. atm_hospital_2 setPos (_var modelToWorld [4.48633,0.438477,-8.25683]);
  118. vendor_hospital_2 setPos (_var modelToWorld [4.48633,0.438477,-8.25683]);
  119. "medic_spawn_3" setMarkerPos (_var modelToWorld [8.01172,-5.47852,-8.20022]);
  120. "med_car_2" setMarkerPos (_var modelToWorld [8.01172,-5.47852,-8.20022]);
  121. hospital_assis_2 setPos (_hs modelToWorld [0.0175781,0.0234375,-0.231956]);
  122. } else {
  123. atm_hospital_3 setPos (_var modelToWorld [4.48633,0.438477,-8.25683]);
  124. vendor_hospital_3 setPos (_var modelToWorld [4.48633,0.438477,-8.25683]);
  125. "medic_spawn_1" setMarkerPos (_var modelToWorld [-1.85181,-6.07715,-8.24944]);
  126. "med_car_1" setMarkerPos (_var modelToWorld [5.9624,11.8799,-8.28493]);
  127. hospital_assis_2 setPos (_hs modelToWorld [0.0175781,0.0234375,-0.231956]);
  128. };
  129. };
  130. } forEach ["hospital_2","hospital_3"];
  131.  
  132. {
  133. if (!isPlayer _x) then {
  134. _npc = _x;
  135. {
  136. if (_x != "") then {
  137. _npc removeWeapon _x;
  138. };
  139. } forEach [primaryWeapon _npc,secondaryWeapon _npc,handgunWeapon _npc];
  140. };
  141. } forEach allUnits;
  142.  
  143. [8,true,12] execFSM "\life_server\FSM\timeModule.fsm";
  144.  
  145. life_adminLevel = 0;
  146. life_medicLevel = 0;
  147. life_copLevel = 0;
  148. CONST(JxMxE_PublishVehicle,"false");
  149.  
  150. /* Setup radio channels for west/independent/civilian */
  151. life_radio_west = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  152. life_radio_civ = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  153. life_radio_indep = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  154.  
  155. /* Set the amount of gold in the federal reserve at mission start */
  156. fed_bank setVariable ["safe",count playableUnits,true];
  157. [] spawn TON_fnc_federalUpdate;
  158.  
  159. /* Event handler for disconnecting players */
  160. addMissionEventHandler ["HandleDisconnect",{_this call TON_fnc_clientDisconnect; false;}];
  161. [] call compile preprocessFileLineNumbers "\life_server\functions.sqf";
  162.  
  163. /* Set OwnerID players for Headless Client */
  164. TON_fnc_requestClientID =
  165. {
  166. (_this select 1) setVariable ["life_clientID", owner (_this select 1), true];
  167. };
  168. "life_fnc_RequestClientId" addPublicVariableEventHandler TON_fnc_requestClientID;
  169.  
  170. /* Event handler for logs */
  171. "money_log" addPublicVariableEventHandler {diag_log (_this select 1)};
  172. "advanced_log" addPublicVariableEventHandler {diag_log (_this select 1)};
  173.  
  174. /* Miscellaneous mission-required stuff */
  175. life_wanted_list = [];
  176.  
  177. cleanupFSM = [] execFSM "\life_server\FSM\cleanup.fsm";
  178.  
  179. [] spawn {
  180. for "_i" from 0 to 1 step 0 do {
  181. uiSleep (30 * 60);
  182. {
  183. _x setVariable ["sellers",[],true];
  184. } forEach [Dealer_1,Dealer_2,Dealer_3];
  185. };
  186. };
  187.  
  188. [] spawn TON_fnc_initHouses;
  189. cleanup = [] spawn TON_fnc_cleanup;
  190.  
  191. TON_fnc_playtime_values = [];
  192. TON_fnc_playtime_values_request = [];
  193.  
  194. //Just incase the Headless Client connects before anyone else
  195. publicVariable "TON_fnc_playtime_values";
  196. publicVariable "TON_fnc_playtime_values_request";
  197.  
  198.  
  199. /* Setup the federal reserve building(s) */
  200. private _vaultHouse = [[["Altis", "Land_Research_house_V1_F"], ["Tanoa", "Land_Medevac_house_V1_F"]]] call TON_fnc_terrainSort;
  201. private _altisArray = [16019.5,16952.9,0];
  202. private _tanoaArray = [11074.2,11501.5,0.00137329];
  203. private _pos = [[["Altis", _altisArray], ["Tanoa", _tanoaArray]]] call TON_fnc_terrainSort;
  204.  
  205. _dome = nearestObject [_pos,"Land_Dome_Big_F"];
  206. _rsb = nearestObject [_pos,_vaultHouse];
  207.  
  208. for "_i" from 1 to 3 do {_dome setVariable [format ["bis_disabled_Door_%1",_i],1,true]; _dome animateSource [format ["Door_%1_source", _i], 0];};
  209. _dome setVariable ["locked",true,true];
  210. _rsb setVariable ["locked",true,true];
  211. _rsb setVariable ["bis_disabled_Door_1",1,true];
  212. _dome allowDamage false;
  213. _rsb allowDamage false;
  214.  
  215. /* Tell clients that the server is ready and is accepting queries */
  216. life_server_isReady = true;
  217. publicVariable "life_server_isReady";
  218.  
  219. /* Initialize hunting zone(s) */
  220. aiSpawn = ["hunting_zone",30] spawn TON_fnc_huntingZone;
  221.  
  222. // We create the attachment point to be used for objects to attachTo load virtually in vehicles.
  223. life_attachment_point = "Land_HelipadEmpty_F" createVehicle [0,0,0];
  224. life_attachment_point setPosASL [0,0,0];
  225. life_attachment_point setVectorDirAndUp [[0,1,0], [0,0,1]];
  226.  
  227. // Sharing the point of attachment with all players.
  228. publicVariable "life_attachment_point";
  229. maxence_waiting_cop_calls = []; publicVariable "maxence_waiting_cop_calls"; maxence_waiting_med_calls = []; publicVariable "maxence_waiting_med_calls";
  230.  
  231. diag_log "----------------------------------------------------------------------------------------------------";
  232. diag_log format [" End of Altis Life Server Init :: Total Execution Time %1 seconds ",(diag_tickTime) - _timeStamp];
  233. diag_log "----------------------------------------------------------------------------------------------------";
  234. #include "script_macros.hpp"
  235. /*
  236. File: init.sqf
  237. Author: Bryan "Tonic" Boardwine
  238.  
  239. Edit: Nanou for HeadlessClient optimization.
  240. Please read support for more informations.
  241.  
  242. Description:
  243. Initialize the server and required systems.
  244. */
  245. private ["_dome","_rsb","_timeStamp","_extDBNotLoaded"];
  246. DB_Async_Active = false;
  247. DB_Async_ExtraLock = false;
  248. life_serverFunctionsReady = false;
  249. TON_fnc_receiveFunctions =
  250. compileFinal "
  251. {
  252. _name = _x select 0;
  253. _code = _x select 1;
  254. missionNamespace setVariable [_name,_code];
  255. }forEach allFunctions;
  256. life_serverFunctionsReady = true;
  257. ";
  258. publicVariable "TON_fnc_receiveFunctions";
  259. [] spawn {
  260. ["server"] remoteExec ["TON_fnc_initFunctions",2];
  261. waitUntil {life_serverFunctionsReady};
  262. };
  263. _extDBNotLoaded = "";
  264. serv_sv_use = [];
  265. publicVariable "life_server_isReady";
  266. life_save_civilian_position = if (LIFE_SETTINGS(getNumber,"save_civilian_position") isEqualTo 0) then {false} else {true};
  267. fn_whoDoneIt = compile preprocessFileLineNumbers "\life_server\Functions\Systems\fn_whoDoneIt.sqf";
  268.  
  269. /*
  270. Prepare the headless client.
  271. */
  272. life_HC_isActive = false;
  273. publicVariable "life_HC_isActive";
  274. HC_Life = false;
  275. publicVariable "HC_Life";
  276.  
  277. if (EXTDB_SETTING(getNumber,"HeadlessSupport") isEqualTo 1) then {
  278. [] execVM "\life_server\initHC.sqf";
  279. };
  280.  
  281. /*
  282. Prepare extDB before starting the initialization process
  283. for the server.
  284. */
  285.  
  286. if (isNil {uiNamespace getVariable "life_sql_id"}) then {
  287. life_sql_id = round(random(9999));
  288. CONSTVAR(life_sql_id);
  289. uiNamespace setVariable ["life_sql_id",life_sql_id];
  290. try {
  291. _result = EXTDB format ["9:ADD_DATABASE:%1",EXTDB_SETTING(getText,"DatabaseName")];
  292. if (!(_result isEqualTo "[1]")) then {throw "extDB3: Error with Database Connection"};
  293. _result = EXTDB format ["9:ADD_DATABASE_PROTOCOL:%2:SQL:%1:TEXT2",FETCH_CONST(life_sql_id),EXTDB_SETTING(getText,"DatabaseName")];
  294. if (!(_result isEqualTo "[1]")) then {throw "extDB3: Error with Database Connection"};
  295. } catch {
  296. diag_log _exception;
  297. _extDBNotLoaded = [true, _exception];
  298. };
  299. if (_extDBNotLoaded isEqualType []) exitWith {};
  300. EXTDB "9:LOCK";
  301. diag_log "extDB3: Connected to Database";
  302. } else {
  303. life_sql_id = uiNamespace getVariable "life_sql_id";
  304. CONSTVAR(life_sql_id);
  305. diag_log "extDB3: Still Connected to Database";
  306. };
  307.  
  308.  
  309. if (_extDBNotLoaded isEqualType []) exitWith {
  310. life_server_extDB_notLoaded = true;
  311. publicVariable "life_server_extDB_notLoaded";
  312. };
  313. life_server_extDB_notLoaded = false;
  314. publicVariable "life_server_extDB_notLoaded";
  315.  
  316. /* Run stored procedures for SQL side cleanup */
  317. ["CALL resetLifeVehicles",1] call DB_fnc_asyncCall;
  318. ["CALL deleteDeadVehicles",1] call DB_fnc_asyncCall;
  319. ["CALL deleteOldHouses",1] call DB_fnc_asyncCall;
  320. ["CALL deleteOldGangs",1] call DB_fnc_asyncCall;
  321.  
  322. _timeStamp = diag_tickTime;
  323. diag_log "----------------------------------------------------------------------------------------------------";
  324. diag_log "---------------------------------- Starting Altis Life Server Init ---------------------------------";
  325. diag_log "------------------------------------------ Version 5.0.0 -------------------------------------------";
  326. diag_log "----------------------------------------------------------------------------------------------------";
  327.  
  328. if (LIFE_SETTINGS(getNumber,"save_civilian_position_restart") isEqualTo 1) then {
  329. [] spawn {
  330. _query = "UPDATE players SET civ_alive = '0' WHERE civ_alive = '1'";
  331. [_query,1] call DB_fnc_asyncCall;
  332. };
  333. };
  334.  
  335. /* Map-based server side initialization. */
  336. master_group attachTo[bank_obj,[0,0,0]];
  337.  
  338. {
  339. _hs = createVehicle ["Land_Hospital_main_F", [0,0,0], [], 0, "NONE"];
  340. _hs setDir (markerDir _x);
  341. _hs setPosATL (getMarkerPos _x);
  342. _var = createVehicle ["Land_Hospital_side1_F", [0,0,0], [], 0, "NONE"];
  343. _var attachTo [_hs, [4.69775,32.6045,-0.1125]];
  344. detach _var;
  345. _var = createVehicle ["Land_Hospital_side2_F", [0,0,0], [], 0, "NONE"];
  346. _var attachTo [_hs, [-28.0336,-10.0317,0.0889387]];
  347. detach _var;
  348. if (worldName isEqualTo "Tanoa") then {
  349. if (_forEachIndex isEqualTo 0) then {
  350. atm_hospital_2 setPos (_var modelToWorld [4.48633,0.438477,-8.25683]);
  351. vendor_hospital_2 setPos (_var modelToWorld [4.48633,0.438477,-8.25683]);
  352. "medic_spawn_3" setMarkerPos (_var modelToWorld [8.01172,-5.47852,-8.20022]);
  353. "med_car_2" setMarkerPos (_var modelToWorld [8.01172,-5.47852,-8.20022]);
  354. hospital_assis_2 setPos (_hs modelToWorld [0.0175781,0.0234375,-0.231956]);
  355. } else {
  356. atm_hospital_3 setPos (_var modelToWorld [4.48633,0.438477,-8.25683]);
  357. vendor_hospital_3 setPos (_var modelToWorld [4.48633,0.438477,-8.25683]);
  358. "medic_spawn_1" setMarkerPos (_var modelToWorld [-1.85181,-6.07715,-8.24944]);
  359. "med_car_1" setMarkerPos (_var modelToWorld [5.9624,11.8799,-8.28493]);
  360. hospital_assis_2 setPos (_hs modelToWorld [0.0175781,0.0234375,-0.231956]);
  361. };
  362. };
  363. } forEach ["hospital_2","hospital_3"];
  364.  
  365. {
  366. if (!isPlayer _x) then {
  367. _npc = _x;
  368. {
  369. if (_x != "") then {
  370. _npc removeWeapon _x;
  371. };
  372. } forEach [primaryWeapon _npc,secondaryWeapon _npc,handgunWeapon _npc];
  373. };
  374. } forEach allUnits;
  375.  
  376. [8,true,12] execFSM "\life_server\FSM\timeModule.fsm";
  377.  
  378. life_adminLevel = 0;
  379. life_medicLevel = 0;
  380. life_copLevel = 0;
  381. CONST(JxMxE_PublishVehicle,"false");
  382.  
  383. /* Setup radio channels for west/independent/civilian */
  384. life_radio_west = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  385. life_radio_civ = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  386. life_radio_indep = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  387.  
  388. /* Set the amount of gold in the federal reserve at mission start */
  389. fed_bank setVariable ["safe",count playableUnits,true];
  390. [] spawn TON_fnc_federalUpdate;
  391.  
  392. /* Event handler for disconnecting players */
  393. addMissionEventHandler ["HandleDisconnect",{_this call TON_fnc_clientDisconnect; false;}];
  394. [] call compile preprocessFileLineNumbers "\life_server\functions.sqf";
  395.  
  396. /* Set OwnerID players for Headless Client */
  397. TON_fnc_requestClientID =
  398. {
  399. (_this select 1) setVariable ["life_clientID", owner (_this select 1), true];
  400. };
  401. "life_fnc_RequestClientId" addPublicVariableEventHandler TON_fnc_requestClientID;
  402.  
  403. /* Event handler for logs */
  404. "money_log" addPublicVariableEventHandler {diag_log (_this select 1)};
  405. "advanced_log" addPublicVariableEventHandler {diag_log (_this select 1)};
  406.  
  407. /* Miscellaneous mission-required stuff */
  408. life_wanted_list = [];
  409.  
  410. cleanupFSM = [] execFSM "\life_server\FSM\cleanup.fsm";
  411.  
  412. [] spawn {
  413. for "_i" from 0 to 1 step 0 do {
  414. uiSleep (30 * 60);
  415. {
  416. _x setVariable ["sellers",[],true];
  417. } forEach [Dealer_1,Dealer_2,Dealer_3];
  418. };
  419. };
  420.  
  421. [] spawn TON_fnc_initHouses;
  422. cleanup = [] spawn TON_fnc_cleanup;
  423.  
  424. TON_fnc_playtime_values = [];
  425. TON_fnc_playtime_values_request = [];
  426.  
  427. //Just incase the Headless Client connects before anyone else
  428. publicVariable "TON_fnc_playtime_values";
  429. publicVariable "TON_fnc_playtime_values_request";
  430.  
  431.  
  432. /* Setup the federal reserve building(s) */
  433. private _vaultHouse = [[["Altis", "Land_Research_house_V1_F"], ["Tanoa", "Land_Medevac_house_V1_F"]]] call TON_fnc_terrainSort;
  434. private _altisArray = [16019.5,16952.9,0];
  435. private _tanoaArray = [11074.2,11501.5,0.00137329];
  436. private _pos = [[["Altis", _altisArray], ["Tanoa", _tanoaArray]]] call TON_fnc_terrainSort;
  437.  
  438. _dome = nearestObject [_pos,"Land_Dome_Big_F"];
  439. _rsb = nearestObject [_pos,_vaultHouse];
  440.  
  441. for "_i" from 1 to 3 do {_dome setVariable [format ["bis_disabled_Door_%1",_i],1,true]; _dome animateSource [format ["Door_%1_source", _i], 0];};
  442. _dome setVariable ["locked",true,true];
  443. _rsb setVariable ["locked",true,true];
  444. _rsb setVariable ["bis_disabled_Door_1",1,true];
  445. _dome allowDamage false;
  446. _rsb allowDamage false;
  447.  
  448. /* Tell clients that the server is ready and is accepting queries */
  449. life_server_isReady = true;
  450. publicVariable "life_server_isReady";
  451.  
  452. /* Initialize hunting zone(s) */
  453. aiSpawn = ["hunting_zone",30] spawn TON_fnc_huntingZone;
  454.  
  455. // We create the attachment point to be used for objects to attachTo load virtually in vehicles.
  456. life_attachment_point = "Land_HelipadEmpty_F" createVehicle [0,0,0];
  457. life_attachment_point setPosASL [0,0,0];
  458. life_attachment_point setVectorDirAndUp [[0,1,0], [0,0,1]];
  459.  
  460. // Sharing the point of attachment with all players.
  461. publicVariable "life_attachment_point";
  462. maxence_waiting_cop_calls = []; publicVariable "maxence_waiting_cop_calls"; maxence_waiting_med_calls = []; publicVariable "maxence_waiting_med_calls";
  463.  
  464. diag_log "----------------------------------------------------------------------------------------------------";
  465. diag_log format [" End of Altis Life Server Init :: Total Execution Time %1 seconds ",(diag_tickTime) - _timeStamp];
  466. diag_log "----------------------------------------------------------------------------------------------------";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement