Skip to content

Store world save variables at characters db#2825

Open
schell244 wants to merge 1 commit intovmangos:developmentfrom
schell244:store_worldstates_at_characters_db
Open

Store world save variables at characters db#2825
schell244 wants to merge 1 commit intovmangos:developmentfrom
schell244:store_worldstates_at_characters_db

Conversation

@schell244
Copy link
Copy Markdown
Contributor

@schell244 schell244 commented Nov 8, 2024

🍰 Pullrequest

Store world persistent variables in characters db.
This enables applying a fresh world db without losing any saved variables.

Refactored storage from a linear vector to an unordered_map for O(1) lookup, replaced the DELETE+INSERT transaction with a single REPLACE INTO, and removed the unused _InsertVariable and LoadVariable functions.

How2Test

  • Apply the changes from this PR
  • Start the server and verify that save states are now stored in world_persistent_variables in the characters db
  • Trigger a world state change (start the Stranglethorn Vale Fishing event and hand in 40 tasty fish)
  • Apply a fresh world db and reboot the server → the event should still be completed for that week

Todo / Checklist

  • None

@0blu 0blu added CPP A issue / PR which references CPP code SQL A issue / PR which references SQL code labels Nov 8, 2024
@ratkosrb
Copy link
Copy Markdown
Contributor

ratkosrb commented Nov 8, 2024

World states is already a term that exists, and it's something that's sent to client. We should not have confusing naming like this, because it implies that those are the same world states blizzard sends if you name the table like this, and that is not what it contains. Variables is our own custom indexes and values, not using blizzard's ids for stuff.

@0blu
Copy link
Copy Markdown
Collaborator

0blu commented Nov 8, 2024

variables is too generic, especially in a database like characters.
Maybe something like this:

  • persistent_world_data
  • persistent_state
  • world_persistence
  • world_progress
  • game_state
  • realm_state

or another permutation of these words?

@schell244
Copy link
Copy Markdown
Contributor Author

maybe world_persistent_variables?

@schell244 schell244 changed the title Store world save states at characters db Store world save variables at characters db Nov 8, 2024
@shudza
Copy link
Copy Markdown
Contributor

shudza commented Nov 8, 2024

... and make world database read only.

game_events is written to as well, or am I wrong?

@schell244
Copy link
Copy Markdown
Contributor Author

... and make world database read only.

game_events is written to as well, or am I wrong?

Oh yes, you're right, there are querys on game_event_creature and game_event_creature_data. Would probably make sense to move those tables to charcter db as well at some point.

@shudza
Copy link
Copy Markdown
Contributor

shudza commented Nov 8, 2024

I don't think it makes sense to change only variables then. For example, variables stores stuff like resources for war effort, but the stage it self is stored in game_events. So if the point was to make world db ephemeral/read-only, this would probably cause issues.

@schell244
Copy link
Copy Markdown
Contributor Author

Did not experience any issues with that change, but I agree that it makes sense to move the other tables as well, together with the variables. Will add some more changes when I have time.

@schell244 schell244 force-pushed the store_worldstates_at_characters_db branch 2 times, most recently from 9e01003 to bdf1813 Compare April 14, 2026 22:12
@schell244 schell244 force-pushed the store_worldstates_at_characters_db branch from bdf1813 to a2e44cd Compare April 14, 2026 22:22
@0blu
Copy link
Copy Markdown
Collaborator

0blu commented Apr 15, 2026

I don't think it makes sense to change only variables then. For example, variables stores stuff like resources for war effort, but the stage it self is stored in game_events. So if the point was to make world db ephemeral/read-only, this would probably cause issues.

We are focusing on non-admin-command induced changes to the DB.

The current war effort stage is stored in variables at index 30050 and not game_event.
This would be covered by Schell's change. 👍

But (what you probably mean,) game_event has the column disabled which is modified during runtime.
I think we need to come up with a solution to store this column in the charDb.


@schell244 Here are some sql snippets you can try to verify your changes.
At the end the server should work with just a read-only world db. (ignoring admin commands to modifying game objects or npcs)

USE world; -- whatever your db name is

-- Creates `root_readonly` user with pw `root` which only has read access to all tables
CREATE USER 'root_readonly'@'%' IDENTIFIED BY 'root';
GRANT SELECT ON *.* TO 'root_readonly'@'%';
FLUSH PRIVILEGES;

-- Grad write permissions to game_event
GRANT INSERT, UPDATE, DELETE ON game_event TO 'root_readonly'@'%';
FLUSH PRIVILEGES;

-- Revoke write permission to game_event
REVOKE INSERT, UPDATE, DELETE ON game_event FROM 'root_readonly'@'%';
FLUSH PRIVILEGES;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CPP A issue / PR which references CPP code SQL A issue / PR which references SQL code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants