Omega_K2

simpleauth.py

Jul 20th, 2012
54
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """
  2. addons/source-python/simpleauth/simpleauth.py
  3. """
  4.  
  5. # =============================================================================
  6. # >> IMPORTS
  7. # =============================================================================
  8. # Python Imports
  9. import re
  10. from os.path import join
  11. # SP Imports
  12. #   C++ Imports
  13. from Source import Player
  14. #   Auth
  15. from auth.provider import Register
  16. from auth.provider import Unregister
  17. from auth.provider import AuthProvider
  18. #   Paths
  19. from paths import CFG_PATH
  20.  
  21. # =============================================================================
  22. # >> LOAD & UNLOAD
  23. # =============================================================================
  24.  
  25. def load():
  26.     global s
  27.     s = SimpleAuthProvider()
  28.     Register(s)
  29.  
  30. def unload():
  31.     Unregister(s)
  32.    
  33.  
  34. # =============================================================================
  35. # >> CLASSES
  36. # =============================================================================
  37.  
  38. class SimpleAuthProvider(AuthProvider):
  39.     def __init__(self):
  40.         self._AddAuthMethod(self.GetSteamIDAuth, 'steamid')
  41.         self._ParseAdmins()
  42.     def _ParseAdmins(self):
  43.         with open(join(CFG_PATH, 'auth_providers', 'simple.txt'), 'r') as f:
  44.             self.steamids = []
  45.             for line in f.readlines():
  46.                 match = re.match('(^STEAM_[0,1]{1}:[0,1]{1}:[0-9]+)', line)
  47.                 if match:
  48.                     self.steamids.append(match.group(0)[8:])
  49.     def GetSteamIDAuth(self, userid):
  50.         steamid = Player.PlayerOfUserid(userid)
  51.         if steamid.startswith('STEAM_'):
  52.             steamid = steamid[8:]
  53.         if steamid not in self.steamids:
  54.             return None
  55.         p = auth.Player()
  56.         p.flags.append(auth.flags['root'])
  57.         p.groups.append(auth.groups['root'])
  58.         return p
  59.     def Refresh(self):
  60.         self._ParseAdmins()
RAW Paste Data