2012-04-05 04:56:21 +02:00
|
|
|
import getpass
|
|
|
|
import sys
|
2012-10-26 02:02:42 +02:00
|
|
|
from optparse import OptionParser
|
2014-10-08 19:12:37 +02:00
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
import authentication
|
2012-04-30 19:05:06 +02:00
|
|
|
|
2014-10-08 19:12:37 +02:00
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
def main():
|
2012-10-26 02:02:42 +02:00
|
|
|
parser = OptionParser()
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
parser.add_option("-u", "--username", dest="username", default=None,
|
2014-10-08 19:12:37 +02:00
|
|
|
help="username to log in with")
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
parser.add_option("-p", "--password", dest="password", default=None,
|
2014-10-08 19:12:37 +02:00
|
|
|
help="password to log in with")
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
parser.add_option("-s", "--server", dest="server", default=None,
|
2014-10-08 19:12:37 +02:00
|
|
|
help="server to connect to")
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
(options, args) = parser.parse_args()
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
if not options.username:
|
|
|
|
options.username = raw_input("Enter your username: ")
|
2012-12-31 03:20:06 +01:00
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
if not options.password:
|
|
|
|
options.password = getpass.getpass("Enter your password: ")
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2015-03-17 18:15:27 +01:00
|
|
|
try:
|
|
|
|
login_response = authentication.login_to_minecraft(options.username, options.password)
|
|
|
|
from pprint import pprint # TODO: remove debug
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2015-03-17 18:15:27 +01:00
|
|
|
pprint(vars(login_response)) # TODO: remove debug
|
|
|
|
except authentication.YggdrasilError as e:
|
|
|
|
print e.human_readable_error
|
2014-06-07 01:47:34 +02:00
|
|
|
return
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
print("Logged in as " + login_response.username)
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
if not options.server:
|
|
|
|
options.server = raw_input("Please enter server address (including port): ")
|
|
|
|
# Try to split out port and address
|
|
|
|
if ':' in options.server:
|
|
|
|
server = options.server.split(":")
|
|
|
|
address = server[0]
|
|
|
|
port = int(server[1])
|
2012-10-26 15:09:16 +02:00
|
|
|
else:
|
2014-06-07 01:47:34 +02:00
|
|
|
address = options.server
|
2012-10-26 15:09:16 +02:00
|
|
|
port = 25565
|
2014-06-07 01:47:34 +02:00
|
|
|
|
|
|
|
from network.connection import Connection
|
2014-10-08 19:12:37 +02:00
|
|
|
|
2014-06-07 01:47:34 +02:00
|
|
|
connection = Connection(address, port, login_response)
|
2015-03-17 18:15:27 +01:00
|
|
|
connection.connect()
|
2014-06-07 01:47:34 +02:00
|
|
|
|
2012-10-26 15:09:16 +02:00
|
|
|
while True:
|
|
|
|
try:
|
2014-06-07 01:47:34 +02:00
|
|
|
text = raw_input()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print "Bye!"
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|