From 8a76fd23285a26d27fcded6c26f001cb37786fc8 Mon Sep 17 00:00:00 2001 From: He-Man Date: Wed, 15 May 2019 21:35:24 +0200 Subject: [PATCH] Statistics #2 (Server Stats) --- Server_Install_Pack/sc/battleye/scripts.txt | 2 +- .../compile/EPOCH_PlayerStatsDialog.sqf | 16 ++ .../compile/EPOCH_ServerStatsDialog.sqf | 207 ++++++++++++++++++ .../compile/setup/masterLoop/Event1.sqf | 1 + .../compile/setup/masterLoop/init.sqf | 7 +- .../Configs/CfgClientFunctions.hpp | 1 + Sources/epoch_config/Configs/CfgEPad.hpp | 23 ++ .../epoch_config/Configs/CfgEpochClient.hpp | 17 +- .../epoch_player/EPOCH_fnc_savePlayer.sqf | 5 +- .../epoch_player/EPOCH_server_deadPlayer.sqf | 4 +- .../EPOCH_server_updatePlayerStats.sqf | 2 +- .../EPOCH_server_UpdateTopStats.sqf | 59 +++++ Sources/epoch_server/config.cpp | 1 + .../epoch_server/init/server_variables.sqf | 38 ++++ 14 files changed, 376 insertions(+), 7 deletions(-) create mode 100644 Sources/epoch_code/compile/EPOCH_ServerStatsDialog.sqf create mode 100644 Sources/epoch_server/compile/epoch_server/EPOCH_server_UpdateTopStats.sqf diff --git a/Server_Install_Pack/sc/battleye/scripts.txt b/Server_Install_Pack/sc/battleye/scripts.txt index 14ad9b24..44858acb 100644 --- a/Server_Install_Pack/sc/battleye/scripts.txt +++ b/Server_Install_Pack/sc/battleye/scripts.txt @@ -23,7 +23,7 @@ 5 createVehicleLocal !="\"Sign_Arrow_Direction_Yellow_F\" createVehicleLocal" !="\"#particlesource\" createVehicleLocal" !="\"#lightpoint\" createVehicleLocal" !="\"BloodSplat\" createVehicleLocal" !="[\"lightning1_F\", \"lightning2_F\"] call BIS_fnc_selectRandom;\n_lighting = _class createVehicleLocal" !="SLX_XEH_DUMMY createVehicleLocal [0, 0, 0];" !="CBA_eventHandlers = \"Logic\" createVehicleLocal [0, 0];" 5 createUnit !="_driver = _grp createUnit[\"I_UAV_AI\", position _unit, [], 0, \"CAN_COLLIDE\"];" !="axeGeneral = grpVIPGeneral createUnit [\"I_officer_F\", axeGeneralPos, [], 1, \"CAN_COLLIDE\"];" !="bis_functions_mainscope = _grpLogic createunit [\"Logic\",[9,9,9],[],0,\"none\"];" !="_unit = _grp createUnit[selectRandom _arrUnits, _pos, [], 0, \"FORM\"];" !="_driver = (group player) createUnit[\"I_UAV_AI\", position axeUAV, [], 0, \"CAN_COLLIDE\"];" 5 createAgent !="bis_revive_ratioLethal = createAgent [\"Logic\", [10,10,0], [], 0, \"CAN_COLLIDE\"];" !="_unit = createAgent[_unitClass, _targetPos, [], 256, \"FORM\"];" !="_unit = createAgent [_unitClass, _targetPos, [], 120, \"FORM\"];" !="_animal = createAgent[_randomAIClass, _animalPos, [], 5, \"NONE\"];" !="_unit = createAgent [\"Epoch_Cloak_F\", _pos, [], 0, \"CAN_COLLIDE\"];" !="_unit = createAgent [\"Epoch_Sapper_F\", _targetPos, [], 180, \"FORM\"];" !="_sapper = createAgent [\"Epoch_Sapper_F\", getPos _cage2, [], 0, \"FORM\"];" !="_unit = createAgent[_unitClass, position player, [], _zRange, \"FORM\"];" !="_animal = createAgent[_randomAIClass, _animalPos, [], 0, \"CAN_COLLIDE\"];" !="_axeSapper = createAgent [\"Epoch_Sapper_F\", _pos, [], 12, \"FORM\"];" !="_nestMate = createAgent [\"Epoch_Sapper_F\", _garrPos, [], 0, \"FORM\"];" -5 createDialog !="createDialog 'server_info_picture'" !="createdialog 'epoch_tablet_gui'" !="createdialog 'Epoch_CamDialog'" !="createDialog \"rmx_dynamenu\";" !="createDialog \"rmx_craftingUI\";" !="createDialog \"QuickUpgrade\";" !="createDialog \"QuickTake\";" !="createDialog \"InteractBank\";" !="createdialog \"SelectGender\";" !="_handled = createdialog _dialog;" !="if !(createdialog \"InteractItem\") exitWith {};" !="createDialog _tapDiag;" !="if !(createdialog \"Trade\") exitWith {};" !="_ok = createdialog \"Interact\";" !="_ok = createdialog \"TradeNPCMenu\";" !="createDialog \"Epoch_myGroup\";" !="createDialog (if ((Epoch_my_GroupUID == \"\") && (Epoch_my_Group isEqualTo [])) then {\"EPOCH_createGrp\"} else {\"Epoch_myGroup\"});" !="createDialog \"GroupRequests\";" !="_ok = createdialog \"MissionSelect\";" !="createDialog 'Skaronator_AdminMenu';" !="createDialog \"Epoch_myTempGroup\";" !="createDialog (if ((Epoch_my_tempGroupUID == \"\") && (Epoch_my_tempGroup isEqualTo [])) then {\"EPOCH_createTempGrp\"} else {\"Epoch_myTempGroup\"});" !="createDialog \"tempGroupRequests\";" !="createdialog 'EPOCH_SimpleInput';" !="createdialog 'PlayerStatsDialog'" +5 createDialog !="createDialog 'server_info_picture'" !="createdialog 'epoch_tablet_gui'" !="createdialog 'Epoch_CamDialog'" !="createDialog \"rmx_dynamenu\";" !="createDialog \"rmx_craftingUI\";" !="createDialog \"QuickUpgrade\";" !="createDialog \"QuickTake\";" !="createDialog \"InteractBank\";" !="createdialog \"SelectGender\";" !="_handled = createdialog _dialog;" !="if !(createdialog \"InteractItem\") exitWith {};" !="createDialog _tapDiag;" !="if !(createdialog \"Trade\") exitWith {};" !="_ok = createdialog \"Interact\";" !="_ok = createdialog \"TradeNPCMenu\";" !="createDialog \"Epoch_myGroup\";" !="createDialog (if ((Epoch_my_GroupUID == \"\") && (Epoch_my_Group isEqualTo [])) then {\"EPOCH_createGrp\"} else {\"Epoch_myGroup\"});" !="createDialog \"GroupRequests\";" !="_ok = createdialog \"MissionSelect\";" !="createDialog 'Skaronator_AdminMenu';" !="createDialog \"Epoch_myTempGroup\";" !="createDialog (if ((Epoch_my_tempGroupUID == \"\") && (Epoch_my_tempGroup isEqualTo [])) then {\"EPOCH_createTempGrp\"} else {\"Epoch_myTempGroup\"});" !="createDialog \"tempGroupRequests\";" !="createdialog 'EPOCH_SimpleInput';" !="createdialog 'PlayerStatsDialog'" !="'ServerStatsDialog'" 5 createDisplay !="createDisplay \"rmx_dynamenu\";" !="createDisplay \"rmx_moveDynamicHUD\";" !="_parent createdisplay _displayClass;" !="finddisplay 151 createdisplay 'RscDisplayOptionsLayout'" !="_display createdisplay \"RscDisplayDLCPreview\";" 5 deleteMarker !="deleteMarkerLocal _mName;" 5 setMarker !="CBA_fnc_setMarkerPersistent\"" !="\\fnc_setMarkerPersistent" !="\"setMarkerPersistent" !="_mName setMarkerShapeLocal _mShape;" !="_mName setMarkerTypeLocal _mType;" !="(_x select 0) setMarkerPosLocal (position player);" !="_zoomMarker setMarkerSizeLocal" diff --git a/Sources/epoch_code/compile/EPOCH_PlayerStatsDialog.sqf b/Sources/epoch_code/compile/EPOCH_PlayerStatsDialog.sqf index e967c676..e9c8b2ba 100644 --- a/Sources/epoch_code/compile/EPOCH_PlayerStatsDialog.sqf +++ b/Sources/epoch_code/compile/EPOCH_PlayerStatsDialog.sqf @@ -1,5 +1,21 @@ +/* + Author: He-Man - EpochMod.com + + Contributors: + + Description: + Fill Player Stats Dialog + + 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_code/compile/EPOCH_PlayerStatsDialog.sqf +*/ +private ["_display","_UsedStats","_ctrlNo","_txt","_value"]; disableSerialization; _display = findDisplay -1200; +if (isnull _display) exitwith {}; _UsedStats = ["CfgEpochClient", "PlayerStatsDialogEntries", []] call EPOCH_fnc_returnConfigEntryV2; _ctrlNo = 1100; { diff --git a/Sources/epoch_code/compile/EPOCH_ServerStatsDialog.sqf b/Sources/epoch_code/compile/EPOCH_ServerStatsDialog.sqf new file mode 100644 index 00000000..e983db30 --- /dev/null +++ b/Sources/epoch_code/compile/EPOCH_ServerStatsDialog.sqf @@ -0,0 +1,207 @@ +/* + Author: He-Man - EpochMod.com + + Contributors: + + Description: + Fill Server Stats Dialog + + 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_code/compile/EPOCH_ServerStatsDialog.sqf +*/ + +private [ + "_display","_UsedStats","_Stat1Pos","_MainDistX","_MainDistY","_SubDistX1","_SubDistX2","_SubDistY1","_SubDistY2","_MainWidth","_SubWidth1","_SubWidth2","_SubWidth3", + "_MainHeight","_SubHeight","_ZeroX","_ZeroY","_c","_posX","_posY","_ListedStats","_ctrl","_SubPosY","_ImIn","_SubPosX" +]; + +disableSerialization; +_display = findDisplay -1200; +if (isnull _display) exitwith {}; +_UsedStats = ["CfgEpochClient", "TopStatsDialogEntries", []] call EPOCH_fnc_returnConfigEntryV2; +_Stat1Pos = [ + 0.0720312 * safezoneW + safezoneX, + 0.071 * safezoneH + safezoneY, + 0.134062 * safezoneW, + 0.033 * safezoneH + ]; +_MainDistX = 0.216406-0.0720312; +_MainDistY = 0.489-0.071; +_SubDistX1 = 0.0926562-0.0720312; +_SubDistX2 = 0.175156-0.0926562; +_SubDistY1 = 0.115-0.071; +_SubDistY2 = 0.148-0.115-0.002; +_MainWidth = 0.134062; +_SubWidth1 = 0.0154688; +_SubWidth2 = 0.0773437; +_SubWidth3 = 0.0309375; +_MainHeight = 0.033; +_SubHeight = 0.022; + +_ZeroX = 0.0720312; +_ZeroY = 0.071; + + +_c = 1; +_posX = _ZeroX; +_posY = _ZeroY; +_ListedStats = []; +{ + _x params ["_stattype","_entrytext",["_calc","%1"]]; + _ctrl = _display ctrlCreate['RscText', -1]; + _ctrl ctrlSetPosition [ + -_MainWidth * safezoneW + safezoneX, + _posY * safezoneH + safezoneY, + _MainWidth * safezoneW, + _MainHeight * safezoneH + ]; + _ctrl ctrlSetText _entrytext; + _ctrl ctrlsetbackgroundcolor [0.02,0,0.03,0.6]; + _ctrl ctrlsetTextColor [1,1,0,1]; + _ctrl ctrlCommit 0; + _ctrl ctrlSetPosition [ + _posX * safezoneW + safezoneX, + _posY * safezoneH + safezoneY + ]; + _ctrl ctrlCommit 0.02; + _SubPosY = _posY+_SubDistY1; + _ImIn = false; + { + _x params ["_value","_UID","_name"]; + _SubPosX = _posX; + _ctrl = _display ctrlCreate['RscText', -1]; + _ctrl ctrlSetPosition [ + -_MainWidth * safezoneW + safezoneX, + _SubPosY * safezoneH + safezoneY, + _SubWidth1 * safezoneW, + _SubHeight * safezoneH + ]; + _ctrl ctrlCommit 0; + _ctrl ctrlSetText str (_foreachindex + 1); + _ctrl ctrlsetbackgroundcolor [0.02,0,0.03,0.6]; + _ctrl ctrlSetPosition [ + _SubPosX * safezoneW + safezoneX, + _SubPosY * safezoneH + safezoneY + ]; + _ctrl ctrlCommit 0.02; + _SubPosX = _SubPosX + _SubDistX1; + _ctrl = _display ctrlCreate['RscText', -1]; + _ctrl ctrlSetPosition [ + -_MainWidth * safezoneW + safezoneX, + _SubPosY * safezoneH + safezoneY, + _SubWidth2 * safezoneW, + _SubHeight * safezoneH + ]; + _ctrl ctrlCommit 0; + _ctrl ctrlSetText _name; + if ((_x select 1) isequalto (getplayeruid player)) then { + _ctrl ctrlsetTextColor [0,1,0,1]; + _ImIn = true; + }; + _ctrl ctrlsetbackgroundcolor [0.02,0,0.03,0.6]; + _ctrl ctrlSetPosition [ + _SubPosX * safezoneW + safezoneX, + _SubPosY * safezoneH + safezoneY + ]; + _ctrl ctrlCommit 0.02; + _SubPosX = _SubPosX + _SubDistX2; + _ctrl = _display ctrlCreate['RscText', -1]; + _ctrl ctrlSetPosition [ + -_MainWidth * safezoneW + safezoneX, + _SubPosY * safezoneH + safezoneY, + _SubWidth3 * safezoneW, + _SubHeight * safezoneH + ]; + _value = format [_calc,_value]; + _value = call compile _value; + if (_value isEqualType "") then { + _ctrl ctrlSetText _value; + } + else { + _ctrl ctrlSetText str _value; + }; + _ctrl ctrlsetbackgroundcolor [0.02,0,0.03,0.6]; + _ctrl ctrlCommit 0; + _ctrl ctrlSetPosition [ + _SubPosX * safezoneW + safezoneX, + _SubPosY * safezoneH + safezoneY + ]; + _ctrl ctrlCommit 0.015; + waituntil {ctrlCommitted _ctrl}; + _SubPosY = _SubPosY+_SubDistY2; + } foreach (EPOCH_Topstats select _foreachindex); + if (!_ImIn) then { + _SubPosX = _posX; + _ctrl = _display ctrlCreate['RscText', -1]; + _ctrl ctrlSetPosition [ + -_MainWidth * safezoneW + safezoneX, + _SubPosY * safezoneH + safezoneY, + _SubWidth1 * safezoneW, + _SubHeight * safezoneH + ]; + _ctrl ctrlCommit 0; + _ctrl ctrlSetText '#'; + _ctrl ctrlsetbackgroundcolor [0.02,0,0.03,0.6]; + _ctrl ctrlSetPosition [ + _SubPosX * safezoneW + safezoneX, + _SubPosY * safezoneH + safezoneY + ]; + _ctrl ctrlCommit 0.02; + _SubPosX = _SubPosX + _SubDistX1; + _ctrl = _display ctrlCreate['RscText', -1]; + _ctrl ctrlSetPosition [ + -_MainWidth * safezoneW + safezoneX, + _SubPosY * safezoneH + safezoneY, + _SubWidth2 * safezoneW, + _SubHeight * safezoneH + ]; + _ctrl ctrlCommit 0; + _txt = name player; + _ctrl ctrlSetText _txt; + _ctrl ctrlsetTextColor [0,1,0,1]; + _ctrl ctrlsetbackgroundcolor [0.02,0,0.03,0.6]; + _ctrl ctrlSetPosition [ + _SubPosX * safezoneW + safezoneX, + _SubPosY * safezoneH + safezoneY + ]; + _ctrl ctrlCommit 0.02; + _SubPosX = _SubPosX + _SubDistX2; + _ctrl = _display ctrlCreate['RscText', -1]; + _ctrl ctrlSetPosition [ + -_MainWidth * safezoneW + safezoneX, + _SubPosY * safezoneH + safezoneY, + _SubWidth3 * safezoneW, + _SubHeight * safezoneH + ]; + _value = missionNamespace getVariable [format ['Epoch_total%1',_stattype],0]; + _value = format [_calc,_value]; + _value = call compile _value; + if (_value isEqualType "") then { + _ctrl ctrlSetText _value; + } + else { + _ctrl ctrlSetText str _value; + }; + _ctrl ctrlsetbackgroundcolor [0.02,0,0.03,0.6]; + _ctrl ctrlCommit 0; + _ctrl ctrlSetPosition [ + _SubPosX * safezoneW + safezoneX, + _SubPosY * safezoneH + safezoneY + ]; + _ctrl ctrlCommit 0.02; + waituntil {ctrlCommitted _ctrl}; + _SubPosY = _SubPosY+_SubDistY2; + }; + _c = _c + 1; + if (_c > 6) then { + _posX = _ZeroX; + _posY = _posY+_MainDistY; + _c = 1; + } + else { + _posX = _posX+_MainDistX; + }; +} foreach _UsedStats; diff --git a/Sources/epoch_code/compile/setup/masterLoop/Event1.sqf b/Sources/epoch_code/compile/setup/masterLoop/Event1.sqf index 921e6f5b..0bf94211 100644 --- a/Sources/epoch_code/compile/setup/masterLoop/Event1.sqf +++ b/Sources/epoch_code/compile/setup/masterLoop/Event1.sqf @@ -436,6 +436,7 @@ if (lifeState player == "INCAPACITATED") then { // force update if (EPOCH_forceUpdateNow) then { + _UpdateTopStats = true; _forceUpdate = false; EPOCH_forceUpdate = false; EPOCH_forceUpdateNow = false; diff --git a/Sources/epoch_code/compile/setup/masterLoop/init.sqf b/Sources/epoch_code/compile/setup/masterLoop/init.sqf index b73926f6..d078abb2 100644 --- a/Sources/epoch_code/compile/setup/masterLoop/init.sqf +++ b/Sources/epoch_code/compile/setup/masterLoop/init.sqf @@ -99,9 +99,10 @@ _fnc_forceUpdate = { ["WalkDist",round _TotalWalkDist,true], ["MaxAliveTime",_MaxAliveTime,true], ["PlayTime", round _PlayTime, true], - ["LootedObjs",missionnamespace getvariable ["EPOCH_totalLootedObjs",0], true] + ["PublicStats",missionnamespace getvariable ["EPOCH_totalPublicStats",1], true] ]; - [player,_customVars,Epoch_personalToken,_stats] remoteExec ["EPOCH_fnc_savePlayer",2]; + [player,_customVars,Epoch_personalToken,_stats,_UpdateTopStats] remoteExec ["EPOCH_fnc_savePlayer",2]; + _UpdateTopStats = false; }; // disable fuel sources client side. @@ -233,6 +234,8 @@ _TotalWalkDist = missionnamespace getvariable ["EPOCH_totalWalkDist",0]; _MaxAliveTime = missionnamespace getvariable ["EPOCH_totalMaxAliveTime",0]; _PlayTime = missionnamespace getvariable ["EPOCH_totalPlayTime",0]; _PlayTimeTimer = diag_ticktime; +_UpdateTopStats = false; +EPOCH_MyStatsPublic = !((missionnamespace getvariable ["EPOCH_totalPublicStats",1]) isEqualTo 0); _pushbacklootedbld = { private ["_lootCheckBufferLimit"]; diff --git a/Sources/epoch_config/Configs/CfgClientFunctions.hpp b/Sources/epoch_config/Configs/CfgClientFunctions.hpp index 48a1b089..19cb3387 100644 --- a/Sources/epoch_config/Configs/CfgClientFunctions.hpp +++ b/Sources/epoch_config/Configs/CfgClientFunctions.hpp @@ -55,6 +55,7 @@ class CfgClientFunctions class CamUse {}; class DefuseBomb {}; class PlayerStatsDialog {}; + class ServerStatsDialog {}; }; class building { diff --git a/Sources/epoch_config/Configs/CfgEPad.hpp b/Sources/epoch_config/Configs/CfgEPad.hpp index f5e85bd7..ad64e9c1 100644 --- a/Sources/epoch_config/Configs/CfgEPad.hpp +++ b/Sources/epoch_config/Configs/CfgEPad.hpp @@ -113,6 +113,17 @@ class e_pad_config ToggleVar = "EPOCH_AutoEarplug"; ToggleAble = "true"; }; + class PublicStats { + ButtonText = ""; + Description = "Public Stats"; + icon = "x\addons\a3_epoch_code\Data\UI\epad\ServerStats.paa"; + color[] = {1,0,0,1}; + colortoggled[] = {0,1,0,1}; + action = "EPOCH_totalPublicStats = if (EPOCH_MyStatsPublic) then {0} else {1};EPOCH_forceUpdateNow = true"; + Tooltip = "Enable / Disable your Stats in Server Stats"; + ToggleVar = "EPOCH_MyStatsPublic"; + ToggleAble = "true"; + }; class Reset { ButtonText = "Reset"; Description = "Reset Settings"; @@ -297,5 +308,17 @@ class e_pad_config ToggleVar = ""; ToggleAble = "false"; }; + class ServerStats + { + ButtonText = ""; + Description = "Server Statistic"; + icon = "x\addons\a3_epoch_code\Data\UI\epad\ServerStats.paa"; + color[] = {1,1,1,1}; + colortoggled[] = {0,1,0,1}; + action = "if (isnull (finddisplay -1200)) then {createdialog 'ServerStatsDialog'};"; + Tooltip = "Server Statistic"; + ToggleVar = ""; + ToggleAble = "false"; + }; }; }; \ No newline at end of file diff --git a/Sources/epoch_config/Configs/CfgEpochClient.hpp b/Sources/epoch_config/Configs/CfgEpochClient.hpp index fe6e69b6..b42ddcb7 100644 --- a/Sources/epoch_config/Configs/CfgEpochClient.hpp +++ b/Sources/epoch_config/Configs/CfgEpochClient.hpp @@ -204,13 +204,14 @@ class CfgEpochClient {"ConnectCount",0,{}}, {"BuildingsSet",0,{}}, {"AIDeaths",0,{}}, + {"PublicStats",1,{}} // DO not change this! Players can disable it within the E-Pad by themself! }; PlayerStatsDialogEntries[] = { { {"ConnectCount","Times connected"}, {"PlayTime","Playtime (hours)","%1/3600 toFixed 2"}, {"MaxAliveTime","Max Alivetime (hours)","%1/3600 toFixed 2"}, - {"Walkdist","Distance Walked (Km)","%1/1000 toFixed 2"} + {"WalkDist","Distance Walked (Km)","%1/1000 toFixed 2"} }, { {"LootedObjs","Objects Looted"}, @@ -238,6 +239,20 @@ class CfgEpochClient {"","K/D PvP","(Epoch_totalMurders/(Epoch_totalDeaths max 1)) toFixed 1"}, {"","K/D PvE","(Epoch_totalAIKills/(Epoch_totalAIDeaths max 1)) toFixed 1"} } + }; + TopStatsDialogEntries[] = { + {"PlayTime","Playtime (hours)","%1/3600 toFixed 2"}, + {"MaxAliveTime","Max Alivetime (hours)","%1/3600 toFixed 2"}, + {"WalkDist","Distance Walked (Km)","%1/1000 toFixed 2"}, + {"LootedObjs","Objects Looted"}, + {"NPCTrades","Trades at Trader"}, + {"BuildingsSet","Placed Buildings"}, + {"CraftedItems","Crafted Items"}, + {"Karma","Karma"}, + {"Murders","Player Kills"}, + {"AIKills","AI Kills"}, + {"Deaths","Deaths by Player"}, + {"AIDeaths","Deaths by AI"} }; group_upgrade_lvl[] = {4,"1000",6,"1500",8,"2000",10,"2500",12,"3000",14,"3500",16,"4000",32,"8000",64,"16000"}; // controls max group limit and cost // Event handler code diff --git a/Sources/epoch_server/compile/epoch_player/EPOCH_fnc_savePlayer.sqf b/Sources/epoch_server/compile/epoch_player/EPOCH_fnc_savePlayer.sqf index 952ed234..55740043 100644 --- a/Sources/epoch_server/compile/epoch_player/EPOCH_fnc_savePlayer.sqf +++ b/Sources/epoch_server/compile/epoch_player/EPOCH_fnc_savePlayer.sqf @@ -12,11 +12,14 @@ Github: https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_server/compile/epoch_player/EPOCH_fnc_savePlayer.sqf */ -params ["_player","",["_token","",[""]],["_stats",[]]]; +params ["_player","",["_token","",[""]],["_stats",[]],["_UpdateTopStats",false]]; if([_player,_token] call EPOCH_server_getPToken)then{ { _x params ["_statType","_adjust","_isTotal"]; [_player, _statType, _adjust, false,_isTotal] call Epoch_server_updatePlayerStats; } foreach _stats; + if (_UpdateTopStats) then { + [_player, _player getVariable["COMMUNITY_STATS", []] ] call EPOCH_server_UpdateTopStats; + }; _this call EPOCH_server_savePlayer; }; diff --git a/Sources/epoch_server/compile/epoch_player/EPOCH_server_deadPlayer.sqf b/Sources/epoch_server/compile/epoch_player/EPOCH_server_deadPlayer.sqf index 060d71ab..925348ac 100644 --- a/Sources/epoch_server/compile/epoch_player/EPOCH_server_deadPlayer.sqf +++ b/Sources/epoch_server/compile/epoch_player/EPOCH_server_deadPlayer.sqf @@ -118,7 +118,9 @@ if (_current_crypto > 0) then{ }; // save community stats (skipped in EPOCH_server_savePlayer for dead Players) -["CommunityStats", _playerUID, EPOCH_expiresCommunityStats, [_playerObj getVariable["COMMUNITY_STATS", EPOCH_defaultStatVars]]] call EPOCH_fnc_server_hiveSETEX; +_stats = _playerObj getVariable["COMMUNITY_STATS", EPOCH_defaultStatVars]; +["CommunityStats", _playerUID, EPOCH_expiresCommunityStats, [_stats]] call EPOCH_fnc_server_hiveSETEX; +[_playerObj,_stats] call EPOCH_server_UpdateTopStats; [_playerObj, _defaultVars] call EPOCH_server_savePlayer; diff --git a/Sources/epoch_server/compile/epoch_player/EPOCH_server_updatePlayerStats.sqf b/Sources/epoch_server/compile/epoch_player/EPOCH_server_updatePlayerStats.sqf index 475d7839..c07d30b1 100644 --- a/Sources/epoch_server/compile/epoch_player/EPOCH_server_updatePlayerStats.sqf +++ b/Sources/epoch_server/compile/epoch_player/EPOCH_server_updatePlayerStats.sqf @@ -39,7 +39,7 @@ if(isNull _playerObj)exitWith{ if(_statType isEqualTo "")exitWith{ diag_log "EPOCHDebug: playerUpdateStats -2- stat type not defined"; }; -if(_adjust isEqualTo 0)exitWith{ +if(_adjust isEqualTo 0 && !_isTotal)exitWith{ diag_log "EPOCHDebug: playerUpdateStats -3- stat adjustment is 0"; }; _playerUID = getplayerUID _playerObj; diff --git a/Sources/epoch_server/compile/epoch_server/EPOCH_server_UpdateTopStats.sqf b/Sources/epoch_server/compile/epoch_server/EPOCH_server_UpdateTopStats.sqf new file mode 100644 index 00000000..28579b47 --- /dev/null +++ b/Sources/epoch_server/compile/epoch_server/EPOCH_server_UpdateTopStats.sqf @@ -0,0 +1,59 @@ +/* + Author: He-Man - EpochMod.com + + Contributors: + + Description: + Update Server TopStats + + 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_server/EPOCH_server_UpdateTopStats.sqf +*/ + + +private ["_playername","_playeruid","_makepublic","_publicindex","_tempStats","_ThisStatArr","_playerisin","_idx","_playerValue"]; +params [['_player',ObjNull],['_vars',[]]]; +_playername = name _player; +_playeruid = getplayeruid _player; +if !((_playerUID isequalto '') || (_vars isequalto [])) then { + _makepublic = 1; + _publicindex = EPOCH_communityStats find 'PublicStats'; + if !(_publicindex isequalto -1) then { + _makepublic = _vars select _publicindex; + }; + _tempStats = EPOCH_TopStats; + { + _ThisStatArr = _x; + _playerisin = false; + _idx = EPOCH_communityStats find (EPOCH_TopStatsVars select _foreachindex); + if (_idx > -1) then { + _playerValue = _vars select _idx; + { + _x params ["_value","_UID","_name"]; + if (_UID isequalto _playerUID) exitwith { + _playerisin = true; + if (_makepublic isEqualTo 0) exitwith { + _ThisStatArr deleteat _foreachindex; + }; + if !(_value isequalto _playerValue) then { + _x set [0,_playerValue]; + _x set [2,_playername]; + }; + }; + } foreach _x; + if (!_playerisin && (_makepublic > 0)) then { + _x pushback [(_vars select _idx),_playerUID,_playername]; + }; + _x sort false; + if (count _x > 10) then { + _x resize 10; + }; + }; + } foreach _tempStats; + EPOCH_TopStats = _tempStats; + ["CommunityStats", "0_TopStats", EPOCH_expiresCommunityStats, EPOCH_TopStats] call EPOCH_fnc_server_hiveSETEX; + publicvariable "EPOCH_TopStats"; +}; diff --git a/Sources/epoch_server/config.cpp b/Sources/epoch_server/config.cpp index e4e9e2dc..a3428d34 100644 --- a/Sources/epoch_server/config.cpp +++ b/Sources/epoch_server/config.cpp @@ -131,6 +131,7 @@ class CfgServerFunctions class server_isNearChecks {}; class server_DefuseBomb {}; class server_PutCrypto {}; + class server_UpdateTopStats{}; }; class epoch_missions { class Server_createObject {}; diff --git a/Sources/epoch_server/init/server_variables.sqf b/Sources/epoch_server/init/server_variables.sqf index dfab6524..17258283 100644 --- a/Sources/epoch_server/init/server_variables.sqf +++ b/Sources/epoch_server/init/server_variables.sqf @@ -100,3 +100,41 @@ private _serverSettingsConfig = configFile >> "CfgEpochServer"; (EPOCH_starterTraderItems select 1) set [_foreachindex, _currentStock]; }; } foreach (EPOCH_starterTraderItems select 0); + +// Load / Build Top-Statistics +_TopStatsVarsDb = (['CommunityStats', '0_TopStatsVars'] call EPOCH_fnc_server_hiveGETRANGE) param [1,[]]; +_TopStatsDb = (['CommunityStats', '0_TopStats'] call EPOCH_fnc_server_hiveGETRANGE) param [1,[]]; +EPOCH_TopStatsVars = (["CfgEpochClient", "TopStatsDialogEntries", []] call EPOCH_fnc_returnConfigEntryV2) apply {_x param [0,""]}; +EPOCH_TopStats = []; +{ + _added1 = false; + if (count _TopStatsVarsDb >= _foreachindex) then { + if (_x isEqualTo (_TopStatsVarsDb select _foreachindex)) then { + if (count _TopStatsDb >= _foreachindex) then { + _newstats2 = []; + { + _x params ["_value","_UID","_name"]; + _communityStats = ((["CommunityStats", _UID] call EPOCH_fnc_server_hiveGETRANGE) param [1,[]]) param [0,[]]; + if !(_communityStats isequalto []) then { + _name = "Unknown"; + _array = (['PlayerData', _UID] call EPOCH_fnc_server_hiveGETRANGE) param [1,[]]; + if !(_array isequalto []) then { + _name = _array select 0; + }; + _newstats2 pushback [_value,_UID,_name]; + }; + } foreach (_TopStatsDb select _foreachindex); + EPOCH_TopStats pushback _newstats2; + _added1 = true; + }; + }; + }; + if (!_added1) then { + EPOCH_TopStats pushback []; + }; +} foreach EPOCH_TopStatsVars; +if !(EPOCH_TopStatsVars isEqualTo _TopStatsVarsDb) then { + ["CommunityStats", "0_TopStatsVars", EPOCH_expiresCommunityStats, EPOCH_TopStatsVars] call EPOCH_fnc_server_hiveSETEX; +}; +publicvariable "EPOCH_TopStats"; +publicvariable "EPOCH_TopStatsVars";