33 * License: MIT
44 */
55
6+ use std:: collections:: HashSet ;
67use std:: path:: PathBuf ;
78
89use anyhow:: Result ;
@@ -26,6 +27,7 @@ pub(crate) struct Client {
2627 audio_player : AudioPlayer ,
2728 random : Random ,
2829 user_mode : UserMode ,
30+ admin_tags : HashSet < Tag > ,
2931 api_client : ApiClient ,
3032 party_config : PartyConfig ,
3133 event_receiver : EventReceiver ,
@@ -35,6 +37,7 @@ impl Client {
3537 pub ( crate ) fn new (
3638 sounds_path : PathBuf ,
3739 user_mode : UserMode ,
40+ admin_tags : HashSet < Tag > ,
3841 api_config : & ApiConfig ,
3942 party_config : PartyConfig ,
4043 event_receiver : EventReceiver ,
@@ -43,6 +46,7 @@ impl Client {
4346 audio_player : AudioPlayer :: new ( sounds_path) ?,
4447 random : Random :: new ( ) ,
4548 user_mode,
49+ admin_tags,
4650 api_client : ApiClient :: new ( api_config, party_config. party_id . clone ( ) ) ,
4751 party_config,
4852 event_receiver,
@@ -119,9 +123,8 @@ impl Client {
119123 Event :: ButtonPressed { button } => {
120124 log:: debug!( "Button pressed: {:?}" , button) ;
121125
122- // Submit if user has identified; ignore if no user has
123- // been specified.
124126 match current_user {
127+ CurrentUser :: Admin => self . handle_button_press_by_admin ( button) ?,
125128 CurrentUser :: User ( user_id) => {
126129 self . handle_button_press_with_identified_user ( user_id, button) ?
127130 }
@@ -166,6 +169,12 @@ impl Client {
166169 }
167170
168171 fn handle_tag_read ( & self , tag : & Tag ) -> Result < EventHandlingResult > {
172+ if self . admin_tags . contains ( tag) {
173+ self . play_sound ( Sound :: AdminModeEntered ) ;
174+ log:: info!( "Entering admin mode." ) ;
175+ return Ok ( EventHandlingResult :: SetCurrentUser ( CurrentUser :: Admin ) ) ;
176+ }
177+
169178 log:: debug!( "Requesting details for tag {} ..." , tag. value) ;
170179 match self . api_client . get_tag_details ( tag) {
171180 Ok ( details) => match details {
@@ -204,6 +213,21 @@ impl Client {
204213 }
205214 }
206215
216+ fn handle_button_press_by_admin ( & self , button : Button ) -> Result < EventHandlingResult > {
217+ Ok ( match button {
218+ Button :: Button1 => {
219+ // Leave admin mode.
220+ log:: info!( "Leaving admin mode." ) ;
221+ self . play_sound ( Sound :: AdminModeLeft ) ;
222+ EventHandlingResult :: ResetCurrentUser
223+ }
224+ _ => {
225+ // Stay in admin mode.
226+ EventHandlingResult :: KeepCurrentUser
227+ }
228+ } )
229+ }
230+
207231 fn handle_button_press_with_identified_user (
208232 & self ,
209233 user_id : & UserId ,
0 commit comments