Bigfootmech

Why do RPCs not work on mod startup?

Recommended Posts

Bigfootmech    21

Does anyone know why a mod RPC command WON'T work during start up, but WILL run on a key press?

Spoiler

-- example modmain for a server-side mod

local NAMESPACE = "MyNamespace"
local RPCFake = "HOWhekDOwork"

local function FakeListenerAction()
	print("EASILY SEARCHABLE STRING")
	print("What is going on!!!")
end

local function RegisterFakeRPCListener()
	AddClientModRPCHandler(NAMESPACE, RPCFake, FakeListenerAction)
	AddModRPCHandler(NAMESPACE, RPCFake, FakeListenerAction)
end

local function CallFakeRPC()
	SendModRPCToServer(GetModRPC(NAMESPACE, RPCFake))
	SendModRPCToClient(GetClientModRPC(NAMESPACE, RPCFake), nil, "var")
end

RegisterFakeRPCListener()
CallFakeRPC() -- ignored / doesn't work

GLOBAL.TheInput:AddKeyDownHandler(string.byte("t"), function()
	CallFakeRPC() -- works
end)

 

 

Edited by Bigfootmech

Share this post


Link to post
Share on other sites
TheSkylarr    18

@Bigfootmech I've run into this problem as well while trying to add some abilities to my mod, RPC's aren't called correctly until the client is fully loaded is what I found, and stuff like that is called just before that's the case. I could be wrong about this though, RPC's aren't my strong suit.

Share this post


Link to post
Share on other sites
Bigfootmech    21
11 minutes ago, penguin0616 said:

Are you testing in a game with caves?

BOTH RPCs don't work?

I'm testing the game with caves (going up and down to trigger client mod load)

Both RPCs don't work on mod load. (hang on, let me double check for error)

One of them works on pressing "t" after I load in (correct behaviour)

So as Skylarr said, I'm assuming it's something to do with timing.

Although as far as I can tell, it seems to be C-side, since I can't plumb TheNet

So I was wondering if anyone knew more

Edited by Bigfootmech

Share this post


Link to post
Share on other sites
penguin0616    914

RPCs generally don't get sent unless the server is able to identify the source & target.

So you'd have to wait until you are loaded in.

Edited by penguin0616
  • Like 1

Share this post


Link to post
Share on other sites
Bigfootmech    21

Well, good news, and bad news :P

I'm pretty sure it happens inside

TheNet:SendModRPCToServer("MyNamespace", 1)

I also can't find the string inside /scripts/

But there is a hit for "Error encoding lua RPC mod namespace" inside

\bin\dontstarve_steam.exe:13290

and

\bin\dontstarve_dedicated_server_nullrenderer.exe:12285

So, it seems to be a C-side error with "encoding mod namespace" at the time of running the mod.

 

I'm assuming then, that the mod (or maybe ALL the mods) need to load before any ModRPCs can be sent?

 

This is less than ideal for me, when the only time I want to send an RPC is on mod load :p

I might already have a workaround though. Since TheNet:SendRemoteExecute() seems to work

Share this post


Link to post
Share on other sites
penguin0616    914

SendRemoteExecute is how the console sends commands to the Remote. It won't do anything unless you have permissions set on the server.

  • Like 1

Share this post


Link to post
Share on other sites
Bigfootmech    21

Wait, I was looking at the wrong place >.<

There's no point looking at server-side startup.

The call is actually sent by the client.

Then I'm seeing a

"Error decoding lua RPC sender" server side (even though SendRemoteExecute works fine to my local hosting, and shows userID)

Still seems to be C-side though

 

46 minutes ago, penguin0616 said:

SendRemoteExecute is how the console sends commands to the Remote. It won't do anything unless you have permissions set on the server.

Ah, I was thinking I could check permissions on the command myself. Guess not.

There also might be the option of something like DoTaskInTime

Alternatively, detect an event server-side for end of migration, and start communication from there.

Possibly even using Net vars (but that seems kind of horrible for sharing a long string once)

I can make it work

I just wanted to try make it work as "tightly" as possible

Edited by Bigfootmech

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now