}
}
+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
*/
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;
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 );
}
}
+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;
}
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;
}
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;
}
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 );
}
static void network_send_username(void){
+ if( !network_connected() )
+ return;
+
netmsg_playerusername *update = alloca( sizeof(netmsg_playerusername)+
NETWORK_USERNAME_MAX );
update->inetmsg_id = k_inetmsg_playerusername;
SteamAPI_ISteamNetworkingSockets_CloseConnection(
hSteamNetworkingSockets, network_client.remote, 0, NULL, 0 );
network_client.remote = 0;
+ network_client.state = k_ESteamNetworkingConnectionState_None;
for( int i=0; i<vg_list_size(netplayers.list); i++ ){
netplayers.list[i].active = 0;
k_ESteamNetworkingConnectionState_Connected ){
vg_success(" Connected to remote server.. authenticating\n");
+ /* send version info to server */
+ netmsg_version version;
+ version.inetmsg_id = k_inetmsg_version;
+ version.version = NETWORK_SKATERIFT_VERSION;
+ SteamAPI_ISteamNetworkingSockets_SendMessageToConnection(
+ hSteamNetworkingSockets, network_client.remote, &version,
+ sizeof(netmsg_version), k_nSteamNetworkingSend_Reliable, NULL );
+
/* TODO: We should really wait to see if the server is in auth mode
* first... */
u32 size = sizeof(netmsg_auth) + network_client.app_key_length;
SteamAPI_ISteamNetworkingSockets_SendMessageToConnection(
hSteamNetworkingSockets, network_client.remote, auth, size,
k_nSteamNetworkingSend_Reliable, NULL );
-
- network_send_username();
-
- for( u32 i=0; i<k_netmsg_playeritem_max; i ++ ){
- network_send_item(i);
- }
}
else if( info->m_info.m_eState ==
k_ESteamNetworkingConnectionState_ClosedByPeer ){
if( info->m_info.m_eEndReason ==
- k_ESteamNetConnectionEnd_Remote_Max ){
+ k_ESteamNetConnectionEnd_Misc_InternalError ){
network_client.retries = 40;
}
network_disconnect();
hSteamNetworkingSockets, &remoteAddr, 0, NULL );
}
+static void network_sign_on_complete(void){
+ vg_success( "Sign on completed\n" );
+
+ /* send our init info */
+ network_send_username();
+ for( u32 i=0; i<k_netmsg_playeritem_max; i ++ ){
+ network_send_item(i);
+ }
+}
+
static void poll_remote_connection(void){
SteamNetworkingMessage_t *messages[32];
int len;
else if( (tmp->inetmsg_id >= 300) && (tmp->inetmsg_id < 400) ){
network_request_rx_300_400( msg );
}
+ else {
+ if( tmp->inetmsg_id == k_inetmsg_version ){
+ netmsg_version *version = msg->m_pData;
+ if( version->version != NETWORK_SKATERIFT_VERSION ){
+ network_disconnect();
+ /* we dont want to connect to this server ever */
+ network_client.retries = 999;
+ network_client.last_attempt = 999999999.9;
+ vg_error( "version mismatch with server\n" );
+ }
+ else {
+ network_client.remote_version = version->version;
+ network_sign_on_complete();
+ }
+ }
+ }
SteamAPI_SteamNetworkingMessage_t_Release( msg );
}