def lap_time(self,insim,lap): InsimClient.lap_time(self, insim, lap) plid=lap.PLID if(not self.drivers[self.driversID[plid]].username.lower()==self.lic.lower()): return self.curlap=lap.LapsDone+1 self.draw_pbut()
def hidden_message(self, insim, msg): InsimClient.hidden_message(self, insim, msg) try: t=msg.Msg print t t=t.split(" ") print t cmd=t[0] if(cmd=="evtset"): #the last item is the time tm=float(t[-1:][0])*60 m=" ".join(t[1:-1]) print tm self.set_evt(tm, m) elif(cmd=="evtpause"): self.pause_evt() elif(cmd=="evtclear"): self.clear_evt() elif(cmd=="evtunpause"): self.unpause_evt() except: print "Command error" print msg.Msg
def chat_message(self,insim,mso): InsimClient.chat_message(self, insim, mso) if(mso.Msg.count("start_cam_changer")>0): self.begin() elif("camtest" in mso.Msg): self.camtest()
def hidden_message(self, insim, msg): InsimClient.hidden_message(self, insim, msg) msg=msg.Msg action=msg print action if(action=='top_crash'): self.draw_top_crashers()
def hidden_message(self, insim, msg): ''' admin messages sent with /i ''' InsimClient.hidden_message(self, insim, msg) self.sendChat("Hidden message: "+msg.Msg)
def __init__(self): ''' Constructor ''' InsimClient.__init__(self, 'TESTINSIM') self.flags=pyinsim.ISF_HLV| pyinsim.ISF_CON | pyinsim.ISF_OBH self.sa=self.config.get("test","showall")
def chat_message(self, insim, mso): InsimClient.chat_message(self, insim, mso) if (mso.Msg.count("start_cam_changer") > 0): self.begin() elif ("camtest" in mso.Msg): self.camtest()
def button_clicked(self,insim,rsp): InsimClient.button_clicked(self, insim, rsp) #bclicked #print 'Button clicked ID: ' +str(rsp.ClickID) + 'flag: '+str(rsp.CFlags) c=rsp.ClickID if(c==50): #close list self.hide_list() elif(c==51): #prev self.hide_list() self.curpage=max(0,self.curpage-1) self.print_crash_list() elif(c==52): #next self.hide_list() self.curpage=min(len(self.crash_list)/25,self.curpage+1) self.print_crash_list() elif(c==10): self.print_crash_list() else: self.hide_list() #these are "Go to accident buttons" id=rsp.ReqI-1 print 'Go to accident ',id self.go_to_crash(self.crash_list[id])
def __init__(self): ''' Constructor ''' InsimClient.__init__(self, 'CRASH LIST') self.version=0.1 self.curpage=0 self.track='' self.top=40 self.left=10 self.crash_msg_queue=deque([]) #crash msgs queue self.warn_color='^1' self.last_time_crash=0 self.crash_list=[] self.crash_counter={} self.tmp=0 self.driver_focus=0 self.flags=pyinsim.ISF_CON|pyinsim.ISF_OBH #read csv, previous crashes if(self.config.get("crash_list","read_clist")=="yes"): print "reading csv" self.read_csv() print "Read ",len(self.crash_list), " rows " #count crashes for cr in self.crash_list: self.count_crash(cr.car_A) self.count_crash(cr.car_B)
def __init__(self): ''' Constructor ''' InsimClient.__init__(self, 'TESTINSIM') self.flags = pyinsim.ISF_HLV | pyinsim.ISF_CON | pyinsim.ISF_OBH self.sa = self.config.get("test", "showall")
def recv_MCI(self, insim, rsp): InsimClient.recv_MCI(self, insim, rsp) #print "Receiving MCI ",round(time.time()-self.tmp,4)*1000 self.tmp = time.time() pen = self.config.get('custom_launcher', 'penalty') c_on_j = self.config.get('custom_launcher', 'cancel_on_jumpstart') if (self.state >= (self.num_lights + 2)): return #green flag already abort_start = False try: t = time.time() #Check all drivers, 0.26 is 1 km/h aprox. for i in self.drivers: if (self.drivers[i].car_speed >= 0.26): if (self.drivers[i].username not in self.pen_given): self.pen_given.append(self.drivers[i].username) #send penalty if ((not pen == 'none') or c_on_j == 'no'): if ((not pen == 'none')): self.print_log("Penalizing driver " + self.drivers[i].playername + " for jumpstart.") self.sendMsg(self.drivers[i].username, '/' + pen + ' ') #calculate EST est = pyinsim.time( int(self.launch_stime + round(t - self.launch_tstamp, 4) * 1000)) est = str(est[0]) + 'h' + str(est[1]) + 'm' + str( est[2]) + '.' + str(est[3]) + 's' self.print_log( 'Jumpstart of ' + self.drivers[i].playername + ' License: ' + self.drivers[i].username.decode('latin-1') + ' Car speed:' + str(round(self.drivers[i].car_speed / 0.26, 3)) + ' (EST: ' + est + ')') self.sendMsg( '^7' + self.config.get('custom_launcher', 'msg1') + ' ' + self.drivers[i].playername) if (c_on_j == 'yes' and self.state < Custom_Launcher.CANCELLED_STATE): abort_start = True #print 'Jump of '+self.drivers[i].playername #print 'Speed ',self.drivers[i].car_speed #print '---' if (abort_start): self.cancel_start() except: print '[ERROR]: Error dealing with MCI packets.' print "Unexpected error:", sys.exc_info()[0]
def car_contact (self, insim, info): InsimClient.car_contact(self, insim, info) print info mcar=info.A #track='KY1R' if(info.SpClose>1): driv_a='' driv_b='' try: driv_a=self.drivers[self.driversID[info.A.PLID]].playername driv_b=self.drivers[self.driversID[info.B.PLID]].playername except: print 'Cant locate driver name, maybe this key is deleted PLID A:',str(info.A.PLID),' B ',info.B.PLID return m= 'Contacto ^7A '+ driv_a+ ' y B'+ driv_b print m print info.Time self.sendMsg(m) p=[mcar.X/16, mcar.Y/16 ] #KY1R Nodes t_coords=[[-461,181],[-484,295],[-485 , 681],[-104 , 845],[187 , 594],[ 250 , 260],[54 , -81],[-354 , -57]] t_names=['T1','T1-T2','T2','T2-T3','T3','T3-T4','T4','T4-T1'] #KY1 Nodes if(self.track=='KY1'): t_coords.reverse() tmp=0 m=9000000 t_f=0 for pl in t_coords: p1=pl if(t_coords.index(pl)==len(t_coords)-1): #last element p2=t_coords[0] else: p2=t_coords[t_coords.index(pl)+1] d=self.pointline_dist(p1, p2, p) print 'Distance To Line ',tmp, ' D: ',d if(d<m): m=d t_f=t_names[tmp] tmp+=1 #print 'Precaucion en ',t_f #self.sendMsg('^2Precaucion en '+str(t_f)) if(self.config.get("crash_list","reg_crash")=="yes"): self.crash_msg_queue.appendleft(str(t_f)) self.last_time_crash=time.time() self.add_crash(Crash_event(self.get_driver(info.A.PLID).get_playername(), self.get_driver(info.B.PLID).get_playername(),info.A.PLID,info.B.PLID, float(info.SpClose), p[0],p[1], t_f,info.Time)) #schedule the message destroy WorkDaemon(self.pop_crash_queue,10,True).start()#destroy it in ten seconds
def split_time(self, insim, split): ''' Overwrite InsimCLient split_time that is binded to the SPLIT TIME packet ''' #always call original method first InsimClient.split_time(self, insim, split) print "Split time received. " self.sendMsg("Split time from "+self.get_driver(split.PLID).playername)
def obj_contact(self, insim, info): InsimClient.obj_contact(self, insim, info) b=False if("yes" in self.sa): b=True elif(self.current_driver_id==info.PLID): b=True if(b): self.print_log('^2OBH PACKET:^7 CSp='+ str(float(info.SpClose)/10)+' '+self.get_driver(info.PLID).get_playername(),True)
def __init__(self): InsimClient.__init__(self, "PIT Informant") self.version="0.1" self.flags=pyinsim.ISF_LOCAL self.pits={} self.lic=self.config.get('pit_warning','licencia') self.posx=self.config.getint('pit_warning','posx') self.posy=self.config.getint('pit_warning','posy') self.pit_gap = self.config.getint('pit_warning','pit_gap') self.curlap=0
def small(self,insim, packet): #TODO manage SubT to just care about IS_GTH subtype packets InsimClient.small(self, insim, packet) id=packet.ReqI t=packet.UVal print 'adding time to id ', id+1 ,' time ',t self.crash_list[id-1].c_time=t #save in file #TODO add if self.write_csv()
def split_time(self, insim, split): ''' Overwrite InsimCLient split_time that is binded to the SPLIT TIME packet ''' #always call original method first InsimClient.split_time(self, insim, split) print "Split time received. " self.sendMsg("Split time from " + self.get_driver(split.PLID).playername)
def race_state(self,insim, rsp): InsimClient.race_state(self, insim, rsp) try: p=self.config.get("cam_changer","props") p=[int(x) for x in p.split(",")] self.del_button(45, 0) if(self.current_driver_id>0): drv=self.get_driver(self.current_driver_id) self.send_button(45, p[1],p[0], p[2], p[3], "^7"+str(drv.position)+". "+(drv.playername.encode("latin-1")), 0, pyinsim.ISB_DARK|pyinsim.ISB_LEFT) except: print "Error sending button"
def __init__(self): ''' Constructor ''' InsimClient.__init__(self, tag="Example_Insim") self.version=0.1 self.flags=pyinsim.ISF_CON|pyinsim.ISF_OBH #connection flags #read a config.cfg parameter self.config_par=self.config.get("section","foo") print self.config_par
def __init__(self): InsimClient.__init__(self, "Cam_Changer") self.version=0.2 self.cur_carcam=0 #self.cams=[pyinsim.VIEW_CAM,pyinsim.VIEW_HELI,pyinsim.VIEW_DRIVER,pyinsim.VIEW_CUSTOM] self.cams=[str(x) for x in self.config.get("cam_changer","cams").split(",")] self.flags=pyinsim.ISF_LOCAL|pyinsim.ISF_MCI #TODO we need MCI for position. FIX self.ccam_t=None self.ccar_t=None self.msg="^7THis is example test." self.c_count=1
def __init__(self): ''' Constructor ''' InsimClient.__init__(self, tag="Example_Insim") self.version = 0.1 self.flags = pyinsim.ISF_CON | pyinsim.ISF_OBH #connection flags #read a config.cfg parameter self.config_par = self.config.get("section", "foo") print self.config_par
def __init__(self): ''' Constructor ''' InsimClient.__init__(self, "Event_Timer") self.version=0.1 self.flags="" self.timer_thread=None self.tm=0#time in seconds self.paused=True self.msg="" self.first=True
def obj_contact(self, insim, info): InsimClient.obj_contact(self, insim, info) b = False if ("yes" in self.sa): b = True elif (self.current_driver_id == info.PLID): b = True if (b): self.print_log( '^2OBH PACKET:^7 CSp=' + str(float(info.SpClose) / 10) + ' ' + self.get_driver(info.PLID).get_playername(), True)
def hlv(self,insim, p): InsimClient.hlv(self, insim, p) #print p reason={1:'Contact with Wall/Car/Obj',0:'Ground',4:'Speeding'} #self.sendMsg('^1HLV PACKET:^7 '+reason[p.HLVC]+' Sp: '+str(p.C.Speed)+ ' H: '+str(p.C.Heading)+ ' D: '+str(p.C.Direction) ,'') b=False if("yes" in self.sa): b=True elif(self.current_driver_id==p.PLID): b=True if(b): self.print_log('^1HLV:^7 '+reason[p.HLVC]+' '+self.get_driver(p.PLID).get_playername()+' Sp: '+str(float(p.C.Speed)),True)
def __init__(self): InsimClient.__init__(self, "Cam_Changer") self.version = 0.2 self.cur_carcam = 0 #self.cams=[pyinsim.VIEW_CAM,pyinsim.VIEW_HELI,pyinsim.VIEW_DRIVER,pyinsim.VIEW_CUSTOM] self.cams = [ str(x) for x in self.config.get("cam_changer", "cams").split(",") ] self.flags = pyinsim.ISF_LOCAL | pyinsim.ISF_MCI #TODO we need MCI for position. FIX self.ccam_t = None self.ccar_t = None self.msg = "^7THis is example test." self.c_count = 1
def race_state(self, insim, rsp): InsimClient.race_state(self, insim, rsp) try: p = self.config.get("cam_changer", "props") p = [int(x) for x in p.split(",")] self.del_button(45, 0) if (self.current_driver_id > 0): drv = self.get_driver(self.current_driver_id) self.send_button( 45, p[1], p[0], p[2], p[3], "^7" + str(drv.position) + ". " + (drv.playername.encode("latin-1")), 0, pyinsim.ISB_DARK | pyinsim.ISB_LEFT) except: print "Error sending button"
def car_contact (self, insim, info): InsimClient.car_contact(self, insim, info) b=False if("yes" in self.sa): b=True elif(self.current_driver_id==info.A.PLID or self.current_driver_id==info.B.PLID): b=True if(b): self.print_log('^3Car contact:^7 CSp='+ str(float(info.SpClose)/10)+' A= '+self.get_driver(info.A.PLID).get_playername()+' B '+self.get_driver(info.B.PLID).get_playername(),True) #self.sendMsg('^3CON PACKET:^7 CSp='+ str(info.SpClose/10),'')
def __init__(self): InsimClient.__init__(self, 'CUSTOM LAUNCHER') self.version="0.4.1" self.print_log("----"+self.tag+" v."+str(self.version) + " started."+"----") self.flags=pyinsim.ISF_MCI self.num_lights=self.config.getint("custom_launcher", "num_lights") self.state=self.num_lights+2 self.pen_given=[] self.tmp=0 self.interval=self.config.getint("connection", "interval") self.sem_styles=[(chr(149),chr(149)),(chr(166)*2,chr(166)*2),('*','*'),("["+chr(149)+"]","["+chr(149)+"]"),(chr(186)*2+' ',chr(186)*2+' '),('#','#')] self.bstyle=[0,pyinsim.ISB_LIGHT, pyinsim.ISB_DARK] self.launch_tstamp=0 self.launch_stime=0#launch server time self.abort_counter=0
def car_contact(self, insim, info): InsimClient.car_contact(self, insim, info) b = False if ("yes" in self.sa): b = True elif (self.current_driver_id == info.A.PLID or self.current_driver_id == info.B.PLID): b = True if (b): self.print_log( '^3Car contact:^7 CSp=' + str(float(info.SpClose) / 10) + ' A= ' + self.get_driver(info.A.PLID).get_playername() + ' B ' + self.get_driver(info.B.PLID).get_playername(), True)
def hlv(self, insim, p): InsimClient.hlv(self, insim, p) #print p reason = {1: 'Contact with Wall/Car/Obj', 0: 'Ground', 4: 'Speeding'} #self.sendMsg('^1HLV PACKET:^7 '+reason[p.HLVC]+' Sp: '+str(p.C.Speed)+ ' H: '+str(p.C.Heading)+ ' D: '+str(p.C.Direction) ,'') b = False if ("yes" in self.sa): b = True elif (self.current_driver_id == p.PLID): b = True if (b): self.print_log( '^1HLV:^7 ' + reason[p.HLVC] + ' ' + self.get_driver(p.PLID).get_playername() + ' Sp: ' + str(float(p.C.Speed)), True)
def recv_MCI(self,insim, rsp): InsimClient.recv_MCI(self, insim, rsp) #print "Receiving MCI ",round(time.time()-self.tmp,4)*1000 self.tmp=time.time() pen=self.config.get('custom_launcher','penalty') c_on_j=self.config.get('custom_launcher','cancel_on_jumpstart') if (self.state>=(self.num_lights+2)): return #green flag already abort_start=False try: t=time.time() #Check all drivers, 0.26 is 1 km/h aprox. for i in self.drivers: if( self.drivers[i].car_speed>=0.26): if( self.drivers[i].username not in self.pen_given): self.pen_given.append(self.drivers[i].username) #send penalty if((not pen=='none') or c_on_j=='no'): if((not pen=='none')): self.print_log("Penalizing driver "+self.drivers[i].playername+ " for jumpstart.") self.sendMsg(self.drivers[i].username, '/'+pen+' ') #calculate EST est=pyinsim.time(int(self.launch_stime+round(t-self.launch_tstamp,4)*1000)) est=str(est[0])+'h'+str(est[1]) +'m'+str(est[2])+'.'+str(est[3])+'s' self.print_log('Jumpstart of '+self.drivers[i].playername+' License: '+self.drivers[i].username.decode('latin-1') + ' Car speed:'+str(round(self.drivers[i].car_speed/0.26,3))+' (EST: '+est+')') self.sendMsg('^7'+self.config.get('custom_launcher','msg1')+' '+self.drivers[i].playername) if(c_on_j=='yes' and self.state<Custom_Launcher.CANCELLED_STATE): abort_start=True #print 'Jump of '+self.drivers[i].playername #print 'Speed ',self.drivers[i].car_speed #print '---' if(abort_start): self.cancel_start() except: print '[ERROR]: Error dealing with MCI packets.' print "Unexpected error:", sys.exc_info()[0]
def __init__(self): InsimClient.__init__(self, 'CUSTOM LAUNCHER') self.version = "0.4.1" self.print_log("----" + self.tag + " v." + str(self.version) + " started." + "----") self.flags = pyinsim.ISF_MCI self.num_lights = self.config.getint("custom_launcher", "num_lights") self.state = self.num_lights + 2 self.pen_given = [] self.tmp = 0 self.interval = self.config.getint("connection", "interval") self.sem_styles = [(chr(149), chr(149)), (chr(166) * 2, chr(166) * 2), ('*', '*'), ("[" + chr(149) + "]", "[" + chr(149) + "]"), (chr(186) * 2 + ' ', chr(186) * 2 + ' '), ('#', '#')] self.bstyle = [0, pyinsim.ISB_LIGHT, pyinsim.ISB_DARK] self.launch_tstamp = 0 self.launch_stime = 0 #launch server time self.abort_counter = 0
def hidden_message(self, insim, msg): InsimClient.hidden_message(self, insim, msg) m = msg.Msg if (m == 'launch'): if (self.state == Custom_Launcher.INIT_STATE or self.state >= (self.num_lights + 2)): self.launch_semaphore() elif (m == 'cancel'): if (self.state > Custom_Launcher.INIT_STATE and self.state <= Custom_Launcher.CANCELLED_STATE): self.cancel_start() elif (m == 'clear'): self.del_button(100) #TODO fix flag issue self.state = (self.num_lights + 2) elif (m == 'ping'): self.tmp = time.time() self.insim.send(pyinsim.ISP_TINY, ReqI=255, SubT=pyinsim.TINY_PING) elif (m == 'gth'): self.insim.send(pyinsim.ISP_TINY, ReqI=255, SubT=pyinsim.TINY_GTH)
def hidden_message(self, insim, msg): InsimClient.hidden_message(self, insim, msg) m=msg.Msg if(m=='launch'): if(self.state==Custom_Launcher.INIT_STATE or self.state>=(self.num_lights+2)): self.launch_semaphore() elif(m=='cancel'): if(self.state>Custom_Launcher.INIT_STATE and self.state<=Custom_Launcher.CANCELLED_STATE): self.cancel_start() elif(m=='clear'): self.del_button(100)#TODO fix flag issue self.state=(self.num_lights+2) elif (m=='ping'): self.tmp=time.time() self.insim.send(pyinsim.ISP_TINY, ReqI=255, SubT=pyinsim.TINY_PING) elif(m=='gth'): self.insim.send(pyinsim.ISP_TINY, ReqI=255, SubT=pyinsim.TINY_GTH)
def pitstop(self,insim, pt): InsimClient.pitstop(self, insim, pt) self.curlap=pt.LapsDone+1 work=pt.Work plid=pt.PLID cl=0 if(not self.drivers[self.driversID[plid]].username.lower()==self.lic.lower()): return #check if valid pitstop prev_pit=self.get_last_validpit() if(prev_pit>0 and (self.curlap-prev_pit)>=self.pit_gap): #is valid cl=1 elif(prev_pit==0): #is valid, no prev pit reg cl=1 else: #is not valid cl=0 #register and exit self.pits[self.curlap]=cl self.draw_pbut() return #check tyres #if Tyres==4 then driver changed tyres if(pt.Tyres[0]==4): cl=2 self.pits[self.curlap]=cl self.draw_pbut()
def chat_message(self,insim,mso): InsimClient.chat_message(self, insim, mso) msg=mso.Msg print 'message is ' + msg
def recv_tiny(self, insim, p): InsimClient.recv_tiny(self, insim, p) if (p.SubT == 4): print 'pong ', round(time.time() - self.tmp, 4) * 1000, 'ms'
def rip(self, insim, packet): InsimClient.rip(self, insim, packet) #When we get this it means that we got to our desired crash time #So the next thing is to locate the camera on the correct car, that is, driver_focus cam=pyinsim.IS_SCC(ReqI=40, ViewPLID=self.driver_focus) self.insim.sendp(cam)
def lap_time(self, insim, lap): InsimClient.lap_time(self, insim, lap)
def race_start(self,insim,rsp): InsimClient.race_start(self, insim, rsp) self.reset()
def recv_tiny(self,insim, p): InsimClient.recv_tiny(self, insim, p) if(p.SubT==4): print 'pong ',round(time.time()-self.tmp,4)*1000,'ms'
def race_start(self, insim, rsp): InsimClient.race_start(self, insim, rsp) self.c_count = 1
def race_start(self,insim,rsp): InsimClient.race_start(self, insim, rsp) self.c_count=1
def new_player(self,insim, npl): InsimClient.new_player(self, insim, npl) print 'Player ', npl.PName, ' FLAGS ', self.dec2listbin(npl.Flags), ' LEN : ',len(self.dec2listbin(npl.Flags))
def lap_time(self,insim,lap): InsimClient.lap_time(self, insim, lap)
def hidden_message(self, insim, msg): ''' admin messages sent with /i ''' InsimClient.hidden_message(self, insim, msg) self.sendChat("Hidden message: " + msg.Msg)
def new_player(self, insim, npl): InsimClient.new_player(self, insim, npl) print 'Player ', npl.PName, ' FLAGS ', self.dec2listbin( npl.Flags), ' LEN : ', len(self.dec2listbin(npl.Flags))