mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 09:19:23 +01:00
add a make-next-uid function and rename pylink-main.py -> main.py
The "I really hate Python imports" update.
This commit is contained in:
parent
7a62a655a3
commit
b1a989c971
@ -19,13 +19,20 @@ with open("config.yml", 'r') as f:
|
|||||||
global networkobjects
|
global networkobjects
|
||||||
networkobjects = {}
|
networkobjects = {}
|
||||||
|
|
||||||
class irc(multiprocessing.Process):
|
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):
|
def __init__(self, network):
|
||||||
multiprocessing.Process.__init__(self)
|
multiprocessing.Process.__init__(self)
|
||||||
self.authenticated = False
|
# Initialize some variables
|
||||||
self.connected = False
|
|
||||||
self.socket = socket.socket()
|
self.socket = socket.socket()
|
||||||
self.kill_received = False
|
self.kill_received = False
|
||||||
|
self.users = {}
|
||||||
|
self.name = network
|
||||||
|
|
||||||
self.serverdata = conf['networks'][network]
|
self.serverdata = conf['networks'][network]
|
||||||
ip = self.serverdata["ip"]
|
ip = self.serverdata["ip"]
|
||||||
@ -33,7 +40,7 @@ class irc(multiprocessing.Process):
|
|||||||
self.sid = self.serverdata["sid"]
|
self.sid = self.serverdata["sid"]
|
||||||
print("[+] New thread started for %s:%s" % (ip, port))
|
print("[+] New thread started for %s:%s" % (ip, port))
|
||||||
|
|
||||||
self.name = network
|
|
||||||
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
|
||||||
# allowed from normal applications ran from the command line. Instead,
|
# allowed from normal applications ran from the command line. Instead,
|
||||||
@ -73,7 +80,7 @@ class irc(multiprocessing.Process):
|
|||||||
print('Disconnected... Restarting IRC Object for: %s' % network)
|
print('Disconnected... Restarting IRC Object for: %s' % network)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
del networkobjects[network]
|
del networkobjects[network]
|
||||||
networkobjects[network] = irc(network)
|
networkobjects[network] = Irc(network)
|
||||||
|
|
||||||
def relay(self, line):
|
def relay(self, line):
|
||||||
for network in networkobjects.values():
|
for network in networkobjects.values():
|
||||||
@ -81,5 +88,5 @@ class irc(multiprocessing.Process):
|
|||||||
|
|
||||||
for network in conf['networks']:
|
for network in conf['networks']:
|
||||||
print('Creating IRC Object for: %s' % network)
|
print('Creating IRC Object for: %s' % network)
|
||||||
networkobjects[network] = irc(network)
|
networkobjects[network] = Irc(network)
|
||||||
networkobjects[network].start()
|
networkobjects[network].start()
|
@ -2,21 +2,41 @@ import threading
|
|||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
|
import string
|
||||||
|
|
||||||
class AuthenticationError:
|
# Ugh... damn you, Python imports!
|
||||||
pass
|
from os import sys, path
|
||||||
|
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
|
||||||
|
from main import IrcUser
|
||||||
|
|
||||||
|
# From http://www.inspircd.org/wiki/Modules/spanningtree/UUIDs.html
|
||||||
|
chars = string.digits + string.ascii_uppercase
|
||||||
|
iters = [iter(chars) for _ in range(6)]
|
||||||
|
a = [next(i) for i in iters]
|
||||||
|
|
||||||
|
def next_uid(sid, level=-1):
|
||||||
|
try:
|
||||||
|
a[level] = next(iters[level])
|
||||||
|
return sid + ''.join(a)
|
||||||
|
except StopIteration:
|
||||||
|
return UID(level-1)
|
||||||
|
|
||||||
|
def connect(irc):
|
||||||
|
ts = int(time.time())
|
||||||
|
u = IrcUser('PyLink', ts)
|
||||||
|
u.data['uid'] = our_uid = next_uid(irc.sid)
|
||||||
|
irc.users['PyLink'] = u
|
||||||
|
|
||||||
def authenticate(irc):
|
|
||||||
f = irc.send
|
f = irc.send
|
||||||
f('CAPAB START 1202')
|
f('CAPAB START 1202')
|
||||||
f('CAPAB CAPABILITIES :NICKMAX=32 HALFOP=0 CHANMAX=65 MAXMODES=20 IDENTMAX=12 MAXQUIT=255 PROTOCOL=1203')
|
f('CAPAB CAPABILITIES :NICKMAX=32 HALFOP=0 CHANMAX=65 MAXMODES=20 IDENTMAX=12 MAXQUIT=255 PROTOCOL=1203')
|
||||||
f('CAPAB END')
|
f('CAPAB END')
|
||||||
f('SERVER %s %s 0 %s :PyLink Service' % (irc.serverdata["hostname"],
|
f('SERVER %s %s 0 %s :PyLink Service' % (irc.serverdata["hostname"],
|
||||||
irc.serverdata["sendpass"], irc.sid))
|
irc.serverdata["sendpass"], irc.sid))
|
||||||
f(':%s BURST %s' % (irc.sid, int(time.time())))
|
f(':%s BURST %s' % (irc.sid, ts))
|
||||||
# :751 UID 751AAAAAA 1220196319 Brain brainwave.brainbox.cc netadmin.chatspike.net brain 192.168.1.10 1220196324 +Siosw +ACKNOQcdfgklnoqtx :Craig Edwards
|
# :751 UID 751AAAAAA 1220196319 Brain brainwave.brainbox.cc netadmin.chatspike.net brain 192.168.1.10 1220196324 +Siosw +ACKNOQcdfgklnoqtx :Craig Edwards
|
||||||
f(":{sid} UID {sid}AAAAAA {ts} PyLink {host} {host} pylink 127.0.0.1 {ts} +o + :PyLink Client".format(sid=irc.sid,
|
f(":{sid} UID {uid} {ts} PyLink {host} {host} pylink 127.0.0.1 {ts} +o + :PyLink Client".format(sid=irc.sid,
|
||||||
ts=int(time.time()), host=irc.serverdata["hostname"]))
|
ts=ts, host=irc.serverdata["hostname"], uid=our_uid))
|
||||||
f(':%s ENDBURST' % (irc.sid))
|
f(':%s ENDBURST' % (irc.sid))
|
||||||
|
|
||||||
# :7NU PING 7NU 0AL
|
# :7NU PING 7NU 0AL
|
||||||
@ -59,6 +79,3 @@ def handle_events(irc, data):
|
|||||||
func(irc, numeric, command, args)
|
func(irc, numeric, command, args)
|
||||||
except KeyError: # unhandled event
|
except KeyError: # unhandled event
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def connect(irc):
|
|
||||||
authenticate(irc)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user