import twisted, sys, codecs, traceback
from twisted.words.protocols import irc
-from twisted.internet import reactor, protocol
+from twisted.internet import reactor, protocol, abstract
from twisted.web import resource, server
from twisted.protocols import basic
-
-import hmac, time, config, qwebirc.config_options as config_options
+from twisted.names.client import Resolver
+import hmac, time, config, random, qwebirc.config_options as config_options
from config import HMACTEMPORAL
+if config.get("CONNECTION_RESOLVER"):
+ CONNECTION_RESOLVER = Resolver(servers=config.get("CONNECTION_RESOLVER"))
+else:
+ CONNECTION_RESOLVER = None
+
if hasattr(config, "WEBIRC_MODE") and config.WEBIRC_MODE == "hmac":
HMACKEY = hmac.HMAC(key=config.HMACKEY)
self.lastError = None
f = self.factory.ircinit
- nick, ident, ip, realname, hostname = f["nick"], f["ident"], f["ip"], f["realname"], f["hostname"]
+ nick, ident, ip, realname, hostname, pass_ = f["nick"], f["ident"], f["ip"], f["realname"], f["hostname"], f.get("password")
self.__nickname = nick
self.__perform = f.get("perform")
self.write("USER %s bleh bleh :%s - %s" % (ident, dispip, realname))
+ if pass_ is not None:
+ self.write("PASS :%s" % pass_)
self.write("NICK %s" % nick)
self.factory.client = self
def createIRC(*args, **kwargs):
f = QWebIRCFactory(*args, **kwargs)
- reactor.connectTCP(config.IRCSERVER, config.IRCPORT, f)
+ if CONNECTION_RESOLVER is None:
+ reactor.connectTCP(config.IRCSERVER, config.IRCPORT, f)
+ return f
+
+ def callback(result):
+ name, port = random.choice(sorted((str(x.payload.target), x.payload.port) for x in result[0]))
+ reactor.connectTCP(name, port, f)
+ def errback(err):
+ f.clientConnectionFailed(None, err) # None?!
+
+ d = CONNECTION_RESOLVER.lookupService(config.IRCSERVER, (1, 3, 11))
+ d.addCallbacks(callback, errback)
return f
if __name__ == "__main__":