scrappy journal thing
authorhgn <hgodden00@gmail.com>
Thu, 19 Jun 2025 00:02:47 +0000 (01:02 +0100)
committerhgn <hgodden00@gmail.com>
Thu, 19 Jun 2025 00:02:47 +0000 (01:02 +0100)
src/gameserver.c
src/gameserver_monitor.c
src/gameserver_monitor.h
src/gameserver_requests.c

index 942df60599776a4e990830314d732818f16fc8db..06b670b2a53f77fe936d08c248182e6bc7056471 100644 (file)
@@ -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 );
 
index ed0e24aa317a6a5dc7ac012b78ae217c9ad81451..5c961ea6a4464f7f58d6f8d0092c34d1975a5b1d 100644 (file)
@@ -1,3 +1,5 @@
+#include <stdarg.h>
+
 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)
index 593da7609c138de80e3b99298d1dcd805e6039c5..afef7693b6be8d9e1b9661209d3bd7c8fb1e7c5d 100644 (file)
@@ -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, ... );
index e167e21551dde0bc26d2ad8a9d3a09c6909bc333..4c6df3e6f6da33798b7faed4999e98774fb44d13 100644 (file)
@@ -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 );
       }