diff --git a/README.md b/README.md index 2f7702d..64fcc7e 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,11 @@ Feel free to chat with us about GodotSteam on the [CoaguCo Discord server](https Current Build --- -You can [download pre-compiled versions _(currently v4.0)_ of this repo here](https://github.com/CoaguCo-Industries/GodotSteam-Server/releases). +You can [download pre-compiled versions _(currently v4.0.1)_ of this repo here](https://github.com/CoaguCo-Industries/GodotSteam-Server/releases). + +**Version 4.0.1 Changes** +- Changed: how initialization functions work, passing empty string now uses default IP (expected behavior) +- Fixed: incorrect verbal message from `serverInitEx` **Version 4.0 Changes** - Added: missing server functions from steam_gameserver.h diff --git a/godot-cpp b/godot-cpp index 1009da4..48b92ac 160000 --- a/godot-cpp +++ b/godot-cpp @@ -1 +1 @@ -Subproject commit 1009da4d7e395abadfdb454cff6623e9456181c4 +Subproject commit 48b92acf8c1de8ab39aab0d5f0f83b7fe4895ee9 diff --git a/godotsteam_server/godotsteam_server.cpp b/godotsteam_server/godotsteam_server.cpp index dc9248f..db2674e 100644 --- a/godotsteam_server/godotsteam_server.cpp +++ b/godotsteam_server/godotsteam_server.cpp @@ -191,19 +191,24 @@ bool SteamServer::serverInit(const String& ip, int game_port, int query_port, Se else{ mode = eServerModeAuthenticationAndSecure; } - uint32_t ip4 = 0; - // Resolve address and convert it - if(ip.is_valid_ip_address()){ - char ip_bytes[4]; - sscanf(ip.utf8().get_data(), "%hhu.%hhu.%hhu.%hhu", &ip_bytes[3], &ip_bytes[2], &ip_bytes[1], &ip_bytes[0]); - ip4 = ip_bytes[0] | ip_bytes[1] << 8 | ip_bytes[2] << 16 | ip_bytes[3] << 24; - } - else{ - return false; + + uint32_t ip_address = 0; + if(!ip.is_empty()){ + // Resolve address and convert it + if(ip.is_valid_ip_address()){ + char ip_bytes[4]; + sscanf(ip.utf8().get_data(), "%hhu.%hhu.%hhu.%hhu", &ip_bytes[3], &ip_bytes[2], &ip_bytes[1], &ip_bytes[0]); + ip_address = ip_bytes[0] | ip_bytes[1] << 8 | ip_bytes[2] << 16 | ip_bytes[3] << 24; + } + else{ + return false; + } } - if(!SteamGameServer_Init(ip4, (uint16)game_port, (uint16)query_port, mode, version_number.utf8().get_data())){ + + if(!SteamGameServer_Init(ip_address, (uint16)game_port, (uint16)query_port, mode, version_number.utf8().get_data())){ return false; } + return true; } @@ -211,11 +216,7 @@ bool SteamServer::serverInit(const String& ip, int game_port, int query_port, Se // After calling this function, you should set any additional server parameters, and then logOnAnonymous() or logOn(). // On success STEAM_API_INIT_RESULT_OK is returned. Otherwise, if error_message is non-NULL, it will receive a non-localized message that explains the reason for the failure Dictionary SteamServer::serverInitEx(const String& ip, int game_port, int query_port, ServerMode server_mode, const String& version_number){ - Dictionary server_initialize; - char error_message[STEAM_MAX_ERROR_MESSAGE] = "IP address is invalid"; - ESteamAPIInitResult initialize_result = k_ESteamAPIInitResult_FailedGeneric; - - // Convert the server mode back + // Convert the server mode back EServerMode mode; if(server_mode == 1){ mode = eServerModeNoAuthentication; @@ -226,13 +227,22 @@ Dictionary SteamServer::serverInitEx(const String& ip, int game_port, int query_ else{ mode = eServerModeAuthenticationAndSecure; } - // Resolve address and convert it - if(ip.is_valid_ip_address()){ - char ip_bytes[4]; - sscanf(ip.utf8().get_data(), "%hhu.%hhu.%hhu.%hhu", &ip_bytes[3], &ip_bytes[2], &ip_bytes[1], &ip_bytes[0]); - uint32_t ip4 = ip_bytes[0] | ip_bytes[1] << 8 | ip_bytes[2] << 16 | ip_bytes[3] << 24; - initialize_result = SteamGameServer_InitEx(ip4, (uint16)game_port, (uint16)query_port, mode, version_number.utf8().get_data(), &error_message); + + uint32_t ip_address = 0; + if(!ip.is_empty()){ + // Resolve address and convert it + if(ip.is_valid_ip_address()){ + char ip_bytes[4]; + sscanf(ip.utf8().get_data(), "%hhu.%hhu.%hhu.%hhu", &ip_bytes[3], &ip_bytes[2], &ip_bytes[1], &ip_bytes[0]); + ip_address = ip_bytes[0] | ip_bytes[1] << 8 | ip_bytes[2] << 16 | ip_bytes[3] << 24; + } } + + char error_message[STEAM_MAX_ERROR_MESSAGE] = "Server initialized successfully"; + ESteamAPIInitResult initialize_result = k_ESteamAPIInitResult_FailedGeneric; + initialize_result = SteamGameServer_InitEx(ip_address, game_port, query_port, mode, version_number.utf8().get_data(), &error_message); + + Dictionary server_initialize; server_initialize["status"] = initialize_result; server_initialize["verbal"] = error_message;