start.py: allow IPv6 addresses to be given in square brackets.
This commit is contained in:
1 parent
67344f2ceb
commit
bca783115c
1 file changed
+16
-12
@@ -4,6 +4,7 @@ from __future__ import print_function
|
|||||||
|
|
||||||
import getpass
|
import getpass
|
||||||
import sys
|
import sys
|
||||||
|
import re
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
from minecraft import authentication
|
from minecraft import authentication
|
||||||
@@ -23,10 +24,12 @@ def get_options():
|
|||||||
help="password to log in with")
|
help="password to log in with")
|
||||||
|
|
||||||
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 host or host:port "
|
||||||
|
"(enclose IPv6 addresses in square brackets)")
|
||||||
|
|
||||||
parser.add_option("-o", "--offline", dest="offline", action="store_true",
|
parser.add_option("-o", "--offline", dest="offline", action="store_true",
|
||||||
help="connect to a server in offline mode")
|
help="connect to a server in offline mode "
|
||||||
|
"(no password required)")
|
||||||
|
|
||||||
parser.add_option("-d", "--dump-packets", dest="dump_packets",
|
parser.add_option("-d", "--dump-packets", dest="dump_packets",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
@@ -38,19 +41,20 @@ def get_options():
|
|||||||
options.username = input("Enter your username: ")
|
options.username = input("Enter your username: ")
|
||||||
|
|
||||||
if not options.password and not options.offline:
|
if not options.password and not options.offline:
|
||||||
options.password = getpass.getpass("Enter your password: ")
|
options.password = getpass.getpass("Enter your password (leave "
|
||||||
|
"blank for offline mode): ")
|
||||||
|
options.offline = options.offline or (options.password == "")
|
||||||
|
|
||||||
if not options.server:
|
if not options.server:
|
||||||
options.server = input("Please enter server address"
|
options.server = input("Enter server host or host:port "
|
||||||
" (including port): ")
|
"(enclose IPv6 addresses in square brackets): ")
|
||||||
# Try to split out port and address
|
# Try to split out port and address
|
||||||
if ':' in options.server:
|
match = re.match(r"((?P<host>[^\[\]:]+)|\[(?P<addr>[^\[\]]+)\])"
|
||||||
server = options.server.split(":")
|
r"(:(?P<port>\d+))?$", options.server)
|
||||||
options.address = server[0]
|
if match is None:
|
||||||
options.port = int(server[1])
|
raise ValueError("Invalid server address: '%s'." % options.server)
|
||||||
else:
|
options.address = match.group("host") or match.group("addr")
|
||||||
options.address = options.server
|
options.port = int(match.group("port") or 25565)
|
||||||
options.port = 25565
|
|
||||||
|
|
||||||
return options
|
return options
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user