-
Notifications
You must be signed in to change notification settings - Fork 13
SteamNetwork
These are all the connections emitted from the SteamNetwork autoload.
peer_status_updated(steam_id)
This event is triggered whenever a peers status has changed. This includes its network connection status, so its mostly useful for verifying this peer is still connected. This can be used in combination with all_peers_connected signal to gate lobbies until all players have successfully connected.
all_peers_connected
As its name suggests, this signal is fired when ALL peers have successfully connected to the server. Note this can and usually will be fired multiple times as players come and go in a lobby.
Example flow:
- Player 1 creates a lobby,
all_peers_connected
will fire - Player 1 invites Player 2
peer_status_updated
will fire - Player 2 joins and after a few seconds connects,
all_peers_connected
will fire again - Player 1 invites Player 3
peer_status_updated
will fire - Player 3 joins and after a few seconds connects,
all_peers_connected
will fire again
When player 2 first joins, a peer_status_updated(steam_id)
signal will fire, this is a good opportunity to disable any "start game" buttons or the equivalent until you receive another "all_peers_connected" signal. The example lobby has a showcase of a very rudimentary way to do this.
peer_session_failure(steam_id, reason)
This is called whenever a peer disconnects for some reason, usually due to a technical issue and not a manual disconnect.
The following can be called on clients:
rpc_on_server(caller: Node, method: String, args: Array)
This calls an RPC on the server, it works very similar to Godots HighLevel networking.
Usage Example:
func shoot(bad_guy):
SteamNetwork.rpc_on_server(self, "server_shoot", [bad_guy])
func server_shoot(sender_id: int, bad_guy):
if not SteamNetwork.is_server():
return
if can_shoot(sender_id, bad_guy):
bad_guy.remove_health(10)
# now update bad_guy state to all peers
The following are all designed to be used on the peer acting as the server.
rpc_on_client(to_peer: Peer, caller: Node, method: String, args: Array)
Calls this method on the client specified.
Usage Example:
func server_buy_item(sender_id: int, expensive_item):
if not SteamNetwork.is_server():
return
get_player(sender_id).remove_gold(999)
SteamNetwork.rpc_on_client(self, sender_id, "client_got_scammed")
rpc_all_clients(caller: Node, method: String, args: Array)
Similar to rpc_on_client
, this calls an RPC on ALL clients.
Usage Example:
func server_stun_bad_guy(bad_guy):
if not SteamNetwork.is_server():
return
SteamNetwork.rpc_all_clients(self, "client_bad_guy_got_stunned", [bad_guy])
func client_bad_guy_got_stunned(sender_id, the_bad_guy):
# do something with bad guy
pass
remote_set(caller: Node, property: String, value)
Sets a property on a node to the specified value
Usage Example:
var bad_guy_health := 30
func server_update_bad_guy_health(health):
if not SteamNetwork.is_server():
return
SteamNetwork.remote_set(self, "bad_guy_health", health)
register_rpc(caller: Node, method: String, permission: int)
Registers a single method to be callable on the current Node by the peer type provided as a permission parameter.
The permission type can be one of the following: PERMISSION {SERVER, CLIENT_ALL}
.
register_rpcs(caller: Node, methods: Array)
Helper function to register multiple RPCs in a single call.
Usage Example:
SteamNetwork.register_rpcs(self,
[
["_server_button_pressed", SteamNetwork.PERMISSION.CLIENT_ALL],
["_client_button_pressed", SteamNetwork.PERMISSION.SERVER],
]
)
register_rset(caller: Node, property: String, permission: int)
Similar to register_rpc, this allows a property to be whitelisted to be modified by the network.
is_peer_connected(steam_id) -> bool
Returns whether the peer passed by steam_id
argument is connected or not
peers_connected() -> bool
Returns whether all peers are connected or not
get_peer(steam_id) -> Peer
Returns a peer object for a given users steam_id
is_server() -> bool
Returns whether this peer is the server or not
get_server_peer() -> Peer
Gets the peer object of the server connection
get_server_steam_id() -> int
Gets the server users steam id