Godot Version
4.6
Question
I have the godotsteam and godotsteam_server plugins installed. I set Debug → Multiple Instances to two, one has the dedicated_server feature tag:
I do have a file called steamworks.gd which runs as a global autoload:
extends Node
func _ready() -> void:
if OS.has_feature("dedicated_server"):
initialize_steam_server()
else:
initialize_steam_client()
func initialize_steam_client() -> void:
var initialize_response: Dictionary = Steam.steamInitEx()
print("Did Steam initialize?: %s " % initialize_response)
print("Steam app id: %d" % Steam.getAppID())
func initialize_steam_server() -> void:
var ip: String = "0.0.0.0"
var game_port: int = 27777
var query_port: int = 27778
var server_mode: int = SteamServer.SERVER_MODE_NO_AUTHENTICATION
var version_number: String = "0.1"
# Emits SteamServer.server
var result: Dictionary = SteamServer.serverInitEx(ip, game_port, query_port, server_mode, version_number)
if result["status"] != SteamServer.STEAM_API_INIT_RESULT_OK:
push_error("Couldn't init server: %d:" % result["status"])
push_error(" > verbal: %s" % result["verbal"])
print("Server initialiyed successfully")
# server_connect_failure callback
# server_connected callback
# server_disconnected callback
SteamServer.logOnAnonymous()
func _process(_delta: float) -> void:
if OS.has_feature("dedicated_server"):
SteamServer.run_callbacks()
else:
Steam.run_callbacks()
Now in the case of the dedicated_server instance, we know that SteamServer.logOnAnonymous() will trigger the server_connected callback. We have a file called network_manager.gd (here I only show the relevant parts otherwise it would be kinda big)
func _ready() -> void:
if not OS.has_feature("dedicated_server"):
Steam.lobby_created.connect(_on_steam_lobby_created)
Steam.lobby_joined.connect(_on_steam_lobby_joined)
if OS.has_feature("dedicated_server"):
SteamServer.server_connected.connect(_on_steam_server_connected)
...
func _on_steam_server_connected() -> void:
# The dedicated_server stores its anonumouse steam id to a file,
# making it acccessible to the client.
# TODO: In 'prod' use cli arg, UDP, anything else that's better
var path: String = "user://server_steam_id.txt"
# Remove existing file
if FileAccess.file_exists(path):
print("Deleting server_steam_id.txt")
DirAccess.remove_absolute(path)
var server_steam_id: int = SteamServer.getSteamID()
print("Storing steam id in file:")
print(" > File: %s" % path)
print(" > Server Steam ID %d" % server_steam_id)
var file = FileAccess.open(path, FileAccess.WRITE)
file.store_string(str(server_steam_id))
file.close()
print("Server ID saved to file.")
# create host
create_steam_server()
func create_steam_server(virtual_port: int = 0) -> Error:
print("Creating Steam Lobby ...")
var peer: SteamMultiplayerPeer = SteamMultiplayerPeer.new()
var error: Error = peer.create_host(virtual_port)
# There would be other stuff here but as soon as we run the peer.create_host() function
# we stop seeing the prints of this and the _on_steam_server_connected function.
return OK
So basically we do:
- Init SteamServer
- Hook up the callbacks
- Get an anonymouse steam ID for our server
- Write it to a file
- Create a host using
create_host(which seems to silently fail)
The issue is: As soon as we use this line
var error: Error = peer.create_host(virtual_port)
we stop seeing basically all server related prints. If you uncomment it or set a breakpoint before it, you will see the prints. Note: There is no error nor warnings, the only warnings are about unused vars etc.
I have no idea what’s going on or how to further debug this.
Any help is appreciated, thanks in advance.
