Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Super duper premium serverside demo pre-recording and demo metadata #2

Merged
merged 12 commits into from
Jun 23, 2023

Conversation

TomArrow
Copy link

@TomArrow TomArrow commented Jun 14, 2023

Allows pre-recording packets for serverside demos, allowing to record defrag demos without missing start of run.

Also adds ability to add custom metadata to serverside demos, for example for more convenient processing in jamme or more precise cutting at a later point.

The metadata for the demos works by inserting an empty message at the start of the demo that starts with lastClientCommand (mandatory) and then immediately svc_EOF and then metadata following the svc_EOF, meaning it is invisible to all normal clients.

Metadata is in JSON format, meaning various keys can be set. Some default data is written into the metadata: Unix timestamp of start of the demo, writing application (EternalJK_Server) and pre-record start offset (if using pre-recording) denoting the time difference (in milliseconds) from start of demo to the time the recording was started.

Pre-recording can be enabled via sv_demoPreRecord 1 and demo metadata can be disabled via sv_demoWriteMeta 0. sv_demoPreRecordTime and sv_demoPreRecordKeyframeDistance are time values in seconds, see updates to documentation as well as pastes below. (Edited to reflect new commits)

New commands for game to control the new features:

svdemometa				// Sets a new metadata entry for server-side demos for one player. Call with clientnum, metakey, "[data]". If data is not provided, the key is cleared. metakey must be letters only, no numbers
svdemoclearmeta			// Clears metadata for server-side demos for one player. Call with clientnum.
svdemoclearprerecord	// Clears pre-record data for a particular client and forces new keyframe generation. Basically discards previously pre-recorded packets. Call with clientnum.

New cvars for server (edited after requested changes):

sv_demoPreRecord 0 // Activate server demo pre-recording so demos can be retroactively recorded for duration sv_demoPreRecordTime (seconds)
sv_demoPreRecordTime 15 // How many seconds of past packets should be stored for pre-recording
sv_demoPreRecordKeyframeDistance 5 // A demo can only start with a gamestate and full non-delta snapshot. How often should we save such a gamestate message (in seconds)? The shorter the distance, the more precisely the pre-record duration will be kept, but also the higher the RAM usage and regularity of non-delta frames being sent to the clients.
sv_demoWriteMeta 1 // Enables writing metadata to demos, which can be set by the server/game. This is invisible to normal clients and can be used for storing information about when the demo was recorded, start of the recording, and so on.

Edit: Updated after 4371f95

Edit 2: Forgot to change description text regarding sv_demoPreRecord.

TomArrow and others added 11 commits June 14, 2023 16:31
- Added game commands for setting demo metadata
- Updated docs to include serverside demo related cvars and commands including new ones
- Bit of improvement to serverside demo pre-recording regarding clearing pre-record buffer
- Implemented demo metadata using method from JK2DemoCutter
- Added sv_demoWriteMeta to enable/disable metadata writing altogether.
… prevent unexpected behavior when pre-recording is disabled.

- Memset entire preRecord struct to 0 when clearing pre-record of a client.
- Guard all serverside demo code with #ifdef DEDICATED, don't need it in client
- Replace strlenConstExpr with sizeof()
- Removed unused variables.
- Set minDeltaFrame back to 0 in a few places, just in case.
- Server pre record time is now controlled via sv_demoPreRecordTime.
- sv_demoPreRecordTime and sv_demoPreRecordKeyframeDistance are both in seconds instead of milliseconds now.
- Some extra safety checks for demo pre-recording, just in case
- Clean up possibly mysteriously leftover packages that for whatever reason weren't cleared yet before adding new messages.
- Always clear demo pre-record buffer on client disconnect, even if demo wasn't being recorded.
@taysta
Copy link
Owner

taysta commented Jun 23, 2023

Seems okay, merging

@taysta taysta merged commit 64b8343 into taysta:master Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants