Advertisement
Guest User

server_monitor.sqf

a guest
Jan 24th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 14.88 KB | None | 0 0
  1. private ["_nul","_result","_pos","_wsDone","_dir","_isOK","_countr","_objWpnTypes","_objWpnQty","_dam","_selection","_totalvehicles","_object","_idKey","_type","_ownerID","_worldspace","_intentory","_hitPoints","_fuel","_damage","_key","_vehLimit","_hiveResponse","_objectCount","_codeCount","_data","_status","_val","_traderid","_retrader","_traderData","_id","_lockable","_debugMarkerPosition","_vehicle_0","_bQty","_vQty","_BuildingQueue","_objectQueue","_superkey","_shutdown","_res","_hiveLoaded"];
  2.  
  3. dayz_versionNo =        getText(configFile >> "CfgMods" >> "DayZ" >> "version");
  4. dayz_hiveVersionNo =    getNumber(configFile >> "CfgMods" >> "DayZ" >> "hiveVersion");
  5.  
  6. _hiveLoaded = false;
  7.  
  8. waitUntil{initialized}; //means all the functions are now defined
  9.  
  10. diag_log "HIVE: Starting";
  11.  
  12. waituntil{isNil "sm_done"}; // prevent server_monitor be called twice (bug during login of the first player)
  13.  
  14. // Time sync
  15. if (isDedicated) then {
  16.     _result = ["PASS",[2012,6,6,10,10]];
  17.     _res    = preprocessFile "\cache\set_time.sqf";
  18.     if ((_res != "") and !(isNil "_res")) then {
  19.         _result = call compile _res;
  20.     };
  21.     _outcome = _result select 0;
  22.  
  23.     if (_outcome == "PASS") then {
  24.         _date = _result select 1;
  25.         setDate _date;
  26.     PVDZE_plr_SetDate = _date;
  27.     publicVariable "PVDZE_plr_SetDate";
  28.         diag_log ("HIVE: Local Time set to " + str(_date));
  29.     };
  30. };
  31.    
  32. // Custom Configs
  33. if(isnil "MaxVehicleLimit") then {
  34.     MaxVehicleLimit = 50;
  35. };
  36.  
  37. if(isnil "MaxDynamicDebris") then {
  38.     MaxDynamicDebris = 100;
  39. };
  40. if(isnil "MaxAmmoBoxes") then {
  41.     MaxAmmoBoxes = 3;
  42. };
  43. if(isnil "MaxMineVeins") then {
  44.     MaxMineVeins = 50;
  45. };
  46. // Custon Configs End
  47.  
  48. if (isServer && isNil "sm_done") then {
  49.     serverVehicleCounter = [];
  50.     diag_log ("LOAD OBJECTS");
  51.  
  52.         _objectArray = [];
  53.    
  54.         _res = preprocessFile "\cache\objects.sqf";
  55.         if ((_res == "") or (isNil "_res")) then {
  56.             diag_log ("OBJECTS NOT FOUND!");
  57.         } else {
  58.             _objectArray = call compile _res;
  59.         };
  60.         _res = nil;
  61.         diag_log format["FOUND %1 OBJECTS", str(count _objectArray)];
  62.    
  63.     // # NOW SPAWN OBJECTS #
  64.     _totalvehicles = 0;
  65.     {
  66.         _idKey =        _x select 1;
  67.         _type =         _x select 2;
  68.         _ownerID =      _x select 3;
  69.  
  70.         _worldspace =   _x select 4;
  71.         _intentory =    _x select 5;
  72.         _hitPoints =    _x select 6;
  73.         _fuel =         _x select 7;
  74.         _damage =       _x select 8;
  75.        
  76.         _dir = 0;
  77.         _pos = [0,0,0];
  78.         _wsDone = false;
  79.         if (count _worldspace >= 2) then
  80.         {
  81.                 if(count _worldspace == 3) then{
  82.                         _vector = _worldspace select 2;
  83.                         if(typename _vector == "ARRAY")then{
  84.                                 if(count _vector == 2)then{
  85.                                         if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
  86.                                                 _vecExists = true;
  87.                                         };
  88.                                 };
  89.  
  90.                         };
  91.  
  92.                 };
  93.                 _dir = _worldspace select 0;
  94.                 if (count (_worldspace select 1) == 3) then {
  95.                         _pos = _worldspace select 1;
  96.                         _wsDone = true;
  97.                 }
  98.         };     
  99.        
  100.         if (!_wsDone) then {
  101.             if (count _worldspace >= 1) then { _dir = _worldspace select 0; };
  102.             _pos = [getMarkerPos "center",0,4000,10,0,2000,0] call BIS_fnc_findSafePos;
  103.             if (count _pos < 3) then { _pos = [_pos select 0,_pos select 1,0]; };
  104.             diag_log ("MOVED OBJ: " + str(_idKey) + " of class " + _type + " to pos: " + str(_pos));
  105.         };
  106.        
  107.         _vector = [[0,0,0],[0,0,0]];
  108.         _vecExists = false;
  109.         _ownerPUID = "0";  
  110.         if (count _worldspace >= 3) then{
  111.             if(count _worldspace == 3) then{
  112.                     if(typename (_worldspace select 2) == "STRING")then{
  113.                         _ownerPUID = _worldspace select 2;
  114.                     }else{
  115.                          if(typename (_worldspace select 2) == "ARRAY")then{
  116.                             _vector = _worldspace select 2;
  117.                             if(count _vector == 2)then{
  118.                                 if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
  119.                                     _vecExists = true;
  120.                                 };
  121.                             };
  122.                         };                  
  123.                     };
  124.  
  125.             }else{
  126.                 //Was not 3 elements, so check if 4 or more
  127.                 if(count _worldspace == 4) then{
  128.                     if(typename (_worldspace select 3) == "STRING")then{
  129.                         _ownerPUID = _worldspace select 3;
  130.                     }else{
  131.                         if(typename (_worldspace select 2) == "STRING")then{
  132.                             _ownerPUID = _worldspace select 2;
  133.                         };
  134.                     };
  135.  
  136.  
  137.                     if(typename (_worldspace select 2) == "ARRAY")then{
  138.                         _vector = _worldspace select 2;
  139.                         if(count _vector == 2)then{
  140.                             if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
  141.                                 _vecExists = true;
  142.                             };
  143.                         };
  144.                     }else{
  145.                         if(typename (_worldspace select 3) == "ARRAY")then{
  146.                             _vector = _worldspace select 3;
  147.                             if(count _vector == 2)then{
  148.                                 if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
  149.                                     _vecExists = true;
  150.                                 };
  151.                             };
  152.                         };
  153.                     };
  154.  
  155.                 }else{
  156.                     //More than 3 or 4 elements found
  157.                     //Might add a search for the vector, ownerPUID will equal 0
  158.                 };
  159.             };
  160.         };
  161.  
  162.         if (_damage < 1) then {
  163.             //diag_log format["OBJ: %1 - %2", _idKey,_type];
  164.            
  165.             //Create it 1
  166.             _object = createVehicle [_type, _pos, [], 0, "CAN_COLLIDE"];
  167.            
  168.             //Door Management
  169.             if (typeOf (_object) in  DZE_DoorsLocked) then {
  170.                 _object setVariable ["doorfriends", _intentory, true];
  171.             };
  172.            
  173.             //Create it 2
  174.             _object setVariable ["lastUpdate",time];
  175.             _object setVariable ["ObjectID", _idKey, true];
  176.             if (typeOf (_object) == "Plastic_Pole_EP1_DZ") then {
  177.             _object setVariable ["plotfriends", _intentory, true];
  178.             };
  179.            
  180.             _lockable = 0;
  181.             if(isNumber (configFile >> "CfgVehicles" >> _type >> "lockable")) then {
  182.                 _lockable = getNumber(configFile >> "CfgVehicles" >> _type >> "lockable");
  183.             };
  184.  
  185.             // fix for leading zero issues on safe codes after restart
  186.             if (_lockable == 4) then {
  187.                 _codeCount = (count (toArray _ownerID));
  188.                 if(_codeCount == 3) then {
  189.                     _ownerID = format["0%1", _ownerID];
  190.                 };
  191.                 if(_codeCount == 2) then {
  192.                     _ownerID = format["00%1", _ownerID];
  193.                 };
  194.                 if(_codeCount == 1) then {
  195.                     _ownerID = format["000%1", _ownerID];
  196.                 };
  197.             };
  198.  
  199.             if (_lockable == 3) then {
  200.                 _codeCount = (count (toArray _ownerID));
  201.                 if(_codeCount == 2) then {
  202.                     _ownerID = format["0%1", _ownerID];
  203.                 };
  204.                 if(_codeCount == 1) then {
  205.                     _ownerID = format["00%1", _ownerID];
  206.                 };
  207.             };
  208.  
  209.             _object setVariable ["CharacterID", _ownerID, true];
  210.            
  211.             clearWeaponCargoGlobal  _object;
  212.             clearMagazineCargoGlobal  _object;
  213.             // _object setVehicleAmmo DZE_vehicleAmmo;
  214.            
  215.             _object setdir _dir;
  216.             if(_vecExists)then{
  217.                 _object setVectorDirAndUp _vector;
  218.             };
  219.             _object setposATL _pos;
  220.             _object setDamage _damage;
  221.            
  222.             if ((typeOf _object) in dayz_allowedObjects) then {
  223.                 _object setVariable["memDir",_dir,true];
  224.                 if (DZE_GodModeBase) then {
  225.                     _object addEventHandler ["HandleDamage", {false}];
  226.                 } else {
  227.                     _object addMPEventHandler ["MPKilled",{_this call object_handleServerKilled;}];
  228.                 };
  229.                 // Test disabling simulation server side on buildables only.
  230.                 _object enableSimulation false;
  231.                 // used for inplace upgrades && lock/unlock of safe
  232.                 _object setVariable ["OEMPos", _pos, true];
  233.                
  234.             };
  235.  
  236.             if ((count _intentory > 0) && !(typeOf( _object) == "Plastic_Pole_EP1_DZ") && !(typeOf( _object) in  DZE_DoorsLocked)) then {
  237.                 if (_type in DZE_LockedStorage) then {
  238.                     // Fill variables with loot
  239.                     _object setVariable ["WeaponCargo", (_intentory select 0),true];
  240.                     _object setVariable ["MagazineCargo", (_intentory select 1),true];
  241.                     _object setVariable ["BackpackCargo", (_intentory select 2),true];
  242.                 } else {
  243.  
  244.                     //Add weapons
  245.                     _objWpnTypes = (_intentory select 0) select 0;
  246.                     _objWpnQty = (_intentory select 0) select 1;
  247.                     _countr = 0;                   
  248.                     {
  249.                         if(_x in (DZE_REPLACE_WEAPONS select 0)) then {
  250.                             _x = (DZE_REPLACE_WEAPONS select 1) select ((DZE_REPLACE_WEAPONS select 0) find _x);
  251.                         };
  252.                         _isOK =     isClass(configFile >> "CfgWeapons" >> _x);
  253.                         if (_isOK) then {
  254.                             _object addWeaponCargoGlobal [_x,(_objWpnQty select _countr)];
  255.                         };
  256.                         _countr = _countr + 1;
  257.                     } count _objWpnTypes;
  258.                
  259.                     //Add Magazines
  260.                     _objWpnTypes = (_intentory select 1) select 0;
  261.                     _objWpnQty = (_intentory select 1) select 1;
  262.                     _countr = 0;
  263.                     {
  264.                         if (_x == "BoltSteel") then { _x = "WoodenArrow" }; // Convert BoltSteel to WoodenArrow
  265.                         if (_x == "ItemTent") then { _x = "ItemTentOld" };
  266.                         _isOK =     isClass(configFile >> "CfgMagazines" >> _x);
  267.                         if (_isOK) then {
  268.                             _object addMagazineCargoGlobal [_x,(_objWpnQty select _countr)];
  269.                         };
  270.                         _countr = _countr + 1;
  271.                     } count _objWpnTypes;
  272.  
  273.                     //Add Backpacks
  274.                     _objWpnTypes = (_intentory select 2) select 0;
  275.                     _objWpnQty = (_intentory select 2) select 1;
  276.                     _countr = 0;
  277.                     {
  278.                         _isOK =     isClass(configFile >> "CfgVehicles" >> _x);
  279.                         if (_isOK) then {
  280.                             _object addBackpackCargoGlobal [_x,(_objWpnQty select _countr)];
  281.                         };
  282.                         _countr = _countr + 1;
  283.                     } count _objWpnTypes;
  284.                 };
  285.             }; 
  286.            
  287.             if (_object isKindOf "AllVehicles") then {
  288.                 private ["_colour","_colour2","_clrinit","_clrinit2"];
  289.                 {
  290.                     _selection = _x select 0;
  291.                     _dam = _x select 1;
  292.                     if (_selection in dayZ_explosiveParts && _dam > 0.8) then {_dam = 0.8};
  293.                     [_object,_selection,_dam] call object_setFixServer;
  294.                 } count _hitpoints;
  295.  
  296.                 //Paint Vehicle
  297.                 if(count _worldspace >= 4) then{   
  298.                     if (((typeName(_worldspace select 2)) == "STRING") and ((typeName(_worldspace select 3)) == "STRING")) then {
  299.                     _colour = _worldspace select 2;
  300.                     _colour2 = _worldspace select 3;
  301.                    
  302.                     if (_colour != "0") then {
  303.                         _object setVariable ["Colour",_colour,true];
  304.                         _clrinit = format ["#(argb,8,8,3)color(%1)",_colour];
  305.                         _object setVehicleInit "this setObjectTexture [0,"+str _clrinit+"];";
  306.                     };
  307.                     if (_colour2 != "0") then {        
  308.                         _object setVariable ["Colour2",_colour2,true];
  309.                         _clrinit2 = format ["#(argb,8,8,3)color(%1)",_colour2];
  310.                         _object setVehicleInit "this setObjectTexture [1,"+str _clrinit2+"];";
  311.                     };
  312.                 };
  313.             };
  314.                
  315.                 _object setFuel _fuel;
  316.  
  317.                 if (!((typeOf _object) in dayz_allowedObjects)) then {
  318.                    
  319.                     //_object setvelocity [0,0,1];
  320.                     _object call fnc_veh_ResetEH;      
  321.                    
  322.                     if(_ownerID != "0" && !(_object isKindOf "Bicycle")) then {
  323.                         _object setvehiclelock "locked";
  324.                     };
  325.                    
  326.                     _totalvehicles = _totalvehicles + 1;
  327.  
  328.                     // total each vehicle
  329.                     serverVehicleCounter set [count serverVehicleCounter,_type];
  330.                 };
  331.             };
  332.  
  333.             //Monitor the object
  334.             PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor,_object];
  335.         };
  336.     } count _objectArray;
  337.     // # END SPAWN OBJECTS #
  338.  
  339.     // preload server traders menu data into cache
  340.     if !(DZE_ConfigTrader) then {
  341.         {
  342.             // get tids
  343.             _traderData = call compile format["menu_%1;",_x];
  344.             if (!isNil "_traderData") then {
  345.                 {
  346.                     _traderid = _x select 1;
  347.                     //_key = format["CHILD:399:%1:",_traderid];
  348.                     _key = format["\cache\traders\%1.sqf", _traderid];
  349.                                         diag_log ("LOAD TRADER: "+_key);
  350.                                         _res = preprocessFile _key;
  351.  
  352.                                         if ((_res == "") or (isNil "_res")) then {
  353.                                             diag_log ("TRADER NOT FOUND");
  354.                                         } else {
  355.                                             call compile format["ServerTcache_%1 = [];", _traderid];
  356.                    
  357.                                             _retrader = call compile _res;
  358.                                             diag_log format["Count: %1", str(count _retrader)];
  359.            
  360.                                             {
  361.                                                 call compile format["ServerTcache_%1 set [count ServerTcache_%1,%2]", _traderid, _x];
  362.                                             } forEach _retrader;
  363.  
  364.                                             _retrader = nil;
  365.                                         };
  366.                                         _res = nil;
  367.  
  368.                 } forEach (_traderData select 0);
  369.             };
  370.         } forEach serverTraders;
  371.     };
  372.  
  373.     //  spawn_vehicles
  374.     _vehLimit = MaxVehicleLimit - _totalvehicles;
  375.     if (_vehLimit > 0) then {
  376.         diag_log ("HIVE: Spawning # of Vehicles: " + str(_vehLimit));
  377.         for "_x" from 1 to _vehLimit do {
  378.             [] spawn spawn_vehicles;
  379.         };
  380.     } else {
  381.         diag_log "HIVE: Vehicle Spawn limit reached!";
  382.     };
  383.    
  384.     //  spawn_roadblocks
  385.     diag_log ("HIVE: Spawning # of Debris: " + str(MaxDynamicDebris));
  386.     for "_x" from 1 to MaxDynamicDebris do {
  387.         [] spawn spawn_roadblocks;
  388.     };
  389.     //  spawn_ammosupply at server start 1% of roadblocks
  390.     diag_log ("HIVE: Spawning # of Ammo Boxes: " + str(MaxAmmoBoxes));
  391.     for "_x" from 1 to MaxAmmoBoxes do {
  392.         [] spawn spawn_ammosupply;
  393.     };
  394.     // call spawning mining veins
  395.     diag_log ("HIVE: Spawning # of Veins: " + str(MaxMineVeins));
  396.     for "_x" from 1 to MaxMineVeins do {
  397.         [] spawn spawn_mineveins;
  398.     };
  399.  
  400.     if(isnil "dayz_MapArea") then {
  401.         dayz_MapArea = 10000;
  402.     };
  403.     if(isnil "HeliCrashArea") then {
  404.         HeliCrashArea = dayz_MapArea / 2;
  405.     };
  406.     if(isnil "OldHeliCrash") then {
  407.         OldHeliCrash = false;
  408.     };
  409.  
  410.     // [_guaranteedLoot, _randomizedLoot, _frequency, _variance, _spawnChance, _spawnMarker, _spawnRadius, _spawnFire, _fadeFire]
  411.     if(OldHeliCrash) then {
  412.         _nul = [3, 4, (50 * 60), (15 * 60), 0.75, 'center', HeliCrashArea, true, false] spawn server_spawnCrashSite;
  413.     };
  414.  
  415.     if (isDedicated) then {
  416.         // Epoch Events
  417.         _id = [] spawn server_spawnEvents;
  418.         // server cleanup
  419.         [] spawn {
  420.             private ["_id"];
  421.             sleep 200; //Sleep Lootcleanup, don't need directly cleanup on startup + fix some performance issues on serverstart
  422.             waitUntil {!isNil "server_spawnCleanAnimals"};
  423.             _id = [] execFSM "\z\addons\dayz_server\system\server_cleanup.fsm";
  424.         };
  425.  
  426.         // spawn debug box
  427.         _debugMarkerPosition = getMarkerPos "respawn_west";
  428.         _debugMarkerPosition = [(_debugMarkerPosition select 0),(_debugMarkerPosition select 1),1];
  429.         _vehicle_0 = createVehicle ["DebugBox_DZ", _debugMarkerPosition, [], 0, "CAN_COLLIDE"];
  430.         _vehicle_0 setPos _debugMarkerPosition;
  431.         _vehicle_0 setVariable ["ObjectID","1",true];
  432.  
  433.         // max number of spawn markers
  434.         if(isnil "spawnMarkerCount") then {
  435.             spawnMarkerCount = 10;
  436.         };
  437.         actualSpawnMarkerCount = 0;
  438.         // count valid spawn marker positions
  439.         for "_i" from 0 to spawnMarkerCount do {
  440.             if (!([(getMarkerPos format["spawn%1", _i]), [0,0,0]] call BIS_fnc_areEqual)) then {
  441.                 actualSpawnMarkerCount = actualSpawnMarkerCount + 1;
  442.             } else {
  443.                 // exit since we did not find any further markers
  444.                 _i = spawnMarkerCount + 99;
  445.             };
  446.            
  447.         };
  448.         diag_log format["Total Number of spawn locations %1", actualSpawnMarkerCount];
  449.        
  450.         endLoadingScreen;
  451.     };
  452.    
  453.     //WAI Mission System
  454.     ExecVM "\z\addons\dayz_server\WAI\init.sqf";
  455.    
  456.     allowConnection = true;
  457.     sm_done = true;
  458.     publicVariable "sm_done";
  459. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement