Ejemplo n.º 1
0
 def others(self,insim, packet):
     t=time.time()
     print "GTH (Server time) ",packet.UVal*10, pyinsim.time(packet.UVal*10)
     cor=round(t-self.launch_tstamp,4)
     print " Sync by ",  cor*1000, 'ms'
     stime= packet.UVal*10
     if(stime==0):
         self.launch_stime=0
         return
     stime-=cor*1000
     stime=int(stime)
     print "GTH (Final) ",stime,' ',pyinsim.time(stime)
     self.launch_stime=stime
Ejemplo n.º 2
0
 def others(self, insim, packet):
     t = time.time()
     print "GTH (Server time) ", packet.UVal * 10, pyinsim.time(
         packet.UVal * 10)
     cor = round(t - self.launch_tstamp, 4)
     print " Sync by ", cor * 1000, 'ms'
     stime = packet.UVal * 10
     if (stime == 0):
         self.launch_stime = 0
         return
     stime -= cor * 1000
     stime = int(stime)
     print "GTH (Final) ", stime, ' ', pyinsim.time(stime)
     self.launch_stime = stime
Ejemplo n.º 3
0
 def draw_evt(self):
     if(self.tm==-1):
         self.timer_thread.stop()
         return
     
     #2 buttons
     top=self.config.getint("evt","posy")
     left=self.config.getint("evt","posx")
     w=13
     h=9
     #format time
     u=(pyinsim.time(self.tm*1000))
     t_msg="%.2d"%(u[0]*60)+":"+"%.2d"%(u[2]) 
     cl="^3"
     if(self.tm<=59):
         cl='^1'
     t_msg=cl+t_msg
     self.send_button(125, top, left, w, h, t_msg, bs=pyinsim.ISB_DARK)
     
     if(self.first):
         w_m=60
         self.send_button(126, top, left+w, w_m, h, '^7'+self.msg, bs=pyinsim.ISB_LIGHT|pyinsim.ISB_LEFT)
     
     self.first=False
     self.tm-=1
Ejemplo n.º 4
0
 def semaphore(self):
     color=''
     msg=''
     if (self.state==Custom_Launcher.CANCELLED_STATE):
         return
     print 'state '+str(self.state)
     for i in range(0,self.num_lights):
         if(i<self.state):
             l_style=self.sem_styles[self.config.getint('custom_launcher','l_style')-1][1]
             color='^'+self.config.get('custom_launcher','on_color')
         else:
             l_style=self.sem_styles[self.config.getint('custom_launcher','l_style')-1][0]
             color='^'+self.config.get('custom_launcher','off_color')
         if(self.state==(self.num_lights+1)):
             l_style=self.sem_styles[self.config.getint('custom_launcher','l_style')-1][1]
             #num_lights +1 in this state the lights, being on,  change it color and the race start indmediatly 
             color='^'+self.config.get('custom_launcher','start_color')
         #msg+=color+chr(149)+' '
         msg+=color+l_style+' '
     msg=msg[:-1]
     self.insim.send(pyinsim.ISP_BTN,ReqI=1, ClickID=100,UCID=255,
                             BStyle= self.bstyle[self.config.getint('custom_launcher','bstyle')] ,
                             T=self.config.getint('custom_launcher','posy'), L=self.config.getint('custom_launcher','posx'), 
                             W=self.config.getint('custom_launcher','width'), H=self.config.getint('custom_launcher','height'), 
                             Text=msg)#Button
     self.state+=1
     if(self.state==1):
         #All lights are off. First wait
         self.print_log("Indicator deployed. All lights off.")
         t=self.gettime('wait_time')
         WorkDaemon(self.semaphore, random.uniform(t[0],t[1]), True).start()
         
     elif(self.state<(self.num_lights+1)):
         #lights are being turned on
         self.print_log("Light "+str(self.state-1)+" turned on.")
         t=self.gettime('light_time')
         WorkDaemon(self.semaphore, random.uniform(t[0],t[1]), True).start()
    
     elif(self.state==(self.num_lights+1)):
         #all lights on. This is the last wait
         self.print_log("Light "+str(self.state-1)+" turned on. All lights on. Final delay started.") 
         t=self.gettime('start_time')
         WorkDaemon(self.semaphore, random.uniform(t[0],t[1]), True).start()
    
     elif(self.state==(self.num_lights+2)):
         #Already green flag, set new thread to delete the flag later
         print 'CAN START'
         t=time.time()
         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'       
         m=self.config.get('custom_launcher','start_msg')
         
         if(not m==''):
             self.sendMsg(m, ap='')
                  
         self.print_log("RACE STARTED."+' (EST: '+est+')')
         t=self.gettime('show_time')
         WorkDaemon(self.clear_semaphore, t[0], True).start()
Ejemplo n.º 5
0
    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]
Ejemplo n.º 6
0
 def print_crash_list(self):
     top=20
     left= 50
     
     #Draw close, refresh
     self.insim.send(pyinsim.ISP_BTN,ReqI=255, ClickID=50,
                                     BStyle= pyinsim.ISB_DARK |pyinsim.ISB_CLICK,
                                     T=top-10, L=left-10, 
                                     W=20, H=7, 
                                     Text="^1 X ^7 Total: "+str(len(self.crash_list)))
     
     self.insim.send(pyinsim.ISP_BTN,ReqI=255, ClickID=51,
                                     BStyle= pyinsim.ISB_DARK |pyinsim.ISB_CLICK,
                                     T=top-10, L=left-10+20, 
                                     W=10, H=7, 
                                     Text="^3<<Prev")
     self.insim.send(pyinsim.ISP_BTN,ReqI=255, ClickID=52,
                                     BStyle= pyinsim.ISB_DARK |pyinsim.ISB_CLICK,
                                     T=top-10, L=left-10+20+10, 
                                     W=10, H=7, 
                                     Text="^3Next>>")
     self.tmp=0
     #draw list
     toshow_list=copy.copy(self.crash_list)
     if(len(toshow_list)>self.curpage*25):
         #toshow_list.reverse()
         toshow_list=toshow_list[self.curpage*25:self.curpage*25+25]
         #toshow_list.reverse()
     
         
     for i in toshow_list:
         #Row, ID, car A, car B, t_sector, time
         tm=pyinsim.time(i.c_time*10)
         tm=str(tm[0])+"h"+str(tm[1])+"m"+str(tm[2])+"s"
         
         #msg="^7"+str(self.tmp+1)+'. ^2CarA: '+i.car_A.encode('utf-8')+'     ^2CarB: '+i.car_B.encode('utf-8')+'     ^3 Sector:^7'+i.t_sector+' ^3 Time: ^7'+str(tm)
         msg="^7"+str(self.tmp+1+self.curpage*25)+'. ^2CarA: '+i.car_A+'      ^2CarB: '+i.car_B+'       Sp:'+str(float(i.closing)/10)+'        ^3 Time: ^7'+str(tm)
         
         try:
             self.insim.send(pyinsim.ISP_BTN,ReqI=self.crash_list.index(i)+1, ClickID=70+self.tmp,
                                     BStyle= pyinsim.ISB_DARK|pyinsim.ISB_CLICK |pyinsim.ISB_LEFT,
                                     T=top+7*self.tmp, L=left, 
                                     W=100, H=7, 
                                     Text=msg)
         except:
             print "Error delivering list"
        
         
         
         
         self.tmp+=1
Ejemplo n.º 7
0
 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]
Ejemplo n.º 8
0
    def semaphore(self):
        color = ''
        msg = ''
        if (self.state == Custom_Launcher.CANCELLED_STATE):
            return
        print 'state ' + str(self.state)
        for i in range(0, self.num_lights):
            if (i < self.state):
                l_style = self.sem_styles[
                    self.config.getint('custom_launcher', 'l_style') - 1][1]
                color = '^' + self.config.get('custom_launcher', 'on_color')
            else:
                l_style = self.sem_styles[
                    self.config.getint('custom_launcher', 'l_style') - 1][0]
                color = '^' + self.config.get('custom_launcher', 'off_color')
            if (self.state == (self.num_lights + 1)):
                l_style = self.sem_styles[
                    self.config.getint('custom_launcher', 'l_style') - 1][1]
                #num_lights +1 in this state the lights, being on,  change it color and the race start indmediatly
                color = '^' + self.config.get('custom_launcher', 'start_color')
            #msg+=color+chr(149)+' '
            msg += color + l_style + ' '
        msg = msg[:-1]
        self.insim.send(pyinsim.ISP_BTN,
                        ReqI=1,
                        ClickID=100,
                        UCID=255,
                        BStyle=self.bstyle[self.config.getint(
                            'custom_launcher', 'bstyle')],
                        T=self.config.getint('custom_launcher', 'posy'),
                        L=self.config.getint('custom_launcher', 'posx'),
                        W=self.config.getint('custom_launcher', 'width'),
                        H=self.config.getint('custom_launcher', 'height'),
                        Text=msg)  #Button
        self.state += 1
        if (self.state == 1):
            #All lights are off. First wait
            self.print_log("Indicator deployed. All lights off.")
            t = self.gettime('wait_time')
            WorkDaemon(self.semaphore, random.uniform(t[0], t[1]),
                       True).start()

        elif (self.state < (self.num_lights + 1)):
            #lights are being turned on
            self.print_log("Light " + str(self.state - 1) + " turned on.")
            t = self.gettime('light_time')
            WorkDaemon(self.semaphore, random.uniform(t[0], t[1]),
                       True).start()

        elif (self.state == (self.num_lights + 1)):
            #all lights on. This is the last wait
            self.print_log("Light " + str(self.state - 1) +
                           " turned on. All lights on. Final delay started.")
            t = self.gettime('start_time')
            WorkDaemon(self.semaphore, random.uniform(t[0], t[1]),
                       True).start()

        elif (self.state == (self.num_lights + 2)):
            #Already green flag, set new thread to delete the flag later
            print 'CAN START'
            t = time.time()
            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'
            m = self.config.get('custom_launcher', 'start_msg')

            if (not m == ''):
                self.sendMsg(m, ap='')

            self.print_log("RACE STARTED." + ' (EST: ' + est + ')')
            t = self.gettime('show_time')
            WorkDaemon(self.clear_semaphore, t[0], True).start()