-
Notifications
You must be signed in to change notification settings - Fork 4
/
client.py
73 lines (52 loc) · 1.9 KB
/
client.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python2.6
#MineBot
#GPL and all that
# - espes
import urllib
import logging
from twisted.internet import reactor
from twisted.python import log
from BotProtocol import BotFactory
from Interface import CommandLineBotInterface, runReactorWithTerminal
from settings import *
#twisted idiom fail, yeah
def main():
logging.basicConfig(filename="client.log", level=logging.DEBUG)
observer = log.PythonLoggingObserver()
observer.start()
from sys import argv
from getpass import getpass
loginname = argv[1]
server = argv[2]
port = int(argv[3])
botname = None
if len(argv) >= 5:
botname = argv[4]
if ENABLE_AUTH:
password = getpass()
logging.info("Logging in")
params = urllib.urlencode({'user': loginname, 'password': password, 'version': 9001})
handler = urllib.urlopen("http://www.minecraft.net/game/getversion.jsp", params)
ret = handler.read()
if ret == "Bad login":
logging.error(ret)
return -1
version, downloadTicket, username, sessionId, _ = ret.split(":")
logging.info("Got %r %r %r %r" % (version, downloadTicket, username, sessionId))
if not botname: botname = username
else:
sessionId = 0
if not botname: botname = loginname
username = botname
interfaceNamespace = {}
f = BotFactory(username, sessionId, botname, interfaceNamespace)
reactor.connectTCP(server, port, f)
if ENABLE_CONSOLE:
#start with a null oberserver to remove DefaultObserver
#because we can't stderr in a terminal
log.startLoggingWithObserver(lambda a: '')
runReactorWithTerminal(CommandLineBotInterface, interfaceNamespace)
else:
reactor.run()
if __name__ == '__main__':
main()