This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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 'validate
token' 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.

Godot version 3.4.4
in Engine by (18 points)

1 Answer

+1 vote

This is quite simple.

You need to set the RPC mode for that function using either keywords ( remote, master, puppet) or rset("function", MODE)

A multiplayer checklist of you will.

  1. Who (which peers) will communicate
  2. Can they communicate (RPC modes set)
  3. How will they communicate (using what functions)
  4. What data will be exchanged ( recommend using the A sends to B and B verifies received to A model)
by (6,942 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.