mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-14 18:02:38 +00:00
feat(multiplayer): add Steam transport foundation
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
class_name SteamTransport
|
||||
extends NetTransport
|
||||
|
||||
const SteamBootstrapScript = preload("res://scripts/steam_bootstrap.gd")
|
||||
|
||||
# The SteamMultiplayerPeer extension is looked up dynamically so a stock ENet
|
||||
# build never references an unavailable native class while parsing scripts.
|
||||
const VIRTUAL_PORT := 0
|
||||
|
||||
func transport_id() -> String:
|
||||
return "steam"
|
||||
|
||||
|
||||
func is_available() -> bool:
|
||||
return SteamBootstrapScript.is_runtime_available()
|
||||
|
||||
|
||||
func unavailable_reason() -> String:
|
||||
return SteamBootstrapScript.unavailable_reason()
|
||||
|
||||
|
||||
func create_server(_port: int, _max_clients: int) -> Dictionary:
|
||||
var boot: Dictionary = SteamBootstrapScript.initialize()
|
||||
if int(boot.error) != OK:
|
||||
return boot
|
||||
var peer := ClassDB.instantiate("SteamMultiplayerPeer") as MultiplayerPeer
|
||||
if peer == null:
|
||||
return {"error": ERR_UNAVAILABLE, "reason": "SteamMultiplayerPeer could not be instantiated"}
|
||||
var err := int(peer.call("create_host", VIRTUAL_PORT))
|
||||
return {"error": err, "peer": peer if err == OK else null, "reason": error_string(err)}
|
||||
|
||||
|
||||
func create_client(address: String, _port: int) -> Dictionary:
|
||||
var steam_id_text := address.strip_edges()
|
||||
if not steam_id_text.is_valid_int() or int(steam_id_text) <= 0:
|
||||
return {"error": ERR_INVALID_PARAMETER, "reason": "Steam transport requires the server's numeric Steam ID"}
|
||||
var boot: Dictionary = SteamBootstrapScript.initialize()
|
||||
if int(boot.error) != OK:
|
||||
return boot
|
||||
var peer := ClassDB.instantiate("SteamMultiplayerPeer") as MultiplayerPeer
|
||||
if peer == null:
|
||||
return {"error": ERR_UNAVAILABLE, "reason": "SteamMultiplayerPeer could not be instantiated"}
|
||||
var err := int(peer.call("create_client", int(steam_id_text), VIRTUAL_PORT))
|
||||
return {"error": err, "peer": peer if err == OK else null, "reason": error_string(err)}
|
||||
Reference in New Issue
Block a user