mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-30 14:49:28 +01:00
Turn spawn pseudoclient and JOIN into its own functions, and move IrcUser/IrcServer to its own module
These classes are protocol independent, so we may as well split them for future protocol modules.
This commit is contained in:
parent
a0babeddcd
commit
c33d5922c6
24
classes.py
Normal file
24
classes.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
class IrcUser():
|
||||||
|
def __init__(self, nick, ts, uid, ident='null', host='null',
|
||||||
|
realname='PyLink dummy client', realhost='null',
|
||||||
|
ip='0.0.0.0'):
|
||||||
|
self.nick = nick
|
||||||
|
self.ts = ts
|
||||||
|
self.uid = uid
|
||||||
|
self.ident = ident
|
||||||
|
self.host = host
|
||||||
|
self.realhost = realhost
|
||||||
|
self.ip = ip
|
||||||
|
self.realname = realname
|
||||||
|
|
||||||
|
self.identified = False
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return repr(self.__dict__)
|
||||||
|
|
||||||
|
class IrcServer():
|
||||||
|
def __init__(self, uplink):
|
||||||
|
self.uplink = uplink
|
||||||
|
self.users = []
|
||||||
|
def __repr__(self):
|
||||||
|
return repr(self.__dict__)
|
58
proto.py
58
proto.py
@ -4,31 +4,7 @@ import sys
|
|||||||
from utils import *
|
from utils import *
|
||||||
from copy import copy
|
from copy import copy
|
||||||
import traceback
|
import traceback
|
||||||
|
from classes import *
|
||||||
class IrcUser():
|
|
||||||
def __init__(self, nick, ts, uid, ident='null', host='null',
|
|
||||||
realname='PyLink dummy client', realhost='null',
|
|
||||||
ip='0.0.0.0'):
|
|
||||||
self.nick = nick
|
|
||||||
self.ts = ts
|
|
||||||
self.uid = uid
|
|
||||||
self.ident = ident
|
|
||||||
self.host = host
|
|
||||||
self.realhost = realhost
|
|
||||||
self.ip = ip
|
|
||||||
self.realname = realname
|
|
||||||
|
|
||||||
self.identified = False
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return repr(self.__dict__)
|
|
||||||
|
|
||||||
class IrcServer():
|
|
||||||
def __init__(self, uplink):
|
|
||||||
self.uplink = uplink
|
|
||||||
self.users = []
|
|
||||||
def __repr__(self):
|
|
||||||
return repr(self.__dict__)
|
|
||||||
|
|
||||||
def _sendFromServer(irc, msg):
|
def _sendFromServer(irc, msg):
|
||||||
irc.send(':%s %s' % (irc.sid, msg))
|
irc.send(':%s %s' % (irc.sid, msg))
|
||||||
@ -43,23 +19,26 @@ def _nicktoUid(irc, nick):
|
|||||||
if v.nick == nick:
|
if v.nick == nick:
|
||||||
return k
|
return k
|
||||||
|
|
||||||
def spawnClient(irc, nick, user, host, *args):
|
def spawnClient(irc, nick, ident, host, *args):
|
||||||
uid = next_uid(irc.sid)
|
uid = next_uid(irc.sid)
|
||||||
_sendFromServer(irc, "UID {uid} {ts} {nick} {host} {host} {user} 0.0.0.0 {ts} +o +"
|
ts = int(time.time())
|
||||||
" :PyLink Client".format(ts=int(time.time()), host=host,
|
_sendFromServer(irc, "UID {uid} {ts} {nick} {host} {host} {ident} 0.0.0.0 {ts} +o +"
|
||||||
nick=nick, user=user, uid=uid))
|
" :PyLink Client".format(ts=ts, host=host,
|
||||||
irc.users[uid] = IrcUser(nick, ts, uid, ident, host, *args)
|
nick=nick, ident=ident, uid=uid))
|
||||||
|
u = irc.users[uid] = IrcUser(nick, ts, uid, ident, host, *args)
|
||||||
irc.servers[irc.sid].users.append(uid)
|
irc.servers[irc.sid].users.append(uid)
|
||||||
|
return u
|
||||||
|
|
||||||
|
def joinClient(irc, client, channel):
|
||||||
|
# Channel list can be a comma-separated list of channels, per the
|
||||||
|
# IRC specification.
|
||||||
|
_sendFromUser(irc, "JOIN {channel} {ts} +nt :,{uid}".format(sid=irc.sid,
|
||||||
|
ts=int(time.time()), uid=client.uid, channel=channel))
|
||||||
|
|
||||||
def connect(irc):
|
def connect(irc):
|
||||||
irc.start_ts = ts = int(time.time())
|
irc.start_ts = ts = int(time.time())
|
||||||
host = irc.serverdata["hostname"]
|
host = irc.serverdata["hostname"]
|
||||||
uid = next_uid(irc.sid)
|
|
||||||
irc.pseudoclient = IrcUser('PyLink', ts, uid, 'pylink', host,
|
|
||||||
'PyLink Client')
|
|
||||||
irc.users[uid] = irc.pseudoclient
|
|
||||||
irc.servers[irc.sid] = IrcServer(None)
|
irc.servers[irc.sid] = IrcServer(None)
|
||||||
irc.servers[irc.sid].users = [uid]
|
|
||||||
|
|
||||||
f = irc.send
|
f = irc.send
|
||||||
f('CAPAB START 1203')
|
f('CAPAB START 1203')
|
||||||
@ -75,14 +54,9 @@ def connect(irc):
|
|||||||
# :751 UID 751AAAAAA 1220196319 Brain brainwave.brainbox.cc
|
# :751 UID 751AAAAAA 1220196319 Brain brainwave.brainbox.cc
|
||||||
# netadmin.chatspike.net brain 192.168.1.10 1220196324 +Siosw
|
# netadmin.chatspike.net brain 192.168.1.10 1220196324 +Siosw
|
||||||
# +ACKNOQcdfgklnoqtx :Craig Edwards
|
# +ACKNOQcdfgklnoqtx :Craig Edwards
|
||||||
f(":{sid} UID {uid} {ts} PyLink {host} {host} pylink 0.0.0.0 {ts} +o +"
|
irc.pseudoclient = spawnClient(irc, 'PyLink', 'pylink', host)
|
||||||
" :PyLink Client".format(sid=irc.sid, ts=ts,
|
|
||||||
host=host,
|
|
||||||
uid=uid))
|
|
||||||
f(':%s ENDBURST' % (irc.sid))
|
f(':%s ENDBURST' % (irc.sid))
|
||||||
for channel in irc.serverdata['channels']:
|
joinClient(irc, irc.pseudoclient, ','.join(irc.serverdata['channels']))
|
||||||
_sendFromUser(irc, "JOIN {channel} {ts} +nt :,{uid}".format(sid=irc.sid,
|
|
||||||
ts=int(time.time()), uid=irc.pseudoclient.uid, channel=channel))
|
|
||||||
|
|
||||||
# :7NU PING 7NU 0AL
|
# :7NU PING 7NU 0AL
|
||||||
def handle_ping(irc, servernumeric, command, args):
|
def handle_ping(irc, servernumeric, command, args):
|
||||||
|
Loading…
Reference in New Issue
Block a user