-#ifdef SR_NETWORKED
-
-/*
- * Runtime connection stuff
- */
-static u8 steam_app_ticket[ 1024 ];
-static u32 steam_app_ticket_length;
-
-static HSteamNetConnection cremote;
-static ESteamNetworkingConnectionState cremote_state =
- k_ESteamNetworkingConnectionState_None;
-
-/*
- * Implementation
- */
-
-static void scores_update(void);
-
-static void on_auth_ticket_recieved( void *result, void *context )
-{
- EncryptedAppTicketResponse_t *response = result;
-
- if( response->m_eResult == k_EResultOK )
- {
- vg_info( " New app ticket ready\n" );
- }
- else
- {
- vg_warn( " Could not request new encrypted app ticket (%u)\n",
- response->m_eResult );
- }
-
- if( SteamAPI_ISteamUser_GetEncryptedAppTicket( hSteamUser,
- steam_app_ticket,
- vg_list_size(steam_app_ticket),
- &steam_app_ticket_length ))
- {
- vg_success( " Loaded app ticket (%u bytes)\n", steam_app_ticket_length );
- }
- else
- {
- vg_error( " No ticket availible\n" );
- steam_app_ticket_length = 0;
- }
-}
-
-static void request_auth_ticket(void)
-{
- /*
- * TODO Check for one thats cached on the disk and load it.
- * This might be OK though because steam seems to cache the result
- */
-
- vg_info( "Requesting new authorization ticket\n" );
- steam_async *call = steam_new_async();
- call->data = NULL;
- call->p_handler = on_auth_ticket_recieved;
- call->id = SteamAPI_ISteamUser_RequestEncryptedAppTicket( hSteamUser,
- NULL, 0 );
-}
-
-static void server_connect(void)
-{
- /* Connect to server if not connected */
-
- SteamNetworkingIPAddr remoteAddr;
-
-#define USE_LOCALHOST
-#ifdef USE_LOCALHOST
- SteamAPI_SteamNetworkingIPAddr_SetIPv6LocalHost( &remoteAddr, 27402 );
-#else
- const char *server_lon1 = "46.101.34.155:27402";
- SteamAPI_SteamNetworkingIPAddr_ParseString( &remoteAddr, server_lon1 );
-#endif
-
- char buf[256];
- SteamAPI_SteamNetworkingIPAddr_ToString( &remoteAddr, buf, 256, 1 );
- vg_info( "connect to: %s\n", buf );
-
- cremote = SteamAPI_ISteamNetworkingSockets_ConnectByIPAddress(
- hSteamNetworkingSockets, &remoteAddr, 0, NULL );
-}
-
-static void send_auth_ticket(void)
-{
- u32 size = sizeof(netmsg_auth) + steam_app_ticket_length;
- netmsg_auth *auth = malloc(size);
-
- auth.inetmsg_id = k_inetmsg_auth;
- auth.ticket_length = steam_app_ticket_length;
- for( int i=0; i<steam_app_ticket_length; i++ )
- auth.ticket[i] = steam_app_ticket[i];
-
- SteamAPI_ISteamNetworkingSockets_SendMessageToConnection(
- hSteamNetworkingSockets, cremote, auth, size,
- k_nSteamNetworkingSend_Reliable, NULL );
-
- free( auth );
-}
-
-static void scores_update(void)
-{
- vg_log( "scores_update()\n" );
-
- if( cremote_state == k_ESteamNetworkingConnectionState_Connected )
- {
- /*
- * request updated scores, this does not require any authentication.
- */
- netmsg_scores_request req;
- req.inetmsg_id = k_inetmsg_scores_request;
-
- SteamAPI_ISteamNetworkingSockets_SendMessageToConnection(
- hSteamNetworkingSockets, cremote, &req,
- sizeof(netmsg_scores_request),
- k_nSteamNetworkingSend_Reliable, NULL );
-
- /*
- * Send record update, it requires authentication
- */
- if( steam_app_ticket_length )
- {
- }
- }
- else
- {
- /*
- * if we are not connected, make a connection to the server and then in
- * the future this function will be called again when it is connected
- */
- server_connect();
- }
-}
-
-static void poll_connection(void)
-{
- SteamNetworkingMessage_t *messages[32];
- int len;