I’ve been refactoring my game’s netcode for about a week now, trying to get a dedicated server model working.
I’ve figured out how to send RPC packets directly to the server with:
@rpc("any_peer","call_remote","reliable",0)
func client_test(Client_ID) -> void:
print("CLIENT CALL from ", Client_ID)
if Input.is_action_just_pressed("jump"):
client_test.rpc_id(1, Client_ID)
This triggers a print event on the server and sends the client who sent it via their ID.
However, is there any way for the server that received this packet to convert it into a string or other variable? And is there any way to store this info? The reason is I’m trying to send actions to the server, then send it back to the client.
Thank you for this response. I don’t have a specific issue, I just need to wrap my head around client-server communication.
Just to vent, networking was never easy, but Godot’s API especially makes it so much worse. Networking logic is pretty straightforward and easy to understand, but the way you have to execute it in Godot can make code so dang convoluted.
If you are still using the SceneMuliplayer:MultiplayerAPI you can achieve this with placing a node, on client and server, at the same node path with two different scripts depending on if it is a client or server. You could also potentially write an api class that both scripts inherent from, and contains rpc defines and stub implementations to reduce compatibility issues. The xlient and server will extend the api class and provide implementations.
But it isnt really necessary and may get convoluted to have class inheritance.
@pennyloafers
This is all pretty useful info, I have a specific issue though, but it’s so difficult to explain.
So basically, what I want to happen is as follows:
Client and server script are in the same project, and are separated by an export preset. (This works)
The server creates itself. (This works)
The client joins the server when the client project is loaded. (This works)
The server is the main authority over all nodes. (This works)
The client receives their own player and unique ID. (This works)
The client sends input to the server from their client script. The server then receives this input info on it’s server script, checks if it’s a valid action, then performs that action on the client’s player script. (This DOES NOT work)
Step 6 baffles me, because I have no idea what to do. I see the information and code examples, but I cannot wrap my head around it.
What I want to happen with step 6 is as follows:
Client sends an any_peer RPC that sends the input to the server.
Server receives that packet, can convert it into a string, and process it. (No idea how to do this)
Server applies that input to the sending client’s player.
Edit: I could make this into a separate question, because this is a lot more specific than this one.