X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=network.c;h=838653c33e8208b1174aa319e2a0b1977933bfe4;hb=603805f69c5484316a52ee099d03254c5a1096f3;hp=a35ead4ef3a6004403c9c78d139ef345f426e127;hpb=71aba6c4108d99f39379f54b04bb71a6d2dc09b5;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/network.c b/network.c index a35ead4..838653c 100644 --- a/network.c +++ b/network.c @@ -1,6 +1,7 @@ #include "player.h" #include "network.h" #include "network_msg.h" +#include "network_common.h" #include "player_remote.h" static void scores_update(void); @@ -123,17 +124,6 @@ static void send_nickname(void){ } #endif -static void network_send_playerframe(void){ - netmsg_playerframe frame; - frame.inetmsg_id = k_inetmsg_playerframe; - v3_copy( localplayer.rb.co, frame.pos_temp ); - - SteamAPI_ISteamNetworkingSockets_SendMessageToConnection( - hSteamNetworkingSockets, network_client.remote, - &frame, sizeof(frame), - k_nSteamNetworkingSend_Unreliable, NULL ); -} - #if 0 static void server_routine_update(void){ send_score_update(); @@ -142,21 +132,78 @@ static void server_routine_update(void){ #endif static void network_send_username(void){ - netmsg_playerusername update; - memset( &update, 0, sizeof(update) ); - update.inetmsg_id = k_inetmsg_playerusername; - update.index = 0xffffffff; + netmsg_playerusername *update = alloca( sizeof(netmsg_playerusername)+ + NETWORK_USERNAME_MAX ); + update->inetmsg_id = k_inetmsg_playerusername; + update->index = 0xff; ISteamFriends *hSteamFriends = SteamAPI_SteamFriends(); const char *username = SteamAPI_ISteamFriends_GetPersonaName(hSteamFriends); - str_utf8_collapse( username, update.username, sizeof(update.username) ); + u32 chs = str_utf8_collapse( username, update->name, NETWORK_USERNAME_MAX ); SteamAPI_ISteamNetworkingSockets_SendMessageToConnection( hSteamNetworkingSockets, network_client.remote, - &update, sizeof(update), + update, sizeof(netmsg_playerusername)+chs+1, k_nSteamNetworkingSend_Reliable, NULL ); } +static void network_send_item( enum netmsg_playeritem_type type ){ + if( !network_client.remote ) + return; + + netmsg_playeritem *item = + alloca( sizeof(netmsg_playeritem) + ADDON_UID_MAX ); + item->inetmsg_id = k_inetmsg_playeritem; + item->type_index = type; + item->client = 0; + + if( (type == k_netmsg_playeritem_world0) || + (type == k_netmsg_playeritem_world1) ){ + + addon_reg *reg = world_static.addon_hub; + + if( type == k_netmsg_playeritem_world1 ) + reg = world_static.addon_client; + + if( reg ) + addon_alias_uid( ®->alias, item->uid ); + else + item->uid[0] = '\0'; + } + else{ + u16 view_id = 0; + enum addon_type addon_type = k_addon_type_none; + if( type == k_netmsg_playeritem_board ){ + view_id = localplayer.board_view_slot; + addon_type = k_addon_type_board; + } + else if( type == k_netmsg_playeritem_player ){ + view_id = localplayer.playermodel_view_slot; + addon_type = k_addon_type_player; + } + else + assert(0); + + struct addon_cache *cache = &addon_system.cache[addon_type]; + vg_pool *pool = &cache->pool; + + SDL_AtomicLock( &addon_system.sl_cache_using_resources ); + addon_cache_entry *entry = vg_pool_item( pool, view_id ); + addon_alias_uid( &entry->reg_ptr->alias, item->uid ); + SDL_AtomicUnlock( &addon_system.sl_cache_using_resources ); + } + + vg_info( "send equip: [%u] %s\n", + item->type_index, item->uid ); + u32 chs = strlen(item->uid); + + SteamAPI_ISteamNetworkingSockets_SendMessageToConnection( + hSteamNetworkingSockets, network_client.remote, + item, sizeof(netmsg_playeritem)+chs+1, + k_nSteamNetworkingSend_Reliable, NULL ); + +} + static void network_disconnect(void){ SteamAPI_ISteamNetworkingSockets_CloseConnection( hSteamNetworkingSockets, network_client.remote, 0, NULL, 0 ); @@ -195,6 +242,10 @@ static void on_server_connect_status( CallbackMsg_t *msg ){ k_nSteamNetworkingSend_Reliable, NULL ); network_send_username(); + + for( u32 i=0; im_info.m_eState == k_ESteamNetworkingConnectionState_ClosedByPeer ){ @@ -220,8 +271,12 @@ static void on_persona_state_change( CallbackMsg_t *msg ){ PersonaStateChange_t *info = (void *)msg->m_pubParam; ISteamUser *hSteamUser = SteamAPI_SteamUser(); + + vg_info( "User: %llu, change: %u\n", info->m_ulSteamID, + info->m_nChangeFlags ); + if( info->m_ulSteamID == SteamAPI_ISteamUser_GetSteamID(hSteamUser) ){ - if( info->m_nChangeFlags == k_EPersonaChangeNickname ){ + if( info->m_nChangeFlags & k_EPersonaChangeName ){ network_send_username(); } } @@ -324,10 +379,13 @@ static void network_update(void){ poll_remote_connection(); f64 frame_delta = vg.time_real - network_client.last_frame; - if( frame_delta > 0.1 ){ + if( frame_delta > NETWORK_FRAMERATE ){ network_client.last_frame = vg.time_real; - network_send_playerframe(); + remote_player_send_playerframe(); + player__clear_sfx_buffer(); } + + remote_player_debug_update(); } else { if( (state == k_ESteamNetworkingConnectionState_Connecting) ||