X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=gameserver.c;h=cd1678a2d3612f73c38f8052f56f400ff9aec1c7;hb=874c9d7e6ee2d826f9eb34518e8163283439c38e;hp=9ac4b2f05ef3bbed94ee7e207058d11ddae88c54;hpb=4bf136afb77a4c2937952b9152165f1ddcd2da9d;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/gameserver.c b/gameserver.c index 9ac4b2f..cd1678a 100644 --- a/gameserver.c +++ b/gameserver.c @@ -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; } @@ -458,6 +515,19 @@ static void gameserver_rx_200_300( SteamNetworkingMessage_t *msg ){ gameserver_send_to_all( client_id, prop, msg->m_cbSize, k_nSteamNetworkingSend_Reliable ); } + else if( tmp->inetmsg_id == k_inetmsg_chat ){ + netmsg_chat *chat = msg->m_pData, + *prop = alloca( sizeof(netmsg_chat) + NETWORK_MAX_CHAT ); + prop->inetmsg_id = k_inetmsg_chat; + prop->client = client_id; + + u32 l = network_msgstring( chat->msg, msg->m_cbSize, sizeof(netmsg_chat), + prop->msg, NETWORK_MAX_CHAT ); + vg_info( "[%d]: %s\n", client_id, prop->msg ); + + gameserver_send_to_all( client_id, prop, sizeof(netmsg_chat)+l+1, + k_nSteamNetworkingSend_Reliable ); + } else { vg_warn( "Unknown inetmsg_id recieved from client. (%u)\n", tmp->inetmsg_id ); @@ -565,11 +635,11 @@ static void gameserver_process_user_request( db_request *db_req ){ vg_msg_init( &data, req->q, msg->m_cbSize - sizeof(netmsg_request) ); /* create response packet */ - netmsg_request *res = alloca( sizeof(netmsg_request) + 512 ); + netmsg_request *res = alloca( sizeof(netmsg_request) + NETWORK_REQUEST_MAX ); res->inetmsg_id = k_inetmsg_response; res->id = req->id; vg_msg body; - vg_msg_init( &body, res->q, 512 ); + vg_msg_init( &body, res->q, NETWORK_REQUEST_MAX ); const char *endpoint = vg_msg_getkvstr( &data, "endpoint" ); @@ -704,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 );