Use Default Port In servers.txt If Not Specified

This commit is contained in:
TheBrokenRail 2021-06-29 16:19:02 -04:00
parent 0c0a61cd23
commit 0bce0d17ac
5 changed files with 21 additions and 13 deletions

View File

@ -1 +1 @@
2.0.7
2.0.8

View File

@ -1,5 +1,8 @@
# Changelog
**2.0.8**
* Use Default Port In ``servers.txt`` If Not Specified
**2.0.7**
* Fix Sign Text Not Updating In Multiplayer When Exiting Editing UI Using Escape Button
* Fix Item Dropping Not Working

View File

@ -9,6 +9,8 @@ Unlike vanilla MCPI, MCPI-Reborn allows you to natively join a server outside of
### Example ``~/.minecraft-pi/servers.txt``
```
# Comment
example.com:19132
# Default Port Is 19132
example.com
# Custom Port
example.com:19133
```

View File

@ -110,7 +110,7 @@ static Minecraft_grabMouse_t Minecraft_grabMouse = (Minecraft_grabMouse_t) 0x15d
typedef void (*Minecraft_leaveGame_t)(unsigned char *minecraft, bool save_remote_level);
static Minecraft_leaveGame_t Minecraft_leaveGame = (Minecraft_leaveGame_t) 0x15ea0;
typedef void (*Minecraft_handleBack_t)(unsigned char *minecraft, bool param_1);
typedef int (*Minecraft_handleBack_t)(unsigned char *minecraft, bool param_1);
static uint32_t Minecraft_handleBack_vtable_offset = 0x34;
static uint32_t Minecraft_screen_width_property_offset = 0x20; // int32_t

View File

@ -35,7 +35,7 @@ static void load_servers() {
// Write Defaults
std::ofstream server_list_file_output(file);
server_list_file_output << "# External Servers File\n";
server_list_file_output << "thebrokenrail.com:19132\n";
server_list_file_output << "thebrokenrail.com\n";
server_list_file_output.close();
// Re-Open Stream
server_list_file = std::ifstream(file);
@ -58,9 +58,13 @@ static void load_servers() {
// Parse
std::string address;
std::string port_str;
// Loop
// Add Default Port If Needed
size_t last_colon = line.find_last_of(':');
if (last_colon != std::string::npos) {
if (last_colon == std::string::npos) {
line.append(":19132");
last_colon = line.find_last_of(':');
}
// Loop
for (std::string::size_type i = 0; i < line.length(); i++) {
if (i > last_colon) {
port_str.push_back(line[i]);
@ -68,7 +72,6 @@ static void load_servers() {
address.push_back(line[i]);
}
}
}
// Check Line
if (address.length() < 1 || port_str.length() < 1 || port_str.find_first_not_of("0123456789") != std::string::npos) {
// Invalid Line