From 6a1d1e01a3e93c00678169328ed0c00e6a5c5b69 Mon Sep 17 00:00:00 2001 From: hgn Date: Thu, 19 Jun 2025 01:02:47 +0100 Subject: [PATCH] scrappy journal thing --- src/gameserver.c | 8 +++++- src/gameserver_monitor.c | 53 +++++++++++++++++++++++++++++++++++++-- src/gameserver_monitor.h | 2 +- src/gameserver_requests.c | 2 ++ 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/gameserver.c b/src/gameserver.c index 942df60..06b670b 100644 --- a/src/gameserver.c +++ b/src/gameserver.c @@ -171,6 +171,7 @@ static void gameserver_player_leave( int index ){ leave.index = index; vg_info( "Player leave (%d)\n", index ); + _gs_monitor_journal( 0, "[OK] Client leave (%u)\n", index ); gameserver_send_to_all( index, &leave, sizeof(leave), k_nSteamNetworkingSend_Reliable ); } @@ -218,6 +219,7 @@ static void handle_new_connection( HSteamNetConnection conn ) if( index == -1 ) { + _gs_monitor_journal( 0, "[BAD] Hit Player limit!\n" ); vg_error( "Server full\n" ); SteamAPI_ISteamNetworkingSockets_CloseConnection( hSteamNetworkingSockets, conn, 4500, NULL, 1 ); return; @@ -229,6 +231,7 @@ static void handle_new_connection( HSteamNetConnection conn ) if( accept_status == k_EResultOK ) { vg_success( "Accepted client (id: %u, index: %d)\n", conn, index ); + _gs_monitor_journal( 0, "[OK] New client (%u)\n", index ); _gameserver.global_uid ++; client->session_uid = _gameserver.global_uid; @@ -443,6 +446,7 @@ static void gameserver_rx_auth( SteamNetworkingMessage_t *msg ) client->admin? "Admin": "User" ); gameserver_player_join( client_id ); _gs_monitor_playerjoin(); + _gs_monitor_journal( 0, "[OK] Authenticated client (%u)\n", client_id ); } /* @@ -984,6 +988,7 @@ int main( int argc, const char *argv[] ) listener = SteamAPI_ISteamNetworkingSockets_CreateListenSocketIP( hSteamNetworkingSockets, &localAddr, 0, NULL ); _gameserver.client_group = SteamAPI_ISteamNetworkingSockets_CreatePollGroup( hSteamNetworkingSockets ); _gameserver.ticks = seconds_to_server_ticks( 30.0 * 60.0 ); + _gs_monitor_journal( 0, "[OK] Gameserver Starting\n" ); while(1) { @@ -1013,7 +1018,8 @@ int main( int argc, const char *argv[] ) } EE:vg_info( "Server end\n" ); - + + _gs_monitor_journal( 0, "[OK] Gameserver Ending\n" ); SteamAPI_ISteamNetworkingSockets_DestroyPollGroup( hSteamNetworkingSockets, _gameserver.client_group ); SteamAPI_ISteamNetworkingSockets_CloseListenSocket( hSteamNetworkingSockets, listener ); diff --git a/src/gameserver_monitor.c b/src/gameserver_monitor.c index ed0e24a..5c961ea 100644 --- a/src/gameserver_monitor.c +++ b/src/gameserver_monitor.c @@ -1,3 +1,5 @@ +#include + struct { const char *html_path; @@ -181,6 +183,7 @@ void _gs_monitor_tick(void) bool _gs_monitor_start_journal( const char *path ) { _gs_monitor.journal_fp = fopen( path, "a+" ); + fseek( _gs_monitor.journal_fp, 0, SEEK_END ); if( !_gs_monitor.journal_fp ) { @@ -202,9 +205,55 @@ void _gs_monitor_set_interval( f64 seconds ) _gs_monitor.timer = 0; } -void _gs_monitor_log_event( const char *event ) +struct task_journal +{ + char buf[ 1024 ]; +}; + +void _monitor_journal_task( vg_async_task *task ) +{ + THREAD_1; + struct task_journal *info = (void *)task->data; + fputs( info->buf, _gs_monitor.journal_fp ); +} + +static void _gs_journal_va( bool thread1, const char *fmt, va_list args ) { - /* TODO */ + if( thread1 ) + { + char buf[ 1024 ]; + vsnprintf( buf, sizeof(buf), fmt, args ); + fputs( buf, _gs_monitor.journal_fp ); + } + else + { + vg_async_task *task = vg_allocate_async_task( &_gs_db.tasks, sizeof(struct task_journal), 1 ); + struct task_journal *info = (void *)task->data; + vsnprintf( info->buf, sizeof(info->buf), fmt, args ); + info->buf[sizeof(info->buf)-2] = '|'; + info->buf[sizeof(info->buf)-1] = '\0'; + vg_async_task_dispatch( task, _monitor_journal_task ); + } +} + +void _gs_monitor_journal( bool thread1, const char *message, ... ) +{ + if( _gs_monitor.journal_fp == NULL ) + return; + + if( thread1 ) + { + THREAD_1; + } + else + { + THREAD_0; + } + + va_list args; + va_start( args, message ); + _gs_journal_va( thread1, message, args ); + va_end( args ); } void _gs_monitor_playerjoin(void) diff --git a/src/gameserver_monitor.h b/src/gameserver_monitor.h index 593da76..afef769 100644 --- a/src/gameserver_monitor.h +++ b/src/gameserver_monitor.h @@ -3,6 +3,6 @@ void _gs_monitor_tick(void); bool _gs_monitor_start_journal( const char *path ); void _gs_monitor_start_html( const char *path ); void _gs_monitor_set_interval( f64 seconds ); -void _gs_monitor_log_event( const char *event ); void _gs_monitor_cleanup(void); void _gs_monitor_playerjoin(void); +void _gs_monitor_journal( bool thread1, const char *message, ... ); diff --git a/src/gameserver_requests.c b/src/gameserver_requests.c index e167e21..4c6df3e 100644 --- a/src/gameserver_requests.c +++ b/src/gameserver_requests.c @@ -392,6 +392,8 @@ static void task_request_run( vg_async_task *task ) goto E0; } + _gs_monitor_journal( 1, "[REQ] setlap %lu \"%s\" %u\n", req->user_steamid, table, centiseconds ); + if( db_writeusertime( table, req->user_steamid, centiseconds, last_second, 1 ) ) _gs_replay_request_save( req->client_id, req->user_steamid, last_second, centiseconds, 1 ); } -- 2.25.1