Calls: only client to server and server to specific client

Godot Version

4.2.2 stable


ok this is my script so that it works BUT with no restrictions

extends Node

func Call():
	print("call 1 on local client")
	SrvCall.rpc_id(1, multiplayer.get_unique_id())

@rpc("any_peer", "reliable")
func SrvCall(id):
	print("call 2 on server")
	CallLocalPlayer.rpc_id(id, id)

@rpc("any_peer", "reliable")
func CallLocalPlayer(id):
	print("WORKS ", id)

I want to know how to make it work that only server can receive the call → SrvCall
or only local player can recieve call only from Server → CallLocalPlayer

I was trying to play with "authority", "call_local", "call_remote", but always hit a wall with a error which I don’t even understand

the authority and server client calls are done like this:

func Server():
	multiplayer.multiplayer_peer = netManager
			await get_tree().create_timer(1).timeout

func Client():
	netManager.create_client(ADDRESS, PORT)
	multiplayer.multiplayer_peer = netManager
	await get_tree().create_timer(2).timeout
## general network node for all players
func AddNetworkNode(id):
	print("empty call to older clients")
	## if the id is my id I'll populate my self and not the others I don't want to care about them now
	if id == multiplayer.get_unique_id():
		localNetworkNode = preload("res://Networking/Client/NetworkNode.tscn").instantiate()
		print("the id: ", id)

if you really need that kind of errors please let me know.
I didn’t provide them because I think you know out of the box what to do from Info I provided.

figured it out:

if multiplayer.get_remote_sender_id() != 1:
		printerr("not server: ", multiplayer.get_remote_sender_id(), get_stack())

and if it’ is 1 that means that only server can give the message

and I can store the id when client connects and I can use it as reference to him

1 Like