-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBotProtocol.py
46 lines (33 loc) · 1.35 KB
/
BotProtocol.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#MineBot
#GPL and all that
# - espes
from __future__ import division
from twisted.internet import reactor, protocol
from packets import *
from BotClient import *
from MCProtocol import MCBaseClientProtocol
class BotProtocol(MCBaseClientProtocol):
def connectionMade(self):
MCBaseClientProtocol.connectionMade(self)
self.client = BotClient(self, self.factory.botname)
if self.factory.interfaceNamespace is not None:
self.factory.interfaceNamespace[self.factory.botname] = self.client
def _handleLogin(self, parts):
MCBaseClientProtocol._handleLogin(self, parts)
self.client.start()
class BotFactory(protocol.ClientFactory):#ReconnectingClientFactory
protocol = BotProtocol
def __init__(self, username, sessionId, botname=None, interfaceNamespace=None):
self.username = username
self.sessionId = sessionId
if botname is None:
self.botname = username
else:
self.botname = botname
self.interfaceNamespace = interfaceNamespace
def clientConnectionFailed(self, connector, reason):
logging.error("Connection failed.")
if reactor.running: reactor.stop()
def clientConnectionLost(self, connector, reason):
logging.error("Connection terminated.")
if reactor.running: reactor.stop()