def buildProtocol(self, addr): # return None here to refuse the connection. # will use this later to hardban e.g. DoS ret = self.scripts.call('on_connection_attempt', address=addr).result if ret is False: print '[WARNING] Connection attempt for %s blocked by script!' % addr.host return None elif ret is not None: return BanProtocol(ret) if database.is_banned_ip(self.db_con, addr.host): print '[INFO] Banned client %s tried to join.' % addr.host return BanProtocol('You are banned on this server.') return CubeWorldConnection(self, addr)
def buildProtocol(self, addr): con_remain = self.config.base.max_connections_per_ip for connection in self.connections: if connection.address.host == addr.host: con_remain -= 1 if con_remain <= 0: if con_remain == 0: print '[WARNING] Too many connections from %s, closing...' % addr.host connection.disconnect() if con_remain <= 0: return self.db_con = database.get_connection() if database.is_banned_ip(self.db_con, addr.host): print '[INFO] Banned client %s tried to join.' % addr.host return 'You are banned from this server.' if self.scripts.call('on_connection_attempt', address=addr).result is False: print '[WARNING] Connection attempt for %s blocked by script!' % addr.host return False return CubeWorldConnection(self, addr)