From 1a211407b93926b2fb15b82d6f6b5d2b9d24bc26 Mon Sep 17 00:00:00 2001 From: vbawol Date: Tue, 15 Aug 2017 14:19:03 -0500 Subject: [PATCH] updates to login system and hitpoints - No longer track hitpoints from client side, now saved server side only and pushed to clients on login. https://community.bistudio.com/wiki/getAllHitPointsDamage - Changed use set / getUnitLoadout and should still have legacy player data support that will upgrade automatically on first save. - Default loadout can be controlled via new variables in epochconfig.hpp - Made data validation check dynamic using isEqualTypeParams as it does type checking and still fails if input is shorter than the default. https://community.bistudio.com/wiki/isEqualTypeParams - Added back server side damage protection for the new player body. If the new unit dies before the player switch it could cause login issues and should not cause issues with scripted setdamage or hitpoints as first thought. https://community.bistudio.com/wiki/allowDamage --- .../@epochhive/epochconfig.hpp | 52 +-- Sources/epoch_code/System/player_login.fsm | 25 +- .../compile/functions/EPOCH_pushCustomVar.sqf | 1 - Sources/epoch_code/init/both_init.sqf | 3 +- .../epoch_config/Configs/CfgEpochClient.hpp | 8 +- .../epoch_player/EPOCH_server_checkPlayer.sqf | 23 +- .../epoch_player/EPOCH_server_loadPlayer.sqf | 403 ++++++++++-------- .../epoch_player/EPOCH_server_savePlayer.sqf | 26 +- 8 files changed, 280 insertions(+), 261 deletions(-) diff --git a/Server_Install_Pack/@epochhive/epochconfig.hpp b/Server_Install_Pack/@epochhive/epochconfig.hpp index 69f5a53d..f1d3adf8 100644 --- a/Server_Install_Pack/@epochhive/epochconfig.hpp +++ b/Server_Install_Pack/@epochhive/epochconfig.hpp @@ -30,7 +30,8 @@ antagonistChanceLoot = 0.09; //9% chance when player click "SEARCH" on a loot ob // Player Related cloneCost = 100; // debt incurred on player death MaxBankDebitforTrade = -50000; // If Player has less money on Bank, Crypto from Trade goes directly to Bank instead to Player -// Start Leadout + +// Default Loadout defaultUniformFemale = "U_Test_uniform"; defaultVestFemale = "V_F41_EPOCH"; defaultUniformMale = "U_Test1_uniform"; @@ -38,47 +39,14 @@ defaultVestMale = "V_41_EPOCH"; defaultGoggles = ""; defaultHeadgear = ""; defaultBackpack = ""; -linkedItems[] = {"ItemMap","EpochRadio0"}; // {"Item1","Item2",...}; These Items will be linked to the Players Inventory -itemsInContainers[] = {}; // {"Item1","Item2",...}; These Items will be put in the Players Cargo(s) -weaponsInContainers[] = {}; // {"Weapon1","Weapon2",...}; These Weapons will be put in the Players Cargo(s) -normalMagazines[] = {}; // {{"Magazine1",Ammocount1},{"Magazine2",Ammocount2},...}; -weaponsAndItems[] = { -/* - "srifle_EBR_F", // Active Weapon (in hand) - { // Full equipped Weapons (put here equipped Weapons that should be in the Weapons Slots) - { - "srifle_EBR_F", // Weapon 1 - "muzzle_snds_B", // Suppressor 1 - "acc_pointer_IR", // Laser 1 - "optic_DMS", // Optics 1 - {"20Rnd_762x51_Mag",20}, // Magtype + ammo count 1 - {}, // 2nd Magtype + ammo count 1 (Only needed for GL-Mags) - "bipod_02_F_blk" // Bipod 1 - }, - { - "Plunger", // Weapon 2 - "", // Suppressor 2 - "", // Laser 2 - "", // Optics 2 - {"stick_swing",1000}, // Magtype + ammo count 2 - "" - }, - { - "ruger_pistol_epoch", - "", // Suppressor 3 - "", // Laser 3 - "", // Optics 3 - {"10rnd_22X44_magazine",10}, // Magtype + ammo count 3 - "" // Bipod 3 - } - }, - { - "srifle_EBR_F", // Primary Weapon - "Plunger", // Secondary Weapon - "ruger_pistol_epoch" // Handgun Weapon - } -*/ -}; +defaultprimaryWeapon[] = {}; // {"arifle_MX_pointer_F","","acc_pointer_IR","",{"30Rnd_65x39_caseless_mag",29},{},""}; +defaultsecondaryWeapon[] = {}; // {"launch_NLAW_F","","","",{"NLAW_F",1},{},""}; +defaulthandgunWeapon[] = {}; // {"hgun_P07_F","","","",{"16Rnd_9x21_Mag",16},{},""}; +defaultuniformItems[] = {}; // {{"FirstAidKit",1},{"30Rnd_65x39_caseless_mag",2,30},{"Chemlight_green",1,1}}; +defaultvestItems[] = {}; // {{"30Rnd_65x39_caseless_mag",3,30},{"16Rnd_9x21_Mag",2,16},{"SmokeShell",1,1},{"SmokeShellGreen",1,1},{"SmokeShellBlue",1,1},{"SmokeShellOrange",1,1},{"Chemlight_green",1,1}}; +defaultbackpackItems[] = {}; // {{"Medikit",1},{"FirstAidKit",10},{{"hgun_P07_F","","","",{"16Rnd_9x21_Mag",16},{},""},1}}; +defaultassignedItems[] = {}; // {"Rangefinder","","","",{},{},""} +defaultlinkedItems[] = {"ItemMap","","EpochRadio0","","",""}; // {"ItemMap","ItemGPS","ItemRadio","ItemCompass","ItemWatch","NVGoggles"}; // vehicles - Max vehicle slots is calculated from per vehicle limits below. Warning! Higher the number lower the performance. disableAutoRefuel = "true"; // Removes auto refuel from all buildings at server startup. diff --git a/Sources/epoch_code/System/player_login.fsm b/Sources/epoch_code/System/player_login.fsm index 70973387..c2681f1a 100644 --- a/Sources/epoch_code/System/player_login.fsm +++ b/Sources/epoch_code/System/player_login.fsm @@ -1,7 +1,7 @@ -/*%FSM*/ +/*%FSM*/ /*%FSM*/ /* -item0[] = {"INIT",0,250,-25.000000,-375.000000,75.000000,-325.000000,0.000000,"INIT"}; +item0[] = {"INIT",0,4346,-25.000000,-375.000000,75.000000,-325.000000,0.000000,"INIT"}; item1[] = {"FINISH",1,250,-149.463196,1518.792480,-49.463196,1568.792480,0.000000,"FINISH"}; item2[] = {"true",8,218,-150.000000,-125.000000,-50.000000,-75.000000,0.000000,"true"}; item3[] = {"Version_Check",2,250,-25.000000,-75.000000,75.000000,-25.000000,0.000000,"Version Check"}; @@ -18,7 +18,7 @@ item13[] = {"ERROR_PlayerUID",2,250,275.000000,125.000000,375.000000,175.000000, item14[] = {"",7,210,471.000061,145.999908,478.999939,154.000092,0.000000,""}; item15[] = {"Timeout_No_Respo",4,218,125.000000,875.000000,225.000000,925.000000,0.000000,"Timeout" \n "No Response"}; item16[] = {"Response",4,218,-150.000000,825.000000,-50.000000,875.000000,0.000000,"Response"}; -item17[] = {"Setup_Player_Var",2,4346,-25.000000,1075.000000,75.000000,1125.000000,0.000000,"Setup Player" \n "Variables"}; +item17[] = {"Setup_Player_Var",2,250,-25.000000,1075.000000,75.000000,1125.000000,0.000000,"Setup Player" \n "Variables"}; item18[] = {"Request_Hive",2,250,-25.000000,575.000000,75.000000,625.000000,0.000000,"Request Hive"}; item19[] = {"Timeout_No_Respo",4,218,125.000000,575.000000,225.000000,625.000000,0.000000,"Timeout" \n "No Response"}; item20[] = {"ERROR_Server_not",2,250,275.000000,875.000000,375.000000,925.000000,0.000000,"ERROR" \n "Server not" \n "Response"}; @@ -183,8 +183,8 @@ link93[] = {82,76}; link94[] = {83,16}; link95[] = {83,22}; link96[] = {84,31}; -globals[] = {0.000000,0,0,0,0,640,480,1,247,6316128,1,-374.618774,303.072205,1651.411377,653.207275,573,844,1}; -window[] = {2,-1,-1,-1,-1,863,96,1080,96,3,595}; +globals[] = {0.000000,0,0,0,0,640,480,1,247,6316128,1,-406.572662,335.025604,359.874329,-776.300476,577,884,1}; +window[] = {2,-1,-1,-32000,-32000,871,104,1088,104,3,595}; *//*%FSM*/ class FSM { @@ -209,7 +209,10 @@ class FSM "EPOCH_loginFSM = _thisFSM;" \n "EPOCH_playerLoginInit = {" \n " EPOCH_loginFSM setFSMVariable [_this select 0, _this select 1];" \n - "};"/*%FSM*/; + "};" \n + "" \n + "// init vars " \n + "_hitpoints = [];"/*%FSM*/; precondition = /*%FSM*/""/*%FSM*/; class Links { @@ -893,11 +896,10 @@ class FSM " player addEventHandler [_x,([""CfgEpochClient"", _x, """"] call EPOCH_fnc_returnConfigEntryV2)];" \n "} forEach ([""CfgEpochClient"", ""addEventHandler"", []] call EPOCH_fnc_returnConfigEntryV2);" \n "" \n - "if (count EPOCH_playerHitPoints isEqualTo count ((getAllHitPointsDamage player) param [0,[]])) then {" \n - " {" \n - " player setHitIndex [_forEachIndex, _x];" \n - " }forEach EPOCH_playerHitPoints;" \n - "};" \n + "// set inital hitpoints" \n + "{" \n + " player setHitIndex [_forEachIndex, _x];" \n + "}forEach _hitpoints;" \n "" \n "true call EPOCH_fnc_Weather;" \n "[5,100] spawn EPOCH_niteLight;" \n @@ -1400,6 +1402,7 @@ class FSM "Epoch_personalToken = _C_SET deleteAt 0;" \n "Epoch_my_Group = _C_SET deleteAt 0;" \n "_communityStats = _C_SET deleteAt 0;" \n + "_hitpoints = _C_SET deleteAt 0;" \n "" \n "_extraPayload = _C_SET deleteAt 0;" \n "" \n diff --git a/Sources/epoch_code/compile/functions/EPOCH_pushCustomVar.sqf b/Sources/epoch_code/compile/functions/EPOCH_pushCustomVar.sqf index 23f73cbf..b9f5e39f 100644 --- a/Sources/epoch_code/compile/functions/EPOCH_pushCustomVar.sqf +++ b/Sources/epoch_code/compile/functions/EPOCH_pushCustomVar.sqf @@ -27,7 +27,6 @@ private ["_customVars","_lastSave","_time"]; _time = if (_this) then [{15},{80}]; _lastSave = missionNamespace getVariable["EPOCH_lastSave", diag_tickTime]; if ((diag_tickTime - _lastSave) >= _time) then { - EPOCH_playerHitPoints = ((getAllHitPointsDamage player) param [2,[]]); _customVars = []; { _customVars pushBack (missionNamespace getVariable format["EPOCH_player%1",_x]); diff --git a/Sources/epoch_code/init/both_init.sqf b/Sources/epoch_code/init/both_init.sqf index 602a5164..c76b4c31 100644 --- a/Sources/epoch_code/init/both_init.sqf +++ b/Sources/epoch_code/init/both_init.sqf @@ -60,7 +60,6 @@ EPOCH_customVarsDefaults = [ ["Toxicity",0,[100,0]], ["Stamina",100,["EPOCH_playerStaminaMax",0]], ["Crypto",0,[250000,0]], - ["HitPoints",[0,0,0,0],[1,1,1,1]], ["BloodP",100,[190,0]], ["SpawnArray",[],[]], ["Karma",0,[50000,-50000]], @@ -142,4 +141,4 @@ if(_dynSimToggle)then "Vehicle" setDynamicSimulationDistance getNumber(_cfgDynamicSimulation >> "vehicleDynSimDistance"); "EmptyVehicle" setDynamicSimulationDistance getNumber(_cfgDynamicSimulation >> "emptyVehicleDynSimDistance"); "Prop" setDynamicSimulationDistance getNumber(_cfgDynamicSimulation >> "propDynSimDistance"); -}; \ No newline at end of file +}; diff --git a/Sources/epoch_config/Configs/CfgEpochClient.hpp b/Sources/epoch_config/Configs/CfgEpochClient.hpp index 23ba3360..abe17872 100644 --- a/Sources/epoch_config/Configs/CfgEpochClient.hpp +++ b/Sources/epoch_config/Configs/CfgEpochClient.hpp @@ -56,7 +56,7 @@ class CfgEpochClient niteLight[] = {1,1.88,22}; //Set ambient lighting at night: {Brightness of light,Height of light}. Default (Low Ambient): {1.88,22} | Twilight: {7.2,88} | Distant: {12.8,142} ryanZombiesEnabled = "true"; antagonistSpawnIndex[] = {{"Epoch_Cloak_F",1},{"GreatWhite_F",2},{"Epoch_Sapper_F",2},{"Epoch_SapperG_F",1},{"Epoch_SapperB_F",1},{"I_UAV_01_F",2},{"PHANTOM",1},{"B_Heli_Transport_01_F",1},{"EPOCH_RyanZombie_1",12},{"I_Soldier_EPOCH",1}}; // {"type", limit} - customVarsDefaults[] = {{"Temp",98.6,{106.7,95,102,105,96,95}},{"Hunger",1500,{5000,0,5001,5001,1250,0}},{"Thirst",750,{2500,0,2501,2501,625,0}},{"AliveTime",0,{-2,0}},{"Energy",0,{2500,0}},{"Wet",0,{100,0,35,55,-1,-1}},{"Soiled",0,{100,0,35,55,-1,-1}},{"Immunity",0,{100,0}},{"Toxicity",0,{100,0,35,55,-1,-1}},{"Stamina",100,{"EPOCH_playerStaminaMax",0}},{"Crypto",0,{250000,0}},{"HitPoints",{0,0,0,0},{1,0,0.5,1,-1,-1}},{"BloodP",100,{190,0,120,140,70,50}},{"SpawnArray",{},{}},{"Karma",0,{50000,-50000}},{"Alcohol",0,{100,0,35,55,-1,-1}},{"Radiation",0,{100,0,35,55,-1,-1}},{"Nuisance",0,{100,0}},{"MissionArray",{},{}}}; // EPOCH_player + varName, default value, {max,min,high-warn,high-critical,low-warn,low-critical} + customVarsDefaults[] = {{"Temp",98.6,{106.7,95,102,105,96,95}},{"Hunger",1500,{5000,0,5001,5001,1250,0}},{"Thirst",750,{2500,0,2501,2501,625,0}},{"AliveTime",0,{-2,0}},{"Energy",0,{2500,0}},{"Wet",0,{100,0,35,55,-1,-1}},{"Soiled",0,{100,0,35,55,-1,-1}},{"Immunity",0,{100,0}},{"Toxicity",0,{100,0,35,55,-1,-1}},{"Stamina",100,{"EPOCH_playerStaminaMax",0}},{"Crypto",0,{250000,0}},{"BloodP",100,{190,0,120,140,70,50}},{"SpawnArray",{},{}},{"Karma",0,{50000,-50000}},{"Alcohol",0,{100,0,35,55,-1,-1}},{"Radiation",0,{100,0,35,55,-1,-1}},{"Nuisance",0,{100,0}},{"MissionArray",{},{}}}; // EPOCH_player + varName, default value, {max,min,high-warn,high-critical,low-warn,low-critical} // add any stats and their starting number here for better community integration and neat stats tracking too! defineCommunityStats[] = {{"Murders",0},{"Deaths",0},{"Suicides",0},{"Revives",0},{"TraderMissions",0},{"AIKills",0},{"AntagonistKills",0},{"ZombieKills",0}}; hudConfigs[] = {{{"BloodP","","",{"getPlayerDamage",">=",0.7}},"topRight","x\addons\a3_epoch_code\Data\UI\bleeding_ca.paa",{"forceUpdate"}},{{"Oxygen","getPlayerOxygenRemaining","",{},{1,0,2,2,1,0.55}},"topRight","x\addons\a3_epoch_code\Data\UI\oxygen_ca.paa"},{"Hunger","topRight","x\addons\a3_epoch_code\Data\UI\hunger_ca.paa",{"forceBloodRise"}},{"Thirst","topRight","x\addons\a3_epoch_code\Data\UI\thirst_ca.paa",{"forceBloodRise"}},{"Temp","topRight",{"x\addons\a3_epoch_code\Data\UI\hot_ca.paa","x\addons\a3_epoch_code\Data\UI\cold_ca.paa"},{"forceFatigue"}},{"Toxicity","topRight","x\addons\a3_epoch_code\Data\UI\hazzard_ca.paa"},{"Alcohol","topRight","x\addons\a3_epoch_code\Data\UI\drunk_ca.paa"},{"Soiled","topRight","x\addons\a3_epoch_code\Data\UI\soiled_ca.paa"},{"Radiation","topRight","x\addons\a3_epoch_code\Data\UI\rads_ca.paa"},{{"HitPoints","getPlayerHitPointDamage","HitLegs"},"topRight","x\addons\a3_epoch_code\Data\UI\broken_ca.paa"}}; @@ -92,13 +92,13 @@ class CfgEpochClient playerDisableRevenge = 0; playerRevengeMinAliveTime = 900; bankTransferTime[] = {0.0006,1.2,0.06}; - + // Favorite Bar Fav_enableFavoriteBar = "true"; // If disabled, players will not be able to use favorite bar Fav_DropIfOverflow = "false"; // If enabled and inventory full, equipped weapon will be dropped on ground in favor for the new selected weapon, otherwise action will fail with message and weapon will not be equipped Fav_FastWeaponSwitching = "false"; // If enabled, same slot weapons from favorites bar are equipped instantly, otherwise reload action is played (recommended for immersion) Fav_BannedItems[] = {"FAK"}; // Items that users are not allowed to pin - + // Advanced Vehicle Repair UseAdvancedVehicleRepair = "true"; // Switch On / Off Advanced Vehicle Repair (Does not effect SuppressedCraftingItems !) DisallowSellOnDamage = "false"; // Prevent from selling Vehicles with one or more fully damaged wheel or engine @@ -122,7 +122,7 @@ class CfgEpochClient {"HitWinch",0.33,0.91,"ItemCables","ItemCables"}, {"HitAvionics",0.33,0.91,"CircuitParts","CircuitParts"} }; - + // include configs #include "CfgEpochClient\Altis.hpp" #include "CfgEpochClient\australia.hpp" diff --git a/Sources/epoch_server/compile/epoch_player/EPOCH_server_checkPlayer.sqf b/Sources/epoch_server/compile/epoch_player/EPOCH_server_checkPlayer.sqf index 391b31b1..808b4d56 100644 --- a/Sources/epoch_server/compile/epoch_player/EPOCH_server_checkPlayer.sqf +++ b/Sources/epoch_server/compile/epoch_player/EPOCH_server_checkPlayer.sqf @@ -13,7 +13,7 @@ https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_server/compile/epoch_player/EPOCH_server_checkPlayer.sqf */ //[[[cog import generate_private_arrays ]]] -private ["_apperance","_arr","_class","_dead","_deadPlayer","_hitpoints","_isMale","_medical","_playerUID","_response","_vars","_communityStatsArray"]; +private ["_apperance","_arr","_class","_communityStatsArray","_dead","_deadPlayer","_defaultData","_instanceID","_isMale","_medical","_playerUID","_response","_return","_vars"]; //[[[end]]] params [["_playerObj",objNull]]; if (_playerObj isEqualType objNull) then { @@ -26,12 +26,19 @@ if (_playerObj isEqualType objNull) then { _dead = false; _isMale = true; + _instanceID = call EPOCH_fn_InstanceID; + _class = "Epoch_Female_F"; + _arr = []; if ((_response select 0) == 1 && (_response select 1) isEqualType []) then { _arr = (_response select 1); }; - if (count _arr < 11) then { + // empty default data format, if "Player" data format is changed update this array! + _defaultData = [[], [], [], [], [], [], [], [], [], [], "", true]; + + // If data does not validate against default or is too short, assume player is new or already dead. + if !(_arr isEqualTypeParams _defaultData) then { _dead = true; } else { _medical = _arr select 1; @@ -40,23 +47,21 @@ if (_playerObj isEqualType objNull) then { if (_class == "Epoch_Female_F") then { _isMale = false; }; - _vars = _arr select 4; - _hitpoints = _vars select 11; - + _medical params ["","","","_damage",["_hitpoints",[0,0,0,0,0,0,0,0,0,0,0]] ]; _deadPlayer = ["PlayerStats", _playerUID, 0] call EPOCH_fnc_server_hiveGETBIT; - - if (_deadPlayer || (_medical select 3 == 1) || (_hitpoints select 2 == 1) || (_hitpoints select 3 == 1) || (_vars select 12 >= 180)) then { + // check if player is already dead or was critically hit HitHead = 2 or HitBody = 7 and if blood pressure too high. + if (_deadPlayer || (_damage == 1) || (_hitpoints select 2 == 1) || (_hitpoints select 7 == 1) || (_vars select 12 >= 180)) then { _dead = true; }; }; - + // check status of community stats to prevent load / save issues _communityStatsArray = ["CommunityStats", _playerUID] call EPOCH_fnc_server_hiveGETRANGE; if((_communityStatsArray select 1) isEqualTo []) then{ _return = ["CommunityStats", _playerUID, EPOCH_expiresCommunityStats, [EPOCH_defaultStatVars]] call EPOCH_fnc_server_hiveSETEX; }; - + /* true => New Char false => load old Char */ ['_checkPlayer_PVC', _dead] remoteExec ['EPOCH_playerLoginInit',_playerObj]; diff --git a/Sources/epoch_server/compile/epoch_player/EPOCH_server_loadPlayer.sqf b/Sources/epoch_server/compile/epoch_player/EPOCH_server_loadPlayer.sqf index 65d59eeb..3b209ead 100644 --- a/Sources/epoch_server/compile/epoch_player/EPOCH_server_loadPlayer.sqf +++ b/Sources/epoch_server/compile/epoch_player/EPOCH_server_loadPlayer.sqf @@ -1,19 +1,19 @@ /* Author: Aaron Clark - EpochMod.com - Contributors: He-Man + Contributors: He-Man Description: Player Login - Licence: - Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike + Licence: + Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike - Github: - https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_server/compile/epoch_player/EPOCH_server_loadPlayer.sqf + Github: + https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_server/compile/epoch_player/EPOCH_server_loadPlayer.sqf */ //[[[cog import generate_private_arrays ]]] -private ["_CheckLocation","_allGroupMembers","_alreadyDead","_attachments","_backpack","_canBeRevived","_class","_currWeap","_deadPlayer","_defaultData","_dir","_equipped","_found","_goggles","_group","_headgear","_hitpoints","_instanceID","_itemsInContainers","_jammer","_jammers","_linkedItems","_location","_newLocation","_newPlyr","_normalMagazines","_playerData","_playerGroup","_playerGroupArray","_playerNetID","_playerUID","_reject","_serverSettingsConfig","_type","_uniform","_vars","_vest","_wMags","_wMagsArray","_weapon","_weaponsAndItems","_weaponsInContainers","_communityStatsArray","_communityStats"]; +private ["_CheckLocation","_allGroupMembers","_alreadyDead","_assignedItems","_attachments","_backpack","_backpackItems","_canBeRevived","_class","_communityStats","_communityStatsArray","_currWeap","_deadPlayer","_defaultData","_dir","_equipped","_found","_goggles","_group","_handgunWeapon","_headgear","_instanceID","_jammer","_jammers","_linkedItems","_loadout","_location","_newLocation","_newPlyr","_playerData","_playerGroup","_playerGroupArray","_playerNetID","_playerUID","_primaryWeapon","_reject","_secondaryWeapon","_serverSettingsConfig","_type","_uniform","_uniformItems","_vars","_vest","_vestItems","_wMags","_wMagsArray","_weapon"]; //[[[end]]] _reject = true; @@ -21,24 +21,24 @@ params [["_player",objNull,[objNull]],["_isMale",true]]; if (!isNull _player) then { - // load server settings - _serverSettingsConfig = configFile >> "CfgEpochServer"; - _instanceID = call EPOCH_fn_InstanceID; + // load server settings + _serverSettingsConfig = configFile >> "CfgEpochServer"; + _instanceID = call EPOCH_fn_InstanceID; - _playerNetID = owner _player; + _playerNetID = owner _player; _playerUID = getPlayerUID _player; if (_playerUID != "") then { // Make Hive call _playerData = []; - (["Player", _playerUID] call EPOCH_fnc_server_hiveGETRANGE) params [ - ["_status", 0 ], - ["_playerDataTmp", [] ] - ]; - if (_status == 1 && _playerDataTmp isEqualType []) then { - _playerData = _playerDataTmp; - }; + (["Player", _playerUID] call EPOCH_fnc_server_hiveGETRANGE) params [ + ["_status", 0 ], + ["_playerDataTmp", [] ] + ]; + if (_status == 1 && _playerDataTmp isEqualType []) then { + _playerData = _playerDataTmp; + }; // Apperance defaults _uniform = [_serverSettingsConfig, "defaultUniformFemale", "U_Test_uniform"] call EPOCH_fnc_returnConfigEntry; @@ -54,87 +54,105 @@ if (!isNull _player) then { _backpack = [_serverSettingsConfig, "defaultBackpack", ""] call EPOCH_fnc_returnConfigEntry; // Inventory defaults - _linkedItems = [_serverSettingsConfig, "linkedItems", ["ItemMap","EpochRadio0"]] call EPOCH_fnc_returnConfigEntry; - _itemsInContainers = [_serverSettingsConfig, "itemsInContainers", []] call EPOCH_fnc_returnConfigEntry; - _weaponsInContainers = [_serverSettingsConfig, "weaponsInContainers", []] call EPOCH_fnc_returnConfigEntry; - _normalMagazines = [_serverSettingsConfig, "normalMagazines", []] call EPOCH_fnc_returnConfigEntry; - _weaponsAndItems = [_serverSettingsConfig, "weaponsAndItems", ["", []] ] call EPOCH_fnc_returnConfigEntry; + _primaryWeapon = [_serverSettingsConfig, "defaultprimaryWeapon", []] call EPOCH_fnc_returnConfigEntry; // ["arifle_MX_pointer_F","","acc_pointer_IR","",["30Rnd_65x39_caseless_mag",29],[],""]; + _secondaryWeapon = [_serverSettingsConfig, "defaultsecondaryWeapon", []] call EPOCH_fnc_returnConfigEntry; // ["launch_NLAW_F","","","",["NLAW_F",1],[],""]; + _handgunWeapon = [_serverSettingsConfig, "defaulthandgunWeapon", []] call EPOCH_fnc_returnConfigEntry; // ["hgun_P07_F","","","",["16Rnd_9x21_Mag",16],[],""]; + _uniformItems = [_serverSettingsConfig, "defaultuniformItems", []] call EPOCH_fnc_returnConfigEntry; // [["FirstAidKit",1],["30Rnd_65x39_caseless_mag",2,30],["Chemlight_green",1,1]]; + _vestItems = [_serverSettingsConfig, "defaultvestItems", []] call EPOCH_fnc_returnConfigEntry; // [["30Rnd_65x39_caseless_mag",3,30],["16Rnd_9x21_Mag",2,16],["SmokeShell",1,1],["SmokeShellGreen",1,1],["SmokeShellBlue",1,1],["SmokeShellOrange",1,1],["Chemlight_green",1,1]]; + _backpackItems = [_serverSettingsConfig, "defaultbackpackItems", []] call EPOCH_fnc_returnConfigEntry; // [["Medikit",1],["FirstAidKit",10],[["hgun_P07_F","","","",["16Rnd_9x21_Mag",16],[],""],1]]; + _assignedItems = [_serverSettingsConfig, "defaultassignedItems", ["","","","",[],[],""]] call EPOCH_fnc_returnConfigEntry; // ["Rangefinder","","","",[],[],""] + _linkedItems = [_serverSettingsConfig, "defaultlinkedItems", ["ItemMap","","EpochRadio0","","",""]] call EPOCH_fnc_returnConfigEntry; // ["ItemMap","ItemGPS","ItemRadio","ItemCompass","ItemWatch","NVGoggles"] - // default data - _defaultData = [[0, [], _instanceID], [0, 0, 1, 0, []], [_goggles, _headgear, _vest, _backpack, _uniform, _class], [], call EPOCH_defaultVars_SEPXVar, _weaponsAndItems, _linkedItems, _normalMagazines, _itemsInContainers, _weaponsInContainers, "", true]; + _loadout = [ + _primaryWeapon, + _secondaryWeapon, + _handgunWeapon, + [_uniform,_uniformItems], + [_vest,_vestItems], + [_backpack,_backpackItems], + _headgear, + _goggles, + _assignedItems, + _linkedItems + ]; - // todo make dynamic - if (count _playerData < 11) then { // invaild format attempt to override + // default data, if "Player" data format is changed update this array! + _defaultData = [[0, [], _instanceID, 1.0], [0, 0, 1, 0, [0,0,0,0,0,0,0,0,0,0,0]], ["", "", "", "", "", _class], [], call EPOCH_defaultVars_SEPXVar, _loadout, [], [], [], [], "", true]; + + // If data does not validate against default or is too short, override with default data. + if !(_playerData isEqualTypeParams _defaultData) then { + diag_log format["DEBUG: Invaild player data %1, defaults used instead.", _playerData]; _playerData = _defaultData; }; - _playerData params ["_worldspace","_medical","","_server_vars","_vars","","","","","","_playerGroup","_canBeRevived"]; + _playerData params ["_worldspace","_medical","","_server_vars","_vars","","","","","","_playerGroup","_canBeRevived"]; // Load world space and previous instance id - _worldspace params ["_dir","_location","_prevInstance"]; + _worldspace params ["_dir","_location","_prevInstance",["_schemaVersion",0.5]]; if (count _location == 2) then{ _location = (_location select 0) vectorAdd (_location select 1); }; - // Get player group - _playerGroupArray = []; - // check players group - if (_playerGroup != "") then { - _found = false; - (["Group", _playerGroup] call EPOCH_fnc_server_hiveGETRANGE) params [ - ["_status", 0 ], - ["_playerGroupArrayTmp", [] ] - ]; - if (_status == 1 && !(_playerGroupArrayTmp isEqualTo[])) then { - _playerGroupArrayTmp params ["","","","_modArray","_memberArray"]; - _found = _playerGroup == _playerUID; - if (!_found) then { - _allGroupMembers = (_modArray + _memberArray) apply {_x select 0}; - _found = _playerUID in _allGroupMembers; - }; - if (_found) then { - _playerGroupArray = _playerGroupArrayTmp; - }; - }; - if (!_found) then { - _playerGroup = ""; - }; - // diag_log format["DEBUG (Load Player) Set Group: %1", _playerGroup]; - }; + // Get player group + _playerGroupArray = []; + // check players group + if (_playerGroup != "") then { + _found = false; + (["Group", _playerGroup] call EPOCH_fnc_server_hiveGETRANGE) params [ + ["_status", 0 ], + ["_playerGroupArrayTmp", [] ] + ]; + if (_status == 1 && !(_playerGroupArrayTmp isEqualTo[])) then { + _playerGroupArrayTmp params ["","","","_modArray","_memberArray"]; + _found = _playerGroup == _playerUID; + if (!_found) then { + _allGroupMembers = (_modArray + _memberArray) apply {_x select 0}; + _found = _playerUID in _allGroupMembers; + }; + if (_found) then { + _playerGroupArray = _playerGroupArrayTmp; + }; + }; + if (!_found) then { + _playerGroup = ""; + }; + // diag_log format["DEBUG (Load Player) Set Group: %1", _playerGroup]; + }; - _hitpoints = _vars select 11; + _medical params ["_bleedingRemaining","_fatigue","_oxygenRemaining","_damage",["_hitpoints",[0,0,0,0,0,0,0,0,0,0,0]] ]; _deadPlayer = ["PlayerStats", _playerUID, 0] call EPOCH_fnc_server_hiveGETBIT; - _alreadyDead = (_deadPlayer || (_medical select 3 == 1) || (_hitpoints select 2 == 1) || (_hitpoints select 3 == 1) || (_vars select 12 >= 180)); + // check if player is already dead or was critically hit HitHead = 2 or HitBody = 7 and if blood pressure too high. + _alreadyDead = (_deadPlayer || (_damage == 1) || (_hitpoints select 2 == 1) || (_hitpoints select 7 == 1) || (_vars select 12 >= 180)); if (_alreadyDead || _prevInstance != _instanceID || (count _location) < 3 || !(_location isEqualType [])) then { _dir = random 360; - // try to find respawn point by position - _newLocation = _server_vars param [0,[]]; // 0 = RESPAWN POS - // normal respawn location - _location = getMarkerPos "respawn_west"; - _location set[2, 0]; - if (_newLocation isEqualType [] && {(count _newLocation) == 3}) then { + // try to find respawn point by position + _newLocation = _server_vars param [0,[]]; // 0 = RESPAWN POS + // normal respawn location + _location = getMarkerPos "respawn_west"; + _location set[2, 0]; + if (_newLocation isEqualType [] && {(count _newLocation) == 3}) then { _CheckLocation = _newLocation; if (surfaceiswater _newLocation) then { _CheckLocation = ATLToASL _newLocation; }; - _jammers = nearestObjects[_CheckLocation, ["PlotPole_EPOCH"], 6]; - if !(_jammers isEqualTo[]) then { - // get nearby object - _jammer = _jammers param [0,objNull]; - // check if object is not null and is alive. - if (!isNull _jammer && {alive _jammer}) then { - // check if player is still a member of object group. - if ((_jammer getVariable["BUILD_OWNER", "-1"]) in [_playerUID, _playerGroup]) then { - // Override location with that of object - _location = _newLocation; - }; - }; - }; - }; + _jammers = nearestObjects[_CheckLocation, ["PlotPole_EPOCH"], 6]; + if !(_jammers isEqualTo[]) then { + // get nearby object + _jammer = _jammers param [0,objNull]; + // check if object is not null and is alive. + if (!isNull _jammer && {alive _jammer}) then { + // check if player is still a member of object group. + if ((_jammer getVariable["BUILD_OWNER", "-1"]) in [_playerUID, _playerGroup]) then { + // Override location with that of object + _location = _newLocation; + }; + }; + }; + }; if (_alreadyDead) then { _vars = call EPOCH_defaultVars_SEPXVar; _canBeRevived = true; @@ -160,6 +178,9 @@ if (!isNull _player) then { _newPlyr = _group createUnit[_class, _location, [], 0, "CAN_COLLIDE"]; if !(isNull _newPlyr) then { + // disable damage server side + _newPlyr allowDamage false; + // add to cleanup addToRemainsCollector[_newPlyr]; { _newPlyr disableAI _x; @@ -170,127 +191,137 @@ if (!isNull _player) then { if (!_alreadyDead) then { // Medical - _medical params ["_bleedingRemaining","_fatigue","_oxygenRemaining","_damage"]; _newPlyr setBleedingRemaining _bleedingRemaining; // _newPlyr setFatigue _fatigue; _newPlyr setOxygenRemaining _oxygenRemaining; _newPlyr setDamage _damage; } else { - // player dead use default Data for appearance and loadout data - _playerData = _defaultData; - }; + // player dead use default Data for appearance and loadout data + _playerData = _defaultData; + }; - // Apperance + Weapons - _playerData params ["","","_apperance","","","_weaponsAndItems","_linkedItems","_normalMagazines","_itemsInContainers","_weaponsInContainers"]; - // load Apperance - _apperance params ["_goggles","_headgear","_vest","_backpack","_uniform"]; + // set player loadout + if (_schemaVersion >= 1.0) then { + _playerData params ["","","","","","_loadout"]; + _newPlyr setUnitLoadout [_loadout, false]; + diag_log format["DEBUG: loaded player %1 with new schema Version %2", _newPlyr, _schemaVersion]; - // Load Apperance START - if (_uniform != "") then { - _newPlyr addUniform _uniform; - }; - if (_backpack != "") then { - _newPlyr addBackpack _backpack; - }; - if (_goggles != "") then { - _newPlyr addGoggles _goggles; - }; - if (_headgear != "") then { - _newPlyr addHeadgear _headgear; - }; - if (_vest != "") then { - _newPlyr addVest _vest; - }; - // Load Apperance END + } else { + // Legacy code start + // Apperance + Weapons + _playerData params ["","","_apperance","","","_weaponsAndItems","_linkedItems","_normalMagazines","_itemsInContainers","_weaponsInContainers"]; + // load Apperance + _apperance params ["_goggles","_headgear","_vest","_backpack","_uniform"]; - _currWeap = ""; - // Load inventory + defaults START - if (count _weaponsAndItems >= 3) then { - _weaponsAndItems params ["_currWeapTmp","_weaponsAndItemsArray","_equipped"]; - _currWeap = _currWeapTmp; - { - _weapon = _x deleteAt 0; - _type = getNumber(configfile >> "cfgweapons" >> _weapon >> "type"); - _attachments = []; - _wMags = false; - _wMagsArray = []; - // suppressor, laser, optics, magazines(array), bipods - { - // magazines - if (_x isEqualType []) then{ - _wMags = true; - _wMagsArray pushback _x; - } else { - // attachments - if (_x != "") then{ - _attachments pushBack _x; - }; - }; - } forEach _x; - if (_wMags) then { - { - _newPlyr addMagazine _x; - } foreach _wMagsArray; - }; - // add weapon if equiped - if (_weapon in _equipped) then { - _equipped = _equipped - [_weapon]; - if (_weapon != "") then { - _newPlyr addWeapon _weapon; - }; - switch (_type) do { - case 1: { // primary - removeAllPrimaryWeaponItems _newPlyr; - { _newPlyr addPrimaryWeaponItem _x } forEach _attachments; - }; - case 2: { // handgun - removeAllHandgunItems _newPlyr; - { _newPlyr addHandgunItem _x } forEach _attachments; - }; - case 4: { // secondary - // removeAllSecondaryWeaponItems player; does not exist ? - { - _newPlyr removeSecondaryWeaponItem _x; - } forEach (secondaryWeaponItems _newPlyr); - { _newPlyr addSecondaryWeaponItem _x } forEach _attachments; - }; - }; - }else{ - { - _newPlyr addItem _x; - } forEach _attachments; - }; - } forEach _weaponsAndItemsArray; - }; - // Linked items - { - if (_x in["Binocular", "Rangefinder","Laserdesignator","Laserdesignator_02","Laserdesignator_03","Laserdesignator_01_khk_F","Laserdesignator_02_ghex_F"]) then { - _newPlyr addWeapon _x; - } else { - _newPlyr linkItem _x; + // old data format for 0.5 and prior. + // Load Apperance START + if (_uniform != "") then { + _newPlyr addUniform _uniform; + }; + if (_backpack != "") then { + _newPlyr addBackpack _backpack; + }; + if (_goggles != "") then { + _newPlyr addGoggles _goggles; + }; + if (_headgear != "") then { + _newPlyr addHeadgear _headgear; + }; + if (_vest != "") then { + _newPlyr addVest _vest; + }; + // Load Apperance END + _currWeap = ""; + // Load inventory + defaults START + if (count _weaponsAndItems >= 3) then { + _weaponsAndItems params ["_currWeapTmp","_weaponsAndItemsArray","_equipped"]; + _currWeap = _currWeapTmp; + { + _weapon = _x deleteAt 0; + _type = getNumber(configfile >> "cfgweapons" >> _weapon >> "type"); + _attachments = []; + _wMags = false; + _wMagsArray = []; + // suppressor, laser, optics, magazines(array), bipods + { + // magazines + if (_x isEqualType []) then{ + _wMags = true; + _wMagsArray pushback _x; + } else { + // attachments + if (_x != "") then{ + _attachments pushBack _x; + }; + }; + } forEach _x; + if (_wMags) then { + { + _newPlyr addMagazine _x; + } foreach _wMagsArray; + }; + // add weapon if equiped + if (_weapon in _equipped) then { + _equipped = _equipped - [_weapon]; + if (_weapon != "") then { + _newPlyr addWeapon _weapon; + }; + switch (_type) do { + case 1: { // primary + removeAllPrimaryWeaponItems _newPlyr; + { _newPlyr addPrimaryWeaponItem _x } forEach _attachments; + }; + case 2: { // handgun + removeAllHandgunItems _newPlyr; + { _newPlyr addHandgunItem _x } forEach _attachments; + }; + case 4: { // secondary + // removeAllSecondaryWeaponItems player; does not exist ? + { + _newPlyr removeSecondaryWeaponItem _x; + } forEach (secondaryWeaponItems _newPlyr); + { _newPlyr addSecondaryWeaponItem _x } forEach _attachments; + }; + }; + }else{ + { + _newPlyr addItem _x; + } forEach _attachments; + }; + } forEach _weaponsAndItemsArray; }; - } forEach _linkedItems; - // add items to containers - [_newPlyr, _itemsInContainers] call EPOCH_fnc_addItemToX; + // Linked items + { + if (_x in["Binocular", "Rangefinder","Laserdesignator","Laserdesignator_02","Laserdesignator_03","Laserdesignator_01_khk_F","Laserdesignator_02_ghex_F"]) then { + _newPlyr addWeapon _x; + } else { + _newPlyr linkItem _x; + }; + } forEach _linkedItems; - // add weapons to containers - [_newPlyr, _weaponsInContainers] call EPOCH_fnc_addItemToX; + // add items to containers + [_newPlyr, _itemsInContainers] call EPOCH_fnc_addItemToX; - // Add magazines - {_newPlyr addMagazine _x} forEach _normalMagazines; - // Load inventory + defaults END + // add weapons to containers + [_newPlyr, _weaponsInContainers] call EPOCH_fnc_addItemToX; + + // Add magazines + {_newPlyr addMagazine _x} forEach _normalMagazines; + // Load inventory + defaults END + // Legacy code stop + }; // Final Push if (isNull _player) then { deleteVehicle _newPlyr; diag_log "Epoch: DEBUG: _player object was null reject connection"; } else { - _reject = false; + _reject = false; - if (_playerGroup != "") then { - _newPlyr setVariable["GROUP", _playerGroup]; - }; + if (_playerGroup != "") then { + _newPlyr setVariable["GROUP", _playerGroup]; + }; _newPlyr setVariable["PUID", _playerUID]; @@ -309,21 +340,21 @@ if (!isNull _player) then { // load community stats _communityStatsArray = ["CommunityStats", _playerUID] call EPOCH_fnc_server_hiveGETRANGE; _communityStats = ((_communityStatsArray select 1) select 0); - _newPlyr setVariable["COMMUNITY_STATS", _communityStats]; + _newPlyr setVariable["COMMUNITY_STATS", _communityStats]; - [_playerNetID, _playerUID, [_newPlyr, _vars, _currWeap, loadAbs _newPlyr, _playerGroup, _canBeRevived, _newPlyr call EPOCH_server_setPToken,_playerGroupArray, _communityStats]] call EPOCH_server_pushPlayer; - //diag_log format["DEBUG (Load Player) Sent Group: %1 %2", _playerGroup, _playerGroupArray]; + // re enable damage server side + _newPlyr allowDamage true; + // Flag new body as ready for use. _newPlyr setVariable["SETUP", true, true]; - // revive - _newPlyr setVariable ['#rev_enabled', true, true]; + // Send message to player so they can take over the new body. + [_playerNetID, _playerUID, [_newPlyr, _vars, _currWeap, loadAbs _newPlyr, _playerGroup, _canBeRevived, _newPlyr call EPOCH_server_setPToken,_playerGroupArray, _communityStats, _hitpoints]] call EPOCH_server_pushPlayer; - // [] remoteExec ["bis_fnc_reviveInit",_player]; + // revive test + _newPlyr setVariable ['#rev_enabled', true, true]; + // [] remoteExec ["bis_fnc_reviveInit",_player]; - // This is a test to see setUnitLoadout can force propagation of unit loadout. - _newPlyr setUnitLoadout (getUnitLoadout _newPlyr); // if this works, possibly replace all inventory code with with get|setUnitLoadout - // new Dynamicsimulation if(["CfgDynamicSimulation", "playerDynamicSimulationSystem", true] call EPOCH_fnc_returnConfigEntryV2)then { diff --git a/Sources/epoch_server/compile/epoch_player/EPOCH_server_savePlayer.sqf b/Sources/epoch_server/compile/epoch_player/EPOCH_server_savePlayer.sqf index 61842bc1..441b6d7e 100644 --- a/Sources/epoch_server/compile/epoch_player/EPOCH_server_savePlayer.sqf +++ b/Sources/epoch_server/compile/epoch_player/EPOCH_server_savePlayer.sqf @@ -12,8 +12,10 @@ Github: https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_server/compile/epoch_player/EPOCH_server_savePlayer.sqf */ -private["_return", "_return2", "_pos", "_medical", "_playerUID", "_weapons", "_itemsplayer", "_weaponsplayer", "_appearance", "_dmg", "_allowSave", "_cIndex", "_Svars", "_current_crypto", "_group", "_revive", "_vehiclePlyr","_server_vars","_stats"]; -params [["_player",objNull], ["_vars",[]]]; +//[[[cog import generate_private_arrays ]]] +private ["_Svars","_allowSave","_appearance","_cIndex","_dmg","_group","_hitpoints","_itemsplayer","_loadout","_medical","_playerUID","_pos","_return","_return2","_revive","_schemaVersion","_server_vars","_stats","_vehiclePlyr","_weapons","_weaponsplayer"]; +//[[[end]]] +params [["_player",objNull], ["_vars",[]] ]; if (isNull _player) exitWith { diag_log "DEBUG SAVE ABORT null player object"; @@ -79,19 +81,31 @@ if (_allowSave) then{ }; _dmg = damage _player; - _medical = [getBleedingRemaining _player, 0, getOxygenRemaining _player, _dmg]; + _hitpoints = (getAllHitPointsDamage _player) param [2,[]]; + _medical = [getBleedingRemaining _player, 0, getOxygenRemaining _player, _dmg, _hitpoints]; + // appearance now handled with getUnitLoadout, typeof is still need to determine players class. + _appearance = ["", "", "", "", "", typeOf _player]; + + /* Old unused method _appearance = [goggles _player, headgear _player, vest _player, backpack _player, uniform _player, typeOf _player]; _itemsplayer = [getItemCargo(uniformContainer _player), getItemCargo(vestContainer _player), getItemCargo(backpackContainer _player)]; _weaponsplayer = [getWeaponCargo(uniformContainer _player), getWeaponCargo(vestContainer _player), getWeaponCargo(backpackContainer _player)]; _weapons = [currentWeapon _player, weaponsItems _player, [primaryWeapon _player, secondaryWeapon _player, handgunWeapon _player]]; + */ + + // new save format + _loadout = getUnitLoadout _player; + + // change this if needed + _schemaVersion = 1.0; // save player - _return = ["Player", _playerUID, EPOCH_expiresPlayer, [[getDir _player, _pos, (call EPOCH_fn_InstanceID)], _medical, _appearance, _server_vars, _vars, _weapons, assignedItems _player, magazinesAmmo _player, _itemsplayer, _weaponsplayer, _group, _revive]] call EPOCH_fnc_server_hiveSETEX; + _return = ["Player", _playerUID, EPOCH_expiresPlayer, [[getDir _player, _pos, (call EPOCH_fn_InstanceID), _schemaVersion], _medical, _appearance, _server_vars, _vars, _loadout, [], [], [], [], _group, _revive]] call EPOCH_fnc_server_hiveSETEX; // save community stats _stats = _player getVariable["COMMUNITY_STATS", EPOCH_defaultStatVars]; - _return2 = ["CommunityStats", _playerUID, EPOCH_expiresCommunityStats, [_stats]] call EPOCH_fnc_server_hiveSETEX; - + _return2 = ["CommunityStats", _playerUID, EPOCH_expiresCommunityStats, [_stats]] call EPOCH_fnc_server_hiveSETEX; + // kill player if blood pressure >= 180 if (_vars select 12 >= 180) then { _player setDamage 1;