X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=gameserver.c;h=8db34132f61adb0ebc5386bfcbe40492cc9a25ef;hb=46f4e9ee87dc67402166e4c6b05efbe922cd7574;hp=c63711ab30883f6cfcea0d17f09e2f5b611635f7;hpb=22f62f001f21d1b91fefd9fc495c122d9ddf205a;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/gameserver.c b/gameserver.c index c63711a..8db3413 100644 --- a/gameserver.c +++ b/gameserver.c @@ -34,21 +34,87 @@ static void set_connection_authsteamid(HSteamNetConnection con, u64_steamid id){ hSteamNetworkingSockets, con, userdata ); } +static void gameserver_player_join( int index ){ + for( int i=0; iactive ) + continue; + + netmsg_playerjoin join; + join.inetmsg_id = k_inetmsg_playerjoin; + join.index = index; + join.board_uid[0] = '\0'; + join.playermodel_uid[0] = '\0'; + join.username[0] = '\0'; + + SteamAPI_ISteamNetworkingSockets_SendMessageToConnection( + hSteamNetworkingSockets, client->connection, + &join, sizeof(join), k_nSteamNetworkingSend_Reliable, NULL ); + } +} + +static void gameserver_player_leave( int index ){ + for( int i=0; iactive ) + continue; + + netmsg_playerjoin leave; + leave.inetmsg_id = k_inetmsg_playerjoin; + leave.index = index; + + SteamAPI_ISteamNetworkingSockets_SendMessageToConnection( + hSteamNetworkingSockets, client->connection, + &leave, sizeof(leave), k_nSteamNetworkingSend_Reliable, NULL ); + } +} + static void new_client_connecting( HSteamNetConnection client ){ + int index = -1; + + /* TODO: LRU */ + for( int i=0; im_info.m_eState==k_ESteamNetworkingConnectionState_Connecting ){ new_client_connecting( info->m_hConn ); } + + if( (info->m_info.m_eState == + k_ESteamNetworkingConnectionState_ClosedByPeer ) || + (info->m_info.m_eState == + k_ESteamNetworkingConnectionState_ProblemDetectedLocally ) ){ + + for( int i=0; iactive ){ + if( client->connection == info->m_hConn ){ + client->connection = 0; + client->active = 0; + gameserver_player_leave(i); + break; + } + } + } + + vg_info( "End reason: %d\n", info->m_info.m_eEndReason ); + SteamAPI_ISteamNetworkingSockets_CloseConnection( + hSteamNetworkingSockets, info->m_hConn, 0, NULL, 0 ); + } } static void on_inet_auth( SteamNetworkingMessage_t *msg ){ @@ -150,7 +239,7 @@ static int inet_require_auth( SteamNetworkingMessage_t *msg ){ if( get_connection_authsteamid( msg ) == k_connection_unauthorized ){ vg_warn( "Unauthorized request! Disconnecting client: %u\n", - msg->m_conn ); + msg->m_conn ); SteamAPI_ISteamNetworkingSockets_CloseConnection( hSteamNetworkingSockets, @@ -221,11 +310,7 @@ static void on_inet_playerframe( SteamNetworkingMessage_t *msg ){ return; } - netmsg_playerframe *info = msg->m_pData; - vg_info( "... @: %.2f %.2f %.2f\n", - //msg->m_identityPeer, - info->pos_temp[0], info->pos_temp[1], info->pos_temp[2] ); } static void poll_connections(void){