begin network integration
[carveJwlIkooP6JGAAIwe30JlM.git] / server.c
index be19dcbf45badf78a105c4eda70843941d34492b..7d8e0e36a28d554bc2add7e18bb4b77ea7a65681 100644 (file)
--- a/server.c
+++ b/server.c
@@ -3,7 +3,7 @@
 /*
  * This server application requires steamclient.so to be present in the 
  * executable directory. This is not provided by vg system, it must be
- * downloaded via steamcmd. It will likely be somewhere in /usr/.steam/ ...
+ * downloaded via steamcmd. It will likely be somewhere in ~/.steam/ ...
  */
 
 #define _DEFAULT_SOURCE
@@ -69,28 +69,26 @@ static void new_client_connecting( HSteamNetConnection client )
    }
 }
 
-static void handle_steam_callback( CallbackMsg_t *msg )
+static void on_auth_status( CallbackMsg_t *msg )
 {
-   if( msg->m_iCallback == k_iSteamNetConnectionStatusChangedCallBack )
-   {
-      SteamNetConnectionStatusChangedCallback_t *info = (void *)msg->m_pubParam;
-      vg_info( "  Connection status changed for %lu\n", info->m_hConn );
+   SteamNetAuthenticationStatus_t *info = (void *)msg->m_pubParam;
+   vg_info( "  Authentication availibility: %s\n", 
+         string_ESteamNetworkingAvailability(info->m_eAvail) );
+   vg_info( "  %s\n", info->m_debugMsg );
+}
 
-      vg_info( "  %s -> %s\n", 
-            string_ESteamNetworkingConnectionState(info->m_info.m_eState),
-            string_ESteamNetworkingConnectionState(info->m_eOldState) );
+static void on_connect_status( CallbackMsg_t *msg )
+{
+   SteamNetConnectionStatusChangedCallback_t *info = (void *)msg->m_pubParam;
+   vg_info( "  Connection status changed for %lu\n", info->m_hConn );
 
-      if( info->m_info.m_eState==k_ESteamNetworkingConnectionState_Connecting )
-      {
-         new_client_connecting( info->m_hConn );
-      }
-   }
-   else if( msg->m_iCallback == k_iSteamNetAuthenticationStatus )
+   vg_info( "  %s -> %s\n", 
+         string_ESteamNetworkingConnectionState(info->m_info.m_eState),
+         string_ESteamNetworkingConnectionState(info->m_eOldState) );
+
+   if( info->m_info.m_eState==k_ESteamNetworkingConnectionState_Connecting )
    {
-      SteamNetAuthenticationStatus_t *info = (void *)msg->m_pubParam;
-      vg_info( "  Authentication availibility: %s\n", 
-            string_ESteamNetworkingAvailability(info->m_eAvail) );
-      vg_info( "  %s\n", info->m_debugMsg );
+      new_client_connecting( info->m_hConn );
    }
 }
 
@@ -147,7 +145,6 @@ static void poll_connections(void)
 int main( int argc, char *argv[] )
 {
    steamworks_ensure_txt( "2103940" );
-
    signal( SIGINT, inthandler );
 
    if( !vg_load_steam_symetric_key( "application_key", steam_symetric_key ) )
@@ -174,8 +171,12 @@ int main( int argc, char *argv[] )
     * Server code
     */
 
+   steam_register_callback( k_iSteamNetAuthenticationStatus, on_auth_status );
+   steam_register_callback( k_iSteamNetConnectionStatusChangedCallBack,
+                             on_connect_status );
+
    vg_success( "Steamworks API running\n" );
-   steamworks_event_loop( hsteampipe, handle_steam_callback );
+   steamworks_event_loop( hsteampipe );
 
    /*
     * Create a listener
@@ -202,12 +203,15 @@ int main( int argc, char *argv[] )
    SteamAPI_ISteamHTTP_SendHTTPRequest( hSteamHTTP, test_req, &call1->id );
 #endif
 
+   u64 server_ticks = 8000;
+
    while( !sig_stop )
    {
-      steamworks_event_loop( hsteampipe, handle_steam_callback );
+      steamworks_event_loop( hsteampipe );
       poll_connections();
 
       usleep(100000);
+      server_ticks ++;
    }
    
    SteamAPI_ISteamNetworkingSockets_DestroyPollGroup( hSteamNetworkingSockets,