@@ -3,10 +3,16 @@ use std::time::Duration;
33use serde:: { Deserialize , Serialize } ;
44use uuid:: Uuid ;
55
6+ fn default_as_false ( ) -> bool {
7+ false
8+ }
9+
610#[ derive( Debug , Serialize , Deserialize ) ]
711pub struct GameDataToken {
812 pub player_db_id : i32 ,
913 pub player_uuid : Uuid ,
14+ #[ serde( default = "default_as_false" ) ]
15+ pub is_readonly : bool ,
1016 // JWT fields
1117 pub exp : u64 ,
1218 pub iat : u64 ,
@@ -15,22 +21,39 @@ pub struct GameDataToken {
1521
1622impl GameDataToken {
1723 #[ inline]
18- pub fn new_access ( player_db_id : i32 , player_uuid : Uuid , duration : Duration ) -> Self {
19- Self :: new ( "access" , player_db_id, player_uuid, duration)
24+ pub fn new_access (
25+ player_db_id : i32 ,
26+ player_uuid : Uuid ,
27+ duration : Duration ,
28+ is_readonly : bool ,
29+ ) -> Self {
30+ Self :: new ( "access" , player_db_id, player_uuid, duration, is_readonly)
2031 }
2132
2233 #[ inline]
23- pub fn new_refresh ( player_db_id : i32 , player_uuid : Uuid , duration : Duration ) -> Self {
24- Self :: new ( "refresh" , player_db_id, player_uuid, duration)
34+ pub fn new_refresh (
35+ player_db_id : i32 ,
36+ player_uuid : Uuid ,
37+ duration : Duration ,
38+ is_readonly : bool ,
39+ ) -> Self {
40+ Self :: new ( "refresh" , player_db_id, player_uuid, duration, is_readonly)
2541 }
2642
27- fn new ( token_type : & str , player_db_id : i32 , player_uuid : Uuid , duration : Duration ) -> Self {
43+ fn new (
44+ token_type : & str ,
45+ player_db_id : i32 ,
46+ player_uuid : Uuid ,
47+ duration : Duration ,
48+ is_readonly : bool ,
49+ ) -> Self {
2850 debug_assert ! ( valid_token_type( token_type) ) ;
2951
3052 let now = jsonwebtoken:: get_current_timestamp ( ) ;
3153 Self {
3254 player_db_id,
3355 player_uuid,
56+ is_readonly,
3457 exp : now + duration. as_secs ( ) ,
3558 iat : now,
3659 sub : token_type. to_string ( ) ,
0 commit comments