Fix DCC connexion
This commit is contained in:
parent
64d4997605
commit
52995e3f0e
22
DCC.py
22
DCC.py
|
@ -51,6 +51,7 @@ class DCC(threading.Thread):
|
||||||
|
|
||||||
# Keep the server
|
# Keep the server
|
||||||
self.srv = srv
|
self.srv = srv
|
||||||
|
self.treatement = self.treat_msg
|
||||||
|
|
||||||
# Found a port for the connection
|
# Found a port for the connection
|
||||||
self.port = self.foundPort()
|
self.port = self.foundPort()
|
||||||
|
@ -146,6 +147,9 @@ class DCC(threading.Thread):
|
||||||
print ('Connected by', addr)
|
print ('Connected by', addr)
|
||||||
self.connected = True
|
self.connected = True
|
||||||
|
|
||||||
|
def send_dcc_raw(self, line):
|
||||||
|
self.conn.sendall(line + b'\n')
|
||||||
|
|
||||||
def send_dcc(self, msg, to = None):
|
def send_dcc(self, msg, to = None):
|
||||||
"""If we talk to this user, send a message through this connection
|
"""If we talk to this user, send a message through this connection
|
||||||
else, send the message to the server class"""
|
else, send the message to the server class"""
|
||||||
|
@ -159,7 +163,7 @@ class DCC(threading.Thread):
|
||||||
self.messages.append(msg)
|
self.messages.append(msg)
|
||||||
else:
|
else:
|
||||||
for line in msg.split("\n"):
|
for line in msg.split("\n"):
|
||||||
self.conn.sendall(line.encode() + b'\n')
|
self.send_dcc_raw(line.encode())
|
||||||
else:
|
else:
|
||||||
self.srv.send_dcc(msg, to)
|
self.srv.send_dcc(msg, to)
|
||||||
|
|
||||||
|
@ -201,8 +205,8 @@ class DCC(threading.Thread):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
readbuffer = b''
|
readbuffer = b''
|
||||||
nicksize = len(self.srv.nick)
|
self.nicksize = len(self.srv.nick)
|
||||||
Bnick = self.srv.nick.encode()
|
self.Bnick = self.srv.nick.encode()
|
||||||
while not self.stop:
|
while not self.stop:
|
||||||
raw = self.conn.recv(1024) #recieve server messages
|
raw = self.conn.recv(1024) #recieve server messages
|
||||||
if not raw:
|
if not raw:
|
||||||
|
@ -212,7 +216,7 @@ class DCC(threading.Thread):
|
||||||
readbuffer = temp.pop()
|
readbuffer = temp.pop()
|
||||||
|
|
||||||
for line in temp:
|
for line in temp:
|
||||||
self.treat_msg(line)
|
self.treatement(line)
|
||||||
|
|
||||||
if self.connected:
|
if self.connected:
|
||||||
self.conn.close()
|
self.conn.close()
|
||||||
|
@ -223,9 +227,13 @@ class DCC(threading.Thread):
|
||||||
|
|
||||||
def treat_msg(self, line):
|
def treat_msg(self, line):
|
||||||
"""Treat a receive message, *can be overwritten*"""
|
"""Treat a receive message, *can be overwritten*"""
|
||||||
if (line[:nicksize] == Bnick and
|
if line == b'NEMUBOT###':
|
||||||
line[nicksize+1:].strip()[:10] == b'my name is'):
|
bot = self.srv.context.add_networkbot(self.srv, self.sender, self)
|
||||||
name = line[nicksize+1:].strip()[11:].decode('utf-8',
|
self.treatement = bot.treat_msg
|
||||||
|
self.send_dcc("NEMUBOT###")
|
||||||
|
elif (line[:self.nicksize] == self.Bnick and
|
||||||
|
line[self.nicksize+1:].strip()[:10] == b'my name is'):
|
||||||
|
name = line[self.nicksize+1:].strip()[11:].decode('utf-8',
|
||||||
'replace')
|
'replace')
|
||||||
if re.match("^[a-zA-Z0-9_-]+$", name):
|
if re.match("^[a-zA-Z0-9_-]+$", name):
|
||||||
if name not in self.srv.dcc_clients:
|
if name not in self.srv.dcc_clients:
|
||||||
|
|
17
message.py
17
message.py
|
@ -23,7 +23,7 @@ import time
|
||||||
|
|
||||||
import credits
|
import credits
|
||||||
from credits import Credits
|
from credits import Credits
|
||||||
import DCC
|
from DCC import DCC
|
||||||
import xmlparser
|
import xmlparser
|
||||||
|
|
||||||
CREDITS = {}
|
CREDITS = {}
|
||||||
|
@ -102,13 +102,13 @@ class Message:
|
||||||
|
|
||||||
def pickWords(self, words):
|
def pickWords(self, words):
|
||||||
"""Parse last argument of a line: can be a single word or a sentence starting with :"""
|
"""Parse last argument of a line: can be a single word or a sentence starting with :"""
|
||||||
if len(words) > 0:
|
if len(words) > 0 and len(words[0]) > 0:
|
||||||
if words[0][0] == 58:
|
if words[0][0] == 58:
|
||||||
return b' '.join(words[0:])[1:]
|
return b' '.join(words[0:])[1:]
|
||||||
else:
|
else:
|
||||||
return words[0]
|
return words[0]
|
||||||
else:
|
else:
|
||||||
return ""
|
return b''
|
||||||
|
|
||||||
def decode(self):
|
def decode(self):
|
||||||
"""Decode the content string usign a specific encoding"""
|
"""Decode the content string usign a specific encoding"""
|
||||||
|
@ -197,17 +197,18 @@ class Message:
|
||||||
elif self.content == '\x01USERINFO\x01':
|
elif self.content == '\x01USERINFO\x01':
|
||||||
self.srv.send_ctcp(self.sender, "USERINFO %s" % (self.srv.realname))
|
self.srv.send_ctcp(self.sender, "USERINFO %s" % (self.srv.realname))
|
||||||
elif self.content == '\x01VERSION\x01':
|
elif self.content == '\x01VERSION\x01':
|
||||||
self.srv.send_ctcp(self.sender, "VERSION nemubot v%d"%VERSION)
|
self.srv.send_ctcp(self.sender, "VERSION nemubot v%s" % self.srv.context.version_txt)
|
||||||
elif self.content[:9] == '\x01DCC CHAT':
|
elif self.content[:9] == '\x01DCC CHAT':
|
||||||
words = self.content[1:len(self.content) - 1].split(' ')
|
words = self.content[1:len(self.content) - 1].split(' ')
|
||||||
ip = self.srv.toIP(int(words[3]))
|
ip = self.srv.toIP(int(words[3]))
|
||||||
fullname = "guest" + words[4] + words[3] +"!guest" + words[4] + words[3] + "@" + ip
|
conn = DCC(self.srv, self.sender)
|
||||||
conn = dcc.DCC(self.srv, fullname)
|
|
||||||
if conn.accept_user(ip, int(words[4])):
|
if conn.accept_user(ip, int(words[4])):
|
||||||
self.srv.dcc_clients[conn.sender] = conn
|
self.srv.dcc_clients[conn.sender] = conn
|
||||||
conn.send_dcc("Hi %s. To changes your name, say \"%s: my name is yournickname\"." % (conn.nick, self.srv.nick))
|
conn.send_dcc("Hello %s!" % conn.nick)
|
||||||
else:
|
else:
|
||||||
print ("DCC: unable to connect to %s:%s" % (ip, words[4]))
|
print ("DCC: unable to connect to %s:%s" % (ip, words[4]))
|
||||||
|
elif self.content == '\x01NEMUBOT\x01':
|
||||||
|
self.srv.send_ctcp(self.sender, "NEMUBOT %f" % self.srv.context.version)
|
||||||
elif self.content[:7] != '\x01ACTION':
|
elif self.content[:7] != '\x01ACTION':
|
||||||
print (self.content)
|
print (self.content)
|
||||||
self.srv.send_ctcp(self.sender, "ERRMSG Unknown or unimplemented CTCP request")
|
self.srv.send_ctcp(self.sender, "ERRMSG Unknown or unimplemented CTCP request")
|
||||||
|
@ -288,7 +289,7 @@ class Message:
|
||||||
self.send_snd("Test DCC")
|
self.send_snd("Test DCC")
|
||||||
elif self.cmd[0] == "dccsendtest":
|
elif self.cmd[0] == "dccsendtest":
|
||||||
print("dccsendtest")
|
print("dccsendtest")
|
||||||
conn = dcc.DCC(self.srv, self.sender)
|
conn = DCC(self.srv, self.sender)
|
||||||
conn.send_file("bot_sample.xml")
|
conn.send_file("bot_sample.xml")
|
||||||
else:
|
else:
|
||||||
hooks.treat_cmd(self)
|
hooks.treat_cmd(self)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user