Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from twisted.conch import telnet
- from twisted.internet import protocol, reactor
- from nevow.livepage import eol, set, js
- from cgi import escape
- # if first chunk contains following sequence we send back rtclient\n
- # so they know it is ok to send html
- #HOWDY_SEQUENCE = "Welcome to Evennia!"
- HTML_TOKEN = chr(240)
- JAVASCRIPT_TOKEN = chr(241)
- UNENCODED_TOKEN = chr(242)
- NO_AUTOCHUNK_TOKEN = chr(243)
- AUTOCHUNK_TOKEN = chr(244)
- ENCODING_TOKENS = [HTML_TOKEN, JAVASCRIPT_TOKEN, UNENCODED_TOKEN, AUTOCHUNK_TOKEN, NO_AUTOCHUNK_TOKEN]
- from random import randint
- class ProxyTelnetClient(telnet.TelnetTransport):
- mode = 'WaitForUser'
- def connectionMade(self):
- pass
- def gotClient(self):
- self.transport.write("ProxyKeyLogin %s\r\n" % self.client.key)
- def dataReceived(self, chunk):
- """ data received FROM the MUD """
- self.client.transport.write(chunk)
- def telnet_WaitForUser(self, line):
- if line.startswith('Username: '):
- self.client.write(self.factory.username + '\r\n')
- return 'WaitForPassword'
- def telnet_WaitForPassword(self, line):
- print "wfp"
- if line.startswith('Password: '):
- self.write(self.factory.password + '\r\n')
- # Instead of this, you could do another state,
- # like "WaitForPrompt" or something.
- reactor.callLater(1, self.reboot)
- return 'Idling'
- def telnet_Idling(self, line):
- print "idle"
- # La la la.
- pass
- def reboot(self):
- self.write('reboot\r\n')
- # This will make us lose our connection after the next
- # line is received. To lose it faster, use
- # self.transport.loseConnection() instead
- self.mode = 'Done'
- def connectionLost(self, reason):
- #self.client.sendLine("Connection lost!!!")
- self.transport.loseConnection()
- if self.client.protocol:
- print "prepping another session"
- self.client.prep_session()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement