Launcher: Assume port 25565 in Direct Connect when no port is given, instead of erroring

This commit is contained in:
UnknownShadow200 2022-01-30 09:53:56 +11:00
parent cacb52b595
commit 607e14a087

View File

@ -563,6 +563,7 @@ static void DirectConnectScreen_Load(struct DirectConnectScreen* s) {
static void DirectConnectScreen_StartClient(void* w, int idx) { static void DirectConnectScreen_StartClient(void* w, int idx) {
static const cc_string defMppass = String_FromConst("(none)"); static const cc_string defMppass = String_FromConst("(none)");
static const cc_string defPort = String_FromConst("25565");
const cc_string* user = &DirectConnectScreen_Instance.iptUsername.text; const cc_string* user = &DirectConnectScreen_Instance.iptUsername.text;
const cc_string* addr = &DirectConnectScreen_Instance.iptAddress.text; const cc_string* addr = &DirectConnectScreen_Instance.iptAddress.text;
const cc_string* mppass = &DirectConnectScreen_Instance.iptMppass.text; const cc_string* mppass = &DirectConnectScreen_Instance.iptMppass.text;
@ -571,12 +572,18 @@ static void DirectConnectScreen_StartClient(void* w, int idx) {
cc_uint16 raw_port; cc_uint16 raw_port;
int index = String_LastIndexOf(addr, ':'); int index = String_LastIndexOf(addr, ':');
if (index <= 0 || index == addr->length - 1) { if (index == 0 || index == addr->length - 1) {
DirectConnectScreen_SetStatus("&eInvalid address"); return; DirectConnectScreen_SetStatus("&eInvalid address"); return;
} }
ip = String_UNSAFE_Substring(addr, 0, index); /* support either "[IP]" or "[IP]:[PORT]" */
port = String_UNSAFE_SubstringAt(addr, index + 1); if (index == -1) {
ip = *addr;
port = defPort;
} else {
ip = String_UNSAFE_Substring(addr, 0, index);
port = String_UNSAFE_SubstringAt(addr, index + 1);
}
if (!user->length) { if (!user->length) {
DirectConnectScreen_SetStatus("&eUsername required"); return; DirectConnectScreen_SetStatus("&eUsername required"); return;