diff --git a/README.md b/README.md index 85371fe..255baca 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # PyLink -PyLink is an IRC PseudoService written in Python that *might one day* be a replacement for the now defunct Janus. +PyLink is an IRC PseudoService written in Python. ## Dependencies diff --git a/config.yml.example b/config.yml.example index 6963fe6..38a7634 100644 --- a/config.yml.example +++ b/config.yml.example @@ -9,17 +9,18 @@ login: user: admin password: changeme -networks: - mynet: +server: # Server name, port, and passwords + netname: whatever ip: 127.0.0.1 - port: 6667 - recvpass: "abcdefg" - sendpass: "gfedcba" + port: 7000 + recvpass: "abcd" + sendpass: "abcd" # Hostname we will use to connect to the remote server - hostname: "pylink.overdrive.pw" + hostname: "pylink.yournet" # SID - required for InspIRCd and TS6 based servers. This must be three characters long. # The first char must be a digit [0-9], and the remaining two chars may be letters [A-Z] or digits. sid: "0AL" - # Set protocol module (currently only a null stub is available, but this will change in the future) - protocol: stub + # Set protocol module + protocol: inspircd + channel: "#pylink" diff --git a/main.py b/main.py index 063623c..f79147a 100755 --- a/main.py +++ b/main.py @@ -16,31 +16,26 @@ with open("config.yml", 'r') as f: # if conf['login']['password'] == 'changeme': # print("You have not set the login details correctly! Exiting...") -global networkobjects -networkobjects = {} - class IrcUser(): def __init__(self, nick, timestamp, data={'uid': None}): self.nick = nick self.data = data self.timestamp = timestamp -class Irc(multiprocessing.Process): - def __init__(self, network): - multiprocessing.Process.__init__(self) +class Irc(): + def __init__(self): # Initialize some variables self.socket = socket.socket() - self.kill_received = False + self.connected = False self.users = {} - self.name = network + self.name = conf['server']['netname'] - self.serverdata = conf['networks'][network] + self.serverdata = conf['server'] ip = self.serverdata["ip"] port = self.serverdata["port"] self.sid = self.serverdata["sid"] - print("[+] New thread started for %s:%s" % (ip, port)) + print("Connecting to network %r on %s:%s" % (self.name, ip, port)) - protoname = self.serverdata['protocol'] # With the introduction of Python 3, relative imports are no longer # allowed from normal applications ran from the command line. Instead, @@ -57,9 +52,11 @@ class Irc(multiprocessing.Process): self.socket = socket.socket() self.socket.connect((ip, port)) self.proto.connect(self) + self.connected = True + self.run() def run(self): - while not self.kill_received: + while self.connected: try: data = self.socket.recv(1024) if data: @@ -68,25 +65,12 @@ class Irc(multiprocessing.Process): print("<- {}".format(line)) self.proto.handle_events(self, line) except socket.error: - self.restart() - break + print('Received socket.error: %s, exiting.' % str(e)) + self.connected = False def send(self, data): data = data.encode("utf-8") + b"\n" print("-> {}".format(data.decode("utf-8").strip("\n"))) self.socket.send(data) - - def restart(self): - print('Disconnected... Restarting IRC Object for: %s' % network) - time.sleep(1) - del networkobjects[network] - networkobjects[network] = Irc(network) - def relay(self, line): - for network in networkobjects.values(): - self.proto.handle_events(self, line) - -for network in conf['networks']: - print('Creating IRC Object for: %s' % network) - networkobjects[network] = Irc(network) - networkobjects[network].start() +irc_obj = Irc() diff --git a/protocols/inspircd.py b/protocols/inspircd.py index c8732c7..0395f9f 100644 --- a/protocols/inspircd.py +++ b/protocols/inspircd.py @@ -70,7 +70,6 @@ def handle_events(irc, data): numeric = args[0] command = args[1] - print(args) except IndexError: return