Пример #1
0
 def bestAgentFor(self, channel, server):
     allowed = self.getRootAgents()        
     
     candidate = list()
     
     for agent in self.getRunnningAgents():
         print agent.server+"/"+server
         if agent.server == server:    
             if agent.nbchan < 8:
                 candidate.append(agent)
             for root_agent in allowed:
                 #print "computer name: "+getComputername(root_agent)+"/"+getComputername(agent.name)+"y"+agent.name
                 if getComputername(root_agent)==getComputername(agent.name):
                     allowed.remove(root_agent) 
     
     #if no candidate
     log.msg("ALLOWED "+str(allowed))
     self.requestNewAgent(allowed, server)
     if len(candidate)==0:
         return None
     
     from random import Random
     rnd = Random()
      
     return candidate[rnd.randint(0, len(candidate)-1)]
Пример #2
0
 def hasSpawnRequest(self, agentname):
     if not self.spawnRequest.has_key(getComputername(agentname)):
         return False
     else:
         if len(self.spawnRequest[getComputername(agentname)]) == 0:
             return False
     return True
Пример #3
0
 def onClientInit(self, eventObj, evtMgr):
     source = eventObj.source
     
     print "SPAWNNN: "+str(self.spawnRequest)
     
     if self.hasSpawnRequest(source):
         server = self.getSpawnRequest(source)
         if server=="irc.worldnet.net" and getComputername(source)=='oil-ocean':
             self.sendTo(source, ConnectEventAction(nickname="scrutator", server="irc.worldnet.net", port=6667))
         else:
             self.sendTo(source, ConnectEventAction(nickname=getNickName(), server=server, port=6667))
         
         agent = Agent()
         agent.name = source
         agent.server = server
         
         self.onRegisterAgent(agent)
         
     else:
         print "DIE !!!"
         self.sendTo(source, DieEvent())
Пример #4
0
 def getSpawnRequest(self,agentname):
     return self.spawnRequest[getComputername(agentname)].pop()
Пример #5
0
 def addSpawnRequest(self, agentname, server):
     if not self.spawnRequest.has_key(getComputername(agentname)):
         self.spawnRequest[getComputername(agentname)] = list()
     if not server in self.spawnRequest[getComputername(agentname)]:
         self.spawnRequest[getComputername(agentname)].append(server)
         self.sendTo(agentname,SpawnEvent(brain='remote.protocols.irc.brain.IrcBrainClient'))