@@ -13,6 +13,7 @@ use crate::{
1313 RemoveReason , SettingChange , SlotType , StateChange , UNSPECIFIED_TEAM_INDEX ,
1414 } ,
1515 util:: LOCALE_NZ ,
16+ NetworkAddress ,
1617 } ,
1718 packet:: Packet ,
1819 router:: RawBlaze ,
@@ -129,8 +130,6 @@ pub struct GamePlayer {
129130 pub player : Arc < Player > ,
130131 /// Weak reference to the associated session
131132 pub link : WeakSessionLink ,
132- /// Networking information for the player
133- pub net : Arc < NetData > ,
134133 /// The mesh state of the player
135134 pub state : PlayerState ,
136135}
@@ -154,15 +153,26 @@ impl GamePlayer {
154153 /// `player` The session player
155154 /// `net` The player networking details
156155 /// `addr` The session address
157- pub fn new ( player : Arc < Player > , net : Arc < NetData > , link : WeakSessionLink ) -> Self {
156+ pub fn new ( player : Arc < Player > , link : WeakSessionLink ) -> Self {
158157 Self {
159158 player,
160159 link,
161- net,
162160 state : PlayerState :: ActiveConnecting ,
163161 }
164162 }
165163
164+ pub fn net ( & self ) -> Option < Arc < NetData > > {
165+ let session = self . link . upgrade ( ) ?;
166+ session. data . net ( )
167+ }
168+
169+ pub fn network_address ( & self ) -> NetworkAddress {
170+ match self . net ( ) {
171+ Some ( net) => net. addr . clone ( ) ,
172+ None => NetworkAddress :: Unset ,
173+ }
174+ }
175+
166176 pub fn try_clear_game ( & self ) {
167177 if let Some ( link) = self . link . upgrade ( ) {
168178 link. data . clear_game_gm ( ) ;
@@ -198,11 +208,7 @@ impl GamePlayer {
198208 GamePlayerSnapshot {
199209 player_id : self . player . id ,
200210 display_name : Box :: from ( self . player . display_name . as_ref ( ) ) ,
201- net : if include_net {
202- Some ( self . net . clone ( ) )
203- } else {
204- None
205- } ,
211+ net : if include_net { self . net ( ) } else { None } ,
206212 }
207213 }
208214
@@ -221,7 +227,7 @@ impl GamePlayer {
221227 // Player ID
222228 w. tag_u32 ( b"PID" , self . player . id ) ;
223229 // Player network data
224- w. tag_ref ( b"PNET" , & self . net . addr ) ;
230+ w. tag_ref ( b"PNET" , & self . network_address ( ) ) ;
225231 // Slot ID
226232 w. tag_owned ( b"SID" , slot) ;
227233 // Slot type
0 commit comments