Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.41 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.         _result = EXTDB format ["9:ADD_DATABASE:%1","altislife"];
  46.         if (!(_result isEqualTo "[1]")) then {throw "extDB3: Error with Database Connection"};
  47.         //_result = EXTDB format ["9:ADD_DATABASE_PROTOCOL:%2:SQL:%1:TEXT2",FETCH_CONST(life_sql_id),EXTDB_SETTING(getText,"DatabaseName")];
  48.         _result = EXTDB format ["9:ADD_DATABASE_PROTOCOL:%2:SQL:%1:TEXT2",FETCH_CONST(life_sql_id),"altislife"];
  49.         if (!(_result isEqualTo "[1]")) then {throw "extDB3: Error with Database Connection"};
  50.     } catch {
  51.         diag_log _exception;
  52.         _extDBNotLoaded = [true, _exception];
  53.     };
  54.     if (_extDBNotLoaded isEqualType []) exitWith {};
  55.     EXTDB "9:LOCK";
  56.     diag_log "extDB3: Connected to Database";
  57. } else {
  58.     life_sql_id = uiNamespace getVariable "life_sql_id";
  59.     CONSTVAR(life_sql_id);
  60.     diag_log "extDB3: Still Connected to Database";
  61. };
  62.  
  63.  
  64. if (_extDBNotLoaded isEqualType []) exitWith {
  65.     life_server_extDB_notLoaded = true;
  66.     publicVariable "life_server_extDB_notLoaded";
  67. };
  68. life_server_extDB_notLoaded = false;
  69. publicVariable "life_server_extDB_notLoaded";
  70.  
  71. /* Run stored procedures for SQL side cleanup */
  72. ["CALL resetLifeVehicles",1] call DB_fnc_asyncCall;
  73. ["CALL deleteDeadVehicles",1] call DB_fnc_asyncCall;
  74. ["CALL deleteOldHouses",1] call DB_fnc_asyncCall;
  75. ["CALL deleteOldGangs",1] call DB_fnc_asyncCall;
  76.  
  77. _timeStamp = diag_tickTime;
  78. diag_log "----------------------------------------------------------------------------------------------------";
  79. diag_log "---------------------------------- Starting Altis Life Server Init ---------------------------------";
  80. diag_log "------------------------------------------ Version 5.0.0 -------------------------------------------";
  81. diag_log "----------------------------------------------------------------------------------------------------";
  82.  
  83. if (LIFE_SETTINGS(getNumber,"save_civilian_position_restart") isEqualTo 1) then {
  84.     [] spawn {
  85.         _query = "UPDATE players SET civ_alive = '0' WHERE civ_alive = '1'";
  86.         [_query,1] call DB_fnc_asyncCall;
  87.     };
  88. };
  89.  
  90. /* Map-based server side initialization. */
  91. master_group attachTo[bank_obj,[0,0,0]];
  92.  
  93. {
  94.     _hs = createVehicle ["Land_Hospital_main_F", [0,0,0], [], 0, "NONE"];
  95.     _hs setDir (markerDir _x);
  96.     _hs setPosATL (getMarkerPos _x);
  97.     _var = createVehicle ["Land_Hospital_side1_F", [0,0,0], [], 0, "NONE"];
  98.     _var attachTo [_hs, [4.69775,32.6045,-0.1125]];
  99.     detach _var;
  100.     _var = createVehicle ["Land_Hospital_side2_F", [0,0,0], [], 0, "NONE"];
  101.     _var attachTo [_hs, [-28.0336,-10.0317,0.0889387]];
  102.     detach _var;
  103.     if (worldName isEqualTo "Tanoa") then {
  104.         if (_forEachIndex isEqualTo 0) then {
  105.             atm_hospital_2 setPos (_var modelToWorld [4.48633,0.438477,-8.25683]);
  106.             vendor_hospital_2 setPos (_var modelToWorld [4.48633,0.438477,-8.25683]);
  107.             "medic_spawn_3" setMarkerPos (_var modelToWorld [8.01172,-5.47852,-8.20022]);
  108.             "med_car_2" setMarkerPos (_var modelToWorld [8.01172,-5.47852,-8.20022]);
  109.             hospital_assis_2 setPos (_hs modelToWorld [0.0175781,0.0234375,-0.231956]);
  110.         } else {
  111.             atm_hospital_3 setPos (_var modelToWorld [4.48633,0.438477,-8.25683]);
  112.             vendor_hospital_3 setPos (_var modelToWorld [4.48633,0.438477,-8.25683]);
  113.             "medic_spawn_1" setMarkerPos (_var modelToWorld [-1.85181,-6.07715,-8.24944]);
  114.             "med_car_1" setMarkerPos (_var modelToWorld [5.9624,11.8799,-8.28493]);
  115.             hospital_assis_2 setPos (_hs modelToWorld [0.0175781,0.0234375,-0.231956]);
  116.         };
  117.     };
  118. } forEach ["hospital_2","hospital_3"];
  119.  
  120. {
  121.     if (!isPlayer _x) then {
  122.         _npc = _x;
  123.         {
  124.             if (_x != "") then {
  125.                 _npc removeWeapon _x;
  126.             };
  127.         } forEach [primaryWeapon _npc,secondaryWeapon _npc,handgunWeapon _npc];
  128.     };
  129. } forEach allUnits;
  130.  
  131. [8,true,12] execFSM "\life_server\FSM\timeModule.fsm";
  132.  
  133. life_adminLevel = 0;
  134. life_medicLevel = 0;
  135. life_copLevel = 0;
  136. CONST(JxMxE_PublishVehicle,"false");
  137.  
  138. /* Setup radio channels for west/independent/civilian */
  139. life_radio_west = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  140. life_radio_civ = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  141. life_radio_indep = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
  142.  
  143. /* Set the amount of gold in the federal reserve at mission start */
  144. fed_bank setVariable ["safe",count playableUnits,true];
  145. [] spawn TON_fnc_federalUpdate;
  146.  
  147. /* Event handler for disconnecting players */
  148. addMissionEventHandler ["HandleDisconnect",{_this call TON_fnc_clientDisconnect; false;}];
  149. [] call compile preprocessFileLineNumbers "\life_server\functions.sqf";
  150.  
  151. /* Set OwnerID players for Headless Client */
  152. TON_fnc_requestClientID =
  153. {
  154.     (_this select 1) setVariable ["life_clientID", owner (_this select 1), true];
  155. };
  156. "life_fnc_RequestClientId" addPublicVariableEventHandler TON_fnc_requestClientID;
  157.  
  158. /* Event handler for logs */
  159. "money_log" addPublicVariableEventHandler {diag_log (_this select 1)};
  160. "advanced_log" addPublicVariableEventHandler {diag_log (_this select 1)};
  161.  
  162. /* Miscellaneous mission-required stuff */
  163. life_wanted_list = [];
  164. life_bounty_list = [];
  165.  
  166. cleanupFSM = [] execFSM "\life_server\FSM\cleanup.fsm";
  167.  
  168. [] spawn {
  169.     for "_i" from 0 to 1 step 0 do {
  170.         uiSleep (30 * 60);
  171.         {
  172.             _x setVariable ["sellers",[],true];
  173.         } forEach [Dealer_2, Dealer_3, Dealer_1_4_2_3];
  174.     };
  175. };
  176.  
  177. [] spawn TON_fnc_initHouses;
  178. cleanup = [] spawn TON_fnc_cleanup;
  179.  
  180. TON_fnc_playtime_values = [];
  181. TON_fnc_playtime_values_request = [];
  182.  
  183. //Just incase the Headless Client connects before anyone else
  184. publicVariable "TON_fnc_playtime_values";
  185. publicVariable "TON_fnc_playtime_values_request";
  186.  
  187.  
  188. /* Setup the federal reserve building(s) */
  189. private _vaultHouse = [[["Altis", "Land_Research_house_V1_F"], ["Malden", "Land_Research_house_V1_F"], ["Tanoa", "Land_Medevac_house_V1_F"]]] call TON_fnc_terrainSort;
  190. private _altisArray = [16019.5,16952.9,0];
  191. private _tanoaArray = [11074.2,11501.5,0.00137329];
  192. private _maldenArray = [11074.2,11501.5,0.00137329]; // A changer
  193. private _pos = [[["Altis", _altisArray], ["Tanoa", _tanoaArray], ["Malden", _maldenArray]]] call TON_fnc_terrainSort;
  194.  
  195. _dome = nearestObject [_pos,"Land_Dome_Big_F"];
  196. _rsb = nearestObject [_pos,_vaultHouse];
  197.  
  198. 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];};
  199. _dome setVariable ["locked",true,true];
  200. _rsb setVariable ["locked",true,true];
  201. _rsb setVariable ["bis_disabled_Door_1",1,true];
  202. _dome allowDamage false;
  203. _rsb allowDamage false;
  204.  
  205. /* Tell clients that the server is ready and is accepting queries */
  206. life_server_isReady = true;
  207. publicVariable "life_server_isReady";
  208.  
  209. /* Initialize hunting zone(s) */
  210. aiSpawn = ["hunting_zone",30] spawn TON_fnc_huntingZone;
  211.  
  212. // We create the attachment point to be used for objects to attachTo load virtually in vehicles.
  213. life_attachment_point = "Land_HelipadEmpty_F" createVehicle [0,0,0];
  214. life_attachment_point setPosASL [0,0,0];
  215. life_attachment_point setVectorDirAndUp [[0,1,0], [0,0,1]];
  216.  
  217. // Sharing the point of attachment with all players.
  218. publicVariable "life_attachment_point";
  219.  
  220. diag_log "Start Init Market Prices";
  221. [] call srv_fnc_initMarket;
  222.  
  223. [] spawn {
  224.     while { true } do {
  225.         sleep 300;
  226.         [] call srv_fnc_updateMarket;
  227.     };
  228. };
  229.  
  230. /*
  231. [] call life_fnc_marketconfiguration;
  232. diag_log "Market prices generated!";
  233.  
  234. "life_market_prices" addPublicVariableEventHandler {
  235.     diag_log format["Market prices updated! %1", _this select 1];
  236. };
  237. */
  238.  
  239. //Start server fsm
  240. [] execFSM "\life_server\FSM\server.fsm";
  241. diag_log "Server FSM executed";
  242.  
  243. diag_log "----------------------------------------------------------------------------------------------------";
  244. diag_log format ["               End of Altis Life Server Init :: Total Execution Time %1 seconds ",(diag_tickTime) - _timeStamp];
  245. diag_log "----------------------------------------------------------------------------------------------------";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement