2012-04-05 04:56:21 +02:00
|
|
|
import getpass
|
|
|
|
import sys
|
2012-10-26 15:09:16 +02:00
|
|
|
import Utils
|
2012-12-17 14:40:49 +01:00
|
|
|
from pluginloader import PluginLoader
|
2012-10-26 02:02:42 +02:00
|
|
|
from networking import PacketSenderManager, NetworkManager
|
|
|
|
from optparse import OptionParser
|
2012-04-30 19:05:06 +02:00
|
|
|
|
2012-04-05 04:56:21 +02:00
|
|
|
if __name__ == "__main__":
|
2012-10-26 02:02:42 +02:00
|
|
|
parser = OptionParser()
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-10-26 02:02:42 +02:00
|
|
|
parser.add_option("-u", "--username", dest="username", default="",
|
2012-12-25 21:38:02 +01:00
|
|
|
help="username to log in with")
|
|
|
|
|
2012-10-26 02:02:42 +02:00
|
|
|
parser.add_option("-p", "--password", dest="password", default="",
|
2012-12-25 21:38:02 +01:00
|
|
|
help="password to log in with")
|
|
|
|
|
2012-10-26 02:02:42 +02:00
|
|
|
parser.add_option("-s", "--server", dest="server", default="",
|
2012-12-25 21:38:02 +01:00
|
|
|
help="server to connect to")
|
|
|
|
|
2012-12-04 10:48:49 +01:00
|
|
|
parser.add_option("-x", "--offline-mode", dest="offlineMode",
|
2012-12-25 21:38:02 +01:00
|
|
|
action="store_true", default=False,
|
|
|
|
help="run in offline mode i.e don't attempt to auth via minecraft.net")
|
|
|
|
|
2012-12-17 14:40:49 +01:00
|
|
|
# pluginLoader
|
|
|
|
pluginLoader = PluginLoader("plugins")
|
|
|
|
pluginLoader.loadPlugins(parser)
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-10-26 02:02:42 +02:00
|
|
|
(options, args) = parser.parse_args()
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-12-17 14:40:49 +01:00
|
|
|
pluginLoader.notifyOptions(options)
|
2012-12-25 21:38:02 +01:00
|
|
|
|
|
|
|
if (options.username != ""):
|
2012-10-26 15:09:16 +02:00
|
|
|
user = options.username
|
2012-04-11 22:22:58 +02:00
|
|
|
else:
|
2012-10-26 15:09:16 +02:00
|
|
|
user = raw_input("Enter your username: ")
|
2012-12-25 21:38:02 +01:00
|
|
|
if (options.password != ""):
|
2012-10-26 15:09:16 +02:00
|
|
|
passwd = options.password
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (not options.offlineMode):
|
2012-10-26 15:09:16 +02:00
|
|
|
passwd = getpass.getpass("Enter your password: ")
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-12-04 10:48:49 +01:00
|
|
|
if (not options.offlineMode):
|
|
|
|
loginThread = Utils.MinecraftLoginThread(user, passwd)
|
|
|
|
loginThread.start()
|
|
|
|
loginThread.join()
|
|
|
|
loginResponse = loginThread.getResponse()
|
2012-12-25 21:38:02 +01:00
|
|
|
if (loginResponse['Response'] != "Good to go!"):
|
2012-12-04 10:48:49 +01:00
|
|
|
print loginResponse['Response']
|
|
|
|
sys.exit(1)
|
|
|
|
sessionid = loginResponse['SessionID']
|
|
|
|
user = loginResponse['Username']
|
|
|
|
print "Logged in as " + loginResponse['Username'] + "! Your session id is: " + sessionid
|
|
|
|
else:
|
|
|
|
sessionid = None
|
2012-12-25 21:38:02 +01:00
|
|
|
|
|
|
|
if (options.server != ""):
|
2012-12-04 10:48:49 +01:00
|
|
|
serverAddress = options.server
|
2012-10-26 15:09:16 +02:00
|
|
|
else:
|
2012-12-04 10:48:49 +01:00
|
|
|
serverAddress = raw_input("Enter host and port if any: ")
|
|
|
|
if ':' in serverAddress:
|
|
|
|
StuffEnteredIntoBox = serverAddress.split(":")
|
2012-10-26 15:09:16 +02:00
|
|
|
host = StuffEnteredIntoBox[0]
|
|
|
|
port = int(StuffEnteredIntoBox[1])
|
|
|
|
else:
|
2012-12-04 10:48:49 +01:00
|
|
|
host = serverAddress
|
2012-10-26 15:09:16 +02:00
|
|
|
port = 25565
|
2012-12-17 14:40:49 +01:00
|
|
|
connection = NetworkManager.ServerConnection(pluginLoader, user, sessionid, host, port, options)
|
|
|
|
connection.setDaemon(True)
|
2012-10-26 15:09:16 +02:00
|
|
|
connection.start()
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
chat_input = raw_input()
|
|
|
|
if (connection.isConnected):
|
2012-12-25 21:38:02 +01:00
|
|
|
PacketSenderManager.send03(connection.grabSocket(), chat_input)
|
2012-10-26 15:09:16 +02:00
|
|
|
else:
|
2012-12-25 21:38:02 +01:00
|
|
|
pass
|
2012-10-26 15:09:16 +02:00
|
|
|
except KeyboardInterrupt, e:
|
|
|
|
connection.disconnect()
|
2012-12-17 14:40:49 +01:00
|
|
|
pluginLoader.disablePlugins()
|
2012-10-26 15:09:16 +02:00
|
|
|
sys.exit(1)
|