
    Ii/                     x    S r SSKrSSKJrJr  SSKJrJrJrJ	r	J
r
  SSKJr  \(       a  SSKJr   " S	 S
\5      rg)z-Network user implementation for real players.    N)AnyTYPE_CHECKING   )UserMenuItemEscapeBehavior
TrustLevelgenerate_uuid)UserPreferences   )ClientConnectionc                   \   \ rS rSrSrSS\R                  SS4S\S\SSS	\S-  S
\S-  S\S\	S\
\   S-  4S jjr\S\4S j5       r\S\4S j5       r\S\4S j5       rS\SS4S jr\S\4S j5       r\S\	4S j5       rS\	SS4S jrS\SS4S jr\S\4S j5       rS
\SS4S jr\SZS j5       rS[S jr\S\4S j5       rS\SS4S jr\S\4S j5       rS \SS4S! jr\S\
\   4S" j5       rS#\
\   SS4S$ jrS\4S% jrS&\ \\!4   SS4S' jr"S&\ \\!4   SS4S( jr#S\
\ \\!4      4S) jr$S\S*\S+\SS4S, jjr%S]S-\S.\&S/\&S0\&SS4
S1 jjr'S^S-\S3\	SS4S4 jjr(S_S5 jr)S`S6\S7\S8\SS4S9 jjr*S_S: jr+S;\
\\,-     S\
\\ -     4S< jr-S2\.R^                  SSS=SS>.S?\S;\
\\,-     S@\	SA\.SB\&S-  SC\	SD\&SE\	SS4SF jjr0   SaS?\S;\
\\,-     SB\&S-  SG\S-  SE\	SS4SH jjr1S?\SS4SI jr2 SbSSSJ.SK\SL\SM\SN\	SO\	SS4SP jjjr3     ScSQ\SR\SS\ST\S-  SU\S-  SL\SS4SV jjr4SK\SS4SW jr5S_SX jr6SYr7g)dNetworkUser   z
Network implementation of User for real players connected via websocket.

Queues messages to be sent asynchronously by the network layer.
NFusernamelocale
connectionr   uuidpreferencestrust_levelapprovedfluent_languagesc	                 H   U=(       d
    [        5       U l        Xl        X l        X0l        U=(       d
    [        5       U l        X`l        Xpl        U=(       d    / U l	        / U l
        [        R                  " 5       U l        SU l        SU l        0 U l        0 U l        SU l        g)z)Initialize a network-backed user session. N)r
   _uuid	_username_locale_connectionr   _preferences_trust_level	_approved_fluent_languages_message_queuetime_connected_at_client_type	_platform_current_menus_current_editboxes_current_music)	selfr   r   r   r   r   r   r   r   s	            =c:\Users\dbart\PlayPalace11\server\core\users\network_user.py__init__NetworkUser.__init__   s     ,]_
!%'<?+<'!,<,B46$(IIK!#  :<=?59    returnc                     U R                   $ )zReturn the user's UUID.)r   r+   s    r,   r   NetworkUser.uuid2   s     zzr/   c                     U R                   $ )zReturn the user's display name.)r   r2   s    r,   r   NetworkUser.username7        ~~r/   c                     U R                   $ )zReturn the user's locale.r   r2   s    r,   r   NetworkUser.locale<   s     ||r/   c                     Xl         g)zSet the user's locale.Nr8   )r+   r   s     r,   
set_localeNetworkUser.set_localeA   s    r/   c                     U R                   $ )zReturn the user's trust level.r    r2   s    r,   r   NetworkUser.trust_levelE           r/   c                     U R                   $ )z$Return True if the user is approved.r!   r2   s    r,   r   NetworkUser.approvedJ   r6   r/   c                     Xl         g)zSet the user's approval status.NrB   )r+   r   s     r,   set_approvedNetworkUser.set_approvedO       !r/   c                     Xl         g)zSet the user's trust level.Nr>   )r+   r   s     r,   set_trust_levelNetworkUser.set_trust_levelS       'r/   c                     U R                   $ )zReturn the user's preferences.r   r2   s    r,   r   NetworkUser.preferencesW   r@   r/   c                     Xl         g)zSet the user's preferences.NrM   )r+   r   s     r,   set_preferencesNetworkUser.set_preferences\   rK   r/   c                     U R                   $ )z(Return the underlying client connection.r   r2   s    r,   r   NetworkUser.connection`   s     r/   c                     Xl         g)z$Update the active client connection.NrS   )r+   r   s     r,   set_connectionNetworkUser.set_connectione   s    %r/   c                     U R                   $ )z/Return the client type (e.g. 'Desktop', 'Web').r&   r2   s    r,   client_typeNetworkUser.client_typei   r@   r/   rZ   c                     Xl         g)zSet the client type.NrY   )r+   rZ   s     r,   set_client_typeNetworkUser.set_client_typen   rK   r/   c                     U R                   $ )z"Return the client platform string.r'   r2   s    r,   platformNetworkUser.platformr   r6   r/   ra   c                     Xl         g)zSet the client platform string.Nr`   )r+   ra   s     r,   set_platformNetworkUser.set_platformw   rG   r/   c                     U R                   $ )z#Return the user's fluent languages.r"   r2   s    r,   r   NetworkUser.fluent_languages{   s     %%%r/   	languagesc                     Xl         g)z Set the user's fluent languages.Nrg   )r+   ri   s     r,   set_fluent_languages NetworkUser.set_fluent_languages   s    !*r/   c                     [         R                   " 5       U R                  -
  n[        US-  5      n[        US-  5      n[        US-  5      nUS:  a  [        US5       S3$ US:  a  U S3$ US-  nU SU S3$ )	z-Format the time this user has been connected.<   i  iQ r   m   hzd )r$   r%   intmax)r+   elapsedminuteshoursdaysremaining_hourss         r,   format_time_onlineNetworkUser.format_time_online   s    ))+ 2 22gm$GtO$7e#$19'1o&a((2:WA;"*r/*!,,r/   packetc                 :    U R                   R                  U5        g)z(Queue a packet to be sent to the client.N)r#   appendr+   r{   s     r,   _queue_packetNetworkUser._queue_packet   s    ""6*r/   c                 &    U R                  U5        g)z1Public helper to queue a raw packet for delivery.Nr   r~   s     r,   queue_packetNetworkUser.queue_packet   s    6"r/   c                 ,    U R                   n/ U l         U$ )z Get and clear the message queue.)r#   )r+   messagess     r,   get_queued_messagesNetworkUser.get_queued_messages   s    && r/   textbufferc                 D    SUS.nUS:w  a  X#S'   U R                  U5        g)z&Queue a speech message for the client.speak)typer   miscr   Nr   )r+   r   r   r{   s       r,   r   NetworkUser.speak   s*    !40V%86"r/   namevolumepanpitchc                 2    U R                  SUUUUS.5        g)z$Queue a sound effect for the client.
play_sound)r   r   r   r   r   Nr   )r+   r   r   r   r   s        r,   r   NetworkUser.play_sound   s$    $ 	
r/   Tloopingc                 @    XS.U l         U R                  SUUS.5        g)z&Start background music for the client.)r   r   
play_music)r   r   r   Nr*   r   )r+   r   r   s      r,   r   NetworkUser.play_music   s)    '+@$"	
r/   c                 8    SU l         U R                  SS05        g)z%Stop background music for the client.Nr   
stop_musicr   r2   s    r,   r   NetworkUser.stop_music   s    "FL12r/   loopintrooutroc                 0    U R                  SUUUS.5        g)z"Play ambient audio for the client.play_ambience)r   r   r   r   Nr   )r+   r   r   r   s       r,   r   NetworkUser.play_ambience   s!    '		
r/   c                 *    U R                  SS05        g)z"Stop ambient audio for the client.r   stop_ambienceNr   r2   s    r,   r   NetworkUser.stop_ambience   s    FO45r/   itemsc                     / nU HJ  n[        U[        5      (       a!  UR                  UR                  5       5        M9  UR                  U5        ML     U$ )z9Convert MenuItem objects to dicts for JSON serialization.)
isinstancer   r}   to_dict)r+   r   resultitems       r,   _convert_itemsNetworkUser._convert_items   sC    D$))dlln-d#	 
 r/   r   )multiletterescape_behaviorpositiongrid_enabled
grid_widthplay_selection_soundmenu_idr   r   r   r   r   r   c                t   U R                  U5      n	U R                  R                  U5      n
UR                  nUc5  U
(       a.  U
R                  S5      n[	        U[
        5      (       a  US:  a  UnU	UUUUUS.U R                  U'   SUU	UUUUS.nUb  US-
  US'   U(       a  SUS	'   U R                  U5        g)
zSend a menu definition to the client.

Always sends full config so the client can correctly deduplicate
and preserve escape behavior across menu switches.
Nr   r   )r   multiletter_enabledr   r   r   r   menu)r   r   r   r   r   r   r   r   Tr   )r   r(   getvaluer   rr   r   )r+   r   r   r   r   r   r   r   r   converted_itemsprevious_menu
escape_strprevious_positionr{   s                 r,   	show_menuNetworkUser.show_menu   s    " --e4++//8$**
 - 1 1* =+S116G!6K, %#.) ($(
G$ $#.)($"
 !)AF:-1F)*6"r/   selection_idc                     U R                  U5      nXR                  ;   a%  X`R                  U   S'   Ub  X0R                  U   S'   SUUS.nUb  US-
  US'   Ub  XGS'   U(       a  SUS	'   U R                  U5        g)
z-Update an existing menu's items or selection.r   Nr   r   r   r   r   r   r   Tr   )r   r(   r   )r+   r   r   r   r   r   r   r{   s           r,   update_menuNetworkUser.update_menu  s     --e4)))4C(1#;C##G,Z8 $"

 !)AF:#%1>"-1F)*6"r/   c                 f    U R                   R                  US5        U R                  SU/ S.5        g)z!Remove a menu from the client UI.Nr   r   )r(   popr   )r+   r   s     r,   remove_menuNetworkUser.remove_menu,  s4    ."	
r/   )	multiline	read_onlyinput_idpromptdefault_valuer   r   c          	      \    UUUUS.U R                   U'   U R                  SUUUUUS.5        g)z'Show a text input prompt on the client.)r   r   r   r   request_input)r   r   r   r   r   r   N)r)   r   )r+   r   r   r   r   r   s         r,   show_editboxNetworkUser.show_editbox8  sI     *""	-
) 	'$ !.&&		
r/   	dialog_idcontentcontent_labelsource_contentsource_labelc                 L    SUUUUS.nUb  XGS'   XWS'   U R                  U5        g)z.Open the document editor dialog on the client.document_editor)r   r   r   r   r   Nr   r   r   )r+   r   r   r   r   r   r   r{   s           r,   show_document_editor NetworkUser.show_document_editorS  sA     &"*"
 %'5#$%1>"6"r/   c                 <    U R                   R                  US5        g)z%Remove an editbox from the client UI.N)r)   r   )r+   r   s     r,   remove_editboxNetworkUser.remove_editboxi  s    ##Hd3r/   c                     U R                   R                  5         U R                  R                  5         U R                  SS05        g)z4Clear menus, editboxes, and UI state for the client.r   clear_uiN)r(   clearr)   r   r2   s    r,   r   NetworkUser.clear_uin  s9    !!#%%'FJ/0r/   )r!   r&   r%   r   r)   r(   r*   r"   r   r#   r'   r   r    r   r   )r0   r   )r   r   r0   N)r   )d   r   r   )T)r0   N)r   r   )NNF)r   )r   r   NNr   )8__name__
__module____qualname____firstlineno____doc__r	   USERstrr   boollistr-   propertyr   r   r   r;   r   r   rE   rI   r   rP   r   rV   rZ   r]   ra   rd   r   rk   ry   dictr   r   r   r   r   rr   r   r   r   r   r   r   r   r   KEYBINDr   r   r   r   r   r   r   __static_attributes__ r/   r,   r   r      s     .2",//-1:: : '	:
 Dj: %t+:  : : s)d*:< c   #        !Z ! ! $  "T "d "(: ($ ( !_ ! !(? (t (    & !S ! !(3 (4 ( #  "S "T " &$s) & &+d3i +D +-C -+DcN +t +#4S> #d #T$sCx.%9 ## #s # #

s 

C 

C 

C 

Z^ 

	
s 	
T 	
T 	
3
	
# 	
c 	
s 	
D 	
6Dx$8 T#*=M  !*8*@*@#"%*2#2# C(N#2#
 2# (2# *2# 2# 2# #2# 
2#p  $#'%*## C(N## *	#
 Dj# ## 
#:

3 

4 

   	
  

 
 	
 
 
 

< %)#'## # 	#
 d
# Dj# # 
#,4s 4t 4
1r/   r   )r   r$   typingr   r   baser   r   r   r	   r
   r   r   network.websocket_serverr   r   r   r/   r,   <module>r      s+    3  % K K (<e1$ e1r/   