3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 09:19:23 +01:00

Change of plans, we're now just a regular pseudoservice

- Remove multinet support
- Update config.yml.example
This commit is contained in:
James Lu 2015-04-17 19:55:48 -07:00
parent 2c73424e86
commit c074d58052
4 changed files with 22 additions and 38 deletions

View File

@ -1,6 +1,6 @@
# PyLink # 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 ## Dependencies

View File

@ -9,17 +9,18 @@ login:
user: admin user: admin
password: changeme password: changeme
networks: server:
mynet:
# Server name, port, and passwords # Server name, port, and passwords
netname: whatever
ip: 127.0.0.1 ip: 127.0.0.1
port: 6667 port: 7000
recvpass: "abcdefg" recvpass: "abcd"
sendpass: "gfedcba" sendpass: "abcd"
# Hostname we will use to connect to the remote server # 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. # 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. # The first char must be a digit [0-9], and the remaining two chars may be letters [A-Z] or digits.
sid: "0AL" sid: "0AL"
# Set protocol module (currently only a null stub is available, but this will change in the future) # Set protocol module
protocol: stub protocol: inspircd
channel: "#pylink"

40
main.py
View File

@ -16,30 +16,25 @@ with open("config.yml", 'r') as f:
# if conf['login']['password'] == 'changeme': # if conf['login']['password'] == 'changeme':
# print("You have not set the login details correctly! Exiting...") # print("You have not set the login details correctly! Exiting...")
global networkobjects
networkobjects = {}
class IrcUser(): class IrcUser():
def __init__(self, nick, timestamp, data={'uid': None}): def __init__(self, nick, timestamp, data={'uid': None}):
self.nick = nick self.nick = nick
self.data = data self.data = data
self.timestamp = timestamp self.timestamp = timestamp
class Irc(multiprocessing.Process): class Irc():
def __init__(self, network): def __init__(self):
multiprocessing.Process.__init__(self)
# Initialize some variables # Initialize some variables
self.socket = socket.socket() self.socket = socket.socket()
self.kill_received = False self.connected = False
self.users = {} self.users = {}
self.name = network self.name = conf['server']['netname']
self.serverdata = conf['networks'][network] self.serverdata = conf['server']
ip = self.serverdata["ip"] ip = self.serverdata["ip"]
port = self.serverdata["port"] port = self.serverdata["port"]
self.sid = self.serverdata["sid"] 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'] protoname = self.serverdata['protocol']
# With the introduction of Python 3, relative imports are no longer # With the introduction of Python 3, relative imports are no longer
@ -57,9 +52,11 @@ class Irc(multiprocessing.Process):
self.socket = socket.socket() self.socket = socket.socket()
self.socket.connect((ip, port)) self.socket.connect((ip, port))
self.proto.connect(self) self.proto.connect(self)
self.connected = True
self.run()
def run(self): def run(self):
while not self.kill_received: while self.connected:
try: try:
data = self.socket.recv(1024) data = self.socket.recv(1024)
if data: if data:
@ -68,25 +65,12 @@ class Irc(multiprocessing.Process):
print("<- {}".format(line)) print("<- {}".format(line))
self.proto.handle_events(self, line) self.proto.handle_events(self, line)
except socket.error: except socket.error:
self.restart() print('Received socket.error: %s, exiting.' % str(e))
break self.connected = False
def send(self, data): def send(self, data):
data = data.encode("utf-8") + b"\n" data = data.encode("utf-8") + b"\n"
print("-> {}".format(data.decode("utf-8").strip("\n"))) print("-> {}".format(data.decode("utf-8").strip("\n")))
self.socket.send(data) self.socket.send(data)
def restart(self): irc_obj = Irc()
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()

View File

@ -70,7 +70,6 @@ def handle_events(irc, data):
numeric = args[0] numeric = args[0]
command = args[1] command = args[1]
print(args)
except IndexError: except IndexError:
return return