3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 01:09:22 +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 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

View File

@ -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"

40
main.py
View File

@ -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()

View File

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