Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.30 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_server_isReady = false;
  16. _extDBNotLoaded = "";
  17. serv_sv_use = [];
  18. publicVariable "life_server_isReady";
  19. life_save_civilian_position = if (LIFE_SETTINGS(getNumber,"save_civilian_position") isEqualTo 0) then {false} else {true};
  20. fn_whoDoneIt = compile preprocessFileLineNumbers "\life_server\Functions\Systems\fn_whoDoneIt.sqf";
  21.  
  22. /*
  23. Prepare the headless client.
  24. */
  25. life_HC_isActive = false;
  26. publicVariable "life_HC_isActive";
  27. HC_Life = false;
  28. publicVariable "HC_Life";
  29.  
  30. if (EXTDB_SETTING(getNumber,"HeadlessSupport") isEqualTo 1) then {
  31. [] execVM "\life_server\initHC.sqf";
  32. };
  33.  
  34. /*
  35. Prepare extDB before starting the initialization process
  36. for the server.
  37. */
  38.  
  39. if (isNil {uiNamespace getVariable "life_sql_id"}) then {
  40. life_sql_id = round(random(9999));
  41. CONSTVAR(life_sql_id);
  42. uiNamespace setVariable ["life_sql_id",life_sql_id];
  43. try {
  44. _result = EXTDB format ["9:ADD_DATABASE:%1",EXTDB_SETTING(getText,"DatabaseName")];
  45. if (!(_result isEqualTo "[1]")) then {throw "extDB3: Error with Database Connection"};
  46. _result = EXTDB format ["9:ADD_DATABASE_PROTOCOL:%2:SQL:%1:TEXT2",FETCH_CONST(life_sql_id),EXTDB_SETTING(getText,"DatabaseName")];
  47. if (!(_result isEqualTo "[1]")) then {throw "extDB3: Error with Database Connection"};
  48. } catch {
  49. diag_log _exception;
  50. _extDBNotLoaded = [true, _exception];
  51. };
  52. if (_extDBNotLoaded isEqualType []) exitWith {};
  53. EXTDB "9:LOCK";
  54. diag_log "extDB3: Connected to Database";
  55. } else {
  56. life_sql_id = uiNamespace getVariable "life_sql_id";
  57. CONSTVAR(life_sql_id);
  58. diag_log "extDB3: Still Connected to Database";
  59. };
  60.  
  61.  
  62. if (_extDBNotLoaded isEqualType []) exitWith {
  63. life_server_extDB_notLoaded = true;
  64. publicVariable "life_server_extDB_notLoaded";
  65. };
  66. life_server_extDB_notLoaded = false;
  67. publicVariable "life_server_extDB_notLoaded";
  68.  
  69. /* Run stored procedures for SQL side cleanup */
  70. ["CALL resetLifeVehicles",1] call DB_fnc_asyncCall;
  71. ["CALL deleteDeadVehicles",1] call DB_fnc_asyncCall;
  72. ["CALL deleteOldHouses",1] call DB_fnc_asyncCall;
  73. ["CALL deleteOldGangs",1] call DB_fnc_asyncCall;
  74.  
  75. _timeStamp = diag_tickTime;
  76. diag_log "----------------------------------------------------------------------------------------------------";
  77. diag_log "---------------------------------- Starting Altis Life Server Init ---------------------------------";
  78. diag_log "------------------------------------------ Version 5.0.0 -------------------------------------------";
  79. diag_log "----------------------------------------------------------------------------------------------------";
  80.  
  81. if (LIFE_SETTINGS(getNumber,"save_civilian_position_restart") isEqualTo 1) then {
  82. [] spawn {
  83. _query = "UPDATE players SET civ_alive = '0' WHERE civ_alive = '1'";
  84. [_query,1] call DB_fnc_asyncCall;
  85. };
  86. };
  87.  
  88. /* Map-based server side initialization. */
  89. master_group attachTo[bank_obj,[0,0,0]];
  90.  
  91.  
  92. {
  93. if (!isPlayer _x) then {
  94. _npc = _x;
  95. {
  96. if (_x != "") then {
  97. _npc removeWeapon _x;
  98. };
  99. } forEach [primaryWeapon _npc,secondaryWeapon _npc,handgunWeapon _npc];
  100. };
  101. } forEach allUnits;
  102.  
  103. [8,true,12] execFSM "\life_server\FSM\timeModule.fsm";
  104.  
  105. life_adminLevel = 0;
  106. life_medicLevel = 0;
  107. life_copLevel = 0;
  108. CONST(JxMxE_PublishVehicle,"false");
  109.  
  110. /* Setup radio channels for west/independent/civilian */
  111. life_radio_west = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  112. life_radio_civ = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  113. life_radio_indep = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  114.  
  115. /* Set the amount of gold in the federal reserve at mission start */
  116. fed_bank setVariable ["safe",count playableUnits,true];
  117. [] spawn TON_fnc_federalUpdate;
  118.  
  119. /* Event handler for disconnecting players */
  120. addMissionEventHandler ["HandleDisconnect",{_this call TON_fnc_clientDisconnect; false;}];
  121. [] call compile preprocessFileLineNumbers "\life_server\functions.sqf";
  122.  
  123. /* Set OwnerID players for Headless Client */
  124. TON_fnc_requestClientID =
  125. {
  126. (_this select 1) setVariable ["life_clientID", owner (_this select 1), true];
  127. };
  128. "life_fnc_RequestClientId" addPublicVariableEventHandler TON_fnc_requestClientID;
  129.  
  130. /* Event handler for logs */
  131. "money_log" addPublicVariableEventHandler {diag_log (_this select 1)};
  132. "advanced_log" addPublicVariableEventHandler {diag_log (_this select 1)};
  133.  
  134. /* Miscellaneous mission-required stuff */
  135. life_wanted_list = [];
  136.  
  137. cleanupFSM = [] execFSM "\life_server\FSM\cleanup.fsm";
  138.  
  139. [] spawn {
  140. for "_i" from 0 to 1 step 0 do {
  141. uiSleep (30 * 60);
  142. {
  143. _x setVariable ["sellers",[],true];
  144. } forEach [Dealer_1,Dealer_2,Dealer_3];
  145. };
  146. };
  147.  
  148. [] spawn TON_fnc_initHouses;
  149. cleanup = [] spawn TON_fnc_cleanup;
  150.  
  151. TON_fnc_playtime_values = [];
  152. TON_fnc_playtime_values_request = [];
  153.  
  154. //Just incase the Headless Client connects before anyone else
  155. publicVariable "TON_fnc_playtime_values";
  156. publicVariable "TON_fnc_playtime_values_request";
  157.  
  158. /* Setup the federal reserve building(s) */
  159. private _vaultHouse = [[["Altis", "Land_Research_house_V1_F"], ["Malden", "Land_Research_house_V1_F"], ["Tanoa", "Land_Medevac_house_V1_F"]]] call TON_fnc_terrainSort;
  160. /* private _altisArray = [16019.5,16952.9,0];
  161. private _tanoaArray = [11074.2,11501.5,0.00137329];
  162. private _maldenArray = [5160,7071,0.75];
  163. private _pos = [[["Altis", _altisArray], ["Malden", _maldenArray], ["Tanoa", _tanoaArray]]] call TON_fnc_terrainSort; */
  164.  
  165. _dome = nearestObject [[5160,7071,0.75],"Land_Dome_Big_F"];
  166. _rsb = nearestObject [[5160,7071,0.75],_vaultHouse];
  167.  
  168. 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];};
  169. _dome setVariable ["locked",true,true];
  170. _rsb setVariable ["locked",true,true];
  171. _rsb setVariable ["bis_disabled_Door_1",1,true];
  172. _dome allowDamage false;
  173. _rsb allowDamage false;
  174.  
  175. /* Tell clients that the server is ready and is accepting queries */
  176. life_server_isReady = true;
  177. publicVariable "life_server_isReady";
  178.  
  179. /* Initialize hunting zone(s) */
  180. aiSpawn = ["hunting_zone",30] spawn TON_fnc_huntingZone;
  181.  
  182. // We create the attachment point to be used for objects to attachTo load virtually in vehicles.
  183. life_attachment_point = "Land_HelipadEmpty_F" createVehicle [0,0,0];
  184. life_attachment_point setPosASL [0,0,0];
  185. life_attachment_point setVectorDirAndUp [[0,1,0], [0,0,1]];
  186.  
  187. // Sharing the point of attachment with all players.
  188. publicVariable "life_attachment_point";
  189.  
  190. diag_log "----------------------------------------------------------------------------------------------------";
  191. diag_log format [" End of Altis Life Server Init :: Total Execution Time %1 seconds ",(diag_tickTime) - _timeStamp];
  192. diag_log "----------------------------------------------------------------------------------------------------";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement