Lay down the foundations for a complete rewrite, the new framework is far more easy to maintain
This commit is contained in:
1 parent
59e4706b25
commit
85112fba1d
17 files changed
+607
-2135
No files matched your search
@@ -1,89 +1,63 @@
|
||||
import getpass
|
||||
import sys
|
||||
import Utils
|
||||
from pluginloader import PluginLoader
|
||||
from networking import PacketSenderManager, NetworkManager
|
||||
from optparse import OptionParser
|
||||
try:
|
||||
import colorama
|
||||
colorama.init()
|
||||
except ImportError:
|
||||
pass
|
||||
import authentication
|
||||
|
||||
if __name__ == "__main__":
|
||||
PROTOCOL_VERSION = 5
|
||||
|
||||
def main():
|
||||
parser = OptionParser()
|
||||
|
||||
parser.add_option("-u", "--username", dest="username", default="",
|
||||
parser.add_option("-u", "--username", dest="username", default=None,
|
||||
help="username to log in with")
|
||||
|
||||
parser.add_option("-p", "--password", dest="password", default="",
|
||||
parser.add_option("-p", "--password", dest="password", default=None,
|
||||
help="password to log in with")
|
||||
|
||||
parser.add_option("-s", "--server", dest="server", default="",
|
||||
parser.add_option("-s", "--server", dest="server", default=None,
|
||||
help="server to connect to")
|
||||
|
||||
parser.add_option("-x", "--offline-mode", dest="offlineMode",
|
||||
action="store_true", default=False,
|
||||
help="run in offline mode i.e don't attempt to auth via minecraft.net")
|
||||
|
||||
parser.add_option("-c", "--disable-console-colours", dest="disableAnsiColours",
|
||||
action="store_true", default=False,
|
||||
help="print minecraft chat colours as their equivalent ansi colours")
|
||||
|
||||
# pluginLoader
|
||||
pluginLoader = PluginLoader("plugins")
|
||||
pluginLoader.loadPlugins(parser)
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
pluginLoader.notifyOptions(options)
|
||||
|
||||
if not options.username:
|
||||
options.username = raw_input("Enter your username: ")
|
||||
|
||||
if (options.username != ""):
|
||||
user = options.username
|
||||
else:
|
||||
user = raw_input("Enter your username: ")
|
||||
if (options.password != ""):
|
||||
passwd = options.password
|
||||
elif (not options.offlineMode):
|
||||
passwd = getpass.getpass("Enter your password: ")
|
||||
if not options.password:
|
||||
options.password = getpass.getpass("Enter your password: ")
|
||||
|
||||
if (not options.offlineMode):
|
||||
loginThread = Utils.MinecraftLoginThread(user, passwd)
|
||||
loginThread.start()
|
||||
loginThread.join()
|
||||
loginResponse = loginThread.getResponse()
|
||||
if (loginResponse['Response'] != "Good to go!"):
|
||||
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
|
||||
login_response = authentication.login_to_minecraft(options.username, options.password)
|
||||
from pprint import pprint # TODO: remove debug
|
||||
pprint(vars(login_response)) # TODO: remove debug
|
||||
|
||||
if (options.server != ""):
|
||||
serverAddress = options.server
|
||||
if login_response.error:
|
||||
print login_response.human_error
|
||||
return
|
||||
|
||||
print("Logged in as " + login_response.username)
|
||||
|
||||
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])
|
||||
else:
|
||||
serverAddress = raw_input("Enter host and port if any: ")
|
||||
if ':' in serverAddress:
|
||||
StuffEnteredIntoBox = serverAddress.split(":")
|
||||
host = StuffEnteredIntoBox[0]
|
||||
port = int(StuffEnteredIntoBox[1])
|
||||
else:
|
||||
host = serverAddress
|
||||
address = options.server
|
||||
port = 25565
|
||||
connection = NetworkManager.ServerConnection(pluginLoader, user, sessionid, host, port, options)
|
||||
connection.setDaemon(True)
|
||||
connection.start()
|
||||
|
||||
from network.connection import Connection
|
||||
connection = Connection(address, port, login_response)
|
||||
connection.status()
|
||||
|
||||
while True:
|
||||
try:
|
||||
chat_input = raw_input()
|
||||
if (connection.isConnected):
|
||||
PacketSenderManager.send03(connection.grabSocket(),
|
||||
chat_input.decode('utf-8')[:100])
|
||||
else:
|
||||
pass
|
||||
except KeyboardInterrupt, e:
|
||||
connection.disconnect()
|
||||
pluginLoader.disablePlugins()
|
||||
sys.exit(1)
|
||||
text = raw_input()
|
||||
except KeyboardInterrupt:
|
||||
print "Bye!"
|
||||
sys.exit()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user