import es import time import playerlib import cmdlib import cfglib info = es.AddonInfo() info.name = 'sbExtra' info.version = '1.1' info.author = 'Eun' info.basename = 'sbextra' info.description = 'calls sb_status automaticly for SourceTV' # global variables # TVID = -1 # holds bot id TIMESTAMP = 0 # holds timestamp STATE = 0 # holds the recording state # end # sbe_config = cfglib.AddonCFG('%s/sbe.cfg' % es.getAddonPath(info.basename)) sbe_print = sbe_config.cvar('sbe_print', 0, 'how messages should be printed (0=none,1=to all,2=bot says it)') sbe_config.write() def PrintTV(text): global TVID es.cexec(TVID, 'echo "' + text + '"') def SayTV(text): global TVID es.sexec(TVID, 'say "' + text + '"') def SVPrint(text): #es.ServerCommand('echo "' + text + '"') #print(text) es.dbgmsg(0, 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 SetTVID(): global TVID TVNAME = es.ServerVar("tv_name") plyrs = playerlib.getPlayerList('#spec') for ply in plyrs: if (ply.name == TVNAME): TVID = ply.userid return def sbstatus(): if ServerEmpty() == 0: es.ServerCommand("sb_status") # 2 empty lines, increases the readability ;) PrintTV("") PrintTV("") def sbecmd(args): if (len(args) == 0): if STATE == 1: endstamp = int(time.strftime("%Y%m%d%H%M%S")) SVPrint ("[" + info.name + "]: Recording to " + str(es.ServerVar('sbe_name_of_demo')) + " [" + GetInHMS(endstamp - TIMESTAMP) + "]" ) else: SVPrint ("[" + info.name + "]: Not recording"); SVPrint (" Possible commands: sbe start " ) SVPrint (" Possible commands: sbe stop" ) SVPrint (" Possible commands: sbe help" ) else: if (args[0] == "start"): if (len(args) == 2): startrecording(args[1]) else: startrecording("") elif (args[0] == "stop"): stoprecording(0) elif (args[0] == "help"): SVPrint ("[" + info.name + "]: Help" ) SVPrint (" With sbExtra (sbe) you can record your server using SourceTV" ) SVPrint (" It allows the use of sb_status (by sbsrc) in the demo") SVPrint ("") SVPrint (" Commands: ") SVPrint (" sbe start - Start recording a demo" ) SVPrint (" sbe stop - Stop recording a demo" ) SVPrint (" sbe help - Show this help" ) SVPrint ("") SVPrint (" Cvars: ") SVPrint (" sbe_print <0-2> - how messages should be printed") SVPrint (" 0 = no messages, 1 = messages to all players, 2 = messages spoken by TVBot") def startrecording(file): global TVID global TIMESTAMP global STATE if STATE == 1: SVPrint ("[" + info.name + "]: ERROR: allready recording!") return # this finds the sourcetv bot # if TVID == -1: SetTVID() if TVID == -1: SVPrint ("[" + info.name + "]: ERROR: SourceTV not found, not recording!") return if (len(file) > 0): # name of demo is the arg es.set('sbe_name_of_demo', file) else: # name of demo generated from time + mapname # es.format ('sbe_name_of_demo', "sbe-%1-%2", time.strftime("%Y-%m-%d-%H-%M-%S"), str(es.ServerVar('eventscripts_currentmap'))) # start message # if (int(sbe_print) == 1): es.msg("#multi", "#green [" + info.name + "]: #lightgreenRecording started.") elif (int(sbe_print) == 2): SayTV("Recording started.") # message to console # SVPrint("[" + info.name + "]: Recording to " + str(es.ServerVar('sbe_name_of_demo'))) # set state # STATE = 1 # start demo # es.ServerCommand("tv_record " + str(es.ServerVar('sbe_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("###############################################################") sbstatus() def stoprecording(args): global TIMESTAMP global STATE if STATE == 0: # if not recording dont stop anything SVPrint("[" + info.name + "]: 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("###############################################################") # stop message # if (int(sbe_print) == 1): es.msg("#multi", "#green [" + info.name + "]: #lightgreenRecording stopped [" + GetInHMS(endstamp - TIMESTAMP) + "].") elif (int(sbe_print) == 2): SayTV("Recording stopped [" + GetInHMS(endstamp - TIMESTAMP) + "].") # message to console # SVPrint("[" + info.name + "]: Recording stopped [" + GetInHMS(endstamp - TIMESTAMP) + "]") STATE = 0 es.delayed(1, "tv_stoprecord") # delay it a bit so we can capure the end header def round_start(event_var): if STATE > 0: sbstatus() def load(): es.set(info.basename,info.version) es.makepublic(info.basename) cmdlib.registerServerCommand('sbe', sbecmd, "sbe cmd") sbe_config.execute() def unload(): cmdlib.unregisterServerCommand('sbe') if STATE > 0: stoprecording(0)