Exemplo n.º 1
0
def define(host, port, database, word):
    """Look up a word using a dict server"""
    d = defer.Deferred()
    factory = DictLookupFactory("define", (database, word), d)

    from reqs.twisted.internet import reactor
    reactor.connectTCP(host, port, factory)
    return d
Exemplo n.º 2
0
def match(host, port, database, strategy, word):
    """Match a word using a dict server"""
    d = defer.Deferred()
    factory = DictLookupFactory("match", (database, strategy, word), d)

    from reqs.twisted.internet import reactor
    reactor.connectTCP(host, port, factory)
    return d
Exemplo n.º 3
0
def match(host, port, database, strategy, word):
    """Match a word using a dict server"""
    d = defer.Deferred()
    factory = DictLookupFactory("match", (database, strategy, word), d)

    from reqs.twisted.internet import reactor
    reactor.connectTCP(host, port, factory)
    return d
Exemplo n.º 4
0
def define(host, port, database, word):
    """Look up a word using a dict server"""
    d = defer.Deferred()
    factory = DictLookupFactory("define", (database, word), d)
    
    from reqs.twisted.internet import reactor
    reactor.connectTCP(host, port, factory)
    return d
Exemplo n.º 5
0
    def connectionMade(self):
        # Don't read anything from the connecting client until we have
        # somewhere to send it to.
        self.transport.pauseProducing()

        client = self.clientProtocolFactory()
        client.setServer(self)

        from reqs.twisted.internet import reactor
        reactor.connectTCP(self.factory.host, self.factory.port, client)
Exemplo n.º 6
0
    def connectionMade(self):
        # Don't read anything from the connecting client until we have
        # somewhere to send it to.
        self.transport.pauseProducing()

        client = self.clientProtocolFactory()
        client.setServer(self)

        from reqs.twisted.internet import reactor
        reactor.connectTCP(self.factory.host, self.factory.port, client)
Exemplo n.º 7
0
def loopbackTCP(server, client, port=0, noisy=True):
    """Run session between server and client protocol instances over TCP."""
    from reqs.twisted.internet import reactor
    f = policies.WrappingFactory(protocol.Factory())
    serverWrapper = _FireOnClose(f, server)
    f.noisy = noisy
    f.buildProtocol = lambda addr: serverWrapper
    serverPort = reactor.listenTCP(port, f, interface='127.0.0.1')
    clientF = LoopbackClientFactory(client)
    clientF.noisy = noisy
    reactor.connectTCP('127.0.0.1', serverPort.getHost().port, clientF)
    d = clientF.deferred
    d.addCallback(lambda x: serverWrapper.deferred)
    d.addCallback(lambda x: serverPort.stopListening())
    return d
Exemplo n.º 8
0
def loopbackTCP(server, client, port=0, noisy=True):
    """Run session between server and client protocol instances over TCP."""
    from reqs.twisted.internet import reactor
    f = policies.WrappingFactory(protocol.Factory())
    serverWrapper = _FireOnClose(f, server)
    f.noisy = noisy
    f.buildProtocol = lambda addr: serverWrapper
    serverPort = reactor.listenTCP(port, f, interface='127.0.0.1')
    clientF = LoopbackClientFactory(client)
    clientF.noisy = noisy
    reactor.connectTCP('127.0.0.1', serverPort.getHost().port, clientF)
    d = clientF.deferred
    d.addCallback(lambda x: serverWrapper.deferred)
    d.addCallback(lambda x: serverPort.stopListening())
    return d
Exemplo n.º 9
0
def rip(key, username, password):
    login_url = 'http://minecraft.net/login.jsp'
    play_url = 'http://minecraft.net/play.jsp?server=%s'

    cj = cookielib.CookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    login_data = urllib.urlencode({'username': username, 'password': password})
    print ("Logging in...")
    opener.open(login_url, login_data)
    print ("Fetching server info...")
    html = opener.open(play_url % key).read()
    ip = re.search(r'param name\="server" value="([0-9.]+)"', html).groups()[0]
    port = int(re.search(r'param name\="port" value="([0-9]+)"', html).groups()[0])
    mppass = re.search(r'param name\="mppass" value="([0-9a-zA-Z]+)"', html).groups()[0]
    print ("Got details. Connecting...")
    f = RipFactory(username, mppass)
    reactor.connectTCP(ip, port, f)
    reactor.run()
Exemplo n.º 10
0
 def setUp(self):
     self.realm = service.InMemoryWordsRealm("realmname")
     self.checker = checkers.InMemoryUsernamePasswordDatabaseDontUse()
     self.portal = portal.Portal(self.realm, [self.checker])
     self.serverFactory = pb.PBServerFactory(self.portal)
     self.serverFactory.protocol = self._protocolFactory
     self.serverFactory.unsafeTracebacks = True
     self.clientFactory = pb.PBClientFactory()
     self.clientFactory.unsafeTracebacks = True
     self.serverPort = reactor.listenTCP(0, self.serverFactory)
     self.clientConn = reactor.connectTCP('127.0.0.1',
                                          self.serverPort.getHost().port,
                                          self.clientFactory)
Exemplo n.º 11
0
 def reloadIrcBot(self):
     if(self.irc_relay):
         try:
             self.irc_relay.quit("Reloading the IRC Bot...")
             global ChatBotFactory
             del ChatBotFactory
             from core.irc_client import ChatBotFactory
             if self.ircbot and self.use_irc:
                 self.irc_nick = self.irc_config.get("irc", "nick")
                 self.irc_pass = self.irc_config.get("irc", "password")
                 self.irc_channel = self.irc_config.get("irc", "channel")
                 self.irc_cmdlogs = self.irc_config.getboolean("irc", "cmdlogs")
                 self.ircbot = self.irc_config.getboolean("irc", "ircbot")
                 self.staffchat = self.irc_config.getboolean("irc", "staffchat")
                 self.irc_relay = ChatBotFactory(self)
                 if self.ircbot and not (self.irc_channel == "#icraft" or self.irc_channel == "#channel") and not self.irc_nick == "botname":
                     reactor.connectTCP(self.irc_config.get("irc", "server"), self.irc_config.getint("irc", "port"), self.irc_relay)
                 else:
                     logging.log(logging.ERROR, "IRC Bot failed to connect, you could modify, rename or remove irc.conf")
                     logging.log(logging.ERROR, "You need to change your 'botname' and 'channel' fields to fix this error or turn the bot off by disabling 'ircbot'")
                 return True
         except:
             return False
     return False
Exemplo n.º 12
0
 def setUp(self):
     self.realm = service.InMemoryWordsRealm("realmname")
     self.checker = checkers.InMemoryUsernamePasswordDatabaseDontUse()
     self.portal = portal.Portal(
         self.realm, [self.checker])
     self.serverFactory = pb.PBServerFactory(self.portal)
     self.serverFactory.protocol = self._protocolFactory
     self.serverFactory.unsafeTracebacks = True
     self.clientFactory = pb.PBClientFactory()
     self.clientFactory.unsafeTracebacks = True
     self.serverPort = reactor.listenTCP(0, self.serverFactory)
     self.clientConn = reactor.connectTCP(
         '127.0.0.1',
         self.serverPort.getHost().port,
         self.clientFactory)
Exemplo n.º 13
0
 def __init__(self):
     self.ServerVars = dict()
     self.specs = ConfigParser()
     self.last_heartbeat = time.time()
     self.lastseen = ConfigParser()
     self.config = ConfigParser()
     self.options_config = ConfigParser()
     self.ploptions_config = ConfigParser()
     self.wordfilter = ConfigParser()
     self.save_count = 1
     try:
         self.config.read("config/main.conf")
     except:
         logging.log(logging.ERROR, "Something is messed up with your main.conf file. (Did you edit it in Notepad?)")
         sys.exit(1)
     try:
         self.options_config.read("config/options.conf")
     except:
         logging.log(logging.ERROR, "Something is messed up with your options.conf file. (Did you edit it in Notepad?)")
         sys.exit(1)
     try:
         self.ploptions_config.read("config/ploptions.conf")
     except:
         logging.log(logging.ERROR, "Something is messed up with your ploptions.conf file. (Did you edit it in Notepad?)")
         sys.exit(1)
     self.use_irc = False
     if  (os.path.exists("config/irc.conf")):
         self.use_irc = True
         self.irc_config = ConfigParser()
         try:
             self.irc_config.read("config/irc.conf")
         except:
             logging.log(logging.ERROR, "Something is messed up with your irc.conf file. (Did you edit it in Notepad?)")
             sys.exit(1)
     self.saving = False
     try:
         self.max_clients = self.config.getint("main", "max_clients")
         self.server_message = self.config.get("main", "description")
         self.public = self.config.getboolean("main", "public")
         self.controller_port = self.config.get("network", "controller_port")
         self.controller_password = self.config.get("network", "controller_password")
         self.server_name = self.config.get("main", "name")
         if self.server_name == "iCraft Server":
             logging.log(logging.ERROR, "You forgot to give your server a name.")
         self.owner = self.config.get("main", "owner").lower()
         if self.owner == "yournamehere":
             logging.log(logging.ERROR, "You forgot to make yourself the server owner.")
     except:
         logging.log(logging.ERROR, "You don't have a main.conf file! You need to rename main.example.conf to main.conf")
         sys.exit(1)
     try:
         self.duplicate_logins = self.options_config.getboolean("options", "duplicate_logins")
         self.info_url = self.options_config.get("options", "info_url")
         self.away_kick = self.options_config.getboolean("options", "away_kick")
         self.away_time = self.options_config.getint("options", "away_time")
         self.colors = self.options_config.getboolean("options", "colors")
         self.physics_limit = self.options_config.getint("worlds", "physics_limit")
         self.default_name = self.options_config.get("worlds", "default_name")
         self.default_backup = self.options_config.get("worlds", "default_backup")
         self.asd_delay = self.options_config.getint("worlds", "asd_delay")
         self.gchat = self.options_config.getboolean("worlds", "gchat")
     except:
         logging.log(logging.ERROR, "You don't have a options.conf file! You need to rename options.example.conf to options.conf")
         sys.exit(1)
     try:
         self.grief_blocks = self.ploptions_config.getint("antigrief", "blocks")
         self.grief_time = self.ploptions_config.getint("antigrief", "time")
         self.backup_freq = self.ploptions_config.getint("backups", "backup_freq")
         self.backup_default = self.ploptions_config.getboolean("backups", "backup_default")
         self.backup_max = self.ploptions_config.getint("backups", "backup_max")
         self.backup_auto = self.ploptions_config.getboolean("backups", "backup_auto")
         self.enable_archives = self.ploptions_config.getboolean("archiver", "enable_archiver")
         self.currency = self.ploptions_config.get("bank", "currency")
         self.build_director = self.ploptions_config.get("build", "director")
         self.build_admin = self.ploptions_config.get("build", "admin")
         self.build_mod = self.ploptions_config.get("build", "mod")
         self.build_op = self.ploptions_config.get("build", "op")
         self.build_other = self.ploptions_config.get("build", "other")
         if self.backup_auto:
             reactor.callLater(float(self.backup_freq * 60),self.AutoBackup)
     except:
         logging.log(logging.ERROR, "You don't have a ploptions.conf file! You need to rename ploptions.example.conf to ploptions.conf")
         sys.exit(1)
     #if not os.path.exists("config/greeting.txt"):
     #    logging.log(logging.ERROR, "You don't have a greeting.txt file! You need to rename greeting.example.txt to greeting.txt (If this error persists, you may have used Notepad.)")
     #    sys.exit(1)
     #if not os.path.exists("config/rules.txt"):
     #    logging.log(logging.ERROR, "You don't have a rules.txt file! You need to rename rules.example.txt to rules.txt (If this error persists, you may have used Notepad.)")
     #    sys.exit(1)
     if self.use_irc:
         self.irc_nick = self.irc_config.get("irc", "nick")
         self.irc_pass = self.irc_config.get("irc", "password")
         self.irc_channel = self.irc_config.get("irc", "channel")
         self.irc_cmdlogs = self.irc_config.getboolean("irc", "cmdlogs")
         self.ircbot = self.irc_config.getboolean("irc", "ircbot")
         self.staffchat = self.irc_config.getboolean("irc", "staffchat")
         self.irc_relay = ChatBotFactory(self)
         if self.ircbot and not (self.irc_channel == "#icraft" or self.irc_channel == "#channel") and not self.irc_nick == "botname":
             reactor.connectTCP(self.irc_config.get("irc", "server"), self.irc_config.getint("irc", "port"), self.irc_relay)
         else:
             logging.log(logging.ERROR, "IRC Bot failed to connect, you could modify, rename or remove irc.conf")
             logging.log(logging.ERROR, "You need to change your 'botname' and 'channel' fields to fix this error or turn the bot off by disabling 'ircbot'")
     else:
         self.irc_relay = None
     self.default_loaded = False
     # Word Filter
     try:
         self.wordfilter.read("config/wordfilter.conf")
     except:
         logging.log(logging.ERROR, "Something is messed up with your wordfilter.conf file. (Did you edit it in Notepad?)")
         sys.exit(1)
     self.filter = []
     try:
         number = int(self.wordfilter.get("filter","count"))
     except:
         logging.log(logging.ERROR, "You need to rename wordfilter.example.conf to wordfilter.conf")
         sys.exit(1);
     for x in range(number):
         self.filter = self.filter + [[self.wordfilter.get("filter","s"+str(x)),self.wordfilter.get("filter","r"+str(x))]]
     # Salt, for the heartbeat server/verify-names
     self.salt = hashlib.md5(hashlib.md5(str(random.getrandbits(128))).digest()).hexdigest()[-32:].strip("0")
     # Load up the plugins specified
     self.plugins_config = ConfigParser()
     try:
         self.plugins_config.read("config/plugins.conf")
     except:
         logging.log(logging.ERROR, "Something is messed up with your irc.conf file. (Did you edit it in Notepad?)")
         sys.exit(1)
     try:
         plugins = self.plugins_config.options("plugins")
     except:
         print ("NOTICE: You need to rename plugins.example.conf to plugins.conf")
         sys.exit(1);
     logging.log(logging.INFO, "Loading plugins...")
     load_plugins(plugins)
     # Open the chat log, ready for appending
     self.chatlog = open("logs/server.log", "a")
     self.chatlog = open("logs/chat.log", "a")
     # Create a default world, if there isn't one.
     if not os.path.isdir("worlds/%s" % self.default_name):
         logging.log(logging.INFO, "Generating %s world..." % self.default_name)
         sx, sy, sz = 64, 64, 64
         grass_to = (sy // 2)
         world = World.create(
             "worlds/%s" % self.default_name,
             sx, sy, sz, # Size
             sx//2,grass_to+2, sz//2, 0, # Spawn
             ([BLOCK_DIRT]*(grass_to-1) + [BLOCK_GRASS] + [BLOCK_AIR]*(sy-grass_to)) # Levels
         )
         logging.log(logging.INFO, "Generated.")
     # Initialise internal datastructures
     self.worlds = {}
     self.directors = set()
     self.admins = set()
     self.mods = set()
     self.globalbuilders = set()
     self.members = set()
     self.spectators = set()
     self.silenced = set()
     self.banned = {}
     self.ipbanned = {}
     self.lastseen = {}
     # Load up the contents of those.
     self.loadMeta()
     # Set up a few more things.
     self.queue = Queue()
     self.clients = {}
     self.usernames = {}
     self.console = StdinPlugin(self)
     self.console.start()
     self.heartbeat = Heartbeat(self)
     # Boot worlds that got loaded
     for world in self.worlds:
         self.loadWorld("worlds/%s" % world, world)
     # Set up tasks to run during execution
     reactor.callLater(0.1, self.sendMessages)
     reactor.callLater(1, self.printInfo)
     # Initial startup is instant, but it updates every 10 minutes.
     self.world_save_stack = []
     reactor.callLater(60, self.saveWorlds)
     if self.enable_archives:
         self.loadPlugin('archives')
         reactor.callLater(1, self.loadArchives)
     gc.disable()
     self.cleanGarbage()