Guest User

Untitled

a guest
Apr 23rd, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.24 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. realTimeSippe = [];
  54. [] spawn TON_fnc_getRealTime;
  55. [] spawn TON_fnc_restart;
  56. EXTDB "9:LOCK";
  57. diag_log "extDB3: Connected to Database";
  58. } else {
  59. life_sql_id = uiNamespace getVariable "life_sql_id";
  60. CONSTVAR(life_sql_id);
  61. diag_log "extDB3: Still Connected to Database";
  62. };
  63.  
  64.  
  65. if (_extDBNotLoaded isEqualType []) exitWith {
  66. life_server_extDB_notLoaded = true;
  67. publicVariable "life_server_extDB_notLoaded";
  68. };
  69. life_server_extDB_notLoaded = false;
  70. publicVariable "life_server_extDB_notLoaded";
  71.  
  72. /* Run stored procedures for SQL side cleanup */
  73. ["CALL resetLifeVehicles",1] call DB_fnc_asyncCall;
  74. ["CALL deleteDeadVehicles",1] call DB_fnc_asyncCall;
  75. ["CALL deleteOldHouses",1] call DB_fnc_asyncCall;
  76. ["CALL deleteOldGangs",1] call DB_fnc_asyncCall;
  77.  
  78. _timeStamp = diag_tickTime;
  79. diag_log "----------------------------------------------------------------------------------------------------";
  80. diag_log "---------------------------------- Starting Altis Life Server Init ---------------------------------";
  81. diag_log format["------------------------------------------ Version %1 -------------------------------------------",(LIFE_SETTINGS(getText,"framework_version"))];
  82. diag_log "----------------------------------------------------------------------------------------------------";
  83.  
  84. if (LIFE_SETTINGS(getNumber,"save_civilian_position_restart") isEqualTo 1) then {
  85. [] spawn {
  86. _query = "UPDATE players SET civ_alive = '0' WHERE civ_alive = '1'";
  87. [_query,1] call DB_fnc_asyncCall;
  88. };
  89. };
  90.  
  91. /* Map-based server side initialization. */
  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. life_adacLevel = 0;
  109. CONST(JxMxE_PublishVehicle,"false");
  110.  
  111. /* Setup radio channels for west/independent/civilian */
  112. life_radio_west = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  113. life_radio_east = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  114. life_radio_civ = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  115. life_radio_indep = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  116.  
  117. /* Set the amount of gold in the federal reserve at mission start */
  118. fed_bank setVariable ["safe",count playableUnits,true];
  119. [] spawn TON_fnc_federalUpdate;
  120.  
  121. /* Event handler for disconnecting players */
  122. addMissionEventHandler ["HandleDisconnect",{_this call TON_fnc_clientDisconnect; false;}];
  123. [] call compile preprocessFileLineNumbers "\life_server\functions.sqf";
  124.  
  125. /* Set OwnerID players for Headless Client */
  126. TON_fnc_requestClientID =
  127. {
  128. (_this select 1) setVariable ["life_clientID", owner (_this select 1), true];
  129. };
  130. "life_fnc_RequestClientId" addPublicVariableEventHandler TON_fnc_requestClientID;
  131.  
  132. /* Event handler for logs */
  133. "money_log" addPublicVariableEventHandler {diag_log (_this select 1)};
  134. "advanced_log" addPublicVariableEventHandler {diag_log (_this select 1)};
  135.  
  136. /* Miscellaneous mission-required stuff */
  137. life_wanted_list = [];
  138.  
  139. cleanupFSM = [] execFSM "\life_server\FSM\cleanup.fsm";
  140.  
  141. [] spawn {
  142. for "_i" from 0 to 1 step 0 do {
  143. uiSleep (30 * 60);
  144. {
  145. _x setVariable ["sellers",[],true];
  146. } forEach ["Dealer_1"];
  147. };
  148. };
  149.  
  150. [] spawn TON_fnc_initHouses;
  151. cleanup = [] spawn TON_fnc_cleanup;
  152.  
  153. TON_fnc_playtime_values = [];
  154. TON_fnc_playtime_values_request = [];
  155.  
  156. //Just incase the Headless Client connects before anyone else
  157. publicVariable "TON_fnc_playtime_values";
  158. publicVariable "TON_fnc_playtime_values_request";
  159.  
  160.  
  161. /* Setup the federal reserve building(s) */
  162. private _vaultHouse = [[["Altis", "Land_Research_house_V1_F"], ["Malden", "Land_Medevac_house_V1_F"], ["Tanoa", "Land_Medevac_house_V1_F"]]] call TON_fnc_terrainSort;
  163. /* private _altisArray = [16019.5,16952.9,0];
  164. private _tanoaArray = [11074.2,11501.5,0.00137329];
  165. private _maldenArray = [6094.11,10779.4,0.770134];
  166. private _pos = [[["Altis", _altisArray], ["Malden", _maldenArray], ["Tanoa", _tanoaArray]]] call TON_fnc_terrainSort; */
  167.  
  168. _dome = nearestObject [[6094.61,10776.4,0],"Land_Dome_Big_F"];
  169. _rsb = nearestObject [[6094.61,10776.4,0],_vaultHouse];
  170.  
  171.  
  172. 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];};
  173. _dome setVariable ["locked",true,true];
  174. _rsb setVariable ["locked",true,true];
  175. _rsb setVariable ["bis_disabled_Door_1",1,true];
  176. _dome allowDamage false;
  177. _rsb allowDamage false;
  178.  
  179. /* Tell clients that the server is ready and is accepting queries */
  180. life_server_isReady = true;
  181. publicVariable "life_server_isReady";
  182.  
  183. /* Initialize hunting zone(s) */
  184. aiSpawn = ["hunting_zone",30] spawn TON_fnc_huntingZone;
  185.  
  186. server_corpses = [];
  187. addMissionEventHandler ["EntityRespawned", {_this call TON_fnc_entityRespawned}];
  188.  
  189. diag_log "----------------------------------------------------------------------------------------------------";
  190. diag_log format [" End of Altis Life Server Init :: Total Execution Time %1 seconds ",(diag_tickTime) - _timeStamp];
  191. diag_log "----------------------------------------------------------------------------------------------------";
Advertisement
Add Comment
Please, Sign In to add comment