More migration tools
authorhgn <hgodden00@gmail.com>
Fri, 20 Jun 2025 02:54:00 +0000 (03:54 +0100)
committerhgn <hgodden00@gmail.com>
Fri, 20 Jun 2025 02:54:00 +0000 (03:54 +0100)
src/gameserver.c
src/gameserver_database.c
src/gameserver_database.h
src/gameserver_replay.c
src/gameserver_requests.c
src/replay2.c

index 06b670b2a53f77fe936d08c248182e6bc7056471..82d61288d05d366cd43bf812186ef2b72ec6c9a0 100644 (file)
@@ -171,9 +171,8 @@ 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 );
+   _gs_monitor_journal( 0, "// Client leave (%u)\n", index );
+   gameserver_send_to_all( index, &leave, sizeof(leave), k_nSteamNetworkingSend_Reliable );
 }
 
 static void gameserver_update_all_knowledge( int client, int clear );
@@ -219,7 +218,7 @@ static void handle_new_connection( HSteamNetConnection conn )
 
    if( index == -1 )
    {
-      _gs_monitor_journal( 0, "[BAD] Hit Player limit!\n" );
+      _gs_monitor_journal( 0, "// BAD!! Hit Player limit!\n" );
       vg_error( "Server full\n" );
       SteamAPI_ISteamNetworkingSockets_CloseConnection( hSteamNetworkingSockets, conn, 4500, NULL, 1 );
       return;
@@ -231,7 +230,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 );
+      _gs_monitor_journal( 0, "// New client (%u)\n", index );
 
       _gameserver.global_uid ++;
       client->session_uid = _gameserver.global_uid;
@@ -446,7 +445,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 );
+   _gs_monitor_journal( 0, "// Authenticated client (%u)\n", client_id );
 }
 
 /*
@@ -785,6 +784,49 @@ static int _rcon_spoofid( int argc, const char *argv[] )
    return 0;
 }
 
+struct task_writeusertime
+{
+   char uid[DB_TABLE_UID_MAX];
+   u64 steamid; 
+   u32 centiseconds;
+   u64 last_second;
+   bool only_if_faster;
+};
+
+static void setlap_task( vg_async_task *task )
+{
+   THREAD_1;
+   struct task_writeusertime *info = (void *)task->data;
+   db_writeusertime( info->uid, info->steamid, info->centiseconds, info->last_second, info->only_if_faster );
+}
+
+static int _rcon_set_lap( int argc, const char *argv[] )
+{
+   if( argc != 4 )
+   {
+      vg_error( "Usage: set_lap <steamid> <table> <centiseconds> <last_second>\n" );
+      return 0;
+   }
+
+   if( strlen( argv[1] ) >= DB_TABLE_UID_MAX )
+   {
+      vg_error( "Table name too long. '%s'\n", argv[1] );
+      return 0;
+   }
+
+   vg_async_task *task = vg_allocate_async_task( &_gs_db.tasks, sizeof(struct task_writeusertime), 1 );
+   struct task_writeusertime *info = (void *)task->data;
+
+   info->steamid = strtoull( argv[0], NULL, 10 );
+   strcpy( info->uid, argv[1] );
+   info->centiseconds = strtoul( argv[2], NULL, 10 );
+   info->last_second = strtoull( argv[3], NULL, 10 );
+
+   vg_async_task_dispatch( task, setlap_task );
+
+   return 0;
+}
+
 static int _rcon_edit_user( int argc, const char *argv[] )
 {
    if( argc >= 1 )
@@ -886,9 +928,9 @@ static int _rcon_edit_user( int argc, const char *argv[] )
 
 static int _rcon_dumpdb( int argc, const char *argv[] )
 {
-   if( argc == 1 )
+   if( argc >= 1 )
    {
-      db_action_dump( argv[0] );
+      db_action_dump( argv[0], argc>1? atoi(argv[1]): 0 );
       return 1;
    }
    else
@@ -906,7 +948,9 @@ int main( int argc, const char *argv[] )
    vg_console_reg_cmd( "spoofid", _rcon_spoofid, NULL );
    vg_console_reg_cmd( "dumpdb", _rcon_dumpdb, NULL );
    vg_console_reg_cmd( "edit_user", _rcon_edit_user, NULL );
+   vg_console_reg_cmd( "setlap", _rcon_set_lap, NULL );
 
+   signal( SIGTERM, inthandler );
    signal( SIGINT, inthandler );
    signal( SIGQUIT, inthandler );
    signal( SIGPIPE, SIG_IGN );
@@ -988,7 +1032,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" );
+   _gs_monitor_journal( 0, "// Gameserver Starting\n" );
 
    while(1)
    {
@@ -1019,7 +1063,7 @@ int main( int argc, const char *argv[] )
 
 EE:vg_info( "Server end\n" );
 
-   _gs_monitor_journal( 0, "[OK] Gameserver Ending\n" );
+   _gs_monitor_journal( 0, "// Gameserver Ending\n" );
    SteamAPI_ISteamNetworkingSockets_DestroyPollGroup( hSteamNetworkingSockets, _gameserver.client_group );
    SteamAPI_ISteamNetworkingSockets_CloseListenSocket( hSteamNetworkingSockets, listener );
 
index d48a4766ab62f10455a57b3bf0b41f4643036e74..cff7600491fb1e10cfaa4636a67d495ddec36ecb 100644 (file)
@@ -390,9 +390,15 @@ enum request_status _gs_db_get_profile( vg_msg *msg, u64 steamid )
    return k_request_status_ok;
 }
 
+enum dump_mode 
+{
+   k_dump_mode_commands,
+   k_dump_mode_kv
+};
+
 struct task_db_dump
 {
-   u32 none;
+   u32 mode;
    char output_path[];
 };
 
@@ -412,8 +418,12 @@ void _gs_db_dump_task( vg_async_task *task )
    u64 master_table_addr = db->userdata_address + offsetof(struct skaterift_database, leaderboards_table),
        user_tree_addr    = db->userdata_address + offsetof(struct skaterift_database, users_tree);
 
-   fprintf( fp, "profiles\n"
-                "{\n" );
+   if( info->mode == k_dump_mode_kv )
+   {
+      fprintf( fp, "profiles\n"
+                   "{\n" );
+   }
+
    vg_tree_iter iter;
    vg_db_tree_iter_init( db, &iter, user_tree_addr );
 
@@ -424,18 +434,42 @@ void _gs_db_dump_task( vg_async_task *task )
 
       struct skaterift_profile profile;
       vg_db_read( db, profile_addr, &profile, sizeof(profile) );
-      fprintf( fp, "   0x%lx\n"
-                   "   {\n"
-                   "      name %s\n"
-                   "      cc %s\n"
-                   "      flags 0x%x\n"
-                   "   }\n", steamid, profile.name, profile.cc, profile.flags );
+
+      if( info->mode == k_dump_mode_kv )
+      {
+         fprintf( fp, "   0x%lx\n"
+                      "   {\n"
+                      "      name %s\n"
+                      "      cc %s\n"
+                      "      flags 0x%x\n"
+                      "   }\n", steamid, profile.name, profile.cc, profile.flags );
+      }
+      else
+      {
+         fprintf( fp, "edit_user %lu name \"%s\"\n", steamid, profile.name );
+
+         if( profile.cc[0] != '\0' )
+            fprintf( fp, "edit_user %lu cc %s\n", steamid, profile.cc );
+
+         if( profile.flags & 0x2 )
+            fprintf( fp, "edit_user %lu +LEGEND\n", steamid );
+
+         if( profile.flags & 0x1 )
+            fprintf( fp, "edit_user %lu +EARLY\n", steamid );
+
+         if( profile.flags & 0x8000 )
+            fprintf( fp, "edit_user %lu +ADMIN\n", steamid );
+      }
    }
 
-   fprintf( fp, "}\n" );
+   if( info->mode == k_dump_mode_kv )
+   {
+      fprintf( fp, "}\n" );
+
+      fprintf( fp, "leaderboards\n"
+                   "{\n" );
+   }
 
-   fprintf( fp, "leaderboards\n"
-                "{\n" );
    u16 table_count = vg_db_table_count( db, master_table_addr );
    for( u16 i=0; i<table_count; i ++ )
    {
@@ -443,8 +477,11 @@ void _gs_db_dump_task( vg_async_task *task )
 
       char uid[ DB_TABLE_UID_MAX ];
       vg_db_read( db, leaderboard_addr + offsetof(struct skaterift_leaderboard,uid), uid, sizeof(uid) );
-      fprintf( fp, "   %s\n"
-                   "   {\n", uid );
+      if( info->mode == k_dump_mode_kv )
+      {
+         fprintf( fp, "   %s\n"
+                      "   {\n", uid );
+      }
 
       u64 entries_addr = leaderboard_addr + offsetof(struct skaterift_leaderboard, entries);
       u16 entries_count = vg_db_table_count( db, entries_addr );
@@ -454,26 +491,37 @@ void _gs_db_dump_task( vg_async_task *task )
          struct skaterift_entry entry;
          u64 entry_addr = vg_db_table_get( db, entries_addr, j );
          vg_db_read( db, entry_addr, &entry, sizeof(entry) );
-         fprintf( fp, "      0x%lx\n"
-                      "      {\n"
-                      "         last_second %lu\n"
-                      "         centiseconds %u\n"
-                      "      }\n", entry.steamid, entry.last_second, entry.centiseconds );
+
+         if( info->mode == k_dump_mode_kv )
+         {
+            fprintf( fp, "      0x%lx\n"
+                         "      {\n"
+                         "         last_second %lu\n"
+                         "         centiseconds %u\n"
+                         "      }\n", entry.steamid, entry.last_second, entry.centiseconds );
+         }
+         else
+         {
+            
+            fprintf( fp, "setlap %lu \"%s\" %u %lu\n", entry.steamid, uid, entry.centiseconds, entry.last_second );
+         }
       }
 
-      fprintf( fp, "   }\n" );
+      if( info->mode == k_dump_mode_kv )
+         fprintf( fp, "   }\n" );
    }
-   fprintf( fp, "}\n" );
+   if( info->mode == k_dump_mode_kv )
+      fprintf( fp, "}\n" );
 
    fclose( fp );
 }
 
-void db_action_dump( const char *path )
+void db_action_dump( const char *path, bool kv_mode )
 {
    THREAD_0;
    vg_async_task *task = vg_allocate_async_task( &_gs_db.tasks, sizeof(struct task_db_dump) + strlen(path)+1, 1 );
    struct task_db_dump *info = (void *)task->data;
-   info->none = 0;
+   info->mode = kv_mode? k_dump_mode_kv: k_dump_mode_commands;
    strcpy( info->output_path, path );
    vg_async_task_dispatch( task, _gs_db_dump_task );
 }
index 3a76458788de3808c23d7f4652667e88532ca21a..cc33142da4263090fefd8b570b4cf2bd3bdf6832 100644 (file)
@@ -32,7 +32,7 @@ struct _gs_db
 }
 extern _gs_db;
 
-void db_action_dump( const char *path );
+void db_action_dump( const char *path, bool kv_mode );
 bool db_get_highscore_table_name( const char *mod_uid, const char *run_uid, char table_name[DB_TABLE_UID_MAX] );
 bool db_writeusertime( char uid[DB_TABLE_UID_MAX], u64 steamid, u32 score, u64 last_second, bool only_if_faster );
 
index d7446270bdd8645474dbc7189dba0b654416730d..a59ca24da4fd793f68d06636588232531b5d9008 100644 (file)
@@ -249,6 +249,7 @@ void _gs_replay_server_tick(void)
       _gs_replay.current_minute = new_minute;
 
       vg_info( "The new minute is: %u\n", new_minute );
+      _gs_monitor_journal( 0, "// new minute: %u\n", new_minute );
    }
 }
 
index 4c6df3e6f6da33798b7faed4999e98774fb44d13..ad645625073d2a734833f58ba596fc145e321dac 100644 (file)
@@ -140,6 +140,7 @@ void _gs_requests_tick(void)
          SteamAPI_ISteamNetworkingSockets_SendMessages( hSteamNetworkingSockets, 1, &msg, NULL );
          req->state = k_request_state_finished;
          log_request_status( req );
+         _gameserver.bytes_send1 += size;
       }
       else if( req->state == k_request_state_transfer_start )
       {
@@ -160,6 +161,7 @@ void _gs_requests_tick(void)
          SteamAPI_ISteamNetworkingSockets_SendMessages( hSteamNetworkingSockets, 1, &msg, NULL );
          req->state = k_request_state_transfer;
          log_request_status( req );
+         _gameserver.bytes_send1 += size;
       }
       else if( req->state == k_request_state_transfer )
       {
@@ -185,6 +187,7 @@ void _gs_requests_tick(void)
 
          SteamAPI_ISteamNetworkingSockets_SendMessages( hSteamNetworkingSockets, 1, &msg, NULL );
          req->send_offset += size;
+         _gameserver.bytes_send1 += size;
       }
       else if( req->state == k_request_state_finished )
       {
@@ -275,6 +278,7 @@ static void task_request_run( vg_async_task *task )
          {
             if( steamid == req->user_steamid )
             {
+               _gs_monitor_journal( 1, "edit_user %lu cc %s\n", req->user_steamid, set_cc );
                u64 user_address = vg_db_translate( &_gs_db.db, _gs_db.users_tree, steamid );
                if( user_address )
                {
@@ -374,26 +378,25 @@ static void task_request_run( vg_async_task *task )
          i64 last_second = time(NULL);
          const char *mod = vg_msg_getkvstr( &client_msg, "mod" );
          const char *route = vg_msg_getkvstr( &client_msg, "route" );
+
+         i32 centiseconds;
+         vg_msg_getkvintg( &client_msg, "time", k_vg_msg_i32, &centiseconds, NULL );
          
-         //char weekly_table[ DB_TABLE_UID_MAX ],
          char table[ DB_TABLE_UID_MAX ];
-
          if( !db_get_highscore_table_name( mod, route, table ) )
          {
             req->status = k_request_status_out_of_memory;
             goto E0;
          }
 
-         i32 centiseconds;
-         vg_msg_getkvintg( &client_msg, "time", k_vg_msg_i32, &centiseconds, NULL );
+         _gs_monitor_journal( 1, "setlap %lu \"%s\" %u %u\n", req->user_steamid, table, centiseconds, last_second );
+
          if( centiseconds < 5*100 )
          {
             req->status = k_request_status_client_error;
             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 );
       }
index 5f9050f29c75ab8f80904bd708c3116ad492846a..2446d44ec3854abe001a584611289366ae0d9a61 100644 (file)
@@ -3,8 +3,53 @@
 struct _remote_replay _remote_replay;
 struct _replay2 _replay2;
 
+static int cmd_replay2_manual_download( int argc, const char *argv[] )
+{
+   if( argc < 2 )
+   {
+      vg_error( "Usage: replay2_watch <steamid> <last_second> <minutes_span (optional)>\n" );
+      return 0;
+   }
+
+   if( _remote_replay.state != k_remote_replay_state_none )
+   {
+      vg_error( "Cant do that right now (remote replay state: %u\n", _remote_replay.state );
+      return 0;
+   }
+
+   u32 minutes_span = 1;
+   if( argc >= 3 )
+      minutes_span = strtoull( argv[2], NULL, 10 );
+
+   u64 steamid = strtoull( argv[0], NULL, 16 );
+   u64 last_second = strtoull( argv[1], NULL, 16 );
+   u32 last_minute = (u32)( last_second / 60 );
+
+   skaterift.activity = k_skaterift_default;
+   vg_queue_clear( &_remote_replay.buffer );
+   _remote_replay.min_frame_t = 0.0;
+   _remote_replay.total_chunks = minutes_span;
+   _remote_replay.chunks_downloaded = 0;
+   _remote_replay.steamid = steamid;
+   _remote_replay.state = k_remote_replay_state_init;
+   _remote_replay.last_second = last_second;
+   
+   for( u32 i=0; i<minutes_span; i ++ )
+   {
+      struct remote_replay_chunk *chunk = &_remote_replay.chunks[i];
+      chunk->minute = last_minute - minutes_span + 1 + i;
+      chunk->state = k_chunk_state_none;
+   }
+
+   gui_helper_reset( k_gui_helper_mode_clear );
+   _replay2_open_player( k_replay_type_network, 0 );
+   return 1;
+}
+
 void _replay2_init(void)
 {
+   vg_console_reg_cmd( "replay2_watch", cmd_replay2_manual_download, NULL );
+
    u32 MB = 1024*1024,
        size = 4*MB;