def procAT(self,flds): # Tests if we have this message stored. If not, add and flood # flds[3] is client's name if not self.factory.clients.has_key(flds[3]) or flds != hhelp.parse_m(self.at(flds[3])): # add to the cache self.factory.clients[flds[3]] = { 'delay':flds[2], 'lat': flds[4], 'long': flds[5], 'time': flds[6], 'server':flds[1] } print(len(flds)) #print(self.factory.clients.has_key(flds[3])) print(flds) print(hhelp.parse_m(self.at(flds[3]))) self.flood(self.at(flds[3]))
def procWHATSAT(self,flds): # flds[1] is client's name latest_at = self.at(flds[1]) at_flds = hhelp.parse_m(latest_at) # Writes the most recent info about that client res_limit=flds[3] lat = at_flds[4] lng=at_flds[5] radius=flds[2] # print("lat:"+str(lat)+' long:'+str(lng)) # print('radius:'+str(radius)) json_res=hhelp.GoogPlac(lat,lng,radius,res_limit) self.transport.write(latest_at+'\n') self.transport.write(json_res+'\n\n')
def lineReceived(self, line): self.factory.log('Line received: '+line) #Parses and stores the message flds = hhelp.parse_m(line) if flds == None or (not hhelp.valid_iamat(flds) and not hhelp.valid_whatsat(flds) and flds[0]!='AT'): #Invalid message send '? message' back to the user self.transport.write('? '+line+'\n') self.factory.log('Invalid command '+line) elif flds[0]=='AT': print(flds) #TODO: fix number rounding to make flooding work self.procAT(flds) elif flds[0]=='WHATSAT': if not self.factory.clients.has_key(flds[1]): self.transport.write('? '+line+'\n') self.factory.log('Invalid WHATSAT command-No previous data for client: '+line) else: self.procWHATSAT(flds) self.factory.log('Successful WHATSAT answer') elif flds[0]=='IAMAT': self.procIAMAT(flds)