Here is the code that runs on the client after I've retrieved the authentication token:
func _ready():
authenticate("username", "password")
func authenticate(username, password):
http_request = HTTPRequest.new()
add_child(http_request)
http_request.connect("request_completed", self, "_http_request_completed")
var body = JSON.print({
"username": username,
"password": password,
})
http_request.request("https://httpbin.org/post", [], true, HTTPClient.METHOD_POST, body)
func _http_request_completed(result, response_code, headers, body):
token = "1234567890qwertyuiop"
Server.connect_to_server()
func connect_to_server():
network.create_client(ip_address, port)
get_tree().set_network_peer(network)
network.connect("connection_failed", self, "_on_connection_failed")
network.connect("connection_succeeded", self, "_on_connection_succeeded")
func _on_connection_succeeded():
validate_token(token)
func validate_token(token):
rpc_id(1, "validate_token", token)
Here is the remote function that runs on the server:
remote func validate_token(token):
var sender_id = get_tree().get_rpc_sender_id()
# TODO query auth server with token
# disconnect peer if token not valid
if true:
get_tree().disconnect_network_peer(sender_id)
However, it's giving the following error on the server debug:
peerconnected: 1611028214
ERROR: RPC 'validatetoken' is not allowed on node /root/Server from: 1611028214. Mode is 0, master is 1.
at: (core/io/multiplayer_api.cpp:285)
Strangely up until now other remote functions have worked fine. But it seems when I call them in this manner I get the error. I've tried other functions in place of validate_token that I know work later in the app, but they don't work when called in this manner. It's strange to me as I know the connection has been established, so I don't know why it's not calling the remote function.