Advertisement
Guest User

server_playerLogin.sqf

a guest
Apr 29th, 2014
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.51 KB | None | 0 0
  1. private ["_res","_isInfected","_doLoop","_hiveVer","_isHiveOk","_playerID","_playerObj","_primary","_key","_charID","_playerName","_backpack","_isNew","_inventory","_survival","_model","_mags","_wpns","_bcpk","_config","_newPlayer"];
  2.  
  3. #ifdef DZE_SERVER_DEBUG
  4. diag_log ("STARTING LOGIN: " + str(_this));
  5. #endif
  6.  
  7. _playerID = _this select 0;
  8. _playerObj = _this select 1;
  9. _playerName = name _playerObj;
  10.  
  11. if (_playerName == '__SERVER__' || _playerID == '' || local player) exitWith {};
  12.  
  13. if (isNil "sm_done") exitWith {
  14. #ifdef DZE_SERVER_DEBUG
  15.     diag_log ("Login cancelled, server is not ready. " + str(_playerObj));
  16. #endif
  17. };
  18.  
  19. if (count _this > 2) then {
  20.     dayz_players = dayz_players - [_this select 2];
  21. };
  22.  
  23. //Variables
  24. _inventory =    [];
  25. _backpack =     [];
  26. _survival =     [0,0,0];
  27. _isInfected =   0;
  28. _model =        "";
  29.  
  30. if (_playerID == "") then {
  31.     _playerID = getPlayerUID _playerObj;
  32. };
  33.  
  34. if ((_playerID == "") or (isNil "_playerID")) exitWith {
  35. #ifdef DZE_SERVER_DEBUG
  36.     diag_log ("LOGIN FAILED: Player [" + _playerName + "] has no login ID");
  37. #endif
  38. };
  39.  
  40. #ifdef DZE_SERVER_DEBUG
  41. diag_log ("LOGIN ATTEMPT: " + str(_playerID) + " " + _playerName);
  42. #endif
  43.  
  44. //Do Connection Attempt
  45. _doLoop = 0;
  46. while {_doLoop < 5} do {
  47.     _key = format["CHILD:101:%1:%2:%3:",_playerID,dayZ_instance,_playerName];
  48.     diag_log (_key);
  49.         _key = format["\cache\players\%1\%2.sqf", MyPlayerCounter, _playerID];
  50.         diag_log ("LOAD PLAYER: "+_key);
  51.         _res = preprocessFile _key;
  52.         diag_log ("PLAYER CACHE: "+_res);
  53.  
  54.         if ((_res == "") or (isNil "_res")) then {
  55.             _key = format["\cache\players\%1\%2.sqf", (MyPlayerCounter - 1), _playerID];
  56.             diag_log ("BACKLOAD PLAYER: "+_key);
  57.             _res = preprocessFile _key;
  58.             diag_log ("PLAYER CACHE: "+_res);
  59.         };
  60.         if ((_res == "") or (isNil "_res")) then {
  61.             _res = preprocessFile "\cache\players\default.sqf";
  62.             diag_log ("PLAYER DEFAULT CACHE: "+_res);
  63.             if ((_res == "") or (isNil "_res")) then {            
  64.             _primary = ["PASS",false,"1",[],[["ItemFlashlight","ItemMap","ItemGPS"],["ItemBandage"]],["DZ_Patrol_Pack_EP1",[],[]],[0,0,0],"Survivor2_DZ",0.96];
  65.             } else {  
  66.                 _primary = call compile _res;
  67.             };
  68.         } else {
  69.             _primary = call compile _res;
  70.         };
  71.         _res = nil;
  72.    
  73.         MyPlayerCounter = MyPlayerCounter + 1;
  74.         diag_log format["CHILD:11:%1:", MyPlayerCounter];
  75.  
  76.     if (count _primary > 0) then {
  77.         if ((_primary select 0) != "ERROR") then {
  78.             _doLoop = 9;
  79.         };
  80.     };
  81.     _doLoop = _doLoop + 1;
  82. };
  83.  
  84. if (isNull _playerObj or !isPlayer _playerObj) exitWith {
  85. #ifdef DZE_SERVER_DEBUG
  86.     diag_log ("LOGIN RESULT: Exiting, player object null: " + str(_playerObj));
  87. #endif
  88. };
  89.  
  90. if ((_primary select 0) == "ERROR") exitWith {
  91. #ifdef DZE_SERVER_DEBUG
  92.     diag_log format ["LOGIN RESULT: Exiting, failed to load _primary: %1 for player: %2 ",_primary,_playerID];
  93. #endif
  94. };
  95.  
  96. //Process request
  97. _newPlayer =    _primary select 1;
  98. ////////// jahan
  99. //////////_isNew =      count _primary < 7; //_result select 1;
  100. _isNew = true;
  101. _isNew =        count (_primary select 3) < 1;
  102. _charID =       _primary select 2;
  103.  
  104. #ifdef DZE_SERVER_DEBUG
  105. diag_log ("LOGIN RESULT: " + str(_primary));
  106. #endif
  107.  
  108. /* PROCESS */
  109. _hiveVer = 0;
  110.  
  111. if (!_isNew) then {
  112.     //RETURNING CHARACTER      
  113.     _inventory =    _primary select 4;
  114.     _backpack =     _primary select 5;
  115.     _survival =     _primary select 6;
  116.     _model =        _primary select 7;
  117.     _hiveVer =      _primary select 8;
  118.    
  119.     if (!(_model in AllPlayers)) then {
  120.         _model = "Survivor2_DZ";
  121.     };
  122.    
  123. } else {
  124.     ////////// jahan: no column infected in character_DATA / should be added?
  125.     /*
  126.     if (DZE_PlayerZed) then {
  127.         _isInfected = _primary select 3;
  128.     } else {
  129.         _isInfected = 0;
  130.     };
  131.     */
  132.     _isInfected = 0;
  133.     ////////// jahan
  134.     //////////_model =      _primary select 4;
  135.     //////////_hiveVer =    _primary select 5;
  136.     _model =        _primary select 7;
  137.     _hiveVer =      _primary select 8;
  138.    
  139.     if (isNil "_model") then {
  140.         _model = "Survivor2_DZ";
  141.     } else {
  142.         if (_model == "") then {
  143.             _model = "Survivor2_DZ";
  144.         };
  145.     };
  146.  
  147.    
  148.     //Record initial inventory only if not player zombie (values defined in init.sqf)
  149.     if(_isInfected != 1) then {
  150.         _config = (configFile >> "CfgSurvival" >> "Inventory" >> "Default");
  151.         _mags = getArray (_config >> "magazines");
  152.         _wpns = getArray (_config >> "weapons");
  153.         _bcpk = getText (_config >> "backpack");
  154.  
  155.         if(!isNil "DefaultMagazines") then {
  156.             _mags = DefaultMagazines;
  157.         };
  158.         if(!isNil "DefaultWeapons") then {
  159.             _wpns = DefaultWeapons;
  160.         };
  161.         if(!isNil "DefaultBackpack") then {
  162.             _bcpk = DefaultBackpack;
  163.         };
  164.         //_randomSpot = true;
  165.    
  166.         //Wait for HIVE to be free
  167.         diag_log format["CHILD:203:%1:%2:%3:",_charID,[_wpns,_mags],[_bcpk,[],[]]];
  168.     };
  169. };
  170.  
  171. #ifdef DZE_SERVER_DEBUG
  172. diag_log ("LOGIN LOADED: " + str(_playerObj) + " Type: " + (typeOf _playerObj) + " at location: " + (getPosATL _playerObj));
  173. #endif
  174.  
  175. _isHiveOk = false;
  176. if (_hiveVer >= dayz_hiveVersionNo) then {
  177.     _isHiveOk = true;
  178. };
  179.  
  180. if (worldName == "chernarus") then {
  181.     ([4654,9595,0] nearestObject 145259) setDamage 1;
  182.     ([4654,9595,0] nearestObject 145260) setDamage 1;
  183. };
  184.  
  185. ////////// jahan
  186. //////////diag_log (format["IsNew: %1",_isNew]);
  187. //////////diag_log (format["IsInfected: %1",_isInfected]);
  188.  
  189. dayzPlayerLogin = [_charID,_inventory,_backpack,_survival,_isNew,dayz_versionNo,_model,_isHiveOk,_newPlayer,_isInfected];
  190. (owner _playerObj) publicVariableClient "dayzPlayerLogin";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement