Dialogue Manager database with server authority

Announcements, support questions, and discussion for the Dialogue System.
Hausl
Posts: 8
Joined: Thu Mar 06, 2025 4:05 am

Dialogue Manager database with server authority

Post by Hausl »

Hello there!

Im absolutely in love with the asset and know the about the save system, and how I save the state on a server if I alter the Storer.

What I want to achieve now, is that the client can not directly alter the datase, especially the LUA variables, because I want to use them for saving progress.

Is there a way to tell my server to alter the variables in the database, without the client beeing able to alter the input, how would you advice me to do that?

Or is there a better way to achieve a degree of server authority in when only thinking about the Dialogue Manager database/variables?

Thank you for your advice!
User avatar
Tony Li
Posts: 22886
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dialogue Manager database with server authority

Post by Tony Li »

Hi,

For those server-authority variables, I recommend writing C# methods to get and set values on the server instead of using dialogue database variables. Then register them with Lua and use them in dialogue entries' Conditions and Script fields (and wherever else you need, such as Dialogue System Triggers).
Hausl
Posts: 8
Joined: Thu Mar 06, 2025 4:05 am

Re: Dialogue Manager database with server authority

Post by Hausl »

Hi!

Okay, thanks for the reply, I will try it that way!
User avatar
Tony Li
Posts: 22886
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dialogue Manager database with server authority

Post by Tony Li »

Sounds good. If any questions come up on it, let me know how I can help.
Hausl
Posts: 8
Joined: Thu Mar 06, 2025 4:05 am

Re: Dialogue Manager database with server authority

Post by Hausl »

So I came up with a solution that registers set and get functions, and alters a gamestate class on my server.

My problem now is, that get functions need to be synchron calls, which makes sense, since the game might lag when I do it asynchron.

And the get request takes a few milliseconds and is asynchron. (i use socket.io)

Do you have any idea for me how I can tackle that?

I thought about syncing a local copy of the gamestate class from the server, and doing some checks on whether it makes sense that the client wants to update a variable (Im thinking about a state machine, where the client only can request transitions in a specific order for example).

But even then, if the client asks for the state locally, im a bit worried.

Do you have a direction for me here? :)

Thank you for your help!
User avatar
Tony Li
Posts: 22886
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dialogue Manager database with server authority

Post by Tony Li »

If you can start the check in the previous node, you can have it run in the background and be ready when that node comes up. It should be able to receive an answer before the player has time to advance the conversation. But if it's still waiting for a response, you could briefly show a spinning wheel or "..." until you get the response, and then advance the conversation.

For example, if your dialogue UI uses continue buttons with a StandardUIContinueButtonFastForward component, you could make a subclass of that component and override the OnFastForward method. In the overridden method, check if a server response is pending. If so, then instead of immediately continuing, wait for the response and then continue.
Hausl
Posts: 8
Joined: Thu Mar 06, 2025 4:05 am

Re: Dialogue Manager database with server authority

Post by Hausl »

Hey there again!

I wrapped my head around the questlog and the override possibilities now.

I understand that I can override the SetQuestEntryStateOverride and CurrentQuestEntryStateOverride and it makes perfect sense to the to validate this on the server and then update the questlog on the local machine.

My question now:

Is there a "simple" way how I can mimic the same Quests and variables that stored are locally, on my server,
so my server always has the authorative state, even the client decides to cheat/hack/alter the local table?

So my override checks the Quest and updates the state itself before answering the client.

Is there a class that represents the luatable and the questtable, which I can use on the server to achieve that?

Thank you in advance!
User avatar
Tony Li
Posts: 22886
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dialogue Manager database with server authority

Post by Tony Li »

Hi,

You can use these two lines of code to get the Lua data, which is where quests, variables, and the like store their values at runtime:

Code: Select all

// Get a string representation of the Lua data:
string s = PersistentDataManager.GetSaveData();

Code: Select all

// Set the Lua data from a string:
PersistentDataManager.ApplySaveData(s);
Hausl
Posts: 8
Joined: Thu Mar 06, 2025 4:05 am

Re: Dialogue Manager database with server authority

Post by Hausl »

Hi there,

thanks for the quick response!

So in theory, I can save the whole lua database as a string into a database for my user using
string s = PersistentDataManager.GetSaveData();
And restore the state, when using
PersistentDataManager.ApplySaveData(s);
?

Sorry, there where are so many options, I always thought this belongs to the whole saving process.
Awesome, I think im good now :D
User avatar
Tony Li
Posts: 22886
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dialogue Manager database with server authority

Post by Tony Li »

Yes, one line to save, one line to load.

If you want the Pixel Crushers save system to save more than just the dialogue database data, you can set up the save system and use one line to save, one line to load -- just different lines. (See How To: Use Save System with other save system assets.)
Post Reply