<s> """<STR_LIT>""" <EOL> from ark . rcon_commands import RconCommands <EOL> from ark . steam . source_server_query import ArkSourceQuery <EOL> from . cli import * <EOL> from . thread_handler import ThreadHandler <EOL> from ark . storage import Storage <EOL> from ark . event_handler import EventHandler <EOL> from ark . database import Db <EOL> import time <EOL> from ark . server_control import ServerControl <EOL> from factory import Factory <EOL> Config = Factory . get ( '<STR_LIT>' ) <EOL> Lang = Factory . get ( '<STR_LIT>' ) <EOL> class Rcon ( RconCommands ) : <EOL> @ classmethod <EOL> def callback_restart ( cls , * args ) : <EOL> """<STR_LIT>""" <EOL> out ( '<STR_LIT>' ) <EOL> ServerControl . restart_server ( ) <EOL> @ classmethod <EOL> def delayed_restart ( cls , minutes , message = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> minutes = int ( minutes ) <EOL> if minutes not in [ <NUM_LIT:5> , <NUM_LIT:10> , <NUM_LIT:30> , <NUM_LIT> ] : <EOL> err = '<STR_LIT>' <EOL> out ( err ) <EOL> return False , err <EOL> def delayed_message ( minutes , message = "<STR_LIT>" ) : <EOL> if minutes == <NUM_LIT> : <EOL> cls . broadcast ( Lang . get ( '<STR_LIT>' ) . format ( '<STR_LIT>' , message ) , cls . response_callback_response_only ) <EOL> time . sleep ( <NUM_LIT:30> * <NUM_LIT> ) <EOL> minutes = <NUM_LIT:30> <EOL> if minutes == <NUM_LIT:30> : <EOL> cls . broadcast ( Lang . get ( '<STR_LIT>' ) . format ( '<STR_LIT>' , message ) , cls . response_callback_response_only ) <EOL> time . sleep ( <NUM_LIT:20> * <NUM_LIT> ) <EOL> minutes = <NUM_LIT:10> <EOL> if minutes == <NUM_LIT:10> : <EOL> cls . broadcast ( Lang . get ( '<STR_LIT>' ) . format ( '<STR_LIT>' , message ) , cls . response_callback_response_only ) <EOL> time . sleep ( <NUM_LIT:5> * <NUM_LIT> ) <EOL> cls . broadcast ( Lang . get ( '<STR_LIT>' ) . format ( '<STR_LIT>' , message ) , cls . response_callback_response_only ) <EOL> time . sleep ( <NUM_LIT:4> * <NUM_LIT> ) <EOL> cls . broadcast ( Lang . get ( '<STR_LIT>' ) . format ( '<STR_LIT>' , message ) , cls . response_callback_response_only ) <EOL> time . sleep ( <NUM_LIT:50> ) <EOL> cls . broadcast ( Lang . get ( '<STR_LIT>' ) . format ( '<STR_LIT>' , message ) , cls . response_callback_response_only ) <EOL> time . sleep ( <NUM_LIT:10> ) <EOL> Storage . restart_timestamp = None <EOL> ServerControl . restart_server ( ) <EOL> Storage . restart_timestamp = floor ( time . time ( ) + ( minutes * <NUM_LIT> ) ) <EOL> callback = lambda : delayed_message ( minutes , message ) <EOL> ThreadHandler . create_thread ( callback , looping = False ) <EOL> return True , None <EOL> @ classmethod <EOL> def set_next_restart_time ( cls , timestamp ) : <EOL> if timestamp < Storage . restart_timestamp : <EOL> Storage . restart_timestamp = timestamp <EOL> @ classmethod <EOL> def get_next_restart_string ( cls ) : <EOL> """<STR_LIT>""" <EOL> if not Storage . restart_timestamp : <EOL> return None , '<STR_LIT>' <EOL> seconds_left = Storage . restart_timestamp - time . time ( ) <EOL> return seconds_left , time_countdown ( seconds_left ) <EOL> @ staticmethod <EOL> def is_admin ( steam_id = None , steam_name = None ) : <EOL> player = Db . find_player ( steam_id = steam_id , steam_name = steam_name ) <EOL> if not player : <EOL> return False <EOL> if player . admin : <EOL> return True <EOL> return False <EOL> @ classmethod <EOL> def reconnect ( cls ) : <EOL> EventHandler . triggerEvent ( EventHandler . E_DISCONNECT , Storage . players_online_steam_name ) <EOL> Storage . players_online_steam_name = { } <EOL> super ( ) . reconnect ( ) <EOL> @ staticmethod <EOL> def find_online_steam_id ( steam_name = None ) : <EOL> for steam_id , name in Storage . players_online_steam_name . items ( ) : <EOL> if steam_name == name : <EOL> return steam_id <EOL> return None <EOL> @ classmethod <EOL> def debug_compare_packet_count ( cls ) : <EOL> out ( "<STR_LIT>" . format ( len ( Rcon . incoming_packets ) , len ( Rcon . outgoing_packets ) ) ) <EOL> @ classmethod <EOL> def init ( cls , host , port , query_port , password , timeout = None ) : <EOL> if host is None or port is None : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> if password is None : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> result , err = cls . socket_connect ( host , port , query_port , password , timeout ) <EOL> if not result : <EOL> cls . reconnect ( ) <EOL> ThreadHandler . create_thread ( cls . listen ) <EOL> ThreadHandler . create_thread ( cls . loop_communication ) <EOL> @ classmethod <EOL> def response_callback_default ( cls , packet ) : <EOL> out ( '<STR_LIT>' . format ( packet . outgoing_command , packet . decoded [ "<STR_LIT:body>" ] . strip ( ) ) ) <EOL> @ classmethod <EOL> def response_callback_response_only ( cls , packet ) : <EOL> out ( '<STR_LIT>' . format ( packet . decoded [ "<STR_LIT:body>" ] . strip ( ) ) ) <EOL> @ classmethod <EOL> def none_response_callback ( cls , packet ) : <EOL> pass <EOL> @ staticmethod <EOL> def query_server ( ) : <EOL> Storage . query_data = ArkSourceQuery . query_info ( Config . rcon_host , Config . query_port ) <EOL> return Storage . query_data </s>
