import re import ChatManager DEV = False class rules: def __init__(self): self.Title = 'Server Rules' self.Version = V(1, 0, 1) self.Author = 'SkinN' self.Description = 'Displays customized rules for your server' self.ResourceId = 1514 self.Default = { 'SETTINGS': { 'PREFIX': '[ SERVER RULES ]', 'COMMAND TRIGGER': 'rules', 'DEFAULT LANGUAGE': 'en', 'ENUMERATE RULES': True, 'REMOVE CHAT COLORS': False, }, 'MESSAGES': { 'TITLE PREFIX': ' SERVER RULES:', 'AVAILABLE LANGS': 'Available languages', 'LANG NOT EXIST': 'Could not find {lang} language, type /rules list for the full list of languages.' }, 'RULES': { 'EN': ( 'Cheating is strictly prohibited.', 'Respect all players', 'Avoid spam in chat.', 'Play fair and don\'t abuse of bugs/exploits.' ), 'PT': ( 'Usar cheats e totalmente proibido.', 'Respeita todos os jogadores.', 'Evita spam no chat.', 'Nao abuses de bugs ou exploits.' ), 'FR': ( 'Tricher est strictement interdit.', 'Respectez tous les joueurs.', 'Évitez le spam dans le chat.', 'Jouer juste et ne pas abuser des bugs / exploits.' ), 'ES': ( 'Los trucos están terminantemente prohibidos.', 'Respeta a todos los jugadores.', 'Evita el Spam en el chat.', 'Juega limpio y no abuses de bugs/exploits.' ), 'DE': ( 'Cheaten ist verboten!', 'Respektiere alle Spieler', 'Spam im Chat zu vermeiden.', 'Spiel fair und missbrauche keine Bugs oder Exploits.' ), 'TR': ( 'Hile kesinlikle yasaktır.', 'Tüm oyuncular Saygı.', 'Sohbet Spam kaçının.', 'Adil oynayın ve böcek / açıkları kötüye yok.' ), 'IT': ( 'Cheating è severamente proibito.', 'Rispettare tutti i giocatori.', 'Evitare lo spam in chat.', 'Fair Play e non abusare di bug / exploit.' ), 'DK': ( 'Snyd er strengt forbudt.', 'Respekter alle spillere.', 'Undgå spam i chatten.', 'Spil fair og misbrug ikke bugs / exploits.' ), 'RU': ( 'Запрещено использовать читы.', 'Запрещено спамить и материться.', 'Уважайте других игроков.', 'Играйте честно и не используйте баги и лазейки.' ), 'NL': ( 'Vals spelen is ten strengste verboden.', 'Respecteer alle spelers', 'Vermijd spam in de chat.', 'Speel eerlijk en maak geen misbruik van bugs / exploits.' ), 'UA': ( 'Обман суворо заборонено.', 'Поважайте всіх гравців', 'Щоб уникнути спаму в чаті.', 'Грати чесно і не зловживати помилки / подвиги.' ), 'RO': ( 'Cheaturile sunt strict interzise!', 'Respectați toți jucătorii!', 'Evitați spamul în chat!', 'Jucați corect și nu abuzați de bug-uri/exploituri!' ), 'HU': ( 'Csalás szigorúan tilos.', 'Tiszteld minden játékostársad.', 'Kerüld a spammolást a chaten.', 'Játssz tisztességesen és nem élj vissza a hibákkal.' ) } } # ------------------------------------------------------------------------- # - CONFIGURATION / DATABASE SYSTEM def LoadDefaultConfig(self): '''Hook called when there is no configuration file ''' self.Config.Clear() self.Config = self.Default self.SaveConfig() # ------------------------------------------------------------------------- def UpdateConfig(self): '''Function to update the configuration file on plugin Init ''' # Override config in developer mode is enabled if DEV: self.LoadDefaultConfig(); return # Start configuration checks for section in self.Default: # Is section in the configuration file if section not in self.Config: # Add section to config self.Config[section] = self.Default[section] elif isinstance(self.Default[section], dict): # Check for sub-section for sub in self.Default[section]: if sub not in self.Config[section]: self.Config[section][sub] = self.Default[section][sub] self.SaveConfig() # ------------------------------------------------------------------------- # - PLUGIN HOOKS def Init(self): '''Hook called when the plugin initializes ''' # Update System self.UpdateConfig() # Global and Plugin variables global MSG, PLUGIN, RULES MSG, PLUGIN, RULES = [self.Config[x] for x in ('MESSAGES', 'SETTINGS', 'RULES')] self.prefix = PLUGIN['PREFIX'] if PLUGIN['PREFIX'] else '' # Command trigger command.AddChatCommand(PLUGIN['COMMAND TRIGGER'], self.Plugin, 'rules_CMD') # Plugin Command command.AddChatCommand('serverrules', self.Plugin, 'plugin_CMD') # ------------------------------------------------------------------------- # - COMMAND FUNCTIONS def rules_CMD(self, player, command, args): '''Rules command function ''' key = PLUGIN['DEFAULT LANGUAGE'].upper() if args: # Get arguments as a string arg = ' '.join(args).upper() if arg.lower() == 'list': self.tell(player, '%s %s: %s' % (self.prefix, MSG['AVAILABLE LANGS'], ', '.join(RULES.keys()))) return # Check if argument is a valid key elif arg in RULES: key = arg else: self.tell(player, '%s %s' % (self.prefix, MSG['LANG NOT EXIST'].replace('{lang}', 'arg'))) return # Get list of rules lis = RULES[key] self.tell(player, MSG['TITLE PREFIX']) if PLUGIN['ENUMERATE RULES']: for n, i in enumerate(lis): self.tell(player, '%s. %s' % (n+1, i)) else: for i in lis: self.tell(player, '%s' % i) # ------------------------------------------------------------------------- def plugin_CMD(self, player, command, args): '''Plugin command function ''' self.tell(player, '%s v%s' % (self.Title, self.Version)) self.tell(player, ' %s' % self.Description) self.tell(player, ' Plugin developed by <#9810FF>SkinN, powered by Oxide 2.') # ------------------------------------------------------------------------- # - PLUGIN FUNCTIONS / HOOKS def playerid(self, player): '''Function to return the player UID ''' return str(player.SteamId) # ------------------------------------------------------------------------- # - MESSAGE SYSTEM def tell(self, player, text): '''Function to send a message to a player ''' ChatManager.Instance.AppendChatboxServerSingle(self.scs(text, self.Config['SETTINGS']['REMOVE CHAT COLORS']), player.Player) # ------------------------------------------------------------------------- def scs(self, text, con=False): ''' Replaces color names and RGB hex code into HTML code ''' colors = ( 'red', 'blue', 'green', 'yellow', 'white', 'black', 'cyan', 'lightblue', 'lime', 'purple', 'darkblue', 'magenta', 'brown', 'orange', 'olive', 'gray', 'grey', 'silver', 'maroon' ) name = r'\<(\w+)\>' hexcode = r'\<(#\w+)\>' end = 'end' if con: for x in (end, name, hexcode): for c in re.findall(x, text): if c.startswith('#') or c in colors or x == end: text = text.replace('<%s>' % c, '') else: text = text.replace('<%s>' % end, '') for f in (name, hexcode): for c in re.findall(f, text): if c.startswith('#') or c in colors: text = text.replace('<%s>' % c, '' % c) return text