mirror of
https://github.com/ammaraskar/pyCraft.git
synced 2024-09-28 06:27:26 +02:00
Add --offline switch to example application.
This commit is contained in:
parent
a753184ca2
commit
434bd1aab4
28
start.py
28
start.py
@ -21,12 +21,15 @@ def get_options():
|
|||||||
parser.add_option("-s", "--server", dest="server", default=None,
|
parser.add_option("-s", "--server", dest="server", default=None,
|
||||||
help="server to connect to")
|
help="server to connect to")
|
||||||
|
|
||||||
|
parser.add_option("-o", "--offline", dest="offline", action="store_true",
|
||||||
|
help="connect to a server in offline mode")
|
||||||
|
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
if not options.username:
|
if not options.username:
|
||||||
options.username = input("Enter your username: ")
|
options.username = input("Enter your username: ")
|
||||||
|
|
||||||
if not options.password:
|
if not options.password and not options.offline:
|
||||||
options.password = getpass.getpass("Enter your password: ")
|
options.password = getpass.getpass("Enter your password: ")
|
||||||
|
|
||||||
if not options.server:
|
if not options.server:
|
||||||
@ -47,16 +50,21 @@ def get_options():
|
|||||||
def main():
|
def main():
|
||||||
options = get_options()
|
options = get_options()
|
||||||
|
|
||||||
auth_token = authentication.AuthenticationToken()
|
if options.offline:
|
||||||
try:
|
print("Connecting in offline mode")
|
||||||
auth_token.authenticate(options.username, options.password)
|
connection = Connection(
|
||||||
except YggdrasilError as e:
|
options.address, options.port, username=options.username)
|
||||||
print(e)
|
else:
|
||||||
sys.exit()
|
auth_token = authentication.AuthenticationToken()
|
||||||
|
try:
|
||||||
|
auth_token.authenticate(options.username, options.password)
|
||||||
|
except YggdrasilError as e:
|
||||||
|
print(e)
|
||||||
|
sys.exit()
|
||||||
|
print("Logged in as " + auth_token.username)
|
||||||
|
connection = Connection(
|
||||||
|
options.address, options.port, auth_token=auth_token)
|
||||||
|
|
||||||
print("Logged in as " + auth_token.username)
|
|
||||||
|
|
||||||
connection = Connection(options.address, options.port, auth_token)
|
|
||||||
connection.connect()
|
connection.connect()
|
||||||
|
|
||||||
def print_chat(chat_packet):
|
def print_chat(chat_packet):
|
||||||
|
Loading…
Reference in New Issue
Block a user