Guest User

Untitled

a guest
Jul 4th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.15 KB | None | 0 0
  1. Authenticate = {
  2.  
  3. Client = nil,
  4. User = false,
  5. Pass = false,
  6. retCode = 0,
  7.  
  8. IsValid = false,
  9. UserId = 0,
  10. UserGroup = 0,
  11. OtherGroups = ""
  12.  
  13. };
  14.  
  15. Authenticate.__index = Authenticate;
  16.  
  17.  
  18.  
  19. function Authenticate:new( o )
  20.  
  21. o = o or { };
  22. setmetatable( o, self );
  23. self.__index = self;
  24. return o;
  25.  
  26. end
  27.  
  28. function Authenticate:OnAuthResult( ... )
  29.  
  30. local result = arg[1];
  31. local userId = arg[2];
  32. local userGroup = arg[3];
  33. local otherGroups = arg[4];
  34.  
  35. if( result == "ERROR" ) then
  36.  
  37. self.retCode = 0;
  38. outputDebugString( "OnAuthResult: Errorcode: " .. userId .. get( "#AUTH_SERVER" ) .. get( "#AUTH_FILE" ), 1 );
  39.  
  40. else
  41.  
  42. -- outputDebugString( "Authenticate:OnAuthResult( " .. #arg .. ", " .. tostring( userId ) .. ", " .. tostring( userGroup ) .. ", " .. tostring( otherGroups ) .. ")", 1 );
  43. self.retCode = 1;
  44. self.IsValid = ( result == "true" );
  45. self.UserId = tonumber( userId );
  46. self.UserGroup = tonumber( userGroup );
  47. self.OtherGroups = otherGroups;
  48.  
  49. end
  50. self:DoAuthStuff( );
  51.  
  52. end
  53.  
  54. function Authenticate:CheckUserGroups( )
  55.  
  56. local adminLevel = 0;
  57.  
  58. if( self.UserGroup == 8 ) then -- vbull banned group
  59.  
  60. self.retCode = 0; -- Return error...
  61. return;
  62.  
  63. elseif( self.UserGroup == 6 ) then -- vbull Admin
  64.  
  65. adminLevel = 2;
  66.  
  67. elseif( self.UserGroup == 12 or self.UserGroup == 7 ) then -- vbull dev / mode
  68.  
  69. adminLevel = 1;
  70.  
  71. end
  72.  
  73. if( adminLevel > 0 ) then -- vbull admin group
  74.  
  75. local account = getAccount( self.User );
  76. local pass = self.Pass;
  77.  
  78. if( account == false ) then
  79.  
  80. account = addAccount( self.User, pass );
  81.  
  82. if( account ~= false ) then
  83.  
  84. if( adminLevel == 2 ) then
  85.  
  86. aclGroupAddObject( aclGetGroup( "Admin" ), "user." .. self.User );
  87.  
  88. else
  89.  
  90. aclGroupAddObject( aclGetGroup( "Moderator" ), "user." .. self.User );
  91.  
  92. end
  93.  
  94. end
  95.  
  96. end
  97.  
  98. if( account ~= false ) then
  99.  
  100. setAccountPassword( account, pass );
  101. logIn( self.Client, account, pass );
  102.  
  103. else
  104.  
  105. outputChatBox( "Adminiks/Modeks seadmisega oli mingi jama. (" .. self.User .. "->" .. self.Pass .. ")", self.Client );
  106.  
  107. end
  108.  
  109. setElementData( self.Client, "User.AdminLevel", adminLevel, true );
  110.  
  111. end
  112.  
  113. setElementData( self.Client, "User.GroupId", self.UserGroup, true );
  114.  
  115. end
  116.  
  117. function Authenticate:DoAuthStuff( )
  118.  
  119. local theMessage = "Ei saanud ühendust autentimisserveriga.";
  120.  
  121. if( self.retCode == 1 ) then -- No Response from auth server...
  122.  
  123. if( not self.IsValid ) then
  124.  
  125. self.retCode = 0;
  126. theMessage = "Vale Kasutajanimi/Parool!";
  127.  
  128. else
  129.  
  130. self:CheckUserGroups( );
  131.  
  132. if( self.retCode == 0 ) then
  133.  
  134. theMessage = "See kasutaja on bannitud!";
  135.  
  136. elseif( self.UserId ~= 0 and self.retCode == 1 ) then
  137.  
  138. setElementData( self.Client, "User.userid", self.UserId, true );
  139. theMessage = "Sisse logitud";
  140.  
  141. else
  142.  
  143. self.retCode = 0;
  144. string.format( theMessage, "Tundmatu viga! retCode: %d, userid: %d", self.retCode, self.UserId);
  145.  
  146. end
  147.  
  148. end
  149.  
  150. end
  151.  
  152. triggerClientEvent( self.Client, "OnPlayerLogin", self.Client, self.retCode, theMessage );
  153.  
  154. end
  155.  
  156. function Authenticate:DoAuth( )
  157.  
  158. theSelf = self;
  159.  
  160. callRemote ( get( "#AUTH_SERVER" ) .. "/" .. get( "#AUTH_FILE" ),
  161. function ( ... )
  162.  
  163. theSelf:OnAuthResult( ... );
  164.  
  165. end
  166. , self.User, self.Pass );
  167.  
  168. end
  169.  
  170. function Authenticate:encode( str )
  171.  
  172. local nStr = "";
  173.  
  174. for letter in string.gmatch( str, "." ) do
  175.  
  176. nStr = nStr .. string.char( string.byte( letter ) + 133 );
  177.  
  178. end
  179.  
  180. return nStr;
  181.  
  182. end
  183.  
  184. function Authenticate:decode( str )
  185.  
  186. local nStr = "";
  187.  
  188. for letter in string.gmatch( str, "." ) do
  189.  
  190. nStr = nStr .. string.char( string.byte( letter ) - 133 );
  191.  
  192. end
  193.  
  194. return nStr;
  195.  
  196. end
Add Comment
Please, Sign In to add comment