Skip to content

Commit

Permalink
Fixed initialization functions, updated submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
Gramps committed Oct 6, 2023
1 parent b4183cc commit 7c5ec21
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 31 additions & 21 deletions godotsteam_server/godotsteam_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,31 +191,32 @@ 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;
}

// Initialize SteamGameServer client and interface objects, and set server properties which may not be changed.
// 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;
Expand All @@ -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;

Expand Down

0 comments on commit 7c5ec21

Please sign in to comment.