Class: LibSL::Packet

Inherits:
Object
  • Object
show all
Defined in:
lib/packet.rb

Direct Known Subclasses

AbortXferPacket, AcceptCallingCardPacket, AcceptFriendshipPacket, ActivateGesturesPacket, ActivateGroupPacket, AddCircuitCodePacket, AgentAlertMessagePacket, AgentAnimationPacket, AgentCachedTexturePacket, AgentCachedTextureResponsePacket, AgentDataUpdatePacket, AgentDataUpdateRequestPacket, AgentDropGroupPacket, AgentFOVPacket, AgentGroupDataUpdatePacket, AgentHeightWidthPacket, AgentIsNowWearingPacket, AgentMovementCompletePacket, AgentPausePacket, AgentQuitCopyPacket, AgentRequestSitPacket, AgentResumePacket, AgentSetAppearancePacket, AgentSitPacket, AgentThrottlePacket, AgentUpdatePacket, AgentWearablesRequestPacket, AgentWearablesUpdatePacket, AlertMessagePacket, AssetUploadCompletePacket, AssetUploadRequestPacket, AtomicPassObjectPacket, AttachedSoundGainChangePacket, AttachedSoundPacket, AvatarAnimationPacket, AvatarAppearancePacket, AvatarClassifiedReplyPacket, AvatarGroupsReplyPacket, AvatarInterestsReplyPacket, AvatarInterestsUpdatePacket, AvatarNotesReplyPacket, AvatarNotesUpdatePacket, AvatarPickerReplyPacket, AvatarPickerRequestBackendPacket, AvatarPickerRequestPacket, AvatarPicksReplyPacket, AvatarPropertiesReplyPacket, AvatarPropertiesRequestBackendPacket, AvatarPropertiesRequestPacket, AvatarPropertiesUpdatePacket, AvatarSitResponsePacket, AvatarTextureUpdatePacket, BulkUpdateInventoryPacket, BuyObjectInventoryPacket, CameraConstraintPacket, CancelAuctionPacket, ChangeInventoryItemFlagsPacket, ChangeUserRightsPacket, ChatFromSimulatorPacket, ChatFromViewerPacket, ChatPassPacket, CheckParcelAuctionsPacket, CheckParcelSalesPacket, ChildAgentAlivePacket, ChildAgentDyingPacket, ChildAgentPositionUpdatePacket, ChildAgentUnknownPacket, ChildAgentUpdatePacket, ClassifiedDeletePacket, ClassifiedGodDeletePacket, ClassifiedInfoReplyPacket, ClassifiedInfoRequestPacket, ClassifiedInfoUpdatePacket, ClearFollowCamPropertiesPacket, CloseCircuitPacket, CoarseLocationUpdatePacket, CompleteAgentMovementPacket, CompleteAuctionPacket, CompletePingCheckPacket, ConfirmAuctionStartPacket, ConfirmEnableSimulatorPacket, ConfirmXferPacketPacket, CopyInventoryFromNotecardPacket, CopyInventoryItemPacket, CreateGroupReplyPacket, CreateGroupRequestPacket, CreateInventoryFolderPacket, CreateInventoryItemPacket, CreateLandmarkForEventPacket, CreateNewOutfitAttachmentsPacket, CreateTrustedCircuitPacket, CrossedRegionPacket, DataHomeLocationReplyPacket, DataHomeLocationRequestPacket, DataServerLogoutPacket, DeRezAckPacket, DeRezObjectPacket, DeactivateGesturesPacket, DeclineCallingCardPacket, DeclineFriendshipPacket, DenyTrustedCircuitPacket, DerezContainerPacket, DetachAttachmentIntoInvPacket, DirClassifiedQueryBackendPacket, DirClassifiedQueryPacket, DirClassifiedReplyPacket, DirEventsReplyPacket, DirFindQueryBackendPacket, DirFindQueryPacket, DirGroupsReplyPacket, DirLandQueryBackendPacket, DirLandQueryPacket, DirLandReplyPacket, DirPeopleReplyPacket, DirPlacesQueryBackendPacket, DirPlacesQueryPacket, DirPlacesReplyPacket, DirPopularQueryBackendPacket, DirPopularQueryPacket, DirPopularReplyPacket, DisableSimulatorPacket, EconomyDataPacket, EconomyDataRequestPacket, EdgeDataPacketPacket, EjectGroupMemberReplyPacket, EjectGroupMemberRequestPacket, EjectUserPacket, EmailMessageReplyPacket, EmailMessageRequestPacket, EnableSimulatorPacket, ErrorPacket, EstateCovenantReplyPacket, EstateCovenantRequestPacket, EstateOwnerMessagePacket, EventGodDeletePacket, EventInfoReplyPacket, EventInfoRequestPacket, EventLocationReplyPacket, EventLocationRequestPacket, EventNotificationAddRequestPacket, EventNotificationRemoveRequestPacket, FeatureDisabledPacket, FetchInventoryDescendentsPacket, FetchInventoryPacket, FetchInventoryReplyPacket, FindAgentPacket, ForceObjectSelectPacket, ForceScriptControlReleasePacket, FormFriendshipPacket, FreezeUserPacket, GenericMessagePacket, GetScriptRunningPacket, GodKickUserPacket, GodUpdateRegionInfoPacket, GodlikeMessagePacket, GrantGodlikePowersPacket, GrantUserRightsPacket, GroupAccountDetailsReplyPacket, GroupAccountDetailsRequestPacket, GroupAccountSummaryReplyPacket, GroupAccountSummaryRequestPacket, GroupAccountTransactionsReplyPacket, GroupAccountTransactionsRequestPacket, GroupActiveProposalItemReplyPacket, GroupActiveProposalsRequestPacket, GroupDataUpdatePacket, GroupMembersReplyPacket, GroupMembersRequestPacket, GroupNoticeAddPacket, GroupNoticeRequestPacket, GroupNoticesListReplyPacket, GroupNoticesListRequestPacket, GroupProfileReplyPacket, GroupProfileRequestPacket, GroupProposalBallotPacket, GroupRoleChangesPacket, GroupRoleDataReplyPacket, GroupRoleDataRequestPacket, GroupRoleMembersReplyPacket, GroupRoleMembersRequestPacket, GroupRoleUpdatePacket, GroupTitleUpdatePacket, GroupTitlesReplyPacket, GroupTitlesRequestPacket, GroupVoteHistoryItemReplyPacket, GroupVoteHistoryRequestPacket, HealthMessagePacket, ImageDataPacket, ImageNotInDatabasePacket, ImagePacketPacket, ImprovedInstantMessagePacket, ImprovedTerseObjectUpdatePacket, InitiateDownloadPacket, InternalScriptMailPacket, InventoryAssetResponsePacket, InventoryDescendentsPacket, InviteGroupRequestPacket, InviteGroupResponsePacket, JoinGroupReplyPacket, JoinGroupRequestPacket, KickUserAckPacket, KickUserPacket, KillChildAgentsPacket, KillObjectPacket, LandStatReplyPacket, LandStatRequestPacket, LayerDataPacket, LeaveGroupReplyPacket, LeaveGroupRequestPacket, LinkInventoryItemPacket, LiveHelpGroupReplyPacket, LiveHelpGroupRequestPacket, LoadURLPacket, LogDwellTimePacket, LogFailedMoneyTransactionPacket, LogParcelChangesPacket, LogTextMessagePacket, LogoutReplyPacket, LogoutRequestPacket, MapBlockReplyPacket, MapBlockRequestPacket, MapItemReplyPacket, MapItemRequestPacket, MapLayerReplyPacket, MapLayerRequestPacket, MapNameRequestPacket, MeanCollisionAlertPacket, MergeParcelPacket, ModifyLandPacket, MoneyBalanceReplyPacket, MoneyBalanceRequestPacket, MoneyTransferBackendPacket, MoneyTransferRequestPacket, MoveInventoryFolderPacket, MoveInventoryItemPacket, MoveTaskInventoryPacket, MultipleObjectUpdatePacket, MuteListRequestPacket, MuteListUpdatePacket, NameValuePairPacket, NearestLandingRegionReplyPacket, NearestLandingRegionRequestPacket, NearestLandingRegionUpdatedPacket, NeighborListPacket, NetTestPacket, ObjectAddPacket, ObjectAttachPacket, ObjectBuyPacket, ObjectCategoryPacket, ObjectClickActionPacket, ObjectDeGrabPacket, ObjectDeletePacket, ObjectDelinkPacket, ObjectDescriptionPacket, ObjectDeselectPacket, ObjectDetachPacket, ObjectDropPacket, ObjectDuplicateOnRayPacket, ObjectDuplicatePacket, ObjectExportSelectedPacket, ObjectExtraParamsPacket, ObjectFlagUpdatePacket, ObjectGrabPacket, ObjectGrabUpdatePacket, ObjectGroupPacket, ObjectImagePacket, ObjectIncludeInSearchPacket, ObjectLinkPacket, ObjectMaterialPacket, ObjectNamePacket, ObjectOwnerPacket, ObjectPermissionsPacket, ObjectPositionPacket, ObjectPropertiesFamilyPacket, ObjectPropertiesPacket, ObjectRotationPacket, ObjectSaleInfoPacket, ObjectScalePacket, ObjectSelectPacket, ObjectShapePacket, ObjectSpinStartPacket, ObjectSpinStopPacket, ObjectSpinUpdatePacket, ObjectUpdateCachedPacket, ObjectUpdateCompressedPacket, ObjectUpdatePacket, OfferCallingCardPacket, OfflineNotificationPacket, OnlineNotificationPacket, OpenCircuitPacket, PacketAckPacket, ParcelAccessListReplyPacket, ParcelAccessListRequestPacket, ParcelAccessListUpdatePacket, ParcelAuctionsPacket, ParcelBuyPacket, ParcelBuyPassPacket, ParcelClaimPacket, ParcelDeedToGroupPacket, ParcelDisableObjectsPacket, ParcelDividePacket, ParcelDwellReplyPacket, ParcelDwellRequestPacket, ParcelGodForceOwnerPacket, ParcelGodMarkAsContentPacket, ParcelInfoReplyPacket, ParcelInfoRequestPacket, ParcelJoinPacket, ParcelMediaCommandMessagePacket, ParcelMediaUpdatePacket, ParcelObjectOwnersReplyPacket, ParcelObjectOwnersRequestPacket, ParcelOverlayPacket, ParcelPropertiesPacket, ParcelPropertiesRequestByIDPacket, ParcelPropertiesRequestPacket, ParcelPropertiesUpdatePacket, ParcelReclaimPacket, ParcelReleasePacket, ParcelRenamePacket, ParcelReturnObjectsPacket, ParcelSalesPacket, ParcelSelectObjectsPacket, ParcelSetOtherCleanTimePacket, PayPriceReplyPacket, PickDeletePacket, PickGodDeletePacket, PickInfoReplyPacket, PickInfoUpdatePacket, PlacesQueryPacket, PlacesReplyPacket, PreloadSoundPacket, PurgeInventoryDescendentsPacket, RebakeAvatarTexturesPacket, RedoPacket, RegionHandleRequestPacket, RegionHandshakePacket, RegionHandshakeReplyPacket, RegionIDAndHandleReplyPacket, RegionInfoPacket, RegionPresenceRequestByHandlePacket, RegionPresenceRequestByRegionIDPacket, RegionPresenceResponsePacket, RemoveAttachmentPacket, RemoveInventoryFolderPacket, RemoveInventoryItemPacket, RemoveInventoryObjectsPacket, RemoveMuteListEntryPacket, RemoveNameValuePairPacket, RemoveParcelPacket, RemoveTaskInventoryPacket, ReplyTaskInventoryPacket, ReportAutosaveCrashPacket, RequestGodlikePowersPacket, RequestImagePacket, RequestInventoryAssetPacket, RequestMultipleObjectsPacket, RequestObjectPropertiesFamilyPacket, RequestParcelTransferPacket, RequestPayPricePacket, RequestRegionInfoPacket, RequestTaskInventoryPacket, RequestTrustedCircuitPacket, RequestXferPacket, RetrieveInstantMessagesPacket, RevokePermissionsPacket, RezMultipleAttachmentsFromInvPacket, RezObjectFromNotecardPacket, RezObjectPacket, RezRestoreToWorldPacket, RezScriptPacket, RezSingleAttachmentFromInvPacket, RoutedMoneyBalanceReplyPacket, RpcChannelReplyPacket, RpcChannelRequestPacket, RpcScriptReplyInboundPacket, RpcScriptRequestInboundForwardPacket, RpcScriptRequestInboundPacket, SaveAssetIntoInventoryPacket, ScriptAnswerYesPacket, ScriptControlChangePacket, ScriptDataReplyPacket, ScriptDataRequestPacket, ScriptDialogPacket, ScriptDialogReplyPacket, ScriptMailRegistrationPacket, ScriptQuestionPacket, ScriptResetPacket, ScriptRunningReplyPacket, ScriptSensorReplyPacket, ScriptSensorRequestPacket, ScriptTeleportRequestPacket, SendPostcardPacket, SendXferPacketPacket, SetAlwaysRunPacket, SetCPURatioPacket, SetFollowCamPropertiesPacket, SetGroupAcceptNoticesPacket, SetGroupContributionPacket, SetScriptRunningPacket, SetSimPresenceInDatabasePacket, SetSimStatusInDatabasePacket, SetStartLocationPacket, SetStartLocationRequestPacket, SimCrashedPacket, SimStatsPacket, SimStatusPacket, SimWideDeletesPacket, SimulatorLoadPacket, SimulatorMapUpdatePacket, SimulatorPresentAtLocationPacket, SimulatorReadyPacket, SimulatorSetMapPacket, SimulatorShutdownRequestPacket, SimulatorViewerTimeMessagePacket, SoundTriggerPacket, StartAuctionPacket, StartGroupProposalPacket, StartLurePacket, StartPingCheckPacket, StateSavePacket, SubscribeLoadPacket, SystemKickUserPacket, SystemMessagePacket, TallyVotesPacket, TelehubInfoPacket, TeleportCancelPacket, TeleportFailedPacket, TeleportFinishPacket, TeleportLandingStatusChangedPacket, TeleportLandmarkRequestPacket, TeleportLocalPacket, TeleportLocationRequestPacket, TeleportLureRequestPacket, TeleportProgressPacket, TeleportRequestPacket, TeleportStartPacket, TerminateFriendshipPacket, TestMessagePacket, TrackAgentPacket, TransferAbortPacket, TransferInfoPacket, TransferInventoryAckPacket, TransferInventoryPacket, TransferPacketPacket, TransferRequestPacket, UUIDGroupNameReplyPacket, UUIDGroupNameRequestPacket, UUIDNameReplyPacket, UUIDNameRequestPacket, UndoLandPacket, UndoPacket, UnsubscribeLoadPacket, UpdateAttachmentPacket, UpdateCreateInventoryItemPacket, UpdateGroupInfoPacket, UpdateInventoryFolderPacket, UpdateInventoryItemPacket, UpdateMuteListEntryPacket, UpdateParcelPacket, UpdateSimulatorPacket, UpdateTaskInventoryPacket, UpdateUserInfoPacket, UseCachedMuteListPacket, UseCircuitCodePacket, UserInfoReplyPacket, UserInfoRequestPacket, UserReportInternalPacket, UserReportPacket, VelocityInterpolateOffPacket, VelocityInterpolateOnPacket, ViewerEffectPacket, ViewerFrozenMessagePacket, ViewerStartAuctionPacket, ViewerStatsPacket

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blocks = {}) ⇒ Packet

Create a new packet Example: { :Block1 => { # Block :Var1 => LLU8.new(0xff), :Var2 => LLVariable1.new(“abcd”) }, :Block2 => [ # Block collection { :Var1 => LLFixed.new(“block1”), :Var2 => LLS32.new(0x12345678) }, { :Var1 => LLFixed.new(“block2”), :Var2 => LLS32.new(0x12345678) } ] }

Parameters:

  • blocks (Hash) (defaults to: {})

    (optional) Data blocks



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/packet.rb', line 74

def initialize(blocks={})
	@zero_coded_flag = false
	@reliable_flag = false
	@resent_flag = false
	@acks_flag = false
	@acks = []
	@resent_count = 0
	build_structure
	blocks.each do |name, block|
		case block
		when Array then
			block.each_index do |i|
				collection = self.send(name)
				case collection
				when VariableBlockCollection then
					b = collection.add
				when FixedBlockCollection then
					b = collection[i]
				end

				block[i].each do |v|
					b.send((v[0].to_s + "=").to_sym, v[1])
				end
			end
		when Hash then
			block.each do |v|
				self.send(name).send((v[0].to_s + "=").to_sym, v[1])
			end
		end
	end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



157
158
159
160
161
# File 'lib/packet.rb', line 157

def method_missing(name, *args)
	block = @blocks.assoc(name)
	throw "The method #{name} does not exist in #{self.class.name}" if block.nil?
	block[1]
end

Instance Attribute Details

#acksObject

Returns the value of attribute acks.



52
53
54
# File 'lib/packet.rb', line 52

def acks
  @acks
end

#acks_flagObject

Returns the value of attribute acks_flag.



52
53
54
# File 'lib/packet.rb', line 52

def acks_flag
  @acks_flag
end

#reliable_flagObject

Returns the value of attribute reliable_flag.



52
53
54
# File 'lib/packet.rb', line 52

def reliable_flag
  @reliable_flag
end

#resent_countObject

Returns the value of attribute resent_count.



52
53
54
# File 'lib/packet.rb', line 52

def resent_count
  @resent_count
end

#resent_flagObject

Returns the value of attribute resent_flag.



52
53
54
# File 'lib/packet.rb', line 52

def resent_flag
  @resent_flag
end

#sequence_numberObject

Returns the value of attribute sequence_number.



52
53
54
# File 'lib/packet.rb', line 52

def sequence_number
  @sequence_number
end

#zero_coded_flagObject

Returns the value of attribute zero_coded_flag.



52
53
54
# File 'lib/packet.rb', line 52

def zero_coded_flag
  @zero_coded_flag
end

Class Method Details

.decode(data) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/packet.rb', line 8

def self.decode(data)
	flags, data = LLU8.decode(data)
	sequence_number, data = LLSequenceNumber.decode(data)
	extra, data = LLU8.decode(data)
	if extra.value > 0 then
		extra, data = LLFixed.decode(data, extra)
	end
	data = zero_decode(data) if flags.value & 0x80 == 0x80
	packet_number, data = LLPacketNumber.decode(data)
	klass = MESSAGE_MAP[packet_number.number]
	throw "Unknown message type!" if klass.nil?

	packet = klass.new
	packet.zero_coded_flag = flags.value & 0x80 == 0x80
	packet.reliable_flag = flags.value & 0x40 == 0x40
	packet.resent_flag = flags.value & 0x20 == 0x20
	packet.acks_flag = flags.value & 0x10 == 0x10
	packet.sequence_number = sequence_number
	data = packet.decode_msg(data)
	if packet.acks_flag && data.length > 0 then
		# Extract acks
		ack_count = data[-1]
		packet.acks = data.unpack('N'+ack_count)
	end
	packet
end

.packet_idObject



4
5
6
# File 'lib/packet.rb', line 4

def self.packet_id()
	0
end

.zero_decode(data) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/packet.rb', line 35

def self.zero_decode(data)
	# Decode 0x00 0xXX to a sequence of 0xXX zeros
	decoded = []
	zero = false
	data.bytes do |byte|
		if byte == 0x00
			zero = true
		elsif zero == true
			byte.times{ decoded << 0x00 }
			zero = false
		else
			decoded << byte
		end
	end
	decoded.pack('C*')
end

Instance Method Details

#build_structureObject

Subclasses have to override this method to build the message structure IMPORTANT: Use arrays to describe the structure, as hashes don’t preserve the order Example: def build_structure() @blocks = [ [:AgentData, Block.new([ [:AgentID, :LLUUID], [:SessionID, :LLUUID] ])], [:SomeData, FixedBlockCollection.new(4, [ [:Data, :LLVariable1] ])] ] end



138
139
# File 'lib/packet.rb', line 138

def build_structure()
end

#decode_msg(data) ⇒ Object



141
142
143
144
145
146
147
148
149
# File 'lib/packet.rb', line 141

def decode_msg(data)
	@blocks.each do |block|
		data = block[1].decode(data)
	end
	data
rescue => e
	puts "[ERROR] #{self.class.name}: #{self.inspect}"
	raise e
end

#encodeObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/packet.rb', line 106

def encode()
	flags = 0
	flags |= 0x80 if @zero_coded_flag
	flags |= 0x40 if @reliable_flag
	flags |= 0x20 if @resent_flag
	flags |= 0x10 if @acks_flag
	
	data = LLU8.new(flags).encode +
		LLSequenceNumber.new(@sequence_number).encode +
		LLU8.new(0).encode
	pid = LLPacketNumber.new(self.class.packet_id).encode
	data += pid
	data += encode_msg
	# append acks
	data += ([*@acks] + [@acks.length]).pack("N#{@acks.length}C") if @acks_flag
	data
end

#encode_msgObject



151
152
153
154
155
# File 'lib/packet.rb', line 151

def encode_msg()
	data = ""
	@blocks.each{ |block| data += block[1].encode }
	data
end