Хранилища Subversion pytwidcpp

Сравнить редакции

Учитывать пробелы Редакция 1 → Редакция HEAD

/trunk/tools/__init__.py
Новый файл
0,0 → 1,2
# -*- coding: utf-8 -*-
""" Direct Connect tools package"""
/trunk/tools/dctools.py
Новый файл
0,0 → 1,18
# -*- coding: utf-8 -*-
import sys
 
def createKey(lock):
""" Function create key from lock for DC connections. """
key = {}
for i in xrange(1, len(lock)):
key[i] = ord(lock[i]) ^ ord(lock[i-1])
key[0] = ord(lock[0]) ^ ord(lock[len(lock)-1]) ^ ord(lock[len(lock)-2]) ^ 5
for i in xrange(0, len(lock)):
key[i] = ((key[i]<<4) & 240) | ((key[i]>>4) & 15)
out = ''
for i in xrange(0, len(lock)):
out += unichr(key[i])
out = out.replace(u'\0', u'/%DCN000%/').replace(u'\5', u'/%DCN005%/').replace(u'\44', u'/%DCN036%/')
out = out.replace(u'\140', u'/%DCN096%/').replace(u'\174', u'/%DCN124%/').replace(u'\176', u'/%DCN126%/')
return out
 
/trunk/client.py
Новый файл
0,0 → 1,31
# -*- coding: utf-8 -*-
""" DC++ Networks Client"""
 
from twisted.internet import reactor, protocol
from nmdc import NMDCClientToHub
 
class NMDCFactory(protocol.ClientFactory):
protocol=NMDCClientToHub
 
def startedConnecting(self, connector):
print "Started Connecting"
pass
 
def clientConnectionFailed(self, connector, reason):
print "Connection Failed"
reactor.stop()
 
def clientConnectionLost(self, connector, reason):
print "Connection Lost"
reactor.stop()
 
 
# this connects the protocol to a server runing on port 8000
def main():
f = NMDCFactory()
reactor.connectTCP("127.0.0.1", 31337 , f)
reactor.run()
 
# this only runs if the module was *not* imported
if __name__ == '__main__':
main()
/trunk/__init__.py
Новый файл
0,0 → 1,3
# -*- coding: utf-8 -*-
""" Python-twisted NMDC/ADC Client/Library """
 
/trunk/nmdc.py
Новый файл
0,0 → 1,105
# -*- coding: utf-8 -*-
""" Neo-Modus Direct Connect Protocol Package """
from protocol import NMDC
 
class NMDCClientToHub(NMDC):
def nmdc_BadPass(self):
pass
 
def nmdc_BotList(self):
pass
 
def nmdc_Close(self):
pass
 
def nmdc_ConnectToMe(self):
pass
 
def nmdc_ForceMove(self):
pass
 
def nmdc_GetNickList(self):
pass
 
def nmdc_GetPass(self):
pass
def nmdc_Hello(self, params):
self.sendLine("$Version 1,0091|$GetNickList|$MyINFO $ALL twistedbot TEST<++ V:0.698,M:A,H:1/0/0,S:5>$ $0.005$$0$|")
#self.makeAnswer("Version","1,0099")
#self.makeAnswer("GetNickList","")
#self.makeAnswer("MyINFO","$ALL twistedbot<++ V:0.698,M:A,H:1/0/0,S:5>$ $0.005$$0$")
 
def nmdc_HubIsFull(self):
pass
 
def nmdc_HubName(self, params):
pass
 
def nmdc_HubTopic(self):
pass
 
def nmdc_Key(self, params):
print "nmdc_Key"
pass
 
def nmdc_Kick(self):
pass
 
def nmdc_Lock(self, params):
from tools.dctools import createKey
keylock = createKey(params)
print "nmdc_Lock: %s" %keylock
self.makeAnswer("Supports",
"UserCommand NoGetINFO NoHello UserIP2 TTHSearch ZPipe0")
self.makeAnswer("Key", keylock)
self.makeAnswer("ValidateNick", "twistedbot")
 
def nmdc_LogedIn(self):
pass
 
def nmdc_MyINFO(self):
pass
 
def nmdc_MyPass(self):
pass
 
def nmdc_NickList(self):
pass
 
def nmdc_OpForceMove(self):
pass
 
def nmdc_OpList(self):
pass
 
def nmdc_Quit(self):
pass
 
def nmdc_RevConnectToMe(self):
pass
 
def nmdc_Search(self):
pass
 
def nmdc_SR(self):
pass
 
def nmdc_Supports(self, params):
pass
 
def nmdc_UserCommand(self):
pass
 
def nmdc_UserIP(self, params):
print "nmdc_UserIP: %s" % params
 
def nmdc_Version(self):
pass
 
def nmdc_ValidateNick(self):
pass
 
def nmdc_ValidateDenide(self):
pass
 
/trunk/protocol.py
Новый файл
0,0 → 1,78
Я -*- coding: utf-8 -*-
""" PyCODC NMDC/ADC Client """
from twisted.internet import protocol
from twisted.protocols import basic
from twisted.python import log
 
import socket
import re
 
class NMDC(basic.LineReceiver):
"""
NMDC Protocol implementation
"""
 
delimiter = "|"
 
buffer = ""
encoding = None
hostname = None
 
def lineReceived(self, line):
print "Line Received: %s" % line
self.parseLine(line)
 
def connectionLost(self, reason):
print "Conlost: %s" %self
 
def connectionMade(self):
print "Made connect"
if self.hostname is None:
self.hostname = socket.getfqdn()
 
def sendLine(self, line):
_to_send = line.encode('utf-8')
self.transport.write(_to_send)
 
def parseLine(self, line):
"""
Returns NMDC command and params
"""
print "parse: %s" % line
if line.startswith("$"):
try:
m = re.match("^\$(?P<command>[a-zA-Z]+)[ ](?P<params>.+$)", line)
 
command = m.group("command")
params = m.group("params")
self.handleCommand(command, params)
except:
print "Exception: %s"% line
 
def handleCommand(self, command, params):
print "handleCommand: %s %s" % (command, params)
method = getattr(self, "nmdc_%s" % command, None)
try:
if method is not None:
method(params)
else: self.nmdc_unknown(command, params)
except:
print "handleCommand except"
log.deferr()
pass
 
def makeAnswer(self, command, params):
if params is not "":
answer = "$%s %s|" % (command, params)
else:
answer = "$%s|"% command
 
self.sendLine(answer)
print "makeAnswer: %s" % answer
 
def nmdc_rawline(self, line):
print "rawline: %s"% line
 
def nmdc_unknown(self, command):
print "nmdc_%s doesn't exist." % command