def test_event_handler_timeout(self): mock = MockEvent(1) eventshandler = AppEventsHandler() handler = eventshandler.register('MockEvent', 2) handler.subscribe(self.onEvent, None) Wait(3)
def chat(self, Message=None): """ sends an instant message to another avatar wraps send_ImprovedInstantMessage with some handy defaults """ if self.session_id == None: self.request_join_group_chat() Wait(5) if self.session_id == None: logger.warning( "Failed to start chat session with group %s. Please try again later." % (self.GroupName)) return if Message != None: _ID = self.GroupID _AgentID = self.agent.agent_id _SessionID = self.agent.session_id _FromGroup = False _ToAgentID = self.GroupID _ParentEstateID = 0 _RegionID = UUID() _Position = Vector3() # don't send position, send uuid zero _Offline = 0 _Dialog = ImprovedIMDialogue.SessionSend _ID = self.GroupID _Timestamp = 0 _FromAgentName = self.agent.Name( ) + "\x00" #struct.pack(">" + str(len(self.agent.Name)) + "c", *(self.agent.Name())) _Message = Message + "\x00" #struct.pack(">" + str(len(Message)) + "c", *(Message)) _BinaryBucket = "\x00" # self.GroupName #struct.pack(">" + str(len(self.GroupName)) + "c", *(self.GroupName)) self.agent.send_ImprovedInstantMessage( _AgentID, _SessionID, _FromGroup, _ToAgentID, _ParentEstateID, _RegionID, _Position, _Offline, _Dialog, _ID, _Timestamp, _FromAgentName, _Message, _BinaryBucket)
agents.append(Agent(settings, params[0], params[1], params[2])) agentmanager = AgentManager() agentmanager.initialize(agents) #print 'Storing agents:' #for agent in agentmanager.agents: #print '\t' + agentmanager.agents[agent].Name() # log them in for key in agentmanager.agents: agentmanager.login(key, options.loginuri, options.region) ############ WORKING HERE # allow 10 seconds for agents to connect Wait(10) giver = None receiver = None keys = agentmanager.agents.keys() giver = agentmanager.agents[keys[0]] receiver = agentmanager.agents[keys[1]] print '' print '' print '' print '' print 'Agent giving inventory is: %s' % (giver) print 'Agent receiving inventory is: %s' % (receiver)
def login(): """ login an to a login endpoint """ parser = OptionParser(usage="usage: %prog [options] firstname lastname") logger = logging.getLogger("client.example") parser.add_option( "-l", "--loginuri", dest="loginuri", default="https://login.aditi.lindenlab.com/cgi-bin/login.cgi", help="specified the target loginuri") parser.add_option( "-r", "--region", dest="region", default=None, help="specifies the region (regionname/x/y/z) to connect to") parser.add_option("-q", "--quiet", dest="verbose", default=True, action="store_false", help="enable verbose mode") parser.add_option( "-p", "--password", dest="password", default=None, help="specifies password instead of being prompted for one") (options, args) = parser.parse_args() if len(args) != 2: parser.error("Expected arguments: firstname lastname") if options.verbose: console = logging.StreamHandler() console.setLevel( logging.DEBUG) # seems to be a no op, set it for the logger formatter = logging.Formatter( '%(asctime)-30s%(name)-30s: %(levelname)-8s %(message)s') console.setFormatter(formatter) logging.getLogger('').addHandler(console) # setting the level for the handler above seems to be a no-op # it needs to be set for the logger, here the root logger # otherwise it is NOTSET(=0) which means to log nothing. logging.getLogger('').setLevel(logging.DEBUG) else: print "Attention: This script will print nothing if you use -q. So it might be boring to use it like that ;-)" # example from a pure agent perspective #grab a password! if options.password: password = options.password else: password = getpass.getpass() # let's disable inventory handling for this example settings = Settings() settings.ENABLE_INVENTORY_MANAGEMENT = False settings.ENABLE_EQ_LOGGING = False settings.ENABLE_CAPS_LOGGING = False #First, initialize the agent client = Agent(settings=settings) # Now let's log it in api.spawn(client.login, options.loginuri, args[0], args[1], password, start_location=options.region, connect_region=True) # wait for the agent to connect to it's region while client.connected == False: api.sleep(0) while client.region.connected == False: api.sleep(0) # do sample script specific stuff here # in this case we create a box waiter = Wait(5) for i in range(len(object_names)): client.region.objects.create_default_box(GroupID=client.ActiveGroupID, relative_position=((i + 1), 0, 0)) waiter = Wait(5) # let's see what's nearby objects_nearby = client.region.objects.find_objects_within_radius(20) for item in objects_nearby: item.select(client) waiter = Wait(15) for item in objects_nearby: item.deselect(client) my_objects = client.region.objects.my_objects() print 'Hey! Will try to set object names' print 'Hey! Will try to set permissions.' i = 0 for item in my_objects: fixed_name = object_names[i] print ' for LocalID %s : %s ' % (item.LocalID, fixed_name) item.set_object_name(client, fixed_name) if fixed_name == 'Alpha': item.set_object_transfer_only_permissions(client) elif fixed_name == 'Bravo': item.set_object_copy_transfer_permissions(client) elif fixed_name == 'Charlie': item.set_object_mod_transfer_permissions(client) elif fixed_name == 'Delta': item.set_object_full_permissions(client) elif fixed_name == 'Echo': item.set_object_copy_only_permissions(client) elif fixed_name == 'Foxtrot': item.set_object_copy_mod_permissions(client) else: print "Name Does Not Match!" i = i + 1 waiter = Wait(2) item.take(client) waiter = Wait(30) while client.running: api.sleep(0) print '' print '' print 'At this point, we have an Agent object, Inventory dirs, and with a Region attribute' print 'Agent attributes:' for attr in client.__dict__: print attr, ':\t\t\t', client.__dict__[attr] print '' print '' print 'Objects being tracked: %s' % len(client.region.objects.object_store) print '' print '' states = {} for _object in client.region.objects.object_store: if _object.State == 0: #items = _object.__dict__.items() #items.sort() print 'Object attributes' for attr in _object.__dict__: print '\t\t%s:\t\t%s' % (attr, _object.__dict__[attr]) print '' else: if states.has_key(_object.State): states[_object.State] += 1 else: states[_object.State] = 1 print '' print 'Object states I don\'t care about atm' for state in states: print '\t State: ', state, '\tFrequency: ', states[state] print '' print '' for _avatar in client.region.objects.avatar_store: print 'LocalID:', _avatar.LocalID, '\tUUID: ', _avatar.FullID, '\tNameValue: ', _avatar.NameValue, '\tPosition: ', _avatar.Position print '' print '' print 'Region attributes:' for attr in client.region.__dict__: print attr, ':\t\t\t', client.region.__dict__[attr]
def login(): """ login an to a login endpoint """ parser = OptionParser(usage="usage: %prog [options] firstname lastname") logger = logging.getLogger("client.example") parser.add_option( "-l", "--loginuri", dest="loginuri", default="https://login.aditi.lindenlab.com/cgi-bin/login.cgi", help="specified the target loginuri") parser.add_option( "-r", "--region", dest="region", default=None, help="specifies the region (regionname/x/y/z) to connect to") parser.add_option("-q", "--quiet", dest="verbose", default=True, action="store_false", help="enable verbose mode") parser.add_option( "-p", "--password", dest="password", default=None, help="specifies password instead of being prompted for one") (options, args) = parser.parse_args() if len(args) != 2: parser.error("Expected arguments: firstname lastname") if options.verbose: console = logging.StreamHandler() console.setLevel( logging.DEBUG) # seems to be a no op, set it for the logger formatter = logging.Formatter( '%(asctime)-30s%(name)-30s: %(levelname)-8s %(message)s') console.setFormatter(formatter) logging.getLogger('').addHandler(console) # setting the level for the handler above seems to be a no-op # it needs to be set for the logger, here the root logger # otherwise it is NOTSET(=0) which means to log nothing. logging.getLogger('').setLevel(logging.DEBUG) else: print "Attention: This script will print nothing if you use -q. So it might be boring to use it like that ;-)" # example from a pure agent perspective print 'we are going to try and group chat with the agent\'s active group. set one active, or get the uuid and create a new script that does it for you!' print '' print 'This only works on unix like machines ATM.' #grab a password! if options.password: password = options.password else: password = getpass.getpass() # let's disable inventory handling for this example settings = Settings() settings.ENABLE_INVENTORY_MANAGEMENT = False settings.ENABLE_OBJECT_TRACKING = False settings.ENABLE_COMMUNICATIONS_TRACKING = True settings.ENABLE_UDP_LOGGING = False settings.ENABLE_EQ_LOGGING = False settings.ENABLE_CAPS_LOGGING = False #First, initialize the agent client = Agent(settings=settings) # Now let's log it in api.spawn(client.login, options.loginuri, args[0], args[1], password, start_location=options.region, connect_region=True) # wait for the agent to connect to it's region while client.connected == False: api.sleep(0) while client.region.connected == False: api.sleep(0) # wait 10 seconds, hoping group data populates by then Wait(10) # do sample script specific stuff here chat_group = client.group_manager.get_group(client.ActiveGroupID) # until the implementation is done, add the agent to the group object chat_group.agent = client print '' print 'I know, this interface is not an interface, you\'ll see, just type when prompted. Saijanai, sounds like you are up for a wx application. Hit Escape to trigger the message prompt.' if chat_group != None: chaty_kathy = MockChatInterface( client, chat_group.chat) # this object is l-a-m-e chaty_kathy.start() else: print "We failed to find the group to start chat session :(. Continuing" while client.running: api.sleep(0) print '' print '' print 'At this point, we have an Agent object, Inventory dirs, and with a Region attribute' print 'Agent attributes:' for attr in client.__dict__: print attr, ':\t\t\t', client.__dict__[attr] print '' print '' print 'Known Groups:' for group in client.group_manager.group_store: print ':\t\t\t', group.GroupName for attr in group.__dict__: print '\t\t\t\t', attr, ':\t', group.__dict__[attr]
def login(): """ login an to a login endpoint """ parser = OptionParser(usage="usage: %prog [options] firstname lastname") logger = logging.getLogger("client.example") parser.add_option( "-l", "--loginuri", dest="loginuri", default="https://login.aditi.lindenlab.com/cgi-bin/login.cgi", help="specified the target loginuri") parser.add_option( "-r", "--region", dest="region", default=None, help="specifies the region (regionname/x/y/z) to connect to") parser.add_option("-q", "--quiet", dest="verbose", default=True, action="store_false", help="enable verbose mode") parser.add_option( "-p", "--password", dest="password", default=None, help="specifies password instead of being prompted for one") parser.add_option("-s", "--search", dest="search", default=None, help="inventory item to search for an rez (optional)") (options, args) = parser.parse_args() if len(args) != 2: parser.error("Expected arguments: firstname lastname") if options.verbose: console = logging.StreamHandler() console.setLevel( logging.DEBUG) # seems to be a no op, set it for the logger formatter = logging.Formatter( '%(asctime)-30s%(name)-30s: %(levelname)-8s %(message)s') console.setFormatter(formatter) logging.getLogger('').addHandler(console) # setting the level for the handler above seems to be a no-op # it needs to be set for the logger, here the root logger # otherwise it is NOTSET(=0) which means to log nothing. logging.getLogger('').setLevel(logging.DEBUG) else: print "Attention: This script will print nothing if you use -q. So it might be boring to use it like that ;-)" # example from a pure agent perspective #grab a password! if options.password: password = options.password else: password = getpass.getpass() # let's disable object tracking for this example settings = Settings() settings.ENABLE_OBJECT_TRACKING = False #First, initialize the agent client = Agent(settings=settings) # Now let's log it in api.spawn(client.login, options.loginuri, args[0], args[1], password, start_location=options.region, connect_region=True) # wait for the agent to connect to it's region while client.connected == False: api.sleep(0) while client.region.connected == False: api.sleep(0) print '' print '' print '++++++++++++++++' print '' print '' # for folders whose parent = root folder aka My Inventory, request their contents [ client.inventory._request_folder_contents(folder.FolderID) for folder in client.inventory.folders if str(folder.ParentID) == str( client.inventory.inventory_root.FolderID) ] # for folders whose parent = library root folder aka Library, request their contents [ client.inventory._request_folder_contents(folder.FolderID, 'library') for folder in client.inventory.library_folders if str(folder.ParentID) == str(client.inventory.library_root.FolderID) ] Wait(10) [ client.inventory.sendFetchInventoryRequest(item.ItemID) for item in client.inventory.search_inventory(name=options.search) ] while client.running: api.sleep(0) print '' print '' print 'At this point, we have an Agent object, Inventory dirs, and with a Region attribute' print 'Agent attributes:' for attr in client.__dict__: print attr, ':\t\t\t', client.__dict__[attr] print '' print '' print 'Inventory: %s folders' % len(client.inventory.folders) for inv_folder in client.inventory.folders: print 'Inventory Folder', ':\t\t\t', inv_folder.Name for item in inv_folder.inventory: print ' ', item.Name print '' print '' print 'Library: %s folders' % len(client.inventory.library_folders) for inv_folder in client.inventory.library_folders: print 'Inventory Folder', ':\t\t\t', inv_folder.Name for item in inv_folder.inventory: print ' ', item.Name
def login(): """ login an to a login endpoint """ parser = OptionParser(usage="usage: %prog [options] firstname lastname") logger = logging.getLogger("client.example") parser.add_option( "-l", "--loginuri", dest="loginuri", default="https://login.aditi.lindenlab.com/cgi-bin/login.cgi", help="specified the target loginuri") parser.add_option( "-r", "--region", dest="region", default=None, help="specifies the region (regionname/x/y/z) to connect to") parser.add_option("-q", "--quiet", dest="verbose", default=True, action="store_false", help="enable verbose mode") parser.add_option("-t", "--to_agent_id", dest="to_agent_id", default=None, help="agent id to offer inventory to (required)") parser.add_option( "-s", "--search", dest="search", default=None, help= "name of inventory item to search for and transfer to account number 2" ) parser.add_option( "-p", "--password", dest="password", default=None, help="specifies password instead of being prompted for one") (options, args) = parser.parse_args() if len(args) != 2: parser.error("Expected arguments: firstname lastname") if options.to_agent_id == None: parser.error("Missing required target agent id") if options.verbose: console = logging.StreamHandler() console.setLevel( logging.DEBUG) # seems to be a no op, set it for the logger formatter = logging.Formatter( '%(asctime)-30s%(name)-30s: %(levelname)-8s %(message)s') console.setFormatter(formatter) logging.getLogger('').addHandler(console) # setting the level for the handler above seems to be a no-op # it needs to be set for the logger, here the root logger # otherwise it is NOTSET(=0) which means to log nothing. logging.getLogger('').setLevel(logging.DEBUG) else: print "Attention: This script will print nothing if you use -q. So it might be boring to use it like that ;-)" # prep instance settings settings = Settings() settings.ENABLE_INVENTORY_MANAGEMENT = True settings.ENABLE_COMMUNICATIONS_TRACKING = False settings.ENABLE_OBJECT_TRACKING = False settings.ENABLE_UDP_LOGGING = True settings.ENABLE_EQ_LOGGING = True settings.ENABLE_CAPS_LOGGING = True settings.MULTIPLE_SIM_CONNECTIONS = False #grab a password! if options.password: password = options.password else: password = getpass.getpass() #First, initialize the agent client = Agent(settings=settings) api.spawn(client.login, options.loginuri, args[0], args[1], password, start_location=options.region, connect_region=True) # wait for the agent to connect to it's region while client.connected == False: api.sleep(0) while client.region.connected == False: api.sleep(0) ############ WORKING HERE # for folders whose parent = root folder aka My Inventory, request their contents [ client.inventory._request_folder_contents(folder.FolderID) for folder in client.inventory.folders if folder.ParentID == client.inventory.inventory_root.FolderID ] #while client.running: #api.sleep(0) # next, let's wait 5 seconds and FetchInventory for items we know about Wait(10) if options.search != None: # and next, let's search the inventory by name matches = client.inventory.search_inventory(name=options.search) # now, if we have a match, let's try and rez the first matching object item_to_give = matches[0] print '' print '' print '' print '' print "Found item to give to another agent: %s" % (str( item_to_give.__dict__)) print '' print '' print '' print '' client.inventory.give_inventory(item_to_give.ItemID, options.to_agent_id) while client.running: api.sleep(0)