Advertisement
Guest User

Untitled

a guest
Aug 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.28 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"];
  13. DB_Async_Active = false;
  14. DB_Async_ExtraLock = false;
  15. life_server_isReady = false;
  16. life_server_extDB_notLoaded = "";
  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 "extDB2: Error with Database Connection"};
  46. _result = EXTDB format["9:ADD_DATABASE_PROTOCOL:%2:SQL_RAW_V2:%1:ADD_QUOTES",FETCH_CONST(life_sql_id),EXTDB_SETTING(getText,"DatabaseName")];
  47. if (!(_result isEqualTo "[1]")) then {throw "extDB2: Error with Database Connection"};
  48. } catch {
  49. diag_log _exception;
  50. life_server_extDB_notLoaded = [true, _exception];
  51. };
  52. publicVariable "life_server_extDB_notLoaded";
  53. if (life_server_extDB_notLoaded isEqualType []) exitWith {};
  54. EXTDB "9:LOCK";
  55. diag_log "extDB2: Connected to Database";
  56. } else {
  57. life_sql_id = uiNamespace getVariable "life_sql_id";
  58. CONSTVAR(life_sql_id);
  59. diag_log "extDB2: Still Connected to Database";
  60. };
  61.  
  62. if (life_server_extDB_notLoaded isEqualType []) exitWith {};
  63.  
  64. /* Run stored procedures for SQL side cleanup */
  65. ["CALL resetLifeVehicles",1] call DB_fnc_asyncCall;
  66. ["CALL deleteDeadVehicles",1] call DB_fnc_asyncCall;
  67. ["CALL deleteOldHouses",1] call DB_fnc_asyncCall;
  68. ["CALL deleteOldGangs",1] call DB_fnc_asyncCall;
  69.  
  70. _timeStamp = diag_tickTime;
  71. diag_log "----------------------------------------------------------------------------------------------------";
  72. diag_log "---------------------------------- Starting Altis Life Server Init ---------------------------------";
  73. diag_log "------------------------------------------ Version 4.4r4 -------------------------------------------";
  74. diag_log "----------------------------------------------------------------------------------------------------";
  75.  
  76. if (LIFE_SETTINGS(getNumber,"save_civilian_position_restart") isEqualTo 1) then {
  77. [] spawn {
  78. _query = "UPDATE players SET civ_alive = '0' WHERE civ_alive = '1'";
  79. [_query,1] call DB_fnc_asyncCall;
  80. };
  81. };
  82.  
  83. /* Map-based server side initialization. */
  84. master_group attachTo[bank_obj,[0,0,0]];
  85.  
  86. {
  87. _hs = createVehicle ["Land_Hospital_main_F", [0,0,0], [], 0, "NONE"];
  88. _hs setDir (markerDir _x);
  89. _hs setPosATL (getMarkerPos _x);
  90. _var = createVehicle ["Land_Hospital_side1_F", [0,0,0], [], 0, "NONE"];
  91. _var attachTo [_hs, [4.69775,32.6045,-0.1125]];
  92. detach _var;
  93. _var = createVehicle ["Land_Hospital_side2_F", [0,0,0], [], 0, "NONE"];
  94. _var attachTo [_hs, [-28.0336,-10.0317,0.0889387]];
  95. detach _var;
  96. } forEach ["hospital_2","hospital_3"];
  97.  
  98. {
  99. if (!isPlayer _x) then {
  100. _npc = _x;
  101. {
  102. if (_x != "") then {
  103. _npc removeWeapon _x;
  104. };
  105. } forEach [primaryWeapon _npc,secondaryWeapon _npc,handgunWeapon _npc];
  106. };
  107. } forEach allUnits;
  108.  
  109. [8,true,12] execFSM "\life_server\FSM\timeModule.fsm";
  110.  
  111. life_adminLevel = 0;
  112. life_medicLevel = 0;
  113. life_copLevel = 0;
  114. CONST(JxMxE_PublishVehicle,"false");
  115.  
  116. /* Setup radio channels for west/independent/civilian */
  117. life_radio_west = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  118. life_radio_civ = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  119. life_radio_indep = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  120.  
  121. /* Set the amount of gold in the federal reserve at mission start */
  122. fed_bank setVariable ["safe",count playableUnits,true];
  123. [] spawn TON_fnc_federalUpdate;
  124.  
  125. /* Event handler for disconnecting players */
  126. addMissionEventHandler ["HandleDisconnect",{_this call TON_fnc_clientDisconnect; false;}];
  127. [] call compile PreProcessFileLineNumbers "\life_server\functions.sqf";
  128.  
  129. /* Set OwnerID players for Headless Client */
  130. TON_fnc_requestClientID =
  131. {
  132. (_this select 1) setVariable ["life_clientID", owner (_this select 1), true];
  133. };
  134. "life_fnc_RequestClientId" addPublicVariableEventHandler TON_fnc_requestClientID;
  135.  
  136. /* Event handler for logs */
  137. "money_log" addPublicVariableEventHandler {diag_log (_this select 1)};
  138. "advanced_log" addPublicVariableEventHandler {diag_log (_this select 1)};
  139.  
  140. /* Miscellaneous mission-required stuff */
  141. life_wanted_list = [];
  142.  
  143. cleanupFSM = [] execFSM "\life_server\FSM\cleanup.fsm";
  144.  
  145. [] spawn {
  146. for "_i" from 0 to 1 step 0 do {
  147. uiSleep (30 * 60);
  148. {
  149. _x setVariable["sellers",[],true];
  150. } forEach [Dealer_1,Dealer_2,Dealer_3];
  151. };
  152. };
  153.  
  154. [] spawn TON_fnc_initHouses;
  155. cleanup = [] spawn TON_fnc_cleanup;
  156.  
  157. TON_fnc_playtime_values = [];
  158. TON_fnc_playtime_values_request = [];
  159.  
  160. //Just incase the Headless Client connects before anyone else
  161. publicVariable "TON_fnc_playtime_values";
  162. publicVariable "TON_fnc_playtime_values_request";
  163.  
  164.  
  165. /* Setup the federal reserve building(s) */
  166. _dome = nearestObject [[18369.2,15279.7,0],"Land_Reserve_Federale_Smith"];
  167. _rsb = nearestObject [[16019.5,16952.9,0],"Land_Research_house_V1_F"];
  168.  
  169. for "_i" from 1 to 3 do {_dome setVariable[format["bis_disabled_Door_%1",_i],1,true]; _dome animate [format["Door_%1_rot",_i],0];};
  170. _dome setVariable["locked",true,true];
  171. _rsb setVariable["locked",true,true];
  172. _rsb setVariable["bis_disabled_Door_1",1,true];
  173. _dome allowDamage false;
  174. _rsb allowDamage false;
  175.  
  176. /* Tell clients that the server is ready and is accepting queries */
  177. life_server_isReady = true;
  178. publicVariable "life_server_isReady";
  179.  
  180. /* Initialize hunting zone(s) */
  181. aiSpawn = ["hunting_zone",30] spawn TON_fnc_huntingZone;
  182.  
  183. // We create the attachment point to be used for objects to attachTo load virtually in vehicles.
  184. life_attachment_point = "Land_HelipadEmpty_F" createVehicle [0,0,0];
  185. life_attachment_point setPosASL [0,0,0];
  186. life_attachment_point setVectorDirAndUp [[0,1,0], [0,0,1]];
  187.  
  188. // Sharing the point of attachment with all players.
  189. publicVariable "life_attachment_point";
  190.  
  191. diag_log "----------------------------------------------------------------------------------------------------";
  192. diag_log format[" End of Altis Life Server Init :: Total Execution Time %1 seconds ",(diag_tickTime) - _timeStamp];
  193. diag_log "----------------------------------------------------------------------------------------------------";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement