def __init__(self,wedgeName, nodeName="", nsHost=None,nsPort=None, listenPort=None, bcLocate=False, clHost=None,clPort=None, allowUnfilteredChat=0, bwDictPath=""): Pyro.config.PYRO_MULTITHREADED = 0 Pyro.config.PYRO_TRACELEVEL = 2 Pyro.core.SynchronizedObjBase.__init__(self) Pyro.core.initServer(banner=0) self.log = sbLog(":sb.wedge.%s"%wedgeName,clHost,clPort) badwordpy.init(bwDictPath,"") if not badwordpy.test("f**k") and not allowUnfilteredChat: self.log.error("Dirty word filter not working, refusing to start. Devs should add .prc setting 'allow-unfiltered-chat 1' to bypass.") raise Exception("No dirty word filter, aborting SB Wedge startup. Devs should add .prc setting 'allow-unfiltered-chat 1' to bypass.") self.wedgeName = wedgeName if nodeName == "": self.nodeName = wedgeName else: self.nodeName = nodeName self.node = None self.log.info("Starting.") self.sbConnected = False self.nsHost = nsHost self.nsPort = nsPort try: self.initPyro(nsHost,nsPort,listenPort,bcLocate) self.updateNode() self.log.debug("Enter sendEnterWedge") self.sendEnterWedge() self.log.debug("Exit sendEnterWedge") self.sbConnected = True except Exception as e: self.log.warning("Failed to connect to Switchboard. Player friends are being faked.") self.onlinePlayers = 0 self.servedLogins = 0 self.servedChat = 0 self.servedChatSC = 0 self.servedMail = 0 self.servedMailSC = 0 self.log.info("-- sb.wedge.%s is ready. --" %self.wedgeName)
def __init__(self, host, port, user, passwd, dbname): self.sqlAvailable = uber.sqlAvailable if not self.sqlAvailable: return # Now set the bwDictPath. Used during token generation to make sure # we're not giving out any strings that contain bad words self.bwDictPath = uber.bwDictPath # If Path string is empty, flag the dict as being offline if self.bwDictPath == "": self.bwDictOnline = False self.notify.info( "Badword filtering for Guild Tokens not online. Dict path not provided" ) else: self.bwDictOnline = True # Now that the module has loaded, try to init the lib with the # bwDictPath provided badwordpy.init(self.bwDictPath, "") # If the path provided is good, the next if statement should return 1 if not badwordpy.test("shit"): self.notify.info( "Bad Word Filtering not online for token guild generation. Dict test failed" ) self.bwDistOnline = False # Place startCleanUpExpiredTokens into TaskMgr. It will clean up the # expired guild membership tokens every 5 minutes. self.startCleanUpExpiredTokens() self.host = host self.port = port self.user = user self.passwd = passwd self.dbname = self.processDBName(dbname) if __debug__: self.notify.info("About to connect to %s MySQL db at %s:%d." % (self.dbname, host, port)) self.db = MySQLdb.connect(host=host, port=port, user=user, passwd=passwd) if __debug__: self.notify.info("Connected to %s MySQL db at %s:%d." % (self.dbname, host, port)) #temp hack for initial dev, create DB structure if it doesn't exist already cursor = self.db.cursor() try: cursor.execute("CREATE DATABASE `%s`" % self.dbname) if __debug__: self.notify.debug( "Database '%s' did not exist, created a new one!" % self.dbname) except _mysql_exceptions.ProgrammingError, e: pass
def getFriendToken(self, guildId, avId, ttl=10): # Generate a friend token for the membership to the guildId passed # Step .5: Verify that the user does not have too many tokens pending # Step One: Generate a token (self.genToken) # Step Two: Verify that the token does not collide with an existing one # and if self.bwDictOnline == True, check for bad words # Step Three: Insert entry into the DB # Step Four: Return token string # Note: The TTL is in days if not self.sqlAvailable: return "Guild DB Unavailable" # Step .5: tooManyTokens = self.checkForTooManyTokens(avId) if tooManyTokens == True: # Too many tokens pending # Return string 'TOO_MANY_TOKENS' return 'TOO_MANY_TOKENS' from otp.friends import GuildManagerUD count = self.memberCount(guildId) if (count >= GuildManagerUD.MAX_MEMBERS): # Too many people in the guild, refuse to issue a token return 'GUILD FULL' # Step One: ourToken = self.genToken() # print 'Token Generated %s.' % ourToken # Step Two: if self.bwDictPath: while not self.isTokenUnique(ourToken) or badwordpy.test(ourToken): self.notify.info( 'Token is not unique or contains a bad word: %s' % ourToken) ourToken = self.genToken() else: while self.isTokenUnique(ourToken) == 0: self.notify.info('Token is not unique: %s' % ourToken) ourToken = self.genToken() # Step Three: foo = time.localtime() date_time = "%d-%d-%d %d:%d:%d" % (foo[0], foo[1], foo[2], foo[3], foo[4], foo[5]) try: cursor = self.db.cursor() cursor.execute( "INSERT INTO `guildtokens` VALUES (%s, %s, %s, %s, %s, NULL)", (ourToken, date_time, ttl, guildId, avId)) self.db.commit() except _mysql_exceptions.OperationalError, e: self.reconnect() print "GuildDB::getFriendToken Error " self.getFriendToken(guildId, avId, ttl)
def __init__(self,host,port,user,passwd,dbname): self.sqlAvailable = uber.sqlAvailable if not self.sqlAvailable: return # Now set the bwDictPath. Used during token generation to make sure # we're not giving out any strings that contain bad words self.bwDictPath = uber.bwDictPath # If Path string is empty, flag the dict as being offline if self.bwDictPath == "": self.bwDictOnline = False self.notify.info("Badword filtering for Guild Tokens not online. Dict path not provided") else: self.bwDictOnline = True # Now that the module has loaded, try to init the lib with the # bwDictPath provided badwordpy.init(self.bwDictPath,"") # If the path provided is good, the next if statement should return 1 if not badwordpy.test("shit"): self.notify.info("Bad Word Filtering not online for token guild generation. Dict test failed") self.bwDistOnline = False # Place startCleanUpExpiredTokens into TaskMgr. It will clean up the # expired guild membership tokens every 5 minutes. self.startCleanUpExpiredTokens() self.host = host self.port = port self.user = user self.passwd = passwd self.dbname = self.processDBName(dbname) if __debug__: self.notify.info("About to connect to %s MySQL db at %s:%d." % (self.dbname, host, port)) self.db = MySQLdb.connect(host=host, port=port, user=user, passwd=passwd) if __debug__: self.notify.info("Connected to %s MySQL db at %s:%d." % (self.dbname, host, port)) #temp hack for initial dev, create DB structure if it doesn't exist already cursor = self.db.cursor() try: cursor.execute("CREATE DATABASE `%s`" % self.dbname) if __debug__: self.notify.debug("Database '%s' did not exist, created a new one!" % self.dbname) except _mysql_exceptions.ProgrammingError as e: pass cursor.execute("USE `%s`" % self.dbname) if __debug__: self.notify.debug("Using database '%s'" % self.dbname) try: cursor.execute("CREATE TABLE `guildinfo` (`gid` INT(32) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, `name` VARCHAR(21), `wantname` VARCHAR(21), `namestatus` INT(8), `create_date` DATETIME)") if __debug__: self.notify.debug("Table guildinfo did not exist, created a new one!") except _mysql_exceptions.OperationalError as e: pass try: cursor.execute("CREATE TABLE `member` (`gid` INT(32) UNSIGNED NOT NULL, `avid` INT(32) UNSIGNED NOT NULL PRIMARY KEY, `rank` INT(8) NOT NULL, FOREIGN KEY (`gid`) REFERENCES `guildinfo` (`gid`))") if __debug__: self.notify.debug("Table member did not exist, created a new one!") except _mysql_exceptions.OperationalError as e: pass try: cursor.execute("CREATE TABLE `guildtokens` (`tokenid` VARCHAR(8) NOT NULL PRIMARY KEY, `createtime` DATETIME, `ttl` INT(8) UNSIGNED NOT NULL, `gid` INT(32) UNSIGNED, `avid` INT(32) UNSIGNED, `rcount` INT(8), FOREIGN KEY (`gid`) REFERENCES `guildinfo` (`gid`), FOREIGN KEY (`avid`) REFERENCES `member` (`avid`))") # An index should also be added to the avid col cursor.execute("CREATE INDEX `avatarid` on guildtokens (avid)") if __debug__: self.notify.debug("Table guildtokens did not exist, created a new one!") except _mysql_exceptions.OperationalError as e: pass