server version check
[carveJwlIkooP6JGAAIwe30JlM.git] / gameserver.c
index 3ff58f1d40936e2abea9daf5923691f8318b7571..9116a34eb3aa240fc4e556fbb54471496bd620ab 100644 (file)
@@ -54,6 +54,18 @@ static void gameserver_send_to_all( int ignore,
    }
 }
 
+static void gameserver_send_version_to_client( int index ){
+   struct gameserver_client *client = &gameserver.clients[index];
+
+   netmsg_version version;
+   version.inetmsg_id = k_inetmsg_version;
+   version.version = NETWORK_SKATERIFT_VERSION;
+   SteamAPI_ISteamNetworkingSockets_SendMessageToConnection(
+         hSteamNetworkingSockets, client->connection,
+         &version, sizeof(netmsg_version), 
+         k_nSteamNetworkingSend_Reliable, NULL );
+}
+
 /*
  * handle server update that client #'index' has joined
  */
@@ -68,8 +80,10 @@ static void gameserver_player_join( int index ){
                            k_nSteamNetworkingSend_Reliable );
 
    /* 
-    * update the joining user about current connections 
+    * update the joining user about current connections and our version
     */
+   gameserver_send_version_to_client( index );
+
    netmsg_playerusername *username = 
       alloca( sizeof(netmsg_playerusername) + NETWORK_USERNAME_MAX );
    username->inetmsg_id = k_inetmsg_playerusername;
@@ -189,11 +203,6 @@ static void handle_new_connection( HSteamNetConnection conn ){
       
       SteamAPI_ISteamNetworkingSockets_SetConnectionUserData(
             hSteamNetworkingSockets, conn, index );
-      
-      if( gameserver.auth_mode != eServerModeAuthentication ){
-         client->steamid = k_steamid_max;
-         gameserver_player_join( index );
-      }
    }
    else{
       vg_warn( "Error accepting connection (id: %u)\n", conn );
@@ -263,14 +272,52 @@ static void on_connect_status( CallbackMsg_t *msg ){
    }
 }
 
+static void gameserver_rx_version( SteamNetworkingMessage_t *msg ){
+   netmsg_version *version = msg->m_pData;
+
+   int client_id = gameserver_conid( msg->m_conn );
+   if( client_id == -1 ) {
+      vg_warn( "Recieved version from unkown connection (%u)\n", msg->m_conn );
+      SteamAPI_ISteamNetworkingSockets_CloseConnection( 
+            hSteamNetworkingSockets, msg->m_conn,
+            k_ESteamNetConnectionEnd_Misc_InternalError,
+            NULL, 1 );
+      return;
+   }
+
+   struct gameserver_client *client = &gameserver.clients[ client_id ];
+
+   if( client->version ){
+      vg_warn( "Already have version for this client (%d conn: %u)", 
+               client_id, msg->m_conn );
+      return;
+   }
+
+   client->version = version->version;
+
+   if( client->version != NETWORK_SKATERIFT_VERSION ){
+      gameserver_send_version_to_client( client_id );
+      remove_client( client_id );
+      return;
+   }
+
+   /* this is the sign on point for non-auth servers,
+    * for auth servers it comes at the end of rx_auth 
+    */
+   if( gameserver.auth_mode != eServerModeAuthentication ){
+      client->steamid = k_steamid_max;
+      gameserver_player_join( client_id );
+   }
+}
+
 /* 
  * recieve auth ticket from connection. will only accept it if we've added them
  * to the client list first.
  */
 static void gameserver_rx_auth( SteamNetworkingMessage_t *msg ){
    if( gameserver.auth_mode != eServerModeAuthentication ){
-      vg_error( "Running server without authentication. "
-                "Connection %u tried to authenticate.\n", msg->m_conn );
+      vg_warn( "Running server without authentication. "
+               "Connection %u tried to authenticate.\n", msg->m_conn );
       return;
    }
 
@@ -278,21 +325,30 @@ static void gameserver_rx_auth( SteamNetworkingMessage_t *msg ){
    if( client_id == -1 ) {
       vg_warn( "Recieved auth ticket from unkown connection (%u)\n", 
                msg->m_conn );
+      SteamAPI_ISteamNetworkingSockets_CloseConnection( 
+            hSteamNetworkingSockets, msg->m_conn,
+            k_ESteamNetConnectionEnd_Misc_InternalError, NULL, 1 );
       return;
    }
 
    struct gameserver_client *client = &gameserver.clients[ client_id ];
-
    if( client->steamid ){
       vg_warn( "Already authorized this user but another app ticket was sent"
                " again (%d conn: %u)\n", client_id, msg->m_conn );
       return;
    }
 
+   if( client->version == 0 ){
+      vg_error( "Client has not sent their version yet (%u)\n", msg->m_conn );
+      remove_client( client_id );
+      return;
+   }
+
    vg_low( "Attempting to verify user\n" );
 
    if( msg->m_cbSize < sizeof(netmsg_auth) ){
       vg_error( "Malformed auth ticket, too small (%u)\n", msg->m_conn );
+      remove_client( client_id );
       return;
    }
 
@@ -301,7 +357,8 @@ static void gameserver_rx_auth( SteamNetworkingMessage_t *msg ){
    if( msg->m_cbSize < sizeof(netmsg_auth)+auth->ticket_length ||
        auth->ticket_length > 1024 ){
       vg_error( "Malformed auth ticket, ticket_length incorrect (%u)\n",
-            auth->ticket_length );
+                  auth->ticket_length );
+      remove_client( client_id );
       return;
    }
 
@@ -717,6 +774,9 @@ static void poll_connections(void){
          else{
             if( tmp->inetmsg_id == k_inetmsg_auth )
                gameserver_rx_auth( msg );
+            else if( tmp->inetmsg_id == k_inetmsg_version ){
+               gameserver_rx_version( msg );
+            }
             else {
                vg_warn( "Unknown inetmsg_id recieved from client. (%u)\n",
                         tmp->inetmsg_id );