1 #include "player_remote.h"
3 static void player_remote_unwatch( struct network_player
*player
){
4 addon_cache_unwatch( k_addon_type_player
, player
->playermodel_view_slot
);
5 addon_cache_unwatch( k_addon_type_board
, player
->board_view_slot
);
8 static void player_remote_clear( struct network_player
*player
){
9 player_remote_unwatch( player
);
10 memset( player
, 0, sizeof(*player
) );
11 strcpy( player
->username
, "unknown" );
12 player
->subsystem
= k_player_subsystem_invalid
;
15 static void player_remote_rx_200_300( SteamNetworkingMessage_t
*msg
){
16 netmsg_blank
*tmp
= msg
->m_pData
;
18 if( tmp
->inetmsg_id
== k_inetmsg_playerjoin
){
19 netmsg_playerjoin
*playerjoin
= msg
->m_pData
;
20 if( !packet_minsize( msg
, sizeof(*playerjoin
) )) return;
22 if( playerjoin
->index
< vg_list_size(netplayers
.list
) ){
23 struct network_player
*player
= &netplayers
.list
[ playerjoin
->index
];
24 player_remote_clear( player
);
27 /* TODO: interpret the uids */
28 player
->board_view_slot
= 0;
29 player
->playermodel_view_slot
= 0;
31 vg_strncpy( playerjoin
->username
, player
->username
,
32 sizeof(player
->username
), k_strncpy_always_add_null
);
34 vg_info( "#%u joined with name: %s\n", player
->username
);
37 vg_error( "inetmsg_playerjoin: player index out of range\n" );
40 else if( tmp
->inetmsg_id
== k_inetmsg_playerleave
){
41 netmsg_playerleave
*playerleave
= msg
->m_pData
;
42 if( !packet_minsize( msg
, sizeof(*playerleave
) )) return;
44 if( playerleave
->index
< vg_list_size(netplayers
.list
) ){
45 struct network_player
*player
= &netplayers
.list
[ playerleave
->index
];
46 player_remote_unwatch( player
);
48 vg_info( "player leave (%d)\n", playerleave
->index
);
51 vg_error( "inetmsg_playerleave: player index out of range\n" );
54 else if( tmp
->inetmsg_id
== k_inetmsg_playerusername
){
55 netmsg_playerusername
*update
= msg
->m_pData
;
56 if( !packet_minsize( msg
, sizeof(*update
) )) return;
58 if( update
->index
< vg_list_size(netplayers
.list
) ){
59 struct network_player
*player
= &netplayers
.list
[ update
->index
];
60 vg_strncpy( update
->username
, player
->username
,
61 sizeof(player
->username
), k_strncpy_always_add_null
);
63 vg_info( "#%u changed username: %s\n", player
->username
);
66 vg_error( "inetmsg_playerleave: player index out of range\n" );
71 static void remote_player_network_imgui(void){
72 if( !network_client
.network_info
)
75 ui_rect panel
= { (vg
.window_x
/ 2) - 200, 0, 400, 600 };
76 ui_fill( panel
, (ui_colour(k_ui_bg
)&0x00ffffff)|0x50000000 );
79 const char *netstatus
= "PROGRAMMING ERROR";
81 struct { enum ESteamNetworkingConnectionState state
; const char *str
; }
83 { k_ESteamNetworkingConnectionState_None
, "None" },
84 { k_ESteamNetworkingConnectionState_Connecting
, "Connecting" },
85 { k_ESteamNetworkingConnectionState_FindingRoute
, "Finding Route" },
86 { k_ESteamNetworkingConnectionState_Connected
, "Connected" },
87 { k_ESteamNetworkingConnectionState_ClosedByPeer
, "Closed by peer" },
88 { k_ESteamNetworkingConnectionState_ProblemDetectedLocally
,
89 "Problem Detected Locally" },
90 { k_ESteamNetworkingConnectionState_FinWait
, "Fin Wait" },
91 { k_ESteamNetworkingConnectionState_Linger
, "Linger" },
92 { k_ESteamNetworkingConnectionState_Dead
, "Dead" }
94 for( u32 i
=0; i
<vg_list_size(states
); i
++ ){
95 if( states
[i
].state
== network_client
.state
){
96 netstatus
= states
[i
].str
;
100 snprintf( buf
, 512, "Network: %s", netstatus
);
101 ui_info( panel
, buf
);
102 ui_info( panel
, "---------------------" );
103 ui_info( panel
, "#-1: localplayer" );
105 for( u32 i
=0; i
<vg_list_size(netplayers
.list
); i
++ ){
106 struct network_player
*player
= &netplayers
.list
[i
];
107 if( player
->active
){
108 const char *sysname
= "invalid";
110 if( (player
->subsystem
>= 0) &&
111 (player
->subsystem
< k_player_subsystem_max
) ){
112 sysname
= player_subsystems
[ player
->subsystem
]->name
;
114 snprintf( buf
, 512, "#%u: %s [%s]", i
, player
->username
, sysname
);
115 ui_info( panel
, buf
);