def test_enqueue_message(self): message = Message('TestMessage1', Block('TestBlock1', Test1 = 0), Block('NeighborBlock', Test0 = 0, Test1 = 1, Test2 = 2)) self.message_manager.enqueue_message(message, reliable = True) self.assertEqual(self.message_manager.outgoing_queue[0][0].name, 'TestMessage1') self.assertTrue(self.message_manager.outgoing_queue[0][1]) message2 = Message('TestMessage2', Block('TestBlock1', Test1 = 0), Block('NeighborBlock', Test0 = 0, Test1 = 1, Test2 = 2)) self.message_manager.enqueue_message(message2, reliable = False, now = True) self.assertEqual(self.message_manager.outgoing_queue[0][0].name, 'TestMessage2') self.assertFalse(self.message_manager.outgoing_queue[0][1])
def test_build(self): msg = Message('TestPacket', Block('CircuitCode', ID=1234, Code=531)) assert msg.blocks['CircuitCode'][0].vars['ID'].data == 1234, \ "Incorrect data in block ID" assert msg.blocks['CircuitCode'][0].vars['Code'].data == 531, \ "Incorrect data in block Code"
def sendRequestTaskInventory(agent, obj_uuid): obj = agent.region.objects.get_object_from_store(FullID=str(obj_uuid)) packet = Message( 'RequestTaskInventory', Block('AgentData', AgentID=agent.agent_id, SessionID=agent.session_id), Block('InventoryData', LocalID=obj.LocalID)) agent.region.enqueue_message(packet)
def send_AgentSetAppearance(self, AgentID, SessionID, Size, bakedTextures, TextureEntry, visualParams): """ Informs simulator how avatar looks """ args = [ Block('AgentData', AgentID=AgentID, SessionID=SessionID, SerialNum=self.AgentSetSerialNum, Size=Size) ] args += [Block('WearableData', CacheID = bakedTextures[i].TextureID, TextureIndex = bakedTextures[i].bakedIndex) \ for i in range(BakedIndex.BAKED_COUNT)] args += [Block('ObjectData', TextureEntry=TextureEntry)] paramkeys = visualParams.keys() paramkeys.sort() args += [Block('VisualParam', ParamValue = visualParams[key].floatToByte()) \ for key in paramkeys if visualParams[key].group is 0] packet = Message('AgentSetAppearance', *args) self.AgentSetSerialNum += 1 self.agent.region.enqueue_message(packet)
def sendObjectLink(self, link, parentId, *childrenIds): print("linking", parentId, childrenIds) if link: msgname = 'ObjectLink' else: msgname = 'ObjectDelink' get_from_store = self.client.region.objects.get_object_from_store parent = get_from_store(FullID=parentId) if not parent: print("Parenting on an object that doesnt exist", parentId) return children_lids = map(lambda s: get_from_store(FullID=s).LocalID, childrenIds) parent_lid = parent.LocalID packet = Message(msgname, Block('AgentData', AgentID = self.client.agent_id, SessionID = self.client.session_id), Block('ObjectData', ObjectLocalID = parent_lid), *[Block('ObjectData', ObjectLocalID = childId) for childId in children_lids]) self.client.region.enqueue_message(packet)
def send_UUIDNameRequest(self, agent_ids, callback): """ sends a UUIDNameRequest message to the host simulator """ handler = self.region.message_handler.register('UUIDNameReply') def onUUIDNameReply(packet): """ handles the UUIDNameReply message from a simulator """ logger.info('UUIDNameReplyPacket received') cbdata = [] for block in packet['UUIDNameBlock']: agent_id = str(block['ID']) first_name = block['FirstName'] last_name = block['LastName'] self.agent_id_map[agent_id] = (first_name, last_name) cbdata.append((agent_id, first_name, last_name)) # Fire the callback only when all names are received missing = [ agent_id for agent_id in agent_ids if agent_id not in self.agent_id_map ] if not missing: handler.unsubscribe(onUUIDNameReply) callback(cbdata) else: logger.info('Still waiting on %d names in send_UUIDNameRequest', len(missing)) handler.subscribe(onUUIDNameReply) logger.info('sending UUIDNameRequest') packet = Message('UUIDNameRequest', [Block('UUIDNameBlock', ID = UUID(agent_id)) for agent_id in agent_ids]) self.region.enqueue_message(packet)
def fetch_offline_ims(client): # Send RetrieveInstantMessages # Get back ImprovedInstantMessage def onImprovedInstantMessage(packet): block = packet['MessageBlock'][0] print "Message:" for prop in [ 'FromGroup', 'ToAgentID', 'ParentEstateID', 'RegionID', 'Position', 'Offline', 'Dialog', 'ID', 'Timestamp', 'FromAgentName', 'Message', 'BinaryBucket' ]: print " %s: %s" % (prop, block[prop]) client.region.message_handler.register('ImprovedInstantMessage').subscribe( onImprovedInstantMessage) packet = Message( 'RetrieveInstantMessages', Block('AgentData', AgentID=client.agent_id, SessionID=client.session_id)) client.region.enqueue_message(packet)
def fetch_agent_properties(client, agent_id, callback=None): # Send AvatarPropertiesRequest # Get back AvatarPropertiesReply def onAgentPropertiesReply(packet): if repr(packet['AgentData'][0]['AvatarID']) == agent_id: block = packet['PropertiesData'][0] for prop in [ 'ImageID', 'FLImageID', 'PartnerID', 'AboutText', 'FLAboutText', 'BornOn', 'ProfileURL', 'CharterMember', 'Flags' ]: print "%s: %s" % (prop, block[prop]) if callback: callback(packet) client.region.message_handler.register('AvatarPropertiesReply').subscribe( onAgentPropertiesReply) packet = Message( 'AvatarPropertiesRequest', Block('AgentData', AgentID=client.agent_id, SessionID=client.session_id, AvatarID=UUID(agent_id))) client.region.enqueue_message(packet)
def sendRezObject(agent, inventory_item, RayStart, RayEnd, FromTaskID=UUID(), BypassRaycast=1, RayTargetID=UUID(), RayEndIsIntersection=False, RezSelected=False, RemoveItem=True, ItemFlags=0, GroupMask=0, EveryoneMask=0, NextOwnerMask=0): """ sends a RezObject packet to a region """ packet = Message( 'RezObject', Block('AgentData', AgentID=agent.agent_id, SessionID=agent.session_id, GroupID=agent.ActiveGroupID), Block('RezData', FromTaskID=UUID(str(FromTaskID)), BypassRaycast=BypassRaycast, RayStart=RayStart, RayEnd=RayEnd, RayTargetID=UUID(str(RayTargetID)), RayEndIsIntersection=RayEndIsIntersection, RezSelected=RezSelected, RemoveItem=RemoveItem, ItemFlags=ItemFlags, GroupMask=GroupMask, EveryoneMask=EveryoneMask, NextOwnerMask=NextOwnerMask), Block('InventoryData', ItemID=inventory_item.ItemID, FolderID=inventory_item.FolderID, CreatorID=inventory_item.CreatorID, OwnerID=inventory_item.OwnerID, GroupID=inventory_item.GroupID, BaseMask=inventory_item.BaseMask, OwnerMask=inventory_item.OwnerMask, GroupMask=inventory_item.GroupMask, EveryoneMask=inventory_item.EveryoneMask, GroupOwned=inventory_item.GroupOwned, TransactionID=UUID(), Type=inventory_item.Type, InvType=inventory_item.InvType, Flags=inventory_item.Flags, SaleType=inventory_item.SaleType, SalePrice=inventory_item.SalePrice, Name=inventory_item.Name, Description=inventory_item.Description, CreationDate=inventory_item.CreationDate, CRC=inventory_item.CRC, NextOwnerMask=inventory_item.NextOwnerMask)) agent.region.enqueue_message(packet)
def send_RemoveInventoryItem(self, agent_id, session_id, item_id): """ sends a RemoveInventoryItem message """ args = [Block('AgentData', AgentID = agent_id, SessionID = session_id)] args += [Block('InventoryData', ItemID = item_id)] self.agent.region.enqueue_message(Message("RemoveInventoryItem", *args))
def sendEstateCovenantRequest(self, agent_id, session_id): """ send an EstateCovenantRequest message to the host simulator """ packet = Message('EstateCovenantRequest', Block('AgentData', AgentID = agent_id, SessionID = session_id)) self.region.enqueue_message(packet)
def send_AgentWearablesRequest(self, AgentID, SessionID): """ sends and AgentWearablesRequest message. """ packet = Message( 'AgentWearablesRequest', Block('AgentData', AgentID=AgentID, SessionID=SessionID)) self.agent.region.enqueue_message(packet)
def test_send_variable(self): msg = Message('PacketAck', Block('Packets', ID=0x00000003)) buf = self.udp_connection.send_message(msg, self.host) assert buf == \ '\x00' + '\x00\x00\x00\x01' + '\x00' + '\xff\xff\xff\xfb' + \ '\x01' + '\x03\x00\x00\x00', \ 'Received: ' + repr(buf) + ' ' + \ 'Expected: ' + repr('\x00' + '\x00\x00\x00\x01' + '\x00' + \ '\xff\xff\xff\xfb' + '\x01' + '\x03\x00\x00\x00')
def send_AgentDataUpdateRequest(self): """ queues a packet requesting an agent data update """ packet = Message('AgentDataUpdateRequest', Block('AgentData', AgentID = self.agent_id, SessionID = self.session_id)) self.region.enqueue_message(packet)
def send_RetrieveInstantMessages(self): """ asks simulator for instant messages stored while agent was offline """ packet = Message('RetrieveInstantMessages', Block('AgentData', AgentID = self.agent_id, SessionID = self.session_id)) self.region.enqueue_message(packet())
def send_JoinGroupRequest(self, agent_id, session_id, group_id): """ sends a JoinGroupRequest message to the hsot simulator """ packet = Message( 'JoinGroupRequest', Block('AgentData', AgentID=AgentID, SessionID=SessionID), Block('GroupData', GroupID=group_id)) self.agent.region.enqueue_message(packet, True)
def processGetScriptRunning(self, obj_id, item_id): print("GetScriptRunning", obj_id, item_id) agent = self.manager.client packet = Message( 'GetScriptRunning', Block('Script', ObjectID=UUID(str(obj_id)), ItemID=UUID(str(item_id)))) agent.region.enqueue_message(packet)
def request_block(self, min_x, max_x, min_y, max_y, callback): """ Return region info for a rectangular chunk of the map. Coordinates are in region-widths (convert from global coords by dividing by Region.WIDTH). Results are NOT cached for subsequent calls. The protocol does not have any indication of completion status. Therefore callbacks could occur at any time. Additionally, the same protocol replies are used for other queries, so spurrious calls could come through as a result of unrelated activity. """ handler = self.agent.region.message_handler.register('MapBlockReply') # This is sent as the Access to indicate that there is no region at # the specified coordinates NO_REGION = 255 # Maximum number of blocks returned per packet MAX_BLOCKS = 20 def onMapBlockReply(packet): """ handles the MapBlockReply message from a simulator """ for data in packet['Data']: if data['Access'] != NO_REGION: region = { 'x': data['X'], 'y': data['Y'], 'name': data['Name'] } callback(region) # NOTE: Cannot detect end-of-results if we get a "full" packet if len(packet['Data']) < MAX_BLOCKS: handler.unsubscribe(onMapBlockReply) # Register a handler for the response handler.subscribe(onMapBlockReply) packet = Message( 'MapBlockRequest', Block( 'AgentData', AgentID=self.agent.agent_id, SessionID=self.agent.session_id, Flags=0, EstateID=0, # filled in on server Godlike=False), # filled in on server Block('PositionData', MinX=min_x, MaxX=max_x, MinY=min_y, MaxY=max_y)) self.agent.region.enqueue_message(packet)
def test_send_reliable(self): msg = Message('PacketAck', Block('Packets', ID=0x00000003)) host = Host((MockupUDPServer(), 80)) ret_msg = self.udp_connection.send_reliable(msg, host, 10) test_str = '\x40' + '\x00\x00\x00\x01' + '\x00' + '\xff\xff\xff\xfb' + \ '\x01' + '\x03\x00\x00\x00' assert ret_msg == \ test_str ,\ 'Received: ' + repr(msg) + ' ' + \ 'Expected: ' + repr(test_str)
def sendParcelInfoRequest(self, agent_id, session_id, parcel_id): """ send a ParcelInfoRequest packet for the specified parcel_id """ packet = Message('ParcelInfoRequest', Block('AgentData', AgentID = agent_id, SessionID = session_id), Block('Data', ParcelID = parcel_id)) self.region.enqueue_message(packet)
def send_ActivateGroup(self, agent_id, session_id, group_id): """ send an ActivateGroup message to the host simulator """ packet = Message( 'ActivateGroup', Block('AgentData', AgentID=agent_id, SessionID=session_id, GroupID=group_id)) self.agent.region.enqueue_message(packet)
def processScriptReset(self, obj_id, item_id): agent = self.manager.client packet = Message( 'ScriptReset', Block('AgentData', AgentID=agent.agent_id, SessionID=agent.session_id), Block('Script', ObjectID=UUID(str(obj_id)), ItemID=UUID(str(item_id)))) agent.region.enqueue_message(packet)
def send_PurgeInventoryDescendents(self, agent, agent_id, session_id, folder_id): """ send a PurgeInventoryDescendents message to the host simulator """ packet = Message('PurgeInventoryDescendents', Block('AgentData', AgentID = agent_id, SessionID = session_id), Block('InventoryData', FolderID = folder_id)) agent.region.enqueue_message(packet)
def sendParcelDwellRequest(self, agent_id, session_id, LocalID): """ send a ParcelDwellRequest packet """ packet = Message('ParcelDwellRequest', Block('AgentData', AgentID = agent_id, SessionID = session_id), Block('Data', LocalID = LocalID, ParcelID = UUID())) self.region.enqueue_message(packet, True)
def test_onObjectUpdate_selected(self): self.object_store.agent = Agent() fake_uuid = UUID() fake_uuid.random() packet = Message( 'ObjectUpdate', Block('RegionData', RegionHandle=0, TimeDilation=0), Block('ObjectData', ID=1, State=1, FullID=fake_uuid, CRC=0, PCode=0, Material=0, ClickAction=0, Scale=Vector3(X=0.0, Y=0.0, Z=0.0), ObjectData='', ParentID=fake_uuid, UpdateFlags=0, ProfileCurve=0, PathBegin=0.0, PathEnd=0.0, PathScaleX=0.0, PathScaleY=0.0, PathShearX=0.0, PathShearY=0.0, PathTwist=-1, PathTwistBegin=-1, PathRadiusOffset=-1, PathTaperX=-1, PathTaperY=-1, PathRevolutions=0, PathSkew=-1, ProfileBegin=0, ProfileEnd=0, ProfileHollow=0, TextureEntry='', TextureAnim='', NameValue='Test', Data='', Text='', TextColor=0x0, MedialURL='')) def callback(payload): self.data.append("foo") object_handler = self.object_store.agent.events_handler.register( "ObjectSelected") object_handler.subscribe(callback) self.object_store.region.message_handler.handle(packet) self.assertTrue(self.data.pop, "foo")
def sendParcelPropertiesRequestByID(self, agent_id, session_id, SequenceID, LocalID): """ sends a ParcelPropertiesRequestByID packet """ packet = Message('ParcelPropertiesRequestByID', Block('AgentData', AgentID = agent_id, SessionID = session_id), Block('ParcelData', SequenceID = SequenceID, LocalID = LocalID)) self.region.enqueue_message(packet)
def sendAutopilot(self, agent, pos): packet = Message( 'GenericMessage', Block('AgentData', AgentID=client.agent_id, SessionID=client.session_id, TransactionID=t_id), Block('MethodData', Method='autopilot', Invoice=invoice_id), Block('ParamList', Parameter=data_x), Block('ParamList', Parameter=data_y), Block('ParamList', Parameter=data_z)) self.manager.client.region.enqueue_message(packet)
def send_AgentIsNowWearing(self, AgentID, SessionID, wearables): """ Tell the simulator that avatar is wearing initial items """ args = [Block('AgentData', AgentID=AgentID, SessionID=SessionID)] args += [Block('WearableData', ItemID = wearables[key].ItemID, WearableType = wearables[key].WearableType) \ for key in wearables.keys()] packet = Message('AgentIsNowWearing', *args) self.agent.region.enqueue_message(packet, True)
def sendParcelAccessListRequest(self, agent_id, session_id, LocalID, Flags, SequenceID = -5150): """ send a ParcelAccessListRequest packet to the host simulator """ packet = Message('ParcelAccessListRequest', Block('AgentData', AgentID = agent_id, SessionID = session_id), Block('Data', SequenceID = SequenceID, Flags = Flags, LocalID = LocalID)) self.region.enqueue_message(packet)
def test_add_reliable(self): circuit = Circuit(self.host, 1) assert circuit.unack_packet_count == 0, "Has incorrect unack count" assert len(circuit.unacked_packets) == 0, "Has incorrect unack" assert len( circuit.final_retry_packets) == 0, "Has incorrect final unacked" msg = Message('PacketAck', Block('Packets', ID=0x00000003)) circuit.add_reliable_packet(msg) assert circuit.unack_packet_count == 1, "Has incorrect unack count" assert len(circuit.unacked_packets) == 1, "Has incorrect unack, " + \ str(len(circuit.unacked_packets)) assert len( circuit.final_retry_packets) == 0, "Has incorrect final unacked"