diff --git a/modules/lobbies/sdk_addons/godot/multiplayer_manager.gd b/modules/lobbies/sdk_addons/godot/multiplayer_manager.gd index b2e76614..1bbdb785 100644 --- a/modules/lobbies/sdk_addons/godot/multiplayer_manager.gd +++ b/modules/lobbies/sdk_addons/godot/multiplayer_manager.gd @@ -1,5 +1,5 @@ extends Node -class_name BackendMultiplayerManager +class_name RivetMultiplayerManager enum Transport { ENET, WEB_SOCKET } @@ -79,7 +79,7 @@ var _player_token = null func setup_multiplayer(): # Validate only initialized once if _multiplayer_setup: - BackendLogger.warning("setup_multiplayer already called") + RivetLogger.warning("setup_multiplayer already called") return _multiplayer_setup = true @@ -111,14 +111,14 @@ func setup_multiplayer(): if OS.has_environment("LOBBY_ID"): _lobby_id = OS.get_environment("LOBBY_ID") else: - BackendLogger.warning("Missing lobby ID") + RivetLogger.warning("Missing lobby ID") if OS.has_environment("LOBBY_TOKEN"): _lobby_token = OS.get_environment("LOBBY_TOKEN") # Start server if transport == Transport.ENET: - BackendLogger.log("Starting ENet server: %s:%s" % [_server_hostname, _server_port]) + RivetLogger.log("Starting ENet server: %s:%s" % [_server_hostname, _server_port]) peer = ENetMultiplayerPeer.new() peer.set_bind_ip(_server_hostname) @@ -126,14 +126,14 @@ func setup_multiplayer(): # TODO: crash if create server fails multiplayer.set_multiplayer_peer(peer) elif transport == Transport.WEB_SOCKET: - BackendLogger.log("Starting WebSocket server: %s:%s" % [_server_hostname, _server_port]) + RivetLogger.log("Starting WebSocket server: %s:%s" % [_server_hostname, _server_port]) peer = WebSocketMultiplayerPeer.new() peer.create_server(_server_port, _server_hostname) # TODO: crash if create server fails multiplayer.set_multiplayer_peer(peer) else: - BackendLogger.error("Unsupported transport: %s" % transport) + RivetLogger.error("Unsupported transport: %s" % transport) OS.crash("Unsupported transport") # Notify lobby ready @@ -142,24 +142,24 @@ func setup_multiplayer(): } if _lobby_token != null: request["lobbyToken"] = _lobby_token - var response = await Backend.lobbies.set_lobby_ready(request).async() + var response = await Rivet.lobbies.set_lobby_ready(request).async() if response.is_ok(): - BackendLogger.log("Lobby ready") + RivetLogger.log("Lobby ready") else: - BackendLogger.warning("Lobby ready failed failed: %s" % response.body) + RivetLogger.warning("Lobby ready failed failed: %s" % response.body) OS.crash("Lobby ready failed") return ## Connect to a lobby returned from the backend. func connect_to_lobby(lobby, player): if !_multiplayer_setup: - BackendLogger.error("setup_multiplayer needs to be called in _ready") + RivetLogger.error("setup_multiplayer needs to be called in _ready") return if is_server: - BackendLogger.warning("Cannot called set_player_token on server") + RivetLogger.warning("Cannot called set_player_token on server") return - BackendLogger.log("Connecting to lobby: %s %s" % [lobby, player]) + RivetLogger.log("Connecting to lobby: %s %s" % [lobby, player]) # Save token _player_token = player.token @@ -179,12 +179,12 @@ func connect_to_lobby(lobby, player): hostname = backend_port.hostname port = backend_port.port else: - BackendLogger.error("Unsupported lobby backend: %s" % lobby.backend) + RivetLogger.error("Unsupported lobby backend: %s" % lobby.backend) return # Start server if transport == Transport.ENET: - BackendLogger.log("Connecting to ENet server: %s:%s" % [hostname, port]) + RivetLogger.log("Connecting to ENet server: %s:%s" % [hostname, port]) peer = ENetMultiplayerPeer.new() peer.create_client(hostname, port) @@ -197,17 +197,17 @@ func connect_to_lobby(lobby, player): ws_protocol = "ws" var url = "%s://%s:%s" % [ws_protocol, hostname, port] - BackendLogger.log("Connecting to WebSocket server: %s" % url) + RivetLogger.log("Connecting to WebSocket server: %s" % url) peer = WebSocketMultiplayerPeer.new() peer.create_client(url) multiplayer.set_multiplayer_peer(peer) else: - BackendLogger.error("Unsupported transport: %s" % transport) + RivetLogger.error("Unsupported transport: %s" % transport) # MARK: Peers func _on_peer_connected(id): - BackendLogger.log('Peer connected: %s' % id) + RivetLogger.log('Peer connected: %s' % id) if is_server: client_connected.emit(id) @@ -215,14 +215,14 @@ func _on_peer_connected(id): server_connected.emit() func _on_peer_disconnected(id): - BackendLogger.log('Peer disconnected: %s' % id) + RivetLogger.log('Peer disconnected: %s' % id) if is_server: # Remove player from lobby var player_token = _player_tokens.get(id) if player_token != null: _player_tokens.erase(id) - BackendLogger.log("Removing player %s" % player_token) + RivetLogger.log("Removing player %s" % player_token) var request = { "lobbyId": _lobby_id, @@ -230,11 +230,11 @@ func _on_peer_disconnected(id): } if _lobby_token != null: request["lobbyToken"] = _lobby_token - var response = await Backend.lobbies.set_player_disconnected(request).async() + var response = await Rivet.lobbies.set_player_disconnected(request).async() if response.is_error(): - BackendLogger.warning("Player disconnect failed for %id: %s" % [id, response.body]) + RivetLogger.warning("Player disconnect failed for %id: %s" % [id, response.body]) else: - BackendLogger.warning("Player disconnected without player token: %s" % id) + RivetLogger.warning("Player disconnected without player token: %s" % id) return # Signal @@ -243,13 +243,13 @@ func _on_peer_disconnected(id): server_disconnected.emit() func _on_connected_to_server(): - BackendLogger.log('Connected to server') + RivetLogger.log('Connected to server') func _on_connection_failed(): - BackendLogger.log('Connection failed') + RivetLogger.log('Connection failed') func _on_server_disconnected(): - BackendLogger.log('Server disconnected') + RivetLogger.log('Server disconnected') # MARK: Authentication func _auth_callback(id: int, buf: PackedByteArray): @@ -259,12 +259,12 @@ func _auth_callback(id: int, buf: PackedByteArray): json.parse(buf.get_string_from_utf8()) var data = json.get_data() - BackendLogger.log("Player authenticating %s: %s" % [id, data]) + RivetLogger.log("Player authenticating %s: %s" % [id, data]) # Check token var player_token = data["player_token"] if player_token == null: - BackendLogger.warning("Player token not provided in auth for %s" % id) + RivetLogger.warning("Player token not provided in auth for %s" % id) _scene_multiplayer.disconnect_peer(id) return @@ -278,13 +278,13 @@ func _auth_callback(id: int, buf: PackedByteArray): } if _lobby_token != null: request["lobbyToken"] = _lobby_token - var response = await Backend.lobbies.set_player_connected(request).async() + var response = await Rivet.lobbies.set_player_connected(request).async() if response.is_ok(): - BackendLogger.log("Player authenticated for %s" % id) + RivetLogger.log("Player authenticated for %s" % id) _scene_multiplayer.complete_auth(id) else: # Player will be cleaned up on disconnect handler - BackendLogger.warning("Player authentiation failed for %s: %s" % [id, response.body]) + RivetLogger.warning("Player authentiation failed for %s: %s" % [id, response.body]) _scene_multiplayer.disconnect_peer(id) else: # Server does not need to auth with client @@ -294,7 +294,7 @@ func _on_peer_authenticating(id): #if is_server: #return - BackendLogger.log("Authenticating with server") + RivetLogger.log("Authenticating with server") var body = JSON.stringify({ "player_token": _player_token }) (multiplayer as SceneMultiplayer).send_auth(id, body.to_utf8_buffer()) @@ -303,6 +303,6 @@ func _on_peer_authentication_failed(id): #if !is_server: #return - BackendLogger.warning("Client authentication failed %s" % id) + RivetLogger.warning("Client authentication failed %s" % id) multiplayer.set_multiplayer_peer(null)