import es import playerlib import time import srcds.console import cmdlib # global variables # TVID = -1 # holds bot id TIMESTAMP = 0 # holds timestamp STATE = 0 # holds the recording state # end # info = es.AddonInfo() info.name = 'sbextra' info.version = '1.0' info.author = 'Eun' info.basename = 'sbextra' info.description = 'calls sbstatus & status automaticly for SourceTV' def PrintTV(text): global TVID es.cexec(TVID, 'echo "' + text + '"') def GetInHMS(seconds): hours = seconds / 3600 seconds -= 3600*hours minutes = seconds / 60 seconds -= 60*minutes return "%02d:%02d:%02d" % (hours, minutes, seconds) def ServerEmpty(): plyrs = playerlib.getPlayerList('#human') for ply in plyrs: return 0 return 1 def get_server_info(): srcds.console.get_concmd_output('status', status_callback) def status_callback(text): info = {} lines = text.split('\n') PrintTV("###################### [sbExtra - status] #####################") for line in lines: PrintTV(line) PrintTV("###############################################################") def status(): if ServerEmpty() == 0: es.ServerCommand("sb_status") get_server_info() def startrecording(args): global TVID global TIMESTAMP global STATE if STATE == 1: print ("[sbExtra]: ERROR: allready recording!") return # this finds the sourcetv bot # if TVID == -1: TVNAME = es.ServerVar("tv_name") PlayerList = es.getUseridList() for Player in PlayerList: PlayerName = es.getplayername(Player) if PlayerName == TVNAME: TVID = Player if TVID == -1: print ("[sbExtra]: ERROR: SourceTV not found, not recording!") return if (len(args) > 0): # name of demo is the arg es.set('name_of_demo', args[0]) else: # name of demo generated from time + mapname # es.format ('name_of_demo', "sbe-%1-%2", time.strftime("%Y-%m-%d-%H-%M-%S"), str(es.ServerVar('eventscripts_currentmap'))) # message for all # # es.msg("#multi", "#green [sbExtra]: #lightgreenRecording started.") # message to console # print("[sbExtra]: Recording to " + str(es.ServerVar('name_of_demo'))) # set state # STATE = 1 # start demo # es.ServerCommand("tv_record " + str(es.ServerVar('name_of_demo'))) # get start time & print record header # TIMESTAMP = int(time.strftime("%Y%m%d%H%M%S")) PrintTV("########################## [sbExtra] ##########################") PrintTV("###################### RECORDING STARTED ######################") PrintTV("##################### " + time.strftime("%H:%M:%S %d.%m.%Y") + " #####################") PrintTV("###############################################################") status() def stoprecording(args): global TIMESTAMP global STATE if STATE == 0: # if not recording dont stop anything print("[sbExtra]: Not Recording") return # get start time & print record header # endstamp = int(time.strftime("%Y%m%d%H%M%S")) PrintTV("########################## [sbExtra] ##########################") PrintTV("###################### RECORDING STOPPED ######################") PrintTV("###################### LENGTH: " + GetInHMS(endstamp - TIMESTAMP) + " #######################") PrintTV("###############################################################") # message for all # # es.msg("#multi", "#green [sbExtra]: #lightgreenRecording stopped.") # message to console # print("[sbExtra]: Recording stopped (" + GetInHMS(endstamp - TIMESTAMP) + ")") es.delayed(1, "tv_stoprecord") # delay it a bit so we can capure the end header def round_start(event_var): if STATE > 0: status() def load(): es.set(info.name,info.version) es.makepublic('sbextra') cmdlib.registerServerCommand('sbe_record', startrecording, "start recording") cmdlib.registerServerCommand('sbe_stoprecord', stoprecording, "stop recording") cmdlib.registerServerCommand('sbe_start', startrecording, "start recording") cmdlib.registerServerCommand('sbe_stop', stoprecording, "stop recording") def unload(): cmdlib.unregisterServerCommand('sbe_record') cmdlib.unregisterServerCommand('sbe_stoprecord') cmdlib.unregisterServerCommand('sbe_start') cmdlib.unregisterServerCommand('sbe_stop') stoprecording(0)