/* * Copyright (c) 2006, the libsecondlife development team * All rights reserved. * * - Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * - Neither the name of the Second Life Reverse Engineering Team nor the names * of its contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ using System; using libsecondlife; namespace libsecondlife.Packets { /// /// /// public class MalformedDataException : ApplicationException { /// /// /// public MalformedDataException() { } /// /// /// /// public MalformedDataException(string Message) : base(Message) { this.Source = "Packet decoding"; } } /// /// /// public abstract class Header { /// public byte[] Data; /// public byte Flags { get { return Data[0]; } set { Data[0] = value; } } /// public bool Reliable { get { return (Data[0] & Helpers.MSG_RELIABLE) != 0; } set { if (value) { Data[0] |= (byte)Helpers.MSG_RELIABLE; } else { Data[0] -= (byte)Helpers.MSG_RELIABLE; } } } /// public bool Resent { get { return (Data[0] & Helpers.MSG_RESENT) != 0; } set { if (value) { Data[0] |= (byte)Helpers.MSG_RESENT; } else { Data[0] -= (byte)Helpers.MSG_RESENT; } } } /// public bool Zerocoded { get { return (Data[0] & Helpers.MSG_ZEROCODED) != 0; } set { if (value) { Data[0] |= (byte)Helpers.MSG_ZEROCODED; } else { Data[0] -= (byte)Helpers.MSG_ZEROCODED; } } } /// public bool AppendedAcks { get { return (Data[0] & Helpers.MSG_APPENDED_ACKS) != 0; } set { if (value) { Data[0] |= (byte)Helpers.MSG_APPENDED_ACKS; } else { Data[0] -= (byte)Helpers.MSG_APPENDED_ACKS; } } } /// public ushort Sequence { get { return (ushort)((Data[2] << 8) + Data[3]); } set { Data[2] = (byte)(value >> 8); Data[3] = (byte)(value % 256); } } /// public abstract ushort ID { get; set; } /// public abstract PacketFrequency Frequency { get; } /// public abstract void ToBytes(byte[] bytes, ref int i); /// public uint[] AckList; /// /// /// /// /// public void AcksToBytes(byte[] bytes, ref int i) { foreach (uint ack in AckList) { bytes[i++] = (byte)((ack >> 24) % 256); bytes[i++] = (byte)((ack >> 16) % 256); bytes[i++] = (byte)((ack >> 8) % 256); bytes[i++] = (byte)(ack % 256); } if (AckList.Length > 0) { bytes[i++] = (byte)AckList.Length; } } /// /// /// /// /// /// /// public static Header BuildHeader(byte[] bytes, ref int pos, ref int packetEnd) { if (bytes[4] == 0xFF) { if (bytes[5] == 0xFF) { return new LowHeader(bytes, ref pos, ref packetEnd); } else { return new MediumHeader(bytes, ref pos, ref packetEnd); } } else { return new HighHeader(bytes, ref pos, ref packetEnd); } } /// /// /// /// /// protected void CreateAckList(byte[] bytes, ref int packetEnd) { if (AppendedAcks) { try { int count = bytes[packetEnd--]; AckList = new uint[count]; for (int i = 0; i < count; i++) { AckList[i] = (ushort)((bytes[(packetEnd - i * 4) - 1] << 8) | (bytes[packetEnd - i * 4])); } packetEnd -= (count * 4); } catch (Exception) { AckList = new uint[0]; throw new MalformedDataException(); } } else { AckList = new uint[0]; } } } /// /// /// public class LowHeader : Header { /// public override ushort ID { get { return (ushort)((Data[6] << 8) + Data[7]); } set { Data[6] = (byte)(value >> 8); Data[7] = (byte)(value % 256); } } /// public override PacketFrequency Frequency { get { return PacketFrequency.Low; } } /// /// /// public LowHeader() { Data = new byte[8]; Data[4] = Data[5] = 0xFF; AckList = new uint[0]; } /// /// /// /// /// /// public LowHeader(byte[] bytes, ref int pos, ref int packetEnd) { if (bytes.Length < 8) { throw new MalformedDataException(); } Data = new byte[8]; Array.Copy(bytes, Data, 8); if ((bytes[0] & Helpers.MSG_ZEROCODED) != 0 && bytes[6] == 0) { if (bytes[7] == 1) { Data[7] = bytes[8]; } else { throw new MalformedDataException(); } } pos = 8; CreateAckList(bytes, ref packetEnd); } /// /// /// /// /// public override void ToBytes(byte[] bytes, ref int i) { Array.Copy(Data, 0, bytes, i, 8); i += 8; } } /// /// /// public class MediumHeader : Header { /// public override ushort ID { get { return (ushort)Data[5]; } set { Data[5] = (byte)value; } } /// public override PacketFrequency Frequency { get { return PacketFrequency.Medium; } } /// /// /// public MediumHeader() { Data = new byte[6]; Data[4] = 0xFF; AckList = new uint[0]; } /// /// /// /// /// /// public MediumHeader(byte[] bytes, ref int pos, ref int packetEnd) { if (bytes.Length < 6) { throw new MalformedDataException(); } Data = new byte[6]; Array.Copy(bytes, Data, 6); pos = 6; CreateAckList(bytes, ref packetEnd); } /// /// /// /// /// public override void ToBytes(byte[] bytes, ref int i) { Array.Copy(Data, 0, bytes, i, 6); i += 6; } } /// /// /// public class HighHeader : Header { /// public override ushort ID { get { return (ushort)Data[4]; } set { Data[4] = (byte)value; } } /// public override PacketFrequency Frequency { get { return PacketFrequency.High; } } /// /// /// public HighHeader() { Data = new byte[5]; AckList = new uint[0]; } /// /// /// /// /// /// public HighHeader(byte[] bytes, ref int pos, ref int packetEnd) { if (bytes.Length < 5) { throw new MalformedDataException(); } Data = new byte[5]; Array.Copy(bytes, Data, 5); pos = 5; CreateAckList(bytes, ref packetEnd); } /// /// /// /// /// public override void ToBytes(byte[] bytes, ref int i) { Array.Copy(Data, 0, bytes, i, 5); i += 5; } } /// Used to identify the type of a packet public enum PacketType { /// A generic value, not an actual packet type Default, /// TestMessage TestMessage, /// AddCircuitCode AddCircuitCode, /// UseCircuitCode UseCircuitCode, /// LogControl LogControl, /// RelayLogControl RelayLogControl, /// LogMessages LogMessages, /// SimulatorAssign SimulatorAssign, /// SpaceServerSimulatorTimeMessage SpaceServerSimulatorTimeMessage, /// AvatarTextureUpdate AvatarTextureUpdate, /// SimulatorMapUpdate SimulatorMapUpdate, /// SimulatorSetMap SimulatorSetMap, /// SubscribeLoad SubscribeLoad, /// UnsubscribeLoad UnsubscribeLoad, /// SimulatorStart SimulatorStart, /// SimulatorReady SimulatorReady, /// TelehubInfo TelehubInfo, /// SimulatorPresentAtLocation SimulatorPresentAtLocation, /// SimulatorLoad SimulatorLoad, /// SimulatorShutdownRequest SimulatorShutdownRequest, /// RegionPresenceRequestByRegionID RegionPresenceRequestByRegionID, /// RegionPresenceRequestByHandle RegionPresenceRequestByHandle, /// RegionPresenceResponse RegionPresenceResponse, /// RecordAgentPresence RecordAgentPresence, /// EraseAgentPresence EraseAgentPresence, /// AgentPresenceRequest AgentPresenceRequest, /// AgentPresenceResponse AgentPresenceResponse, /// UpdateSimulator UpdateSimulator, /// TrackAgentSession TrackAgentSession, /// ClearAgentSessions ClearAgentSessions, /// LogDwellTime LogDwellTime, /// FeatureDisabled FeatureDisabled, /// LogFailedMoneyTransaction LogFailedMoneyTransaction, /// UserReportInternal UserReportInternal, /// SetSimStatusInDatabase SetSimStatusInDatabase, /// SetSimPresenceInDatabase SetSimPresenceInDatabase, /// EconomyDataRequest EconomyDataRequest, /// EconomyData EconomyData, /// AvatarPickerRequest AvatarPickerRequest, /// AvatarPickerRequestBackend AvatarPickerRequestBackend, /// AvatarPickerReply AvatarPickerReply, /// PlacesQuery PlacesQuery, /// PlacesReply PlacesReply, /// DirFindQuery DirFindQuery, /// DirFindQueryBackend DirFindQueryBackend, /// DirPlacesQuery DirPlacesQuery, /// DirPlacesQueryBackend DirPlacesQueryBackend, /// DirPlacesReply DirPlacesReply, /// DirPeopleQuery DirPeopleQuery, /// DirPeopleQueryBackend DirPeopleQueryBackend, /// DirPeopleReply DirPeopleReply, /// DirEventsReply DirEventsReply, /// DirGroupsQuery DirGroupsQuery, /// DirGroupsQueryBackend DirGroupsQueryBackend, /// DirGroupsReply DirGroupsReply, /// DirClassifiedQuery DirClassifiedQuery, /// DirClassifiedQueryBackend DirClassifiedQueryBackend, /// DirClassifiedReply DirClassifiedReply, /// AvatarClassifiedReply AvatarClassifiedReply, /// ClassifiedInfoRequest ClassifiedInfoRequest, /// ClassifiedInfoReply ClassifiedInfoReply, /// ClassifiedInfoUpdate ClassifiedInfoUpdate, /// ClassifiedDelete ClassifiedDelete, /// ClassifiedGodDelete ClassifiedGodDelete, /// DirPicksQuery DirPicksQuery, /// DirPicksQueryBackend DirPicksQueryBackend, /// DirPicksReply DirPicksReply, /// DirLandQuery DirLandQuery, /// DirLandQueryBackend DirLandQueryBackend, /// DirLandReply DirLandReply, /// DirPopularQuery DirPopularQuery, /// DirPopularQueryBackend DirPopularQueryBackend, /// DirPopularReply DirPopularReply, /// ParcelInfoRequest ParcelInfoRequest, /// ParcelInfoReply ParcelInfoReply, /// ParcelObjectOwnersRequest ParcelObjectOwnersRequest, /// OnlineStatusRequest OnlineStatusRequest, /// OnlineStatusReply OnlineStatusReply, /// ParcelObjectOwnersReply ParcelObjectOwnersReply, /// GroupNoticesListRequest GroupNoticesListRequest, /// GroupNoticesListReply GroupNoticesListReply, /// GroupNoticeRequest GroupNoticeRequest, /// GroupNoticeAdd GroupNoticeAdd, /// GroupNoticeDelete GroupNoticeDelete, /// TeleportRequest TeleportRequest, /// TeleportLocationRequest TeleportLocationRequest, /// TeleportLocal TeleportLocal, /// TeleportLandmarkRequest TeleportLandmarkRequest, /// TeleportProgress TeleportProgress, /// DataAgentAccessRequest DataAgentAccessRequest, /// DataAgentAccessReply DataAgentAccessReply, /// DataHomeLocationRequest DataHomeLocationRequest, /// DataHomeLocationReply DataHomeLocationReply, /// SpaceLocationTeleportRequest SpaceLocationTeleportRequest, /// SpaceLocationTeleportReply SpaceLocationTeleportReply, /// TeleportFinish TeleportFinish, /// StartLure StartLure, /// TeleportLureRequest TeleportLureRequest, /// TeleportCancel TeleportCancel, /// CompleteLure CompleteLure, /// TeleportStart TeleportStart, /// TeleportFailed TeleportFailed, /// LeaderBoardRequest LeaderBoardRequest, /// LeaderBoardData LeaderBoardData, /// RegisterNewAgent RegisterNewAgent, /// Undo Undo, /// Redo Redo, /// UndoLand UndoLand, /// RedoLand RedoLand, /// AgentPause AgentPause, /// AgentResume AgentResume, /// ChatFromViewer ChatFromViewer, /// AgentThrottle AgentThrottle, /// AgentFOV AgentFOV, /// AgentHeightWidth AgentHeightWidth, /// AgentSetAppearance AgentSetAppearance, /// AgentQuit AgentQuit, /// AgentQuitCopy AgentQuitCopy, /// ImageNotInDatabase ImageNotInDatabase, /// RebakeAvatarTextures RebakeAvatarTextures, /// SetAlwaysRun SetAlwaysRun, /// ObjectDelete ObjectDelete, /// ObjectDuplicate ObjectDuplicate, /// ObjectDuplicateOnRay ObjectDuplicateOnRay, /// ObjectScale ObjectScale, /// ObjectRotation ObjectRotation, /// ObjectFlagUpdate ObjectFlagUpdate, /// ObjectClickAction ObjectClickAction, /// ObjectImage ObjectImage, /// ObjectMaterial ObjectMaterial, /// ObjectShape ObjectShape, /// ObjectExtraParams ObjectExtraParams, /// ObjectOwner ObjectOwner, /// ObjectGroup ObjectGroup, /// ObjectBuy ObjectBuy, /// BuyObjectInventory BuyObjectInventory, /// DerezContainer DerezContainer, /// ObjectPermissions ObjectPermissions, /// ObjectSaleInfo ObjectSaleInfo, /// ObjectName ObjectName, /// ObjectDescription ObjectDescription, /// ObjectCategory ObjectCategory, /// ObjectSelect ObjectSelect, /// ObjectDeselect ObjectDeselect, /// ObjectAttach ObjectAttach, /// ObjectDetach ObjectDetach, /// ObjectDrop ObjectDrop, /// ObjectLink ObjectLink, /// ObjectDelink ObjectDelink, /// ObjectHinge ObjectHinge, /// ObjectDehinge ObjectDehinge, /// ObjectGrab ObjectGrab, /// ObjectGrabUpdate ObjectGrabUpdate, /// ObjectDeGrab ObjectDeGrab, /// ObjectSpinStart ObjectSpinStart, /// ObjectSpinUpdate ObjectSpinUpdate, /// ObjectSpinStop ObjectSpinStop, /// ObjectExportSelected ObjectExportSelected, /// ObjectImport ObjectImport, /// ModifyLand ModifyLand, /// VelocityInterpolateOn VelocityInterpolateOn, /// VelocityInterpolateOff VelocityInterpolateOff, /// StateSave StateSave, /// ReportAutosaveCrash ReportAutosaveCrash, /// SimWideDeletes SimWideDeletes, /// TrackAgent TrackAgent, /// GrantModification GrantModification, /// RevokeModification RevokeModification, /// RequestGrantedProxies RequestGrantedProxies, /// GrantedProxies GrantedProxies, /// AddModifyAbility AddModifyAbility, /// RemoveModifyAbility RemoveModifyAbility, /// ViewerStats ViewerStats, /// ScriptAnswerYes ScriptAnswerYes, /// UserReport UserReport, /// AlertMessage AlertMessage, /// AgentAlertMessage AgentAlertMessage, /// MeanCollisionAlert MeanCollisionAlert, /// ViewerFrozenMessage ViewerFrozenMessage, /// HealthMessage HealthMessage, /// ChatFromSimulator ChatFromSimulator, /// SimStats SimStats, /// RequestRegionInfo RequestRegionInfo, /// RegionInfo RegionInfo, /// GodUpdateRegionInfo GodUpdateRegionInfo, /// NearestLandingRegionRequest NearestLandingRegionRequest, /// NearestLandingRegionReply NearestLandingRegionReply, /// NearestLandingRegionUpdated NearestLandingRegionUpdated, /// TeleportLandingStatusChanged TeleportLandingStatusChanged, /// RegionHandshake RegionHandshake, /// RegionHandshakeReply RegionHandshakeReply, /// SimulatorViewerTimeMessage SimulatorViewerTimeMessage, /// EnableSimulator EnableSimulator, /// DisableSimulator DisableSimulator, /// TransferRequest TransferRequest, /// TransferInfo TransferInfo, /// TransferAbort TransferAbort, /// TransferPriority TransferPriority, /// RequestXfer RequestXfer, /// AbortXfer AbortXfer, /// RequestAvatarInfo RequestAvatarInfo, /// AvatarAppearance AvatarAppearance, /// SetFollowCamProperties SetFollowCamProperties, /// ClearFollowCamProperties ClearFollowCamProperties, /// RequestPayPrice RequestPayPrice, /// PayPriceReply PayPriceReply, /// KickUser KickUser, /// KickUserAck KickUserAck, /// GodKickUser GodKickUser, /// SystemKickUser SystemKickUser, /// EjectUser EjectUser, /// FreezeUser FreezeUser, /// AvatarPropertiesRequest AvatarPropertiesRequest, /// AvatarPropertiesRequestBackend AvatarPropertiesRequestBackend, /// AvatarPropertiesReply AvatarPropertiesReply, /// AvatarInterestsReply AvatarInterestsReply, /// AvatarGroupsReply AvatarGroupsReply, /// AvatarPropertiesUpdate AvatarPropertiesUpdate, /// AvatarInterestsUpdate AvatarInterestsUpdate, /// AvatarStatisticsReply AvatarStatisticsReply, /// AvatarNotesReply AvatarNotesReply, /// AvatarNotesUpdate AvatarNotesUpdate, /// AvatarPicksReply AvatarPicksReply, /// EventInfoRequest EventInfoRequest, /// EventInfoReply EventInfoReply, /// EventNotificationAddRequest EventNotificationAddRequest, /// EventNotificationRemoveRequest EventNotificationRemoveRequest, /// EventGodDelete EventGodDelete, /// PickInfoRequest PickInfoRequest, /// PickInfoReply PickInfoReply, /// PickInfoUpdate PickInfoUpdate, /// PickDelete PickDelete, /// PickGodDelete PickGodDelete, /// ScriptQuestion ScriptQuestion, /// ScriptControlChange ScriptControlChange, /// ScriptDialog ScriptDialog, /// ScriptDialogReply ScriptDialogReply, /// ForceScriptControlRelease ForceScriptControlRelease, /// RevokePermissions RevokePermissions, /// LoadURL LoadURL, /// ScriptTeleportRequest ScriptTeleportRequest, /// ParcelOverlay ParcelOverlay, /// ParcelPropertiesRequestByID ParcelPropertiesRequestByID, /// ParcelPropertiesUpdate ParcelPropertiesUpdate, /// ParcelReturnObjects ParcelReturnObjects, /// ParcelSetOtherCleanTime ParcelSetOtherCleanTime, /// ParcelDisableObjects ParcelDisableObjects, /// ParcelSelectObjects ParcelSelectObjects, /// EstateCovenantRequest EstateCovenantRequest, /// EstateCovenantReply EstateCovenantReply, /// ForceObjectSelect ForceObjectSelect, /// ParcelBuyPass ParcelBuyPass, /// ParcelDeedToGroup ParcelDeedToGroup, /// ParcelReclaim ParcelReclaim, /// ParcelClaim ParcelClaim, /// ParcelJoin ParcelJoin, /// ParcelDivide ParcelDivide, /// ParcelRelease ParcelRelease, /// ParcelBuy ParcelBuy, /// ParcelGodForceOwner ParcelGodForceOwner, /// ParcelAccessListRequest ParcelAccessListRequest, /// ParcelAccessListReply ParcelAccessListReply, /// ParcelAccessListUpdate ParcelAccessListUpdate, /// ParcelDwellRequest ParcelDwellRequest, /// ParcelDwellReply ParcelDwellReply, /// RequestParcelTransfer RequestParcelTransfer, /// UpdateParcel UpdateParcel, /// RemoveParcel RemoveParcel, /// MergeParcel MergeParcel, /// LogParcelChanges LogParcelChanges, /// CheckParcelSales CheckParcelSales, /// ParcelSales ParcelSales, /// ParcelGodMarkAsContent ParcelGodMarkAsContent, /// ParcelGodReserveForNewbie ParcelGodReserveForNewbie, /// ViewerStartAuction ViewerStartAuction, /// StartAuction StartAuction, /// ConfirmAuctionStart ConfirmAuctionStart, /// CompleteAuction CompleteAuction, /// CancelAuction CancelAuction, /// CheckParcelAuctions CheckParcelAuctions, /// ParcelAuctions ParcelAuctions, /// UUIDNameRequest UUIDNameRequest, /// UUIDNameReply UUIDNameReply, /// UUIDGroupNameRequest UUIDGroupNameRequest, /// UUIDGroupNameReply UUIDGroupNameReply, /// ChatPass ChatPass, /// ChildAgentDying ChildAgentDying, /// ChildAgentUnknown ChildAgentUnknown, /// KillChildAgents KillChildAgents, /// GetScriptRunning GetScriptRunning, /// ScriptRunningReply ScriptRunningReply, /// SetScriptRunning SetScriptRunning, /// ScriptReset ScriptReset, /// ScriptSensorRequest ScriptSensorRequest, /// ScriptSensorReply ScriptSensorReply, /// CompleteAgentMovement CompleteAgentMovement, /// AgentMovementComplete AgentMovementComplete, /// LogLogin LogLogin, /// ConnectAgentToUserserver ConnectAgentToUserserver, /// ConnectToUserserver ConnectToUserserver, /// DataServerLogout DataServerLogout, /// LogoutRequest LogoutRequest, /// FinalizeLogout FinalizeLogout, /// LogoutReply LogoutReply, /// LogoutDemand LogoutDemand, /// ImprovedInstantMessage ImprovedInstantMessage, /// RetrieveInstantMessages RetrieveInstantMessages, /// DequeueInstantMessages DequeueInstantMessages, /// FindAgent FindAgent, /// RequestGodlikePowers RequestGodlikePowers, /// GrantGodlikePowers GrantGodlikePowers, /// GodlikeMessage GodlikeMessage, /// EstateOwnerMessage EstateOwnerMessage, /// GenericMessage GenericMessage, /// MuteListRequest MuteListRequest, /// UpdateMuteListEntry UpdateMuteListEntry, /// RemoveMuteListEntry RemoveMuteListEntry, /// CopyInventoryFromNotecard CopyInventoryFromNotecard, /// UpdateInventoryItem UpdateInventoryItem, /// UpdateCreateInventoryItem UpdateCreateInventoryItem, /// MoveInventoryItem MoveInventoryItem, /// CopyInventoryItem CopyInventoryItem, /// RemoveInventoryItem RemoveInventoryItem, /// ChangeInventoryItemFlags ChangeInventoryItemFlags, /// SaveAssetIntoInventory SaveAssetIntoInventory, /// CreateInventoryFolder CreateInventoryFolder, /// UpdateInventoryFolder UpdateInventoryFolder, /// MoveInventoryFolder MoveInventoryFolder, /// RemoveInventoryFolder RemoveInventoryFolder, /// FetchInventoryDescendents FetchInventoryDescendents, /// InventoryDescendents InventoryDescendents, /// FetchInventory FetchInventory, /// FetchInventoryReply FetchInventoryReply, /// BulkUpdateInventory BulkUpdateInventory, /// RequestInventoryAsset RequestInventoryAsset, /// InventoryAssetResponse InventoryAssetResponse, /// RemoveInventoryObjects RemoveInventoryObjects, /// PurgeInventoryDescendents PurgeInventoryDescendents, /// UpdateTaskInventory UpdateTaskInventory, /// RemoveTaskInventory RemoveTaskInventory, /// MoveTaskInventory MoveTaskInventory, /// RequestTaskInventory RequestTaskInventory, /// ReplyTaskInventory ReplyTaskInventory, /// DeRezObject DeRezObject, /// DeRezAck DeRezAck, /// RezObject RezObject, /// RezObjectFromNotecard RezObjectFromNotecard, /// DeclineInventory DeclineInventory, /// TransferInventory TransferInventory, /// TransferInventoryAck TransferInventoryAck, /// RequestFriendship RequestFriendship, /// AcceptFriendship AcceptFriendship, /// DeclineFriendship DeclineFriendship, /// FormFriendship FormFriendship, /// TerminateFriendship TerminateFriendship, /// OfferCallingCard OfferCallingCard, /// AcceptCallingCard AcceptCallingCard, /// DeclineCallingCard DeclineCallingCard, /// RezScript RezScript, /// CreateInventoryItem CreateInventoryItem, /// CreateLandmarkForEvent CreateLandmarkForEvent, /// EventLocationRequest EventLocationRequest, /// EventLocationReply EventLocationReply, /// RegionHandleRequest RegionHandleRequest, /// RegionIDAndHandleReply RegionIDAndHandleReply, /// MoneyTransferRequest MoneyTransferRequest, /// MoneyTransferBackend MoneyTransferBackend, /// BulkMoneyTransfer BulkMoneyTransfer, /// AdjustBalance AdjustBalance, /// MoneyBalanceRequest MoneyBalanceRequest, /// MoneyBalanceReply MoneyBalanceReply, /// RoutedMoneyBalanceReply RoutedMoneyBalanceReply, /// MoneyHistoryRequest MoneyHistoryRequest, /// MoneyHistoryReply MoneyHistoryReply, /// MoneySummaryRequest MoneySummaryRequest, /// MoneySummaryReply MoneySummaryReply, /// MoneyDetailsRequest MoneyDetailsRequest, /// MoneyDetailsReply MoneyDetailsReply, /// MoneyTransactionsRequest MoneyTransactionsRequest, /// MoneyTransactionsReply MoneyTransactionsReply, /// GestureRequest GestureRequest, /// ActivateGestures ActivateGestures, /// DeactivateGestures DeactivateGestures, /// InventoryUpdate InventoryUpdate, /// MuteListUpdate MuteListUpdate, /// UseCachedMuteList UseCachedMuteList, /// UserLoginLocationReply UserLoginLocationReply, /// UserSimLocationReply UserSimLocationReply, /// UserListReply UserListReply, /// OnlineNotification OnlineNotification, /// OfflineNotification OfflineNotification, /// SetStartLocationRequest SetStartLocationRequest, /// SetStartLocation SetStartLocation, /// UserLoginLocationRequest UserLoginLocationRequest, /// SpaceLoginLocationReply SpaceLoginLocationReply, /// NetTest NetTest, /// SetCPURatio SetCPURatio, /// SimCrashed SimCrashed, /// SimulatorPauseState SimulatorPauseState, /// SimulatorThrottleSettings SimulatorThrottleSettings, /// NameValuePair NameValuePair, /// RemoveNameValuePair RemoveNameValuePair, /// GetNameValuePair GetNameValuePair, /// UpdateAttachment UpdateAttachment, /// RemoveAttachment RemoveAttachment, /// AssetUploadRequest AssetUploadRequest, /// AssetUploadComplete AssetUploadComplete, /// ReputationAgentAssign ReputationAgentAssign, /// ReputationIndividualRequest ReputationIndividualRequest, /// ReputationIndividualReply ReputationIndividualReply, /// EmailMessageRequest EmailMessageRequest, /// EmailMessageReply EmailMessageReply, /// ScriptDataRequest ScriptDataRequest, /// ScriptDataReply ScriptDataReply, /// CreateGroupRequest CreateGroupRequest, /// CreateGroupReply CreateGroupReply, /// UpdateGroupInfo UpdateGroupInfo, /// GroupRoleChanges GroupRoleChanges, /// JoinGroupRequest JoinGroupRequest, /// JoinGroupReply JoinGroupReply, /// EjectGroupMemberRequest EjectGroupMemberRequest, /// EjectGroupMemberReply EjectGroupMemberReply, /// LeaveGroupRequest LeaveGroupRequest, /// LeaveGroupReply LeaveGroupReply, /// InviteGroupRequest InviteGroupRequest, /// InviteGroupResponse InviteGroupResponse, /// GroupProfileRequest GroupProfileRequest, /// GroupProfileReply GroupProfileReply, /// GroupAccountSummaryRequest GroupAccountSummaryRequest, /// GroupAccountSummaryReply GroupAccountSummaryReply, /// GroupAccountDetailsRequest GroupAccountDetailsRequest, /// GroupAccountDetailsReply GroupAccountDetailsReply, /// GroupAccountTransactionsRequest GroupAccountTransactionsRequest, /// GroupAccountTransactionsReply GroupAccountTransactionsReply, /// GroupActiveProposalsRequest GroupActiveProposalsRequest, /// GroupActiveProposalItemReply GroupActiveProposalItemReply, /// GroupVoteHistoryRequest GroupVoteHistoryRequest, /// GroupVoteHistoryItemReply GroupVoteHistoryItemReply, /// StartGroupProposal StartGroupProposal, /// GroupProposalBallot GroupProposalBallot, /// TallyVotes TallyVotes, /// GroupMembersRequest GroupMembersRequest, /// GroupMembersReply GroupMembersReply, /// ActivateGroup ActivateGroup, /// SetGroupContribution SetGroupContribution, /// SetGroupAcceptNotices SetGroupAcceptNotices, /// GroupRoleDataRequest GroupRoleDataRequest, /// GroupRoleDataReply GroupRoleDataReply, /// GroupRoleMembersRequest GroupRoleMembersRequest, /// GroupRoleMembersReply GroupRoleMembersReply, /// GroupTitlesRequest GroupTitlesRequest, /// GroupTitlesReply GroupTitlesReply, /// GroupTitleUpdate GroupTitleUpdate, /// GroupRoleUpdate GroupRoleUpdate, /// LiveHelpGroupRequest LiveHelpGroupRequest, /// LiveHelpGroupReply LiveHelpGroupReply, /// AgentWearablesRequest AgentWearablesRequest, /// AgentWearablesUpdate AgentWearablesUpdate, /// AgentIsNowWearing AgentIsNowWearing, /// AgentCachedTexture AgentCachedTexture, /// AgentCachedTextureResponse AgentCachedTextureResponse, /// AgentDataUpdateRequest AgentDataUpdateRequest, /// AgentDataUpdate AgentDataUpdate, /// GroupDataUpdate GroupDataUpdate, /// AgentGroupDataUpdate AgentGroupDataUpdate, /// AgentDropGroup AgentDropGroup, /// LogTextMessage LogTextMessage, /// CreateTrustedCircuit CreateTrustedCircuit, /// DenyTrustedCircuit DenyTrustedCircuit, /// RezSingleAttachmentFromInv RezSingleAttachmentFromInv, /// RezMultipleAttachmentsFromInv RezMultipleAttachmentsFromInv, /// DetachAttachmentIntoInv DetachAttachmentIntoInv, /// CreateNewOutfitAttachments CreateNewOutfitAttachments, /// UserInfoRequest UserInfoRequest, /// UserInfoReply UserInfoReply, /// UpdateUserInfo UpdateUserInfo, /// GodExpungeUser GodExpungeUser, /// StartExpungeProcess StartExpungeProcess, /// StartExpungeProcessAck StartExpungeProcessAck, /// StartParcelRename StartParcelRename, /// StartParcelRenameAck StartParcelRenameAck, /// BulkParcelRename BulkParcelRename, /// ParcelRename ParcelRename, /// StartParcelRemove StartParcelRemove, /// StartParcelRemoveAck StartParcelRemoveAck, /// BulkParcelRemove BulkParcelRemove, /// InitiateUpload InitiateUpload, /// InitiateDownload InitiateDownload, /// SystemMessage SystemMessage, /// MapLayerRequest MapLayerRequest, /// MapLayerReply MapLayerReply, /// MapBlockRequest MapBlockRequest, /// MapNameRequest MapNameRequest, /// MapBlockReply MapBlockReply, /// MapItemRequest MapItemRequest, /// MapItemReply MapItemReply, /// SendPostcard SendPostcard, /// RpcChannelRequest RpcChannelRequest, /// RpcChannelReply RpcChannelReply, /// RpcScriptRequestInbound RpcScriptRequestInbound, /// RpcScriptRequestInboundForward RpcScriptRequestInboundForward, /// RpcScriptReplyInbound RpcScriptReplyInbound, /// MailTaskSimRequest MailTaskSimRequest, /// MailTaskSimReply MailTaskSimReply, /// ScriptMailRegistration ScriptMailRegistration, /// ParcelMediaCommandMessage ParcelMediaCommandMessage, /// ParcelMediaUpdate ParcelMediaUpdate, /// LandStatRequest LandStatRequest, /// LandStatReply LandStatReply, /// SecuredTemplateChecksumRequest SecuredTemplateChecksumRequest, /// PacketAck PacketAck, /// OpenCircuit OpenCircuit, /// CloseCircuit CloseCircuit, /// TemplateChecksumRequest TemplateChecksumRequest, /// TemplateChecksumReply TemplateChecksumReply, /// ClosestSimulator ClosestSimulator, /// ObjectAdd ObjectAdd, /// MultipleObjectUpdate MultipleObjectUpdate, /// RequestMultipleObjects RequestMultipleObjects, /// ObjectPosition ObjectPosition, /// RequestObjectPropertiesFamily RequestObjectPropertiesFamily, /// CoarseLocationUpdate CoarseLocationUpdate, /// CrossedRegion CrossedRegion, /// ConfirmEnableSimulator ConfirmEnableSimulator, /// ObjectProperties ObjectProperties, /// ObjectPropertiesFamily ObjectPropertiesFamily, /// ParcelPropertiesRequest ParcelPropertiesRequest, /// SimStatus SimStatus, /// GestureUpdate GestureUpdate, /// AttachedSound AttachedSound, /// AttachedSoundGainChange AttachedSoundGainChange, /// AttachedSoundCutoffRadius AttachedSoundCutoffRadius, /// PreloadSound PreloadSound, /// InternalScriptMail InternalScriptMail, /// ViewerEffect ViewerEffect, /// SetSunPhase SetSunPhase, /// StartPingCheck StartPingCheck, /// CompletePingCheck CompletePingCheck, /// NeighborList NeighborList, /// MovedIntoSimulator MovedIntoSimulator, /// AgentUpdate AgentUpdate, /// AgentAnimation AgentAnimation, /// AgentRequestSit AgentRequestSit, /// AgentSit AgentSit, /// RequestImage RequestImage, /// ImageData ImageData, /// ImagePacket ImagePacket, /// LayerData LayerData, /// ObjectUpdate ObjectUpdate, /// ObjectUpdateCompressed ObjectUpdateCompressed, /// ObjectUpdateCached ObjectUpdateCached, /// ImprovedTerseObjectUpdate ImprovedTerseObjectUpdate, /// KillObject KillObject, /// AgentToNewRegion AgentToNewRegion, /// TransferPacket TransferPacket, /// SendXferPacket SendXferPacket, /// ConfirmXferPacket ConfirmXferPacket, /// AvatarAnimation AvatarAnimation, /// AvatarSitResponse AvatarSitResponse, /// CameraConstraint CameraConstraint, /// ParcelProperties ParcelProperties, /// EdgeDataPacket EdgeDataPacket, /// ChildAgentUpdate ChildAgentUpdate, /// ChildAgentAlive ChildAgentAlive, /// ChildAgentPositionUpdate ChildAgentPositionUpdate, /// PassObject PassObject, /// AtomicPassObject AtomicPassObject, /// SoundTrigger SoundTrigger, } /// Base class for all packet classes public abstract class Packet { /// Either a LowHeader, MediumHeader, or HighHeader representing the first bytes of the packet public abstract Header Header { get; set; } /// The type of this packet, identified by it's frequency and ID public abstract PacketType Type { get; } /// Used internally to track timeouts, do not use public int TickCount; /// Serializes the packet in to a byte array /// A byte array containing the serialized packet payload, ready to be sent across the wire public abstract byte[] ToBytes(); /// Get the PacketType for a given packet id and packet frequency /// The packet ID from the header /// Frequency of this packet /// The packet type, or PacketType.Default public static PacketType GetType(ushort id, PacketFrequency frequency) { switch (frequency) { case PacketFrequency.Low: switch (id) { case 1: return PacketType.TestMessage; case 2: return PacketType.AddCircuitCode; case 3: return PacketType.UseCircuitCode; case 4: return PacketType.LogControl; case 5: return PacketType.RelayLogControl; case 6: return PacketType.LogMessages; case 7: return PacketType.SimulatorAssign; case 8: return PacketType.SpaceServerSimulatorTimeMessage; case 9: return PacketType.AvatarTextureUpdate; case 10: return PacketType.SimulatorMapUpdate; case 11: return PacketType.SimulatorSetMap; case 12: return PacketType.SubscribeLoad; case 13: return PacketType.UnsubscribeLoad; case 14: return PacketType.SimulatorStart; case 15: return PacketType.SimulatorReady; case 16: return PacketType.TelehubInfo; case 17: return PacketType.SimulatorPresentAtLocation; case 18: return PacketType.SimulatorLoad; case 19: return PacketType.SimulatorShutdownRequest; case 20: return PacketType.RegionPresenceRequestByRegionID; case 21: return PacketType.RegionPresenceRequestByHandle; case 22: return PacketType.RegionPresenceResponse; case 23: return PacketType.RecordAgentPresence; case 24: return PacketType.EraseAgentPresence; case 25: return PacketType.AgentPresenceRequest; case 26: return PacketType.AgentPresenceResponse; case 27: return PacketType.UpdateSimulator; case 28: return PacketType.TrackAgentSession; case 29: return PacketType.ClearAgentSessions; case 30: return PacketType.LogDwellTime; case 31: return PacketType.FeatureDisabled; case 32: return PacketType.LogFailedMoneyTransaction; case 33: return PacketType.UserReportInternal; case 34: return PacketType.SetSimStatusInDatabase; case 35: return PacketType.SetSimPresenceInDatabase; case 36: return PacketType.EconomyDataRequest; case 37: return PacketType.EconomyData; case 38: return PacketType.AvatarPickerRequest; case 39: return PacketType.AvatarPickerRequestBackend; case 40: return PacketType.AvatarPickerReply; case 41: return PacketType.PlacesQuery; case 42: return PacketType.PlacesReply; case 43: return PacketType.DirFindQuery; case 44: return PacketType.DirFindQueryBackend; case 45: return PacketType.DirPlacesQuery; case 46: return PacketType.DirPlacesQueryBackend; case 47: return PacketType.DirPlacesReply; case 48: return PacketType.DirPeopleQuery; case 49: return PacketType.DirPeopleQueryBackend; case 50: return PacketType.DirPeopleReply; case 51: return PacketType.DirEventsReply; case 52: return PacketType.DirGroupsQuery; case 53: return PacketType.DirGroupsQueryBackend; case 54: return PacketType.DirGroupsReply; case 55: return PacketType.DirClassifiedQuery; case 56: return PacketType.DirClassifiedQueryBackend; case 57: return PacketType.DirClassifiedReply; case 58: return PacketType.AvatarClassifiedReply; case 59: return PacketType.ClassifiedInfoRequest; case 60: return PacketType.ClassifiedInfoReply; case 61: return PacketType.ClassifiedInfoUpdate; case 62: return PacketType.ClassifiedDelete; case 63: return PacketType.ClassifiedGodDelete; case 64: return PacketType.DirPicksQuery; case 65: return PacketType.DirPicksQueryBackend; case 66: return PacketType.DirPicksReply; case 67: return PacketType.DirLandQuery; case 68: return PacketType.DirLandQueryBackend; case 69: return PacketType.DirLandReply; case 70: return PacketType.DirPopularQuery; case 71: return PacketType.DirPopularQueryBackend; case 72: return PacketType.DirPopularReply; case 73: return PacketType.ParcelInfoRequest; case 74: return PacketType.ParcelInfoReply; case 75: return PacketType.ParcelObjectOwnersRequest; case 76: return PacketType.OnlineStatusRequest; case 77: return PacketType.OnlineStatusReply; case 78: return PacketType.ParcelObjectOwnersReply; case 79: return PacketType.GroupNoticesListRequest; case 80: return PacketType.GroupNoticesListReply; case 81: return PacketType.GroupNoticeRequest; case 82: return PacketType.GroupNoticeAdd; case 83: return PacketType.GroupNoticeDelete; case 84: return PacketType.TeleportRequest; case 85: return PacketType.TeleportLocationRequest; case 86: return PacketType.TeleportLocal; case 87: return PacketType.TeleportLandmarkRequest; case 88: return PacketType.TeleportProgress; case 89: return PacketType.DataAgentAccessRequest; case 90: return PacketType.DataAgentAccessReply; case 91: return PacketType.DataHomeLocationRequest; case 92: return PacketType.DataHomeLocationReply; case 93: return PacketType.SpaceLocationTeleportRequest; case 94: return PacketType.SpaceLocationTeleportReply; case 95: return PacketType.TeleportFinish; case 96: return PacketType.StartLure; case 97: return PacketType.TeleportLureRequest; case 98: return PacketType.TeleportCancel; case 99: return PacketType.CompleteLure; case 100: return PacketType.TeleportStart; case 101: return PacketType.TeleportFailed; case 102: return PacketType.LeaderBoardRequest; case 103: return PacketType.LeaderBoardData; case 104: return PacketType.RegisterNewAgent; case 105: return PacketType.Undo; case 106: return PacketType.Redo; case 107: return PacketType.UndoLand; case 108: return PacketType.RedoLand; case 109: return PacketType.AgentPause; case 110: return PacketType.AgentResume; case 111: return PacketType.ChatFromViewer; case 112: return PacketType.AgentThrottle; case 113: return PacketType.AgentFOV; case 114: return PacketType.AgentHeightWidth; case 115: return PacketType.AgentSetAppearance; case 116: return PacketType.AgentQuit; case 117: return PacketType.AgentQuitCopy; case 118: return PacketType.ImageNotInDatabase; case 119: return PacketType.RebakeAvatarTextures; case 120: return PacketType.SetAlwaysRun; case 121: return PacketType.ObjectDelete; case 122: return PacketType.ObjectDuplicate; case 123: return PacketType.ObjectDuplicateOnRay; case 124: return PacketType.ObjectScale; case 125: return PacketType.ObjectRotation; case 126: return PacketType.ObjectFlagUpdate; case 127: return PacketType.ObjectClickAction; case 128: return PacketType.ObjectImage; case 129: return PacketType.ObjectMaterial; case 130: return PacketType.ObjectShape; case 131: return PacketType.ObjectExtraParams; case 132: return PacketType.ObjectOwner; case 133: return PacketType.ObjectGroup; case 134: return PacketType.ObjectBuy; case 135: return PacketType.BuyObjectInventory; case 136: return PacketType.DerezContainer; case 137: return PacketType.ObjectPermissions; case 138: return PacketType.ObjectSaleInfo; case 139: return PacketType.ObjectName; case 140: return PacketType.ObjectDescription; case 141: return PacketType.ObjectCategory; case 142: return PacketType.ObjectSelect; case 143: return PacketType.ObjectDeselect; case 144: return PacketType.ObjectAttach; case 145: return PacketType.ObjectDetach; case 146: return PacketType.ObjectDrop; case 147: return PacketType.ObjectLink; case 148: return PacketType.ObjectDelink; case 149: return PacketType.ObjectHinge; case 150: return PacketType.ObjectDehinge; case 151: return PacketType.ObjectGrab; case 152: return PacketType.ObjectGrabUpdate; case 153: return PacketType.ObjectDeGrab; case 154: return PacketType.ObjectSpinStart; case 155: return PacketType.ObjectSpinUpdate; case 156: return PacketType.ObjectSpinStop; case 157: return PacketType.ObjectExportSelected; case 158: return PacketType.ObjectImport; case 159: return PacketType.ModifyLand; case 160: return PacketType.VelocityInterpolateOn; case 161: return PacketType.VelocityInterpolateOff; case 162: return PacketType.StateSave; case 163: return PacketType.ReportAutosaveCrash; case 164: return PacketType.SimWideDeletes; case 165: return PacketType.TrackAgent; case 166: return PacketType.GrantModification; case 167: return PacketType.RevokeModification; case 168: return PacketType.RequestGrantedProxies; case 169: return PacketType.GrantedProxies; case 170: return PacketType.AddModifyAbility; case 171: return PacketType.RemoveModifyAbility; case 172: return PacketType.ViewerStats; case 173: return PacketType.ScriptAnswerYes; case 174: return PacketType.UserReport; case 175: return PacketType.AlertMessage; case 176: return PacketType.AgentAlertMessage; case 177: return PacketType.MeanCollisionAlert; case 178: return PacketType.ViewerFrozenMessage; case 179: return PacketType.HealthMessage; case 180: return PacketType.ChatFromSimulator; case 181: return PacketType.SimStats; case 182: return PacketType.RequestRegionInfo; case 183: return PacketType.RegionInfo; case 184: return PacketType.GodUpdateRegionInfo; case 185: return PacketType.NearestLandingRegionRequest; case 186: return PacketType.NearestLandingRegionReply; case 187: return PacketType.NearestLandingRegionUpdated; case 188: return PacketType.TeleportLandingStatusChanged; case 189: return PacketType.RegionHandshake; case 190: return PacketType.RegionHandshakeReply; case 191: return PacketType.SimulatorViewerTimeMessage; case 192: return PacketType.EnableSimulator; case 193: return PacketType.DisableSimulator; case 194: return PacketType.TransferRequest; case 195: return PacketType.TransferInfo; case 196: return PacketType.TransferAbort; case 197: return PacketType.TransferPriority; case 198: return PacketType.RequestXfer; case 199: return PacketType.AbortXfer; case 200: return PacketType.RequestAvatarInfo; case 201: return PacketType.AvatarAppearance; case 202: return PacketType.SetFollowCamProperties; case 203: return PacketType.ClearFollowCamProperties; case 204: return PacketType.RequestPayPrice; case 205: return PacketType.PayPriceReply; case 206: return PacketType.KickUser; case 207: return PacketType.KickUserAck; case 208: return PacketType.GodKickUser; case 209: return PacketType.SystemKickUser; case 210: return PacketType.EjectUser; case 211: return PacketType.FreezeUser; case 212: return PacketType.AvatarPropertiesRequest; case 213: return PacketType.AvatarPropertiesRequestBackend; case 214: return PacketType.AvatarPropertiesReply; case 215: return PacketType.AvatarInterestsReply; case 216: return PacketType.AvatarGroupsReply; case 217: return PacketType.AvatarPropertiesUpdate; case 218: return PacketType.AvatarInterestsUpdate; case 219: return PacketType.AvatarStatisticsReply; case 220: return PacketType.AvatarNotesReply; case 221: return PacketType.AvatarNotesUpdate; case 222: return PacketType.AvatarPicksReply; case 223: return PacketType.EventInfoRequest; case 224: return PacketType.EventInfoReply; case 225: return PacketType.EventNotificationAddRequest; case 226: return PacketType.EventNotificationRemoveRequest; case 227: return PacketType.EventGodDelete; case 228: return PacketType.PickInfoRequest; case 229: return PacketType.PickInfoReply; case 230: return PacketType.PickInfoUpdate; case 231: return PacketType.PickDelete; case 232: return PacketType.PickGodDelete; case 233: return PacketType.ScriptQuestion; case 234: return PacketType.ScriptControlChange; case 235: return PacketType.ScriptDialog; case 236: return PacketType.ScriptDialogReply; case 237: return PacketType.ForceScriptControlRelease; case 238: return PacketType.RevokePermissions; case 239: return PacketType.LoadURL; case 240: return PacketType.ScriptTeleportRequest; case 241: return PacketType.ParcelOverlay; case 242: return PacketType.ParcelPropertiesRequestByID; case 243: return PacketType.ParcelPropertiesUpdate; case 244: return PacketType.ParcelReturnObjects; case 245: return PacketType.ParcelSetOtherCleanTime; case 246: return PacketType.ParcelDisableObjects; case 247: return PacketType.ParcelSelectObjects; case 248: return PacketType.EstateCovenantRequest; case 249: return PacketType.EstateCovenantReply; case 250: return PacketType.ForceObjectSelect; case 251: return PacketType.ParcelBuyPass; case 252: return PacketType.ParcelDeedToGroup; case 253: return PacketType.ParcelReclaim; case 254: return PacketType.ParcelClaim; case 255: return PacketType.ParcelJoin; case 256: return PacketType.ParcelDivide; case 257: return PacketType.ParcelRelease; case 258: return PacketType.ParcelBuy; case 259: return PacketType.ParcelGodForceOwner; case 260: return PacketType.ParcelAccessListRequest; case 261: return PacketType.ParcelAccessListReply; case 262: return PacketType.ParcelAccessListUpdate; case 263: return PacketType.ParcelDwellRequest; case 264: return PacketType.ParcelDwellReply; case 265: return PacketType.RequestParcelTransfer; case 266: return PacketType.UpdateParcel; case 267: return PacketType.RemoveParcel; case 268: return PacketType.MergeParcel; case 269: return PacketType.LogParcelChanges; case 270: return PacketType.CheckParcelSales; case 271: return PacketType.ParcelSales; case 272: return PacketType.ParcelGodMarkAsContent; case 273: return PacketType.ParcelGodReserveForNewbie; case 274: return PacketType.ViewerStartAuction; case 275: return PacketType.StartAuction; case 276: return PacketType.ConfirmAuctionStart; case 277: return PacketType.CompleteAuction; case 278: return PacketType.CancelAuction; case 279: return PacketType.CheckParcelAuctions; case 280: return PacketType.ParcelAuctions; case 281: return PacketType.UUIDNameRequest; case 282: return PacketType.UUIDNameReply; case 283: return PacketType.UUIDGroupNameRequest; case 284: return PacketType.UUIDGroupNameReply; case 285: return PacketType.ChatPass; case 286: return PacketType.ChildAgentDying; case 287: return PacketType.ChildAgentUnknown; case 288: return PacketType.KillChildAgents; case 289: return PacketType.GetScriptRunning; case 290: return PacketType.ScriptRunningReply; case 291: return PacketType.SetScriptRunning; case 292: return PacketType.ScriptReset; case 293: return PacketType.ScriptSensorRequest; case 294: return PacketType.ScriptSensorReply; case 295: return PacketType.CompleteAgentMovement; case 296: return PacketType.AgentMovementComplete; case 297: return PacketType.LogLogin; case 298: return PacketType.ConnectAgentToUserserver; case 299: return PacketType.ConnectToUserserver; case 300: return PacketType.DataServerLogout; case 301: return PacketType.LogoutRequest; case 302: return PacketType.FinalizeLogout; case 303: return PacketType.LogoutReply; case 304: return PacketType.LogoutDemand; case 305: return PacketType.ImprovedInstantMessage; case 306: return PacketType.RetrieveInstantMessages; case 307: return PacketType.DequeueInstantMessages; case 308: return PacketType.FindAgent; case 309: return PacketType.RequestGodlikePowers; case 310: return PacketType.GrantGodlikePowers; case 311: return PacketType.GodlikeMessage; case 312: return PacketType.EstateOwnerMessage; case 313: return PacketType.GenericMessage; case 314: return PacketType.MuteListRequest; case 315: return PacketType.UpdateMuteListEntry; case 316: return PacketType.RemoveMuteListEntry; case 317: return PacketType.CopyInventoryFromNotecard; case 318: return PacketType.UpdateInventoryItem; case 319: return PacketType.UpdateCreateInventoryItem; case 320: return PacketType.MoveInventoryItem; case 321: return PacketType.CopyInventoryItem; case 322: return PacketType.RemoveInventoryItem; case 323: return PacketType.ChangeInventoryItemFlags; case 324: return PacketType.SaveAssetIntoInventory; case 325: return PacketType.CreateInventoryFolder; case 326: return PacketType.UpdateInventoryFolder; case 327: return PacketType.MoveInventoryFolder; case 328: return PacketType.RemoveInventoryFolder; case 329: return PacketType.FetchInventoryDescendents; case 330: return PacketType.InventoryDescendents; case 331: return PacketType.FetchInventory; case 332: return PacketType.FetchInventoryReply; case 333: return PacketType.BulkUpdateInventory; case 334: return PacketType.RequestInventoryAsset; case 335: return PacketType.InventoryAssetResponse; case 336: return PacketType.RemoveInventoryObjects; case 337: return PacketType.PurgeInventoryDescendents; case 338: return PacketType.UpdateTaskInventory; case 339: return PacketType.RemoveTaskInventory; case 340: return PacketType.MoveTaskInventory; case 341: return PacketType.RequestTaskInventory; case 342: return PacketType.ReplyTaskInventory; case 343: return PacketType.DeRezObject; case 344: return PacketType.DeRezAck; case 345: return PacketType.RezObject; case 346: return PacketType.RezObjectFromNotecard; case 347: return PacketType.DeclineInventory; case 348: return PacketType.TransferInventory; case 349: return PacketType.TransferInventoryAck; case 350: return PacketType.RequestFriendship; case 351: return PacketType.AcceptFriendship; case 352: return PacketType.DeclineFriendship; case 353: return PacketType.FormFriendship; case 354: return PacketType.TerminateFriendship; case 355: return PacketType.OfferCallingCard; case 356: return PacketType.AcceptCallingCard; case 357: return PacketType.DeclineCallingCard; case 358: return PacketType.RezScript; case 359: return PacketType.CreateInventoryItem; case 360: return PacketType.CreateLandmarkForEvent; case 361: return PacketType.EventLocationRequest; case 362: return PacketType.EventLocationReply; case 363: return PacketType.RegionHandleRequest; case 364: return PacketType.RegionIDAndHandleReply; case 365: return PacketType.MoneyTransferRequest; case 366: return PacketType.MoneyTransferBackend; case 367: return PacketType.BulkMoneyTransfer; case 368: return PacketType.AdjustBalance; case 369: return PacketType.MoneyBalanceRequest; case 370: return PacketType.MoneyBalanceReply; case 371: return PacketType.RoutedMoneyBalanceReply; case 372: return PacketType.MoneyHistoryRequest; case 373: return PacketType.MoneyHistoryReply; case 374: return PacketType.MoneySummaryRequest; case 375: return PacketType.MoneySummaryReply; case 376: return PacketType.MoneyDetailsRequest; case 377: return PacketType.MoneyDetailsReply; case 378: return PacketType.MoneyTransactionsRequest; case 379: return PacketType.MoneyTransactionsReply; case 380: return PacketType.GestureRequest; case 381: return PacketType.ActivateGestures; case 382: return PacketType.DeactivateGestures; case 383: return PacketType.InventoryUpdate; case 384: return PacketType.MuteListUpdate; case 385: return PacketType.UseCachedMuteList; case 386: return PacketType.UserLoginLocationReply; case 387: return PacketType.UserSimLocationReply; case 388: return PacketType.UserListReply; case 389: return PacketType.OnlineNotification; case 390: return PacketType.OfflineNotification; case 391: return PacketType.SetStartLocationRequest; case 392: return PacketType.SetStartLocation; case 393: return PacketType.UserLoginLocationRequest; case 394: return PacketType.SpaceLoginLocationReply; case 395: return PacketType.NetTest; case 396: return PacketType.SetCPURatio; case 397: return PacketType.SimCrashed; case 398: return PacketType.SimulatorPauseState; case 399: return PacketType.SimulatorThrottleSettings; case 400: return PacketType.NameValuePair; case 401: return PacketType.RemoveNameValuePair; case 402: return PacketType.GetNameValuePair; case 403: return PacketType.UpdateAttachment; case 404: return PacketType.RemoveAttachment; case 405: return PacketType.AssetUploadRequest; case 406: return PacketType.AssetUploadComplete; case 407: return PacketType.ReputationAgentAssign; case 408: return PacketType.ReputationIndividualRequest; case 409: return PacketType.ReputationIndividualReply; case 410: return PacketType.EmailMessageRequest; case 411: return PacketType.EmailMessageReply; case 412: return PacketType.ScriptDataRequest; case 413: return PacketType.ScriptDataReply; case 414: return PacketType.CreateGroupRequest; case 415: return PacketType.CreateGroupReply; case 416: return PacketType.UpdateGroupInfo; case 417: return PacketType.GroupRoleChanges; case 418: return PacketType.JoinGroupRequest; case 419: return PacketType.JoinGroupReply; case 420: return PacketType.EjectGroupMemberRequest; case 421: return PacketType.EjectGroupMemberReply; case 422: return PacketType.LeaveGroupRequest; case 423: return PacketType.LeaveGroupReply; case 424: return PacketType.InviteGroupRequest; case 425: return PacketType.InviteGroupResponse; case 426: return PacketType.GroupProfileRequest; case 427: return PacketType.GroupProfileReply; case 428: return PacketType.GroupAccountSummaryRequest; case 429: return PacketType.GroupAccountSummaryReply; case 430: return PacketType.GroupAccountDetailsRequest; case 431: return PacketType.GroupAccountDetailsReply; case 432: return PacketType.GroupAccountTransactionsRequest; case 433: return PacketType.GroupAccountTransactionsReply; case 434: return PacketType.GroupActiveProposalsRequest; case 435: return PacketType.GroupActiveProposalItemReply; case 436: return PacketType.GroupVoteHistoryRequest; case 437: return PacketType.GroupVoteHistoryItemReply; case 438: return PacketType.StartGroupProposal; case 439: return PacketType.GroupProposalBallot; case 440: return PacketType.TallyVotes; case 441: return PacketType.GroupMembersRequest; case 442: return PacketType.GroupMembersReply; case 443: return PacketType.ActivateGroup; case 444: return PacketType.SetGroupContribution; case 445: return PacketType.SetGroupAcceptNotices; case 446: return PacketType.GroupRoleDataRequest; case 447: return PacketType.GroupRoleDataReply; case 448: return PacketType.GroupRoleMembersRequest; case 449: return PacketType.GroupRoleMembersReply; case 450: return PacketType.GroupTitlesRequest; case 451: return PacketType.GroupTitlesReply; case 452: return PacketType.GroupTitleUpdate; case 453: return PacketType.GroupRoleUpdate; case 454: return PacketType.LiveHelpGroupRequest; case 455: return PacketType.LiveHelpGroupReply; case 456: return PacketType.AgentWearablesRequest; case 457: return PacketType.AgentWearablesUpdate; case 458: return PacketType.AgentIsNowWearing; case 459: return PacketType.AgentCachedTexture; case 460: return PacketType.AgentCachedTextureResponse; case 461: return PacketType.AgentDataUpdateRequest; case 462: return PacketType.AgentDataUpdate; case 463: return PacketType.GroupDataUpdate; case 464: return PacketType.AgentGroupDataUpdate; case 465: return PacketType.AgentDropGroup; case 466: return PacketType.LogTextMessage; case 467: return PacketType.CreateTrustedCircuit; case 468: return PacketType.DenyTrustedCircuit; case 469: return PacketType.RezSingleAttachmentFromInv; case 470: return PacketType.RezMultipleAttachmentsFromInv; case 471: return PacketType.DetachAttachmentIntoInv; case 472: return PacketType.CreateNewOutfitAttachments; case 473: return PacketType.UserInfoRequest; case 474: return PacketType.UserInfoReply; case 475: return PacketType.UpdateUserInfo; case 476: return PacketType.GodExpungeUser; case 477: return PacketType.StartExpungeProcess; case 478: return PacketType.StartExpungeProcessAck; case 479: return PacketType.StartParcelRename; case 480: return PacketType.StartParcelRenameAck; case 481: return PacketType.BulkParcelRename; case 482: return PacketType.ParcelRename; case 483: return PacketType.StartParcelRemove; case 484: return PacketType.StartParcelRemoveAck; case 485: return PacketType.BulkParcelRemove; case 486: return PacketType.InitiateUpload; case 487: return PacketType.InitiateDownload; case 488: return PacketType.SystemMessage; case 489: return PacketType.MapLayerRequest; case 490: return PacketType.MapLayerReply; case 491: return PacketType.MapBlockRequest; case 492: return PacketType.MapNameRequest; case 493: return PacketType.MapBlockReply; case 494: return PacketType.MapItemRequest; case 495: return PacketType.MapItemReply; case 496: return PacketType.SendPostcard; case 497: return PacketType.RpcChannelRequest; case 498: return PacketType.RpcChannelReply; case 499: return PacketType.RpcScriptRequestInbound; case 500: return PacketType.RpcScriptRequestInboundForward; case 501: return PacketType.RpcScriptReplyInbound; case 502: return PacketType.MailTaskSimRequest; case 503: return PacketType.MailTaskSimReply; case 504: return PacketType.ScriptMailRegistration; case 505: return PacketType.ParcelMediaCommandMessage; case 506: return PacketType.ParcelMediaUpdate; case 507: return PacketType.LandStatRequest; case 508: return PacketType.LandStatReply; case 65530: return PacketType.SecuredTemplateChecksumRequest; case 65531: return PacketType.PacketAck; case 65532: return PacketType.OpenCircuit; case 65533: return PacketType.CloseCircuit; case 65534: return PacketType.TemplateChecksumRequest; case 65535: return PacketType.TemplateChecksumReply; } break; case PacketFrequency.Medium: switch (id) { case 1: return PacketType.ClosestSimulator; case 2: return PacketType.ObjectAdd; case 3: return PacketType.MultipleObjectUpdate; case 4: return PacketType.RequestMultipleObjects; case 5: return PacketType.ObjectPosition; case 6: return PacketType.RequestObjectPropertiesFamily; case 7: return PacketType.CoarseLocationUpdate; case 8: return PacketType.CrossedRegion; case 9: return PacketType.ConfirmEnableSimulator; case 10: return PacketType.ObjectProperties; case 11: return PacketType.ObjectPropertiesFamily; case 12: return PacketType.ParcelPropertiesRequest; case 13: return PacketType.SimStatus; case 14: return PacketType.GestureUpdate; case 15: return PacketType.AttachedSound; case 16: return PacketType.AttachedSoundGainChange; case 17: return PacketType.AttachedSoundCutoffRadius; case 18: return PacketType.PreloadSound; case 19: return PacketType.InternalScriptMail; case 20: return PacketType.ViewerEffect; case 21: return PacketType.SetSunPhase; } break; case PacketFrequency.High: switch (id) { case 1: return PacketType.StartPingCheck; case 2: return PacketType.CompletePingCheck; case 3: return PacketType.NeighborList; case 4: return PacketType.MovedIntoSimulator; case 5: return PacketType.AgentUpdate; case 6: return PacketType.AgentAnimation; case 7: return PacketType.AgentRequestSit; case 8: return PacketType.AgentSit; case 9: return PacketType.RequestImage; case 10: return PacketType.ImageData; case 11: return PacketType.ImagePacket; case 12: return PacketType.LayerData; case 13: return PacketType.ObjectUpdate; case 14: return PacketType.ObjectUpdateCompressed; case 15: return PacketType.ObjectUpdateCached; case 16: return PacketType.ImprovedTerseObjectUpdate; case 17: return PacketType.KillObject; case 18: return PacketType.AgentToNewRegion; case 19: return PacketType.TransferPacket; case 20: return PacketType.SendXferPacket; case 21: return PacketType.ConfirmXferPacket; case 22: return PacketType.AvatarAnimation; case 23: return PacketType.AvatarSitResponse; case 24: return PacketType.CameraConstraint; case 25: return PacketType.ParcelProperties; case 26: return PacketType.EdgeDataPacket; case 27: return PacketType.ChildAgentUpdate; case 28: return PacketType.ChildAgentAlive; case 29: return PacketType.ChildAgentPositionUpdate; case 30: return PacketType.PassObject; case 31: return PacketType.AtomicPassObject; case 32: return PacketType.SoundTrigger; } break; } return PacketType.Default; } /// Construct a packet in it's native class from a byte array /// Byte array containing the packet, starting at position 0 /// The last byte of the packet. If the packet was 76 bytes long, packetEnd would be 75 /// The native packet class for this type of packet, typecasted to the generic Packet public static Packet BuildPacket(byte[] bytes, ref int packetEnd) { ushort id; int i = 0; Header header = Header.BuildHeader(bytes, ref i, ref packetEnd); if (header.Zerocoded) { byte[] zeroBuffer = new byte[8192]; packetEnd = Helpers.ZeroDecode(bytes, packetEnd + 1, zeroBuffer) - 1; bytes = zeroBuffer; } if (bytes[4] == 0xFF) { if (bytes[5] == 0xFF) { id = (ushort)((bytes[6] << 8) + bytes[7]); switch (id) { case 1: return new TestMessagePacket(header, bytes, ref i); case 2: return new AddCircuitCodePacket(header, bytes, ref i); case 3: return new UseCircuitCodePacket(header, bytes, ref i); case 4: return new LogControlPacket(header, bytes, ref i); case 5: return new RelayLogControlPacket(header, bytes, ref i); case 6: return new LogMessagesPacket(header, bytes, ref i); case 7: return new SimulatorAssignPacket(header, bytes, ref i); case 8: return new SpaceServerSimulatorTimeMessagePacket(header, bytes, ref i); case 9: return new AvatarTextureUpdatePacket(header, bytes, ref i); case 10: return new SimulatorMapUpdatePacket(header, bytes, ref i); case 11: return new SimulatorSetMapPacket(header, bytes, ref i); case 12: return new SubscribeLoadPacket(header, bytes, ref i); case 13: return new UnsubscribeLoadPacket(header, bytes, ref i); case 14: return new SimulatorStartPacket(header, bytes, ref i); case 15: return new SimulatorReadyPacket(header, bytes, ref i); case 16: return new TelehubInfoPacket(header, bytes, ref i); case 17: return new SimulatorPresentAtLocationPacket(header, bytes, ref i); case 18: return new SimulatorLoadPacket(header, bytes, ref i); case 19: return new SimulatorShutdownRequestPacket(header, bytes, ref i); case 20: return new RegionPresenceRequestByRegionIDPacket(header, bytes, ref i); case 21: return new RegionPresenceRequestByHandlePacket(header, bytes, ref i); case 22: return new RegionPresenceResponsePacket(header, bytes, ref i); case 23: return new RecordAgentPresencePacket(header, bytes, ref i); case 24: return new EraseAgentPresencePacket(header, bytes, ref i); case 25: return new AgentPresenceRequestPacket(header, bytes, ref i); case 26: return new AgentPresenceResponsePacket(header, bytes, ref i); case 27: return new UpdateSimulatorPacket(header, bytes, ref i); case 28: return new TrackAgentSessionPacket(header, bytes, ref i); case 29: return new ClearAgentSessionsPacket(header, bytes, ref i); case 30: return new LogDwellTimePacket(header, bytes, ref i); case 31: return new FeatureDisabledPacket(header, bytes, ref i); case 32: return new LogFailedMoneyTransactionPacket(header, bytes, ref i); case 33: return new UserReportInternalPacket(header, bytes, ref i); case 34: return new SetSimStatusInDatabasePacket(header, bytes, ref i); case 35: return new SetSimPresenceInDatabasePacket(header, bytes, ref i); case 36: return new EconomyDataRequestPacket(header, bytes, ref i); case 37: return new EconomyDataPacket(header, bytes, ref i); case 38: return new AvatarPickerRequestPacket(header, bytes, ref i); case 39: return new AvatarPickerRequestBackendPacket(header, bytes, ref i); case 40: return new AvatarPickerReplyPacket(header, bytes, ref i); case 41: return new PlacesQueryPacket(header, bytes, ref i); case 42: return new PlacesReplyPacket(header, bytes, ref i); case 43: return new DirFindQueryPacket(header, bytes, ref i); case 44: return new DirFindQueryBackendPacket(header, bytes, ref i); case 45: return new DirPlacesQueryPacket(header, bytes, ref i); case 46: return new DirPlacesQueryBackendPacket(header, bytes, ref i); case 47: return new DirPlacesReplyPacket(header, bytes, ref i); case 48: return new DirPeopleQueryPacket(header, bytes, ref i); case 49: return new DirPeopleQueryBackendPacket(header, bytes, ref i); case 50: return new DirPeopleReplyPacket(header, bytes, ref i); case 51: return new DirEventsReplyPacket(header, bytes, ref i); case 52: return new DirGroupsQueryPacket(header, bytes, ref i); case 53: return new DirGroupsQueryBackendPacket(header, bytes, ref i); case 54: return new DirGroupsReplyPacket(header, bytes, ref i); case 55: return new DirClassifiedQueryPacket(header, bytes, ref i); case 56: return new DirClassifiedQueryBackendPacket(header, bytes, ref i); case 57: return new DirClassifiedReplyPacket(header, bytes, ref i); case 58: return new AvatarClassifiedReplyPacket(header, bytes, ref i); case 59: return new ClassifiedInfoRequestPacket(header, bytes, ref i); case 60: return new ClassifiedInfoReplyPacket(header, bytes, ref i); case 61: return new ClassifiedInfoUpdatePacket(header, bytes, ref i); case 62: return new ClassifiedDeletePacket(header, bytes, ref i); case 63: return new ClassifiedGodDeletePacket(header, bytes, ref i); case 64: return new DirPicksQueryPacket(header, bytes, ref i); case 65: return new DirPicksQueryBackendPacket(header, bytes, ref i); case 66: return new DirPicksReplyPacket(header, bytes, ref i); case 67: return new DirLandQueryPacket(header, bytes, ref i); case 68: return new DirLandQueryBackendPacket(header, bytes, ref i); case 69: return new DirLandReplyPacket(header, bytes, ref i); case 70: return new DirPopularQueryPacket(header, bytes, ref i); case 71: return new DirPopularQueryBackendPacket(header, bytes, ref i); case 72: return new DirPopularReplyPacket(header, bytes, ref i); case 73: return new ParcelInfoRequestPacket(header, bytes, ref i); case 74: return new ParcelInfoReplyPacket(header, bytes, ref i); case 75: return new ParcelObjectOwnersRequestPacket(header, bytes, ref i); case 76: return new OnlineStatusRequestPacket(header, bytes, ref i); case 77: return new OnlineStatusReplyPacket(header, bytes, ref i); case 78: return new ParcelObjectOwnersReplyPacket(header, bytes, ref i); case 79: return new GroupNoticesListRequestPacket(header, bytes, ref i); case 80: return new GroupNoticesListReplyPacket(header, bytes, ref i); case 81: return new GroupNoticeRequestPacket(header, bytes, ref i); case 82: return new GroupNoticeAddPacket(header, bytes, ref i); case 83: return new GroupNoticeDeletePacket(header, bytes, ref i); case 84: return new TeleportRequestPacket(header, bytes, ref i); case 85: return new TeleportLocationRequestPacket(header, bytes, ref i); case 86: return new TeleportLocalPacket(header, bytes, ref i); case 87: return new TeleportLandmarkRequestPacket(header, bytes, ref i); case 88: return new TeleportProgressPacket(header, bytes, ref i); case 89: return new DataAgentAccessRequestPacket(header, bytes, ref i); case 90: return new DataAgentAccessReplyPacket(header, bytes, ref i); case 91: return new DataHomeLocationRequestPacket(header, bytes, ref i); case 92: return new DataHomeLocationReplyPacket(header, bytes, ref i); case 93: return new SpaceLocationTeleportRequestPacket(header, bytes, ref i); case 94: return new SpaceLocationTeleportReplyPacket(header, bytes, ref i); case 95: return new TeleportFinishPacket(header, bytes, ref i); case 96: return new StartLurePacket(header, bytes, ref i); case 97: return new TeleportLureRequestPacket(header, bytes, ref i); case 98: return new TeleportCancelPacket(header, bytes, ref i); case 99: return new CompleteLurePacket(header, bytes, ref i); case 100: return new TeleportStartPacket(header, bytes, ref i); case 101: return new TeleportFailedPacket(header, bytes, ref i); case 102: return new LeaderBoardRequestPacket(header, bytes, ref i); case 103: return new LeaderBoardDataPacket(header, bytes, ref i); case 104: return new RegisterNewAgentPacket(header, bytes, ref i); case 105: return new UndoPacket(header, bytes, ref i); case 106: return new RedoPacket(header, bytes, ref i); case 107: return new UndoLandPacket(header, bytes, ref i); case 108: return new RedoLandPacket(header, bytes, ref i); case 109: return new AgentPausePacket(header, bytes, ref i); case 110: return new AgentResumePacket(header, bytes, ref i); case 111: return new ChatFromViewerPacket(header, bytes, ref i); case 112: return new AgentThrottlePacket(header, bytes, ref i); case 113: return new AgentFOVPacket(header, bytes, ref i); case 114: return new AgentHeightWidthPacket(header, bytes, ref i); case 115: return new AgentSetAppearancePacket(header, bytes, ref i); case 116: return new AgentQuitPacket(header, bytes, ref i); case 117: return new AgentQuitCopyPacket(header, bytes, ref i); case 118: return new ImageNotInDatabasePacket(header, bytes, ref i); case 119: return new RebakeAvatarTexturesPacket(header, bytes, ref i); case 120: return new SetAlwaysRunPacket(header, bytes, ref i); case 121: return new ObjectDeletePacket(header, bytes, ref i); case 122: return new ObjectDuplicatePacket(header, bytes, ref i); case 123: return new ObjectDuplicateOnRayPacket(header, bytes, ref i); case 124: return new ObjectScalePacket(header, bytes, ref i); case 125: return new ObjectRotationPacket(header, bytes, ref i); case 126: return new ObjectFlagUpdatePacket(header, bytes, ref i); case 127: return new ObjectClickActionPacket(header, bytes, ref i); case 128: return new ObjectImagePacket(header, bytes, ref i); case 129: return new ObjectMaterialPacket(header, bytes, ref i); case 130: return new ObjectShapePacket(header, bytes, ref i); case 131: return new ObjectExtraParamsPacket(header, bytes, ref i); case 132: return new ObjectOwnerPacket(header, bytes, ref i); case 133: return new ObjectGroupPacket(header, bytes, ref i); case 134: return new ObjectBuyPacket(header, bytes, ref i); case 135: return new BuyObjectInventoryPacket(header, bytes, ref i); case 136: return new DerezContainerPacket(header, bytes, ref i); case 137: return new ObjectPermissionsPacket(header, bytes, ref i); case 138: return new ObjectSaleInfoPacket(header, bytes, ref i); case 139: return new ObjectNamePacket(header, bytes, ref i); case 140: return new ObjectDescriptionPacket(header, bytes, ref i); case 141: return new ObjectCategoryPacket(header, bytes, ref i); case 142: return new ObjectSelectPacket(header, bytes, ref i); case 143: return new ObjectDeselectPacket(header, bytes, ref i); case 144: return new ObjectAttachPacket(header, bytes, ref i); case 145: return new ObjectDetachPacket(header, bytes, ref i); case 146: return new ObjectDropPacket(header, bytes, ref i); case 147: return new ObjectLinkPacket(header, bytes, ref i); case 148: return new ObjectDelinkPacket(header, bytes, ref i); case 149: return new ObjectHingePacket(header, bytes, ref i); case 150: return new ObjectDehingePacket(header, bytes, ref i); case 151: return new ObjectGrabPacket(header, bytes, ref i); case 152: return new ObjectGrabUpdatePacket(header, bytes, ref i); case 153: return new ObjectDeGrabPacket(header, bytes, ref i); case 154: return new ObjectSpinStartPacket(header, bytes, ref i); case 155: return new ObjectSpinUpdatePacket(header, bytes, ref i); case 156: return new ObjectSpinStopPacket(header, bytes, ref i); case 157: return new ObjectExportSelectedPacket(header, bytes, ref i); case 158: return new ObjectImportPacket(header, bytes, ref i); case 159: return new ModifyLandPacket(header, bytes, ref i); case 160: return new VelocityInterpolateOnPacket(header, bytes, ref i); case 161: return new VelocityInterpolateOffPacket(header, bytes, ref i); case 162: return new StateSavePacket(header, bytes, ref i); case 163: return new ReportAutosaveCrashPacket(header, bytes, ref i); case 164: return new SimWideDeletesPacket(header, bytes, ref i); case 165: return new TrackAgentPacket(header, bytes, ref i); case 166: return new GrantModificationPacket(header, bytes, ref i); case 167: return new RevokeModificationPacket(header, bytes, ref i); case 168: return new RequestGrantedProxiesPacket(header, bytes, ref i); case 169: return new GrantedProxiesPacket(header, bytes, ref i); case 170: return new AddModifyAbilityPacket(header, bytes, ref i); case 171: return new RemoveModifyAbilityPacket(header, bytes, ref i); case 172: return new ViewerStatsPacket(header, bytes, ref i); case 173: return new ScriptAnswerYesPacket(header, bytes, ref i); case 174: return new UserReportPacket(header, bytes, ref i); case 175: return new AlertMessagePacket(header, bytes, ref i); case 176: return new AgentAlertMessagePacket(header, bytes, ref i); case 177: return new MeanCollisionAlertPacket(header, bytes, ref i); case 178: return new ViewerFrozenMessagePacket(header, bytes, ref i); case 179: return new HealthMessagePacket(header, bytes, ref i); case 180: return new ChatFromSimulatorPacket(header, bytes, ref i); case 181: return new SimStatsPacket(header, bytes, ref i); case 182: return new RequestRegionInfoPacket(header, bytes, ref i); case 183: return new RegionInfoPacket(header, bytes, ref i); case 184: return new GodUpdateRegionInfoPacket(header, bytes, ref i); case 185: return new NearestLandingRegionRequestPacket(header, bytes, ref i); case 186: return new NearestLandingRegionReplyPacket(header, bytes, ref i); case 187: return new NearestLandingRegionUpdatedPacket(header, bytes, ref i); case 188: return new TeleportLandingStatusChangedPacket(header, bytes, ref i); case 189: return new RegionHandshakePacket(header, bytes, ref i); case 190: return new RegionHandshakeReplyPacket(header, bytes, ref i); case 191: return new SimulatorViewerTimeMessagePacket(header, bytes, ref i); case 192: return new EnableSimulatorPacket(header, bytes, ref i); case 193: return new DisableSimulatorPacket(header, bytes, ref i); case 194: return new TransferRequestPacket(header, bytes, ref i); case 195: return new TransferInfoPacket(header, bytes, ref i); case 196: return new TransferAbortPacket(header, bytes, ref i); case 197: return new TransferPriorityPacket(header, bytes, ref i); case 198: return new RequestXferPacket(header, bytes, ref i); case 199: return new AbortXferPacket(header, bytes, ref i); case 200: return new RequestAvatarInfoPacket(header, bytes, ref i); case 201: return new AvatarAppearancePacket(header, bytes, ref i); case 202: return new SetFollowCamPropertiesPacket(header, bytes, ref i); case 203: return new ClearFollowCamPropertiesPacket(header, bytes, ref i); case 204: return new RequestPayPricePacket(header, bytes, ref i); case 205: return new PayPriceReplyPacket(header, bytes, ref i); case 206: return new KickUserPacket(header, bytes, ref i); case 207: return new KickUserAckPacket(header, bytes, ref i); case 208: return new GodKickUserPacket(header, bytes, ref i); case 209: return new SystemKickUserPacket(header, bytes, ref i); case 210: return new EjectUserPacket(header, bytes, ref i); case 211: return new FreezeUserPacket(header, bytes, ref i); case 212: return new AvatarPropertiesRequestPacket(header, bytes, ref i); case 213: return new AvatarPropertiesRequestBackendPacket(header, bytes, ref i); case 214: return new AvatarPropertiesReplyPacket(header, bytes, ref i); case 215: return new AvatarInterestsReplyPacket(header, bytes, ref i); case 216: return new AvatarGroupsReplyPacket(header, bytes, ref i); case 217: return new AvatarPropertiesUpdatePacket(header, bytes, ref i); case 218: return new AvatarInterestsUpdatePacket(header, bytes, ref i); case 219: return new AvatarStatisticsReplyPacket(header, bytes, ref i); case 220: return new AvatarNotesReplyPacket(header, bytes, ref i); case 221: return new AvatarNotesUpdatePacket(header, bytes, ref i); case 222: return new AvatarPicksReplyPacket(header, bytes, ref i); case 223: return new EventInfoRequestPacket(header, bytes, ref i); case 224: return new EventInfoReplyPacket(header, bytes, ref i); case 225: return new EventNotificationAddRequestPacket(header, bytes, ref i); case 226: return new EventNotificationRemoveRequestPacket(header, bytes, ref i); case 227: return new EventGodDeletePacket(header, bytes, ref i); case 228: return new PickInfoRequestPacket(header, bytes, ref i); case 229: return new PickInfoReplyPacket(header, bytes, ref i); case 230: return new PickInfoUpdatePacket(header, bytes, ref i); case 231: return new PickDeletePacket(header, bytes, ref i); case 232: return new PickGodDeletePacket(header, bytes, ref i); case 233: return new ScriptQuestionPacket(header, bytes, ref i); case 234: return new ScriptControlChangePacket(header, bytes, ref i); case 235: return new ScriptDialogPacket(header, bytes, ref i); case 236: return new ScriptDialogReplyPacket(header, bytes, ref i); case 237: return new ForceScriptControlReleasePacket(header, bytes, ref i); case 238: return new RevokePermissionsPacket(header, bytes, ref i); case 239: return new LoadURLPacket(header, bytes, ref i); case 240: return new ScriptTeleportRequestPacket(header, bytes, ref i); case 241: return new ParcelOverlayPacket(header, bytes, ref i); case 242: return new ParcelPropertiesRequestByIDPacket(header, bytes, ref i); case 243: return new ParcelPropertiesUpdatePacket(header, bytes, ref i); case 244: return new ParcelReturnObjectsPacket(header, bytes, ref i); case 245: return new ParcelSetOtherCleanTimePacket(header, bytes, ref i); case 246: return new ParcelDisableObjectsPacket(header, bytes, ref i); case 247: return new ParcelSelectObjectsPacket(header, bytes, ref i); case 248: return new EstateCovenantRequestPacket(header, bytes, ref i); case 249: return new EstateCovenantReplyPacket(header, bytes, ref i); case 250: return new ForceObjectSelectPacket(header, bytes, ref i); case 251: return new ParcelBuyPassPacket(header, bytes, ref i); case 252: return new ParcelDeedToGroupPacket(header, bytes, ref i); case 253: return new ParcelReclaimPacket(header, bytes, ref i); case 254: return new ParcelClaimPacket(header, bytes, ref i); case 255: return new ParcelJoinPacket(header, bytes, ref i); case 256: return new ParcelDividePacket(header, bytes, ref i); case 257: return new ParcelReleasePacket(header, bytes, ref i); case 258: return new ParcelBuyPacket(header, bytes, ref i); case 259: return new ParcelGodForceOwnerPacket(header, bytes, ref i); case 260: return new ParcelAccessListRequestPacket(header, bytes, ref i); case 261: return new ParcelAccessListReplyPacket(header, bytes, ref i); case 262: return new ParcelAccessListUpdatePacket(header, bytes, ref i); case 263: return new ParcelDwellRequestPacket(header, bytes, ref i); case 264: return new ParcelDwellReplyPacket(header, bytes, ref i); case 265: return new RequestParcelTransferPacket(header, bytes, ref i); case 266: return new UpdateParcelPacket(header, bytes, ref i); case 267: return new RemoveParcelPacket(header, bytes, ref i); case 268: return new MergeParcelPacket(header, bytes, ref i); case 269: return new LogParcelChangesPacket(header, bytes, ref i); case 270: return new CheckParcelSalesPacket(header, bytes, ref i); case 271: return new ParcelSalesPacket(header, bytes, ref i); case 272: return new ParcelGodMarkAsContentPacket(header, bytes, ref i); case 273: return new ParcelGodReserveForNewbiePacket(header, bytes, ref i); case 274: return new ViewerStartAuctionPacket(header, bytes, ref i); case 275: return new StartAuctionPacket(header, bytes, ref i); case 276: return new ConfirmAuctionStartPacket(header, bytes, ref i); case 277: return new CompleteAuctionPacket(header, bytes, ref i); case 278: return new CancelAuctionPacket(header, bytes, ref i); case 279: return new CheckParcelAuctionsPacket(header, bytes, ref i); case 280: return new ParcelAuctionsPacket(header, bytes, ref i); case 281: return new UUIDNameRequestPacket(header, bytes, ref i); case 282: return new UUIDNameReplyPacket(header, bytes, ref i); case 283: return new UUIDGroupNameRequestPacket(header, bytes, ref i); case 284: return new UUIDGroupNameReplyPacket(header, bytes, ref i); case 285: return new ChatPassPacket(header, bytes, ref i); case 286: return new ChildAgentDyingPacket(header, bytes, ref i); case 287: return new ChildAgentUnknownPacket(header, bytes, ref i); case 288: return new KillChildAgentsPacket(header, bytes, ref i); case 289: return new GetScriptRunningPacket(header, bytes, ref i); case 290: return new ScriptRunningReplyPacket(header, bytes, ref i); case 291: return new SetScriptRunningPacket(header, bytes, ref i); case 292: return new ScriptResetPacket(header, bytes, ref i); case 293: return new ScriptSensorRequestPacket(header, bytes, ref i); case 294: return new ScriptSensorReplyPacket(header, bytes, ref i); case 295: return new CompleteAgentMovementPacket(header, bytes, ref i); case 296: return new AgentMovementCompletePacket(header, bytes, ref i); case 297: return new LogLoginPacket(header, bytes, ref i); case 298: return new ConnectAgentToUserserverPacket(header, bytes, ref i); case 299: return new ConnectToUserserverPacket(header, bytes, ref i); case 300: return new DataServerLogoutPacket(header, bytes, ref i); case 301: return new LogoutRequestPacket(header, bytes, ref i); case 302: return new FinalizeLogoutPacket(header, bytes, ref i); case 303: return new LogoutReplyPacket(header, bytes, ref i); case 304: return new LogoutDemandPacket(header, bytes, ref i); case 305: return new ImprovedInstantMessagePacket(header, bytes, ref i); case 306: return new RetrieveInstantMessagesPacket(header, bytes, ref i); case 307: return new DequeueInstantMessagesPacket(header, bytes, ref i); case 308: return new FindAgentPacket(header, bytes, ref i); case 309: return new RequestGodlikePowersPacket(header, bytes, ref i); case 310: return new GrantGodlikePowersPacket(header, bytes, ref i); case 311: return new GodlikeMessagePacket(header, bytes, ref i); case 312: return new EstateOwnerMessagePacket(header, bytes, ref i); case 313: return new GenericMessagePacket(header, bytes, ref i); case 314: return new MuteListRequestPacket(header, bytes, ref i); case 315: return new UpdateMuteListEntryPacket(header, bytes, ref i); case 316: return new RemoveMuteListEntryPacket(header, bytes, ref i); case 317: return new CopyInventoryFromNotecardPacket(header, bytes, ref i); case 318: return new UpdateInventoryItemPacket(header, bytes, ref i); case 319: return new UpdateCreateInventoryItemPacket(header, bytes, ref i); case 320: return new MoveInventoryItemPacket(header, bytes, ref i); case 321: return new CopyInventoryItemPacket(header, bytes, ref i); case 322: return new RemoveInventoryItemPacket(header, bytes, ref i); case 323: return new ChangeInventoryItemFlagsPacket(header, bytes, ref i); case 324: return new SaveAssetIntoInventoryPacket(header, bytes, ref i); case 325: return new CreateInventoryFolderPacket(header, bytes, ref i); case 326: return new UpdateInventoryFolderPacket(header, bytes, ref i); case 327: return new MoveInventoryFolderPacket(header, bytes, ref i); case 328: return new RemoveInventoryFolderPacket(header, bytes, ref i); case 329: return new FetchInventoryDescendentsPacket(header, bytes, ref i); case 330: return new InventoryDescendentsPacket(header, bytes, ref i); case 331: return new FetchInventoryPacket(header, bytes, ref i); case 332: return new FetchInventoryReplyPacket(header, bytes, ref i); case 333: return new BulkUpdateInventoryPacket(header, bytes, ref i); case 334: return new RequestInventoryAssetPacket(header, bytes, ref i); case 335: return new InventoryAssetResponsePacket(header, bytes, ref i); case 336: return new RemoveInventoryObjectsPacket(header, bytes, ref i); case 337: return new PurgeInventoryDescendentsPacket(header, bytes, ref i); case 338: return new UpdateTaskInventoryPacket(header, bytes, ref i); case 339: return new RemoveTaskInventoryPacket(header, bytes, ref i); case 340: return new MoveTaskInventoryPacket(header, bytes, ref i); case 341: return new RequestTaskInventoryPacket(header, bytes, ref i); case 342: return new ReplyTaskInventoryPacket(header, bytes, ref i); case 343: return new DeRezObjectPacket(header, bytes, ref i); case 344: return new DeRezAckPacket(header, bytes, ref i); case 345: return new RezObjectPacket(header, bytes, ref i); case 346: return new RezObjectFromNotecardPacket(header, bytes, ref i); case 347: return new DeclineInventoryPacket(header, bytes, ref i); case 348: return new TransferInventoryPacket(header, bytes, ref i); case 349: return new TransferInventoryAckPacket(header, bytes, ref i); case 350: return new RequestFriendshipPacket(header, bytes, ref i); case 351: return new AcceptFriendshipPacket(header, bytes, ref i); case 352: return new DeclineFriendshipPacket(header, bytes, ref i); case 353: return new FormFriendshipPacket(header, bytes, ref i); case 354: return new TerminateFriendshipPacket(header, bytes, ref i); case 355: return new OfferCallingCardPacket(header, bytes, ref i); case 356: return new AcceptCallingCardPacket(header, bytes, ref i); case 357: return new DeclineCallingCardPacket(header, bytes, ref i); case 358: return new RezScriptPacket(header, bytes, ref i); case 359: return new CreateInventoryItemPacket(header, bytes, ref i); case 360: return new CreateLandmarkForEventPacket(header, bytes, ref i); case 361: return new EventLocationRequestPacket(header, bytes, ref i); case 362: return new EventLocationReplyPacket(header, bytes, ref i); case 363: return new RegionHandleRequestPacket(header, bytes, ref i); case 364: return new RegionIDAndHandleReplyPacket(header, bytes, ref i); case 365: return new MoneyTransferRequestPacket(header, bytes, ref i); case 366: return new MoneyTransferBackendPacket(header, bytes, ref i); case 367: return new BulkMoneyTransferPacket(header, bytes, ref i); case 368: return new AdjustBalancePacket(header, bytes, ref i); case 369: return new MoneyBalanceRequestPacket(header, bytes, ref i); case 370: return new MoneyBalanceReplyPacket(header, bytes, ref i); case 371: return new RoutedMoneyBalanceReplyPacket(header, bytes, ref i); case 372: return new MoneyHistoryRequestPacket(header, bytes, ref i); case 373: return new MoneyHistoryReplyPacket(header, bytes, ref i); case 374: return new MoneySummaryRequestPacket(header, bytes, ref i); case 375: return new MoneySummaryReplyPacket(header, bytes, ref i); case 376: return new MoneyDetailsRequestPacket(header, bytes, ref i); case 377: return new MoneyDetailsReplyPacket(header, bytes, ref i); case 378: return new MoneyTransactionsRequestPacket(header, bytes, ref i); case 379: return new MoneyTransactionsReplyPacket(header, bytes, ref i); case 380: return new GestureRequestPacket(header, bytes, ref i); case 381: return new ActivateGesturesPacket(header, bytes, ref i); case 382: return new DeactivateGesturesPacket(header, bytes, ref i); case 383: return new InventoryUpdatePacket(header, bytes, ref i); case 384: return new MuteListUpdatePacket(header, bytes, ref i); case 385: return new UseCachedMuteListPacket(header, bytes, ref i); case 386: return new UserLoginLocationReplyPacket(header, bytes, ref i); case 387: return new UserSimLocationReplyPacket(header, bytes, ref i); case 388: return new UserListReplyPacket(header, bytes, ref i); case 389: return new OnlineNotificationPacket(header, bytes, ref i); case 390: return new OfflineNotificationPacket(header, bytes, ref i); case 391: return new SetStartLocationRequestPacket(header, bytes, ref i); case 392: return new SetStartLocationPacket(header, bytes, ref i); case 393: return new UserLoginLocationRequestPacket(header, bytes, ref i); case 394: return new SpaceLoginLocationReplyPacket(header, bytes, ref i); case 395: return new NetTestPacket(header, bytes, ref i); case 396: return new SetCPURatioPacket(header, bytes, ref i); case 397: return new SimCrashedPacket(header, bytes, ref i); case 398: return new SimulatorPauseStatePacket(header, bytes, ref i); case 399: return new SimulatorThrottleSettingsPacket(header, bytes, ref i); case 400: return new NameValuePairPacket(header, bytes, ref i); case 401: return new RemoveNameValuePairPacket(header, bytes, ref i); case 402: return new GetNameValuePairPacket(header, bytes, ref i); case 403: return new UpdateAttachmentPacket(header, bytes, ref i); case 404: return new RemoveAttachmentPacket(header, bytes, ref i); case 405: return new AssetUploadRequestPacket(header, bytes, ref i); case 406: return new AssetUploadCompletePacket(header, bytes, ref i); case 407: return new ReputationAgentAssignPacket(header, bytes, ref i); case 408: return new ReputationIndividualRequestPacket(header, bytes, ref i); case 409: return new ReputationIndividualReplyPacket(header, bytes, ref i); case 410: return new EmailMessageRequestPacket(header, bytes, ref i); case 411: return new EmailMessageReplyPacket(header, bytes, ref i); case 412: return new ScriptDataRequestPacket(header, bytes, ref i); case 413: return new ScriptDataReplyPacket(header, bytes, ref i); case 414: return new CreateGroupRequestPacket(header, bytes, ref i); case 415: return new CreateGroupReplyPacket(header, bytes, ref i); case 416: return new UpdateGroupInfoPacket(header, bytes, ref i); case 417: return new GroupRoleChangesPacket(header, bytes, ref i); case 418: return new JoinGroupRequestPacket(header, bytes, ref i); case 419: return new JoinGroupReplyPacket(header, bytes, ref i); case 420: return new EjectGroupMemberRequestPacket(header, bytes, ref i); case 421: return new EjectGroupMemberReplyPacket(header, bytes, ref i); case 422: return new LeaveGroupRequestPacket(header, bytes, ref i); case 423: return new LeaveGroupReplyPacket(header, bytes, ref i); case 424: return new InviteGroupRequestPacket(header, bytes, ref i); case 425: return new InviteGroupResponsePacket(header, bytes, ref i); case 426: return new GroupProfileRequestPacket(header, bytes, ref i); case 427: return new GroupProfileReplyPacket(header, bytes, ref i); case 428: return new GroupAccountSummaryRequestPacket(header, bytes, ref i); case 429: return new GroupAccountSummaryReplyPacket(header, bytes, ref i); case 430: return new GroupAccountDetailsRequestPacket(header, bytes, ref i); case 431: return new GroupAccountDetailsReplyPacket(header, bytes, ref i); case 432: return new GroupAccountTransactionsRequestPacket(header, bytes, ref i); case 433: return new GroupAccountTransactionsReplyPacket(header, bytes, ref i); case 434: return new GroupActiveProposalsRequestPacket(header, bytes, ref i); case 435: return new GroupActiveProposalItemReplyPacket(header, bytes, ref i); case 436: return new GroupVoteHistoryRequestPacket(header, bytes, ref i); case 437: return new GroupVoteHistoryItemReplyPacket(header, bytes, ref i); case 438: return new StartGroupProposalPacket(header, bytes, ref i); case 439: return new GroupProposalBallotPacket(header, bytes, ref i); case 440: return new TallyVotesPacket(header, bytes, ref i); case 441: return new GroupMembersRequestPacket(header, bytes, ref i); case 442: return new GroupMembersReplyPacket(header, bytes, ref i); case 443: return new ActivateGroupPacket(header, bytes, ref i); case 444: return new SetGroupContributionPacket(header, bytes, ref i); case 445: return new SetGroupAcceptNoticesPacket(header, bytes, ref i); case 446: return new GroupRoleDataRequestPacket(header, bytes, ref i); case 447: return new GroupRoleDataReplyPacket(header, bytes, ref i); case 448: return new GroupRoleMembersRequestPacket(header, bytes, ref i); case 449: return new GroupRoleMembersReplyPacket(header, bytes, ref i); case 450: return new GroupTitlesRequestPacket(header, bytes, ref i); case 451: return new GroupTitlesReplyPacket(header, bytes, ref i); case 452: return new GroupTitleUpdatePacket(header, bytes, ref i); case 453: return new GroupRoleUpdatePacket(header, bytes, ref i); case 454: return new LiveHelpGroupRequestPacket(header, bytes, ref i); case 455: return new LiveHelpGroupReplyPacket(header, bytes, ref i); case 456: return new AgentWearablesRequestPacket(header, bytes, ref i); case 457: return new AgentWearablesUpdatePacket(header, bytes, ref i); case 458: return new AgentIsNowWearingPacket(header, bytes, ref i); case 459: return new AgentCachedTexturePacket(header, bytes, ref i); case 460: return new AgentCachedTextureResponsePacket(header, bytes, ref i); case 461: return new AgentDataUpdateRequestPacket(header, bytes, ref i); case 462: return new AgentDataUpdatePacket(header, bytes, ref i); case 463: return new GroupDataUpdatePacket(header, bytes, ref i); case 464: return new AgentGroupDataUpdatePacket(header, bytes, ref i); case 465: return new AgentDropGroupPacket(header, bytes, ref i); case 466: return new LogTextMessagePacket(header, bytes, ref i); case 467: return new CreateTrustedCircuitPacket(header, bytes, ref i); case 468: return new DenyTrustedCircuitPacket(header, bytes, ref i); case 469: return new RezSingleAttachmentFromInvPacket(header, bytes, ref i); case 470: return new RezMultipleAttachmentsFromInvPacket(header, bytes, ref i); case 471: return new DetachAttachmentIntoInvPacket(header, bytes, ref i); case 472: return new CreateNewOutfitAttachmentsPacket(header, bytes, ref i); case 473: return new UserInfoRequestPacket(header, bytes, ref i); case 474: return new UserInfoReplyPacket(header, bytes, ref i); case 475: return new UpdateUserInfoPacket(header, bytes, ref i); case 476: return new GodExpungeUserPacket(header, bytes, ref i); case 477: return new StartExpungeProcessPacket(header, bytes, ref i); case 478: return new StartExpungeProcessAckPacket(header, bytes, ref i); case 479: return new StartParcelRenamePacket(header, bytes, ref i); case 480: return new StartParcelRenameAckPacket(header, bytes, ref i); case 481: return new BulkParcelRenamePacket(header, bytes, ref i); case 482: return new ParcelRenamePacket(header, bytes, ref i); case 483: return new StartParcelRemovePacket(header, bytes, ref i); case 484: return new StartParcelRemoveAckPacket(header, bytes, ref i); case 485: return new BulkParcelRemovePacket(header, bytes, ref i); case 486: return new InitiateUploadPacket(header, bytes, ref i); case 487: return new InitiateDownloadPacket(header, bytes, ref i); case 488: return new SystemMessagePacket(header, bytes, ref i); case 489: return new MapLayerRequestPacket(header, bytes, ref i); case 490: return new MapLayerReplyPacket(header, bytes, ref i); case 491: return new MapBlockRequestPacket(header, bytes, ref i); case 492: return new MapNameRequestPacket(header, bytes, ref i); case 493: return new MapBlockReplyPacket(header, bytes, ref i); case 494: return new MapItemRequestPacket(header, bytes, ref i); case 495: return new MapItemReplyPacket(header, bytes, ref i); case 496: return new SendPostcardPacket(header, bytes, ref i); case 497: return new RpcChannelRequestPacket(header, bytes, ref i); case 498: return new RpcChannelReplyPacket(header, bytes, ref i); case 499: return new RpcScriptRequestInboundPacket(header, bytes, ref i); case 500: return new RpcScriptRequestInboundForwardPacket(header, bytes, ref i); case 501: return new RpcScriptReplyInboundPacket(header, bytes, ref i); case 502: return new MailTaskSimRequestPacket(header, bytes, ref i); case 503: return new MailTaskSimReplyPacket(header, bytes, ref i); case 504: return new ScriptMailRegistrationPacket(header, bytes, ref i); case 505: return new ParcelMediaCommandMessagePacket(header, bytes, ref i); case 506: return new ParcelMediaUpdatePacket(header, bytes, ref i); case 507: return new LandStatRequestPacket(header, bytes, ref i); case 508: return new LandStatReplyPacket(header, bytes, ref i); case 65530: return new SecuredTemplateChecksumRequestPacket(header, bytes, ref i); case 65531: return new PacketAckPacket(header, bytes, ref i); case 65532: return new OpenCircuitPacket(header, bytes, ref i); case 65533: return new CloseCircuitPacket(header, bytes, ref i); case 65534: return new TemplateChecksumRequestPacket(header, bytes, ref i); case 65535: return new TemplateChecksumReplyPacket(header, bytes, ref i); } } else { id = (ushort)bytes[5]; switch (id) { case 1: return new ClosestSimulatorPacket(header, bytes, ref i); case 2: return new ObjectAddPacket(header, bytes, ref i); case 3: return new MultipleObjectUpdatePacket(header, bytes, ref i); case 4: return new RequestMultipleObjectsPacket(header, bytes, ref i); case 5: return new ObjectPositionPacket(header, bytes, ref i); case 6: return new RequestObjectPropertiesFamilyPacket(header, bytes, ref i); case 7: return new CoarseLocationUpdatePacket(header, bytes, ref i); case 8: return new CrossedRegionPacket(header, bytes, ref i); case 9: return new ConfirmEnableSimulatorPacket(header, bytes, ref i); case 10: return new ObjectPropertiesPacket(header, bytes, ref i); case 11: return new ObjectPropertiesFamilyPacket(header, bytes, ref i); case 12: return new ParcelPropertiesRequestPacket(header, bytes, ref i); case 13: return new SimStatusPacket(header, bytes, ref i); case 14: return new GestureUpdatePacket(header, bytes, ref i); case 15: return new AttachedSoundPacket(header, bytes, ref i); case 16: return new AttachedSoundGainChangePacket(header, bytes, ref i); case 17: return new AttachedSoundCutoffRadiusPacket(header, bytes, ref i); case 18: return new PreloadSoundPacket(header, bytes, ref i); case 19: return new InternalScriptMailPacket(header, bytes, ref i); case 20: return new ViewerEffectPacket(header, bytes, ref i); case 21: return new SetSunPhasePacket(header, bytes, ref i); } } } else { id = (ushort)bytes[4]; switch (id) { case 1: return new StartPingCheckPacket(header, bytes, ref i); case 2: return new CompletePingCheckPacket(header, bytes, ref i); case 3: return new NeighborListPacket(header, bytes, ref i); case 4: return new MovedIntoSimulatorPacket(header, bytes, ref i); case 5: return new AgentUpdatePacket(header, bytes, ref i); case 6: return new AgentAnimationPacket(header, bytes, ref i); case 7: return new AgentRequestSitPacket(header, bytes, ref i); case 8: return new AgentSitPacket(header, bytes, ref i); case 9: return new RequestImagePacket(header, bytes, ref i); case 10: return new ImageDataPacket(header, bytes, ref i); case 11: return new ImagePacketPacket(header, bytes, ref i); case 12: return new LayerDataPacket(header, bytes, ref i); case 13: return new ObjectUpdatePacket(header, bytes, ref i); case 14: return new ObjectUpdateCompressedPacket(header, bytes, ref i); case 15: return new ObjectUpdateCachedPacket(header, bytes, ref i); case 16: return new ImprovedTerseObjectUpdatePacket(header, bytes, ref i); case 17: return new KillObjectPacket(header, bytes, ref i); case 18: return new AgentToNewRegionPacket(header, bytes, ref i); case 19: return new TransferPacketPacket(header, bytes, ref i); case 20: return new SendXferPacketPacket(header, bytes, ref i); case 21: return new ConfirmXferPacketPacket(header, bytes, ref i); case 22: return new AvatarAnimationPacket(header, bytes, ref i); case 23: return new AvatarSitResponsePacket(header, bytes, ref i); case 24: return new CameraConstraintPacket(header, bytes, ref i); case 25: return new ParcelPropertiesPacket(header, bytes, ref i); case 26: return new EdgeDataPacketPacket(header, bytes, ref i); case 27: return new ChildAgentUpdatePacket(header, bytes, ref i); case 28: return new ChildAgentAlivePacket(header, bytes, ref i); case 29: return new ChildAgentPositionUpdatePacket(header, bytes, ref i); case 30: return new PassObjectPacket(header, bytes, ref i); case 31: return new AtomicPassObjectPacket(header, bytes, ref i); case 32: return new SoundTriggerPacket(header, bytes, ref i); } } throw new MalformedDataException("Unknown packet ID"); } } /// TestMessage packet public class TestMessagePacket : Packet { /// TestBlock1 block public class TestBlock1Block { /// Test1 field public uint Test1; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public TestBlock1Block() { } /// Constructor for building the block from a byte array public TestBlock1Block(byte[] bytes, ref int i) { try { Test1 = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Test1 % 256); bytes[i++] = (byte)((Test1 >> 8) % 256); bytes[i++] = (byte)((Test1 >> 16) % 256); bytes[i++] = (byte)((Test1 >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TestBlock1 --\n"; output += "Test1: " + Test1.ToString() + "\n"; output = output.Trim(); return output; } } /// NeighborBlock block public class NeighborBlockBlock { /// Test0 field public uint Test0; /// Test1 field public uint Test1; /// Test2 field public uint Test2; /// Length of this block serialized in bytes public int Length { get { return 12; } } /// Default constructor public NeighborBlockBlock() { } /// Constructor for building the block from a byte array public NeighborBlockBlock(byte[] bytes, ref int i) { try { Test0 = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Test1 = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Test2 = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Test0 % 256); bytes[i++] = (byte)((Test0 >> 8) % 256); bytes[i++] = (byte)((Test0 >> 16) % 256); bytes[i++] = (byte)((Test0 >> 24) % 256); bytes[i++] = (byte)(Test1 % 256); bytes[i++] = (byte)((Test1 >> 8) % 256); bytes[i++] = (byte)((Test1 >> 16) % 256); bytes[i++] = (byte)((Test1 >> 24) % 256); bytes[i++] = (byte)(Test2 % 256); bytes[i++] = (byte)((Test2 >> 8) % 256); bytes[i++] = (byte)((Test2 >> 16) % 256); bytes[i++] = (byte)((Test2 >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- NeighborBlock --\n"; output += "Test0: " + Test0.ToString() + "\n"; output += "Test1: " + Test1.ToString() + "\n"; output += "Test2: " + Test2.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TestMessage public override PacketType Type { get { return PacketType.TestMessage; } } /// TestBlock1 block public TestBlock1Block TestBlock1; /// NeighborBlock block public NeighborBlockBlock[] NeighborBlock; /// Default constructor public TestMessagePacket() { Header = new LowHeader(); Header.ID = 1; Header.Reliable = true; Header.Zerocoded = true; TestBlock1 = new TestBlock1Block(); NeighborBlock = new NeighborBlockBlock[4]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TestMessagePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TestBlock1 = new TestBlock1Block(bytes, ref i); NeighborBlock = new NeighborBlockBlock[4]; for (int j = 0; j < 4; j++) { NeighborBlock[j] = new NeighborBlockBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public TestMessagePacket(Header head, byte[] bytes, ref int i) { Header = head; TestBlock1 = new TestBlock1Block(bytes, ref i); NeighborBlock = new NeighborBlockBlock[4]; for (int j = 0; j < 4; j++) { NeighborBlock[j] = new NeighborBlockBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TestBlock1.Length;; for (int j = 0; j < 4; j++) { length += NeighborBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TestBlock1.ToBytes(bytes, ref i); for (int j = 0; j < 4; j++) { NeighborBlock[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TestMessage ---\n"; output += TestBlock1.ToString() + "\n"; for (int j = 0; j < 4; j++) { output += NeighborBlock[j].ToString() + "\n"; } return output; } } /// AddCircuitCode packet public class AddCircuitCodePacket : Packet { /// CircuitCode block public class CircuitCodeBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Code field public uint Code; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public CircuitCodeBlock() { } /// Constructor for building the block from a byte array public CircuitCodeBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; Code = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Code % 256); bytes[i++] = (byte)((Code >> 8) % 256); bytes[i++] = (byte)((Code >> 16) % 256); bytes[i++] = (byte)((Code >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- CircuitCode --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "Code: " + Code.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AddCircuitCode public override PacketType Type { get { return PacketType.AddCircuitCode; } } /// CircuitCode block public CircuitCodeBlock CircuitCode; /// Default constructor public AddCircuitCodePacket() { Header = new LowHeader(); Header.ID = 2; Header.Reliable = true; CircuitCode = new CircuitCodeBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AddCircuitCodePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); CircuitCode = new CircuitCodeBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AddCircuitCodePacket(Header head, byte[] bytes, ref int i) { Header = head; CircuitCode = new CircuitCodeBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += CircuitCode.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); CircuitCode.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AddCircuitCode ---\n"; output += CircuitCode.ToString() + "\n"; return output; } } /// UseCircuitCode packet public class UseCircuitCodePacket : Packet { /// CircuitCode block public class CircuitCodeBlock { /// ID field public LLUUID ID; /// SessionID field public LLUUID SessionID; /// Code field public uint Code; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public CircuitCodeBlock() { } /// Constructor for building the block from a byte array public CircuitCodeBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; Code = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Code % 256); bytes[i++] = (byte)((Code >> 8) % 256); bytes[i++] = (byte)((Code >> 16) % 256); bytes[i++] = (byte)((Code >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- CircuitCode --\n"; output += "ID: " + ID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "Code: " + Code.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UseCircuitCode public override PacketType Type { get { return PacketType.UseCircuitCode; } } /// CircuitCode block public CircuitCodeBlock CircuitCode; /// Default constructor public UseCircuitCodePacket() { Header = new LowHeader(); Header.ID = 3; Header.Reliable = true; CircuitCode = new CircuitCodeBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UseCircuitCodePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); CircuitCode = new CircuitCodeBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public UseCircuitCodePacket(Header head, byte[] bytes, ref int i) { Header = head; CircuitCode = new CircuitCodeBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += CircuitCode.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); CircuitCode.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UseCircuitCode ---\n"; output += CircuitCode.ToString() + "\n"; return output; } } /// LogControl packet public class LogControlPacket : Packet { /// Options block public class OptionsBlock { /// Mask field public uint Mask; /// Time field public bool Time; /// RemoteInfos field public bool RemoteInfos; /// Location field public bool Location; /// Level field public byte Level; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public OptionsBlock() { } /// Constructor for building the block from a byte array public OptionsBlock(byte[] bytes, ref int i) { try { Mask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Time = (bytes[i++] != 0) ? (bool)true : (bool)false; RemoteInfos = (bytes[i++] != 0) ? (bool)true : (bool)false; Location = (bytes[i++] != 0) ? (bool)true : (bool)false; Level = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Mask % 256); bytes[i++] = (byte)((Mask >> 8) % 256); bytes[i++] = (byte)((Mask >> 16) % 256); bytes[i++] = (byte)((Mask >> 24) % 256); bytes[i++] = (byte)((Time) ? 1 : 0); bytes[i++] = (byte)((RemoteInfos) ? 1 : 0); bytes[i++] = (byte)((Location) ? 1 : 0); bytes[i++] = Level; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Options --\n"; output += "Mask: " + Mask.ToString() + "\n"; output += "Time: " + Time.ToString() + "\n"; output += "RemoteInfos: " + RemoteInfos.ToString() + "\n"; output += "Location: " + Location.ToString() + "\n"; output += "Level: " + Level.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.LogControl public override PacketType Type { get { return PacketType.LogControl; } } /// Options block public OptionsBlock Options; /// Default constructor public LogControlPacket() { Header = new LowHeader(); Header.ID = 4; Header.Reliable = true; Options = new OptionsBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public LogControlPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Options = new OptionsBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public LogControlPacket(Header head, byte[] bytes, ref int i) { Header = head; Options = new OptionsBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Options.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Options.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- LogControl ---\n"; output += Options.ToString() + "\n"; return output; } } /// RelayLogControl packet public class RelayLogControlPacket : Packet { /// Options block public class OptionsBlock { /// Mask field public uint Mask; /// Time field public bool Time; /// RemoteInfos field public bool RemoteInfos; /// Location field public bool Location; /// Level field public byte Level; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public OptionsBlock() { } /// Constructor for building the block from a byte array public OptionsBlock(byte[] bytes, ref int i) { try { Mask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Time = (bytes[i++] != 0) ? (bool)true : (bool)false; RemoteInfos = (bytes[i++] != 0) ? (bool)true : (bool)false; Location = (bytes[i++] != 0) ? (bool)true : (bool)false; Level = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Mask % 256); bytes[i++] = (byte)((Mask >> 8) % 256); bytes[i++] = (byte)((Mask >> 16) % 256); bytes[i++] = (byte)((Mask >> 24) % 256); bytes[i++] = (byte)((Time) ? 1 : 0); bytes[i++] = (byte)((RemoteInfos) ? 1 : 0); bytes[i++] = (byte)((Location) ? 1 : 0); bytes[i++] = Level; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Options --\n"; output += "Mask: " + Mask.ToString() + "\n"; output += "Time: " + Time.ToString() + "\n"; output += "RemoteInfos: " + RemoteInfos.ToString() + "\n"; output += "Location: " + Location.ToString() + "\n"; output += "Level: " + Level.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RelayLogControl public override PacketType Type { get { return PacketType.RelayLogControl; } } /// Options block public OptionsBlock Options; /// Default constructor public RelayLogControlPacket() { Header = new LowHeader(); Header.ID = 5; Header.Reliable = true; Options = new OptionsBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RelayLogControlPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Options = new OptionsBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RelayLogControlPacket(Header head, byte[] bytes, ref int i) { Header = head; Options = new OptionsBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Options.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Options.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RelayLogControl ---\n"; output += Options.ToString() + "\n"; return output; } } /// LogMessages packet public class LogMessagesPacket : Packet { /// Options block public class OptionsBlock { /// Enable field public bool Enable; /// Length of this block serialized in bytes public int Length { get { return 1; } } /// Default constructor public OptionsBlock() { } /// Constructor for building the block from a byte array public OptionsBlock(byte[] bytes, ref int i) { try { Enable = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((Enable) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Options --\n"; output += "Enable: " + Enable.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.LogMessages public override PacketType Type { get { return PacketType.LogMessages; } } /// Options block public OptionsBlock Options; /// Default constructor public LogMessagesPacket() { Header = new LowHeader(); Header.ID = 6; Header.Reliable = true; Options = new OptionsBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public LogMessagesPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Options = new OptionsBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public LogMessagesPacket(Header head, byte[] bytes, ref int i) { Header = head; Options = new OptionsBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Options.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Options.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- LogMessages ---\n"; output += Options.ToString() + "\n"; return output; } } /// SimulatorAssign packet public class SimulatorAssignPacket : Packet { /// RegionInfo block public class RegionInfoBlock { /// IP field public uint IP; /// SecPerDay field public uint SecPerDay; /// MetersPerGrid field public float MetersPerGrid; /// UsecSinceStart field public ulong UsecSinceStart; /// Port field public ushort Port; /// SecPerYear field public uint SecPerYear; /// GridsPerEdge field public int GridsPerEdge; /// Handle field public ulong Handle; /// SunAngVelocity field public LLVector3 SunAngVelocity; /// SunDirection field public LLVector3 SunDirection; /// Length of this block serialized in bytes public int Length { get { return 62; } } /// Default constructor public RegionInfoBlock() { } /// Constructor for building the block from a byte array public RegionInfoBlock(byte[] bytes, ref int i) { try { IP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SecPerDay = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); MetersPerGrid = BitConverter.ToSingle(bytes, i); i += 4; UsecSinceStart = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); Port = (ushort)((bytes[i++] << 8) + bytes[i++]); SecPerYear = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GridsPerEdge = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Handle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); SunAngVelocity = new LLVector3(bytes, i); i += 12; SunDirection = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = (byte)(IP % 256); bytes[i++] = (byte)((IP >> 8) % 256); bytes[i++] = (byte)((IP >> 16) % 256); bytes[i++] = (byte)((IP >> 24) % 256); bytes[i++] = (byte)(SecPerDay % 256); bytes[i++] = (byte)((SecPerDay >> 8) % 256); bytes[i++] = (byte)((SecPerDay >> 16) % 256); bytes[i++] = (byte)((SecPerDay >> 24) % 256); ba = BitConverter.GetBytes(MetersPerGrid); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(UsecSinceStart % 256); bytes[i++] = (byte)((UsecSinceStart >> 8) % 256); bytes[i++] = (byte)((UsecSinceStart >> 16) % 256); bytes[i++] = (byte)((UsecSinceStart >> 24) % 256); bytes[i++] = (byte)((UsecSinceStart >> 32) % 256); bytes[i++] = (byte)((UsecSinceStart >> 40) % 256); bytes[i++] = (byte)((UsecSinceStart >> 48) % 256); bytes[i++] = (byte)((UsecSinceStart >> 56) % 256); bytes[i++] = (byte)((Port >> 8) % 256); bytes[i++] = (byte)(Port % 256); bytes[i++] = (byte)(SecPerYear % 256); bytes[i++] = (byte)((SecPerYear >> 8) % 256); bytes[i++] = (byte)((SecPerYear >> 16) % 256); bytes[i++] = (byte)((SecPerYear >> 24) % 256); bytes[i++] = (byte)(GridsPerEdge % 256); bytes[i++] = (byte)((GridsPerEdge >> 8) % 256); bytes[i++] = (byte)((GridsPerEdge >> 16) % 256); bytes[i++] = (byte)((GridsPerEdge >> 24) % 256); bytes[i++] = (byte)(Handle % 256); bytes[i++] = (byte)((Handle >> 8) % 256); bytes[i++] = (byte)((Handle >> 16) % 256); bytes[i++] = (byte)((Handle >> 24) % 256); bytes[i++] = (byte)((Handle >> 32) % 256); bytes[i++] = (byte)((Handle >> 40) % 256); bytes[i++] = (byte)((Handle >> 48) % 256); bytes[i++] = (byte)((Handle >> 56) % 256); if(SunAngVelocity == null) { Console.WriteLine("Warning: SunAngVelocity is null, in " + this.GetType()); } Array.Copy(SunAngVelocity.GetBytes(), 0, bytes, i, 12); i += 12; if(SunDirection == null) { Console.WriteLine("Warning: SunDirection is null, in " + this.GetType()); } Array.Copy(SunDirection.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionInfo --\n"; output += "IP: " + IP.ToString() + "\n"; output += "SecPerDay: " + SecPerDay.ToString() + "\n"; output += "MetersPerGrid: " + MetersPerGrid.ToString() + "\n"; output += "UsecSinceStart: " + UsecSinceStart.ToString() + "\n"; output += "Port: " + Port.ToString() + "\n"; output += "SecPerYear: " + SecPerYear.ToString() + "\n"; output += "GridsPerEdge: " + GridsPerEdge.ToString() + "\n"; output += "Handle: " + Handle.ToString() + "\n"; output += "SunAngVelocity: " + SunAngVelocity.ToString() + "\n"; output += "SunDirection: " + SunDirection.ToString() + "\n"; output = output.Trim(); return output; } } /// NeighborBlock block public class NeighborBlockBlock { /// IP field public uint IP; /// PublicPort field public ushort PublicPort; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// Port field public ushort Port; /// SimAccess field public byte SimAccess; /// PublicIP field public uint PublicIP; /// Length of this block serialized in bytes public int Length { get { int length = 13; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public NeighborBlockBlock() { } /// Constructor for building the block from a byte array public NeighborBlockBlock(byte[] bytes, ref int i) { int length; try { IP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); PublicPort = (ushort)((bytes[i++] << 8) + bytes[i++]); length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; Port = (ushort)((bytes[i++] << 8) + bytes[i++]); SimAccess = (byte)bytes[i++]; PublicIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(IP % 256); bytes[i++] = (byte)((IP >> 8) % 256); bytes[i++] = (byte)((IP >> 16) % 256); bytes[i++] = (byte)((IP >> 24) % 256); bytes[i++] = (byte)((PublicPort >> 8) % 256); bytes[i++] = (byte)(PublicPort % 256); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)((Port >> 8) % 256); bytes[i++] = (byte)(Port % 256); bytes[i++] = SimAccess; bytes[i++] = (byte)(PublicIP % 256); bytes[i++] = (byte)((PublicIP >> 8) % 256); bytes[i++] = (byte)((PublicIP >> 16) % 256); bytes[i++] = (byte)((PublicIP >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- NeighborBlock --\n"; output += "IP: " + IP.ToString() + "\n"; output += "PublicPort: " + PublicPort.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "Port: " + Port.ToString() + "\n"; output += "SimAccess: " + SimAccess.ToString() + "\n"; output += "PublicIP: " + PublicIP.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SimulatorAssign public override PacketType Type { get { return PacketType.SimulatorAssign; } } /// RegionInfo block public RegionInfoBlock RegionInfo; /// NeighborBlock block public NeighborBlockBlock[] NeighborBlock; /// Default constructor public SimulatorAssignPacket() { Header = new LowHeader(); Header.ID = 7; Header.Reliable = true; Header.Zerocoded = true; RegionInfo = new RegionInfoBlock(); NeighborBlock = new NeighborBlockBlock[4]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SimulatorAssignPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); RegionInfo = new RegionInfoBlock(bytes, ref i); NeighborBlock = new NeighborBlockBlock[4]; for (int j = 0; j < 4; j++) { NeighborBlock[j] = new NeighborBlockBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public SimulatorAssignPacket(Header head, byte[] bytes, ref int i) { Header = head; RegionInfo = new RegionInfoBlock(bytes, ref i); NeighborBlock = new NeighborBlockBlock[4]; for (int j = 0; j < 4; j++) { NeighborBlock[j] = new NeighborBlockBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += RegionInfo.Length;; for (int j = 0; j < 4; j++) { length += NeighborBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); RegionInfo.ToBytes(bytes, ref i); for (int j = 0; j < 4; j++) { NeighborBlock[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SimulatorAssign ---\n"; output += RegionInfo.ToString() + "\n"; for (int j = 0; j < 4; j++) { output += NeighborBlock[j].ToString() + "\n"; } return output; } } /// SpaceServerSimulatorTimeMessage packet public class SpaceServerSimulatorTimeMessagePacket : Packet { /// TimeInfo block public class TimeInfoBlock { /// SecPerDay field public uint SecPerDay; /// UsecSinceStart field public ulong UsecSinceStart; /// SecPerYear field public uint SecPerYear; /// SunAngVelocity field public LLVector3 SunAngVelocity; /// SunPhase field public float SunPhase; /// SunDirection field public LLVector3 SunDirection; /// Length of this block serialized in bytes public int Length { get { return 44; } } /// Default constructor public TimeInfoBlock() { } /// Constructor for building the block from a byte array public TimeInfoBlock(byte[] bytes, ref int i) { try { SecPerDay = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); UsecSinceStart = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); SecPerYear = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SunAngVelocity = new LLVector3(bytes, i); i += 12; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); SunPhase = BitConverter.ToSingle(bytes, i); i += 4; SunDirection = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = (byte)(SecPerDay % 256); bytes[i++] = (byte)((SecPerDay >> 8) % 256); bytes[i++] = (byte)((SecPerDay >> 16) % 256); bytes[i++] = (byte)((SecPerDay >> 24) % 256); bytes[i++] = (byte)(UsecSinceStart % 256); bytes[i++] = (byte)((UsecSinceStart >> 8) % 256); bytes[i++] = (byte)((UsecSinceStart >> 16) % 256); bytes[i++] = (byte)((UsecSinceStart >> 24) % 256); bytes[i++] = (byte)((UsecSinceStart >> 32) % 256); bytes[i++] = (byte)((UsecSinceStart >> 40) % 256); bytes[i++] = (byte)((UsecSinceStart >> 48) % 256); bytes[i++] = (byte)((UsecSinceStart >> 56) % 256); bytes[i++] = (byte)(SecPerYear % 256); bytes[i++] = (byte)((SecPerYear >> 8) % 256); bytes[i++] = (byte)((SecPerYear >> 16) % 256); bytes[i++] = (byte)((SecPerYear >> 24) % 256); if(SunAngVelocity == null) { Console.WriteLine("Warning: SunAngVelocity is null, in " + this.GetType()); } Array.Copy(SunAngVelocity.GetBytes(), 0, bytes, i, 12); i += 12; ba = BitConverter.GetBytes(SunPhase); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(SunDirection == null) { Console.WriteLine("Warning: SunDirection is null, in " + this.GetType()); } Array.Copy(SunDirection.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TimeInfo --\n"; output += "SecPerDay: " + SecPerDay.ToString() + "\n"; output += "UsecSinceStart: " + UsecSinceStart.ToString() + "\n"; output += "SecPerYear: " + SecPerYear.ToString() + "\n"; output += "SunAngVelocity: " + SunAngVelocity.ToString() + "\n"; output += "SunPhase: " + SunPhase.ToString() + "\n"; output += "SunDirection: " + SunDirection.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SpaceServerSimulatorTimeMessage public override PacketType Type { get { return PacketType.SpaceServerSimulatorTimeMessage; } } /// TimeInfo block public TimeInfoBlock TimeInfo; /// Default constructor public SpaceServerSimulatorTimeMessagePacket() { Header = new LowHeader(); Header.ID = 8; Header.Reliable = true; TimeInfo = new TimeInfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SpaceServerSimulatorTimeMessagePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TimeInfo = new TimeInfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SpaceServerSimulatorTimeMessagePacket(Header head, byte[] bytes, ref int i) { Header = head; TimeInfo = new TimeInfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TimeInfo.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TimeInfo.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SpaceServerSimulatorTimeMessage ---\n"; output += TimeInfo.ToString() + "\n"; return output; } } /// AvatarTextureUpdate packet public class AvatarTextureUpdatePacket : Packet { /// WearableData block public class WearableDataBlock { /// TextureIndex field public byte TextureIndex; private byte[] _hostname; /// HostName field public byte[] HostName { get { return _hostname; } set { if (value == null) { _hostname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _hostname = new byte[value.Length]; Array.Copy(value, _hostname, value.Length); } } } /// CacheID field public LLUUID CacheID; /// Length of this block serialized in bytes public int Length { get { int length = 17; if (HostName != null) { length += 1 + HostName.Length; } return length; } } /// Default constructor public WearableDataBlock() { } /// Constructor for building the block from a byte array public WearableDataBlock(byte[] bytes, ref int i) { int length; try { TextureIndex = (byte)bytes[i++]; length = (ushort)bytes[i++]; _hostname = new byte[length]; Array.Copy(bytes, i, _hostname, 0, length); i += length; CacheID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = TextureIndex; if(HostName == null) { Console.WriteLine("Warning: HostName is null, in " + this.GetType()); } bytes[i++] = (byte)HostName.Length; Array.Copy(HostName, 0, bytes, i, HostName.Length); i += HostName.Length; if(CacheID == null) { Console.WriteLine("Warning: CacheID is null, in " + this.GetType()); } Array.Copy(CacheID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- WearableData --\n"; output += "TextureIndex: " + TextureIndex.ToString() + "\n"; output += Helpers.FieldToString(HostName, "HostName") + "\n"; output += "CacheID: " + CacheID.ToString() + "\n"; output = output.Trim(); return output; } } /// TextureData block public class TextureDataBlock { /// TextureID field public LLUUID TextureID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public TextureDataBlock() { } /// Constructor for building the block from a byte array public TextureDataBlock(byte[] bytes, ref int i) { try { TextureID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TextureID == null) { Console.WriteLine("Warning: TextureID is null, in " + this.GetType()); } Array.Copy(TextureID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TextureData --\n"; output += "TextureID: " + TextureID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// TexturesChanged field public bool TexturesChanged; /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 17; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { TexturesChanged = (bytes[i++] != 0) ? (bool)true : (bool)false; AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((TexturesChanged) ? 1 : 0); if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "TexturesChanged: " + TexturesChanged.ToString() + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AvatarTextureUpdate public override PacketType Type { get { return PacketType.AvatarTextureUpdate; } } /// WearableData block public WearableDataBlock[] WearableData; /// TextureData block public TextureDataBlock[] TextureData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AvatarTextureUpdatePacket() { Header = new LowHeader(); Header.ID = 9; Header.Reliable = true; Header.Zerocoded = true; WearableData = new WearableDataBlock[0]; TextureData = new TextureDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AvatarTextureUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; WearableData = new WearableDataBlock[count]; for (int j = 0; j < count; j++) { WearableData[j] = new WearableDataBlock(bytes, ref i); } count = (int)bytes[i++]; TextureData = new TextureDataBlock[count]; for (int j = 0; j < count; j++) { TextureData[j] = new TextureDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AvatarTextureUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; WearableData = new WearableDataBlock[count]; for (int j = 0; j < count; j++) { WearableData[j] = new WearableDataBlock(bytes, ref i); } count = (int)bytes[i++]; TextureData = new TextureDataBlock[count]; for (int j = 0; j < count; j++) { TextureData[j] = new TextureDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < WearableData.Length; j++) { length += WearableData[j].Length; } length++; for (int j = 0; j < TextureData.Length; j++) { length += TextureData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)WearableData.Length; for (int j = 0; j < WearableData.Length; j++) { WearableData[j].ToBytes(bytes, ref i); } bytes[i++] = (byte)TextureData.Length; for (int j = 0; j < TextureData.Length; j++) { TextureData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AvatarTextureUpdate ---\n"; for (int j = 0; j < WearableData.Length; j++) { output += WearableData[j].ToString() + "\n"; } for (int j = 0; j < TextureData.Length; j++) { output += TextureData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// SimulatorMapUpdate packet public class SimulatorMapUpdatePacket : Packet { /// MapData block public class MapDataBlock { /// Flags field public uint Flags; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public MapDataBlock() { } /// Constructor for building the block from a byte array public MapDataBlock(byte[] bytes, ref int i) { try { Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MapData --\n"; output += "Flags: " + Flags.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SimulatorMapUpdate public override PacketType Type { get { return PacketType.SimulatorMapUpdate; } } /// MapData block public MapDataBlock MapData; /// Default constructor public SimulatorMapUpdatePacket() { Header = new LowHeader(); Header.ID = 10; Header.Reliable = true; MapData = new MapDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SimulatorMapUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MapData = new MapDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SimulatorMapUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; MapData = new MapDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MapData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MapData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SimulatorMapUpdate ---\n"; output += MapData.ToString() + "\n"; return output; } } /// SimulatorSetMap packet public class SimulatorSetMapPacket : Packet { /// MapData block public class MapDataBlock { /// MapImage field public LLUUID MapImage; /// Type field public int Type; /// RegionHandle field public ulong RegionHandle; /// Length of this block serialized in bytes public int Length { get { return 28; } } /// Default constructor public MapDataBlock() { } /// Constructor for building the block from a byte array public MapDataBlock(byte[] bytes, ref int i) { try { MapImage = new LLUUID(bytes, i); i += 16; Type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(MapImage == null) { Console.WriteLine("Warning: MapImage is null, in " + this.GetType()); } Array.Copy(MapImage.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Type % 256); bytes[i++] = (byte)((Type >> 8) % 256); bytes[i++] = (byte)((Type >> 16) % 256); bytes[i++] = (byte)((Type >> 24) % 256); bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MapData --\n"; output += "MapImage: " + MapImage.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SimulatorSetMap public override PacketType Type { get { return PacketType.SimulatorSetMap; } } /// MapData block public MapDataBlock MapData; /// Default constructor public SimulatorSetMapPacket() { Header = new LowHeader(); Header.ID = 11; Header.Reliable = true; MapData = new MapDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SimulatorSetMapPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MapData = new MapDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SimulatorSetMapPacket(Header head, byte[] bytes, ref int i) { Header = head; MapData = new MapDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MapData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MapData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SimulatorSetMap ---\n"; output += MapData.ToString() + "\n"; return output; } } /// SubscribeLoad packet public class SubscribeLoadPacket : Packet { private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SubscribeLoad public override PacketType Type { get { return PacketType.SubscribeLoad; } } /// Default constructor public SubscribeLoadPacket() { Header = new LowHeader(); Header.ID = 12; Header.Reliable = true; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SubscribeLoadPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); } /// Constructor that takes a byte array and a prebuilt header public SubscribeLoadPacket(Header head, byte[] bytes, ref int i) { Header = head; } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SubscribeLoad ---\n"; return output; } } /// UnsubscribeLoad packet public class UnsubscribeLoadPacket : Packet { private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UnsubscribeLoad public override PacketType Type { get { return PacketType.UnsubscribeLoad; } } /// Default constructor public UnsubscribeLoadPacket() { Header = new LowHeader(); Header.ID = 13; Header.Reliable = true; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UnsubscribeLoadPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); } /// Constructor that takes a byte array and a prebuilt header public UnsubscribeLoadPacket(Header head, byte[] bytes, ref int i) { Header = head; } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UnsubscribeLoad ---\n"; return output; } } /// SimulatorStart packet public class SimulatorStartPacket : Packet { /// PositionSuggestion block public class PositionSuggestionBlock { /// Ignore field public bool Ignore; /// GridX field public int GridX; /// GridY field public int GridY; /// Length of this block serialized in bytes public int Length { get { return 9; } } /// Default constructor public PositionSuggestionBlock() { } /// Constructor for building the block from a byte array public PositionSuggestionBlock(byte[] bytes, ref int i) { try { Ignore = (bytes[i++] != 0) ? (bool)true : (bool)false; GridX = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GridY = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((Ignore) ? 1 : 0); bytes[i++] = (byte)(GridX % 256); bytes[i++] = (byte)((GridX >> 8) % 256); bytes[i++] = (byte)((GridX >> 16) % 256); bytes[i++] = (byte)((GridX >> 24) % 256); bytes[i++] = (byte)(GridY % 256); bytes[i++] = (byte)((GridY >> 8) % 256); bytes[i++] = (byte)((GridY >> 16) % 256); bytes[i++] = (byte)((GridY >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- PositionSuggestion --\n"; output += "Ignore: " + Ignore.ToString() + "\n"; output += "GridX: " + GridX.ToString() + "\n"; output += "GridY: " + GridY.ToString() + "\n"; output = output.Trim(); return output; } } /// ControlPort block public class ControlPortBlock { /// PublicPort field public ushort PublicPort; /// Port field public ushort Port; /// PublicIP field public uint PublicIP; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public ControlPortBlock() { } /// Constructor for building the block from a byte array public ControlPortBlock(byte[] bytes, ref int i) { try { PublicPort = (ushort)((bytes[i++] << 8) + bytes[i++]); Port = (ushort)((bytes[i++] << 8) + bytes[i++]); PublicIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((PublicPort >> 8) % 256); bytes[i++] = (byte)(PublicPort % 256); bytes[i++] = (byte)((Port >> 8) % 256); bytes[i++] = (byte)(Port % 256); bytes[i++] = (byte)(PublicIP % 256); bytes[i++] = (byte)((PublicIP >> 8) % 256); bytes[i++] = (byte)((PublicIP >> 16) % 256); bytes[i++] = (byte)((PublicIP >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ControlPort --\n"; output += "PublicPort: " + PublicPort.ToString() + "\n"; output += "Port: " + Port.ToString() + "\n"; output += "PublicIP: " + PublicIP.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SimulatorStart public override PacketType Type { get { return PacketType.SimulatorStart; } } /// PositionSuggestion block public PositionSuggestionBlock PositionSuggestion; /// ControlPort block public ControlPortBlock ControlPort; /// Default constructor public SimulatorStartPacket() { Header = new LowHeader(); Header.ID = 14; Header.Reliable = true; PositionSuggestion = new PositionSuggestionBlock(); ControlPort = new ControlPortBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SimulatorStartPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); PositionSuggestion = new PositionSuggestionBlock(bytes, ref i); ControlPort = new ControlPortBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SimulatorStartPacket(Header head, byte[] bytes, ref int i) { Header = head; PositionSuggestion = new PositionSuggestionBlock(bytes, ref i); ControlPort = new ControlPortBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += PositionSuggestion.Length; length += ControlPort.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); PositionSuggestion.ToBytes(bytes, ref i); ControlPort.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SimulatorStart ---\n"; output += PositionSuggestion.ToString() + "\n"; output += ControlPort.ToString() + "\n"; return output; } } /// SimulatorReady packet public class SimulatorReadyPacket : Packet { /// TelehubBlock block public class TelehubBlockBlock { /// HasTelehub field public bool HasTelehub; /// TelehubPos field public LLVector3 TelehubPos; /// Length of this block serialized in bytes public int Length { get { return 13; } } /// Default constructor public TelehubBlockBlock() { } /// Constructor for building the block from a byte array public TelehubBlockBlock(byte[] bytes, ref int i) { try { HasTelehub = (bytes[i++] != 0) ? (bool)true : (bool)false; TelehubPos = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((HasTelehub) ? 1 : 0); if(TelehubPos == null) { Console.WriteLine("Warning: TelehubPos is null, in " + this.GetType()); } Array.Copy(TelehubPos.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TelehubBlock --\n"; output += "HasTelehub: " + HasTelehub.ToString() + "\n"; output += "TelehubPos: " + TelehubPos.ToString() + "\n"; output = output.Trim(); return output; } } /// SimulatorBlock block public class SimulatorBlockBlock { private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// RegionFlags field public uint RegionFlags; /// RegionID field public LLUUID RegionID; /// SimAccess field public byte SimAccess; /// ParentEstateID field public uint ParentEstateID; /// EstateID field public uint EstateID; /// Length of this block serialized in bytes public int Length { get { int length = 29; if (SimName != null) { length += 1 + SimName.Length; } return length; } } /// Default constructor public SimulatorBlockBlock() { } /// Constructor for building the block from a byte array public SimulatorBlockBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; RegionFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RegionID = new LLUUID(bytes, i); i += 16; SimAccess = (byte)bytes[i++]; ParentEstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; bytes[i++] = (byte)(RegionFlags % 256); bytes[i++] = (byte)((RegionFlags >> 8) % 256); bytes[i++] = (byte)((RegionFlags >> 16) % 256); bytes[i++] = (byte)((RegionFlags >> 24) % 256); if(RegionID == null) { Console.WriteLine("Warning: RegionID is null, in " + this.GetType()); } Array.Copy(RegionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = SimAccess; bytes[i++] = (byte)(ParentEstateID % 256); bytes[i++] = (byte)((ParentEstateID >> 8) % 256); bytes[i++] = (byte)((ParentEstateID >> 16) % 256); bytes[i++] = (byte)((ParentEstateID >> 24) % 256); bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- SimulatorBlock --\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "RegionFlags: " + RegionFlags.ToString() + "\n"; output += "RegionID: " + RegionID.ToString() + "\n"; output += "SimAccess: " + SimAccess.ToString() + "\n"; output += "ParentEstateID: " + ParentEstateID.ToString() + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SimulatorReady public override PacketType Type { get { return PacketType.SimulatorReady; } } /// TelehubBlock block public TelehubBlockBlock TelehubBlock; /// SimulatorBlock block public SimulatorBlockBlock SimulatorBlock; /// Default constructor public SimulatorReadyPacket() { Header = new LowHeader(); Header.ID = 15; Header.Reliable = true; Header.Zerocoded = true; TelehubBlock = new TelehubBlockBlock(); SimulatorBlock = new SimulatorBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SimulatorReadyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TelehubBlock = new TelehubBlockBlock(bytes, ref i); SimulatorBlock = new SimulatorBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SimulatorReadyPacket(Header head, byte[] bytes, ref int i) { Header = head; TelehubBlock = new TelehubBlockBlock(bytes, ref i); SimulatorBlock = new SimulatorBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TelehubBlock.Length; length += SimulatorBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TelehubBlock.ToBytes(bytes, ref i); SimulatorBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SimulatorReady ---\n"; output += TelehubBlock.ToString() + "\n"; output += SimulatorBlock.ToString() + "\n"; return output; } } /// TelehubInfo packet public class TelehubInfoPacket : Packet { /// TelehubBlock block public class TelehubBlockBlock { private byte[] _objectname; /// ObjectName field public byte[] ObjectName { get { return _objectname; } set { if (value == null) { _objectname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _objectname = new byte[value.Length]; Array.Copy(value, _objectname, value.Length); } } } /// ObjectID field public LLUUID ObjectID; /// TelehubPos field public LLVector3 TelehubPos; /// TelehubRot field public LLQuaternion TelehubRot; /// Length of this block serialized in bytes public int Length { get { int length = 40; if (ObjectName != null) { length += 1 + ObjectName.Length; } return length; } } /// Default constructor public TelehubBlockBlock() { } /// Constructor for building the block from a byte array public TelehubBlockBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _objectname = new byte[length]; Array.Copy(bytes, i, _objectname, 0, length); i += length; ObjectID = new LLUUID(bytes, i); i += 16; TelehubPos = new LLVector3(bytes, i); i += 12; TelehubRot = new LLQuaternion(bytes, i, true); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectName == null) { Console.WriteLine("Warning: ObjectName is null, in " + this.GetType()); } bytes[i++] = (byte)ObjectName.Length; Array.Copy(ObjectName, 0, bytes, i, ObjectName.Length); i += ObjectName.Length; if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; if(TelehubPos == null) { Console.WriteLine("Warning: TelehubPos is null, in " + this.GetType()); } Array.Copy(TelehubPos.GetBytes(), 0, bytes, i, 12); i += 12; if(TelehubRot == null) { Console.WriteLine("Warning: TelehubRot is null, in " + this.GetType()); } Array.Copy(TelehubRot.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TelehubBlock --\n"; output += Helpers.FieldToString(ObjectName, "ObjectName") + "\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "TelehubPos: " + TelehubPos.ToString() + "\n"; output += "TelehubRot: " + TelehubRot.ToString() + "\n"; output = output.Trim(); return output; } } /// SpawnPointBlock block public class SpawnPointBlockBlock { /// SpawnPointPos field public LLVector3 SpawnPointPos; /// Length of this block serialized in bytes public int Length { get { return 12; } } /// Default constructor public SpawnPointBlockBlock() { } /// Constructor for building the block from a byte array public SpawnPointBlockBlock(byte[] bytes, ref int i) { try { SpawnPointPos = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(SpawnPointPos == null) { Console.WriteLine("Warning: SpawnPointPos is null, in " + this.GetType()); } Array.Copy(SpawnPointPos.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- SpawnPointBlock --\n"; output += "SpawnPointPos: " + SpawnPointPos.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TelehubInfo public override PacketType Type { get { return PacketType.TelehubInfo; } } /// TelehubBlock block public TelehubBlockBlock TelehubBlock; /// SpawnPointBlock block public SpawnPointBlockBlock[] SpawnPointBlock; /// Default constructor public TelehubInfoPacket() { Header = new LowHeader(); Header.ID = 16; Header.Reliable = true; TelehubBlock = new TelehubBlockBlock(); SpawnPointBlock = new SpawnPointBlockBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TelehubInfoPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TelehubBlock = new TelehubBlockBlock(bytes, ref i); int count = (int)bytes[i++]; SpawnPointBlock = new SpawnPointBlockBlock[count]; for (int j = 0; j < count; j++) { SpawnPointBlock[j] = new SpawnPointBlockBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public TelehubInfoPacket(Header head, byte[] bytes, ref int i) { Header = head; TelehubBlock = new TelehubBlockBlock(bytes, ref i); int count = (int)bytes[i++]; SpawnPointBlock = new SpawnPointBlockBlock[count]; for (int j = 0; j < count; j++) { SpawnPointBlock[j] = new SpawnPointBlockBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TelehubBlock.Length;; length++; for (int j = 0; j < SpawnPointBlock.Length; j++) { length += SpawnPointBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TelehubBlock.ToBytes(bytes, ref i); bytes[i++] = (byte)SpawnPointBlock.Length; for (int j = 0; j < SpawnPointBlock.Length; j++) { SpawnPointBlock[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TelehubInfo ---\n"; output += TelehubBlock.ToString() + "\n"; for (int j = 0; j < SpawnPointBlock.Length; j++) { output += SpawnPointBlock[j].ToString() + "\n"; } return output; } } /// SimulatorPresentAtLocation packet public class SimulatorPresentAtLocationPacket : Packet { /// TelehubBlock block public class TelehubBlockBlock { /// HasTelehub field public bool HasTelehub; /// TelehubPos field public LLVector3 TelehubPos; /// Length of this block serialized in bytes public int Length { get { return 13; } } /// Default constructor public TelehubBlockBlock() { } /// Constructor for building the block from a byte array public TelehubBlockBlock(byte[] bytes, ref int i) { try { HasTelehub = (bytes[i++] != 0) ? (bool)true : (bool)false; TelehubPos = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((HasTelehub) ? 1 : 0); if(TelehubPos == null) { Console.WriteLine("Warning: TelehubPos is null, in " + this.GetType()); } Array.Copy(TelehubPos.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TelehubBlock --\n"; output += "HasTelehub: " + HasTelehub.ToString() + "\n"; output += "TelehubPos: " + TelehubPos.ToString() + "\n"; output = output.Trim(); return output; } } /// SimulatorBlock block public class SimulatorBlockBlock { private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// RegionFlags field public uint RegionFlags; /// RegionID field public LLUUID RegionID; /// SimAccess field public byte SimAccess; /// ParentEstateID field public uint ParentEstateID; /// EstateID field public uint EstateID; /// Length of this block serialized in bytes public int Length { get { int length = 29; if (SimName != null) { length += 1 + SimName.Length; } return length; } } /// Default constructor public SimulatorBlockBlock() { } /// Constructor for building the block from a byte array public SimulatorBlockBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; RegionFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RegionID = new LLUUID(bytes, i); i += 16; SimAccess = (byte)bytes[i++]; ParentEstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; bytes[i++] = (byte)(RegionFlags % 256); bytes[i++] = (byte)((RegionFlags >> 8) % 256); bytes[i++] = (byte)((RegionFlags >> 16) % 256); bytes[i++] = (byte)((RegionFlags >> 24) % 256); if(RegionID == null) { Console.WriteLine("Warning: RegionID is null, in " + this.GetType()); } Array.Copy(RegionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = SimAccess; bytes[i++] = (byte)(ParentEstateID % 256); bytes[i++] = (byte)((ParentEstateID >> 8) % 256); bytes[i++] = (byte)((ParentEstateID >> 16) % 256); bytes[i++] = (byte)((ParentEstateID >> 24) % 256); bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- SimulatorBlock --\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "RegionFlags: " + RegionFlags.ToString() + "\n"; output += "RegionID: " + RegionID.ToString() + "\n"; output += "SimAccess: " + SimAccess.ToString() + "\n"; output += "ParentEstateID: " + ParentEstateID.ToString() + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output = output.Trim(); return output; } } /// SimulatorPublicHostBlock block public class SimulatorPublicHostBlockBlock { /// Port field public ushort Port; /// SimulatorIP field public uint SimulatorIP; /// GridX field public uint GridX; /// GridY field public uint GridY; /// Length of this block serialized in bytes public int Length { get { return 14; } } /// Default constructor public SimulatorPublicHostBlockBlock() { } /// Constructor for building the block from a byte array public SimulatorPublicHostBlockBlock(byte[] bytes, ref int i) { try { Port = (ushort)((bytes[i++] << 8) + bytes[i++]); SimulatorIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GridX = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GridY = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((Port >> 8) % 256); bytes[i++] = (byte)(Port % 256); bytes[i++] = (byte)(SimulatorIP % 256); bytes[i++] = (byte)((SimulatorIP >> 8) % 256); bytes[i++] = (byte)((SimulatorIP >> 16) % 256); bytes[i++] = (byte)((SimulatorIP >> 24) % 256); bytes[i++] = (byte)(GridX % 256); bytes[i++] = (byte)((GridX >> 8) % 256); bytes[i++] = (byte)((GridX >> 16) % 256); bytes[i++] = (byte)((GridX >> 24) % 256); bytes[i++] = (byte)(GridY % 256); bytes[i++] = (byte)((GridY >> 8) % 256); bytes[i++] = (byte)((GridY >> 16) % 256); bytes[i++] = (byte)((GridY >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- SimulatorPublicHostBlock --\n"; output += "Port: " + Port.ToString() + "\n"; output += "SimulatorIP: " + SimulatorIP.ToString() + "\n"; output += "GridX: " + GridX.ToString() + "\n"; output += "GridY: " + GridY.ToString() + "\n"; output = output.Trim(); return output; } } /// NeighborBlock block public class NeighborBlockBlock { /// IP field public uint IP; /// Port field public ushort Port; /// Length of this block serialized in bytes public int Length { get { return 6; } } /// Default constructor public NeighborBlockBlock() { } /// Constructor for building the block from a byte array public NeighborBlockBlock(byte[] bytes, ref int i) { try { IP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Port = (ushort)((bytes[i++] << 8) + bytes[i++]); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(IP % 256); bytes[i++] = (byte)((IP >> 8) % 256); bytes[i++] = (byte)((IP >> 16) % 256); bytes[i++] = (byte)((IP >> 24) % 256); bytes[i++] = (byte)((Port >> 8) % 256); bytes[i++] = (byte)(Port % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- NeighborBlock --\n"; output += "IP: " + IP.ToString() + "\n"; output += "Port: " + Port.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SimulatorPresentAtLocation public override PacketType Type { get { return PacketType.SimulatorPresentAtLocation; } } /// TelehubBlock block public TelehubBlockBlock[] TelehubBlock; /// SimulatorBlock block public SimulatorBlockBlock SimulatorBlock; /// SimulatorPublicHostBlock block public SimulatorPublicHostBlockBlock SimulatorPublicHostBlock; /// NeighborBlock block public NeighborBlockBlock[] NeighborBlock; /// Default constructor public SimulatorPresentAtLocationPacket() { Header = new LowHeader(); Header.ID = 17; Header.Reliable = true; TelehubBlock = new TelehubBlockBlock[0]; SimulatorBlock = new SimulatorBlockBlock(); SimulatorPublicHostBlock = new SimulatorPublicHostBlockBlock(); NeighborBlock = new NeighborBlockBlock[4]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SimulatorPresentAtLocationPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; TelehubBlock = new TelehubBlockBlock[count]; for (int j = 0; j < count; j++) { TelehubBlock[j] = new TelehubBlockBlock(bytes, ref i); } SimulatorBlock = new SimulatorBlockBlock(bytes, ref i); SimulatorPublicHostBlock = new SimulatorPublicHostBlockBlock(bytes, ref i); NeighborBlock = new NeighborBlockBlock[4]; for (int j = 0; j < 4; j++) { NeighborBlock[j] = new NeighborBlockBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public SimulatorPresentAtLocationPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; TelehubBlock = new TelehubBlockBlock[count]; for (int j = 0; j < count; j++) { TelehubBlock[j] = new TelehubBlockBlock(bytes, ref i); } SimulatorBlock = new SimulatorBlockBlock(bytes, ref i); SimulatorPublicHostBlock = new SimulatorPublicHostBlockBlock(bytes, ref i); NeighborBlock = new NeighborBlockBlock[4]; for (int j = 0; j < 4; j++) { NeighborBlock[j] = new NeighborBlockBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += SimulatorBlock.Length; length += SimulatorPublicHostBlock.Length;; length++; for (int j = 0; j < TelehubBlock.Length; j++) { length += TelehubBlock[j].Length; } for (int j = 0; j < 4; j++) { length += NeighborBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)TelehubBlock.Length; for (int j = 0; j < TelehubBlock.Length; j++) { TelehubBlock[j].ToBytes(bytes, ref i); } SimulatorBlock.ToBytes(bytes, ref i); SimulatorPublicHostBlock.ToBytes(bytes, ref i); for (int j = 0; j < 4; j++) { NeighborBlock[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SimulatorPresentAtLocation ---\n"; for (int j = 0; j < TelehubBlock.Length; j++) { output += TelehubBlock[j].ToString() + "\n"; } output += SimulatorBlock.ToString() + "\n"; output += SimulatorPublicHostBlock.ToString() + "\n"; for (int j = 0; j < 4; j++) { output += NeighborBlock[j].ToString() + "\n"; } return output; } } /// SimulatorLoad packet public class SimulatorLoadPacket : Packet { /// SimulatorLoad block public class SimulatorLoadBlock { /// CanAcceptAgents field public bool CanAcceptAgents; /// TimeDilation field public float TimeDilation; /// AgentCount field public int AgentCount; /// Length of this block serialized in bytes public int Length { get { return 9; } } /// Default constructor public SimulatorLoadBlock() { } /// Constructor for building the block from a byte array public SimulatorLoadBlock(byte[] bytes, ref int i) { try { CanAcceptAgents = (bytes[i++] != 0) ? (bool)true : (bool)false; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); TimeDilation = BitConverter.ToSingle(bytes, i); i += 4; AgentCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = (byte)((CanAcceptAgents) ? 1 : 0); ba = BitConverter.GetBytes(TimeDilation); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(AgentCount % 256); bytes[i++] = (byte)((AgentCount >> 8) % 256); bytes[i++] = (byte)((AgentCount >> 16) % 256); bytes[i++] = (byte)((AgentCount >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- SimulatorLoad --\n"; output += "CanAcceptAgents: " + CanAcceptAgents.ToString() + "\n"; output += "TimeDilation: " + TimeDilation.ToString() + "\n"; output += "AgentCount: " + AgentCount.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentList block public class AgentListBlock { /// X field public byte X; /// Y field public byte Y; /// CircuitCode field public uint CircuitCode; /// Length of this block serialized in bytes public int Length { get { return 6; } } /// Default constructor public AgentListBlock() { } /// Constructor for building the block from a byte array public AgentListBlock(byte[] bytes, ref int i) { try { X = (byte)bytes[i++]; Y = (byte)bytes[i++]; CircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = X; bytes[i++] = Y; bytes[i++] = (byte)(CircuitCode % 256); bytes[i++] = (byte)((CircuitCode >> 8) % 256); bytes[i++] = (byte)((CircuitCode >> 16) % 256); bytes[i++] = (byte)((CircuitCode >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentList --\n"; output += "X: " + X.ToString() + "\n"; output += "Y: " + Y.ToString() + "\n"; output += "CircuitCode: " + CircuitCode.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SimulatorLoad public override PacketType Type { get { return PacketType.SimulatorLoad; } } /// SimulatorLoad block public SimulatorLoadBlock SimulatorLoad; /// AgentList block public AgentListBlock[] AgentList; /// Default constructor public SimulatorLoadPacket() { Header = new LowHeader(); Header.ID = 18; Header.Reliable = true; SimulatorLoad = new SimulatorLoadBlock(); AgentList = new AgentListBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SimulatorLoadPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); SimulatorLoad = new SimulatorLoadBlock(bytes, ref i); int count = (int)bytes[i++]; AgentList = new AgentListBlock[count]; for (int j = 0; j < count; j++) { AgentList[j] = new AgentListBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public SimulatorLoadPacket(Header head, byte[] bytes, ref int i) { Header = head; SimulatorLoad = new SimulatorLoadBlock(bytes, ref i); int count = (int)bytes[i++]; AgentList = new AgentListBlock[count]; for (int j = 0; j < count; j++) { AgentList[j] = new AgentListBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += SimulatorLoad.Length;; length++; for (int j = 0; j < AgentList.Length; j++) { length += AgentList[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); SimulatorLoad.ToBytes(bytes, ref i); bytes[i++] = (byte)AgentList.Length; for (int j = 0; j < AgentList.Length; j++) { AgentList[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SimulatorLoad ---\n"; output += SimulatorLoad.ToString() + "\n"; for (int j = 0; j < AgentList.Length; j++) { output += AgentList[j].ToString() + "\n"; } return output; } } /// SimulatorShutdownRequest packet public class SimulatorShutdownRequestPacket : Packet { private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SimulatorShutdownRequest public override PacketType Type { get { return PacketType.SimulatorShutdownRequest; } } /// Default constructor public SimulatorShutdownRequestPacket() { Header = new LowHeader(); Header.ID = 19; Header.Reliable = true; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SimulatorShutdownRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); } /// Constructor that takes a byte array and a prebuilt header public SimulatorShutdownRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SimulatorShutdownRequest ---\n"; return output; } } /// RegionPresenceRequestByRegionID packet public class RegionPresenceRequestByRegionIDPacket : Packet { /// RegionData block public class RegionDataBlock { /// RegionID field public LLUUID RegionID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public RegionDataBlock() { } /// Constructor for building the block from a byte array public RegionDataBlock(byte[] bytes, ref int i) { try { RegionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RegionID == null) { Console.WriteLine("Warning: RegionID is null, in " + this.GetType()); } Array.Copy(RegionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionData --\n"; output += "RegionID: " + RegionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RegionPresenceRequestByRegionID public override PacketType Type { get { return PacketType.RegionPresenceRequestByRegionID; } } /// RegionData block public RegionDataBlock[] RegionData; /// Default constructor public RegionPresenceRequestByRegionIDPacket() { Header = new LowHeader(); Header.ID = 20; Header.Reliable = true; RegionData = new RegionDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RegionPresenceRequestByRegionIDPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; RegionData = new RegionDataBlock[count]; for (int j = 0; j < count; j++) { RegionData[j] = new RegionDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public RegionPresenceRequestByRegionIDPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; RegionData = new RegionDataBlock[count]; for (int j = 0; j < count; j++) { RegionData[j] = new RegionDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < RegionData.Length; j++) { length += RegionData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)RegionData.Length; for (int j = 0; j < RegionData.Length; j++) { RegionData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RegionPresenceRequestByRegionID ---\n"; for (int j = 0; j < RegionData.Length; j++) { output += RegionData[j].ToString() + "\n"; } return output; } } /// RegionPresenceRequestByHandle packet public class RegionPresenceRequestByHandlePacket : Packet { /// RegionData block public class RegionDataBlock { /// RegionHandle field public ulong RegionHandle; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public RegionDataBlock() { } /// Constructor for building the block from a byte array public RegionDataBlock(byte[] bytes, ref int i) { try { RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionData --\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RegionPresenceRequestByHandle public override PacketType Type { get { return PacketType.RegionPresenceRequestByHandle; } } /// RegionData block public RegionDataBlock[] RegionData; /// Default constructor public RegionPresenceRequestByHandlePacket() { Header = new LowHeader(); Header.ID = 21; Header.Reliable = true; RegionData = new RegionDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RegionPresenceRequestByHandlePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; RegionData = new RegionDataBlock[count]; for (int j = 0; j < count; j++) { RegionData[j] = new RegionDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public RegionPresenceRequestByHandlePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; RegionData = new RegionDataBlock[count]; for (int j = 0; j < count; j++) { RegionData[j] = new RegionDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < RegionData.Length; j++) { length += RegionData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)RegionData.Length; for (int j = 0; j < RegionData.Length; j++) { RegionData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RegionPresenceRequestByHandle ---\n"; for (int j = 0; j < RegionData.Length; j++) { output += RegionData[j].ToString() + "\n"; } return output; } } /// RegionPresenceResponse packet public class RegionPresenceResponsePacket : Packet { /// RegionData block public class RegionDataBlock { /// ValidUntil field public double ValidUntil; /// InternalRegionIP field public uint InternalRegionIP; /// ExternalRegionIP field public uint ExternalRegionIP; private byte[] _message; /// Message field public byte[] Message { get { return _message; } set { if (value == null) { _message = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _message = new byte[value.Length]; Array.Copy(value, _message, value.Length); } } } /// RegionID field public LLUUID RegionID; /// RegionHandle field public ulong RegionHandle; /// RegionPort field public ushort RegionPort; /// Length of this block serialized in bytes public int Length { get { int length = 42; if (Message != null) { length += 1 + Message.Length; } return length; } } /// Default constructor public RegionDataBlock() { } /// Constructor for building the block from a byte array public RegionDataBlock(byte[] bytes, ref int i) { int length; try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 8); ValidUntil = BitConverter.ToDouble(bytes, i); i += 8; InternalRegionIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ExternalRegionIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _message = new byte[length]; Array.Copy(bytes, i, _message, 0, length); i += length; RegionID = new LLUUID(bytes, i); i += 16; RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); RegionPort = (ushort)((bytes[i++] << 8) + bytes[i++]); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(ValidUntil); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 8); } Array.Copy(ba, 0, bytes, i, 8); i += 8; bytes[i++] = (byte)(InternalRegionIP % 256); bytes[i++] = (byte)((InternalRegionIP >> 8) % 256); bytes[i++] = (byte)((InternalRegionIP >> 16) % 256); bytes[i++] = (byte)((InternalRegionIP >> 24) % 256); bytes[i++] = (byte)(ExternalRegionIP % 256); bytes[i++] = (byte)((ExternalRegionIP >> 8) % 256); bytes[i++] = (byte)((ExternalRegionIP >> 16) % 256); bytes[i++] = (byte)((ExternalRegionIP >> 24) % 256); if(Message == null) { Console.WriteLine("Warning: Message is null, in " + this.GetType()); } bytes[i++] = (byte)Message.Length; Array.Copy(Message, 0, bytes, i, Message.Length); i += Message.Length; if(RegionID == null) { Console.WriteLine("Warning: RegionID is null, in " + this.GetType()); } Array.Copy(RegionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); bytes[i++] = (byte)((RegionPort >> 8) % 256); bytes[i++] = (byte)(RegionPort % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionData --\n"; output += "ValidUntil: " + ValidUntil.ToString() + "\n"; output += "InternalRegionIP: " + InternalRegionIP.ToString() + "\n"; output += "ExternalRegionIP: " + ExternalRegionIP.ToString() + "\n"; output += Helpers.FieldToString(Message, "Message") + "\n"; output += "RegionID: " + RegionID.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output += "RegionPort: " + RegionPort.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RegionPresenceResponse public override PacketType Type { get { return PacketType.RegionPresenceResponse; } } /// RegionData block public RegionDataBlock[] RegionData; /// Default constructor public RegionPresenceResponsePacket() { Header = new LowHeader(); Header.ID = 22; Header.Reliable = true; Header.Zerocoded = true; RegionData = new RegionDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RegionPresenceResponsePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; RegionData = new RegionDataBlock[count]; for (int j = 0; j < count; j++) { RegionData[j] = new RegionDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public RegionPresenceResponsePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; RegionData = new RegionDataBlock[count]; for (int j = 0; j < count; j++) { RegionData[j] = new RegionDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < RegionData.Length; j++) { length += RegionData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)RegionData.Length; for (int j = 0; j < RegionData.Length; j++) { RegionData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RegionPresenceResponse ---\n"; for (int j = 0; j < RegionData.Length; j++) { output += RegionData[j].ToString() + "\n"; } return output; } } /// RecordAgentPresence packet public class RecordAgentPresencePacket : Packet { /// RegionData block public class RegionDataBlock { /// RegionID field public LLUUID RegionID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public RegionDataBlock() { } /// Constructor for building the block from a byte array public RegionDataBlock(byte[] bytes, ref int i) { try { RegionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RegionID == null) { Console.WriteLine("Warning: RegionID is null, in " + this.GetType()); } Array.Copy(RegionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionData --\n"; output += "RegionID: " + RegionID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// LocalX field public short LocalX; /// LocalY field public short LocalY; /// Status field public int Status; /// SecureSessionID field public LLUUID SecureSessionID; /// EstateID field public uint EstateID; /// TimeToLive field public int TimeToLive; /// Length of this block serialized in bytes public int Length { get { return 64; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; LocalX = (short)(bytes[i++] + (bytes[i++] << 8)); LocalY = (short)(bytes[i++] + (bytes[i++] << 8)); Status = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SecureSessionID = new LLUUID(bytes, i); i += 16; EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TimeToLive = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(LocalX % 256); bytes[i++] = (byte)((LocalX >> 8) % 256); bytes[i++] = (byte)(LocalY % 256); bytes[i++] = (byte)((LocalY >> 8) % 256); bytes[i++] = (byte)(Status % 256); bytes[i++] = (byte)((Status >> 8) % 256); bytes[i++] = (byte)((Status >> 16) % 256); bytes[i++] = (byte)((Status >> 24) % 256); if(SecureSessionID == null) { Console.WriteLine("Warning: SecureSessionID is null, in " + this.GetType()); } Array.Copy(SecureSessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); bytes[i++] = (byte)(TimeToLive % 256); bytes[i++] = (byte)((TimeToLive >> 8) % 256); bytes[i++] = (byte)((TimeToLive >> 16) % 256); bytes[i++] = (byte)((TimeToLive >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "LocalX: " + LocalX.ToString() + "\n"; output += "LocalY: " + LocalY.ToString() + "\n"; output += "Status: " + Status.ToString() + "\n"; output += "SecureSessionID: " + SecureSessionID.ToString() + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output += "TimeToLive: " + TimeToLive.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RecordAgentPresence public override PacketType Type { get { return PacketType.RecordAgentPresence; } } /// RegionData block public RegionDataBlock RegionData; /// AgentData block public AgentDataBlock[] AgentData; /// Default constructor public RecordAgentPresencePacket() { Header = new LowHeader(); Header.ID = 23; Header.Reliable = true; RegionData = new RegionDataBlock(); AgentData = new AgentDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RecordAgentPresencePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); RegionData = new RegionDataBlock(bytes, ref i); int count = (int)bytes[i++]; AgentData = new AgentDataBlock[count]; for (int j = 0; j < count; j++) { AgentData[j] = new AgentDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public RecordAgentPresencePacket(Header head, byte[] bytes, ref int i) { Header = head; RegionData = new RegionDataBlock(bytes, ref i); int count = (int)bytes[i++]; AgentData = new AgentDataBlock[count]; for (int j = 0; j < count; j++) { AgentData[j] = new AgentDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += RegionData.Length;; length++; for (int j = 0; j < AgentData.Length; j++) { length += AgentData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); RegionData.ToBytes(bytes, ref i); bytes[i++] = (byte)AgentData.Length; for (int j = 0; j < AgentData.Length; j++) { AgentData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RecordAgentPresence ---\n"; output += RegionData.ToString() + "\n"; for (int j = 0; j < AgentData.Length; j++) { output += AgentData[j].ToString() + "\n"; } return output; } } /// EraseAgentPresence packet public class EraseAgentPresencePacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.EraseAgentPresence public override PacketType Type { get { return PacketType.EraseAgentPresence; } } /// AgentData block public AgentDataBlock[] AgentData; /// Default constructor public EraseAgentPresencePacket() { Header = new LowHeader(); Header.ID = 24; Header.Reliable = true; AgentData = new AgentDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public EraseAgentPresencePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; AgentData = new AgentDataBlock[count]; for (int j = 0; j < count; j++) { AgentData[j] = new AgentDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public EraseAgentPresencePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; AgentData = new AgentDataBlock[count]; for (int j = 0; j < count; j++) { AgentData[j] = new AgentDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < AgentData.Length; j++) { length += AgentData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)AgentData.Length; for (int j = 0; j < AgentData.Length; j++) { AgentData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- EraseAgentPresence ---\n"; for (int j = 0; j < AgentData.Length; j++) { output += AgentData[j].ToString() + "\n"; } return output; } } /// AgentPresenceRequest packet public class AgentPresenceRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentPresenceRequest public override PacketType Type { get { return PacketType.AgentPresenceRequest; } } /// AgentData block public AgentDataBlock[] AgentData; /// Default constructor public AgentPresenceRequestPacket() { Header = new LowHeader(); Header.ID = 25; Header.Reliable = true; AgentData = new AgentDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentPresenceRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; AgentData = new AgentDataBlock[count]; for (int j = 0; j < count; j++) { AgentData[j] = new AgentDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public AgentPresenceRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; AgentData = new AgentDataBlock[count]; for (int j = 0; j < count; j++) { AgentData[j] = new AgentDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < AgentData.Length; j++) { length += AgentData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)AgentData.Length; for (int j = 0; j < AgentData.Length; j++) { AgentData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentPresenceRequest ---\n"; for (int j = 0; j < AgentData.Length; j++) { output += AgentData[j].ToString() + "\n"; } return output; } } /// AgentPresenceResponse packet public class AgentPresenceResponsePacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// ValidUntil field public double ValidUntil; /// RegionIP field public uint RegionIP; /// RegionPort field public ushort RegionPort; /// EstateID field public uint EstateID; /// Length of this block serialized in bytes public int Length { get { return 34; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 8); ValidUntil = BitConverter.ToDouble(bytes, i); i += 8; RegionIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RegionPort = (ushort)((bytes[i++] << 8) + bytes[i++]); EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; ba = BitConverter.GetBytes(ValidUntil); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 8); } Array.Copy(ba, 0, bytes, i, 8); i += 8; bytes[i++] = (byte)(RegionIP % 256); bytes[i++] = (byte)((RegionIP >> 8) % 256); bytes[i++] = (byte)((RegionIP >> 16) % 256); bytes[i++] = (byte)((RegionIP >> 24) % 256); bytes[i++] = (byte)((RegionPort >> 8) % 256); bytes[i++] = (byte)(RegionPort % 256); bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "ValidUntil: " + ValidUntil.ToString() + "\n"; output += "RegionIP: " + RegionIP.ToString() + "\n"; output += "RegionPort: " + RegionPort.ToString() + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentPresenceResponse public override PacketType Type { get { return PacketType.AgentPresenceResponse; } } /// AgentData block public AgentDataBlock[] AgentData; /// Default constructor public AgentPresenceResponsePacket() { Header = new LowHeader(); Header.ID = 26; Header.Reliable = true; AgentData = new AgentDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentPresenceResponsePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; AgentData = new AgentDataBlock[count]; for (int j = 0; j < count; j++) { AgentData[j] = new AgentDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public AgentPresenceResponsePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; AgentData = new AgentDataBlock[count]; for (int j = 0; j < count; j++) { AgentData[j] = new AgentDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < AgentData.Length; j++) { length += AgentData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)AgentData.Length; for (int j = 0; j < AgentData.Length; j++) { AgentData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentPresenceResponse ---\n"; for (int j = 0; j < AgentData.Length; j++) { output += AgentData[j].ToString() + "\n"; } return output; } } /// UpdateSimulator packet public class UpdateSimulatorPacket : Packet { /// SimulatorInfo block public class SimulatorInfoBlock { private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// RegionID field public LLUUID RegionID; /// SimAccess field public byte SimAccess; /// EstateID field public uint EstateID; /// Length of this block serialized in bytes public int Length { get { int length = 21; if (SimName != null) { length += 1 + SimName.Length; } return length; } } /// Default constructor public SimulatorInfoBlock() { } /// Constructor for building the block from a byte array public SimulatorInfoBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; RegionID = new LLUUID(bytes, i); i += 16; SimAccess = (byte)bytes[i++]; EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; if(RegionID == null) { Console.WriteLine("Warning: RegionID is null, in " + this.GetType()); } Array.Copy(RegionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = SimAccess; bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- SimulatorInfo --\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "RegionID: " + RegionID.ToString() + "\n"; output += "SimAccess: " + SimAccess.ToString() + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UpdateSimulator public override PacketType Type { get { return PacketType.UpdateSimulator; } } /// SimulatorInfo block public SimulatorInfoBlock SimulatorInfo; /// Default constructor public UpdateSimulatorPacket() { Header = new LowHeader(); Header.ID = 27; Header.Reliable = true; SimulatorInfo = new SimulatorInfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UpdateSimulatorPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); SimulatorInfo = new SimulatorInfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public UpdateSimulatorPacket(Header head, byte[] bytes, ref int i) { Header = head; SimulatorInfo = new SimulatorInfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += SimulatorInfo.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); SimulatorInfo.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UpdateSimulator ---\n"; output += SimulatorInfo.ToString() + "\n"; return output; } } /// TrackAgentSession packet public class TrackAgentSessionPacket : Packet { /// SessionInfo block public class SessionInfoBlock { /// GlobalX field public double GlobalX; /// GlobalY field public double GlobalY; /// SessionID field public LLUUID SessionID; /// ViewerPort field public ushort ViewerPort; /// ViewerIP field public uint ViewerIP; /// Length of this block serialized in bytes public int Length { get { return 38; } } /// Default constructor public SessionInfoBlock() { } /// Constructor for building the block from a byte array public SessionInfoBlock(byte[] bytes, ref int i) { try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 8); GlobalX = BitConverter.ToDouble(bytes, i); i += 8; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 8); GlobalY = BitConverter.ToDouble(bytes, i); i += 8; SessionID = new LLUUID(bytes, i); i += 16; ViewerPort = (ushort)((bytes[i++] << 8) + bytes[i++]); ViewerIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(GlobalX); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 8); } Array.Copy(ba, 0, bytes, i, 8); i += 8; ba = BitConverter.GetBytes(GlobalY); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 8); } Array.Copy(ba, 0, bytes, i, 8); i += 8; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((ViewerPort >> 8) % 256); bytes[i++] = (byte)(ViewerPort % 256); bytes[i++] = (byte)(ViewerIP % 256); bytes[i++] = (byte)((ViewerIP >> 8) % 256); bytes[i++] = (byte)((ViewerIP >> 16) % 256); bytes[i++] = (byte)((ViewerIP >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- SessionInfo --\n"; output += "GlobalX: " + GlobalX.ToString() + "\n"; output += "GlobalY: " + GlobalY.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "ViewerPort: " + ViewerPort.ToString() + "\n"; output += "ViewerIP: " + ViewerIP.ToString() + "\n"; output = output.Trim(); return output; } } /// RegionData block public class RegionDataBlock { /// RegionX field public float RegionX; /// RegionY field public float RegionY; /// SpaceIP field public uint SpaceIP; /// AgentCount field public uint AgentCount; /// EstateID field public uint EstateID; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public RegionDataBlock() { } /// Constructor for building the block from a byte array public RegionDataBlock(byte[] bytes, ref int i) { try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); RegionX = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); RegionY = BitConverter.ToSingle(bytes, i); i += 4; SpaceIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); AgentCount = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(RegionX); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(RegionY); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(SpaceIP % 256); bytes[i++] = (byte)((SpaceIP >> 8) % 256); bytes[i++] = (byte)((SpaceIP >> 16) % 256); bytes[i++] = (byte)((SpaceIP >> 24) % 256); bytes[i++] = (byte)(AgentCount % 256); bytes[i++] = (byte)((AgentCount >> 8) % 256); bytes[i++] = (byte)((AgentCount >> 16) % 256); bytes[i++] = (byte)((AgentCount >> 24) % 256); bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionData --\n"; output += "RegionX: " + RegionX.ToString() + "\n"; output += "RegionY: " + RegionY.ToString() + "\n"; output += "SpaceIP: " + SpaceIP.ToString() + "\n"; output += "AgentCount: " + AgentCount.ToString() + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TrackAgentSession public override PacketType Type { get { return PacketType.TrackAgentSession; } } /// SessionInfo block public SessionInfoBlock[] SessionInfo; /// RegionData block public RegionDataBlock RegionData; /// Default constructor public TrackAgentSessionPacket() { Header = new LowHeader(); Header.ID = 28; Header.Reliable = true; SessionInfo = new SessionInfoBlock[0]; RegionData = new RegionDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TrackAgentSessionPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; SessionInfo = new SessionInfoBlock[count]; for (int j = 0; j < count; j++) { SessionInfo[j] = new SessionInfoBlock(bytes, ref i); } RegionData = new RegionDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TrackAgentSessionPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; SessionInfo = new SessionInfoBlock[count]; for (int j = 0; j < count; j++) { SessionInfo[j] = new SessionInfoBlock(bytes, ref i); } RegionData = new RegionDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += RegionData.Length;; length++; for (int j = 0; j < SessionInfo.Length; j++) { length += SessionInfo[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)SessionInfo.Length; for (int j = 0; j < SessionInfo.Length; j++) { SessionInfo[j].ToBytes(bytes, ref i); } RegionData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TrackAgentSession ---\n"; for (int j = 0; j < SessionInfo.Length; j++) { output += SessionInfo[j].ToString() + "\n"; } output += RegionData.ToString() + "\n"; return output; } } /// ClearAgentSessions packet public class ClearAgentSessionsPacket : Packet { /// RegionInfo block public class RegionInfoBlock { /// RegionX field public uint RegionX; /// RegionY field public uint RegionY; /// SpaceIP field public uint SpaceIP; /// Length of this block serialized in bytes public int Length { get { return 12; } } /// Default constructor public RegionInfoBlock() { } /// Constructor for building the block from a byte array public RegionInfoBlock(byte[] bytes, ref int i) { try { RegionX = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RegionY = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SpaceIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(RegionX % 256); bytes[i++] = (byte)((RegionX >> 8) % 256); bytes[i++] = (byte)((RegionX >> 16) % 256); bytes[i++] = (byte)((RegionX >> 24) % 256); bytes[i++] = (byte)(RegionY % 256); bytes[i++] = (byte)((RegionY >> 8) % 256); bytes[i++] = (byte)((RegionY >> 16) % 256); bytes[i++] = (byte)((RegionY >> 24) % 256); bytes[i++] = (byte)(SpaceIP % 256); bytes[i++] = (byte)((SpaceIP >> 8) % 256); bytes[i++] = (byte)((SpaceIP >> 16) % 256); bytes[i++] = (byte)((SpaceIP >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionInfo --\n"; output += "RegionX: " + RegionX.ToString() + "\n"; output += "RegionY: " + RegionY.ToString() + "\n"; output += "SpaceIP: " + SpaceIP.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ClearAgentSessions public override PacketType Type { get { return PacketType.ClearAgentSessions; } } /// RegionInfo block public RegionInfoBlock RegionInfo; /// Default constructor public ClearAgentSessionsPacket() { Header = new LowHeader(); Header.ID = 29; Header.Reliable = true; RegionInfo = new RegionInfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ClearAgentSessionsPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); RegionInfo = new RegionInfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ClearAgentSessionsPacket(Header head, byte[] bytes, ref int i) { Header = head; RegionInfo = new RegionInfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += RegionInfo.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); RegionInfo.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ClearAgentSessions ---\n"; output += RegionInfo.ToString() + "\n"; return output; } } /// LogDwellTime packet public class LogDwellTimePacket : Packet { /// DwellInfo block public class DwellInfoBlock { /// Duration field public float Duration; private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// AgentID field public LLUUID AgentID; /// RegionX field public uint RegionX; /// RegionY field public uint RegionY; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { int length = 44; if (SimName != null) { length += 1 + SimName.Length; } return length; } } /// Default constructor public DwellInfoBlock() { } /// Constructor for building the block from a byte array public DwellInfoBlock(byte[] bytes, ref int i) { int length; try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Duration = BitConverter.ToSingle(bytes, i); i += 4; length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; AgentID = new LLUUID(bytes, i); i += 16; RegionX = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RegionY = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(Duration); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(RegionX % 256); bytes[i++] = (byte)((RegionX >> 8) % 256); bytes[i++] = (byte)((RegionX >> 16) % 256); bytes[i++] = (byte)((RegionX >> 24) % 256); bytes[i++] = (byte)(RegionY % 256); bytes[i++] = (byte)((RegionY >> 8) % 256); bytes[i++] = (byte)((RegionY >> 16) % 256); bytes[i++] = (byte)((RegionY >> 24) % 256); if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DwellInfo --\n"; output += "Duration: " + Duration.ToString() + "\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "RegionX: " + RegionX.ToString() + "\n"; output += "RegionY: " + RegionY.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.LogDwellTime public override PacketType Type { get { return PacketType.LogDwellTime; } } /// DwellInfo block public DwellInfoBlock DwellInfo; /// Default constructor public LogDwellTimePacket() { Header = new LowHeader(); Header.ID = 30; Header.Reliable = true; DwellInfo = new DwellInfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public LogDwellTimePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); DwellInfo = new DwellInfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public LogDwellTimePacket(Header head, byte[] bytes, ref int i) { Header = head; DwellInfo = new DwellInfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += DwellInfo.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DwellInfo.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- LogDwellTime ---\n"; output += DwellInfo.ToString() + "\n"; return output; } } /// FeatureDisabled packet public class FeatureDisabledPacket : Packet { /// FailureInfo block public class FailureInfoBlock { /// AgentID field public LLUUID AgentID; private byte[] _errormessage; /// ErrorMessage field public byte[] ErrorMessage { get { return _errormessage; } set { if (value == null) { _errormessage = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _errormessage = new byte[value.Length]; Array.Copy(value, _errormessage, value.Length); } } } /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { int length = 32; if (ErrorMessage != null) { length += 1 + ErrorMessage.Length; } return length; } } /// Default constructor public FailureInfoBlock() { } /// Constructor for building the block from a byte array public FailureInfoBlock(byte[] bytes, ref int i) { int length; try { AgentID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _errormessage = new byte[length]; Array.Copy(bytes, i, _errormessage, 0, length); i += length; TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(ErrorMessage == null) { Console.WriteLine("Warning: ErrorMessage is null, in " + this.GetType()); } bytes[i++] = (byte)ErrorMessage.Length; Array.Copy(ErrorMessage, 0, bytes, i, ErrorMessage.Length); i += ErrorMessage.Length; if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- FailureInfo --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += Helpers.FieldToString(ErrorMessage, "ErrorMessage") + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.FeatureDisabled public override PacketType Type { get { return PacketType.FeatureDisabled; } } /// FailureInfo block public FailureInfoBlock FailureInfo; /// Default constructor public FeatureDisabledPacket() { Header = new LowHeader(); Header.ID = 31; Header.Reliable = true; FailureInfo = new FailureInfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public FeatureDisabledPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); FailureInfo = new FailureInfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public FeatureDisabledPacket(Header head, byte[] bytes, ref int i) { Header = head; FailureInfo = new FailureInfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += FailureInfo.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); FailureInfo.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- FeatureDisabled ---\n"; output += FailureInfo.ToString() + "\n"; return output; } } /// LogFailedMoneyTransaction packet public class LogFailedMoneyTransactionPacket : Packet { /// TransactionData block public class TransactionDataBlock { /// FailureType field public byte FailureType; /// DestID field public LLUUID DestID; /// Amount field public int Amount; /// SimulatorIP field public uint SimulatorIP; /// Flags field public byte Flags; /// GridX field public uint GridX; /// GridY field public uint GridY; /// SourceID field public LLUUID SourceID; /// TransactionID field public LLUUID TransactionID; /// TransactionTime field public uint TransactionTime; /// TransactionType field public int TransactionType; /// Length of this block serialized in bytes public int Length { get { return 74; } } /// Default constructor public TransactionDataBlock() { } /// Constructor for building the block from a byte array public TransactionDataBlock(byte[] bytes, ref int i) { try { FailureType = (byte)bytes[i++]; DestID = new LLUUID(bytes, i); i += 16; Amount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SimulatorIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Flags = (byte)bytes[i++]; GridX = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GridY = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SourceID = new LLUUID(bytes, i); i += 16; TransactionID = new LLUUID(bytes, i); i += 16; TransactionTime = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TransactionType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = FailureType; if(DestID == null) { Console.WriteLine("Warning: DestID is null, in " + this.GetType()); } Array.Copy(DestID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Amount % 256); bytes[i++] = (byte)((Amount >> 8) % 256); bytes[i++] = (byte)((Amount >> 16) % 256); bytes[i++] = (byte)((Amount >> 24) % 256); bytes[i++] = (byte)(SimulatorIP % 256); bytes[i++] = (byte)((SimulatorIP >> 8) % 256); bytes[i++] = (byte)((SimulatorIP >> 16) % 256); bytes[i++] = (byte)((SimulatorIP >> 24) % 256); bytes[i++] = Flags; bytes[i++] = (byte)(GridX % 256); bytes[i++] = (byte)((GridX >> 8) % 256); bytes[i++] = (byte)((GridX >> 16) % 256); bytes[i++] = (byte)((GridX >> 24) % 256); bytes[i++] = (byte)(GridY % 256); bytes[i++] = (byte)((GridY >> 8) % 256); bytes[i++] = (byte)((GridY >> 16) % 256); bytes[i++] = (byte)((GridY >> 24) % 256); if(SourceID == null) { Console.WriteLine("Warning: SourceID is null, in " + this.GetType()); } Array.Copy(SourceID.GetBytes(), 0, bytes, i, 16); i += 16; if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(TransactionTime % 256); bytes[i++] = (byte)((TransactionTime >> 8) % 256); bytes[i++] = (byte)((TransactionTime >> 16) % 256); bytes[i++] = (byte)((TransactionTime >> 24) % 256); bytes[i++] = (byte)(TransactionType % 256); bytes[i++] = (byte)((TransactionType >> 8) % 256); bytes[i++] = (byte)((TransactionType >> 16) % 256); bytes[i++] = (byte)((TransactionType >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TransactionData --\n"; output += "FailureType: " + FailureType.ToString() + "\n"; output += "DestID: " + DestID.ToString() + "\n"; output += "Amount: " + Amount.ToString() + "\n"; output += "SimulatorIP: " + SimulatorIP.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "GridX: " + GridX.ToString() + "\n"; output += "GridY: " + GridY.ToString() + "\n"; output += "SourceID: " + SourceID.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output += "TransactionTime: " + TransactionTime.ToString() + "\n"; output += "TransactionType: " + TransactionType.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.LogFailedMoneyTransaction public override PacketType Type { get { return PacketType.LogFailedMoneyTransaction; } } /// TransactionData block public TransactionDataBlock TransactionData; /// Default constructor public LogFailedMoneyTransactionPacket() { Header = new LowHeader(); Header.ID = 32; Header.Reliable = true; TransactionData = new TransactionDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public LogFailedMoneyTransactionPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TransactionData = new TransactionDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public LogFailedMoneyTransactionPacket(Header head, byte[] bytes, ref int i) { Header = head; TransactionData = new TransactionDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TransactionData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TransactionData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- LogFailedMoneyTransaction ---\n"; output += TransactionData.ToString() + "\n"; return output; } } /// UserReportInternal packet public class UserReportInternalPacket : Packet { /// MeanCollision block public class MeanCollisionBlock { /// Mag field public float Mag; /// Time field public uint Time; /// Perp field public LLUUID Perp; /// Type field public byte Type; /// Length of this block serialized in bytes public int Length { get { return 25; } } /// Default constructor public MeanCollisionBlock() { } /// Constructor for building the block from a byte array public MeanCollisionBlock(byte[] bytes, ref int i) { try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Mag = BitConverter.ToSingle(bytes, i); i += 4; Time = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Perp = new LLUUID(bytes, i); i += 16; Type = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(Mag); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(Time % 256); bytes[i++] = (byte)((Time >> 8) % 256); bytes[i++] = (byte)((Time >> 16) % 256); bytes[i++] = (byte)((Time >> 24) % 256); if(Perp == null) { Console.WriteLine("Warning: Perp is null, in " + this.GetType()); } Array.Copy(Perp.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = Type; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MeanCollision --\n"; output += "Mag: " + Mag.ToString() + "\n"; output += "Time: " + Time.ToString() + "\n"; output += "Perp: " + Perp.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output = output.Trim(); return output; } } /// ReportData block public class ReportDataBlock { private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// ObjectID field public LLUUID ObjectID; private byte[] _details; /// Details field public byte[] Details { get { return _details; } set { if (value == null) { _details = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _details = new byte[value.Length]; Array.Copy(value, _details, value.Length); } } } private byte[] _versionstring; /// VersionString field public byte[] VersionString { get { return _versionstring; } set { if (value == null) { _versionstring = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _versionstring = new byte[value.Length]; Array.Copy(value, _versionstring, value.Length); } } } /// AgentPosition field public LLVector3 AgentPosition; /// Category field public byte Category; /// OwnerID field public LLUUID OwnerID; /// CreatorID field public LLUUID CreatorID; private byte[] _summary; /// Summary field public byte[] Summary { get { return _summary; } set { if (value == null) { _summary = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _summary = new byte[value.Length]; Array.Copy(value, _summary, value.Length); } } } /// ReporterID field public LLUUID ReporterID; /// ReportType field public byte ReportType; /// ScreenshotID field public LLUUID ScreenshotID; /// LastOwnerID field public LLUUID LastOwnerID; /// ViewerPosition field public LLVector3 ViewerPosition; /// Length of this block serialized in bytes public int Length { get { int length = 122; if (SimName != null) { length += 1 + SimName.Length; } if (Details != null) { length += 2 + Details.Length; } if (VersionString != null) { length += 1 + VersionString.Length; } if (Summary != null) { length += 1 + Summary.Length; } return length; } } /// Default constructor public ReportDataBlock() { } /// Constructor for building the block from a byte array public ReportDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; ObjectID = new LLUUID(bytes, i); i += 16; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _details = new byte[length]; Array.Copy(bytes, i, _details, 0, length); i += length; length = (ushort)bytes[i++]; _versionstring = new byte[length]; Array.Copy(bytes, i, _versionstring, 0, length); i += length; AgentPosition = new LLVector3(bytes, i); i += 12; Category = (byte)bytes[i++]; OwnerID = new LLUUID(bytes, i); i += 16; CreatorID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _summary = new byte[length]; Array.Copy(bytes, i, _summary, 0, length); i += length; ReporterID = new LLUUID(bytes, i); i += 16; ReportType = (byte)bytes[i++]; ScreenshotID = new LLUUID(bytes, i); i += 16; LastOwnerID = new LLUUID(bytes, i); i += 16; ViewerPosition = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; if(Details == null) { Console.WriteLine("Warning: Details is null, in " + this.GetType()); } bytes[i++] = (byte)(Details.Length % 256); bytes[i++] = (byte)((Details.Length >> 8) % 256); Array.Copy(Details, 0, bytes, i, Details.Length); i += Details.Length; if(VersionString == null) { Console.WriteLine("Warning: VersionString is null, in " + this.GetType()); } bytes[i++] = (byte)VersionString.Length; Array.Copy(VersionString, 0, bytes, i, VersionString.Length); i += VersionString.Length; if(AgentPosition == null) { Console.WriteLine("Warning: AgentPosition is null, in " + this.GetType()); } Array.Copy(AgentPosition.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = Category; if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(CreatorID == null) { Console.WriteLine("Warning: CreatorID is null, in " + this.GetType()); } Array.Copy(CreatorID.GetBytes(), 0, bytes, i, 16); i += 16; if(Summary == null) { Console.WriteLine("Warning: Summary is null, in " + this.GetType()); } bytes[i++] = (byte)Summary.Length; Array.Copy(Summary, 0, bytes, i, Summary.Length); i += Summary.Length; if(ReporterID == null) { Console.WriteLine("Warning: ReporterID is null, in " + this.GetType()); } Array.Copy(ReporterID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = ReportType; if(ScreenshotID == null) { Console.WriteLine("Warning: ScreenshotID is null, in " + this.GetType()); } Array.Copy(ScreenshotID.GetBytes(), 0, bytes, i, 16); i += 16; if(LastOwnerID == null) { Console.WriteLine("Warning: LastOwnerID is null, in " + this.GetType()); } Array.Copy(LastOwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(ViewerPosition == null) { Console.WriteLine("Warning: ViewerPosition is null, in " + this.GetType()); } Array.Copy(ViewerPosition.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ReportData --\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += Helpers.FieldToString(Details, "Details") + "\n"; output += Helpers.FieldToString(VersionString, "VersionString") + "\n"; output += "AgentPosition: " + AgentPosition.ToString() + "\n"; output += "Category: " + Category.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "CreatorID: " + CreatorID.ToString() + "\n"; output += Helpers.FieldToString(Summary, "Summary") + "\n"; output += "ReporterID: " + ReporterID.ToString() + "\n"; output += "ReportType: " + ReportType.ToString() + "\n"; output += "ScreenshotID: " + ScreenshotID.ToString() + "\n"; output += "LastOwnerID: " + LastOwnerID.ToString() + "\n"; output += "ViewerPosition: " + ViewerPosition.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UserReportInternal public override PacketType Type { get { return PacketType.UserReportInternal; } } /// MeanCollision block public MeanCollisionBlock[] MeanCollision; /// ReportData block public ReportDataBlock ReportData; /// Default constructor public UserReportInternalPacket() { Header = new LowHeader(); Header.ID = 33; Header.Reliable = true; Header.Zerocoded = true; MeanCollision = new MeanCollisionBlock[0]; ReportData = new ReportDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UserReportInternalPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; MeanCollision = new MeanCollisionBlock[count]; for (int j = 0; j < count; j++) { MeanCollision[j] = new MeanCollisionBlock(bytes, ref i); } ReportData = new ReportDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public UserReportInternalPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; MeanCollision = new MeanCollisionBlock[count]; for (int j = 0; j < count; j++) { MeanCollision[j] = new MeanCollisionBlock(bytes, ref i); } ReportData = new ReportDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ReportData.Length;; length++; for (int j = 0; j < MeanCollision.Length; j++) { length += MeanCollision[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)MeanCollision.Length; for (int j = 0; j < MeanCollision.Length; j++) { MeanCollision[j].ToBytes(bytes, ref i); } ReportData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UserReportInternal ---\n"; for (int j = 0; j < MeanCollision.Length; j++) { output += MeanCollision[j].ToString() + "\n"; } output += ReportData.ToString() + "\n"; return output; } } /// SetSimStatusInDatabase packet public class SetSimStatusInDatabasePacket : Packet { /// Data block public class DataBlock { /// X field public int X; /// Y field public int Y; /// PID field public int PID; /// RegionID field public LLUUID RegionID; private byte[] _status; /// Status field public byte[] Status { get { return _status; } set { if (value == null) { _status = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _status = new byte[value.Length]; Array.Copy(value, _status, value.Length); } } } /// AgentCount field public int AgentCount; private byte[] _hostname; /// HostName field public byte[] HostName { get { return _hostname; } set { if (value == null) { _hostname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _hostname = new byte[value.Length]; Array.Copy(value, _hostname, value.Length); } } } /// TimeToLive field public int TimeToLive; /// Length of this block serialized in bytes public int Length { get { int length = 36; if (Status != null) { length += 1 + Status.Length; } if (HostName != null) { length += 1 + HostName.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { X = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Y = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); PID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RegionID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _status = new byte[length]; Array.Copy(bytes, i, _status, 0, length); i += length; AgentCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _hostname = new byte[length]; Array.Copy(bytes, i, _hostname, 0, length); i += length; TimeToLive = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(X % 256); bytes[i++] = (byte)((X >> 8) % 256); bytes[i++] = (byte)((X >> 16) % 256); bytes[i++] = (byte)((X >> 24) % 256); bytes[i++] = (byte)(Y % 256); bytes[i++] = (byte)((Y >> 8) % 256); bytes[i++] = (byte)((Y >> 16) % 256); bytes[i++] = (byte)((Y >> 24) % 256); bytes[i++] = (byte)(PID % 256); bytes[i++] = (byte)((PID >> 8) % 256); bytes[i++] = (byte)((PID >> 16) % 256); bytes[i++] = (byte)((PID >> 24) % 256); if(RegionID == null) { Console.WriteLine("Warning: RegionID is null, in " + this.GetType()); } Array.Copy(RegionID.GetBytes(), 0, bytes, i, 16); i += 16; if(Status == null) { Console.WriteLine("Warning: Status is null, in " + this.GetType()); } bytes[i++] = (byte)Status.Length; Array.Copy(Status, 0, bytes, i, Status.Length); i += Status.Length; bytes[i++] = (byte)(AgentCount % 256); bytes[i++] = (byte)((AgentCount >> 8) % 256); bytes[i++] = (byte)((AgentCount >> 16) % 256); bytes[i++] = (byte)((AgentCount >> 24) % 256); if(HostName == null) { Console.WriteLine("Warning: HostName is null, in " + this.GetType()); } bytes[i++] = (byte)HostName.Length; Array.Copy(HostName, 0, bytes, i, HostName.Length); i += HostName.Length; bytes[i++] = (byte)(TimeToLive % 256); bytes[i++] = (byte)((TimeToLive >> 8) % 256); bytes[i++] = (byte)((TimeToLive >> 16) % 256); bytes[i++] = (byte)((TimeToLive >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "X: " + X.ToString() + "\n"; output += "Y: " + Y.ToString() + "\n"; output += "PID: " + PID.ToString() + "\n"; output += "RegionID: " + RegionID.ToString() + "\n"; output += Helpers.FieldToString(Status, "Status") + "\n"; output += "AgentCount: " + AgentCount.ToString() + "\n"; output += Helpers.FieldToString(HostName, "HostName") + "\n"; output += "TimeToLive: " + TimeToLive.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SetSimStatusInDatabase public override PacketType Type { get { return PacketType.SetSimStatusInDatabase; } } /// Data block public DataBlock Data; /// Default constructor public SetSimStatusInDatabasePacket() { Header = new LowHeader(); Header.ID = 34; Header.Reliable = true; Data = new DataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SetSimStatusInDatabasePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SetSimStatusInDatabasePacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SetSimStatusInDatabase ---\n"; output += Data.ToString() + "\n"; return output; } } /// SetSimPresenceInDatabase packet public class SetSimPresenceInDatabasePacket : Packet { /// SimData block public class SimDataBlock { /// PID field public int PID; /// RegionID field public LLUUID RegionID; private byte[] _status; /// Status field public byte[] Status { get { return _status; } set { if (value == null) { _status = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _status = new byte[value.Length]; Array.Copy(value, _status, value.Length); } } } /// AgentCount field public int AgentCount; /// GridX field public uint GridX; /// GridY field public uint GridY; private byte[] _hostname; /// HostName field public byte[] HostName { get { return _hostname; } set { if (value == null) { _hostname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _hostname = new byte[value.Length]; Array.Copy(value, _hostname, value.Length); } } } /// TimeToLive field public int TimeToLive; /// Length of this block serialized in bytes public int Length { get { int length = 36; if (Status != null) { length += 1 + Status.Length; } if (HostName != null) { length += 1 + HostName.Length; } return length; } } /// Default constructor public SimDataBlock() { } /// Constructor for building the block from a byte array public SimDataBlock(byte[] bytes, ref int i) { int length; try { PID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RegionID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _status = new byte[length]; Array.Copy(bytes, i, _status, 0, length); i += length; AgentCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GridX = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GridY = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _hostname = new byte[length]; Array.Copy(bytes, i, _hostname, 0, length); i += length; TimeToLive = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(PID % 256); bytes[i++] = (byte)((PID >> 8) % 256); bytes[i++] = (byte)((PID >> 16) % 256); bytes[i++] = (byte)((PID >> 24) % 256); if(RegionID == null) { Console.WriteLine("Warning: RegionID is null, in " + this.GetType()); } Array.Copy(RegionID.GetBytes(), 0, bytes, i, 16); i += 16; if(Status == null) { Console.WriteLine("Warning: Status is null, in " + this.GetType()); } bytes[i++] = (byte)Status.Length; Array.Copy(Status, 0, bytes, i, Status.Length); i += Status.Length; bytes[i++] = (byte)(AgentCount % 256); bytes[i++] = (byte)((AgentCount >> 8) % 256); bytes[i++] = (byte)((AgentCount >> 16) % 256); bytes[i++] = (byte)((AgentCount >> 24) % 256); bytes[i++] = (byte)(GridX % 256); bytes[i++] = (byte)((GridX >> 8) % 256); bytes[i++] = (byte)((GridX >> 16) % 256); bytes[i++] = (byte)((GridX >> 24) % 256); bytes[i++] = (byte)(GridY % 256); bytes[i++] = (byte)((GridY >> 8) % 256); bytes[i++] = (byte)((GridY >> 16) % 256); bytes[i++] = (byte)((GridY >> 24) % 256); if(HostName == null) { Console.WriteLine("Warning: HostName is null, in " + this.GetType()); } bytes[i++] = (byte)HostName.Length; Array.Copy(HostName, 0, bytes, i, HostName.Length); i += HostName.Length; bytes[i++] = (byte)(TimeToLive % 256); bytes[i++] = (byte)((TimeToLive >> 8) % 256); bytes[i++] = (byte)((TimeToLive >> 16) % 256); bytes[i++] = (byte)((TimeToLive >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- SimData --\n"; output += "PID: " + PID.ToString() + "\n"; output += "RegionID: " + RegionID.ToString() + "\n"; output += Helpers.FieldToString(Status, "Status") + "\n"; output += "AgentCount: " + AgentCount.ToString() + "\n"; output += "GridX: " + GridX.ToString() + "\n"; output += "GridY: " + GridY.ToString() + "\n"; output += Helpers.FieldToString(HostName, "HostName") + "\n"; output += "TimeToLive: " + TimeToLive.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SetSimPresenceInDatabase public override PacketType Type { get { return PacketType.SetSimPresenceInDatabase; } } /// SimData block public SimDataBlock SimData; /// Default constructor public SetSimPresenceInDatabasePacket() { Header = new LowHeader(); Header.ID = 35; Header.Reliable = true; SimData = new SimDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SetSimPresenceInDatabasePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); SimData = new SimDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SetSimPresenceInDatabasePacket(Header head, byte[] bytes, ref int i) { Header = head; SimData = new SimDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += SimData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); SimData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SetSimPresenceInDatabase ---\n"; output += SimData.ToString() + "\n"; return output; } } /// EconomyDataRequest packet public class EconomyDataRequestPacket : Packet { private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.EconomyDataRequest public override PacketType Type { get { return PacketType.EconomyDataRequest; } } /// Default constructor public EconomyDataRequestPacket() { Header = new LowHeader(); Header.ID = 36; Header.Reliable = true; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public EconomyDataRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); } /// Constructor that takes a byte array and a prebuilt header public EconomyDataRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- EconomyDataRequest ---\n"; return output; } } /// EconomyData packet public class EconomyDataPacket : Packet { /// Info block public class InfoBlock { /// PriceParcelClaimFactor field public float PriceParcelClaimFactor; /// ObjectCapacity field public int ObjectCapacity; /// EnergyEfficiency field public float EnergyEfficiency; /// ObjectCount field public int ObjectCount; /// TeleportPriceExponent field public float TeleportPriceExponent; /// PriceGroupCreate field public int PriceGroupCreate; /// PriceObjectRent field public float PriceObjectRent; /// PricePublicObjectDelete field public int PricePublicObjectDelete; /// PriceEnergyUnit field public int PriceEnergyUnit; /// TeleportMinPrice field public int TeleportMinPrice; /// PricePublicObjectDecay field public int PricePublicObjectDecay; /// PriceObjectClaim field public int PriceObjectClaim; /// PriceParcelClaim field public int PriceParcelClaim; /// PriceObjectScaleFactor field public float PriceObjectScaleFactor; /// PriceRentLight field public int PriceRentLight; /// PriceParcelRent field public int PriceParcelRent; /// PriceUpload field public int PriceUpload; /// Length of this block serialized in bytes public int Length { get { return 68; } } /// Default constructor public InfoBlock() { } /// Constructor for building the block from a byte array public InfoBlock(byte[] bytes, ref int i) { try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); PriceParcelClaimFactor = BitConverter.ToSingle(bytes, i); i += 4; ObjectCapacity = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); EnergyEfficiency = BitConverter.ToSingle(bytes, i); i += 4; ObjectCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); TeleportPriceExponent = BitConverter.ToSingle(bytes, i); i += 4; PriceGroupCreate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); PriceObjectRent = BitConverter.ToSingle(bytes, i); i += 4; PricePublicObjectDelete = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); PriceEnergyUnit = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TeleportMinPrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); PricePublicObjectDecay = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); PriceObjectClaim = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); PriceParcelClaim = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); PriceObjectScaleFactor = BitConverter.ToSingle(bytes, i); i += 4; PriceRentLight = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); PriceParcelRent = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); PriceUpload = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(PriceParcelClaimFactor); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(ObjectCapacity % 256); bytes[i++] = (byte)((ObjectCapacity >> 8) % 256); bytes[i++] = (byte)((ObjectCapacity >> 16) % 256); bytes[i++] = (byte)((ObjectCapacity >> 24) % 256); ba = BitConverter.GetBytes(EnergyEfficiency); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(ObjectCount % 256); bytes[i++] = (byte)((ObjectCount >> 8) % 256); bytes[i++] = (byte)((ObjectCount >> 16) % 256); bytes[i++] = (byte)((ObjectCount >> 24) % 256); ba = BitConverter.GetBytes(TeleportPriceExponent); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(PriceGroupCreate % 256); bytes[i++] = (byte)((PriceGroupCreate >> 8) % 256); bytes[i++] = (byte)((PriceGroupCreate >> 16) % 256); bytes[i++] = (byte)((PriceGroupCreate >> 24) % 256); ba = BitConverter.GetBytes(PriceObjectRent); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(PricePublicObjectDelete % 256); bytes[i++] = (byte)((PricePublicObjectDelete >> 8) % 256); bytes[i++] = (byte)((PricePublicObjectDelete >> 16) % 256); bytes[i++] = (byte)((PricePublicObjectDelete >> 24) % 256); bytes[i++] = (byte)(PriceEnergyUnit % 256); bytes[i++] = (byte)((PriceEnergyUnit >> 8) % 256); bytes[i++] = (byte)((PriceEnergyUnit >> 16) % 256); bytes[i++] = (byte)((PriceEnergyUnit >> 24) % 256); bytes[i++] = (byte)(TeleportMinPrice % 256); bytes[i++] = (byte)((TeleportMinPrice >> 8) % 256); bytes[i++] = (byte)((TeleportMinPrice >> 16) % 256); bytes[i++] = (byte)((TeleportMinPrice >> 24) % 256); bytes[i++] = (byte)(PricePublicObjectDecay % 256); bytes[i++] = (byte)((PricePublicObjectDecay >> 8) % 256); bytes[i++] = (byte)((PricePublicObjectDecay >> 16) % 256); bytes[i++] = (byte)((PricePublicObjectDecay >> 24) % 256); bytes[i++] = (byte)(PriceObjectClaim % 256); bytes[i++] = (byte)((PriceObjectClaim >> 8) % 256); bytes[i++] = (byte)((PriceObjectClaim >> 16) % 256); bytes[i++] = (byte)((PriceObjectClaim >> 24) % 256); bytes[i++] = (byte)(PriceParcelClaim % 256); bytes[i++] = (byte)((PriceParcelClaim >> 8) % 256); bytes[i++] = (byte)((PriceParcelClaim >> 16) % 256); bytes[i++] = (byte)((PriceParcelClaim >> 24) % 256); ba = BitConverter.GetBytes(PriceObjectScaleFactor); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(PriceRentLight % 256); bytes[i++] = (byte)((PriceRentLight >> 8) % 256); bytes[i++] = (byte)((PriceRentLight >> 16) % 256); bytes[i++] = (byte)((PriceRentLight >> 24) % 256); bytes[i++] = (byte)(PriceParcelRent % 256); bytes[i++] = (byte)((PriceParcelRent >> 8) % 256); bytes[i++] = (byte)((PriceParcelRent >> 16) % 256); bytes[i++] = (byte)((PriceParcelRent >> 24) % 256); bytes[i++] = (byte)(PriceUpload % 256); bytes[i++] = (byte)((PriceUpload >> 8) % 256); bytes[i++] = (byte)((PriceUpload >> 16) % 256); bytes[i++] = (byte)((PriceUpload >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Info --\n"; output += "PriceParcelClaimFactor: " + PriceParcelClaimFactor.ToString() + "\n"; output += "ObjectCapacity: " + ObjectCapacity.ToString() + "\n"; output += "EnergyEfficiency: " + EnergyEfficiency.ToString() + "\n"; output += "ObjectCount: " + ObjectCount.ToString() + "\n"; output += "TeleportPriceExponent: " + TeleportPriceExponent.ToString() + "\n"; output += "PriceGroupCreate: " + PriceGroupCreate.ToString() + "\n"; output += "PriceObjectRent: " + PriceObjectRent.ToString() + "\n"; output += "PricePublicObjectDelete: " + PricePublicObjectDelete.ToString() + "\n"; output += "PriceEnergyUnit: " + PriceEnergyUnit.ToString() + "\n"; output += "TeleportMinPrice: " + TeleportMinPrice.ToString() + "\n"; output += "PricePublicObjectDecay: " + PricePublicObjectDecay.ToString() + "\n"; output += "PriceObjectClaim: " + PriceObjectClaim.ToString() + "\n"; output += "PriceParcelClaim: " + PriceParcelClaim.ToString() + "\n"; output += "PriceObjectScaleFactor: " + PriceObjectScaleFactor.ToString() + "\n"; output += "PriceRentLight: " + PriceRentLight.ToString() + "\n"; output += "PriceParcelRent: " + PriceParcelRent.ToString() + "\n"; output += "PriceUpload: " + PriceUpload.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.EconomyData public override PacketType Type { get { return PacketType.EconomyData; } } /// Info block public InfoBlock Info; /// Default constructor public EconomyDataPacket() { Header = new LowHeader(); Header.ID = 37; Header.Reliable = true; Header.Zerocoded = true; Info = new InfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public EconomyDataPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Info = new InfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public EconomyDataPacket(Header head, byte[] bytes, ref int i) { Header = head; Info = new InfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Info.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Info.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- EconomyData ---\n"; output += Info.ToString() + "\n"; return output; } } /// AvatarPickerRequest packet public class AvatarPickerRequestPacket : Packet { /// Data block public class DataBlock { private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// QueryID field public LLUUID QueryID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; QueryID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AvatarPickerRequest public override PacketType Type { get { return PacketType.AvatarPickerRequest; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AvatarPickerRequestPacket() { Header = new LowHeader(); Header.ID = 38; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AvatarPickerRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AvatarPickerRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AvatarPickerRequest ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// AvatarPickerRequestBackend packet public class AvatarPickerRequestBackendPacket : Packet { /// Data block public class DataBlock { private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// GodLevel field public byte GodLevel; /// QueryID field public LLUUID QueryID; /// Length of this block serialized in bytes public int Length { get { return 49; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; GodLevel = (byte)bytes[i++]; QueryID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = GodLevel; if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "GodLevel: " + GodLevel.ToString() + "\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AvatarPickerRequestBackend public override PacketType Type { get { return PacketType.AvatarPickerRequestBackend; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AvatarPickerRequestBackendPacket() { Header = new LowHeader(); Header.ID = 39; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AvatarPickerRequestBackendPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AvatarPickerRequestBackendPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AvatarPickerRequestBackend ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// AvatarPickerReply packet public class AvatarPickerReplyPacket : Packet { /// Data block public class DataBlock { private byte[] _lastname; /// LastName field public byte[] LastName { get { return _lastname; } set { if (value == null) { _lastname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _lastname = new byte[value.Length]; Array.Copy(value, _lastname, value.Length); } } } private byte[] _firstname; /// FirstName field public byte[] FirstName { get { return _firstname; } set { if (value == null) { _firstname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _firstname = new byte[value.Length]; Array.Copy(value, _firstname, value.Length); } } } /// AvatarID field public LLUUID AvatarID; /// Length of this block serialized in bytes public int Length { get { int length = 16; if (LastName != null) { length += 1 + LastName.Length; } if (FirstName != null) { length += 1 + FirstName.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _lastname = new byte[length]; Array.Copy(bytes, i, _lastname, 0, length); i += length; length = (ushort)bytes[i++]; _firstname = new byte[length]; Array.Copy(bytes, i, _firstname, 0, length); i += length; AvatarID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(LastName == null) { Console.WriteLine("Warning: LastName is null, in " + this.GetType()); } bytes[i++] = (byte)LastName.Length; Array.Copy(LastName, 0, bytes, i, LastName.Length); i += LastName.Length; if(FirstName == null) { Console.WriteLine("Warning: FirstName is null, in " + this.GetType()); } bytes[i++] = (byte)FirstName.Length; Array.Copy(FirstName, 0, bytes, i, FirstName.Length); i += FirstName.Length; if(AvatarID == null) { Console.WriteLine("Warning: AvatarID is null, in " + this.GetType()); } Array.Copy(AvatarID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += Helpers.FieldToString(LastName, "LastName") + "\n"; output += Helpers.FieldToString(FirstName, "FirstName") + "\n"; output += "AvatarID: " + AvatarID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// QueryID field public LLUUID QueryID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; QueryID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AvatarPickerReply public override PacketType Type { get { return PacketType.AvatarPickerReply; } } /// Data block public DataBlock[] Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AvatarPickerReplyPacket() { Header = new LowHeader(); Header.ID = 40; Header.Reliable = true; Data = new DataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AvatarPickerReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AvatarPickerReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)Data.Length; for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AvatarPickerReply ---\n"; for (int j = 0; j < Data.Length; j++) { output += Data[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// PlacesQuery packet public class PlacesQueryPacket : Packet { /// QueryData block public class QueryDataBlock { private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// Category field public sbyte Category; /// QueryFlags field public uint QueryFlags; private byte[] _querytext; /// QueryText field public byte[] QueryText { get { return _querytext; } set { if (value == null) { _querytext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _querytext = new byte[value.Length]; Array.Copy(value, _querytext, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 5; if (SimName != null) { length += 1 + SimName.Length; } if (QueryText != null) { length += 1 + QueryText.Length; } return length; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; Category = (sbyte)bytes[i++]; QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _querytext = new byte[length]; Array.Copy(bytes, i, _querytext, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; bytes[i++] = (byte)Category; bytes[i++] = (byte)(QueryFlags % 256); bytes[i++] = (byte)((QueryFlags >> 8) % 256); bytes[i++] = (byte)((QueryFlags >> 16) % 256); bytes[i++] = (byte)((QueryFlags >> 24) % 256); if(QueryText == null) { Console.WriteLine("Warning: QueryText is null, in " + this.GetType()); } bytes[i++] = (byte)QueryText.Length; Array.Copy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "Category: " + Category.ToString() + "\n"; output += "QueryFlags: " + QueryFlags.ToString() + "\n"; output += Helpers.FieldToString(QueryText, "QueryText") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// QueryID field public LLUUID QueryID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; QueryID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output = output.Trim(); return output; } } /// TransactionData block public class TransactionDataBlock { /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public TransactionDataBlock() { } /// Constructor for building the block from a byte array public TransactionDataBlock(byte[] bytes, ref int i) { try { TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TransactionData --\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.PlacesQuery public override PacketType Type { get { return PacketType.PlacesQuery; } } /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// TransactionData block public TransactionDataBlock TransactionData; /// Default constructor public PlacesQueryPacket() { Header = new LowHeader(); Header.ID = 41; Header.Reliable = true; Header.Zerocoded = true; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); TransactionData = new TransactionDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public PlacesQueryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); TransactionData = new TransactionDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public PlacesQueryPacket(Header head, byte[] bytes, ref int i) { Header = head; QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); TransactionData = new TransactionDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length; length += TransactionData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); TransactionData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- PlacesQuery ---\n"; output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; output += TransactionData.ToString() + "\n"; return output; } } /// PlacesReply packet public class PlacesReplyPacket : Packet { /// QueryData block public class QueryDataBlock { private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// BillableArea field public int BillableArea; /// ActualArea field public int ActualArea; /// GlobalX field public float GlobalX; /// GlobalY field public float GlobalY; /// GlobalZ field public float GlobalZ; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } private byte[] _desc; /// Desc field public byte[] Desc { get { return _desc; } set { if (value == null) { _desc = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _desc = new byte[value.Length]; Array.Copy(value, _desc, value.Length); } } } /// OwnerID field public LLUUID OwnerID; /// SnapshotID field public LLUUID SnapshotID; /// Flags field public byte Flags; /// Price field public int Price; /// Dwell field public float Dwell; /// Length of this block serialized in bytes public int Length { get { int length = 61; if (SimName != null) { length += 1 + SimName.Length; } if (Name != null) { length += 1 + Name.Length; } if (Desc != null) { length += 1 + Desc.Length; } return length; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; BillableArea = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ActualArea = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); GlobalX = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); GlobalY = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); GlobalZ = BitConverter.ToSingle(bytes, i); i += 4; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; length = (ushort)bytes[i++]; _desc = new byte[length]; Array.Copy(bytes, i, _desc, 0, length); i += length; OwnerID = new LLUUID(bytes, i); i += 16; SnapshotID = new LLUUID(bytes, i); i += 16; Flags = (byte)bytes[i++]; Price = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Dwell = BitConverter.ToSingle(bytes, i); i += 4; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; bytes[i++] = (byte)(BillableArea % 256); bytes[i++] = (byte)((BillableArea >> 8) % 256); bytes[i++] = (byte)((BillableArea >> 16) % 256); bytes[i++] = (byte)((BillableArea >> 24) % 256); bytes[i++] = (byte)(ActualArea % 256); bytes[i++] = (byte)((ActualArea >> 8) % 256); bytes[i++] = (byte)((ActualArea >> 16) % 256); bytes[i++] = (byte)((ActualArea >> 24) % 256); ba = BitConverter.GetBytes(GlobalX); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(GlobalY); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(GlobalZ); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(Desc == null) { Console.WriteLine("Warning: Desc is null, in " + this.GetType()); } bytes[i++] = (byte)Desc.Length; Array.Copy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(SnapshotID == null) { Console.WriteLine("Warning: SnapshotID is null, in " + this.GetType()); } Array.Copy(SnapshotID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = Flags; bytes[i++] = (byte)(Price % 256); bytes[i++] = (byte)((Price >> 8) % 256); bytes[i++] = (byte)((Price >> 16) % 256); bytes[i++] = (byte)((Price >> 24) % 256); ba = BitConverter.GetBytes(Dwell); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "BillableArea: " + BillableArea.ToString() + "\n"; output += "ActualArea: " + ActualArea.ToString() + "\n"; output += "GlobalX: " + GlobalX.ToString() + "\n"; output += "GlobalY: " + GlobalY.ToString() + "\n"; output += "GlobalZ: " + GlobalZ.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += Helpers.FieldToString(Desc, "Desc") + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "SnapshotID: " + SnapshotID.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "Price: " + Price.ToString() + "\n"; output += "Dwell: " + Dwell.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// QueryID field public LLUUID QueryID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; QueryID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output = output.Trim(); return output; } } /// TransactionData block public class TransactionDataBlock { /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public TransactionDataBlock() { } /// Constructor for building the block from a byte array public TransactionDataBlock(byte[] bytes, ref int i) { try { TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TransactionData --\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.PlacesReply public override PacketType Type { get { return PacketType.PlacesReply; } } /// QueryData block public QueryDataBlock[] QueryData; /// AgentData block public AgentDataBlock AgentData; /// TransactionData block public TransactionDataBlock TransactionData; /// Default constructor public PlacesReplyPacket() { Header = new LowHeader(); Header.ID = 42; Header.Reliable = true; Header.Zerocoded = true; QueryData = new QueryDataBlock[0]; AgentData = new AgentDataBlock(); TransactionData = new TransactionDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public PlacesReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; QueryData = new QueryDataBlock[count]; for (int j = 0; j < count; j++) { QueryData[j] = new QueryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); TransactionData = new TransactionDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public PlacesReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; QueryData = new QueryDataBlock[count]; for (int j = 0; j < count; j++) { QueryData[j] = new QueryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); TransactionData = new TransactionDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += TransactionData.Length;; length++; for (int j = 0; j < QueryData.Length; j++) { length += QueryData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)QueryData.Length; for (int j = 0; j < QueryData.Length; j++) { QueryData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); TransactionData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- PlacesReply ---\n"; for (int j = 0; j < QueryData.Length; j++) { output += QueryData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; output += TransactionData.ToString() + "\n"; return output; } } /// DirFindQuery packet public class DirFindQueryPacket : Packet { /// QueryData block public class QueryDataBlock { /// QueryID field public LLUUID QueryID; /// QueryFlags field public uint QueryFlags; /// QueryStart field public int QueryStart; private byte[] _querytext; /// QueryText field public byte[] QueryText { get { return _querytext; } set { if (value == null) { _querytext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _querytext = new byte[value.Length]; Array.Copy(value, _querytext, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 24; if (QueryText != null) { length += 1 + QueryText.Length; } return length; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { int length; try { QueryID = new LLUUID(bytes, i); i += 16; QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); QueryStart = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _querytext = new byte[length]; Array.Copy(bytes, i, _querytext, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(QueryFlags % 256); bytes[i++] = (byte)((QueryFlags >> 8) % 256); bytes[i++] = (byte)((QueryFlags >> 16) % 256); bytes[i++] = (byte)((QueryFlags >> 24) % 256); bytes[i++] = (byte)(QueryStart % 256); bytes[i++] = (byte)((QueryStart >> 8) % 256); bytes[i++] = (byte)((QueryStart >> 16) % 256); bytes[i++] = (byte)((QueryStart >> 24) % 256); if(QueryText == null) { Console.WriteLine("Warning: QueryText is null, in " + this.GetType()); } bytes[i++] = (byte)QueryText.Length; Array.Copy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += "QueryFlags: " + QueryFlags.ToString() + "\n"; output += "QueryStart: " + QueryStart.ToString() + "\n"; output += Helpers.FieldToString(QueryText, "QueryText") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirFindQuery public override PacketType Type { get { return PacketType.DirFindQuery; } } /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirFindQueryPacket() { Header = new LowHeader(); Header.ID = 43; Header.Reliable = true; Header.Zerocoded = true; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirFindQueryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirFindQueryPacket(Header head, byte[] bytes, ref int i) { Header = head; QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirFindQuery ---\n"; output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirFindQueryBackend packet public class DirFindQueryBackendPacket : Packet { /// QueryData block public class QueryDataBlock { /// SpaceIP field public uint SpaceIP; /// Godlike field public bool Godlike; /// QueryID field public LLUUID QueryID; /// QueryFlags field public uint QueryFlags; /// QueryStart field public int QueryStart; private byte[] _querytext; /// QueryText field public byte[] QueryText { get { return _querytext; } set { if (value == null) { _querytext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _querytext = new byte[value.Length]; Array.Copy(value, _querytext, value.Length); } } } /// EstateID field public uint EstateID; /// Length of this block serialized in bytes public int Length { get { int length = 33; if (QueryText != null) { length += 1 + QueryText.Length; } return length; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { int length; try { SpaceIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; QueryID = new LLUUID(bytes, i); i += 16; QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); QueryStart = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _querytext = new byte[length]; Array.Copy(bytes, i, _querytext, 0, length); i += length; EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(SpaceIP % 256); bytes[i++] = (byte)((SpaceIP >> 8) % 256); bytes[i++] = (byte)((SpaceIP >> 16) % 256); bytes[i++] = (byte)((SpaceIP >> 24) % 256); bytes[i++] = (byte)((Godlike) ? 1 : 0); if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(QueryFlags % 256); bytes[i++] = (byte)((QueryFlags >> 8) % 256); bytes[i++] = (byte)((QueryFlags >> 16) % 256); bytes[i++] = (byte)((QueryFlags >> 24) % 256); bytes[i++] = (byte)(QueryStart % 256); bytes[i++] = (byte)((QueryStart >> 8) % 256); bytes[i++] = (byte)((QueryStart >> 16) % 256); bytes[i++] = (byte)((QueryStart >> 24) % 256); if(QueryText == null) { Console.WriteLine("Warning: QueryText is null, in " + this.GetType()); } bytes[i++] = (byte)QueryText.Length; Array.Copy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "SpaceIP: " + SpaceIP.ToString() + "\n"; output += "Godlike: " + Godlike.ToString() + "\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += "QueryFlags: " + QueryFlags.ToString() + "\n"; output += "QueryStart: " + QueryStart.ToString() + "\n"; output += Helpers.FieldToString(QueryText, "QueryText") + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirFindQueryBackend public override PacketType Type { get { return PacketType.DirFindQueryBackend; } } /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirFindQueryBackendPacket() { Header = new LowHeader(); Header.ID = 44; Header.Reliable = true; Header.Zerocoded = true; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirFindQueryBackendPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirFindQueryBackendPacket(Header head, byte[] bytes, ref int i) { Header = head; QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirFindQueryBackend ---\n"; output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirPlacesQuery packet public class DirPlacesQueryPacket : Packet { /// QueryData block public class QueryDataBlock { private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// QueryID field public LLUUID QueryID; /// Category field public sbyte Category; /// QueryFlags field public uint QueryFlags; /// QueryStart field public int QueryStart; private byte[] _querytext; /// QueryText field public byte[] QueryText { get { return _querytext; } set { if (value == null) { _querytext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _querytext = new byte[value.Length]; Array.Copy(value, _querytext, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 25; if (SimName != null) { length += 1 + SimName.Length; } if (QueryText != null) { length += 1 + QueryText.Length; } return length; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; QueryID = new LLUUID(bytes, i); i += 16; Category = (sbyte)bytes[i++]; QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); QueryStart = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _querytext = new byte[length]; Array.Copy(bytes, i, _querytext, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)Category; bytes[i++] = (byte)(QueryFlags % 256); bytes[i++] = (byte)((QueryFlags >> 8) % 256); bytes[i++] = (byte)((QueryFlags >> 16) % 256); bytes[i++] = (byte)((QueryFlags >> 24) % 256); bytes[i++] = (byte)(QueryStart % 256); bytes[i++] = (byte)((QueryStart >> 8) % 256); bytes[i++] = (byte)((QueryStart >> 16) % 256); bytes[i++] = (byte)((QueryStart >> 24) % 256); if(QueryText == null) { Console.WriteLine("Warning: QueryText is null, in " + this.GetType()); } bytes[i++] = (byte)QueryText.Length; Array.Copy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += "Category: " + Category.ToString() + "\n"; output += "QueryFlags: " + QueryFlags.ToString() + "\n"; output += "QueryStart: " + QueryStart.ToString() + "\n"; output += Helpers.FieldToString(QueryText, "QueryText") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirPlacesQuery public override PacketType Type { get { return PacketType.DirPlacesQuery; } } /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirPlacesQueryPacket() { Header = new LowHeader(); Header.ID = 45; Header.Reliable = true; Header.Zerocoded = true; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirPlacesQueryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirPlacesQueryPacket(Header head, byte[] bytes, ref int i) { Header = head; QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirPlacesQuery ---\n"; output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirPlacesQueryBackend packet public class DirPlacesQueryBackendPacket : Packet { /// QueryData block public class QueryDataBlock { private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// Godlike field public bool Godlike; /// QueryID field public LLUUID QueryID; /// Category field public sbyte Category; /// QueryFlags field public uint QueryFlags; /// QueryStart field public int QueryStart; private byte[] _querytext; /// QueryText field public byte[] QueryText { get { return _querytext; } set { if (value == null) { _querytext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _querytext = new byte[value.Length]; Array.Copy(value, _querytext, value.Length); } } } /// EstateID field public uint EstateID; /// Length of this block serialized in bytes public int Length { get { int length = 30; if (SimName != null) { length += 1 + SimName.Length; } if (QueryText != null) { length += 1 + QueryText.Length; } return length; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; QueryID = new LLUUID(bytes, i); i += 16; Category = (sbyte)bytes[i++]; QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); QueryStart = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _querytext = new byte[length]; Array.Copy(bytes, i, _querytext, 0, length); i += length; EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; bytes[i++] = (byte)((Godlike) ? 1 : 0); if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)Category; bytes[i++] = (byte)(QueryFlags % 256); bytes[i++] = (byte)((QueryFlags >> 8) % 256); bytes[i++] = (byte)((QueryFlags >> 16) % 256); bytes[i++] = (byte)((QueryFlags >> 24) % 256); bytes[i++] = (byte)(QueryStart % 256); bytes[i++] = (byte)((QueryStart >> 8) % 256); bytes[i++] = (byte)((QueryStart >> 16) % 256); bytes[i++] = (byte)((QueryStart >> 24) % 256); if(QueryText == null) { Console.WriteLine("Warning: QueryText is null, in " + this.GetType()); } bytes[i++] = (byte)QueryText.Length; Array.Copy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "Godlike: " + Godlike.ToString() + "\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += "Category: " + Category.ToString() + "\n"; output += "QueryFlags: " + QueryFlags.ToString() + "\n"; output += "QueryStart: " + QueryStart.ToString() + "\n"; output += Helpers.FieldToString(QueryText, "QueryText") + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirPlacesQueryBackend public override PacketType Type { get { return PacketType.DirPlacesQueryBackend; } } /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirPlacesQueryBackendPacket() { Header = new LowHeader(); Header.ID = 46; Header.Reliable = true; Header.Zerocoded = true; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirPlacesQueryBackendPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirPlacesQueryBackendPacket(Header head, byte[] bytes, ref int i) { Header = head; QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirPlacesQueryBackend ---\n"; output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirPlacesReply packet public class DirPlacesReplyPacket : Packet { /// QueryReplies block public class QueryRepliesBlock { /// ReservedNewbie field public bool ReservedNewbie; /// ForSale field public bool ForSale; /// ParcelID field public LLUUID ParcelID; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// Auction field public bool Auction; /// Dwell field public float Dwell; /// Length of this block serialized in bytes public int Length { get { int length = 23; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public QueryRepliesBlock() { } /// Constructor for building the block from a byte array public QueryRepliesBlock(byte[] bytes, ref int i) { int length; try { ReservedNewbie = (bytes[i++] != 0) ? (bool)true : (bool)false; ForSale = (bytes[i++] != 0) ? (bool)true : (bool)false; ParcelID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; Auction = (bytes[i++] != 0) ? (bool)true : (bool)false; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Dwell = BitConverter.ToSingle(bytes, i); i += 4; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = (byte)((ReservedNewbie) ? 1 : 0); bytes[i++] = (byte)((ForSale) ? 1 : 0); if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)((Auction) ? 1 : 0); ba = BitConverter.GetBytes(Dwell); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryReplies --\n"; output += "ReservedNewbie: " + ReservedNewbie.ToString() + "\n"; output += "ForSale: " + ForSale.ToString() + "\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "Auction: " + Auction.ToString() + "\n"; output += "Dwell: " + Dwell.ToString() + "\n"; output = output.Trim(); return output; } } /// QueryData block public class QueryDataBlock { /// QueryID field public LLUUID QueryID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { try { QueryID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirPlacesReply public override PacketType Type { get { return PacketType.DirPlacesReply; } } /// QueryReplies block public QueryRepliesBlock[] QueryReplies; /// QueryData block public QueryDataBlock[] QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirPlacesReplyPacket() { Header = new LowHeader(); Header.ID = 47; Header.Reliable = true; Header.Zerocoded = true; QueryReplies = new QueryRepliesBlock[0]; QueryData = new QueryDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirPlacesReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; QueryReplies = new QueryRepliesBlock[count]; for (int j = 0; j < count; j++) { QueryReplies[j] = new QueryRepliesBlock(bytes, ref i); } count = (int)bytes[i++]; QueryData = new QueryDataBlock[count]; for (int j = 0; j < count; j++) { QueryData[j] = new QueryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirPlacesReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; QueryReplies = new QueryRepliesBlock[count]; for (int j = 0; j < count; j++) { QueryReplies[j] = new QueryRepliesBlock(bytes, ref i); } count = (int)bytes[i++]; QueryData = new QueryDataBlock[count]; for (int j = 0; j < count; j++) { QueryData[j] = new QueryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } length++; for (int j = 0; j < QueryData.Length; j++) { length += QueryData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)QueryReplies.Length; for (int j = 0; j < QueryReplies.Length; j++) { QueryReplies[j].ToBytes(bytes, ref i); } bytes[i++] = (byte)QueryData.Length; for (int j = 0; j < QueryData.Length; j++) { QueryData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirPlacesReply ---\n"; for (int j = 0; j < QueryReplies.Length; j++) { output += QueryReplies[j].ToString() + "\n"; } for (int j = 0; j < QueryData.Length; j++) { output += QueryData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// DirPeopleQuery packet public class DirPeopleQueryPacket : Packet { /// QueryData block public class QueryDataBlock { /// SkillFlags field public uint SkillFlags; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// QueryID field public LLUUID QueryID; /// Online field public byte Online; private byte[] _reputation; /// Reputation field public byte[] Reputation { get { return _reputation; } set { if (value == null) { _reputation = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _reputation = new byte[value.Length]; Array.Copy(value, _reputation, value.Length); } } } private byte[] _distance; /// Distance field public byte[] Distance { get { return _distance; } set { if (value == null) { _distance = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _distance = new byte[value.Length]; Array.Copy(value, _distance, value.Length); } } } private byte[] _group; /// Group field public byte[] Group { get { return _group; } set { if (value == null) { _group = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _group = new byte[value.Length]; Array.Copy(value, _group, value.Length); } } } private byte[] _querytext; /// QueryText field public byte[] QueryText { get { return _querytext; } set { if (value == null) { _querytext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _querytext = new byte[value.Length]; Array.Copy(value, _querytext, value.Length); } } } /// WantToFlags field public uint WantToFlags; /// Length of this block serialized in bytes public int Length { get { int length = 25; if (Name != null) { length += 1 + Name.Length; } if (Reputation != null) { length += 1 + Reputation.Length; } if (Distance != null) { length += 1 + Distance.Length; } if (Group != null) { length += 1 + Group.Length; } if (QueryText != null) { length += 1 + QueryText.Length; } return length; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { int length; try { SkillFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; QueryID = new LLUUID(bytes, i); i += 16; Online = (byte)bytes[i++]; length = (ushort)bytes[i++]; _reputation = new byte[length]; Array.Copy(bytes, i, _reputation, 0, length); i += length; length = (ushort)bytes[i++]; _distance = new byte[length]; Array.Copy(bytes, i, _distance, 0, length); i += length; length = (ushort)bytes[i++]; _group = new byte[length]; Array.Copy(bytes, i, _group, 0, length); i += length; length = (ushort)bytes[i++]; _querytext = new byte[length]; Array.Copy(bytes, i, _querytext, 0, length); i += length; WantToFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(SkillFlags % 256); bytes[i++] = (byte)((SkillFlags >> 8) % 256); bytes[i++] = (byte)((SkillFlags >> 16) % 256); bytes[i++] = (byte)((SkillFlags >> 24) % 256); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = Online; if(Reputation == null) { Console.WriteLine("Warning: Reputation is null, in " + this.GetType()); } bytes[i++] = (byte)Reputation.Length; Array.Copy(Reputation, 0, bytes, i, Reputation.Length); i += Reputation.Length; if(Distance == null) { Console.WriteLine("Warning: Distance is null, in " + this.GetType()); } bytes[i++] = (byte)Distance.Length; Array.Copy(Distance, 0, bytes, i, Distance.Length); i += Distance.Length; if(Group == null) { Console.WriteLine("Warning: Group is null, in " + this.GetType()); } bytes[i++] = (byte)Group.Length; Array.Copy(Group, 0, bytes, i, Group.Length); i += Group.Length; if(QueryText == null) { Console.WriteLine("Warning: QueryText is null, in " + this.GetType()); } bytes[i++] = (byte)QueryText.Length; Array.Copy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; bytes[i++] = (byte)(WantToFlags % 256); bytes[i++] = (byte)((WantToFlags >> 8) % 256); bytes[i++] = (byte)((WantToFlags >> 16) % 256); bytes[i++] = (byte)((WantToFlags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "SkillFlags: " + SkillFlags.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += "Online: " + Online.ToString() + "\n"; output += Helpers.FieldToString(Reputation, "Reputation") + "\n"; output += Helpers.FieldToString(Distance, "Distance") + "\n"; output += Helpers.FieldToString(Group, "Group") + "\n"; output += Helpers.FieldToString(QueryText, "QueryText") + "\n"; output += "WantToFlags: " + WantToFlags.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirPeopleQuery public override PacketType Type { get { return PacketType.DirPeopleQuery; } } /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirPeopleQueryPacket() { Header = new LowHeader(); Header.ID = 48; Header.Reliable = true; Header.Zerocoded = true; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirPeopleQueryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirPeopleQueryPacket(Header head, byte[] bytes, ref int i) { Header = head; QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirPeopleQuery ---\n"; output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirPeopleQueryBackend packet public class DirPeopleQueryBackendPacket : Packet { /// QueryData block public class QueryDataBlock { /// SpaceIP field public uint SpaceIP; /// Godlike field public bool Godlike; /// SkillFlags field public uint SkillFlags; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// QueryID field public LLUUID QueryID; /// Online field public byte Online; private byte[] _reputation; /// Reputation field public byte[] Reputation { get { return _reputation; } set { if (value == null) { _reputation = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _reputation = new byte[value.Length]; Array.Copy(value, _reputation, value.Length); } } } private byte[] _distance; /// Distance field public byte[] Distance { get { return _distance; } set { if (value == null) { _distance = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _distance = new byte[value.Length]; Array.Copy(value, _distance, value.Length); } } } private byte[] _group; /// Group field public byte[] Group { get { return _group; } set { if (value == null) { _group = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _group = new byte[value.Length]; Array.Copy(value, _group, value.Length); } } } private byte[] _querytext; /// QueryText field public byte[] QueryText { get { return _querytext; } set { if (value == null) { _querytext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _querytext = new byte[value.Length]; Array.Copy(value, _querytext, value.Length); } } } /// EstateID field public uint EstateID; /// WantToFlags field public uint WantToFlags; /// Length of this block serialized in bytes public int Length { get { int length = 34; if (Name != null) { length += 1 + Name.Length; } if (Reputation != null) { length += 1 + Reputation.Length; } if (Distance != null) { length += 1 + Distance.Length; } if (Group != null) { length += 1 + Group.Length; } if (QueryText != null) { length += 1 + QueryText.Length; } return length; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { int length; try { SpaceIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; SkillFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; QueryID = new LLUUID(bytes, i); i += 16; Online = (byte)bytes[i++]; length = (ushort)bytes[i++]; _reputation = new byte[length]; Array.Copy(bytes, i, _reputation, 0, length); i += length; length = (ushort)bytes[i++]; _distance = new byte[length]; Array.Copy(bytes, i, _distance, 0, length); i += length; length = (ushort)bytes[i++]; _group = new byte[length]; Array.Copy(bytes, i, _group, 0, length); i += length; length = (ushort)bytes[i++]; _querytext = new byte[length]; Array.Copy(bytes, i, _querytext, 0, length); i += length; EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); WantToFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(SpaceIP % 256); bytes[i++] = (byte)((SpaceIP >> 8) % 256); bytes[i++] = (byte)((SpaceIP >> 16) % 256); bytes[i++] = (byte)((SpaceIP >> 24) % 256); bytes[i++] = (byte)((Godlike) ? 1 : 0); bytes[i++] = (byte)(SkillFlags % 256); bytes[i++] = (byte)((SkillFlags >> 8) % 256); bytes[i++] = (byte)((SkillFlags >> 16) % 256); bytes[i++] = (byte)((SkillFlags >> 24) % 256); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = Online; if(Reputation == null) { Console.WriteLine("Warning: Reputation is null, in " + this.GetType()); } bytes[i++] = (byte)Reputation.Length; Array.Copy(Reputation, 0, bytes, i, Reputation.Length); i += Reputation.Length; if(Distance == null) { Console.WriteLine("Warning: Distance is null, in " + this.GetType()); } bytes[i++] = (byte)Distance.Length; Array.Copy(Distance, 0, bytes, i, Distance.Length); i += Distance.Length; if(Group == null) { Console.WriteLine("Warning: Group is null, in " + this.GetType()); } bytes[i++] = (byte)Group.Length; Array.Copy(Group, 0, bytes, i, Group.Length); i += Group.Length; if(QueryText == null) { Console.WriteLine("Warning: QueryText is null, in " + this.GetType()); } bytes[i++] = (byte)QueryText.Length; Array.Copy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); bytes[i++] = (byte)(WantToFlags % 256); bytes[i++] = (byte)((WantToFlags >> 8) % 256); bytes[i++] = (byte)((WantToFlags >> 16) % 256); bytes[i++] = (byte)((WantToFlags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "SpaceIP: " + SpaceIP.ToString() + "\n"; output += "Godlike: " + Godlike.ToString() + "\n"; output += "SkillFlags: " + SkillFlags.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += "Online: " + Online.ToString() + "\n"; output += Helpers.FieldToString(Reputation, "Reputation") + "\n"; output += Helpers.FieldToString(Distance, "Distance") + "\n"; output += Helpers.FieldToString(Group, "Group") + "\n"; output += Helpers.FieldToString(QueryText, "QueryText") + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output += "WantToFlags: " + WantToFlags.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirPeopleQueryBackend public override PacketType Type { get { return PacketType.DirPeopleQueryBackend; } } /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirPeopleQueryBackendPacket() { Header = new LowHeader(); Header.ID = 49; Header.Reliable = true; Header.Zerocoded = true; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirPeopleQueryBackendPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirPeopleQueryBackendPacket(Header head, byte[] bytes, ref int i) { Header = head; QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirPeopleQueryBackend ---\n"; output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirPeopleReply packet public class DirPeopleReplyPacket : Packet { /// QueryReplies block public class QueryRepliesBlock { /// AgentID field public LLUUID AgentID; private byte[] _lastname; /// LastName field public byte[] LastName { get { return _lastname; } set { if (value == null) { _lastname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _lastname = new byte[value.Length]; Array.Copy(value, _lastname, value.Length); } } } private byte[] _firstname; /// FirstName field public byte[] FirstName { get { return _firstname; } set { if (value == null) { _firstname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _firstname = new byte[value.Length]; Array.Copy(value, _firstname, value.Length); } } } /// Online field public bool Online; /// Reputation field public int Reputation; private byte[] _group; /// Group field public byte[] Group { get { return _group; } set { if (value == null) { _group = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _group = new byte[value.Length]; Array.Copy(value, _group, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 21; if (LastName != null) { length += 1 + LastName.Length; } if (FirstName != null) { length += 1 + FirstName.Length; } if (Group != null) { length += 1 + Group.Length; } return length; } } /// Default constructor public QueryRepliesBlock() { } /// Constructor for building the block from a byte array public QueryRepliesBlock(byte[] bytes, ref int i) { int length; try { AgentID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _lastname = new byte[length]; Array.Copy(bytes, i, _lastname, 0, length); i += length; length = (ushort)bytes[i++]; _firstname = new byte[length]; Array.Copy(bytes, i, _firstname, 0, length); i += length; Online = (bytes[i++] != 0) ? (bool)true : (bool)false; Reputation = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _group = new byte[length]; Array.Copy(bytes, i, _group, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(LastName == null) { Console.WriteLine("Warning: LastName is null, in " + this.GetType()); } bytes[i++] = (byte)LastName.Length; Array.Copy(LastName, 0, bytes, i, LastName.Length); i += LastName.Length; if(FirstName == null) { Console.WriteLine("Warning: FirstName is null, in " + this.GetType()); } bytes[i++] = (byte)FirstName.Length; Array.Copy(FirstName, 0, bytes, i, FirstName.Length); i += FirstName.Length; bytes[i++] = (byte)((Online) ? 1 : 0); bytes[i++] = (byte)(Reputation % 256); bytes[i++] = (byte)((Reputation >> 8) % 256); bytes[i++] = (byte)((Reputation >> 16) % 256); bytes[i++] = (byte)((Reputation >> 24) % 256); if(Group == null) { Console.WriteLine("Warning: Group is null, in " + this.GetType()); } bytes[i++] = (byte)Group.Length; Array.Copy(Group, 0, bytes, i, Group.Length); i += Group.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryReplies --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += Helpers.FieldToString(LastName, "LastName") + "\n"; output += Helpers.FieldToString(FirstName, "FirstName") + "\n"; output += "Online: " + Online.ToString() + "\n"; output += "Reputation: " + Reputation.ToString() + "\n"; output += Helpers.FieldToString(Group, "Group") + "\n"; output = output.Trim(); return output; } } /// QueryData block public class QueryDataBlock { /// QueryID field public LLUUID QueryID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { try { QueryID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirPeopleReply public override PacketType Type { get { return PacketType.DirPeopleReply; } } /// QueryReplies block public QueryRepliesBlock[] QueryReplies; /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirPeopleReplyPacket() { Header = new LowHeader(); Header.ID = 50; Header.Reliable = true; Header.Zerocoded = true; QueryReplies = new QueryRepliesBlock[0]; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirPeopleReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; QueryReplies = new QueryRepliesBlock[count]; for (int j = 0; j < count; j++) { QueryReplies[j] = new QueryRepliesBlock(bytes, ref i); } QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirPeopleReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; QueryReplies = new QueryRepliesBlock[count]; for (int j = 0; j < count; j++) { QueryReplies[j] = new QueryRepliesBlock(bytes, ref i); } QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; length++; for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)QueryReplies.Length; for (int j = 0; j < QueryReplies.Length; j++) { QueryReplies[j].ToBytes(bytes, ref i); } QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirPeopleReply ---\n"; for (int j = 0; j < QueryReplies.Length; j++) { output += QueryReplies[j].ToString() + "\n"; } output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirEventsReply packet public class DirEventsReplyPacket : Packet { /// QueryReplies block public class QueryRepliesBlock { private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } private byte[] _date; /// Date field public byte[] Date { get { return _date; } set { if (value == null) { _date = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _date = new byte[value.Length]; Array.Copy(value, _date, value.Length); } } } /// EventID field public uint EventID; /// OwnerID field public LLUUID OwnerID; /// EventFlags field public uint EventFlags; /// UnixTime field public uint UnixTime; /// Length of this block serialized in bytes public int Length { get { int length = 28; if (Name != null) { length += 1 + Name.Length; } if (Date != null) { length += 1 + Date.Length; } return length; } } /// Default constructor public QueryRepliesBlock() { } /// Constructor for building the block from a byte array public QueryRepliesBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; length = (ushort)bytes[i++]; _date = new byte[length]; Array.Copy(bytes, i, _date, 0, length); i += length; EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerID = new LLUUID(bytes, i); i += 16; EventFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); UnixTime = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(Date == null) { Console.WriteLine("Warning: Date is null, in " + this.GetType()); } bytes[i++] = (byte)Date.Length; Array.Copy(Date, 0, bytes, i, Date.Length); i += Date.Length; bytes[i++] = (byte)(EventID % 256); bytes[i++] = (byte)((EventID >> 8) % 256); bytes[i++] = (byte)((EventID >> 16) % 256); bytes[i++] = (byte)((EventID >> 24) % 256); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(EventFlags % 256); bytes[i++] = (byte)((EventFlags >> 8) % 256); bytes[i++] = (byte)((EventFlags >> 16) % 256); bytes[i++] = (byte)((EventFlags >> 24) % 256); bytes[i++] = (byte)(UnixTime % 256); bytes[i++] = (byte)((UnixTime >> 8) % 256); bytes[i++] = (byte)((UnixTime >> 16) % 256); bytes[i++] = (byte)((UnixTime >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryReplies --\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += Helpers.FieldToString(Date, "Date") + "\n"; output += "EventID: " + EventID.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "EventFlags: " + EventFlags.ToString() + "\n"; output += "UnixTime: " + UnixTime.ToString() + "\n"; output = output.Trim(); return output; } } /// QueryData block public class QueryDataBlock { /// QueryID field public LLUUID QueryID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { try { QueryID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirEventsReply public override PacketType Type { get { return PacketType.DirEventsReply; } } /// QueryReplies block public QueryRepliesBlock[] QueryReplies; /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirEventsReplyPacket() { Header = new LowHeader(); Header.ID = 51; Header.Reliable = true; Header.Zerocoded = true; QueryReplies = new QueryRepliesBlock[0]; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirEventsReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; QueryReplies = new QueryRepliesBlock[count]; for (int j = 0; j < count; j++) { QueryReplies[j] = new QueryRepliesBlock(bytes, ref i); } QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirEventsReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; QueryReplies = new QueryRepliesBlock[count]; for (int j = 0; j < count; j++) { QueryReplies[j] = new QueryRepliesBlock(bytes, ref i); } QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; length++; for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)QueryReplies.Length; for (int j = 0; j < QueryReplies.Length; j++) { QueryReplies[j].ToBytes(bytes, ref i); } QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirEventsReply ---\n"; for (int j = 0; j < QueryReplies.Length; j++) { output += QueryReplies[j].ToString() + "\n"; } output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirGroupsQuery packet public class DirGroupsQueryPacket : Packet { /// QueryData block public class QueryDataBlock { /// QueryID field public LLUUID QueryID; private byte[] _querytext; /// QueryText field public byte[] QueryText { get { return _querytext; } set { if (value == null) { _querytext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _querytext = new byte[value.Length]; Array.Copy(value, _querytext, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 16; if (QueryText != null) { length += 1 + QueryText.Length; } return length; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { int length; try { QueryID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _querytext = new byte[length]; Array.Copy(bytes, i, _querytext, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; if(QueryText == null) { Console.WriteLine("Warning: QueryText is null, in " + this.GetType()); } bytes[i++] = (byte)QueryText.Length; Array.Copy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += Helpers.FieldToString(QueryText, "QueryText") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirGroupsQuery public override PacketType Type { get { return PacketType.DirGroupsQuery; } } /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirGroupsQueryPacket() { Header = new LowHeader(); Header.ID = 52; Header.Reliable = true; Header.Zerocoded = true; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirGroupsQueryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirGroupsQueryPacket(Header head, byte[] bytes, ref int i) { Header = head; QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirGroupsQuery ---\n"; output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirGroupsQueryBackend packet public class DirGroupsQueryBackendPacket : Packet { /// QueryData block public class QueryDataBlock { /// Godlike field public bool Godlike; /// QueryID field public LLUUID QueryID; private byte[] _querytext; /// QueryText field public byte[] QueryText { get { return _querytext; } set { if (value == null) { _querytext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _querytext = new byte[value.Length]; Array.Copy(value, _querytext, value.Length); } } } /// EstateID field public uint EstateID; /// Length of this block serialized in bytes public int Length { get { int length = 21; if (QueryText != null) { length += 1 + QueryText.Length; } return length; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { int length; try { Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; QueryID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _querytext = new byte[length]; Array.Copy(bytes, i, _querytext, 0, length); i += length; EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((Godlike) ? 1 : 0); if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; if(QueryText == null) { Console.WriteLine("Warning: QueryText is null, in " + this.GetType()); } bytes[i++] = (byte)QueryText.Length; Array.Copy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "Godlike: " + Godlike.ToString() + "\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += Helpers.FieldToString(QueryText, "QueryText") + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirGroupsQueryBackend public override PacketType Type { get { return PacketType.DirGroupsQueryBackend; } } /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirGroupsQueryBackendPacket() { Header = new LowHeader(); Header.ID = 53; Header.Reliable = true; Header.Zerocoded = true; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirGroupsQueryBackendPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirGroupsQueryBackendPacket(Header head, byte[] bytes, ref int i) { Header = head; QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirGroupsQueryBackend ---\n"; output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirGroupsReply packet public class DirGroupsReplyPacket : Packet { /// QueryReplies block public class QueryRepliesBlock { /// Members field public int Members; /// GroupID field public LLUUID GroupID; /// MembershipFee field public int MembershipFee; /// OpenEnrollment field public bool OpenEnrollment; private byte[] _groupname; /// GroupName field public byte[] GroupName { get { return _groupname; } set { if (value == null) { _groupname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _groupname = new byte[value.Length]; Array.Copy(value, _groupname, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 25; if (GroupName != null) { length += 1 + GroupName.Length; } return length; } } /// Default constructor public QueryRepliesBlock() { } /// Constructor for building the block from a byte array public QueryRepliesBlock(byte[] bytes, ref int i) { int length; try { Members = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupID = new LLUUID(bytes, i); i += 16; MembershipFee = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OpenEnrollment = (bytes[i++] != 0) ? (bool)true : (bool)false; length = (ushort)bytes[i++]; _groupname = new byte[length]; Array.Copy(bytes, i, _groupname, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Members % 256); bytes[i++] = (byte)((Members >> 8) % 256); bytes[i++] = (byte)((Members >> 16) % 256); bytes[i++] = (byte)((Members >> 24) % 256); if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(MembershipFee % 256); bytes[i++] = (byte)((MembershipFee >> 8) % 256); bytes[i++] = (byte)((MembershipFee >> 16) % 256); bytes[i++] = (byte)((MembershipFee >> 24) % 256); bytes[i++] = (byte)((OpenEnrollment) ? 1 : 0); if(GroupName == null) { Console.WriteLine("Warning: GroupName is null, in " + this.GetType()); } bytes[i++] = (byte)GroupName.Length; Array.Copy(GroupName, 0, bytes, i, GroupName.Length); i += GroupName.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryReplies --\n"; output += "Members: " + Members.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "MembershipFee: " + MembershipFee.ToString() + "\n"; output += "OpenEnrollment: " + OpenEnrollment.ToString() + "\n"; output += Helpers.FieldToString(GroupName, "GroupName") + "\n"; output = output.Trim(); return output; } } /// QueryData block public class QueryDataBlock { /// QueryID field public LLUUID QueryID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { try { QueryID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirGroupsReply public override PacketType Type { get { return PacketType.DirGroupsReply; } } /// QueryReplies block public QueryRepliesBlock[] QueryReplies; /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirGroupsReplyPacket() { Header = new LowHeader(); Header.ID = 54; Header.Reliable = true; Header.Zerocoded = true; QueryReplies = new QueryRepliesBlock[0]; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirGroupsReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; QueryReplies = new QueryRepliesBlock[count]; for (int j = 0; j < count; j++) { QueryReplies[j] = new QueryRepliesBlock(bytes, ref i); } QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirGroupsReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; QueryReplies = new QueryRepliesBlock[count]; for (int j = 0; j < count; j++) { QueryReplies[j] = new QueryRepliesBlock(bytes, ref i); } QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; length++; for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)QueryReplies.Length; for (int j = 0; j < QueryReplies.Length; j++) { QueryReplies[j].ToBytes(bytes, ref i); } QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirGroupsReply ---\n"; for (int j = 0; j < QueryReplies.Length; j++) { output += QueryReplies[j].ToString() + "\n"; } output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirClassifiedQuery packet public class DirClassifiedQueryPacket : Packet { /// QueryData block public class QueryDataBlock { /// QueryID field public LLUUID QueryID; /// Category field public uint Category; /// QueryFlags field public uint QueryFlags; private byte[] _querytext; /// QueryText field public byte[] QueryText { get { return _querytext; } set { if (value == null) { _querytext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _querytext = new byte[value.Length]; Array.Copy(value, _querytext, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 24; if (QueryText != null) { length += 1 + QueryText.Length; } return length; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { int length; try { QueryID = new LLUUID(bytes, i); i += 16; Category = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _querytext = new byte[length]; Array.Copy(bytes, i, _querytext, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Category % 256); bytes[i++] = (byte)((Category >> 8) % 256); bytes[i++] = (byte)((Category >> 16) % 256); bytes[i++] = (byte)((Category >> 24) % 256); bytes[i++] = (byte)(QueryFlags % 256); bytes[i++] = (byte)((QueryFlags >> 8) % 256); bytes[i++] = (byte)((QueryFlags >> 16) % 256); bytes[i++] = (byte)((QueryFlags >> 24) % 256); if(QueryText == null) { Console.WriteLine("Warning: QueryText is null, in " + this.GetType()); } bytes[i++] = (byte)QueryText.Length; Array.Copy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += "Category: " + Category.ToString() + "\n"; output += "QueryFlags: " + QueryFlags.ToString() + "\n"; output += Helpers.FieldToString(QueryText, "QueryText") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirClassifiedQuery public override PacketType Type { get { return PacketType.DirClassifiedQuery; } } /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirClassifiedQueryPacket() { Header = new LowHeader(); Header.ID = 55; Header.Reliable = true; Header.Zerocoded = true; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirClassifiedQueryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirClassifiedQueryPacket(Header head, byte[] bytes, ref int i) { Header = head; QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirClassifiedQuery ---\n"; output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirClassifiedQueryBackend packet public class DirClassifiedQueryBackendPacket : Packet { /// QueryData block public class QueryDataBlock { /// Godlike field public bool Godlike; /// QueryID field public LLUUID QueryID; /// Category field public uint Category; /// QueryFlags field public uint QueryFlags; private byte[] _querytext; /// QueryText field public byte[] QueryText { get { return _querytext; } set { if (value == null) { _querytext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _querytext = new byte[value.Length]; Array.Copy(value, _querytext, value.Length); } } } /// EstateID field public uint EstateID; /// Length of this block serialized in bytes public int Length { get { int length = 29; if (QueryText != null) { length += 1 + QueryText.Length; } return length; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { int length; try { Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; QueryID = new LLUUID(bytes, i); i += 16; Category = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _querytext = new byte[length]; Array.Copy(bytes, i, _querytext, 0, length); i += length; EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((Godlike) ? 1 : 0); if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Category % 256); bytes[i++] = (byte)((Category >> 8) % 256); bytes[i++] = (byte)((Category >> 16) % 256); bytes[i++] = (byte)((Category >> 24) % 256); bytes[i++] = (byte)(QueryFlags % 256); bytes[i++] = (byte)((QueryFlags >> 8) % 256); bytes[i++] = (byte)((QueryFlags >> 16) % 256); bytes[i++] = (byte)((QueryFlags >> 24) % 256); if(QueryText == null) { Console.WriteLine("Warning: QueryText is null, in " + this.GetType()); } bytes[i++] = (byte)QueryText.Length; Array.Copy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "Godlike: " + Godlike.ToString() + "\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += "Category: " + Category.ToString() + "\n"; output += "QueryFlags: " + QueryFlags.ToString() + "\n"; output += Helpers.FieldToString(QueryText, "QueryText") + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirClassifiedQueryBackend public override PacketType Type { get { return PacketType.DirClassifiedQueryBackend; } } /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirClassifiedQueryBackendPacket() { Header = new LowHeader(); Header.ID = 56; Header.Reliable = true; Header.Zerocoded = true; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirClassifiedQueryBackendPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirClassifiedQueryBackendPacket(Header head, byte[] bytes, ref int i) { Header = head; QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirClassifiedQueryBackend ---\n"; output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirClassifiedReply packet public class DirClassifiedReplyPacket : Packet { /// QueryReplies block public class QueryRepliesBlock { /// ClassifiedFlags field public byte ClassifiedFlags; /// CreationDate field public uint CreationDate; /// ClassifiedID field public LLUUID ClassifiedID; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// PriceForListing field public int PriceForListing; /// ExpirationDate field public uint ExpirationDate; /// Length of this block serialized in bytes public int Length { get { int length = 29; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public QueryRepliesBlock() { } /// Constructor for building the block from a byte array public QueryRepliesBlock(byte[] bytes, ref int i) { int length; try { ClassifiedFlags = (byte)bytes[i++]; CreationDate = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ClassifiedID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; PriceForListing = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ExpirationDate = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = ClassifiedFlags; bytes[i++] = (byte)(CreationDate % 256); bytes[i++] = (byte)((CreationDate >> 8) % 256); bytes[i++] = (byte)((CreationDate >> 16) % 256); bytes[i++] = (byte)((CreationDate >> 24) % 256); if(ClassifiedID == null) { Console.WriteLine("Warning: ClassifiedID is null, in " + this.GetType()); } Array.Copy(ClassifiedID.GetBytes(), 0, bytes, i, 16); i += 16; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)(PriceForListing % 256); bytes[i++] = (byte)((PriceForListing >> 8) % 256); bytes[i++] = (byte)((PriceForListing >> 16) % 256); bytes[i++] = (byte)((PriceForListing >> 24) % 256); bytes[i++] = (byte)(ExpirationDate % 256); bytes[i++] = (byte)((ExpirationDate >> 8) % 256); bytes[i++] = (byte)((ExpirationDate >> 16) % 256); bytes[i++] = (byte)((ExpirationDate >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryReplies --\n"; output += "ClassifiedFlags: " + ClassifiedFlags.ToString() + "\n"; output += "CreationDate: " + CreationDate.ToString() + "\n"; output += "ClassifiedID: " + ClassifiedID.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "PriceForListing: " + PriceForListing.ToString() + "\n"; output += "ExpirationDate: " + ExpirationDate.ToString() + "\n"; output = output.Trim(); return output; } } /// QueryData block public class QueryDataBlock { /// QueryID field public LLUUID QueryID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { try { QueryID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirClassifiedReply public override PacketType Type { get { return PacketType.DirClassifiedReply; } } /// QueryReplies block public QueryRepliesBlock[] QueryReplies; /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirClassifiedReplyPacket() { Header = new LowHeader(); Header.ID = 57; Header.Reliable = true; Header.Zerocoded = true; QueryReplies = new QueryRepliesBlock[0]; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirClassifiedReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; QueryReplies = new QueryRepliesBlock[count]; for (int j = 0; j < count; j++) { QueryReplies[j] = new QueryRepliesBlock(bytes, ref i); } QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirClassifiedReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; QueryReplies = new QueryRepliesBlock[count]; for (int j = 0; j < count; j++) { QueryReplies[j] = new QueryRepliesBlock(bytes, ref i); } QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; length++; for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)QueryReplies.Length; for (int j = 0; j < QueryReplies.Length; j++) { QueryReplies[j].ToBytes(bytes, ref i); } QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirClassifiedReply ---\n"; for (int j = 0; j < QueryReplies.Length; j++) { output += QueryReplies[j].ToString() + "\n"; } output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// AvatarClassifiedReply packet public class AvatarClassifiedReplyPacket : Packet { /// Data block public class DataBlock { /// ClassifiedID field public LLUUID ClassifiedID; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 16; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { ClassifiedID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ClassifiedID == null) { Console.WriteLine("Warning: ClassifiedID is null, in " + this.GetType()); } Array.Copy(ClassifiedID.GetBytes(), 0, bytes, i, 16); i += 16; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "ClassifiedID: " + ClassifiedID.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// TargetID field public LLUUID TargetID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; TargetID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(TargetID == null) { Console.WriteLine("Warning: TargetID is null, in " + this.GetType()); } Array.Copy(TargetID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "TargetID: " + TargetID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AvatarClassifiedReply public override PacketType Type { get { return PacketType.AvatarClassifiedReply; } } /// Data block public DataBlock[] Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AvatarClassifiedReplyPacket() { Header = new LowHeader(); Header.ID = 58; Header.Reliable = true; Data = new DataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AvatarClassifiedReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AvatarClassifiedReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)Data.Length; for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AvatarClassifiedReply ---\n"; for (int j = 0; j < Data.Length; j++) { output += Data[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ClassifiedInfoRequest packet public class ClassifiedInfoRequestPacket : Packet { /// Data block public class DataBlock { /// ClassifiedID field public LLUUID ClassifiedID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { ClassifiedID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ClassifiedID == null) { Console.WriteLine("Warning: ClassifiedID is null, in " + this.GetType()); } Array.Copy(ClassifiedID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "ClassifiedID: " + ClassifiedID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ClassifiedInfoRequest public override PacketType Type { get { return PacketType.ClassifiedInfoRequest; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ClassifiedInfoRequestPacket() { Header = new LowHeader(); Header.ID = 59; Header.Reliable = true; Header.Zerocoded = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ClassifiedInfoRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ClassifiedInfoRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ClassifiedInfoRequest ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ClassifiedInfoReply packet public class ClassifiedInfoReplyPacket : Packet { /// Data block public class DataBlock { /// ClassifiedFlags field public byte ClassifiedFlags; /// CreationDate field public uint CreationDate; private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// ClassifiedID field public LLUUID ClassifiedID; /// PosGlobal field public LLVector3d PosGlobal; /// ParcelID field public LLUUID ParcelID; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } private byte[] _desc; /// Desc field public byte[] Desc { get { return _desc; } set { if (value == null) { _desc = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _desc = new byte[value.Length]; Array.Copy(value, _desc, value.Length); } } } private byte[] _parcelname; /// ParcelName field public byte[] ParcelName { get { return _parcelname; } set { if (value == null) { _parcelname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _parcelname = new byte[value.Length]; Array.Copy(value, _parcelname, value.Length); } } } /// Category field public uint Category; /// CreatorID field public LLUUID CreatorID; /// SnapshotID field public LLUUID SnapshotID; /// PriceForListing field public int PriceForListing; /// ExpirationDate field public uint ExpirationDate; /// ParentEstate field public uint ParentEstate; /// Length of this block serialized in bytes public int Length { get { int length = 109; if (SimName != null) { length += 1 + SimName.Length; } if (Name != null) { length += 1 + Name.Length; } if (Desc != null) { length += 2 + Desc.Length; } if (ParcelName != null) { length += 1 + ParcelName.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { ClassifiedFlags = (byte)bytes[i++]; CreationDate = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; ClassifiedID = new LLUUID(bytes, i); i += 16; PosGlobal = new LLVector3d(bytes, i); i += 24; ParcelID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _desc = new byte[length]; Array.Copy(bytes, i, _desc, 0, length); i += length; length = (ushort)bytes[i++]; _parcelname = new byte[length]; Array.Copy(bytes, i, _parcelname, 0, length); i += length; Category = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CreatorID = new LLUUID(bytes, i); i += 16; SnapshotID = new LLUUID(bytes, i); i += 16; PriceForListing = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ExpirationDate = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ParentEstate = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = ClassifiedFlags; bytes[i++] = (byte)(CreationDate % 256); bytes[i++] = (byte)((CreationDate >> 8) % 256); bytes[i++] = (byte)((CreationDate >> 16) % 256); bytes[i++] = (byte)((CreationDate >> 24) % 256); if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; if(ClassifiedID == null) { Console.WriteLine("Warning: ClassifiedID is null, in " + this.GetType()); } Array.Copy(ClassifiedID.GetBytes(), 0, bytes, i, 16); i += 16; if(PosGlobal == null) { Console.WriteLine("Warning: PosGlobal is null, in " + this.GetType()); } Array.Copy(PosGlobal.GetBytes(), 0, bytes, i, 24); i += 24; if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(Desc == null) { Console.WriteLine("Warning: Desc is null, in " + this.GetType()); } bytes[i++] = (byte)(Desc.Length % 256); bytes[i++] = (byte)((Desc.Length >> 8) % 256); Array.Copy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; if(ParcelName == null) { Console.WriteLine("Warning: ParcelName is null, in " + this.GetType()); } bytes[i++] = (byte)ParcelName.Length; Array.Copy(ParcelName, 0, bytes, i, ParcelName.Length); i += ParcelName.Length; bytes[i++] = (byte)(Category % 256); bytes[i++] = (byte)((Category >> 8) % 256); bytes[i++] = (byte)((Category >> 16) % 256); bytes[i++] = (byte)((Category >> 24) % 256); if(CreatorID == null) { Console.WriteLine("Warning: CreatorID is null, in " + this.GetType()); } Array.Copy(CreatorID.GetBytes(), 0, bytes, i, 16); i += 16; if(SnapshotID == null) { Console.WriteLine("Warning: SnapshotID is null, in " + this.GetType()); } Array.Copy(SnapshotID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(PriceForListing % 256); bytes[i++] = (byte)((PriceForListing >> 8) % 256); bytes[i++] = (byte)((PriceForListing >> 16) % 256); bytes[i++] = (byte)((PriceForListing >> 24) % 256); bytes[i++] = (byte)(ExpirationDate % 256); bytes[i++] = (byte)((ExpirationDate >> 8) % 256); bytes[i++] = (byte)((ExpirationDate >> 16) % 256); bytes[i++] = (byte)((ExpirationDate >> 24) % 256); bytes[i++] = (byte)(ParentEstate % 256); bytes[i++] = (byte)((ParentEstate >> 8) % 256); bytes[i++] = (byte)((ParentEstate >> 16) % 256); bytes[i++] = (byte)((ParentEstate >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "ClassifiedFlags: " + ClassifiedFlags.ToString() + "\n"; output += "CreationDate: " + CreationDate.ToString() + "\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "ClassifiedID: " + ClassifiedID.ToString() + "\n"; output += "PosGlobal: " + PosGlobal.ToString() + "\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += Helpers.FieldToString(Desc, "Desc") + "\n"; output += Helpers.FieldToString(ParcelName, "ParcelName") + "\n"; output += "Category: " + Category.ToString() + "\n"; output += "CreatorID: " + CreatorID.ToString() + "\n"; output += "SnapshotID: " + SnapshotID.ToString() + "\n"; output += "PriceForListing: " + PriceForListing.ToString() + "\n"; output += "ExpirationDate: " + ExpirationDate.ToString() + "\n"; output += "ParentEstate: " + ParentEstate.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ClassifiedInfoReply public override PacketType Type { get { return PacketType.ClassifiedInfoReply; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ClassifiedInfoReplyPacket() { Header = new LowHeader(); Header.ID = 60; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ClassifiedInfoReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ClassifiedInfoReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ClassifiedInfoReply ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ClassifiedInfoUpdate packet public class ClassifiedInfoUpdatePacket : Packet { /// Data block public class DataBlock { /// ClassifiedFlags field public byte ClassifiedFlags; /// ClassifiedID field public LLUUID ClassifiedID; /// PosGlobal field public LLVector3d PosGlobal; /// ParcelID field public LLUUID ParcelID; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } private byte[] _desc; /// Desc field public byte[] Desc { get { return _desc; } set { if (value == null) { _desc = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _desc = new byte[value.Length]; Array.Copy(value, _desc, value.Length); } } } /// Category field public uint Category; /// SnapshotID field public LLUUID SnapshotID; /// PriceForListing field public int PriceForListing; /// ParentEstate field public uint ParentEstate; /// Length of this block serialized in bytes public int Length { get { int length = 85; if (Name != null) { length += 1 + Name.Length; } if (Desc != null) { length += 2 + Desc.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { ClassifiedFlags = (byte)bytes[i++]; ClassifiedID = new LLUUID(bytes, i); i += 16; PosGlobal = new LLVector3d(bytes, i); i += 24; ParcelID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _desc = new byte[length]; Array.Copy(bytes, i, _desc, 0, length); i += length; Category = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SnapshotID = new LLUUID(bytes, i); i += 16; PriceForListing = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ParentEstate = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = ClassifiedFlags; if(ClassifiedID == null) { Console.WriteLine("Warning: ClassifiedID is null, in " + this.GetType()); } Array.Copy(ClassifiedID.GetBytes(), 0, bytes, i, 16); i += 16; if(PosGlobal == null) { Console.WriteLine("Warning: PosGlobal is null, in " + this.GetType()); } Array.Copy(PosGlobal.GetBytes(), 0, bytes, i, 24); i += 24; if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(Desc == null) { Console.WriteLine("Warning: Desc is null, in " + this.GetType()); } bytes[i++] = (byte)(Desc.Length % 256); bytes[i++] = (byte)((Desc.Length >> 8) % 256); Array.Copy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; bytes[i++] = (byte)(Category % 256); bytes[i++] = (byte)((Category >> 8) % 256); bytes[i++] = (byte)((Category >> 16) % 256); bytes[i++] = (byte)((Category >> 24) % 256); if(SnapshotID == null) { Console.WriteLine("Warning: SnapshotID is null, in " + this.GetType()); } Array.Copy(SnapshotID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(PriceForListing % 256); bytes[i++] = (byte)((PriceForListing >> 8) % 256); bytes[i++] = (byte)((PriceForListing >> 16) % 256); bytes[i++] = (byte)((PriceForListing >> 24) % 256); bytes[i++] = (byte)(ParentEstate % 256); bytes[i++] = (byte)((ParentEstate >> 8) % 256); bytes[i++] = (byte)((ParentEstate >> 16) % 256); bytes[i++] = (byte)((ParentEstate >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "ClassifiedFlags: " + ClassifiedFlags.ToString() + "\n"; output += "ClassifiedID: " + ClassifiedID.ToString() + "\n"; output += "PosGlobal: " + PosGlobal.ToString() + "\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += Helpers.FieldToString(Desc, "Desc") + "\n"; output += "Category: " + Category.ToString() + "\n"; output += "SnapshotID: " + SnapshotID.ToString() + "\n"; output += "PriceForListing: " + PriceForListing.ToString() + "\n"; output += "ParentEstate: " + ParentEstate.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ClassifiedInfoUpdate public override PacketType Type { get { return PacketType.ClassifiedInfoUpdate; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ClassifiedInfoUpdatePacket() { Header = new LowHeader(); Header.ID = 61; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ClassifiedInfoUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ClassifiedInfoUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ClassifiedInfoUpdate ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ClassifiedDelete packet public class ClassifiedDeletePacket : Packet { /// Data block public class DataBlock { /// ClassifiedID field public LLUUID ClassifiedID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { ClassifiedID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ClassifiedID == null) { Console.WriteLine("Warning: ClassifiedID is null, in " + this.GetType()); } Array.Copy(ClassifiedID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "ClassifiedID: " + ClassifiedID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ClassifiedDelete public override PacketType Type { get { return PacketType.ClassifiedDelete; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ClassifiedDeletePacket() { Header = new LowHeader(); Header.ID = 62; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ClassifiedDeletePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ClassifiedDeletePacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ClassifiedDelete ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ClassifiedGodDelete packet public class ClassifiedGodDeletePacket : Packet { /// Data block public class DataBlock { /// ClassifiedID field public LLUUID ClassifiedID; /// QueryID field public LLUUID QueryID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { ClassifiedID = new LLUUID(bytes, i); i += 16; QueryID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ClassifiedID == null) { Console.WriteLine("Warning: ClassifiedID is null, in " + this.GetType()); } Array.Copy(ClassifiedID.GetBytes(), 0, bytes, i, 16); i += 16; if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "ClassifiedID: " + ClassifiedID.ToString() + "\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ClassifiedGodDelete public override PacketType Type { get { return PacketType.ClassifiedGodDelete; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ClassifiedGodDeletePacket() { Header = new LowHeader(); Header.ID = 63; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ClassifiedGodDeletePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ClassifiedGodDeletePacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ClassifiedGodDelete ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirPicksQuery packet public class DirPicksQueryPacket : Packet { /// QueryData block public class QueryDataBlock { /// QueryID field public LLUUID QueryID; /// QueryFlags field public uint QueryFlags; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { try { QueryID = new LLUUID(bytes, i); i += 16; QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(QueryFlags % 256); bytes[i++] = (byte)((QueryFlags >> 8) % 256); bytes[i++] = (byte)((QueryFlags >> 16) % 256); bytes[i++] = (byte)((QueryFlags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += "QueryFlags: " + QueryFlags.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirPicksQuery public override PacketType Type { get { return PacketType.DirPicksQuery; } } /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirPicksQueryPacket() { Header = new LowHeader(); Header.ID = 64; Header.Reliable = true; Header.Zerocoded = true; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirPicksQueryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirPicksQueryPacket(Header head, byte[] bytes, ref int i) { Header = head; QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirPicksQuery ---\n"; output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirPicksQueryBackend packet public class DirPicksQueryBackendPacket : Packet { /// QueryData block public class QueryDataBlock { /// Godlike field public bool Godlike; /// QueryID field public LLUUID QueryID; /// QueryFlags field public uint QueryFlags; /// EstateID field public uint EstateID; /// Length of this block serialized in bytes public int Length { get { return 25; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { try { Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; QueryID = new LLUUID(bytes, i); i += 16; QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((Godlike) ? 1 : 0); if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(QueryFlags % 256); bytes[i++] = (byte)((QueryFlags >> 8) % 256); bytes[i++] = (byte)((QueryFlags >> 16) % 256); bytes[i++] = (byte)((QueryFlags >> 24) % 256); bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "Godlike: " + Godlike.ToString() + "\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += "QueryFlags: " + QueryFlags.ToString() + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirPicksQueryBackend public override PacketType Type { get { return PacketType.DirPicksQueryBackend; } } /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirPicksQueryBackendPacket() { Header = new LowHeader(); Header.ID = 65; Header.Reliable = true; Header.Zerocoded = true; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirPicksQueryBackendPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirPicksQueryBackendPacket(Header head, byte[] bytes, ref int i) { Header = head; QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirPicksQueryBackend ---\n"; output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirPicksReply packet public class DirPicksReplyPacket : Packet { /// QueryReplies block public class QueryRepliesBlock { /// Enabled field public bool Enabled; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// PickID field public LLUUID PickID; /// Length of this block serialized in bytes public int Length { get { int length = 17; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public QueryRepliesBlock() { } /// Constructor for building the block from a byte array public QueryRepliesBlock(byte[] bytes, ref int i) { int length; try { Enabled = (bytes[i++] != 0) ? (bool)true : (bool)false; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; PickID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((Enabled) ? 1 : 0); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(PickID == null) { Console.WriteLine("Warning: PickID is null, in " + this.GetType()); } Array.Copy(PickID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryReplies --\n"; output += "Enabled: " + Enabled.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "PickID: " + PickID.ToString() + "\n"; output = output.Trim(); return output; } } /// QueryData block public class QueryDataBlock { /// QueryID field public LLUUID QueryID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { try { QueryID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirPicksReply public override PacketType Type { get { return PacketType.DirPicksReply; } } /// QueryReplies block public QueryRepliesBlock[] QueryReplies; /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirPicksReplyPacket() { Header = new LowHeader(); Header.ID = 66; Header.Reliable = true; Header.Zerocoded = true; QueryReplies = new QueryRepliesBlock[0]; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirPicksReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; QueryReplies = new QueryRepliesBlock[count]; for (int j = 0; j < count; j++) { QueryReplies[j] = new QueryRepliesBlock(bytes, ref i); } QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirPicksReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; QueryReplies = new QueryRepliesBlock[count]; for (int j = 0; j < count; j++) { QueryReplies[j] = new QueryRepliesBlock(bytes, ref i); } QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; length++; for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)QueryReplies.Length; for (int j = 0; j < QueryReplies.Length; j++) { QueryReplies[j].ToBytes(bytes, ref i); } QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirPicksReply ---\n"; for (int j = 0; j < QueryReplies.Length; j++) { output += QueryReplies[j].ToString() + "\n"; } output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirLandQuery packet public class DirLandQueryPacket : Packet { /// QueryData block public class QueryDataBlock { /// ReservedNewbie field public bool ReservedNewbie; /// ForSale field public bool ForSale; /// QueryID field public LLUUID QueryID; /// Auction field public bool Auction; /// QueryFlags field public uint QueryFlags; /// Length of this block serialized in bytes public int Length { get { return 23; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { try { ReservedNewbie = (bytes[i++] != 0) ? (bool)true : (bool)false; ForSale = (bytes[i++] != 0) ? (bool)true : (bool)false; QueryID = new LLUUID(bytes, i); i += 16; Auction = (bytes[i++] != 0) ? (bool)true : (bool)false; QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((ReservedNewbie) ? 1 : 0); bytes[i++] = (byte)((ForSale) ? 1 : 0); if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((Auction) ? 1 : 0); bytes[i++] = (byte)(QueryFlags % 256); bytes[i++] = (byte)((QueryFlags >> 8) % 256); bytes[i++] = (byte)((QueryFlags >> 16) % 256); bytes[i++] = (byte)((QueryFlags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "ReservedNewbie: " + ReservedNewbie.ToString() + "\n"; output += "ForSale: " + ForSale.ToString() + "\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += "Auction: " + Auction.ToString() + "\n"; output += "QueryFlags: " + QueryFlags.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirLandQuery public override PacketType Type { get { return PacketType.DirLandQuery; } } /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirLandQueryPacket() { Header = new LowHeader(); Header.ID = 67; Header.Reliable = true; Header.Zerocoded = true; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirLandQueryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirLandQueryPacket(Header head, byte[] bytes, ref int i) { Header = head; QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirLandQuery ---\n"; output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirLandQueryBackend packet public class DirLandQueryBackendPacket : Packet { /// QueryData block public class QueryDataBlock { /// ReservedNewbie field public bool ReservedNewbie; /// ForSale field public bool ForSale; /// Godlike field public bool Godlike; /// QueryID field public LLUUID QueryID; /// Auction field public bool Auction; /// QueryFlags field public uint QueryFlags; /// EstateID field public uint EstateID; /// Length of this block serialized in bytes public int Length { get { return 28; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { try { ReservedNewbie = (bytes[i++] != 0) ? (bool)true : (bool)false; ForSale = (bytes[i++] != 0) ? (bool)true : (bool)false; Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; QueryID = new LLUUID(bytes, i); i += 16; Auction = (bytes[i++] != 0) ? (bool)true : (bool)false; QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((ReservedNewbie) ? 1 : 0); bytes[i++] = (byte)((ForSale) ? 1 : 0); bytes[i++] = (byte)((Godlike) ? 1 : 0); if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((Auction) ? 1 : 0); bytes[i++] = (byte)(QueryFlags % 256); bytes[i++] = (byte)((QueryFlags >> 8) % 256); bytes[i++] = (byte)((QueryFlags >> 16) % 256); bytes[i++] = (byte)((QueryFlags >> 24) % 256); bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "ReservedNewbie: " + ReservedNewbie.ToString() + "\n"; output += "ForSale: " + ForSale.ToString() + "\n"; output += "Godlike: " + Godlike.ToString() + "\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += "Auction: " + Auction.ToString() + "\n"; output += "QueryFlags: " + QueryFlags.ToString() + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirLandQueryBackend public override PacketType Type { get { return PacketType.DirLandQueryBackend; } } /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirLandQueryBackendPacket() { Header = new LowHeader(); Header.ID = 68; Header.Reliable = true; Header.Zerocoded = true; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirLandQueryBackendPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirLandQueryBackendPacket(Header head, byte[] bytes, ref int i) { Header = head; QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirLandQueryBackend ---\n"; output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirLandReply packet public class DirLandReplyPacket : Packet { /// QueryReplies block public class QueryRepliesBlock { /// ReservedNewbie field public bool ReservedNewbie; /// ActualArea field public int ActualArea; /// ForSale field public bool ForSale; /// ParcelID field public LLUUID ParcelID; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// Auction field public bool Auction; /// SalePrice field public int SalePrice; /// Length of this block serialized in bytes public int Length { get { int length = 27; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public QueryRepliesBlock() { } /// Constructor for building the block from a byte array public QueryRepliesBlock(byte[] bytes, ref int i) { int length; try { ReservedNewbie = (bytes[i++] != 0) ? (bool)true : (bool)false; ActualArea = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ForSale = (bytes[i++] != 0) ? (bool)true : (bool)false; ParcelID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; Auction = (bytes[i++] != 0) ? (bool)true : (bool)false; SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((ReservedNewbie) ? 1 : 0); bytes[i++] = (byte)(ActualArea % 256); bytes[i++] = (byte)((ActualArea >> 8) % 256); bytes[i++] = (byte)((ActualArea >> 16) % 256); bytes[i++] = (byte)((ActualArea >> 24) % 256); bytes[i++] = (byte)((ForSale) ? 1 : 0); if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)((Auction) ? 1 : 0); bytes[i++] = (byte)(SalePrice % 256); bytes[i++] = (byte)((SalePrice >> 8) % 256); bytes[i++] = (byte)((SalePrice >> 16) % 256); bytes[i++] = (byte)((SalePrice >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryReplies --\n"; output += "ReservedNewbie: " + ReservedNewbie.ToString() + "\n"; output += "ActualArea: " + ActualArea.ToString() + "\n"; output += "ForSale: " + ForSale.ToString() + "\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "Auction: " + Auction.ToString() + "\n"; output += "SalePrice: " + SalePrice.ToString() + "\n"; output = output.Trim(); return output; } } /// QueryData block public class QueryDataBlock { /// QueryID field public LLUUID QueryID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { try { QueryID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirLandReply public override PacketType Type { get { return PacketType.DirLandReply; } } /// QueryReplies block public QueryRepliesBlock[] QueryReplies; /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirLandReplyPacket() { Header = new LowHeader(); Header.ID = 69; Header.Reliable = true; Header.Zerocoded = true; QueryReplies = new QueryRepliesBlock[0]; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirLandReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; QueryReplies = new QueryRepliesBlock[count]; for (int j = 0; j < count; j++) { QueryReplies[j] = new QueryRepliesBlock(bytes, ref i); } QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirLandReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; QueryReplies = new QueryRepliesBlock[count]; for (int j = 0; j < count; j++) { QueryReplies[j] = new QueryRepliesBlock(bytes, ref i); } QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; length++; for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)QueryReplies.Length; for (int j = 0; j < QueryReplies.Length; j++) { QueryReplies[j].ToBytes(bytes, ref i); } QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirLandReply ---\n"; for (int j = 0; j < QueryReplies.Length; j++) { output += QueryReplies[j].ToString() + "\n"; } output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirPopularQuery packet public class DirPopularQueryPacket : Packet { /// QueryData block public class QueryDataBlock { /// QueryID field public LLUUID QueryID; /// QueryFlags field public uint QueryFlags; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { try { QueryID = new LLUUID(bytes, i); i += 16; QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(QueryFlags % 256); bytes[i++] = (byte)((QueryFlags >> 8) % 256); bytes[i++] = (byte)((QueryFlags >> 16) % 256); bytes[i++] = (byte)((QueryFlags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += "QueryFlags: " + QueryFlags.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirPopularQuery public override PacketType Type { get { return PacketType.DirPopularQuery; } } /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirPopularQueryPacket() { Header = new LowHeader(); Header.ID = 70; Header.Reliable = true; Header.Zerocoded = true; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirPopularQueryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirPopularQueryPacket(Header head, byte[] bytes, ref int i) { Header = head; QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirPopularQuery ---\n"; output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirPopularQueryBackend packet public class DirPopularQueryBackendPacket : Packet { /// QueryData block public class QueryDataBlock { /// Godlike field public bool Godlike; /// QueryID field public LLUUID QueryID; /// QueryFlags field public uint QueryFlags; /// EstateID field public uint EstateID; /// Length of this block serialized in bytes public int Length { get { return 25; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { try { Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; QueryID = new LLUUID(bytes, i); i += 16; QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((Godlike) ? 1 : 0); if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(QueryFlags % 256); bytes[i++] = (byte)((QueryFlags >> 8) % 256); bytes[i++] = (byte)((QueryFlags >> 16) % 256); bytes[i++] = (byte)((QueryFlags >> 24) % 256); bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "Godlike: " + Godlike.ToString() + "\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += "QueryFlags: " + QueryFlags.ToString() + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirPopularQueryBackend public override PacketType Type { get { return PacketType.DirPopularQueryBackend; } } /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirPopularQueryBackendPacket() { Header = new LowHeader(); Header.ID = 71; Header.Reliable = true; Header.Zerocoded = true; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirPopularQueryBackendPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirPopularQueryBackendPacket(Header head, byte[] bytes, ref int i) { Header = head; QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirPopularQueryBackend ---\n"; output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DirPopularReply packet public class DirPopularReplyPacket : Packet { /// QueryReplies block public class QueryRepliesBlock { /// ParcelID field public LLUUID ParcelID; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// Dwell field public float Dwell; /// Length of this block serialized in bytes public int Length { get { int length = 20; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public QueryRepliesBlock() { } /// Constructor for building the block from a byte array public QueryRepliesBlock(byte[] bytes, ref int i) { int length; try { ParcelID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Dwell = BitConverter.ToSingle(bytes, i); i += 4; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; ba = BitConverter.GetBytes(Dwell); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryReplies --\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "Dwell: " + Dwell.ToString() + "\n"; output = output.Trim(); return output; } } /// QueryData block public class QueryDataBlock { /// QueryID field public LLUUID QueryID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { try { QueryID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DirPopularReply public override PacketType Type { get { return PacketType.DirPopularReply; } } /// QueryReplies block public QueryRepliesBlock[] QueryReplies; /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DirPopularReplyPacket() { Header = new LowHeader(); Header.ID = 72; Header.Reliable = true; Header.Zerocoded = true; QueryReplies = new QueryRepliesBlock[0]; QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DirPopularReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; QueryReplies = new QueryRepliesBlock[count]; for (int j = 0; j < count; j++) { QueryReplies[j] = new QueryRepliesBlock(bytes, ref i); } QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DirPopularReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; QueryReplies = new QueryRepliesBlock[count]; for (int j = 0; j < count; j++) { QueryReplies[j] = new QueryRepliesBlock(bytes, ref i); } QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length; length += AgentData.Length;; length++; for (int j = 0; j < QueryReplies.Length; j++) { length += QueryReplies[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)QueryReplies.Length; for (int j = 0; j < QueryReplies.Length; j++) { QueryReplies[j].ToBytes(bytes, ref i); } QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DirPopularReply ---\n"; for (int j = 0; j < QueryReplies.Length; j++) { output += QueryReplies[j].ToString() + "\n"; } output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ParcelInfoRequest packet public class ParcelInfoRequestPacket : Packet { /// Data block public class DataBlock { /// ParcelID field public LLUUID ParcelID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { ParcelID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelInfoRequest public override PacketType Type { get { return PacketType.ParcelInfoRequest; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelInfoRequestPacket() { Header = new LowHeader(); Header.ID = 73; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelInfoRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelInfoRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelInfoRequest ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ParcelInfoReply packet public class ParcelInfoReplyPacket : Packet { /// Data block public class DataBlock { private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// BillableArea field public int BillableArea; /// ActualArea field public int ActualArea; /// GlobalX field public float GlobalX; /// GlobalY field public float GlobalY; /// GlobalZ field public float GlobalZ; /// ParcelID field public LLUUID ParcelID; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } private byte[] _desc; /// Desc field public byte[] Desc { get { return _desc; } set { if (value == null) { _desc = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _desc = new byte[value.Length]; Array.Copy(value, _desc, value.Length); } } } /// SalePrice field public int SalePrice; /// OwnerID field public LLUUID OwnerID; /// SnapshotID field public LLUUID SnapshotID; /// Flags field public byte Flags; /// AuctionID field public int AuctionID; /// Dwell field public float Dwell; /// Length of this block serialized in bytes public int Length { get { int length = 81; if (SimName != null) { length += 1 + SimName.Length; } if (Name != null) { length += 1 + Name.Length; } if (Desc != null) { length += 1 + Desc.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; BillableArea = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ActualArea = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); GlobalX = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); GlobalY = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); GlobalZ = BitConverter.ToSingle(bytes, i); i += 4; ParcelID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; length = (ushort)bytes[i++]; _desc = new byte[length]; Array.Copy(bytes, i, _desc, 0, length); i += length; SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerID = new LLUUID(bytes, i); i += 16; SnapshotID = new LLUUID(bytes, i); i += 16; Flags = (byte)bytes[i++]; AuctionID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Dwell = BitConverter.ToSingle(bytes, i); i += 4; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; bytes[i++] = (byte)(BillableArea % 256); bytes[i++] = (byte)((BillableArea >> 8) % 256); bytes[i++] = (byte)((BillableArea >> 16) % 256); bytes[i++] = (byte)((BillableArea >> 24) % 256); bytes[i++] = (byte)(ActualArea % 256); bytes[i++] = (byte)((ActualArea >> 8) % 256); bytes[i++] = (byte)((ActualArea >> 16) % 256); bytes[i++] = (byte)((ActualArea >> 24) % 256); ba = BitConverter.GetBytes(GlobalX); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(GlobalY); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(GlobalZ); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(Desc == null) { Console.WriteLine("Warning: Desc is null, in " + this.GetType()); } bytes[i++] = (byte)Desc.Length; Array.Copy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; bytes[i++] = (byte)(SalePrice % 256); bytes[i++] = (byte)((SalePrice >> 8) % 256); bytes[i++] = (byte)((SalePrice >> 16) % 256); bytes[i++] = (byte)((SalePrice >> 24) % 256); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(SnapshotID == null) { Console.WriteLine("Warning: SnapshotID is null, in " + this.GetType()); } Array.Copy(SnapshotID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = Flags; bytes[i++] = (byte)(AuctionID % 256); bytes[i++] = (byte)((AuctionID >> 8) % 256); bytes[i++] = (byte)((AuctionID >> 16) % 256); bytes[i++] = (byte)((AuctionID >> 24) % 256); ba = BitConverter.GetBytes(Dwell); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "BillableArea: " + BillableArea.ToString() + "\n"; output += "ActualArea: " + ActualArea.ToString() + "\n"; output += "GlobalX: " + GlobalX.ToString() + "\n"; output += "GlobalY: " + GlobalY.ToString() + "\n"; output += "GlobalZ: " + GlobalZ.ToString() + "\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += Helpers.FieldToString(Desc, "Desc") + "\n"; output += "SalePrice: " + SalePrice.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "SnapshotID: " + SnapshotID.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "AuctionID: " + AuctionID.ToString() + "\n"; output += "Dwell: " + Dwell.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelInfoReply public override PacketType Type { get { return PacketType.ParcelInfoReply; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelInfoReplyPacket() { Header = new LowHeader(); Header.ID = 74; Header.Reliable = true; Header.Zerocoded = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelInfoReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelInfoReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelInfoReply ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ParcelObjectOwnersRequest packet public class ParcelObjectOwnersRequestPacket : Packet { /// ParcelData block public class ParcelDataBlock { /// LocalID field public int LocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelObjectOwnersRequest public override PacketType Type { get { return PacketType.ParcelObjectOwnersRequest; } } /// ParcelData block public ParcelDataBlock ParcelData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelObjectOwnersRequestPacket() { Header = new LowHeader(); Header.ID = 75; Header.Reliable = true; ParcelData = new ParcelDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelObjectOwnersRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelObjectOwnersRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ParcelData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ParcelData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelObjectOwnersRequest ---\n"; output += ParcelData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// OnlineStatusRequest packet public class OnlineStatusRequestPacket : Packet { /// Data block public class DataBlock { /// ID field public LLUUID ID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "ID: " + ID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SpaceIP field public uint SpaceIP; /// Godlike field public bool Godlike; /// QueryID field public LLUUID QueryID; /// EstateID field public uint EstateID; /// Length of this block serialized in bytes public int Length { get { return 41; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SpaceIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; QueryID = new LLUUID(bytes, i); i += 16; EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(SpaceIP % 256); bytes[i++] = (byte)((SpaceIP >> 8) % 256); bytes[i++] = (byte)((SpaceIP >> 16) % 256); bytes[i++] = (byte)((SpaceIP >> 24) % 256); bytes[i++] = (byte)((Godlike) ? 1 : 0); if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SpaceIP: " + SpaceIP.ToString() + "\n"; output += "Godlike: " + Godlike.ToString() + "\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.OnlineStatusRequest public override PacketType Type { get { return PacketType.OnlineStatusRequest; } } /// Data block public DataBlock[] Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public OnlineStatusRequestPacket() { Header = new LowHeader(); Header.ID = 76; Header.Reliable = true; Data = new DataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public OnlineStatusRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public OnlineStatusRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)Data.Length; for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- OnlineStatusRequest ---\n"; for (int j = 0; j < Data.Length; j++) { output += Data[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// OnlineStatusReply packet public class OnlineStatusReplyPacket : Packet { /// Data block public class DataBlock { /// ID field public LLUUID ID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "ID: " + ID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// QueryID field public LLUUID QueryID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; QueryID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.OnlineStatusReply public override PacketType Type { get { return PacketType.OnlineStatusReply; } } /// Data block public DataBlock[] Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public OnlineStatusReplyPacket() { Header = new LowHeader(); Header.ID = 77; Header.Reliable = true; Header.Zerocoded = true; Data = new DataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public OnlineStatusReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public OnlineStatusReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)Data.Length; for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- OnlineStatusReply ---\n"; for (int j = 0; j < Data.Length; j++) { output += Data[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ParcelObjectOwnersReply packet public class ParcelObjectOwnersReplyPacket : Packet { /// Data block public class DataBlock { /// OnlineStatus field public bool OnlineStatus; /// IsGroupOwned field public bool IsGroupOwned; /// OwnerID field public LLUUID OwnerID; /// Count field public int Count; /// Length of this block serialized in bytes public int Length { get { return 22; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { OnlineStatus = (bytes[i++] != 0) ? (bool)true : (bool)false; IsGroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; OwnerID = new LLUUID(bytes, i); i += 16; Count = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((OnlineStatus) ? 1 : 0); bytes[i++] = (byte)((IsGroupOwned) ? 1 : 0); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Count % 256); bytes[i++] = (byte)((Count >> 8) % 256); bytes[i++] = (byte)((Count >> 16) % 256); bytes[i++] = (byte)((Count >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "OnlineStatus: " + OnlineStatus.ToString() + "\n"; output += "IsGroupOwned: " + IsGroupOwned.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "Count: " + Count.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelObjectOwnersReply public override PacketType Type { get { return PacketType.ParcelObjectOwnersReply; } } /// Data block public DataBlock[] Data; /// Default constructor public ParcelObjectOwnersReplyPacket() { Header = new LowHeader(); Header.ID = 78; Header.Reliable = true; Header.Zerocoded = true; Data = new DataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelObjectOwnersReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public ParcelObjectOwnersReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)Data.Length; for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelObjectOwnersReply ---\n"; for (int j = 0; j < Data.Length; j++) { output += Data[j].ToString() + "\n"; } return output; } } /// GroupNoticesListRequest packet public class GroupNoticesListRequestPacket : Packet { /// Data block public class DataBlock { /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupNoticesListRequest public override PacketType Type { get { return PacketType.GroupNoticesListRequest; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GroupNoticesListRequestPacket() { Header = new LowHeader(); Header.ID = 79; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupNoticesListRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupNoticesListRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupNoticesListRequest ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// GroupNoticesListReply packet public class GroupNoticesListReplyPacket : Packet { /// Data block public class DataBlock { /// Timestamp field public uint Timestamp; private byte[] _subject; /// Subject field public byte[] Subject { get { return _subject; } set { if (value == null) { _subject = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _subject = new byte[value.Length]; Array.Copy(value, _subject, value.Length); } } } /// HasAttachment field public bool HasAttachment; /// NoticeID field public LLUUID NoticeID; private byte[] _fromname; /// FromName field public byte[] FromName { get { return _fromname; } set { if (value == null) { _fromname = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _fromname = new byte[value.Length]; Array.Copy(value, _fromname, value.Length); } } } /// AssetType field public byte AssetType; /// Length of this block serialized in bytes public int Length { get { int length = 22; if (Subject != null) { length += 2 + Subject.Length; } if (FromName != null) { length += 2 + FromName.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { Timestamp = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _subject = new byte[length]; Array.Copy(bytes, i, _subject, 0, length); i += length; HasAttachment = (bytes[i++] != 0) ? (bool)true : (bool)false; NoticeID = new LLUUID(bytes, i); i += 16; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _fromname = new byte[length]; Array.Copy(bytes, i, _fromname, 0, length); i += length; AssetType = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Timestamp % 256); bytes[i++] = (byte)((Timestamp >> 8) % 256); bytes[i++] = (byte)((Timestamp >> 16) % 256); bytes[i++] = (byte)((Timestamp >> 24) % 256); if(Subject == null) { Console.WriteLine("Warning: Subject is null, in " + this.GetType()); } bytes[i++] = (byte)(Subject.Length % 256); bytes[i++] = (byte)((Subject.Length >> 8) % 256); Array.Copy(Subject, 0, bytes, i, Subject.Length); i += Subject.Length; bytes[i++] = (byte)((HasAttachment) ? 1 : 0); if(NoticeID == null) { Console.WriteLine("Warning: NoticeID is null, in " + this.GetType()); } Array.Copy(NoticeID.GetBytes(), 0, bytes, i, 16); i += 16; if(FromName == null) { Console.WriteLine("Warning: FromName is null, in " + this.GetType()); } bytes[i++] = (byte)(FromName.Length % 256); bytes[i++] = (byte)((FromName.Length >> 8) % 256); Array.Copy(FromName, 0, bytes, i, FromName.Length); i += FromName.Length; bytes[i++] = AssetType; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "Timestamp: " + Timestamp.ToString() + "\n"; output += Helpers.FieldToString(Subject, "Subject") + "\n"; output += "HasAttachment: " + HasAttachment.ToString() + "\n"; output += "NoticeID: " + NoticeID.ToString() + "\n"; output += Helpers.FieldToString(FromName, "FromName") + "\n"; output += "AssetType: " + AssetType.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupNoticesListReply public override PacketType Type { get { return PacketType.GroupNoticesListReply; } } /// Data block public DataBlock[] Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GroupNoticesListReplyPacket() { Header = new LowHeader(); Header.ID = 80; Header.Reliable = true; Data = new DataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupNoticesListReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupNoticesListReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)Data.Length; for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupNoticesListReply ---\n"; for (int j = 0; j < Data.Length; j++) { output += Data[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// GroupNoticeRequest packet public class GroupNoticeRequestPacket : Packet { /// Data block public class DataBlock { /// GroupNoticeID field public LLUUID GroupNoticeID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { GroupNoticeID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GroupNoticeID == null) { Console.WriteLine("Warning: GroupNoticeID is null, in " + this.GetType()); } Array.Copy(GroupNoticeID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "GroupNoticeID: " + GroupNoticeID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupNoticeRequest public override PacketType Type { get { return PacketType.GroupNoticeRequest; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GroupNoticeRequestPacket() { Header = new LowHeader(); Header.ID = 81; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupNoticeRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupNoticeRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupNoticeRequest ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// GroupNoticeAdd packet public class GroupNoticeAddPacket : Packet { /// MessageBlock block public class MessageBlockBlock { /// ID field public LLUUID ID; private byte[] _message; /// Message field public byte[] Message { get { return _message; } set { if (value == null) { _message = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _message = new byte[value.Length]; Array.Copy(value, _message, value.Length); } } } /// Dialog field public byte Dialog; /// ToGroupID field public LLUUID ToGroupID; private byte[] _binarybucket; /// BinaryBucket field public byte[] BinaryBucket { get { return _binarybucket; } set { if (value == null) { _binarybucket = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _binarybucket = new byte[value.Length]; Array.Copy(value, _binarybucket, value.Length); } } } private byte[] _fromagentname; /// FromAgentName field public byte[] FromAgentName { get { return _fromagentname; } set { if (value == null) { _fromagentname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _fromagentname = new byte[value.Length]; Array.Copy(value, _fromagentname, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 33; if (Message != null) { length += 2 + Message.Length; } if (BinaryBucket != null) { length += 2 + BinaryBucket.Length; } if (FromAgentName != null) { length += 1 + FromAgentName.Length; } return length; } } /// Default constructor public MessageBlockBlock() { } /// Constructor for building the block from a byte array public MessageBlockBlock(byte[] bytes, ref int i) { int length; try { ID = new LLUUID(bytes, i); i += 16; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _message = new byte[length]; Array.Copy(bytes, i, _message, 0, length); i += length; Dialog = (byte)bytes[i++]; ToGroupID = new LLUUID(bytes, i); i += 16; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _binarybucket = new byte[length]; Array.Copy(bytes, i, _binarybucket, 0, length); i += length; length = (ushort)bytes[i++]; _fromagentname = new byte[length]; Array.Copy(bytes, i, _fromagentname, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; if(Message == null) { Console.WriteLine("Warning: Message is null, in " + this.GetType()); } bytes[i++] = (byte)(Message.Length % 256); bytes[i++] = (byte)((Message.Length >> 8) % 256); Array.Copy(Message, 0, bytes, i, Message.Length); i += Message.Length; bytes[i++] = Dialog; if(ToGroupID == null) { Console.WriteLine("Warning: ToGroupID is null, in " + this.GetType()); } Array.Copy(ToGroupID.GetBytes(), 0, bytes, i, 16); i += 16; if(BinaryBucket == null) { Console.WriteLine("Warning: BinaryBucket is null, in " + this.GetType()); } bytes[i++] = (byte)(BinaryBucket.Length % 256); bytes[i++] = (byte)((BinaryBucket.Length >> 8) % 256); Array.Copy(BinaryBucket, 0, bytes, i, BinaryBucket.Length); i += BinaryBucket.Length; if(FromAgentName == null) { Console.WriteLine("Warning: FromAgentName is null, in " + this.GetType()); } bytes[i++] = (byte)FromAgentName.Length; Array.Copy(FromAgentName, 0, bytes, i, FromAgentName.Length); i += FromAgentName.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MessageBlock --\n"; output += "ID: " + ID.ToString() + "\n"; output += Helpers.FieldToString(Message, "Message") + "\n"; output += "Dialog: " + Dialog.ToString() + "\n"; output += "ToGroupID: " + ToGroupID.ToString() + "\n"; output += Helpers.FieldToString(BinaryBucket, "BinaryBucket") + "\n"; output += Helpers.FieldToString(FromAgentName, "FromAgentName") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupNoticeAdd public override PacketType Type { get { return PacketType.GroupNoticeAdd; } } /// MessageBlock block public MessageBlockBlock MessageBlock; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GroupNoticeAddPacket() { Header = new LowHeader(); Header.ID = 82; Header.Reliable = true; MessageBlock = new MessageBlockBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupNoticeAddPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MessageBlock = new MessageBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupNoticeAddPacket(Header head, byte[] bytes, ref int i) { Header = head; MessageBlock = new MessageBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MessageBlock.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MessageBlock.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupNoticeAdd ---\n"; output += MessageBlock.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// GroupNoticeDelete packet public class GroupNoticeDeletePacket : Packet { /// Data block public class DataBlock { /// GroupNoticeID field public LLUUID GroupNoticeID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { GroupNoticeID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GroupNoticeID == null) { Console.WriteLine("Warning: GroupNoticeID is null, in " + this.GetType()); } Array.Copy(GroupNoticeID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "GroupNoticeID: " + GroupNoticeID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupNoticeDelete public override PacketType Type { get { return PacketType.GroupNoticeDelete; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GroupNoticeDeletePacket() { Header = new LowHeader(); Header.ID = 83; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupNoticeDeletePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupNoticeDeletePacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupNoticeDelete ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// TeleportRequest packet public class TeleportRequestPacket : Packet { /// Info block public class InfoBlock { /// RegionID field public LLUUID RegionID; /// LookAt field public LLVector3 LookAt; /// Position field public LLVector3 Position; /// Length of this block serialized in bytes public int Length { get { return 40; } } /// Default constructor public InfoBlock() { } /// Constructor for building the block from a byte array public InfoBlock(byte[] bytes, ref int i) { try { RegionID = new LLUUID(bytes, i); i += 16; LookAt = new LLVector3(bytes, i); i += 12; Position = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RegionID == null) { Console.WriteLine("Warning: RegionID is null, in " + this.GetType()); } Array.Copy(RegionID.GetBytes(), 0, bytes, i, 16); i += 16; if(LookAt == null) { Console.WriteLine("Warning: LookAt is null, in " + this.GetType()); } Array.Copy(LookAt.GetBytes(), 0, bytes, i, 12); i += 12; if(Position == null) { Console.WriteLine("Warning: Position is null, in " + this.GetType()); } Array.Copy(Position.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Info --\n"; output += "RegionID: " + RegionID.ToString() + "\n"; output += "LookAt: " + LookAt.ToString() + "\n"; output += "Position: " + Position.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TeleportRequest public override PacketType Type { get { return PacketType.TeleportRequest; } } /// Info block public InfoBlock Info; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public TeleportRequestPacket() { Header = new LowHeader(); Header.ID = 84; Header.Reliable = true; Info = new InfoBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TeleportRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Info = new InfoBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TeleportRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; Info = new InfoBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Info.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Info.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TeleportRequest ---\n"; output += Info.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// TeleportLocationRequest packet public class TeleportLocationRequestPacket : Packet { /// Info block public class InfoBlock { /// RegionHandle field public ulong RegionHandle; /// LookAt field public LLVector3 LookAt; /// Position field public LLVector3 Position; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public InfoBlock() { } /// Constructor for building the block from a byte array public InfoBlock(byte[] bytes, ref int i) { try { RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); LookAt = new LLVector3(bytes, i); i += 12; Position = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); if(LookAt == null) { Console.WriteLine("Warning: LookAt is null, in " + this.GetType()); } Array.Copy(LookAt.GetBytes(), 0, bytes, i, 12); i += 12; if(Position == null) { Console.WriteLine("Warning: Position is null, in " + this.GetType()); } Array.Copy(Position.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Info --\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output += "LookAt: " + LookAt.ToString() + "\n"; output += "Position: " + Position.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TeleportLocationRequest public override PacketType Type { get { return PacketType.TeleportLocationRequest; } } /// Info block public InfoBlock Info; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public TeleportLocationRequestPacket() { Header = new LowHeader(); Header.ID = 85; Header.Reliable = true; Info = new InfoBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TeleportLocationRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Info = new InfoBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TeleportLocationRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; Info = new InfoBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Info.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Info.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TeleportLocationRequest ---\n"; output += Info.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// TeleportLocal packet public class TeleportLocalPacket : Packet { /// Info block public class InfoBlock { /// AgentID field public LLUUID AgentID; /// LocationID field public uint LocationID; /// LookAt field public LLVector3 LookAt; /// TeleportFlags field public uint TeleportFlags; /// Position field public LLVector3 Position; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public InfoBlock() { } /// Constructor for building the block from a byte array public InfoBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; LocationID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); LookAt = new LLVector3(bytes, i); i += 12; TeleportFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Position = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(LocationID % 256); bytes[i++] = (byte)((LocationID >> 8) % 256); bytes[i++] = (byte)((LocationID >> 16) % 256); bytes[i++] = (byte)((LocationID >> 24) % 256); if(LookAt == null) { Console.WriteLine("Warning: LookAt is null, in " + this.GetType()); } Array.Copy(LookAt.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = (byte)(TeleportFlags % 256); bytes[i++] = (byte)((TeleportFlags >> 8) % 256); bytes[i++] = (byte)((TeleportFlags >> 16) % 256); bytes[i++] = (byte)((TeleportFlags >> 24) % 256); if(Position == null) { Console.WriteLine("Warning: Position is null, in " + this.GetType()); } Array.Copy(Position.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Info --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "LocationID: " + LocationID.ToString() + "\n"; output += "LookAt: " + LookAt.ToString() + "\n"; output += "TeleportFlags: " + TeleportFlags.ToString() + "\n"; output += "Position: " + Position.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TeleportLocal public override PacketType Type { get { return PacketType.TeleportLocal; } } /// Info block public InfoBlock Info; /// Default constructor public TeleportLocalPacket() { Header = new LowHeader(); Header.ID = 86; Header.Reliable = true; Info = new InfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TeleportLocalPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Info = new InfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TeleportLocalPacket(Header head, byte[] bytes, ref int i) { Header = head; Info = new InfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Info.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Info.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TeleportLocal ---\n"; output += Info.ToString() + "\n"; return output; } } /// TeleportLandmarkRequest packet public class TeleportLandmarkRequestPacket : Packet { /// Info block public class InfoBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// LandmarkID field public LLUUID LandmarkID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public InfoBlock() { } /// Constructor for building the block from a byte array public InfoBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; LandmarkID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(LandmarkID == null) { Console.WriteLine("Warning: LandmarkID is null, in " + this.GetType()); } Array.Copy(LandmarkID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Info --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "LandmarkID: " + LandmarkID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TeleportLandmarkRequest public override PacketType Type { get { return PacketType.TeleportLandmarkRequest; } } /// Info block public InfoBlock Info; /// Default constructor public TeleportLandmarkRequestPacket() { Header = new LowHeader(); Header.ID = 87; Header.Reliable = true; Header.Zerocoded = true; Info = new InfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TeleportLandmarkRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Info = new InfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TeleportLandmarkRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; Info = new InfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Info.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Info.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TeleportLandmarkRequest ---\n"; output += Info.ToString() + "\n"; return output; } } /// TeleportProgress packet public class TeleportProgressPacket : Packet { /// Info block public class InfoBlock { private byte[] _message; /// Message field public byte[] Message { get { return _message; } set { if (value == null) { _message = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _message = new byte[value.Length]; Array.Copy(value, _message, value.Length); } } } /// TeleportFlags field public uint TeleportFlags; /// Length of this block serialized in bytes public int Length { get { int length = 4; if (Message != null) { length += 1 + Message.Length; } return length; } } /// Default constructor public InfoBlock() { } /// Constructor for building the block from a byte array public InfoBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _message = new byte[length]; Array.Copy(bytes, i, _message, 0, length); i += length; TeleportFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Message == null) { Console.WriteLine("Warning: Message is null, in " + this.GetType()); } bytes[i++] = (byte)Message.Length; Array.Copy(Message, 0, bytes, i, Message.Length); i += Message.Length; bytes[i++] = (byte)(TeleportFlags % 256); bytes[i++] = (byte)((TeleportFlags >> 8) % 256); bytes[i++] = (byte)((TeleportFlags >> 16) % 256); bytes[i++] = (byte)((TeleportFlags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Info --\n"; output += Helpers.FieldToString(Message, "Message") + "\n"; output += "TeleportFlags: " + TeleportFlags.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TeleportProgress public override PacketType Type { get { return PacketType.TeleportProgress; } } /// Info block public InfoBlock Info; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public TeleportProgressPacket() { Header = new LowHeader(); Header.ID = 88; Header.Reliable = true; Info = new InfoBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TeleportProgressPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Info = new InfoBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TeleportProgressPacket(Header head, byte[] bytes, ref int i) { Header = head; Info = new InfoBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Info.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Info.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TeleportProgress ---\n"; output += Info.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DataAgentAccessRequest packet public class DataAgentAccessRequestPacket : Packet { /// Info block public class InfoBlock { /// LocationPos field public LLVector3 LocationPos; /// AgentID field public LLUUID AgentID; /// RegionHandle field public ulong RegionHandle; /// LocationID field public uint LocationID; /// LocationLookAt field public LLVector3 LocationLookAt; /// EstateID field public uint EstateID; /// Length of this block serialized in bytes public int Length { get { return 56; } } /// Default constructor public InfoBlock() { } /// Constructor for building the block from a byte array public InfoBlock(byte[] bytes, ref int i) { try { LocationPos = new LLVector3(bytes, i); i += 12; AgentID = new LLUUID(bytes, i); i += 16; RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); LocationID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); LocationLookAt = new LLVector3(bytes, i); i += 12; EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(LocationPos == null) { Console.WriteLine("Warning: LocationPos is null, in " + this.GetType()); } Array.Copy(LocationPos.GetBytes(), 0, bytes, i, 12); i += 12; if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); bytes[i++] = (byte)(LocationID % 256); bytes[i++] = (byte)((LocationID >> 8) % 256); bytes[i++] = (byte)((LocationID >> 16) % 256); bytes[i++] = (byte)((LocationID >> 24) % 256); if(LocationLookAt == null) { Console.WriteLine("Warning: LocationLookAt is null, in " + this.GetType()); } Array.Copy(LocationLookAt.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Info --\n"; output += "LocationPos: " + LocationPos.ToString() + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output += "LocationID: " + LocationID.ToString() + "\n"; output += "LocationLookAt: " + LocationLookAt.ToString() + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DataAgentAccessRequest public override PacketType Type { get { return PacketType.DataAgentAccessRequest; } } /// Info block public InfoBlock Info; /// Default constructor public DataAgentAccessRequestPacket() { Header = new LowHeader(); Header.ID = 89; Header.Reliable = true; Info = new InfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DataAgentAccessRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Info = new InfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DataAgentAccessRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; Info = new InfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Info.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Info.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DataAgentAccessRequest ---\n"; output += Info.ToString() + "\n"; return output; } } /// DataAgentAccessReply packet public class DataAgentAccessReplyPacket : Packet { /// Info block public class InfoBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public InfoBlock() { } /// Constructor for building the block from a byte array public InfoBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Info --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DataAgentAccessReply public override PacketType Type { get { return PacketType.DataAgentAccessReply; } } /// Info block public InfoBlock Info; /// Default constructor public DataAgentAccessReplyPacket() { Header = new LowHeader(); Header.ID = 90; Header.Reliable = true; Info = new InfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DataAgentAccessReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Info = new InfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DataAgentAccessReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; Info = new InfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Info.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Info.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DataAgentAccessReply ---\n"; output += Info.ToString() + "\n"; return output; } } /// DataHomeLocationRequest packet public class DataHomeLocationRequestPacket : Packet { /// Info block public class InfoBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public InfoBlock() { } /// Constructor for building the block from a byte array public InfoBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Info --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DataHomeLocationRequest public override PacketType Type { get { return PacketType.DataHomeLocationRequest; } } /// Info block public InfoBlock Info; /// Default constructor public DataHomeLocationRequestPacket() { Header = new LowHeader(); Header.ID = 91; Header.Reliable = true; Header.Zerocoded = true; Info = new InfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DataHomeLocationRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Info = new InfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DataHomeLocationRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; Info = new InfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Info.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Info.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DataHomeLocationRequest ---\n"; output += Info.ToString() + "\n"; return output; } } /// DataHomeLocationReply packet public class DataHomeLocationReplyPacket : Packet { /// Info block public class InfoBlock { /// AgentID field public LLUUID AgentID; /// RegionHandle field public ulong RegionHandle; /// LookAt field public LLVector3 LookAt; /// Position field public LLVector3 Position; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public InfoBlock() { } /// Constructor for building the block from a byte array public InfoBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); LookAt = new LLVector3(bytes, i); i += 12; Position = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); if(LookAt == null) { Console.WriteLine("Warning: LookAt is null, in " + this.GetType()); } Array.Copy(LookAt.GetBytes(), 0, bytes, i, 12); i += 12; if(Position == null) { Console.WriteLine("Warning: Position is null, in " + this.GetType()); } Array.Copy(Position.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Info --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output += "LookAt: " + LookAt.ToString() + "\n"; output += "Position: " + Position.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DataHomeLocationReply public override PacketType Type { get { return PacketType.DataHomeLocationReply; } } /// Info block public InfoBlock Info; /// Default constructor public DataHomeLocationReplyPacket() { Header = new LowHeader(); Header.ID = 92; Header.Reliable = true; Info = new InfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DataHomeLocationReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Info = new InfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DataHomeLocationReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; Info = new InfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Info.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Info.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DataHomeLocationReply ---\n"; output += Info.ToString() + "\n"; return output; } } /// SpaceLocationTeleportRequest packet public class SpaceLocationTeleportRequestPacket : Packet { /// Info block public class InfoBlock { /// AgentID field public LLUUID AgentID; /// TravelAccess field public byte TravelAccess; /// SessionID field public LLUUID SessionID; /// RegionHandle field public ulong RegionHandle; /// CircuitCode field public uint CircuitCode; /// LookAt field public LLVector3 LookAt; /// ParentEstateID field public uint ParentEstateID; /// TeleportFlags field public uint TeleportFlags; /// Position field public LLVector3 Position; /// Length of this block serialized in bytes public int Length { get { return 77; } } /// Default constructor public InfoBlock() { } /// Constructor for building the block from a byte array public InfoBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; TravelAccess = (byte)bytes[i++]; SessionID = new LLUUID(bytes, i); i += 16; RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); CircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); LookAt = new LLVector3(bytes, i); i += 12; ParentEstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TeleportFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Position = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = TravelAccess; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); bytes[i++] = (byte)(CircuitCode % 256); bytes[i++] = (byte)((CircuitCode >> 8) % 256); bytes[i++] = (byte)((CircuitCode >> 16) % 256); bytes[i++] = (byte)((CircuitCode >> 24) % 256); if(LookAt == null) { Console.WriteLine("Warning: LookAt is null, in " + this.GetType()); } Array.Copy(LookAt.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = (byte)(ParentEstateID % 256); bytes[i++] = (byte)((ParentEstateID >> 8) % 256); bytes[i++] = (byte)((ParentEstateID >> 16) % 256); bytes[i++] = (byte)((ParentEstateID >> 24) % 256); bytes[i++] = (byte)(TeleportFlags % 256); bytes[i++] = (byte)((TeleportFlags >> 8) % 256); bytes[i++] = (byte)((TeleportFlags >> 16) % 256); bytes[i++] = (byte)((TeleportFlags >> 24) % 256); if(Position == null) { Console.WriteLine("Warning: Position is null, in " + this.GetType()); } Array.Copy(Position.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Info --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "TravelAccess: " + TravelAccess.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output += "CircuitCode: " + CircuitCode.ToString() + "\n"; output += "LookAt: " + LookAt.ToString() + "\n"; output += "ParentEstateID: " + ParentEstateID.ToString() + "\n"; output += "TeleportFlags: " + TeleportFlags.ToString() + "\n"; output += "Position: " + Position.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SpaceLocationTeleportRequest public override PacketType Type { get { return PacketType.SpaceLocationTeleportRequest; } } /// Info block public InfoBlock Info; /// Default constructor public SpaceLocationTeleportRequestPacket() { Header = new LowHeader(); Header.ID = 93; Header.Reliable = true; Info = new InfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SpaceLocationTeleportRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Info = new InfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SpaceLocationTeleportRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; Info = new InfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Info.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Info.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SpaceLocationTeleportRequest ---\n"; output += Info.ToString() + "\n"; return output; } } /// SpaceLocationTeleportReply packet public class SpaceLocationTeleportReplyPacket : Packet { /// Info block public class InfoBlock { private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// AgentID field public LLUUID AgentID; /// SimPort field public ushort SimPort; /// RegionHandle field public ulong RegionHandle; /// LocationID field public uint LocationID; /// SimAccess field public byte SimAccess; /// LookAt field public LLVector3 LookAt; /// SimIP field public uint SimIP; /// TeleportFlags field public uint TeleportFlags; /// Position field public LLVector3 Position; /// Length of this block serialized in bytes public int Length { get { int length = 63; if (SimName != null) { length += 1 + SimName.Length; } return length; } } /// Default constructor public InfoBlock() { } /// Constructor for building the block from a byte array public InfoBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; AgentID = new LLUUID(bytes, i); i += 16; SimPort = (ushort)((bytes[i++] << 8) + bytes[i++]); RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); LocationID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SimAccess = (byte)bytes[i++]; LookAt = new LLVector3(bytes, i); i += 12; SimIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TeleportFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Position = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((SimPort >> 8) % 256); bytes[i++] = (byte)(SimPort % 256); bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); bytes[i++] = (byte)(LocationID % 256); bytes[i++] = (byte)((LocationID >> 8) % 256); bytes[i++] = (byte)((LocationID >> 16) % 256); bytes[i++] = (byte)((LocationID >> 24) % 256); bytes[i++] = SimAccess; if(LookAt == null) { Console.WriteLine("Warning: LookAt is null, in " + this.GetType()); } Array.Copy(LookAt.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = (byte)(SimIP % 256); bytes[i++] = (byte)((SimIP >> 8) % 256); bytes[i++] = (byte)((SimIP >> 16) % 256); bytes[i++] = (byte)((SimIP >> 24) % 256); bytes[i++] = (byte)(TeleportFlags % 256); bytes[i++] = (byte)((TeleportFlags >> 8) % 256); bytes[i++] = (byte)((TeleportFlags >> 16) % 256); bytes[i++] = (byte)((TeleportFlags >> 24) % 256); if(Position == null) { Console.WriteLine("Warning: Position is null, in " + this.GetType()); } Array.Copy(Position.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Info --\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SimPort: " + SimPort.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output += "LocationID: " + LocationID.ToString() + "\n"; output += "SimAccess: " + SimAccess.ToString() + "\n"; output += "LookAt: " + LookAt.ToString() + "\n"; output += "SimIP: " + SimIP.ToString() + "\n"; output += "TeleportFlags: " + TeleportFlags.ToString() + "\n"; output += "Position: " + Position.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SpaceLocationTeleportReply public override PacketType Type { get { return PacketType.SpaceLocationTeleportReply; } } /// Info block public InfoBlock Info; /// Default constructor public SpaceLocationTeleportReplyPacket() { Header = new LowHeader(); Header.ID = 94; Header.Reliable = true; Info = new InfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SpaceLocationTeleportReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Info = new InfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SpaceLocationTeleportReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; Info = new InfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Info.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Info.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SpaceLocationTeleportReply ---\n"; output += Info.ToString() + "\n"; return output; } } /// TeleportFinish packet public class TeleportFinishPacket : Packet { /// Info block public class InfoBlock { private byte[] _seedcapability; /// SeedCapability field public byte[] SeedCapability { get { return _seedcapability; } set { if (value == null) { _seedcapability = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _seedcapability = new byte[value.Length]; Array.Copy(value, _seedcapability, value.Length); } } } /// AgentID field public LLUUID AgentID; /// SimPort field public ushort SimPort; /// RegionHandle field public ulong RegionHandle; /// LocationID field public uint LocationID; /// SimAccess field public byte SimAccess; /// SimIP field public uint SimIP; /// TeleportFlags field public uint TeleportFlags; /// Length of this block serialized in bytes public int Length { get { int length = 39; if (SeedCapability != null) { length += 2 + SeedCapability.Length; } return length; } } /// Default constructor public InfoBlock() { } /// Constructor for building the block from a byte array public InfoBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _seedcapability = new byte[length]; Array.Copy(bytes, i, _seedcapability, 0, length); i += length; AgentID = new LLUUID(bytes, i); i += 16; SimPort = (ushort)((bytes[i++] << 8) + bytes[i++]); RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); LocationID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SimAccess = (byte)bytes[i++]; SimIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TeleportFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(SeedCapability == null) { Console.WriteLine("Warning: SeedCapability is null, in " + this.GetType()); } bytes[i++] = (byte)(SeedCapability.Length % 256); bytes[i++] = (byte)((SeedCapability.Length >> 8) % 256); Array.Copy(SeedCapability, 0, bytes, i, SeedCapability.Length); i += SeedCapability.Length; if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((SimPort >> 8) % 256); bytes[i++] = (byte)(SimPort % 256); bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); bytes[i++] = (byte)(LocationID % 256); bytes[i++] = (byte)((LocationID >> 8) % 256); bytes[i++] = (byte)((LocationID >> 16) % 256); bytes[i++] = (byte)((LocationID >> 24) % 256); bytes[i++] = SimAccess; bytes[i++] = (byte)(SimIP % 256); bytes[i++] = (byte)((SimIP >> 8) % 256); bytes[i++] = (byte)((SimIP >> 16) % 256); bytes[i++] = (byte)((SimIP >> 24) % 256); bytes[i++] = (byte)(TeleportFlags % 256); bytes[i++] = (byte)((TeleportFlags >> 8) % 256); bytes[i++] = (byte)((TeleportFlags >> 16) % 256); bytes[i++] = (byte)((TeleportFlags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Info --\n"; output += Helpers.FieldToString(SeedCapability, "SeedCapability") + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SimPort: " + SimPort.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output += "LocationID: " + LocationID.ToString() + "\n"; output += "SimAccess: " + SimAccess.ToString() + "\n"; output += "SimIP: " + SimIP.ToString() + "\n"; output += "TeleportFlags: " + TeleportFlags.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TeleportFinish public override PacketType Type { get { return PacketType.TeleportFinish; } } /// Info block public InfoBlock Info; /// Default constructor public TeleportFinishPacket() { Header = new LowHeader(); Header.ID = 95; Header.Reliable = true; Info = new InfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TeleportFinishPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Info = new InfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TeleportFinishPacket(Header head, byte[] bytes, ref int i) { Header = head; Info = new InfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Info.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Info.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TeleportFinish ---\n"; output += Info.ToString() + "\n"; return output; } } /// StartLure packet public class StartLurePacket : Packet { /// Info block public class InfoBlock { private byte[] _message; /// Message field public byte[] Message { get { return _message; } set { if (value == null) { _message = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _message = new byte[value.Length]; Array.Copy(value, _message, value.Length); } } } /// TargetID field public LLUUID TargetID; /// LureType field public byte LureType; /// Length of this block serialized in bytes public int Length { get { int length = 17; if (Message != null) { length += 1 + Message.Length; } return length; } } /// Default constructor public InfoBlock() { } /// Constructor for building the block from a byte array public InfoBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _message = new byte[length]; Array.Copy(bytes, i, _message, 0, length); i += length; TargetID = new LLUUID(bytes, i); i += 16; LureType = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Message == null) { Console.WriteLine("Warning: Message is null, in " + this.GetType()); } bytes[i++] = (byte)Message.Length; Array.Copy(Message, 0, bytes, i, Message.Length); i += Message.Length; if(TargetID == null) { Console.WriteLine("Warning: TargetID is null, in " + this.GetType()); } Array.Copy(TargetID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = LureType; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Info --\n"; output += Helpers.FieldToString(Message, "Message") + "\n"; output += "TargetID: " + TargetID.ToString() + "\n"; output += "LureType: " + LureType.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.StartLure public override PacketType Type { get { return PacketType.StartLure; } } /// Info block public InfoBlock Info; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public StartLurePacket() { Header = new LowHeader(); Header.ID = 96; Header.Reliable = true; Info = new InfoBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public StartLurePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Info = new InfoBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public StartLurePacket(Header head, byte[] bytes, ref int i) { Header = head; Info = new InfoBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Info.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Info.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- StartLure ---\n"; output += Info.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// TeleportLureRequest packet public class TeleportLureRequestPacket : Packet { /// Info block public class InfoBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// LureID field public LLUUID LureID; /// TeleportFlags field public uint TeleportFlags; /// Length of this block serialized in bytes public int Length { get { return 52; } } /// Default constructor public InfoBlock() { } /// Constructor for building the block from a byte array public InfoBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; LureID = new LLUUID(bytes, i); i += 16; TeleportFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(LureID == null) { Console.WriteLine("Warning: LureID is null, in " + this.GetType()); } Array.Copy(LureID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(TeleportFlags % 256); bytes[i++] = (byte)((TeleportFlags >> 8) % 256); bytes[i++] = (byte)((TeleportFlags >> 16) % 256); bytes[i++] = (byte)((TeleportFlags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Info --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "LureID: " + LureID.ToString() + "\n"; output += "TeleportFlags: " + TeleportFlags.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TeleportLureRequest public override PacketType Type { get { return PacketType.TeleportLureRequest; } } /// Info block public InfoBlock Info; /// Default constructor public TeleportLureRequestPacket() { Header = new LowHeader(); Header.ID = 97; Header.Reliable = true; Info = new InfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TeleportLureRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Info = new InfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TeleportLureRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; Info = new InfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Info.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Info.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TeleportLureRequest ---\n"; output += Info.ToString() + "\n"; return output; } } /// TeleportCancel packet public class TeleportCancelPacket : Packet { /// Info block public class InfoBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public InfoBlock() { } /// Constructor for building the block from a byte array public InfoBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Info --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TeleportCancel public override PacketType Type { get { return PacketType.TeleportCancel; } } /// Info block public InfoBlock Info; /// Default constructor public TeleportCancelPacket() { Header = new LowHeader(); Header.ID = 98; Header.Reliable = true; Info = new InfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TeleportCancelPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Info = new InfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TeleportCancelPacket(Header head, byte[] bytes, ref int i) { Header = head; Info = new InfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Info.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Info.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TeleportCancel ---\n"; output += Info.ToString() + "\n"; return output; } } /// CompleteLure packet public class CompleteLurePacket : Packet { /// Info block public class InfoBlock { /// AgentID field public LLUUID AgentID; /// TravelAccess field public byte TravelAccess; /// SessionID field public LLUUID SessionID; /// CircuitCode field public uint CircuitCode; /// LureID field public LLUUID LureID; /// ParentEstateID field public uint ParentEstateID; /// TeleportFlags field public uint TeleportFlags; /// Length of this block serialized in bytes public int Length { get { return 61; } } /// Default constructor public InfoBlock() { } /// Constructor for building the block from a byte array public InfoBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; TravelAccess = (byte)bytes[i++]; SessionID = new LLUUID(bytes, i); i += 16; CircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); LureID = new LLUUID(bytes, i); i += 16; ParentEstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TeleportFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = TravelAccess; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(CircuitCode % 256); bytes[i++] = (byte)((CircuitCode >> 8) % 256); bytes[i++] = (byte)((CircuitCode >> 16) % 256); bytes[i++] = (byte)((CircuitCode >> 24) % 256); if(LureID == null) { Console.WriteLine("Warning: LureID is null, in " + this.GetType()); } Array.Copy(LureID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(ParentEstateID % 256); bytes[i++] = (byte)((ParentEstateID >> 8) % 256); bytes[i++] = (byte)((ParentEstateID >> 16) % 256); bytes[i++] = (byte)((ParentEstateID >> 24) % 256); bytes[i++] = (byte)(TeleportFlags % 256); bytes[i++] = (byte)((TeleportFlags >> 8) % 256); bytes[i++] = (byte)((TeleportFlags >> 16) % 256); bytes[i++] = (byte)((TeleportFlags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Info --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "TravelAccess: " + TravelAccess.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "CircuitCode: " + CircuitCode.ToString() + "\n"; output += "LureID: " + LureID.ToString() + "\n"; output += "ParentEstateID: " + ParentEstateID.ToString() + "\n"; output += "TeleportFlags: " + TeleportFlags.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.CompleteLure public override PacketType Type { get { return PacketType.CompleteLure; } } /// Info block public InfoBlock Info; /// Default constructor public CompleteLurePacket() { Header = new LowHeader(); Header.ID = 99; Header.Reliable = true; Info = new InfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public CompleteLurePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Info = new InfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public CompleteLurePacket(Header head, byte[] bytes, ref int i) { Header = head; Info = new InfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Info.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Info.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- CompleteLure ---\n"; output += Info.ToString() + "\n"; return output; } } /// TeleportStart packet public class TeleportStartPacket : Packet { /// Info block public class InfoBlock { /// TeleportFlags field public uint TeleportFlags; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public InfoBlock() { } /// Constructor for building the block from a byte array public InfoBlock(byte[] bytes, ref int i) { try { TeleportFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(TeleportFlags % 256); bytes[i++] = (byte)((TeleportFlags >> 8) % 256); bytes[i++] = (byte)((TeleportFlags >> 16) % 256); bytes[i++] = (byte)((TeleportFlags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Info --\n"; output += "TeleportFlags: " + TeleportFlags.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TeleportStart public override PacketType Type { get { return PacketType.TeleportStart; } } /// Info block public InfoBlock Info; /// Default constructor public TeleportStartPacket() { Header = new LowHeader(); Header.ID = 100; Header.Reliable = true; Info = new InfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TeleportStartPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Info = new InfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TeleportStartPacket(Header head, byte[] bytes, ref int i) { Header = head; Info = new InfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Info.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Info.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TeleportStart ---\n"; output += Info.ToString() + "\n"; return output; } } /// TeleportFailed packet public class TeleportFailedPacket : Packet { /// Info block public class InfoBlock { /// AgentID field public LLUUID AgentID; private byte[] _reason; /// Reason field public byte[] Reason { get { return _reason; } set { if (value == null) { _reason = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _reason = new byte[value.Length]; Array.Copy(value, _reason, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 16; if (Reason != null) { length += 1 + Reason.Length; } return length; } } /// Default constructor public InfoBlock() { } /// Constructor for building the block from a byte array public InfoBlock(byte[] bytes, ref int i) { int length; try { AgentID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _reason = new byte[length]; Array.Copy(bytes, i, _reason, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(Reason == null) { Console.WriteLine("Warning: Reason is null, in " + this.GetType()); } bytes[i++] = (byte)Reason.Length; Array.Copy(Reason, 0, bytes, i, Reason.Length); i += Reason.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Info --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += Helpers.FieldToString(Reason, "Reason") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TeleportFailed public override PacketType Type { get { return PacketType.TeleportFailed; } } /// Info block public InfoBlock Info; /// Default constructor public TeleportFailedPacket() { Header = new LowHeader(); Header.ID = 101; Header.Reliable = true; Info = new InfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TeleportFailedPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Info = new InfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TeleportFailedPacket(Header head, byte[] bytes, ref int i) { Header = head; Info = new InfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Info.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Info.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TeleportFailed ---\n"; output += Info.ToString() + "\n"; return output; } } /// LeaderBoardRequest packet public class LeaderBoardRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Type field public int Type; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; Type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Type % 256); bytes[i++] = (byte)((Type >> 8) % 256); bytes[i++] = (byte)((Type >> 16) % 256); bytes[i++] = (byte)((Type >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.LeaderBoardRequest public override PacketType Type { get { return PacketType.LeaderBoardRequest; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public LeaderBoardRequestPacket() { Header = new LowHeader(); Header.ID = 102; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public LeaderBoardRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public LeaderBoardRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- LeaderBoardRequest ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// LeaderBoardData packet public class LeaderBoardDataPacket : Packet { /// BoardData block public class BoardDataBlock { private byte[] _timestring; /// TimeString field public byte[] TimeString { get { return _timestring; } set { if (value == null) { _timestring = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _timestring = new byte[value.Length]; Array.Copy(value, _timestring, value.Length); } } } /// MaxPlace field public int MaxPlace; /// MinPlace field public int MinPlace; /// Type field public int Type; /// Length of this block serialized in bytes public int Length { get { int length = 12; if (TimeString != null) { length += 1 + TimeString.Length; } return length; } } /// Default constructor public BoardDataBlock() { } /// Constructor for building the block from a byte array public BoardDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _timestring = new byte[length]; Array.Copy(bytes, i, _timestring, 0, length); i += length; MaxPlace = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); MinPlace = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TimeString == null) { Console.WriteLine("Warning: TimeString is null, in " + this.GetType()); } bytes[i++] = (byte)TimeString.Length; Array.Copy(TimeString, 0, bytes, i, TimeString.Length); i += TimeString.Length; bytes[i++] = (byte)(MaxPlace % 256); bytes[i++] = (byte)((MaxPlace >> 8) % 256); bytes[i++] = (byte)((MaxPlace >> 16) % 256); bytes[i++] = (byte)((MaxPlace >> 24) % 256); bytes[i++] = (byte)(MinPlace % 256); bytes[i++] = (byte)((MinPlace >> 8) % 256); bytes[i++] = (byte)((MinPlace >> 16) % 256); bytes[i++] = (byte)((MinPlace >> 24) % 256); bytes[i++] = (byte)(Type % 256); bytes[i++] = (byte)((Type >> 8) % 256); bytes[i++] = (byte)((Type >> 16) % 256); bytes[i++] = (byte)((Type >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- BoardData --\n"; output += Helpers.FieldToString(TimeString, "TimeString") + "\n"; output += "MaxPlace: " + MaxPlace.ToString() + "\n"; output += "MinPlace: " + MinPlace.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output = output.Trim(); return output; } } /// Entry block public class EntryBlock { /// ID field public LLUUID ID; /// Name field public byte[] Name; /// Sequence field public int Sequence; /// Place field public int Place; /// Score field public int Score; /// Length of this block serialized in bytes public int Length { get { return 60; } } /// Default constructor public EntryBlock() { } /// Constructor for building the block from a byte array public EntryBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; Name = new byte[32]; Array.Copy(bytes, i, Name, 0, 32); i += 32; Sequence = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Place = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Score = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; Array.Copy(Name, 0, bytes, i, 32);i += 32; bytes[i++] = (byte)(Sequence % 256); bytes[i++] = (byte)((Sequence >> 8) % 256); bytes[i++] = (byte)((Sequence >> 16) % 256); bytes[i++] = (byte)((Sequence >> 24) % 256); bytes[i++] = (byte)(Place % 256); bytes[i++] = (byte)((Place >> 8) % 256); bytes[i++] = (byte)((Place >> 16) % 256); bytes[i++] = (byte)((Place >> 24) % 256); bytes[i++] = (byte)(Score % 256); bytes[i++] = (byte)((Score >> 8) % 256); bytes[i++] = (byte)((Score >> 16) % 256); bytes[i++] = (byte)((Score >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Entry --\n"; output += "ID: " + ID.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "Sequence: " + Sequence.ToString() + "\n"; output += "Place: " + Place.ToString() + "\n"; output += "Score: " + Score.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.LeaderBoardData public override PacketType Type { get { return PacketType.LeaderBoardData; } } /// BoardData block public BoardDataBlock BoardData; /// Entry block public EntryBlock[] Entry; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public LeaderBoardDataPacket() { Header = new LowHeader(); Header.ID = 103; Header.Reliable = true; Header.Zerocoded = true; BoardData = new BoardDataBlock(); Entry = new EntryBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public LeaderBoardDataPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); BoardData = new BoardDataBlock(bytes, ref i); int count = (int)bytes[i++]; Entry = new EntryBlock[count]; for (int j = 0; j < count; j++) { Entry[j] = new EntryBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public LeaderBoardDataPacket(Header head, byte[] bytes, ref int i) { Header = head; BoardData = new BoardDataBlock(bytes, ref i); int count = (int)bytes[i++]; Entry = new EntryBlock[count]; for (int j = 0; j < count; j++) { Entry[j] = new EntryBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += BoardData.Length; length += AgentData.Length;; length++; for (int j = 0; j < Entry.Length; j++) { length += Entry[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); BoardData.ToBytes(bytes, ref i); bytes[i++] = (byte)Entry.Length; for (int j = 0; j < Entry.Length; j++) { Entry[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- LeaderBoardData ---\n"; output += BoardData.ToString() + "\n"; for (int j = 0; j < Entry.Length; j++) { output += Entry[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// RegisterNewAgent packet public class RegisterNewAgentPacket : Packet { /// HelloBlock block public class HelloBlockBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Godlike field public bool Godlike; /// LocationID field public uint LocationID; /// Length of this block serialized in bytes public int Length { get { return 37; } } /// Default constructor public HelloBlockBlock() { } /// Constructor for building the block from a byte array public HelloBlockBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; LocationID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((Godlike) ? 1 : 0); bytes[i++] = (byte)(LocationID % 256); bytes[i++] = (byte)((LocationID >> 8) % 256); bytes[i++] = (byte)((LocationID >> 16) % 256); bytes[i++] = (byte)((LocationID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- HelloBlock --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "Godlike: " + Godlike.ToString() + "\n"; output += "LocationID: " + LocationID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RegisterNewAgent public override PacketType Type { get { return PacketType.RegisterNewAgent; } } /// HelloBlock block public HelloBlockBlock HelloBlock; /// Default constructor public RegisterNewAgentPacket() { Header = new LowHeader(); Header.ID = 104; Header.Reliable = true; HelloBlock = new HelloBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RegisterNewAgentPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); HelloBlock = new HelloBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RegisterNewAgentPacket(Header head, byte[] bytes, ref int i) { Header = head; HelloBlock = new HelloBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += HelloBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); HelloBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RegisterNewAgent ---\n"; output += HelloBlock.ToString() + "\n"; return output; } } /// Undo packet public class UndoPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectID field public LLUUID ObjectID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.Undo public override PacketType Type { get { return PacketType.Undo; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public UndoPacket() { Header = new LowHeader(); Header.ID = 105; Header.Reliable = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UndoPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public UndoPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- Undo ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// Redo packet public class RedoPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectID field public LLUUID ObjectID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.Redo public override PacketType Type { get { return PacketType.Redo; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RedoPacket() { Header = new LowHeader(); Header.ID = 106; Header.Reliable = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RedoPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RedoPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- Redo ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// UndoLand packet public class UndoLandPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UndoLand public override PacketType Type { get { return PacketType.UndoLand; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public UndoLandPacket() { Header = new LowHeader(); Header.ID = 107; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UndoLandPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public UndoLandPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UndoLand ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// RedoLand packet public class RedoLandPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RedoLand public override PacketType Type { get { return PacketType.RedoLand; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RedoLandPacket() { Header = new LowHeader(); Header.ID = 108; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RedoLandPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RedoLandPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RedoLand ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// AgentPause packet public class AgentPausePacket : Packet { /// AgentData block public class AgentDataBlock { /// SerialNum field public uint SerialNum; /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { SerialNum = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(SerialNum % 256); bytes[i++] = (byte)((SerialNum >> 8) % 256); bytes[i++] = (byte)((SerialNum >> 16) % 256); bytes[i++] = (byte)((SerialNum >> 24) % 256); if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "SerialNum: " + SerialNum.ToString() + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentPause public override PacketType Type { get { return PacketType.AgentPause; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentPausePacket() { Header = new LowHeader(); Header.ID = 109; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentPausePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentPausePacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentPause ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// AgentResume packet public class AgentResumePacket : Packet { /// AgentData block public class AgentDataBlock { /// SerialNum field public uint SerialNum; /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { SerialNum = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(SerialNum % 256); bytes[i++] = (byte)((SerialNum >> 8) % 256); bytes[i++] = (byte)((SerialNum >> 16) % 256); bytes[i++] = (byte)((SerialNum >> 24) % 256); if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "SerialNum: " + SerialNum.ToString() + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentResume public override PacketType Type { get { return PacketType.AgentResume; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentResumePacket() { Header = new LowHeader(); Header.ID = 110; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentResumePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentResumePacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentResume ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// ChatFromViewer packet public class ChatFromViewerPacket : Packet { /// ChatData block public class ChatDataBlock { /// Channel field public int Channel; private byte[] _message; /// Message field public byte[] Message { get { return _message; } set { if (value == null) { _message = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _message = new byte[value.Length]; Array.Copy(value, _message, value.Length); } } } /// Type field public byte Type; /// Length of this block serialized in bytes public int Length { get { int length = 5; if (Message != null) { length += 2 + Message.Length; } return length; } } /// Default constructor public ChatDataBlock() { } /// Constructor for building the block from a byte array public ChatDataBlock(byte[] bytes, ref int i) { int length; try { Channel = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _message = new byte[length]; Array.Copy(bytes, i, _message, 0, length); i += length; Type = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Channel % 256); bytes[i++] = (byte)((Channel >> 8) % 256); bytes[i++] = (byte)((Channel >> 16) % 256); bytes[i++] = (byte)((Channel >> 24) % 256); if(Message == null) { Console.WriteLine("Warning: Message is null, in " + this.GetType()); } bytes[i++] = (byte)(Message.Length % 256); bytes[i++] = (byte)((Message.Length >> 8) % 256); Array.Copy(Message, 0, bytes, i, Message.Length); i += Message.Length; bytes[i++] = Type; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ChatData --\n"; output += "Channel: " + Channel.ToString() + "\n"; output += Helpers.FieldToString(Message, "Message") + "\n"; output += "Type: " + Type.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ChatFromViewer public override PacketType Type { get { return PacketType.ChatFromViewer; } } /// ChatData block public ChatDataBlock ChatData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ChatFromViewerPacket() { Header = new LowHeader(); Header.ID = 111; Header.Reliable = true; Header.Zerocoded = true; ChatData = new ChatDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ChatFromViewerPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ChatData = new ChatDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ChatFromViewerPacket(Header head, byte[] bytes, ref int i) { Header = head; ChatData = new ChatDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ChatData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ChatData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ChatFromViewer ---\n"; output += ChatData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// AgentThrottle packet public class AgentThrottlePacket : Packet { /// Throttle block public class ThrottleBlock { /// GenCounter field public uint GenCounter; private byte[] _throttles; /// Throttles field public byte[] Throttles { get { return _throttles; } set { if (value == null) { _throttles = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _throttles = new byte[value.Length]; Array.Copy(value, _throttles, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 4; if (Throttles != null) { length += 1 + Throttles.Length; } return length; } } /// Default constructor public ThrottleBlock() { } /// Constructor for building the block from a byte array public ThrottleBlock(byte[] bytes, ref int i) { int length; try { GenCounter = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _throttles = new byte[length]; Array.Copy(bytes, i, _throttles, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(GenCounter % 256); bytes[i++] = (byte)((GenCounter >> 8) % 256); bytes[i++] = (byte)((GenCounter >> 16) % 256); bytes[i++] = (byte)((GenCounter >> 24) % 256); if(Throttles == null) { Console.WriteLine("Warning: Throttles is null, in " + this.GetType()); } bytes[i++] = (byte)Throttles.Length; Array.Copy(Throttles, 0, bytes, i, Throttles.Length); i += Throttles.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Throttle --\n"; output += "GenCounter: " + GenCounter.ToString() + "\n"; output += Helpers.FieldToString(Throttles, "Throttles") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// CircuitCode field public uint CircuitCode; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; CircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(CircuitCode % 256); bytes[i++] = (byte)((CircuitCode >> 8) % 256); bytes[i++] = (byte)((CircuitCode >> 16) % 256); bytes[i++] = (byte)((CircuitCode >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "CircuitCode: " + CircuitCode.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentThrottle public override PacketType Type { get { return PacketType.AgentThrottle; } } /// Throttle block public ThrottleBlock Throttle; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentThrottlePacket() { Header = new LowHeader(); Header.ID = 112; Header.Reliable = true; Header.Zerocoded = true; Throttle = new ThrottleBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentThrottlePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Throttle = new ThrottleBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentThrottlePacket(Header head, byte[] bytes, ref int i) { Header = head; Throttle = new ThrottleBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Throttle.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Throttle.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentThrottle ---\n"; output += Throttle.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// AgentFOV packet public class AgentFOVPacket : Packet { /// FOVBlock block public class FOVBlockBlock { /// GenCounter field public uint GenCounter; /// VerticalAngle field public float VerticalAngle; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public FOVBlockBlock() { } /// Constructor for building the block from a byte array public FOVBlockBlock(byte[] bytes, ref int i) { try { GenCounter = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); VerticalAngle = BitConverter.ToSingle(bytes, i); i += 4; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = (byte)(GenCounter % 256); bytes[i++] = (byte)((GenCounter >> 8) % 256); bytes[i++] = (byte)((GenCounter >> 16) % 256); bytes[i++] = (byte)((GenCounter >> 24) % 256); ba = BitConverter.GetBytes(VerticalAngle); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- FOVBlock --\n"; output += "GenCounter: " + GenCounter.ToString() + "\n"; output += "VerticalAngle: " + VerticalAngle.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// CircuitCode field public uint CircuitCode; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; CircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(CircuitCode % 256); bytes[i++] = (byte)((CircuitCode >> 8) % 256); bytes[i++] = (byte)((CircuitCode >> 16) % 256); bytes[i++] = (byte)((CircuitCode >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "CircuitCode: " + CircuitCode.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentFOV public override PacketType Type { get { return PacketType.AgentFOV; } } /// FOVBlock block public FOVBlockBlock FOVBlock; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentFOVPacket() { Header = new LowHeader(); Header.ID = 113; Header.Reliable = true; FOVBlock = new FOVBlockBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentFOVPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); FOVBlock = new FOVBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentFOVPacket(Header head, byte[] bytes, ref int i) { Header = head; FOVBlock = new FOVBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += FOVBlock.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); FOVBlock.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentFOV ---\n"; output += FOVBlock.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// AgentHeightWidth packet public class AgentHeightWidthPacket : Packet { /// HeightWidthBlock block public class HeightWidthBlockBlock { /// GenCounter field public uint GenCounter; /// Height field public ushort Height; /// Width field public ushort Width; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public HeightWidthBlockBlock() { } /// Constructor for building the block from a byte array public HeightWidthBlockBlock(byte[] bytes, ref int i) { try { GenCounter = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Height = (ushort)(bytes[i++] + (bytes[i++] << 8)); Width = (ushort)(bytes[i++] + (bytes[i++] << 8)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(GenCounter % 256); bytes[i++] = (byte)((GenCounter >> 8) % 256); bytes[i++] = (byte)((GenCounter >> 16) % 256); bytes[i++] = (byte)((GenCounter >> 24) % 256); bytes[i++] = (byte)(Height % 256); bytes[i++] = (byte)((Height >> 8) % 256); bytes[i++] = (byte)(Width % 256); bytes[i++] = (byte)((Width >> 8) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- HeightWidthBlock --\n"; output += "GenCounter: " + GenCounter.ToString() + "\n"; output += "Height: " + Height.ToString() + "\n"; output += "Width: " + Width.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// CircuitCode field public uint CircuitCode; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; CircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(CircuitCode % 256); bytes[i++] = (byte)((CircuitCode >> 8) % 256); bytes[i++] = (byte)((CircuitCode >> 16) % 256); bytes[i++] = (byte)((CircuitCode >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "CircuitCode: " + CircuitCode.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentHeightWidth public override PacketType Type { get { return PacketType.AgentHeightWidth; } } /// HeightWidthBlock block public HeightWidthBlockBlock HeightWidthBlock; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentHeightWidthPacket() { Header = new LowHeader(); Header.ID = 114; Header.Reliable = true; HeightWidthBlock = new HeightWidthBlockBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentHeightWidthPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); HeightWidthBlock = new HeightWidthBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentHeightWidthPacket(Header head, byte[] bytes, ref int i) { Header = head; HeightWidthBlock = new HeightWidthBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += HeightWidthBlock.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); HeightWidthBlock.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentHeightWidth ---\n"; output += HeightWidthBlock.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// AgentSetAppearance packet public class AgentSetAppearancePacket : Packet { /// VisualParam block public class VisualParamBlock { /// ParamValue field public byte ParamValue; /// Length of this block serialized in bytes public int Length { get { return 1; } } /// Default constructor public VisualParamBlock() { } /// Constructor for building the block from a byte array public VisualParamBlock(byte[] bytes, ref int i) { try { ParamValue = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = ParamValue; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- VisualParam --\n"; output += "ParamValue: " + ParamValue.ToString() + "\n"; output = output.Trim(); return output; } } /// ObjectData block public class ObjectDataBlock { private byte[] _textureentry; /// TextureEntry field public byte[] TextureEntry { get { return _textureentry; } set { if (value == null) { _textureentry = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _textureentry = new byte[value.Length]; Array.Copy(value, _textureentry, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (TextureEntry != null) { length += 2 + TextureEntry.Length; } return length; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _textureentry = new byte[length]; Array.Copy(bytes, i, _textureentry, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TextureEntry == null) { Console.WriteLine("Warning: TextureEntry is null, in " + this.GetType()); } bytes[i++] = (byte)(TextureEntry.Length % 256); bytes[i++] = (byte)((TextureEntry.Length >> 8) % 256); Array.Copy(TextureEntry, 0, bytes, i, TextureEntry.Length); i += TextureEntry.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += Helpers.FieldToString(TextureEntry, "TextureEntry") + "\n"; output = output.Trim(); return output; } } /// WearableData block public class WearableDataBlock { /// TextureIndex field public byte TextureIndex; /// CacheID field public LLUUID CacheID; /// Length of this block serialized in bytes public int Length { get { return 17; } } /// Default constructor public WearableDataBlock() { } /// Constructor for building the block from a byte array public WearableDataBlock(byte[] bytes, ref int i) { try { TextureIndex = (byte)bytes[i++]; CacheID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = TextureIndex; if(CacheID == null) { Console.WriteLine("Warning: CacheID is null, in " + this.GetType()); } Array.Copy(CacheID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- WearableData --\n"; output += "TextureIndex: " + TextureIndex.ToString() + "\n"; output += "CacheID: " + CacheID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// SerialNum field public uint SerialNum; /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Size field public LLVector3 Size; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { SerialNum = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; Size = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(SerialNum % 256); bytes[i++] = (byte)((SerialNum >> 8) % 256); bytes[i++] = (byte)((SerialNum >> 16) % 256); bytes[i++] = (byte)((SerialNum >> 24) % 256); if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(Size == null) { Console.WriteLine("Warning: Size is null, in " + this.GetType()); } Array.Copy(Size.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "SerialNum: " + SerialNum.ToString() + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "Size: " + Size.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentSetAppearance public override PacketType Type { get { return PacketType.AgentSetAppearance; } } /// VisualParam block public VisualParamBlock[] VisualParam; /// ObjectData block public ObjectDataBlock ObjectData; /// WearableData block public WearableDataBlock[] WearableData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentSetAppearancePacket() { Header = new LowHeader(); Header.ID = 115; Header.Reliable = true; Header.Zerocoded = true; VisualParam = new VisualParamBlock[0]; ObjectData = new ObjectDataBlock(); WearableData = new WearableDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentSetAppearancePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; VisualParam = new VisualParamBlock[count]; for (int j = 0; j < count; j++) { VisualParam[j] = new VisualParamBlock(bytes, ref i); } ObjectData = new ObjectDataBlock(bytes, ref i); count = (int)bytes[i++]; WearableData = new WearableDataBlock[count]; for (int j = 0; j < count; j++) { WearableData[j] = new WearableDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentSetAppearancePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; VisualParam = new VisualParamBlock[count]; for (int j = 0; j < count; j++) { VisualParam[j] = new VisualParamBlock(bytes, ref i); } ObjectData = new ObjectDataBlock(bytes, ref i); count = (int)bytes[i++]; WearableData = new WearableDataBlock[count]; for (int j = 0; j < count; j++) { WearableData[j] = new WearableDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ObjectData.Length; length += AgentData.Length;; length++; for (int j = 0; j < VisualParam.Length; j++) { length += VisualParam[j].Length; } length++; for (int j = 0; j < WearableData.Length; j++) { length += WearableData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)VisualParam.Length; for (int j = 0; j < VisualParam.Length; j++) { VisualParam[j].ToBytes(bytes, ref i); } ObjectData.ToBytes(bytes, ref i); bytes[i++] = (byte)WearableData.Length; for (int j = 0; j < WearableData.Length; j++) { WearableData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentSetAppearance ---\n"; for (int j = 0; j < VisualParam.Length; j++) { output += VisualParam[j].ToString() + "\n"; } output += ObjectData.ToString() + "\n"; for (int j = 0; j < WearableData.Length; j++) { output += WearableData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// AgentQuit packet public class AgentQuitPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentQuit public override PacketType Type { get { return PacketType.AgentQuit; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentQuitPacket() { Header = new LowHeader(); Header.ID = 116; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentQuitPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentQuitPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentQuit ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// AgentQuitCopy packet public class AgentQuitCopyPacket : Packet { /// FuseBlock block public class FuseBlockBlock { /// ViewerCircuitCode field public uint ViewerCircuitCode; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public FuseBlockBlock() { } /// Constructor for building the block from a byte array public FuseBlockBlock(byte[] bytes, ref int i) { try { ViewerCircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ViewerCircuitCode % 256); bytes[i++] = (byte)((ViewerCircuitCode >> 8) % 256); bytes[i++] = (byte)((ViewerCircuitCode >> 16) % 256); bytes[i++] = (byte)((ViewerCircuitCode >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- FuseBlock --\n"; output += "ViewerCircuitCode: " + ViewerCircuitCode.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentQuitCopy public override PacketType Type { get { return PacketType.AgentQuitCopy; } } /// FuseBlock block public FuseBlockBlock FuseBlock; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentQuitCopyPacket() { Header = new LowHeader(); Header.ID = 117; Header.Reliable = true; FuseBlock = new FuseBlockBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentQuitCopyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); FuseBlock = new FuseBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentQuitCopyPacket(Header head, byte[] bytes, ref int i) { Header = head; FuseBlock = new FuseBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += FuseBlock.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); FuseBlock.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentQuitCopy ---\n"; output += FuseBlock.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ImageNotInDatabase packet public class ImageNotInDatabasePacket : Packet { /// ImageID block public class ImageIDBlock { /// ID field public LLUUID ID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ImageIDBlock() { } /// Constructor for building the block from a byte array public ImageIDBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ImageID --\n"; output += "ID: " + ID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ImageNotInDatabase public override PacketType Type { get { return PacketType.ImageNotInDatabase; } } /// ImageID block public ImageIDBlock ImageID; /// Default constructor public ImageNotInDatabasePacket() { Header = new LowHeader(); Header.ID = 118; Header.Reliable = true; ImageID = new ImageIDBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ImageNotInDatabasePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ImageID = new ImageIDBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ImageNotInDatabasePacket(Header head, byte[] bytes, ref int i) { Header = head; ImageID = new ImageIDBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ImageID.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ImageID.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ImageNotInDatabase ---\n"; output += ImageID.ToString() + "\n"; return output; } } /// RebakeAvatarTextures packet public class RebakeAvatarTexturesPacket : Packet { /// TextureData block public class TextureDataBlock { /// TextureID field public LLUUID TextureID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public TextureDataBlock() { } /// Constructor for building the block from a byte array public TextureDataBlock(byte[] bytes, ref int i) { try { TextureID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TextureID == null) { Console.WriteLine("Warning: TextureID is null, in " + this.GetType()); } Array.Copy(TextureID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TextureData --\n"; output += "TextureID: " + TextureID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RebakeAvatarTextures public override PacketType Type { get { return PacketType.RebakeAvatarTextures; } } /// TextureData block public TextureDataBlock TextureData; /// Default constructor public RebakeAvatarTexturesPacket() { Header = new LowHeader(); Header.ID = 119; Header.Reliable = true; TextureData = new TextureDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RebakeAvatarTexturesPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TextureData = new TextureDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RebakeAvatarTexturesPacket(Header head, byte[] bytes, ref int i) { Header = head; TextureData = new TextureDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TextureData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TextureData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RebakeAvatarTextures ---\n"; output += TextureData.ToString() + "\n"; return output; } } /// SetAlwaysRun packet public class SetAlwaysRunPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// AlwaysRun field public bool AlwaysRun; /// Length of this block serialized in bytes public int Length { get { return 33; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; AlwaysRun = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((AlwaysRun) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "AlwaysRun: " + AlwaysRun.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SetAlwaysRun public override PacketType Type { get { return PacketType.SetAlwaysRun; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public SetAlwaysRunPacket() { Header = new LowHeader(); Header.ID = 120; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SetAlwaysRunPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SetAlwaysRunPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SetAlwaysRun ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// ObjectDelete packet public class ObjectDeletePacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectLocalID field public uint ObjectLocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Force field public bool Force; /// Length of this block serialized in bytes public int Length { get { return 33; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; Force = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((Force) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "Force: " + Force.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectDelete public override PacketType Type { get { return PacketType.ObjectDelete; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectDeletePacket() { Header = new LowHeader(); Header.ID = 121; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectDeletePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectDeletePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectDelete ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectDuplicate packet public class ObjectDuplicatePacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectLocalID field public uint ObjectLocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// SharedData block public class SharedDataBlock { /// DuplicateFlags field public uint DuplicateFlags; /// Offset field public LLVector3 Offset; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public SharedDataBlock() { } /// Constructor for building the block from a byte array public SharedDataBlock(byte[] bytes, ref int i) { try { DuplicateFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Offset = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(DuplicateFlags % 256); bytes[i++] = (byte)((DuplicateFlags >> 8) % 256); bytes[i++] = (byte)((DuplicateFlags >> 16) % 256); bytes[i++] = (byte)((DuplicateFlags >> 24) % 256); if(Offset == null) { Console.WriteLine("Warning: Offset is null, in " + this.GetType()); } Array.Copy(Offset.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- SharedData --\n"; output += "DuplicateFlags: " + DuplicateFlags.ToString() + "\n"; output += "Offset: " + Offset.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectDuplicate public override PacketType Type { get { return PacketType.ObjectDuplicate; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// SharedData block public SharedDataBlock SharedData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectDuplicatePacket() { Header = new LowHeader(); Header.ID = 122; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; SharedData = new SharedDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectDuplicatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } SharedData = new SharedDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectDuplicatePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } SharedData = new SharedDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += SharedData.Length; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } SharedData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectDuplicate ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += SharedData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ObjectDuplicateOnRay packet public class ObjectDuplicateOnRayPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectLocalID field public uint ObjectLocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// DuplicateFlags field public uint DuplicateFlags; /// CopyRotates field public bool CopyRotates; /// SessionID field public LLUUID SessionID; /// RayStart field public LLVector3 RayStart; /// GroupID field public LLUUID GroupID; /// RayEndIsIntersection field public bool RayEndIsIntersection; /// RayEnd field public LLVector3 RayEnd; /// BypassRaycast field public bool BypassRaycast; /// CopyCenters field public bool CopyCenters; /// RayTargetID field public LLUUID RayTargetID; /// Length of this block serialized in bytes public int Length { get { return 96; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; DuplicateFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CopyRotates = (bytes[i++] != 0) ? (bool)true : (bool)false; SessionID = new LLUUID(bytes, i); i += 16; RayStart = new LLVector3(bytes, i); i += 12; GroupID = new LLUUID(bytes, i); i += 16; RayEndIsIntersection = (bytes[i++] != 0) ? (bool)true : (bool)false; RayEnd = new LLVector3(bytes, i); i += 12; BypassRaycast = (bytes[i++] != 0) ? (bool)true : (bool)false; CopyCenters = (bytes[i++] != 0) ? (bool)true : (bool)false; RayTargetID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(DuplicateFlags % 256); bytes[i++] = (byte)((DuplicateFlags >> 8) % 256); bytes[i++] = (byte)((DuplicateFlags >> 16) % 256); bytes[i++] = (byte)((DuplicateFlags >> 24) % 256); bytes[i++] = (byte)((CopyRotates) ? 1 : 0); if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(RayStart == null) { Console.WriteLine("Warning: RayStart is null, in " + this.GetType()); } Array.Copy(RayStart.GetBytes(), 0, bytes, i, 12); i += 12; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((RayEndIsIntersection) ? 1 : 0); if(RayEnd == null) { Console.WriteLine("Warning: RayEnd is null, in " + this.GetType()); } Array.Copy(RayEnd.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = (byte)((BypassRaycast) ? 1 : 0); bytes[i++] = (byte)((CopyCenters) ? 1 : 0); if(RayTargetID == null) { Console.WriteLine("Warning: RayTargetID is null, in " + this.GetType()); } Array.Copy(RayTargetID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "DuplicateFlags: " + DuplicateFlags.ToString() + "\n"; output += "CopyRotates: " + CopyRotates.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "RayStart: " + RayStart.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "RayEndIsIntersection: " + RayEndIsIntersection.ToString() + "\n"; output += "RayEnd: " + RayEnd.ToString() + "\n"; output += "BypassRaycast: " + BypassRaycast.ToString() + "\n"; output += "CopyCenters: " + CopyCenters.ToString() + "\n"; output += "RayTargetID: " + RayTargetID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectDuplicateOnRay public override PacketType Type { get { return PacketType.ObjectDuplicateOnRay; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectDuplicateOnRayPacket() { Header = new LowHeader(); Header.ID = 123; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectDuplicateOnRayPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectDuplicateOnRayPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectDuplicateOnRay ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectScale packet public class ObjectScalePacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectLocalID field public uint ObjectLocalID; /// Scale field public LLVector3 Scale; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Scale = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); if(Scale == null) { Console.WriteLine("Warning: Scale is null, in " + this.GetType()); } Array.Copy(Scale.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output += "Scale: " + Scale.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectScale public override PacketType Type { get { return PacketType.ObjectScale; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectScalePacket() { Header = new LowHeader(); Header.ID = 124; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectScalePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectScalePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectScale ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectRotation packet public class ObjectRotationPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectLocalID field public uint ObjectLocalID; /// Rotation field public LLQuaternion Rotation; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Rotation = new LLQuaternion(bytes, i, true); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); if(Rotation == null) { Console.WriteLine("Warning: Rotation is null, in " + this.GetType()); } Array.Copy(Rotation.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output += "Rotation: " + Rotation.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectRotation public override PacketType Type { get { return PacketType.ObjectRotation; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectRotationPacket() { Header = new LowHeader(); Header.ID = 125; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectRotationPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectRotationPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectRotation ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectFlagUpdate packet public class ObjectFlagUpdatePacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// IsTemporary field public bool IsTemporary; /// ObjectLocalID field public uint ObjectLocalID; /// UsePhysics field public bool UsePhysics; /// CastsShadows field public bool CastsShadows; /// IsPhantom field public bool IsPhantom; /// Length of this block serialized in bytes public int Length { get { return 40; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; IsTemporary = (bytes[i++] != 0) ? (bool)true : (bool)false; ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); UsePhysics = (bytes[i++] != 0) ? (bool)true : (bool)false; CastsShadows = (bytes[i++] != 0) ? (bool)true : (bool)false; IsPhantom = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((IsTemporary) ? 1 : 0); bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); bytes[i++] = (byte)((UsePhysics) ? 1 : 0); bytes[i++] = (byte)((CastsShadows) ? 1 : 0); bytes[i++] = (byte)((IsPhantom) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "IsTemporary: " + IsTemporary.ToString() + "\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output += "UsePhysics: " + UsePhysics.ToString() + "\n"; output += "CastsShadows: " + CastsShadows.ToString() + "\n"; output += "IsPhantom: " + IsPhantom.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectFlagUpdate public override PacketType Type { get { return PacketType.ObjectFlagUpdate; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectFlagUpdatePacket() { Header = new LowHeader(); Header.ID = 126; Header.Reliable = true; Header.Zerocoded = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectFlagUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectFlagUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectFlagUpdate ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// ObjectClickAction packet public class ObjectClickActionPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ClickAction field public byte ClickAction; /// ObjectLocalID field public uint ObjectLocalID; /// Length of this block serialized in bytes public int Length { get { return 5; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ClickAction = (byte)bytes[i++]; ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = ClickAction; bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ClickAction: " + ClickAction.ToString() + "\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectClickAction public override PacketType Type { get { return PacketType.ObjectClickAction; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectClickActionPacket() { Header = new LowHeader(); Header.ID = 127; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectClickActionPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectClickActionPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectClickAction ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectImage packet public class ObjectImagePacket : Packet { /// ObjectData block public class ObjectDataBlock { private byte[] _mediaurl; /// MediaURL field public byte[] MediaURL { get { return _mediaurl; } set { if (value == null) { _mediaurl = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _mediaurl = new byte[value.Length]; Array.Copy(value, _mediaurl, value.Length); } } } /// ObjectLocalID field public uint ObjectLocalID; private byte[] _textureentry; /// TextureEntry field public byte[] TextureEntry { get { return _textureentry; } set { if (value == null) { _textureentry = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _textureentry = new byte[value.Length]; Array.Copy(value, _textureentry, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 4; if (MediaURL != null) { length += 1 + MediaURL.Length; } if (TextureEntry != null) { length += 2 + TextureEntry.Length; } return length; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _mediaurl = new byte[length]; Array.Copy(bytes, i, _mediaurl, 0, length); i += length; ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _textureentry = new byte[length]; Array.Copy(bytes, i, _textureentry, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(MediaURL == null) { Console.WriteLine("Warning: MediaURL is null, in " + this.GetType()); } bytes[i++] = (byte)MediaURL.Length; Array.Copy(MediaURL, 0, bytes, i, MediaURL.Length); i += MediaURL.Length; bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); if(TextureEntry == null) { Console.WriteLine("Warning: TextureEntry is null, in " + this.GetType()); } bytes[i++] = (byte)(TextureEntry.Length % 256); bytes[i++] = (byte)((TextureEntry.Length >> 8) % 256); Array.Copy(TextureEntry, 0, bytes, i, TextureEntry.Length); i += TextureEntry.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += Helpers.FieldToString(MediaURL, "MediaURL") + "\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output += Helpers.FieldToString(TextureEntry, "TextureEntry") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectImage public override PacketType Type { get { return PacketType.ObjectImage; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectImagePacket() { Header = new LowHeader(); Header.ID = 128; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectImagePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectImagePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectImage ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectMaterial packet public class ObjectMaterialPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// Material field public byte Material; /// ObjectLocalID field public uint ObjectLocalID; /// Length of this block serialized in bytes public int Length { get { return 5; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { Material = (byte)bytes[i++]; ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = Material; bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "Material: " + Material.ToString() + "\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectMaterial public override PacketType Type { get { return PacketType.ObjectMaterial; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectMaterialPacket() { Header = new LowHeader(); Header.ID = 129; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectMaterialPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectMaterialPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectMaterial ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectShape packet public class ObjectShapePacket : Packet { /// ObjectData block public class ObjectDataBlock { /// PathTwistBegin field public sbyte PathTwistBegin; /// PathEnd field public byte PathEnd; /// ProfileBegin field public byte ProfileBegin; /// PathRadiusOffset field public sbyte PathRadiusOffset; /// PathSkew field public sbyte PathSkew; /// ProfileCurve field public byte ProfileCurve; /// PathScaleX field public byte PathScaleX; /// PathScaleY field public byte PathScaleY; /// ObjectLocalID field public uint ObjectLocalID; /// PathShearX field public byte PathShearX; /// PathShearY field public byte PathShearY; /// PathTaperX field public sbyte PathTaperX; /// PathTaperY field public sbyte PathTaperY; /// ProfileEnd field public byte ProfileEnd; /// PathBegin field public byte PathBegin; /// PathCurve field public byte PathCurve; /// PathTwist field public sbyte PathTwist; /// ProfileHollow field public byte ProfileHollow; /// PathRevolutions field public byte PathRevolutions; /// Length of this block serialized in bytes public int Length { get { return 22; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { PathTwistBegin = (sbyte)bytes[i++]; PathEnd = (byte)bytes[i++]; ProfileBegin = (byte)bytes[i++]; PathRadiusOffset = (sbyte)bytes[i++]; PathSkew = (sbyte)bytes[i++]; ProfileCurve = (byte)bytes[i++]; PathScaleX = (byte)bytes[i++]; PathScaleY = (byte)bytes[i++]; ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); PathShearX = (byte)bytes[i++]; PathShearY = (byte)bytes[i++]; PathTaperX = (sbyte)bytes[i++]; PathTaperY = (sbyte)bytes[i++]; ProfileEnd = (byte)bytes[i++]; PathBegin = (byte)bytes[i++]; PathCurve = (byte)bytes[i++]; PathTwist = (sbyte)bytes[i++]; ProfileHollow = (byte)bytes[i++]; PathRevolutions = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)PathTwistBegin; bytes[i++] = PathEnd; bytes[i++] = ProfileBegin; bytes[i++] = (byte)PathRadiusOffset; bytes[i++] = (byte)PathSkew; bytes[i++] = ProfileCurve; bytes[i++] = PathScaleX; bytes[i++] = PathScaleY; bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); bytes[i++] = PathShearX; bytes[i++] = PathShearY; bytes[i++] = (byte)PathTaperX; bytes[i++] = (byte)PathTaperY; bytes[i++] = ProfileEnd; bytes[i++] = PathBegin; bytes[i++] = PathCurve; bytes[i++] = (byte)PathTwist; bytes[i++] = ProfileHollow; bytes[i++] = PathRevolutions; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "PathTwistBegin: " + PathTwistBegin.ToString() + "\n"; output += "PathEnd: " + PathEnd.ToString() + "\n"; output += "ProfileBegin: " + ProfileBegin.ToString() + "\n"; output += "PathRadiusOffset: " + PathRadiusOffset.ToString() + "\n"; output += "PathSkew: " + PathSkew.ToString() + "\n"; output += "ProfileCurve: " + ProfileCurve.ToString() + "\n"; output += "PathScaleX: " + PathScaleX.ToString() + "\n"; output += "PathScaleY: " + PathScaleY.ToString() + "\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output += "PathShearX: " + PathShearX.ToString() + "\n"; output += "PathShearY: " + PathShearY.ToString() + "\n"; output += "PathTaperX: " + PathTaperX.ToString() + "\n"; output += "PathTaperY: " + PathTaperY.ToString() + "\n"; output += "ProfileEnd: " + ProfileEnd.ToString() + "\n"; output += "PathBegin: " + PathBegin.ToString() + "\n"; output += "PathCurve: " + PathCurve.ToString() + "\n"; output += "PathTwist: " + PathTwist.ToString() + "\n"; output += "ProfileHollow: " + ProfileHollow.ToString() + "\n"; output += "PathRevolutions: " + PathRevolutions.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectShape public override PacketType Type { get { return PacketType.ObjectShape; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectShapePacket() { Header = new LowHeader(); Header.ID = 130; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectShapePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectShapePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectShape ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectExtraParams packet public class ObjectExtraParamsPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ParamInUse field public bool ParamInUse; /// ObjectLocalID field public uint ObjectLocalID; private byte[] _paramdata; /// ParamData field public byte[] ParamData { get { return _paramdata; } set { if (value == null) { _paramdata = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _paramdata = new byte[value.Length]; Array.Copy(value, _paramdata, value.Length); } } } /// ParamSize field public uint ParamSize; /// ParamType field public ushort ParamType; /// Length of this block serialized in bytes public int Length { get { int length = 11; if (ParamData != null) { length += 1 + ParamData.Length; } return length; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { int length; try { ParamInUse = (bytes[i++] != 0) ? (bool)true : (bool)false; ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _paramdata = new byte[length]; Array.Copy(bytes, i, _paramdata, 0, length); i += length; ParamSize = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ParamType = (ushort)(bytes[i++] + (bytes[i++] << 8)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((ParamInUse) ? 1 : 0); bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); if(ParamData == null) { Console.WriteLine("Warning: ParamData is null, in " + this.GetType()); } bytes[i++] = (byte)ParamData.Length; Array.Copy(ParamData, 0, bytes, i, ParamData.Length); i += ParamData.Length; bytes[i++] = (byte)(ParamSize % 256); bytes[i++] = (byte)((ParamSize >> 8) % 256); bytes[i++] = (byte)((ParamSize >> 16) % 256); bytes[i++] = (byte)((ParamSize >> 24) % 256); bytes[i++] = (byte)(ParamType % 256); bytes[i++] = (byte)((ParamType >> 8) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ParamInUse: " + ParamInUse.ToString() + "\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output += Helpers.FieldToString(ParamData, "ParamData") + "\n"; output += "ParamSize: " + ParamSize.ToString() + "\n"; output += "ParamType: " + ParamType.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectExtraParams public override PacketType Type { get { return PacketType.ObjectExtraParams; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectExtraParamsPacket() { Header = new LowHeader(); Header.ID = 131; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectExtraParamsPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectExtraParamsPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectExtraParams ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectOwner packet public class ObjectOwnerPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectLocalID field public uint ObjectLocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// HeaderData block public class HeaderDataBlock { /// GroupID field public LLUUID GroupID; /// OwnerID field public LLUUID OwnerID; /// Override field public bool Override; /// Length of this block serialized in bytes public int Length { get { return 33; } } /// Default constructor public HeaderDataBlock() { } /// Constructor for building the block from a byte array public HeaderDataBlock(byte[] bytes, ref int i) { try { GroupID = new LLUUID(bytes, i); i += 16; OwnerID = new LLUUID(bytes, i); i += 16; Override = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((Override) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- HeaderData --\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "Override: " + Override.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectOwner public override PacketType Type { get { return PacketType.ObjectOwner; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// HeaderData block public HeaderDataBlock HeaderData; /// Default constructor public ObjectOwnerPacket() { Header = new LowHeader(); Header.ID = 132; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); HeaderData = new HeaderDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectOwnerPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); HeaderData = new HeaderDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectOwnerPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); HeaderData = new HeaderDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += HeaderData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); HeaderData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectOwner ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; output += HeaderData.ToString() + "\n"; return output; } } /// ObjectGroup packet public class ObjectGroupPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectLocalID field public uint ObjectLocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectGroup public override PacketType Type { get { return PacketType.ObjectGroup; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectGroupPacket() { Header = new LowHeader(); Header.ID = 133; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectGroupPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectGroupPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectGroup ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectBuy packet public class ObjectBuyPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// SaleType field public byte SaleType; /// SalePrice field public int SalePrice; /// ObjectLocalID field public uint ObjectLocalID; /// Length of this block serialized in bytes public int Length { get { return 9; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { SaleType = (byte)bytes[i++]; SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = SaleType; bytes[i++] = (byte)(SalePrice % 256); bytes[i++] = (byte)((SalePrice >> 8) % 256); bytes[i++] = (byte)((SalePrice >> 16) % 256); bytes[i++] = (byte)((SalePrice >> 24) % 256); bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "SaleType: " + SaleType.ToString() + "\n"; output += "SalePrice: " + SalePrice.ToString() + "\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// GroupID field public LLUUID GroupID; /// CategoryID field public LLUUID CategoryID; /// Length of this block serialized in bytes public int Length { get { return 64; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; CategoryID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; if(CategoryID == null) { Console.WriteLine("Warning: CategoryID is null, in " + this.GetType()); } Array.Copy(CategoryID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "CategoryID: " + CategoryID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectBuy public override PacketType Type { get { return PacketType.ObjectBuy; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectBuyPacket() { Header = new LowHeader(); Header.ID = 134; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectBuyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectBuyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectBuy ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// BuyObjectInventory packet public class BuyObjectInventoryPacket : Packet { /// Data block public class DataBlock { /// ObjectID field public LLUUID ObjectID; /// ItemID field public LLUUID ItemID; /// FolderID field public LLUUID FolderID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; FolderID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.BuyObjectInventory public override PacketType Type { get { return PacketType.BuyObjectInventory; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public BuyObjectInventoryPacket() { Header = new LowHeader(); Header.ID = 135; Header.Reliable = true; Header.Zerocoded = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public BuyObjectInventoryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public BuyObjectInventoryPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- BuyObjectInventory ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DerezContainer packet public class DerezContainerPacket : Packet { /// Data block public class DataBlock { /// ObjectID field public LLUUID ObjectID; /// Delete field public bool Delete; /// Length of this block serialized in bytes public int Length { get { return 17; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; Delete = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((Delete) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "Delete: " + Delete.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DerezContainer public override PacketType Type { get { return PacketType.DerezContainer; } } /// Data block public DataBlock Data; /// Default constructor public DerezContainerPacket() { Header = new LowHeader(); Header.ID = 136; Header.Reliable = true; Header.Zerocoded = true; Data = new DataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DerezContainerPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DerezContainerPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DerezContainer ---\n"; output += Data.ToString() + "\n"; return output; } } /// ObjectPermissions packet public class ObjectPermissionsPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// Set field public byte Set; /// Mask field public uint Mask; /// ObjectLocalID field public uint ObjectLocalID; /// Field field public byte Field; /// Length of this block serialized in bytes public int Length { get { return 10; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { Set = (byte)bytes[i++]; Mask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Field = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = Set; bytes[i++] = (byte)(Mask % 256); bytes[i++] = (byte)((Mask >> 8) % 256); bytes[i++] = (byte)((Mask >> 16) % 256); bytes[i++] = (byte)((Mask >> 24) % 256); bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); bytes[i++] = Field; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "Set: " + Set.ToString() + "\n"; output += "Mask: " + Mask.ToString() + "\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output += "Field: " + Field.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// HeaderData block public class HeaderDataBlock { /// Override field public bool Override; /// Length of this block serialized in bytes public int Length { get { return 1; } } /// Default constructor public HeaderDataBlock() { } /// Constructor for building the block from a byte array public HeaderDataBlock(byte[] bytes, ref int i) { try { Override = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((Override) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- HeaderData --\n"; output += "Override: " + Override.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectPermissions public override PacketType Type { get { return PacketType.ObjectPermissions; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// HeaderData block public HeaderDataBlock HeaderData; /// Default constructor public ObjectPermissionsPacket() { Header = new LowHeader(); Header.ID = 137; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); HeaderData = new HeaderDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectPermissionsPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); HeaderData = new HeaderDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectPermissionsPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); HeaderData = new HeaderDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += HeaderData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); HeaderData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectPermissions ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; output += HeaderData.ToString() + "\n"; return output; } } /// ObjectSaleInfo packet public class ObjectSaleInfoPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// LocalID field public uint LocalID; /// SaleType field public byte SaleType; /// SalePrice field public int SalePrice; /// Length of this block serialized in bytes public int Length { get { return 9; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SaleType = (byte)bytes[i++]; SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); bytes[i++] = SaleType; bytes[i++] = (byte)(SalePrice % 256); bytes[i++] = (byte)((SalePrice >> 8) % 256); bytes[i++] = (byte)((SalePrice >> 16) % 256); bytes[i++] = (byte)((SalePrice >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "SaleType: " + SaleType.ToString() + "\n"; output += "SalePrice: " + SalePrice.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectSaleInfo public override PacketType Type { get { return PacketType.ObjectSaleInfo; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectSaleInfoPacket() { Header = new LowHeader(); Header.ID = 138; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectSaleInfoPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectSaleInfoPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectSaleInfo ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectName packet public class ObjectNamePacket : Packet { /// ObjectData block public class ObjectDataBlock { /// LocalID field public uint LocalID; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 4; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { int length; try { LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectName public override PacketType Type { get { return PacketType.ObjectName; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectNamePacket() { Header = new LowHeader(); Header.ID = 139; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectNamePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectNamePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectName ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectDescription packet public class ObjectDescriptionPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// LocalID field public uint LocalID; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 4; if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { int length; try { LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectDescription public override PacketType Type { get { return PacketType.ObjectDescription; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectDescriptionPacket() { Header = new LowHeader(); Header.ID = 140; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectDescriptionPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectDescriptionPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectDescription ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectCategory packet public class ObjectCategoryPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// LocalID field public uint LocalID; /// Category field public uint Category; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Category = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); bytes[i++] = (byte)(Category % 256); bytes[i++] = (byte)((Category >> 8) % 256); bytes[i++] = (byte)((Category >> 16) % 256); bytes[i++] = (byte)((Category >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "Category: " + Category.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectCategory public override PacketType Type { get { return PacketType.ObjectCategory; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectCategoryPacket() { Header = new LowHeader(); Header.ID = 141; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectCategoryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectCategoryPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectCategory ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectSelect packet public class ObjectSelectPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectLocalID field public uint ObjectLocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectSelect public override PacketType Type { get { return PacketType.ObjectSelect; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectSelectPacket() { Header = new LowHeader(); Header.ID = 142; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectSelectPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectSelectPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectSelect ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectDeselect packet public class ObjectDeselectPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectLocalID field public uint ObjectLocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectDeselect public override PacketType Type { get { return PacketType.ObjectDeselect; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectDeselectPacket() { Header = new LowHeader(); Header.ID = 143; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectDeselectPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectDeselectPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectDeselect ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectAttach packet public class ObjectAttachPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectLocalID field public uint ObjectLocalID; /// Rotation field public LLQuaternion Rotation; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Rotation = new LLQuaternion(bytes, i, true); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); if(Rotation == null) { Console.WriteLine("Warning: Rotation is null, in " + this.GetType()); } Array.Copy(Rotation.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output += "Rotation: " + Rotation.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AttachmentPoint field public byte AttachmentPoint; /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 33; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AttachmentPoint = (byte)bytes[i++]; AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = AttachmentPoint; if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AttachmentPoint: " + AttachmentPoint.ToString() + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectAttach public override PacketType Type { get { return PacketType.ObjectAttach; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectAttachPacket() { Header = new LowHeader(); Header.ID = 144; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectAttachPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectAttachPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectAttach ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectDetach packet public class ObjectDetachPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectLocalID field public uint ObjectLocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectDetach public override PacketType Type { get { return PacketType.ObjectDetach; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectDetachPacket() { Header = new LowHeader(); Header.ID = 145; Header.Reliable = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectDetachPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectDetachPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectDetach ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectDrop packet public class ObjectDropPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectLocalID field public uint ObjectLocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectDrop public override PacketType Type { get { return PacketType.ObjectDrop; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectDropPacket() { Header = new LowHeader(); Header.ID = 146; Header.Reliable = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectDropPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectDropPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectDrop ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectLink packet public class ObjectLinkPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectLocalID field public uint ObjectLocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectLink public override PacketType Type { get { return PacketType.ObjectLink; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectLinkPacket() { Header = new LowHeader(); Header.ID = 147; Header.Reliable = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectLinkPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectLinkPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectLink ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectDelink packet public class ObjectDelinkPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectLocalID field public uint ObjectLocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectDelink public override PacketType Type { get { return PacketType.ObjectDelink; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectDelinkPacket() { Header = new LowHeader(); Header.ID = 148; Header.Reliable = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectDelinkPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectDelinkPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectDelink ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectHinge packet public class ObjectHingePacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectLocalID field public uint ObjectLocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// JointType block public class JointTypeBlock { /// Type field public byte Type; /// Length of this block serialized in bytes public int Length { get { return 1; } } /// Default constructor public JointTypeBlock() { } /// Constructor for building the block from a byte array public JointTypeBlock(byte[] bytes, ref int i) { try { Type = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = Type; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- JointType --\n"; output += "Type: " + Type.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectHinge public override PacketType Type { get { return PacketType.ObjectHinge; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// JointType block public JointTypeBlock JointType; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectHingePacket() { Header = new LowHeader(); Header.ID = 149; Header.Reliable = true; ObjectData = new ObjectDataBlock[0]; JointType = new JointTypeBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectHingePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } JointType = new JointTypeBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectHingePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } JointType = new JointTypeBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += JointType.Length; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } JointType.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectHinge ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += JointType.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ObjectDehinge packet public class ObjectDehingePacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectLocalID field public uint ObjectLocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectDehinge public override PacketType Type { get { return PacketType.ObjectDehinge; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectDehingePacket() { Header = new LowHeader(); Header.ID = 150; Header.Reliable = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectDehingePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectDehingePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectDehinge ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectGrab packet public class ObjectGrabPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// GrabOffset field public LLVector3 GrabOffset; /// LocalID field public uint LocalID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { GrabOffset = new LLVector3(bytes, i); i += 12; LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GrabOffset == null) { Console.WriteLine("Warning: GrabOffset is null, in " + this.GetType()); } Array.Copy(GrabOffset.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "GrabOffset: " + GrabOffset.ToString() + "\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectGrab public override PacketType Type { get { return PacketType.ObjectGrab; } } /// ObjectData block public ObjectDataBlock ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectGrabPacket() { Header = new LowHeader(); Header.ID = 151; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectGrabPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ObjectData = new ObjectDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectGrabPacket(Header head, byte[] bytes, ref int i) { Header = head; ObjectData = new ObjectDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ObjectData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ObjectData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectGrab ---\n"; output += ObjectData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ObjectGrabUpdate packet public class ObjectGrabUpdatePacket : Packet { /// ObjectData block public class ObjectDataBlock { /// TimeSinceLast field public uint TimeSinceLast; /// ObjectID field public LLUUID ObjectID; /// GrabOffsetInitial field public LLVector3 GrabOffsetInitial; /// GrabPosition field public LLVector3 GrabPosition; /// Length of this block serialized in bytes public int Length { get { return 44; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { TimeSinceLast = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ObjectID = new LLUUID(bytes, i); i += 16; GrabOffsetInitial = new LLVector3(bytes, i); i += 12; GrabPosition = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(TimeSinceLast % 256); bytes[i++] = (byte)((TimeSinceLast >> 8) % 256); bytes[i++] = (byte)((TimeSinceLast >> 16) % 256); bytes[i++] = (byte)((TimeSinceLast >> 24) % 256); if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; if(GrabOffsetInitial == null) { Console.WriteLine("Warning: GrabOffsetInitial is null, in " + this.GetType()); } Array.Copy(GrabOffsetInitial.GetBytes(), 0, bytes, i, 12); i += 12; if(GrabPosition == null) { Console.WriteLine("Warning: GrabPosition is null, in " + this.GetType()); } Array.Copy(GrabPosition.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "TimeSinceLast: " + TimeSinceLast.ToString() + "\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "GrabOffsetInitial: " + GrabOffsetInitial.ToString() + "\n"; output += "GrabPosition: " + GrabPosition.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectGrabUpdate public override PacketType Type { get { return PacketType.ObjectGrabUpdate; } } /// ObjectData block public ObjectDataBlock ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectGrabUpdatePacket() { Header = new LowHeader(); Header.ID = 152; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectGrabUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ObjectData = new ObjectDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectGrabUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; ObjectData = new ObjectDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ObjectData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ObjectData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectGrabUpdate ---\n"; output += ObjectData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ObjectDeGrab packet public class ObjectDeGrabPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// LocalID field public uint LocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectDeGrab public override PacketType Type { get { return PacketType.ObjectDeGrab; } } /// ObjectData block public ObjectDataBlock ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectDeGrabPacket() { Header = new LowHeader(); Header.ID = 153; Header.Reliable = true; ObjectData = new ObjectDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectDeGrabPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ObjectData = new ObjectDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectDeGrabPacket(Header head, byte[] bytes, ref int i) { Header = head; ObjectData = new ObjectDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ObjectData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ObjectData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectDeGrab ---\n"; output += ObjectData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ObjectSpinStart packet public class ObjectSpinStartPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectID field public LLUUID ObjectID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectSpinStart public override PacketType Type { get { return PacketType.ObjectSpinStart; } } /// ObjectData block public ObjectDataBlock ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectSpinStartPacket() { Header = new LowHeader(); Header.ID = 154; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectSpinStartPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ObjectData = new ObjectDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectSpinStartPacket(Header head, byte[] bytes, ref int i) { Header = head; ObjectData = new ObjectDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ObjectData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ObjectData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectSpinStart ---\n"; output += ObjectData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ObjectSpinUpdate packet public class ObjectSpinUpdatePacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectID field public LLUUID ObjectID; /// Rotation field public LLQuaternion Rotation; /// Length of this block serialized in bytes public int Length { get { return 28; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; Rotation = new LLQuaternion(bytes, i, true); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; if(Rotation == null) { Console.WriteLine("Warning: Rotation is null, in " + this.GetType()); } Array.Copy(Rotation.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "Rotation: " + Rotation.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectSpinUpdate public override PacketType Type { get { return PacketType.ObjectSpinUpdate; } } /// ObjectData block public ObjectDataBlock ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectSpinUpdatePacket() { Header = new LowHeader(); Header.ID = 155; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectSpinUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ObjectData = new ObjectDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectSpinUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; ObjectData = new ObjectDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ObjectData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ObjectData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectSpinUpdate ---\n"; output += ObjectData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ObjectSpinStop packet public class ObjectSpinStopPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectID field public LLUUID ObjectID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectSpinStop public override PacketType Type { get { return PacketType.ObjectSpinStop; } } /// ObjectData block public ObjectDataBlock ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectSpinStopPacket() { Header = new LowHeader(); Header.ID = 156; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectSpinStopPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ObjectData = new ObjectDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectSpinStopPacket(Header head, byte[] bytes, ref int i) { Header = head; ObjectData = new ObjectDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ObjectData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ObjectData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectSpinStop ---\n"; output += ObjectData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ObjectExportSelected packet public class ObjectExportSelectedPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectID field public LLUUID ObjectID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// RequestID field public LLUUID RequestID; /// VolumeDetail field public short VolumeDetail; /// Length of this block serialized in bytes public int Length { get { return 34; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; RequestID = new LLUUID(bytes, i); i += 16; VolumeDetail = (short)(bytes[i++] + (bytes[i++] << 8)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(VolumeDetail % 256); bytes[i++] = (byte)((VolumeDetail >> 8) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "VolumeDetail: " + VolumeDetail.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectExportSelected public override PacketType Type { get { return PacketType.ObjectExportSelected; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectExportSelectedPacket() { Header = new LowHeader(); Header.ID = 157; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectExportSelectedPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectExportSelectedPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectExportSelected ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectImport packet public class ObjectImportPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// FolderID field public LLUUID FolderID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; FolderID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output = output.Trim(); return output; } } /// AssetData block public class AssetDataBlock { private byte[] _objectname; /// ObjectName field public byte[] ObjectName { get { return _objectname; } set { if (value == null) { _objectname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _objectname = new byte[value.Length]; Array.Copy(value, _objectname, value.Length); } } } /// FileID field public LLUUID FileID; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 16; if (ObjectName != null) { length += 1 + ObjectName.Length; } if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public AssetDataBlock() { } /// Constructor for building the block from a byte array public AssetDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _objectname = new byte[length]; Array.Copy(bytes, i, _objectname, 0, length); i += length; FileID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectName == null) { Console.WriteLine("Warning: ObjectName is null, in " + this.GetType()); } bytes[i++] = (byte)ObjectName.Length; Array.Copy(ObjectName, 0, bytes, i, ObjectName.Length); i += ObjectName.Length; if(FileID == null) { Console.WriteLine("Warning: FileID is null, in " + this.GetType()); } Array.Copy(FileID.GetBytes(), 0, bytes, i, 16); i += 16; if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AssetData --\n"; output += Helpers.FieldToString(ObjectName, "ObjectName") + "\n"; output += "FileID: " + FileID.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectImport public override PacketType Type { get { return PacketType.ObjectImport; } } /// AgentData block public AgentDataBlock AgentData; /// AssetData block public AssetDataBlock AssetData; /// Default constructor public ObjectImportPacket() { Header = new LowHeader(); Header.ID = 158; Header.Reliable = true; Header.Zerocoded = true; AgentData = new AgentDataBlock(); AssetData = new AssetDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectImportPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); AssetData = new AssetDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectImportPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); AssetData = new AssetDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += AssetData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); AssetData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectImport ---\n"; output += AgentData.ToString() + "\n"; output += AssetData.ToString() + "\n"; return output; } } /// ModifyLand packet public class ModifyLandPacket : Packet { /// ModifyBlock block public class ModifyBlockBlock { /// BrushSize field public byte BrushSize; /// Seconds field public float Seconds; /// Height field public float Height; /// Action field public byte Action; /// Length of this block serialized in bytes public int Length { get { return 10; } } /// Default constructor public ModifyBlockBlock() { } /// Constructor for building the block from a byte array public ModifyBlockBlock(byte[] bytes, ref int i) { try { BrushSize = (byte)bytes[i++]; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Seconds = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Height = BitConverter.ToSingle(bytes, i); i += 4; Action = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = BrushSize; ba = BitConverter.GetBytes(Seconds); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(Height); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = Action; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ModifyBlock --\n"; output += "BrushSize: " + BrushSize.ToString() + "\n"; output += "Seconds: " + Seconds.ToString() + "\n"; output += "Height: " + Height.ToString() + "\n"; output += "Action: " + Action.ToString() + "\n"; output = output.Trim(); return output; } } /// ParcelData block public class ParcelDataBlock { /// LocalID field public int LocalID; /// East field public float East; /// West field public float West; /// North field public float North; /// South field public float South; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); East = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); West = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); North = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); South = BitConverter.ToSingle(bytes, i); i += 4; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); ba = BitConverter.GetBytes(East); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(West); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(North); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(South); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "East: " + East.ToString() + "\n"; output += "West: " + West.ToString() + "\n"; output += "North: " + North.ToString() + "\n"; output += "South: " + South.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ModifyLand public override PacketType Type { get { return PacketType.ModifyLand; } } /// ModifyBlock block public ModifyBlockBlock ModifyBlock; /// ParcelData block public ParcelDataBlock[] ParcelData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ModifyLandPacket() { Header = new LowHeader(); Header.ID = 159; Header.Reliable = true; Header.Zerocoded = true; ModifyBlock = new ModifyBlockBlock(); ParcelData = new ParcelDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ModifyLandPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ModifyBlock = new ModifyBlockBlock(bytes, ref i); int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ModifyLandPacket(Header head, byte[] bytes, ref int i) { Header = head; ModifyBlock = new ModifyBlockBlock(bytes, ref i); int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ModifyBlock.Length; length += AgentData.Length;; length++; for (int j = 0; j < ParcelData.Length; j++) { length += ParcelData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ModifyBlock.ToBytes(bytes, ref i); bytes[i++] = (byte)ParcelData.Length; for (int j = 0; j < ParcelData.Length; j++) { ParcelData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ModifyLand ---\n"; output += ModifyBlock.ToString() + "\n"; for (int j = 0; j < ParcelData.Length; j++) { output += ParcelData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// VelocityInterpolateOn packet public class VelocityInterpolateOnPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.VelocityInterpolateOn public override PacketType Type { get { return PacketType.VelocityInterpolateOn; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public VelocityInterpolateOnPacket() { Header = new LowHeader(); Header.ID = 160; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public VelocityInterpolateOnPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public VelocityInterpolateOnPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- VelocityInterpolateOn ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// VelocityInterpolateOff packet public class VelocityInterpolateOffPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.VelocityInterpolateOff public override PacketType Type { get { return PacketType.VelocityInterpolateOff; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public VelocityInterpolateOffPacket() { Header = new LowHeader(); Header.ID = 161; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public VelocityInterpolateOffPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public VelocityInterpolateOffPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- VelocityInterpolateOff ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// StateSave packet public class StateSavePacket : Packet { /// DataBlock block public class DataBlockBlock { private byte[] _filename; /// Filename field public byte[] Filename { get { return _filename; } set { if (value == null) { _filename = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _filename = new byte[value.Length]; Array.Copy(value, _filename, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (Filename != null) { length += 1 + Filename.Length; } return length; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _filename = new byte[length]; Array.Copy(bytes, i, _filename, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Filename == null) { Console.WriteLine("Warning: Filename is null, in " + this.GetType()); } bytes[i++] = (byte)Filename.Length; Array.Copy(Filename, 0, bytes, i, Filename.Length); i += Filename.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += Helpers.FieldToString(Filename, "Filename") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.StateSave public override PacketType Type { get { return PacketType.StateSave; } } /// DataBlock block public DataBlockBlock DataBlock; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public StateSavePacket() { Header = new LowHeader(); Header.ID = 162; Header.Reliable = true; DataBlock = new DataBlockBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public StateSavePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); DataBlock = new DataBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public StateSavePacket(Header head, byte[] bytes, ref int i) { Header = head; DataBlock = new DataBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += DataBlock.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- StateSave ---\n"; output += DataBlock.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ReportAutosaveCrash packet public class ReportAutosaveCrashPacket : Packet { /// AutosaveData block public class AutosaveDataBlock { /// PID field public int PID; /// Status field public int Status; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public AutosaveDataBlock() { } /// Constructor for building the block from a byte array public AutosaveDataBlock(byte[] bytes, ref int i) { try { PID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Status = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(PID % 256); bytes[i++] = (byte)((PID >> 8) % 256); bytes[i++] = (byte)((PID >> 16) % 256); bytes[i++] = (byte)((PID >> 24) % 256); bytes[i++] = (byte)(Status % 256); bytes[i++] = (byte)((Status >> 8) % 256); bytes[i++] = (byte)((Status >> 16) % 256); bytes[i++] = (byte)((Status >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AutosaveData --\n"; output += "PID: " + PID.ToString() + "\n"; output += "Status: " + Status.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ReportAutosaveCrash public override PacketType Type { get { return PacketType.ReportAutosaveCrash; } } /// AutosaveData block public AutosaveDataBlock AutosaveData; /// Default constructor public ReportAutosaveCrashPacket() { Header = new LowHeader(); Header.ID = 163; Header.Reliable = true; AutosaveData = new AutosaveDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ReportAutosaveCrashPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AutosaveData = new AutosaveDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ReportAutosaveCrashPacket(Header head, byte[] bytes, ref int i) { Header = head; AutosaveData = new AutosaveDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AutosaveData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AutosaveData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ReportAutosaveCrash ---\n"; output += AutosaveData.ToString() + "\n"; return output; } } /// SimWideDeletes packet public class SimWideDeletesPacket : Packet { /// DataBlock block public class DataBlockBlock { /// TargetID field public LLUUID TargetID; /// Flags field public uint Flags; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { try { TargetID = new LLUUID(bytes, i); i += 16; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TargetID == null) { Console.WriteLine("Warning: TargetID is null, in " + this.GetType()); } Array.Copy(TargetID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "TargetID: " + TargetID.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SimWideDeletes public override PacketType Type { get { return PacketType.SimWideDeletes; } } /// DataBlock block public DataBlockBlock DataBlock; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public SimWideDeletesPacket() { Header = new LowHeader(); Header.ID = 164; Header.Reliable = true; DataBlock = new DataBlockBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SimWideDeletesPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); DataBlock = new DataBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SimWideDeletesPacket(Header head, byte[] bytes, ref int i) { Header = head; DataBlock = new DataBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += DataBlock.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SimWideDeletes ---\n"; output += DataBlock.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// TrackAgent packet public class TrackAgentPacket : Packet { /// TargetData block public class TargetDataBlock { /// PreyID field public LLUUID PreyID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public TargetDataBlock() { } /// Constructor for building the block from a byte array public TargetDataBlock(byte[] bytes, ref int i) { try { PreyID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(PreyID == null) { Console.WriteLine("Warning: PreyID is null, in " + this.GetType()); } Array.Copy(PreyID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TargetData --\n"; output += "PreyID: " + PreyID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TrackAgent public override PacketType Type { get { return PacketType.TrackAgent; } } /// TargetData block public TargetDataBlock TargetData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public TrackAgentPacket() { Header = new LowHeader(); Header.ID = 165; Header.Reliable = true; TargetData = new TargetDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TrackAgentPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TargetData = new TargetDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TrackAgentPacket(Header head, byte[] bytes, ref int i) { Header = head; TargetData = new TargetDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TargetData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TargetData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TrackAgent ---\n"; output += TargetData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// GrantModification packet public class GrantModificationPacket : Packet { /// EmpoweredBlock block public class EmpoweredBlockBlock { /// EmpoweredID field public LLUUID EmpoweredID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public EmpoweredBlockBlock() { } /// Constructor for building the block from a byte array public EmpoweredBlockBlock(byte[] bytes, ref int i) { try { EmpoweredID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(EmpoweredID == null) { Console.WriteLine("Warning: EmpoweredID is null, in " + this.GetType()); } Array.Copy(EmpoweredID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- EmpoweredBlock --\n"; output += "EmpoweredID: " + EmpoweredID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; private byte[] _grantername; /// GranterName field public byte[] GranterName { get { return _grantername; } set { if (value == null) { _grantername = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _grantername = new byte[value.Length]; Array.Copy(value, _grantername, value.Length); } } } /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { int length = 32; if (GranterName != null) { length += 1 + GranterName.Length; } return length; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { int length; try { AgentID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _grantername = new byte[length]; Array.Copy(bytes, i, _grantername, 0, length); i += length; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(GranterName == null) { Console.WriteLine("Warning: GranterName is null, in " + this.GetType()); } bytes[i++] = (byte)GranterName.Length; Array.Copy(GranterName, 0, bytes, i, GranterName.Length); i += GranterName.Length; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += Helpers.FieldToString(GranterName, "GranterName") + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GrantModification public override PacketType Type { get { return PacketType.GrantModification; } } /// EmpoweredBlock block public EmpoweredBlockBlock[] EmpoweredBlock; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GrantModificationPacket() { Header = new LowHeader(); Header.ID = 166; Header.Reliable = true; EmpoweredBlock = new EmpoweredBlockBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GrantModificationPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; EmpoweredBlock = new EmpoweredBlockBlock[count]; for (int j = 0; j < count; j++) { EmpoweredBlock[j] = new EmpoweredBlockBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GrantModificationPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; EmpoweredBlock = new EmpoweredBlockBlock[count]; for (int j = 0; j < count; j++) { EmpoweredBlock[j] = new EmpoweredBlockBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < EmpoweredBlock.Length; j++) { length += EmpoweredBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)EmpoweredBlock.Length; for (int j = 0; j < EmpoweredBlock.Length; j++) { EmpoweredBlock[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GrantModification ---\n"; for (int j = 0; j < EmpoweredBlock.Length; j++) { output += EmpoweredBlock[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// RevokeModification packet public class RevokeModificationPacket : Packet { /// RevokedBlock block public class RevokedBlockBlock { /// RevokedID field public LLUUID RevokedID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public RevokedBlockBlock() { } /// Constructor for building the block from a byte array public RevokedBlockBlock(byte[] bytes, ref int i) { try { RevokedID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RevokedID == null) { Console.WriteLine("Warning: RevokedID is null, in " + this.GetType()); } Array.Copy(RevokedID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RevokedBlock --\n"; output += "RevokedID: " + RevokedID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; private byte[] _grantername; /// GranterName field public byte[] GranterName { get { return _grantername; } set { if (value == null) { _grantername = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _grantername = new byte[value.Length]; Array.Copy(value, _grantername, value.Length); } } } /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { int length = 32; if (GranterName != null) { length += 1 + GranterName.Length; } return length; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { int length; try { AgentID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _grantername = new byte[length]; Array.Copy(bytes, i, _grantername, 0, length); i += length; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(GranterName == null) { Console.WriteLine("Warning: GranterName is null, in " + this.GetType()); } bytes[i++] = (byte)GranterName.Length; Array.Copy(GranterName, 0, bytes, i, GranterName.Length); i += GranterName.Length; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += Helpers.FieldToString(GranterName, "GranterName") + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RevokeModification public override PacketType Type { get { return PacketType.RevokeModification; } } /// RevokedBlock block public RevokedBlockBlock[] RevokedBlock; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RevokeModificationPacket() { Header = new LowHeader(); Header.ID = 167; Header.Reliable = true; RevokedBlock = new RevokedBlockBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RevokeModificationPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; RevokedBlock = new RevokedBlockBlock[count]; for (int j = 0; j < count; j++) { RevokedBlock[j] = new RevokedBlockBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RevokeModificationPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; RevokedBlock = new RevokedBlockBlock[count]; for (int j = 0; j < count; j++) { RevokedBlock[j] = new RevokedBlockBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < RevokedBlock.Length; j++) { length += RevokedBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)RevokedBlock.Length; for (int j = 0; j < RevokedBlock.Length; j++) { RevokedBlock[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RevokeModification ---\n"; for (int j = 0; j < RevokedBlock.Length; j++) { output += RevokedBlock[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// RequestGrantedProxies packet public class RequestGrantedProxiesPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RequestGrantedProxies public override PacketType Type { get { return PacketType.RequestGrantedProxies; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RequestGrantedProxiesPacket() { Header = new LowHeader(); Header.ID = 168; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RequestGrantedProxiesPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RequestGrantedProxiesPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RequestGrantedProxies ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// GrantedProxies packet public class GrantedProxiesPacket : Packet { /// EmpoweredBlock block public class EmpoweredBlockBlock { /// EmpoweredID field public LLUUID EmpoweredID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public EmpoweredBlockBlock() { } /// Constructor for building the block from a byte array public EmpoweredBlockBlock(byte[] bytes, ref int i) { try { EmpoweredID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(EmpoweredID == null) { Console.WriteLine("Warning: EmpoweredID is null, in " + this.GetType()); } Array.Copy(EmpoweredID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- EmpoweredBlock --\n"; output += "EmpoweredID: " + EmpoweredID.ToString() + "\n"; output = output.Trim(); return output; } } /// GranterBlock block public class GranterBlockBlock { /// GranterID field public LLUUID GranterID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public GranterBlockBlock() { } /// Constructor for building the block from a byte array public GranterBlockBlock(byte[] bytes, ref int i) { try { GranterID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GranterID == null) { Console.WriteLine("Warning: GranterID is null, in " + this.GetType()); } Array.Copy(GranterID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GranterBlock --\n"; output += "GranterID: " + GranterID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GrantedProxies public override PacketType Type { get { return PacketType.GrantedProxies; } } /// EmpoweredBlock block public EmpoweredBlockBlock[] EmpoweredBlock; /// GranterBlock block public GranterBlockBlock[] GranterBlock; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GrantedProxiesPacket() { Header = new LowHeader(); Header.ID = 169; Header.Reliable = true; EmpoweredBlock = new EmpoweredBlockBlock[0]; GranterBlock = new GranterBlockBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GrantedProxiesPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; EmpoweredBlock = new EmpoweredBlockBlock[count]; for (int j = 0; j < count; j++) { EmpoweredBlock[j] = new EmpoweredBlockBlock(bytes, ref i); } count = (int)bytes[i++]; GranterBlock = new GranterBlockBlock[count]; for (int j = 0; j < count; j++) { GranterBlock[j] = new GranterBlockBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GrantedProxiesPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; EmpoweredBlock = new EmpoweredBlockBlock[count]; for (int j = 0; j < count; j++) { EmpoweredBlock[j] = new EmpoweredBlockBlock(bytes, ref i); } count = (int)bytes[i++]; GranterBlock = new GranterBlockBlock[count]; for (int j = 0; j < count; j++) { GranterBlock[j] = new GranterBlockBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < EmpoweredBlock.Length; j++) { length += EmpoweredBlock[j].Length; } length++; for (int j = 0; j < GranterBlock.Length; j++) { length += GranterBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)EmpoweredBlock.Length; for (int j = 0; j < EmpoweredBlock.Length; j++) { EmpoweredBlock[j].ToBytes(bytes, ref i); } bytes[i++] = (byte)GranterBlock.Length; for (int j = 0; j < GranterBlock.Length; j++) { GranterBlock[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GrantedProxies ---\n"; for (int j = 0; j < EmpoweredBlock.Length; j++) { output += EmpoweredBlock[j].ToString() + "\n"; } for (int j = 0; j < GranterBlock.Length; j++) { output += GranterBlock[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// AddModifyAbility packet public class AddModifyAbilityPacket : Packet { /// TargetBlock block public class TargetBlockBlock { /// TargetIP field public uint TargetIP; /// TargetPort field public ushort TargetPort; /// Length of this block serialized in bytes public int Length { get { return 6; } } /// Default constructor public TargetBlockBlock() { } /// Constructor for building the block from a byte array public TargetBlockBlock(byte[] bytes, ref int i) { try { TargetIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TargetPort = (ushort)((bytes[i++] << 8) + bytes[i++]); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(TargetIP % 256); bytes[i++] = (byte)((TargetIP >> 8) % 256); bytes[i++] = (byte)((TargetIP >> 16) % 256); bytes[i++] = (byte)((TargetIP >> 24) % 256); bytes[i++] = (byte)((TargetPort >> 8) % 256); bytes[i++] = (byte)(TargetPort % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TargetBlock --\n"; output += "TargetIP: " + TargetIP.ToString() + "\n"; output += "TargetPort: " + TargetPort.ToString() + "\n"; output = output.Trim(); return output; } } /// GranterBlock block public class GranterBlockBlock { /// GranterID field public LLUUID GranterID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public GranterBlockBlock() { } /// Constructor for building the block from a byte array public GranterBlockBlock(byte[] bytes, ref int i) { try { GranterID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GranterID == null) { Console.WriteLine("Warning: GranterID is null, in " + this.GetType()); } Array.Copy(GranterID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GranterBlock --\n"; output += "GranterID: " + GranterID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentBlock block public class AgentBlockBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentBlockBlock() { } /// Constructor for building the block from a byte array public AgentBlockBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentBlock --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AddModifyAbility public override PacketType Type { get { return PacketType.AddModifyAbility; } } /// TargetBlock block public TargetBlockBlock TargetBlock; /// GranterBlock block public GranterBlockBlock[] GranterBlock; /// AgentBlock block public AgentBlockBlock AgentBlock; /// Default constructor public AddModifyAbilityPacket() { Header = new LowHeader(); Header.ID = 170; Header.Reliable = true; Header.Zerocoded = true; TargetBlock = new TargetBlockBlock(); GranterBlock = new GranterBlockBlock[0]; AgentBlock = new AgentBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AddModifyAbilityPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TargetBlock = new TargetBlockBlock(bytes, ref i); int count = (int)bytes[i++]; GranterBlock = new GranterBlockBlock[count]; for (int j = 0; j < count; j++) { GranterBlock[j] = new GranterBlockBlock(bytes, ref i); } AgentBlock = new AgentBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AddModifyAbilityPacket(Header head, byte[] bytes, ref int i) { Header = head; TargetBlock = new TargetBlockBlock(bytes, ref i); int count = (int)bytes[i++]; GranterBlock = new GranterBlockBlock[count]; for (int j = 0; j < count; j++) { GranterBlock[j] = new GranterBlockBlock(bytes, ref i); } AgentBlock = new AgentBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TargetBlock.Length; length += AgentBlock.Length;; length++; for (int j = 0; j < GranterBlock.Length; j++) { length += GranterBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TargetBlock.ToBytes(bytes, ref i); bytes[i++] = (byte)GranterBlock.Length; for (int j = 0; j < GranterBlock.Length; j++) { GranterBlock[j].ToBytes(bytes, ref i); } AgentBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AddModifyAbility ---\n"; output += TargetBlock.ToString() + "\n"; for (int j = 0; j < GranterBlock.Length; j++) { output += GranterBlock[j].ToString() + "\n"; } output += AgentBlock.ToString() + "\n"; return output; } } /// RemoveModifyAbility packet public class RemoveModifyAbilityPacket : Packet { /// TargetBlock block public class TargetBlockBlock { /// TargetIP field public uint TargetIP; /// TargetPort field public ushort TargetPort; /// Length of this block serialized in bytes public int Length { get { return 6; } } /// Default constructor public TargetBlockBlock() { } /// Constructor for building the block from a byte array public TargetBlockBlock(byte[] bytes, ref int i) { try { TargetIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TargetPort = (ushort)((bytes[i++] << 8) + bytes[i++]); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(TargetIP % 256); bytes[i++] = (byte)((TargetIP >> 8) % 256); bytes[i++] = (byte)((TargetIP >> 16) % 256); bytes[i++] = (byte)((TargetIP >> 24) % 256); bytes[i++] = (byte)((TargetPort >> 8) % 256); bytes[i++] = (byte)(TargetPort % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TargetBlock --\n"; output += "TargetIP: " + TargetIP.ToString() + "\n"; output += "TargetPort: " + TargetPort.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentBlock block public class AgentBlockBlock { /// AgentID field public LLUUID AgentID; /// RevokerID field public LLUUID RevokerID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentBlockBlock() { } /// Constructor for building the block from a byte array public AgentBlockBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; RevokerID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(RevokerID == null) { Console.WriteLine("Warning: RevokerID is null, in " + this.GetType()); } Array.Copy(RevokerID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentBlock --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "RevokerID: " + RevokerID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RemoveModifyAbility public override PacketType Type { get { return PacketType.RemoveModifyAbility; } } /// TargetBlock block public TargetBlockBlock TargetBlock; /// AgentBlock block public AgentBlockBlock AgentBlock; /// Default constructor public RemoveModifyAbilityPacket() { Header = new LowHeader(); Header.ID = 171; Header.Reliable = true; TargetBlock = new TargetBlockBlock(); AgentBlock = new AgentBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RemoveModifyAbilityPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TargetBlock = new TargetBlockBlock(bytes, ref i); AgentBlock = new AgentBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RemoveModifyAbilityPacket(Header head, byte[] bytes, ref int i) { Header = head; TargetBlock = new TargetBlockBlock(bytes, ref i); AgentBlock = new AgentBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TargetBlock.Length; length += AgentBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TargetBlock.ToBytes(bytes, ref i); AgentBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RemoveModifyAbility ---\n"; output += TargetBlock.ToString() + "\n"; output += AgentBlock.ToString() + "\n"; return output; } } /// ViewerStats packet public class ViewerStatsPacket : Packet { /// DownloadTotals block public class DownloadTotalsBlock { /// Objects field public uint Objects; /// Textures field public uint Textures; /// World field public uint World; /// Length of this block serialized in bytes public int Length { get { return 12; } } /// Default constructor public DownloadTotalsBlock() { } /// Constructor for building the block from a byte array public DownloadTotalsBlock(byte[] bytes, ref int i) { try { Objects = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Textures = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); World = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Objects % 256); bytes[i++] = (byte)((Objects >> 8) % 256); bytes[i++] = (byte)((Objects >> 16) % 256); bytes[i++] = (byte)((Objects >> 24) % 256); bytes[i++] = (byte)(Textures % 256); bytes[i++] = (byte)((Textures >> 8) % 256); bytes[i++] = (byte)((Textures >> 16) % 256); bytes[i++] = (byte)((Textures >> 24) % 256); bytes[i++] = (byte)(World % 256); bytes[i++] = (byte)((World >> 8) % 256); bytes[i++] = (byte)((World >> 16) % 256); bytes[i++] = (byte)((World >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DownloadTotals --\n"; output += "Objects: " + Objects.ToString() + "\n"; output += "Textures: " + Textures.ToString() + "\n"; output += "World: " + World.ToString() + "\n"; output = output.Trim(); return output; } } /// MiscStats block public class MiscStatsBlock { /// Type field public uint Type; /// Value field public double Value; /// Length of this block serialized in bytes public int Length { get { return 12; } } /// Default constructor public MiscStatsBlock() { } /// Constructor for building the block from a byte array public MiscStatsBlock(byte[] bytes, ref int i) { try { Type = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 8); Value = BitConverter.ToDouble(bytes, i); i += 8; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = (byte)(Type % 256); bytes[i++] = (byte)((Type >> 8) % 256); bytes[i++] = (byte)((Type >> 16) % 256); bytes[i++] = (byte)((Type >> 24) % 256); ba = BitConverter.GetBytes(Value); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 8); } Array.Copy(ba, 0, bytes, i, 8); i += 8; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MiscStats --\n"; output += "Type: " + Type.ToString() + "\n"; output += "Value: " + Value.ToString() + "\n"; output = output.Trim(); return output; } } /// NetStats block public class NetStatsBlock { /// Packets field public uint Packets; /// Savings field public uint Savings; /// Compressed field public uint Compressed; /// Bytes field public uint Bytes; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public NetStatsBlock() { } /// Constructor for building the block from a byte array public NetStatsBlock(byte[] bytes, ref int i) { try { Packets = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Savings = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Compressed = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Bytes = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Packets % 256); bytes[i++] = (byte)((Packets >> 8) % 256); bytes[i++] = (byte)((Packets >> 16) % 256); bytes[i++] = (byte)((Packets >> 24) % 256); bytes[i++] = (byte)(Savings % 256); bytes[i++] = (byte)((Savings >> 8) % 256); bytes[i++] = (byte)((Savings >> 16) % 256); bytes[i++] = (byte)((Savings >> 24) % 256); bytes[i++] = (byte)(Compressed % 256); bytes[i++] = (byte)((Compressed >> 8) % 256); bytes[i++] = (byte)((Compressed >> 16) % 256); bytes[i++] = (byte)((Compressed >> 24) % 256); bytes[i++] = (byte)(Bytes % 256); bytes[i++] = (byte)((Bytes >> 8) % 256); bytes[i++] = (byte)((Bytes >> 16) % 256); bytes[i++] = (byte)((Bytes >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- NetStats --\n"; output += "Packets: " + Packets.ToString() + "\n"; output += "Savings: " + Savings.ToString() + "\n"; output += "Compressed: " + Compressed.ToString() + "\n"; output += "Bytes: " + Bytes.ToString() + "\n"; output = output.Trim(); return output; } } /// FailStats block public class FailStatsBlock { /// FailedResends field public uint FailedResends; /// Invalid field public uint Invalid; /// SendPacket field public uint SendPacket; /// Dropped field public uint Dropped; /// OffCircuit field public uint OffCircuit; /// Resent field public uint Resent; /// Length of this block serialized in bytes public int Length { get { return 24; } } /// Default constructor public FailStatsBlock() { } /// Constructor for building the block from a byte array public FailStatsBlock(byte[] bytes, ref int i) { try { FailedResends = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Invalid = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SendPacket = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Dropped = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OffCircuit = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Resent = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(FailedResends % 256); bytes[i++] = (byte)((FailedResends >> 8) % 256); bytes[i++] = (byte)((FailedResends >> 16) % 256); bytes[i++] = (byte)((FailedResends >> 24) % 256); bytes[i++] = (byte)(Invalid % 256); bytes[i++] = (byte)((Invalid >> 8) % 256); bytes[i++] = (byte)((Invalid >> 16) % 256); bytes[i++] = (byte)((Invalid >> 24) % 256); bytes[i++] = (byte)(SendPacket % 256); bytes[i++] = (byte)((SendPacket >> 8) % 256); bytes[i++] = (byte)((SendPacket >> 16) % 256); bytes[i++] = (byte)((SendPacket >> 24) % 256); bytes[i++] = (byte)(Dropped % 256); bytes[i++] = (byte)((Dropped >> 8) % 256); bytes[i++] = (byte)((Dropped >> 16) % 256); bytes[i++] = (byte)((Dropped >> 24) % 256); bytes[i++] = (byte)(OffCircuit % 256); bytes[i++] = (byte)((OffCircuit >> 8) % 256); bytes[i++] = (byte)((OffCircuit >> 16) % 256); bytes[i++] = (byte)((OffCircuit >> 24) % 256); bytes[i++] = (byte)(Resent % 256); bytes[i++] = (byte)((Resent >> 8) % 256); bytes[i++] = (byte)((Resent >> 16) % 256); bytes[i++] = (byte)((Resent >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- FailStats --\n"; output += "FailedResends: " + FailedResends.ToString() + "\n"; output += "Invalid: " + Invalid.ToString() + "\n"; output += "SendPacket: " + SendPacket.ToString() + "\n"; output += "Dropped: " + Dropped.ToString() + "\n"; output += "OffCircuit: " + OffCircuit.ToString() + "\n"; output += "Resent: " + Resent.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// IP field public uint IP; /// FPS field public float FPS; /// AgentID field public LLUUID AgentID; /// RegionsVisited field public int RegionsVisited; /// SessionID field public LLUUID SessionID; /// Ping field public float Ping; /// RunTime field public float RunTime; /// MetersTraveled field public double MetersTraveled; private byte[] _syscpu; /// SysCPU field public byte[] SysCPU { get { return _syscpu; } set { if (value == null) { _syscpu = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _syscpu = new byte[value.Length]; Array.Copy(value, _syscpu, value.Length); } } } private byte[] _sysgpu; /// SysGPU field public byte[] SysGPU { get { return _sysgpu; } set { if (value == null) { _sysgpu = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _sysgpu = new byte[value.Length]; Array.Copy(value, _sysgpu, value.Length); } } } /// SysRAM field public uint SysRAM; /// StartTime field public uint StartTime; private byte[] _sysos; /// SysOS field public byte[] SysOS { get { return _sysos; } set { if (value == null) { _sysos = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _sysos = new byte[value.Length]; Array.Copy(value, _sysos, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 68; if (SysCPU != null) { length += 1 + SysCPU.Length; } if (SysGPU != null) { length += 1 + SysGPU.Length; } if (SysOS != null) { length += 1 + SysOS.Length; } return length; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { int length; try { IP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); FPS = BitConverter.ToSingle(bytes, i); i += 4; AgentID = new LLUUID(bytes, i); i += 16; RegionsVisited = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SessionID = new LLUUID(bytes, i); i += 16; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Ping = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); RunTime = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 8); MetersTraveled = BitConverter.ToDouble(bytes, i); i += 8; length = (ushort)bytes[i++]; _syscpu = new byte[length]; Array.Copy(bytes, i, _syscpu, 0, length); i += length; length = (ushort)bytes[i++]; _sysgpu = new byte[length]; Array.Copy(bytes, i, _sysgpu, 0, length); i += length; SysRAM = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); StartTime = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _sysos = new byte[length]; Array.Copy(bytes, i, _sysos, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = (byte)(IP % 256); bytes[i++] = (byte)((IP >> 8) % 256); bytes[i++] = (byte)((IP >> 16) % 256); bytes[i++] = (byte)((IP >> 24) % 256); ba = BitConverter.GetBytes(FPS); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(RegionsVisited % 256); bytes[i++] = (byte)((RegionsVisited >> 8) % 256); bytes[i++] = (byte)((RegionsVisited >> 16) % 256); bytes[i++] = (byte)((RegionsVisited >> 24) % 256); if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; ba = BitConverter.GetBytes(Ping); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(RunTime); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(MetersTraveled); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 8); } Array.Copy(ba, 0, bytes, i, 8); i += 8; if(SysCPU == null) { Console.WriteLine("Warning: SysCPU is null, in " + this.GetType()); } bytes[i++] = (byte)SysCPU.Length; Array.Copy(SysCPU, 0, bytes, i, SysCPU.Length); i += SysCPU.Length; if(SysGPU == null) { Console.WriteLine("Warning: SysGPU is null, in " + this.GetType()); } bytes[i++] = (byte)SysGPU.Length; Array.Copy(SysGPU, 0, bytes, i, SysGPU.Length); i += SysGPU.Length; bytes[i++] = (byte)(SysRAM % 256); bytes[i++] = (byte)((SysRAM >> 8) % 256); bytes[i++] = (byte)((SysRAM >> 16) % 256); bytes[i++] = (byte)((SysRAM >> 24) % 256); bytes[i++] = (byte)(StartTime % 256); bytes[i++] = (byte)((StartTime >> 8) % 256); bytes[i++] = (byte)((StartTime >> 16) % 256); bytes[i++] = (byte)((StartTime >> 24) % 256); if(SysOS == null) { Console.WriteLine("Warning: SysOS is null, in " + this.GetType()); } bytes[i++] = (byte)SysOS.Length; Array.Copy(SysOS, 0, bytes, i, SysOS.Length); i += SysOS.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "IP: " + IP.ToString() + "\n"; output += "FPS: " + FPS.ToString() + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "RegionsVisited: " + RegionsVisited.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "Ping: " + Ping.ToString() + "\n"; output += "RunTime: " + RunTime.ToString() + "\n"; output += "MetersTraveled: " + MetersTraveled.ToString() + "\n"; output += Helpers.FieldToString(SysCPU, "SysCPU") + "\n"; output += Helpers.FieldToString(SysGPU, "SysGPU") + "\n"; output += "SysRAM: " + SysRAM.ToString() + "\n"; output += "StartTime: " + StartTime.ToString() + "\n"; output += Helpers.FieldToString(SysOS, "SysOS") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ViewerStats public override PacketType Type { get { return PacketType.ViewerStats; } } /// DownloadTotals block public DownloadTotalsBlock DownloadTotals; /// MiscStats block public MiscStatsBlock[] MiscStats; /// NetStats block public NetStatsBlock[] NetStats; /// FailStats block public FailStatsBlock FailStats; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ViewerStatsPacket() { Header = new LowHeader(); Header.ID = 172; Header.Reliable = true; Header.Zerocoded = true; DownloadTotals = new DownloadTotalsBlock(); MiscStats = new MiscStatsBlock[0]; NetStats = new NetStatsBlock[2]; FailStats = new FailStatsBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ViewerStatsPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); DownloadTotals = new DownloadTotalsBlock(bytes, ref i); int count = (int)bytes[i++]; MiscStats = new MiscStatsBlock[count]; for (int j = 0; j < count; j++) { MiscStats[j] = new MiscStatsBlock(bytes, ref i); } NetStats = new NetStatsBlock[2]; for (int j = 0; j < 2; j++) { NetStats[j] = new NetStatsBlock(bytes, ref i); } FailStats = new FailStatsBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ViewerStatsPacket(Header head, byte[] bytes, ref int i) { Header = head; DownloadTotals = new DownloadTotalsBlock(bytes, ref i); int count = (int)bytes[i++]; MiscStats = new MiscStatsBlock[count]; for (int j = 0; j < count; j++) { MiscStats[j] = new MiscStatsBlock(bytes, ref i); } NetStats = new NetStatsBlock[2]; for (int j = 0; j < 2; j++) { NetStats[j] = new NetStatsBlock(bytes, ref i); } FailStats = new FailStatsBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += DownloadTotals.Length; length += FailStats.Length; length += AgentData.Length;; length++; for (int j = 0; j < MiscStats.Length; j++) { length += MiscStats[j].Length; } for (int j = 0; j < 2; j++) { length += NetStats[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DownloadTotals.ToBytes(bytes, ref i); bytes[i++] = (byte)MiscStats.Length; for (int j = 0; j < MiscStats.Length; j++) { MiscStats[j].ToBytes(bytes, ref i); } for (int j = 0; j < 2; j++) { NetStats[j].ToBytes(bytes, ref i); } FailStats.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ViewerStats ---\n"; output += DownloadTotals.ToString() + "\n"; for (int j = 0; j < MiscStats.Length; j++) { output += MiscStats[j].ToString() + "\n"; } for (int j = 0; j < 2; j++) { output += NetStats[j].ToString() + "\n"; } output += FailStats.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ScriptAnswerYes packet public class ScriptAnswerYesPacket : Packet { /// Data block public class DataBlock { /// TaskID field public LLUUID TaskID; /// ItemID field public LLUUID ItemID; /// Questions field public int Questions; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { TaskID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; Questions = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TaskID == null) { Console.WriteLine("Warning: TaskID is null, in " + this.GetType()); } Array.Copy(TaskID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Questions % 256); bytes[i++] = (byte)((Questions >> 8) % 256); bytes[i++] = (byte)((Questions >> 16) % 256); bytes[i++] = (byte)((Questions >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "TaskID: " + TaskID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "Questions: " + Questions.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ScriptAnswerYes public override PacketType Type { get { return PacketType.ScriptAnswerYes; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ScriptAnswerYesPacket() { Header = new LowHeader(); Header.ID = 173; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ScriptAnswerYesPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ScriptAnswerYesPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ScriptAnswerYes ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// UserReport packet public class UserReportPacket : Packet { /// MeanCollision block public class MeanCollisionBlock { /// Mag field public float Mag; /// Time field public uint Time; /// Perp field public LLUUID Perp; /// Type field public byte Type; /// Length of this block serialized in bytes public int Length { get { return 25; } } /// Default constructor public MeanCollisionBlock() { } /// Constructor for building the block from a byte array public MeanCollisionBlock(byte[] bytes, ref int i) { try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Mag = BitConverter.ToSingle(bytes, i); i += 4; Time = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Perp = new LLUUID(bytes, i); i += 16; Type = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(Mag); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(Time % 256); bytes[i++] = (byte)((Time >> 8) % 256); bytes[i++] = (byte)((Time >> 16) % 256); bytes[i++] = (byte)((Time >> 24) % 256); if(Perp == null) { Console.WriteLine("Warning: Perp is null, in " + this.GetType()); } Array.Copy(Perp.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = Type; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MeanCollision --\n"; output += "Mag: " + Mag.ToString() + "\n"; output += "Time: " + Time.ToString() + "\n"; output += "Perp: " + Perp.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output = output.Trim(); return output; } } /// ReportData block public class ReportDataBlock { /// ObjectID field public LLUUID ObjectID; private byte[] _details; /// Details field public byte[] Details { get { return _details; } set { if (value == null) { _details = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _details = new byte[value.Length]; Array.Copy(value, _details, value.Length); } } } private byte[] _versionstring; /// VersionString field public byte[] VersionString { get { return _versionstring; } set { if (value == null) { _versionstring = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _versionstring = new byte[value.Length]; Array.Copy(value, _versionstring, value.Length); } } } /// CheckFlags field public byte CheckFlags; /// Category field public byte Category; private byte[] _summary; /// Summary field public byte[] Summary { get { return _summary; } set { if (value == null) { _summary = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _summary = new byte[value.Length]; Array.Copy(value, _summary, value.Length); } } } /// ReportType field public byte ReportType; /// ScreenshotID field public LLUUID ScreenshotID; /// Position field public LLVector3 Position; /// Length of this block serialized in bytes public int Length { get { int length = 47; if (Details != null) { length += 2 + Details.Length; } if (VersionString != null) { length += 1 + VersionString.Length; } if (Summary != null) { length += 1 + Summary.Length; } return length; } } /// Default constructor public ReportDataBlock() { } /// Constructor for building the block from a byte array public ReportDataBlock(byte[] bytes, ref int i) { int length; try { ObjectID = new LLUUID(bytes, i); i += 16; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _details = new byte[length]; Array.Copy(bytes, i, _details, 0, length); i += length; length = (ushort)bytes[i++]; _versionstring = new byte[length]; Array.Copy(bytes, i, _versionstring, 0, length); i += length; CheckFlags = (byte)bytes[i++]; Category = (byte)bytes[i++]; length = (ushort)bytes[i++]; _summary = new byte[length]; Array.Copy(bytes, i, _summary, 0, length); i += length; ReportType = (byte)bytes[i++]; ScreenshotID = new LLUUID(bytes, i); i += 16; Position = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; if(Details == null) { Console.WriteLine("Warning: Details is null, in " + this.GetType()); } bytes[i++] = (byte)(Details.Length % 256); bytes[i++] = (byte)((Details.Length >> 8) % 256); Array.Copy(Details, 0, bytes, i, Details.Length); i += Details.Length; if(VersionString == null) { Console.WriteLine("Warning: VersionString is null, in " + this.GetType()); } bytes[i++] = (byte)VersionString.Length; Array.Copy(VersionString, 0, bytes, i, VersionString.Length); i += VersionString.Length; bytes[i++] = CheckFlags; bytes[i++] = Category; if(Summary == null) { Console.WriteLine("Warning: Summary is null, in " + this.GetType()); } bytes[i++] = (byte)Summary.Length; Array.Copy(Summary, 0, bytes, i, Summary.Length); i += Summary.Length; bytes[i++] = ReportType; if(ScreenshotID == null) { Console.WriteLine("Warning: ScreenshotID is null, in " + this.GetType()); } Array.Copy(ScreenshotID.GetBytes(), 0, bytes, i, 16); i += 16; if(Position == null) { Console.WriteLine("Warning: Position is null, in " + this.GetType()); } Array.Copy(Position.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ReportData --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += Helpers.FieldToString(Details, "Details") + "\n"; output += Helpers.FieldToString(VersionString, "VersionString") + "\n"; output += "CheckFlags: " + CheckFlags.ToString() + "\n"; output += "Category: " + Category.ToString() + "\n"; output += Helpers.FieldToString(Summary, "Summary") + "\n"; output += "ReportType: " + ReportType.ToString() + "\n"; output += "ScreenshotID: " + ScreenshotID.ToString() + "\n"; output += "Position: " + Position.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UserReport public override PacketType Type { get { return PacketType.UserReport; } } /// MeanCollision block public MeanCollisionBlock[] MeanCollision; /// ReportData block public ReportDataBlock ReportData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public UserReportPacket() { Header = new LowHeader(); Header.ID = 174; Header.Reliable = true; Header.Zerocoded = true; MeanCollision = new MeanCollisionBlock[0]; ReportData = new ReportDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UserReportPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; MeanCollision = new MeanCollisionBlock[count]; for (int j = 0; j < count; j++) { MeanCollision[j] = new MeanCollisionBlock(bytes, ref i); } ReportData = new ReportDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public UserReportPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; MeanCollision = new MeanCollisionBlock[count]; for (int j = 0; j < count; j++) { MeanCollision[j] = new MeanCollisionBlock(bytes, ref i); } ReportData = new ReportDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ReportData.Length; length += AgentData.Length;; length++; for (int j = 0; j < MeanCollision.Length; j++) { length += MeanCollision[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)MeanCollision.Length; for (int j = 0; j < MeanCollision.Length; j++) { MeanCollision[j].ToBytes(bytes, ref i); } ReportData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UserReport ---\n"; for (int j = 0; j < MeanCollision.Length; j++) { output += MeanCollision[j].ToString() + "\n"; } output += ReportData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// AlertMessage packet public class AlertMessagePacket : Packet { /// AlertData block public class AlertDataBlock { private byte[] _message; /// Message field public byte[] Message { get { return _message; } set { if (value == null) { _message = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _message = new byte[value.Length]; Array.Copy(value, _message, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (Message != null) { length += 1 + Message.Length; } return length; } } /// Default constructor public AlertDataBlock() { } /// Constructor for building the block from a byte array public AlertDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _message = new byte[length]; Array.Copy(bytes, i, _message, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Message == null) { Console.WriteLine("Warning: Message is null, in " + this.GetType()); } bytes[i++] = (byte)Message.Length; Array.Copy(Message, 0, bytes, i, Message.Length); i += Message.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AlertData --\n"; output += Helpers.FieldToString(Message, "Message") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AlertMessage public override PacketType Type { get { return PacketType.AlertMessage; } } /// AlertData block public AlertDataBlock AlertData; /// Default constructor public AlertMessagePacket() { Header = new LowHeader(); Header.ID = 175; Header.Reliable = true; AlertData = new AlertDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AlertMessagePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AlertData = new AlertDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AlertMessagePacket(Header head, byte[] bytes, ref int i) { Header = head; AlertData = new AlertDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AlertData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AlertData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AlertMessage ---\n"; output += AlertData.ToString() + "\n"; return output; } } /// AgentAlertMessage packet public class AgentAlertMessagePacket : Packet { /// AlertData block public class AlertDataBlock { private byte[] _message; /// Message field public byte[] Message { get { return _message; } set { if (value == null) { _message = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _message = new byte[value.Length]; Array.Copy(value, _message, value.Length); } } } /// Modal field public bool Modal; /// Length of this block serialized in bytes public int Length { get { int length = 1; if (Message != null) { length += 1 + Message.Length; } return length; } } /// Default constructor public AlertDataBlock() { } /// Constructor for building the block from a byte array public AlertDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _message = new byte[length]; Array.Copy(bytes, i, _message, 0, length); i += length; Modal = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Message == null) { Console.WriteLine("Warning: Message is null, in " + this.GetType()); } bytes[i++] = (byte)Message.Length; Array.Copy(Message, 0, bytes, i, Message.Length); i += Message.Length; bytes[i++] = (byte)((Modal) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AlertData --\n"; output += Helpers.FieldToString(Message, "Message") + "\n"; output += "Modal: " + Modal.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentAlertMessage public override PacketType Type { get { return PacketType.AgentAlertMessage; } } /// AlertData block public AlertDataBlock AlertData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentAlertMessagePacket() { Header = new LowHeader(); Header.ID = 176; Header.Reliable = true; AlertData = new AlertDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentAlertMessagePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AlertData = new AlertDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentAlertMessagePacket(Header head, byte[] bytes, ref int i) { Header = head; AlertData = new AlertDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AlertData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AlertData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentAlertMessage ---\n"; output += AlertData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// MeanCollisionAlert packet public class MeanCollisionAlertPacket : Packet { /// MeanCollision block public class MeanCollisionBlock { /// Mag field public float Mag; /// Time field public uint Time; /// Perp field public LLUUID Perp; /// Type field public byte Type; /// Victim field public LLUUID Victim; /// Length of this block serialized in bytes public int Length { get { return 41; } } /// Default constructor public MeanCollisionBlock() { } /// Constructor for building the block from a byte array public MeanCollisionBlock(byte[] bytes, ref int i) { try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Mag = BitConverter.ToSingle(bytes, i); i += 4; Time = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Perp = new LLUUID(bytes, i); i += 16; Type = (byte)bytes[i++]; Victim = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(Mag); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(Time % 256); bytes[i++] = (byte)((Time >> 8) % 256); bytes[i++] = (byte)((Time >> 16) % 256); bytes[i++] = (byte)((Time >> 24) % 256); if(Perp == null) { Console.WriteLine("Warning: Perp is null, in " + this.GetType()); } Array.Copy(Perp.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = Type; if(Victim == null) { Console.WriteLine("Warning: Victim is null, in " + this.GetType()); } Array.Copy(Victim.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MeanCollision --\n"; output += "Mag: " + Mag.ToString() + "\n"; output += "Time: " + Time.ToString() + "\n"; output += "Perp: " + Perp.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "Victim: " + Victim.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MeanCollisionAlert public override PacketType Type { get { return PacketType.MeanCollisionAlert; } } /// MeanCollision block public MeanCollisionBlock[] MeanCollision; /// Default constructor public MeanCollisionAlertPacket() { Header = new LowHeader(); Header.ID = 177; Header.Reliable = true; Header.Zerocoded = true; MeanCollision = new MeanCollisionBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MeanCollisionAlertPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; MeanCollision = new MeanCollisionBlock[count]; for (int j = 0; j < count; j++) { MeanCollision[j] = new MeanCollisionBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public MeanCollisionAlertPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; MeanCollision = new MeanCollisionBlock[count]; for (int j = 0; j < count; j++) { MeanCollision[j] = new MeanCollisionBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < MeanCollision.Length; j++) { length += MeanCollision[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)MeanCollision.Length; for (int j = 0; j < MeanCollision.Length; j++) { MeanCollision[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MeanCollisionAlert ---\n"; for (int j = 0; j < MeanCollision.Length; j++) { output += MeanCollision[j].ToString() + "\n"; } return output; } } /// ViewerFrozenMessage packet public class ViewerFrozenMessagePacket : Packet { /// FrozenData block public class FrozenDataBlock { /// Data field public bool Data; /// Length of this block serialized in bytes public int Length { get { return 1; } } /// Default constructor public FrozenDataBlock() { } /// Constructor for building the block from a byte array public FrozenDataBlock(byte[] bytes, ref int i) { try { Data = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((Data) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- FrozenData --\n"; output += "Data: " + Data.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ViewerFrozenMessage public override PacketType Type { get { return PacketType.ViewerFrozenMessage; } } /// FrozenData block public FrozenDataBlock FrozenData; /// Default constructor public ViewerFrozenMessagePacket() { Header = new LowHeader(); Header.ID = 178; Header.Reliable = true; FrozenData = new FrozenDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ViewerFrozenMessagePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); FrozenData = new FrozenDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ViewerFrozenMessagePacket(Header head, byte[] bytes, ref int i) { Header = head; FrozenData = new FrozenDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += FrozenData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); FrozenData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ViewerFrozenMessage ---\n"; output += FrozenData.ToString() + "\n"; return output; } } /// HealthMessage packet public class HealthMessagePacket : Packet { /// HealthData block public class HealthDataBlock { /// Health field public float Health; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public HealthDataBlock() { } /// Constructor for building the block from a byte array public HealthDataBlock(byte[] bytes, ref int i) { try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Health = BitConverter.ToSingle(bytes, i); i += 4; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(Health); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- HealthData --\n"; output += "Health: " + Health.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.HealthMessage public override PacketType Type { get { return PacketType.HealthMessage; } } /// HealthData block public HealthDataBlock HealthData; /// Default constructor public HealthMessagePacket() { Header = new LowHeader(); Header.ID = 179; Header.Reliable = true; Header.Zerocoded = true; HealthData = new HealthDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public HealthMessagePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); HealthData = new HealthDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public HealthMessagePacket(Header head, byte[] bytes, ref int i) { Header = head; HealthData = new HealthDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += HealthData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); HealthData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- HealthMessage ---\n"; output += HealthData.ToString() + "\n"; return output; } } /// ChatFromSimulator packet public class ChatFromSimulatorPacket : Packet { /// ChatData block public class ChatDataBlock { private byte[] _message; /// Message field public byte[] Message { get { return _message; } set { if (value == null) { _message = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _message = new byte[value.Length]; Array.Copy(value, _message, value.Length); } } } /// Audible field public byte Audible; /// ChatType field public byte ChatType; /// OwnerID field public LLUUID OwnerID; private byte[] _fromname; /// FromName field public byte[] FromName { get { return _fromname; } set { if (value == null) { _fromname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _fromname = new byte[value.Length]; Array.Copy(value, _fromname, value.Length); } } } /// SourceType field public byte SourceType; /// SourceID field public LLUUID SourceID; /// Position field public LLVector3 Position; /// Length of this block serialized in bytes public int Length { get { int length = 47; if (Message != null) { length += 2 + Message.Length; } if (FromName != null) { length += 1 + FromName.Length; } return length; } } /// Default constructor public ChatDataBlock() { } /// Constructor for building the block from a byte array public ChatDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _message = new byte[length]; Array.Copy(bytes, i, _message, 0, length); i += length; Audible = (byte)bytes[i++]; ChatType = (byte)bytes[i++]; OwnerID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _fromname = new byte[length]; Array.Copy(bytes, i, _fromname, 0, length); i += length; SourceType = (byte)bytes[i++]; SourceID = new LLUUID(bytes, i); i += 16; Position = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Message == null) { Console.WriteLine("Warning: Message is null, in " + this.GetType()); } bytes[i++] = (byte)(Message.Length % 256); bytes[i++] = (byte)((Message.Length >> 8) % 256); Array.Copy(Message, 0, bytes, i, Message.Length); i += Message.Length; bytes[i++] = Audible; bytes[i++] = ChatType; if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(FromName == null) { Console.WriteLine("Warning: FromName is null, in " + this.GetType()); } bytes[i++] = (byte)FromName.Length; Array.Copy(FromName, 0, bytes, i, FromName.Length); i += FromName.Length; bytes[i++] = SourceType; if(SourceID == null) { Console.WriteLine("Warning: SourceID is null, in " + this.GetType()); } Array.Copy(SourceID.GetBytes(), 0, bytes, i, 16); i += 16; if(Position == null) { Console.WriteLine("Warning: Position is null, in " + this.GetType()); } Array.Copy(Position.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ChatData --\n"; output += Helpers.FieldToString(Message, "Message") + "\n"; output += "Audible: " + Audible.ToString() + "\n"; output += "ChatType: " + ChatType.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += Helpers.FieldToString(FromName, "FromName") + "\n"; output += "SourceType: " + SourceType.ToString() + "\n"; output += "SourceID: " + SourceID.ToString() + "\n"; output += "Position: " + Position.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ChatFromSimulator public override PacketType Type { get { return PacketType.ChatFromSimulator; } } /// ChatData block public ChatDataBlock ChatData; /// Default constructor public ChatFromSimulatorPacket() { Header = new LowHeader(); Header.ID = 180; Header.Reliable = true; ChatData = new ChatDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ChatFromSimulatorPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ChatData = new ChatDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ChatFromSimulatorPacket(Header head, byte[] bytes, ref int i) { Header = head; ChatData = new ChatDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ChatData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ChatData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ChatFromSimulator ---\n"; output += ChatData.ToString() + "\n"; return output; } } /// SimStats packet public class SimStatsPacket : Packet { /// Stat block public class StatBlock { /// StatValue field public float StatValue; /// StatID field public uint StatID; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public StatBlock() { } /// Constructor for building the block from a byte array public StatBlock(byte[] bytes, ref int i) { try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); StatValue = BitConverter.ToSingle(bytes, i); i += 4; StatID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(StatValue); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(StatID % 256); bytes[i++] = (byte)((StatID >> 8) % 256); bytes[i++] = (byte)((StatID >> 16) % 256); bytes[i++] = (byte)((StatID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Stat --\n"; output += "StatValue: " + StatValue.ToString() + "\n"; output += "StatID: " + StatID.ToString() + "\n"; output = output.Trim(); return output; } } /// Region block public class RegionBlock { /// RegionX field public uint RegionX; /// RegionY field public uint RegionY; /// RegionFlags field public uint RegionFlags; /// ObjectCapacity field public uint ObjectCapacity; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public RegionBlock() { } /// Constructor for building the block from a byte array public RegionBlock(byte[] bytes, ref int i) { try { RegionX = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RegionY = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RegionFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ObjectCapacity = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(RegionX % 256); bytes[i++] = (byte)((RegionX >> 8) % 256); bytes[i++] = (byte)((RegionX >> 16) % 256); bytes[i++] = (byte)((RegionX >> 24) % 256); bytes[i++] = (byte)(RegionY % 256); bytes[i++] = (byte)((RegionY >> 8) % 256); bytes[i++] = (byte)((RegionY >> 16) % 256); bytes[i++] = (byte)((RegionY >> 24) % 256); bytes[i++] = (byte)(RegionFlags % 256); bytes[i++] = (byte)((RegionFlags >> 8) % 256); bytes[i++] = (byte)((RegionFlags >> 16) % 256); bytes[i++] = (byte)((RegionFlags >> 24) % 256); bytes[i++] = (byte)(ObjectCapacity % 256); bytes[i++] = (byte)((ObjectCapacity >> 8) % 256); bytes[i++] = (byte)((ObjectCapacity >> 16) % 256); bytes[i++] = (byte)((ObjectCapacity >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Region --\n"; output += "RegionX: " + RegionX.ToString() + "\n"; output += "RegionY: " + RegionY.ToString() + "\n"; output += "RegionFlags: " + RegionFlags.ToString() + "\n"; output += "ObjectCapacity: " + ObjectCapacity.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SimStats public override PacketType Type { get { return PacketType.SimStats; } } /// Stat block public StatBlock[] Stat; /// Region block public RegionBlock Region; /// Default constructor public SimStatsPacket() { Header = new LowHeader(); Header.ID = 181; Header.Reliable = true; Stat = new StatBlock[0]; Region = new RegionBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SimStatsPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; Stat = new StatBlock[count]; for (int j = 0; j < count; j++) { Stat[j] = new StatBlock(bytes, ref i); } Region = new RegionBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SimStatsPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; Stat = new StatBlock[count]; for (int j = 0; j < count; j++) { Stat[j] = new StatBlock(bytes, ref i); } Region = new RegionBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Region.Length;; length++; for (int j = 0; j < Stat.Length; j++) { length += Stat[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)Stat.Length; for (int j = 0; j < Stat.Length; j++) { Stat[j].ToBytes(bytes, ref i); } Region.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SimStats ---\n"; for (int j = 0; j < Stat.Length; j++) { output += Stat[j].ToString() + "\n"; } output += Region.ToString() + "\n"; return output; } } /// RequestRegionInfo packet public class RequestRegionInfoPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RequestRegionInfo public override PacketType Type { get { return PacketType.RequestRegionInfo; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RequestRegionInfoPacket() { Header = new LowHeader(); Header.ID = 182; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RequestRegionInfoPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RequestRegionInfoPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RequestRegionInfo ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// RegionInfo packet public class RegionInfoPacket : Packet { /// RegionInfo block public class RegionInfoBlock { /// BillableFactor field public float BillableFactor; /// ObjectBonusFactor field public float ObjectBonusFactor; /// RedirectGridX field public int RedirectGridX; /// RedirectGridY field public int RedirectGridY; private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// PricePerMeter field public int PricePerMeter; /// RegionFlags field public uint RegionFlags; /// WaterHeight field public float WaterHeight; /// UseEstateSun field public bool UseEstateSun; /// SunHour field public float SunHour; /// MaxAgents field public byte MaxAgents; /// SimAccess field public byte SimAccess; /// TerrainLowerLimit field public float TerrainLowerLimit; /// ParentEstateID field public uint ParentEstateID; /// TerrainRaiseLimit field public float TerrainRaiseLimit; /// EstateID field public uint EstateID; /// Length of this block serialized in bytes public int Length { get { int length = 51; if (SimName != null) { length += 1 + SimName.Length; } return length; } } /// Default constructor public RegionInfoBlock() { } /// Constructor for building the block from a byte array public RegionInfoBlock(byte[] bytes, ref int i) { int length; try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); BillableFactor = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); ObjectBonusFactor = BitConverter.ToSingle(bytes, i); i += 4; RedirectGridX = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RedirectGridY = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; PricePerMeter = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RegionFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); WaterHeight = BitConverter.ToSingle(bytes, i); i += 4; UseEstateSun = (bytes[i++] != 0) ? (bool)true : (bool)false; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); SunHour = BitConverter.ToSingle(bytes, i); i += 4; MaxAgents = (byte)bytes[i++]; SimAccess = (byte)bytes[i++]; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); TerrainLowerLimit = BitConverter.ToSingle(bytes, i); i += 4; ParentEstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); TerrainRaiseLimit = BitConverter.ToSingle(bytes, i); i += 4; EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(BillableFactor); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(ObjectBonusFactor); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(RedirectGridX % 256); bytes[i++] = (byte)((RedirectGridX >> 8) % 256); bytes[i++] = (byte)((RedirectGridX >> 16) % 256); bytes[i++] = (byte)((RedirectGridX >> 24) % 256); bytes[i++] = (byte)(RedirectGridY % 256); bytes[i++] = (byte)((RedirectGridY >> 8) % 256); bytes[i++] = (byte)((RedirectGridY >> 16) % 256); bytes[i++] = (byte)((RedirectGridY >> 24) % 256); if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; bytes[i++] = (byte)(PricePerMeter % 256); bytes[i++] = (byte)((PricePerMeter >> 8) % 256); bytes[i++] = (byte)((PricePerMeter >> 16) % 256); bytes[i++] = (byte)((PricePerMeter >> 24) % 256); bytes[i++] = (byte)(RegionFlags % 256); bytes[i++] = (byte)((RegionFlags >> 8) % 256); bytes[i++] = (byte)((RegionFlags >> 16) % 256); bytes[i++] = (byte)((RegionFlags >> 24) % 256); ba = BitConverter.GetBytes(WaterHeight); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)((UseEstateSun) ? 1 : 0); ba = BitConverter.GetBytes(SunHour); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = MaxAgents; bytes[i++] = SimAccess; ba = BitConverter.GetBytes(TerrainLowerLimit); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(ParentEstateID % 256); bytes[i++] = (byte)((ParentEstateID >> 8) % 256); bytes[i++] = (byte)((ParentEstateID >> 16) % 256); bytes[i++] = (byte)((ParentEstateID >> 24) % 256); ba = BitConverter.GetBytes(TerrainRaiseLimit); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionInfo --\n"; output += "BillableFactor: " + BillableFactor.ToString() + "\n"; output += "ObjectBonusFactor: " + ObjectBonusFactor.ToString() + "\n"; output += "RedirectGridX: " + RedirectGridX.ToString() + "\n"; output += "RedirectGridY: " + RedirectGridY.ToString() + "\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "PricePerMeter: " + PricePerMeter.ToString() + "\n"; output += "RegionFlags: " + RegionFlags.ToString() + "\n"; output += "WaterHeight: " + WaterHeight.ToString() + "\n"; output += "UseEstateSun: " + UseEstateSun.ToString() + "\n"; output += "SunHour: " + SunHour.ToString() + "\n"; output += "MaxAgents: " + MaxAgents.ToString() + "\n"; output += "SimAccess: " + SimAccess.ToString() + "\n"; output += "TerrainLowerLimit: " + TerrainLowerLimit.ToString() + "\n"; output += "ParentEstateID: " + ParentEstateID.ToString() + "\n"; output += "TerrainRaiseLimit: " + TerrainRaiseLimit.ToString() + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RegionInfo public override PacketType Type { get { return PacketType.RegionInfo; } } /// RegionInfo block public RegionInfoBlock RegionInfo; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RegionInfoPacket() { Header = new LowHeader(); Header.ID = 183; Header.Reliable = true; Header.Zerocoded = true; RegionInfo = new RegionInfoBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RegionInfoPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); RegionInfo = new RegionInfoBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RegionInfoPacket(Header head, byte[] bytes, ref int i) { Header = head; RegionInfo = new RegionInfoBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += RegionInfo.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); RegionInfo.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RegionInfo ---\n"; output += RegionInfo.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// GodUpdateRegionInfo packet public class GodUpdateRegionInfoPacket : Packet { /// RegionInfo block public class RegionInfoBlock { /// BillableFactor field public float BillableFactor; /// RedirectGridX field public int RedirectGridX; /// RedirectGridY field public int RedirectGridY; private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// PricePerMeter field public int PricePerMeter; /// RegionFlags field public uint RegionFlags; /// ParentEstateID field public uint ParentEstateID; /// EstateID field public uint EstateID; /// Length of this block serialized in bytes public int Length { get { int length = 28; if (SimName != null) { length += 1 + SimName.Length; } return length; } } /// Default constructor public RegionInfoBlock() { } /// Constructor for building the block from a byte array public RegionInfoBlock(byte[] bytes, ref int i) { int length; try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); BillableFactor = BitConverter.ToSingle(bytes, i); i += 4; RedirectGridX = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RedirectGridY = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; PricePerMeter = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RegionFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ParentEstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(BillableFactor); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(RedirectGridX % 256); bytes[i++] = (byte)((RedirectGridX >> 8) % 256); bytes[i++] = (byte)((RedirectGridX >> 16) % 256); bytes[i++] = (byte)((RedirectGridX >> 24) % 256); bytes[i++] = (byte)(RedirectGridY % 256); bytes[i++] = (byte)((RedirectGridY >> 8) % 256); bytes[i++] = (byte)((RedirectGridY >> 16) % 256); bytes[i++] = (byte)((RedirectGridY >> 24) % 256); if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; bytes[i++] = (byte)(PricePerMeter % 256); bytes[i++] = (byte)((PricePerMeter >> 8) % 256); bytes[i++] = (byte)((PricePerMeter >> 16) % 256); bytes[i++] = (byte)((PricePerMeter >> 24) % 256); bytes[i++] = (byte)(RegionFlags % 256); bytes[i++] = (byte)((RegionFlags >> 8) % 256); bytes[i++] = (byte)((RegionFlags >> 16) % 256); bytes[i++] = (byte)((RegionFlags >> 24) % 256); bytes[i++] = (byte)(ParentEstateID % 256); bytes[i++] = (byte)((ParentEstateID >> 8) % 256); bytes[i++] = (byte)((ParentEstateID >> 16) % 256); bytes[i++] = (byte)((ParentEstateID >> 24) % 256); bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionInfo --\n"; output += "BillableFactor: " + BillableFactor.ToString() + "\n"; output += "RedirectGridX: " + RedirectGridX.ToString() + "\n"; output += "RedirectGridY: " + RedirectGridY.ToString() + "\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "PricePerMeter: " + PricePerMeter.ToString() + "\n"; output += "RegionFlags: " + RegionFlags.ToString() + "\n"; output += "ParentEstateID: " + ParentEstateID.ToString() + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GodUpdateRegionInfo public override PacketType Type { get { return PacketType.GodUpdateRegionInfo; } } /// RegionInfo block public RegionInfoBlock RegionInfo; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GodUpdateRegionInfoPacket() { Header = new LowHeader(); Header.ID = 184; Header.Reliable = true; Header.Zerocoded = true; RegionInfo = new RegionInfoBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GodUpdateRegionInfoPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); RegionInfo = new RegionInfoBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GodUpdateRegionInfoPacket(Header head, byte[] bytes, ref int i) { Header = head; RegionInfo = new RegionInfoBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += RegionInfo.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); RegionInfo.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GodUpdateRegionInfo ---\n"; output += RegionInfo.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// NearestLandingRegionRequest packet public class NearestLandingRegionRequestPacket : Packet { /// RequestingRegionData block public class RequestingRegionDataBlock { /// RegionHandle field public ulong RegionHandle; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public RequestingRegionDataBlock() { } /// Constructor for building the block from a byte array public RequestingRegionDataBlock(byte[] bytes, ref int i) { try { RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RequestingRegionData --\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.NearestLandingRegionRequest public override PacketType Type { get { return PacketType.NearestLandingRegionRequest; } } /// RequestingRegionData block public RequestingRegionDataBlock RequestingRegionData; /// Default constructor public NearestLandingRegionRequestPacket() { Header = new LowHeader(); Header.ID = 185; Header.Reliable = true; RequestingRegionData = new RequestingRegionDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public NearestLandingRegionRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); RequestingRegionData = new RequestingRegionDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public NearestLandingRegionRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; RequestingRegionData = new RequestingRegionDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += RequestingRegionData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); RequestingRegionData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- NearestLandingRegionRequest ---\n"; output += RequestingRegionData.ToString() + "\n"; return output; } } /// NearestLandingRegionReply packet public class NearestLandingRegionReplyPacket : Packet { /// LandingRegionData block public class LandingRegionDataBlock { /// RegionHandle field public ulong RegionHandle; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public LandingRegionDataBlock() { } /// Constructor for building the block from a byte array public LandingRegionDataBlock(byte[] bytes, ref int i) { try { RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- LandingRegionData --\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.NearestLandingRegionReply public override PacketType Type { get { return PacketType.NearestLandingRegionReply; } } /// LandingRegionData block public LandingRegionDataBlock LandingRegionData; /// Default constructor public NearestLandingRegionReplyPacket() { Header = new LowHeader(); Header.ID = 186; Header.Reliable = true; LandingRegionData = new LandingRegionDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public NearestLandingRegionReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); LandingRegionData = new LandingRegionDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public NearestLandingRegionReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; LandingRegionData = new LandingRegionDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += LandingRegionData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); LandingRegionData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- NearestLandingRegionReply ---\n"; output += LandingRegionData.ToString() + "\n"; return output; } } /// NearestLandingRegionUpdated packet public class NearestLandingRegionUpdatedPacket : Packet { /// RegionData block public class RegionDataBlock { /// RegionHandle field public ulong RegionHandle; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public RegionDataBlock() { } /// Constructor for building the block from a byte array public RegionDataBlock(byte[] bytes, ref int i) { try { RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionData --\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.NearestLandingRegionUpdated public override PacketType Type { get { return PacketType.NearestLandingRegionUpdated; } } /// RegionData block public RegionDataBlock RegionData; /// Default constructor public NearestLandingRegionUpdatedPacket() { Header = new LowHeader(); Header.ID = 187; Header.Reliable = true; RegionData = new RegionDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public NearestLandingRegionUpdatedPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); RegionData = new RegionDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public NearestLandingRegionUpdatedPacket(Header head, byte[] bytes, ref int i) { Header = head; RegionData = new RegionDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += RegionData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); RegionData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- NearestLandingRegionUpdated ---\n"; output += RegionData.ToString() + "\n"; return output; } } /// TeleportLandingStatusChanged packet public class TeleportLandingStatusChangedPacket : Packet { /// RegionData block public class RegionDataBlock { /// RegionHandle field public ulong RegionHandle; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public RegionDataBlock() { } /// Constructor for building the block from a byte array public RegionDataBlock(byte[] bytes, ref int i) { try { RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionData --\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TeleportLandingStatusChanged public override PacketType Type { get { return PacketType.TeleportLandingStatusChanged; } } /// RegionData block public RegionDataBlock RegionData; /// Default constructor public TeleportLandingStatusChangedPacket() { Header = new LowHeader(); Header.ID = 188; Header.Reliable = true; RegionData = new RegionDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TeleportLandingStatusChangedPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); RegionData = new RegionDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TeleportLandingStatusChangedPacket(Header head, byte[] bytes, ref int i) { Header = head; RegionData = new RegionDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += RegionData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); RegionData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TeleportLandingStatusChanged ---\n"; output += RegionData.ToString() + "\n"; return output; } } /// RegionHandshake packet public class RegionHandshakePacket : Packet { /// RegionInfo block public class RegionInfoBlock { /// BillableFactor field public float BillableFactor; /// TerrainHeightRange00 field public float TerrainHeightRange00; /// TerrainHeightRange01 field public float TerrainHeightRange01; /// TerrainHeightRange10 field public float TerrainHeightRange10; /// TerrainHeightRange11 field public float TerrainHeightRange11; private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// RegionFlags field public uint RegionFlags; /// TerrainStartHeight00 field public float TerrainStartHeight00; /// TerrainStartHeight01 field public float TerrainStartHeight01; /// TerrainStartHeight10 field public float TerrainStartHeight10; /// TerrainStartHeight11 field public float TerrainStartHeight11; /// WaterHeight field public float WaterHeight; /// SimOwner field public LLUUID SimOwner; /// SimAccess field public byte SimAccess; /// TerrainBase0 field public LLUUID TerrainBase0; /// TerrainBase1 field public LLUUID TerrainBase1; /// TerrainBase2 field public LLUUID TerrainBase2; /// TerrainBase3 field public LLUUID TerrainBase3; /// TerrainDetail0 field public LLUUID TerrainDetail0; /// TerrainDetail1 field public LLUUID TerrainDetail1; /// TerrainDetail2 field public LLUUID TerrainDetail2; /// TerrainDetail3 field public LLUUID TerrainDetail3; /// IsEstateManager field public bool IsEstateManager; /// CacheID field public LLUUID CacheID; /// Length of this block serialized in bytes public int Length { get { int length = 206; if (SimName != null) { length += 1 + SimName.Length; } return length; } } /// Default constructor public RegionInfoBlock() { } /// Constructor for building the block from a byte array public RegionInfoBlock(byte[] bytes, ref int i) { int length; try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); BillableFactor = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); TerrainHeightRange00 = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); TerrainHeightRange01 = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); TerrainHeightRange10 = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); TerrainHeightRange11 = BitConverter.ToSingle(bytes, i); i += 4; length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; RegionFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); TerrainStartHeight00 = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); TerrainStartHeight01 = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); TerrainStartHeight10 = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); TerrainStartHeight11 = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); WaterHeight = BitConverter.ToSingle(bytes, i); i += 4; SimOwner = new LLUUID(bytes, i); i += 16; SimAccess = (byte)bytes[i++]; TerrainBase0 = new LLUUID(bytes, i); i += 16; TerrainBase1 = new LLUUID(bytes, i); i += 16; TerrainBase2 = new LLUUID(bytes, i); i += 16; TerrainBase3 = new LLUUID(bytes, i); i += 16; TerrainDetail0 = new LLUUID(bytes, i); i += 16; TerrainDetail1 = new LLUUID(bytes, i); i += 16; TerrainDetail2 = new LLUUID(bytes, i); i += 16; TerrainDetail3 = new LLUUID(bytes, i); i += 16; IsEstateManager = (bytes[i++] != 0) ? (bool)true : (bool)false; CacheID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(BillableFactor); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(TerrainHeightRange00); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(TerrainHeightRange01); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(TerrainHeightRange10); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(TerrainHeightRange11); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; bytes[i++] = (byte)(RegionFlags % 256); bytes[i++] = (byte)((RegionFlags >> 8) % 256); bytes[i++] = (byte)((RegionFlags >> 16) % 256); bytes[i++] = (byte)((RegionFlags >> 24) % 256); ba = BitConverter.GetBytes(TerrainStartHeight00); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(TerrainStartHeight01); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(TerrainStartHeight10); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(TerrainStartHeight11); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(WaterHeight); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(SimOwner == null) { Console.WriteLine("Warning: SimOwner is null, in " + this.GetType()); } Array.Copy(SimOwner.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = SimAccess; if(TerrainBase0 == null) { Console.WriteLine("Warning: TerrainBase0 is null, in " + this.GetType()); } Array.Copy(TerrainBase0.GetBytes(), 0, bytes, i, 16); i += 16; if(TerrainBase1 == null) { Console.WriteLine("Warning: TerrainBase1 is null, in " + this.GetType()); } Array.Copy(TerrainBase1.GetBytes(), 0, bytes, i, 16); i += 16; if(TerrainBase2 == null) { Console.WriteLine("Warning: TerrainBase2 is null, in " + this.GetType()); } Array.Copy(TerrainBase2.GetBytes(), 0, bytes, i, 16); i += 16; if(TerrainBase3 == null) { Console.WriteLine("Warning: TerrainBase3 is null, in " + this.GetType()); } Array.Copy(TerrainBase3.GetBytes(), 0, bytes, i, 16); i += 16; if(TerrainDetail0 == null) { Console.WriteLine("Warning: TerrainDetail0 is null, in " + this.GetType()); } Array.Copy(TerrainDetail0.GetBytes(), 0, bytes, i, 16); i += 16; if(TerrainDetail1 == null) { Console.WriteLine("Warning: TerrainDetail1 is null, in " + this.GetType()); } Array.Copy(TerrainDetail1.GetBytes(), 0, bytes, i, 16); i += 16; if(TerrainDetail2 == null) { Console.WriteLine("Warning: TerrainDetail2 is null, in " + this.GetType()); } Array.Copy(TerrainDetail2.GetBytes(), 0, bytes, i, 16); i += 16; if(TerrainDetail3 == null) { Console.WriteLine("Warning: TerrainDetail3 is null, in " + this.GetType()); } Array.Copy(TerrainDetail3.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((IsEstateManager) ? 1 : 0); if(CacheID == null) { Console.WriteLine("Warning: CacheID is null, in " + this.GetType()); } Array.Copy(CacheID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionInfo --\n"; output += "BillableFactor: " + BillableFactor.ToString() + "\n"; output += "TerrainHeightRange00: " + TerrainHeightRange00.ToString() + "\n"; output += "TerrainHeightRange01: " + TerrainHeightRange01.ToString() + "\n"; output += "TerrainHeightRange10: " + TerrainHeightRange10.ToString() + "\n"; output += "TerrainHeightRange11: " + TerrainHeightRange11.ToString() + "\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "RegionFlags: " + RegionFlags.ToString() + "\n"; output += "TerrainStartHeight00: " + TerrainStartHeight00.ToString() + "\n"; output += "TerrainStartHeight01: " + TerrainStartHeight01.ToString() + "\n"; output += "TerrainStartHeight10: " + TerrainStartHeight10.ToString() + "\n"; output += "TerrainStartHeight11: " + TerrainStartHeight11.ToString() + "\n"; output += "WaterHeight: " + WaterHeight.ToString() + "\n"; output += "SimOwner: " + SimOwner.ToString() + "\n"; output += "SimAccess: " + SimAccess.ToString() + "\n"; output += "TerrainBase0: " + TerrainBase0.ToString() + "\n"; output += "TerrainBase1: " + TerrainBase1.ToString() + "\n"; output += "TerrainBase2: " + TerrainBase2.ToString() + "\n"; output += "TerrainBase3: " + TerrainBase3.ToString() + "\n"; output += "TerrainDetail0: " + TerrainDetail0.ToString() + "\n"; output += "TerrainDetail1: " + TerrainDetail1.ToString() + "\n"; output += "TerrainDetail2: " + TerrainDetail2.ToString() + "\n"; output += "TerrainDetail3: " + TerrainDetail3.ToString() + "\n"; output += "IsEstateManager: " + IsEstateManager.ToString() + "\n"; output += "CacheID: " + CacheID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RegionHandshake public override PacketType Type { get { return PacketType.RegionHandshake; } } /// RegionInfo block public RegionInfoBlock RegionInfo; /// Default constructor public RegionHandshakePacket() { Header = new LowHeader(); Header.ID = 189; Header.Reliable = true; Header.Zerocoded = true; RegionInfo = new RegionInfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RegionHandshakePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); RegionInfo = new RegionInfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RegionHandshakePacket(Header head, byte[] bytes, ref int i) { Header = head; RegionInfo = new RegionInfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += RegionInfo.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); RegionInfo.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RegionHandshake ---\n"; output += RegionInfo.ToString() + "\n"; return output; } } /// RegionHandshakeReply packet public class RegionHandshakeReplyPacket : Packet { /// RegionInfo block public class RegionInfoBlock { /// Flags field public uint Flags; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public RegionInfoBlock() { } /// Constructor for building the block from a byte array public RegionInfoBlock(byte[] bytes, ref int i) { try { Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionInfo --\n"; output += "Flags: " + Flags.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RegionHandshakeReply public override PacketType Type { get { return PacketType.RegionHandshakeReply; } } /// RegionInfo block public RegionInfoBlock RegionInfo; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RegionHandshakeReplyPacket() { Header = new LowHeader(); Header.ID = 190; Header.Reliable = true; Header.Zerocoded = true; RegionInfo = new RegionInfoBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RegionHandshakeReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); RegionInfo = new RegionInfoBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RegionHandshakeReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; RegionInfo = new RegionInfoBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += RegionInfo.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); RegionInfo.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RegionHandshakeReply ---\n"; output += RegionInfo.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// SimulatorViewerTimeMessage packet public class SimulatorViewerTimeMessagePacket : Packet { /// TimeInfo block public class TimeInfoBlock { /// SecPerDay field public uint SecPerDay; /// UsecSinceStart field public ulong UsecSinceStart; /// SecPerYear field public uint SecPerYear; /// SunAngVelocity field public LLVector3 SunAngVelocity; /// SunPhase field public float SunPhase; /// SunDirection field public LLVector3 SunDirection; /// Length of this block serialized in bytes public int Length { get { return 44; } } /// Default constructor public TimeInfoBlock() { } /// Constructor for building the block from a byte array public TimeInfoBlock(byte[] bytes, ref int i) { try { SecPerDay = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); UsecSinceStart = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); SecPerYear = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SunAngVelocity = new LLVector3(bytes, i); i += 12; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); SunPhase = BitConverter.ToSingle(bytes, i); i += 4; SunDirection = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = (byte)(SecPerDay % 256); bytes[i++] = (byte)((SecPerDay >> 8) % 256); bytes[i++] = (byte)((SecPerDay >> 16) % 256); bytes[i++] = (byte)((SecPerDay >> 24) % 256); bytes[i++] = (byte)(UsecSinceStart % 256); bytes[i++] = (byte)((UsecSinceStart >> 8) % 256); bytes[i++] = (byte)((UsecSinceStart >> 16) % 256); bytes[i++] = (byte)((UsecSinceStart >> 24) % 256); bytes[i++] = (byte)((UsecSinceStart >> 32) % 256); bytes[i++] = (byte)((UsecSinceStart >> 40) % 256); bytes[i++] = (byte)((UsecSinceStart >> 48) % 256); bytes[i++] = (byte)((UsecSinceStart >> 56) % 256); bytes[i++] = (byte)(SecPerYear % 256); bytes[i++] = (byte)((SecPerYear >> 8) % 256); bytes[i++] = (byte)((SecPerYear >> 16) % 256); bytes[i++] = (byte)((SecPerYear >> 24) % 256); if(SunAngVelocity == null) { Console.WriteLine("Warning: SunAngVelocity is null, in " + this.GetType()); } Array.Copy(SunAngVelocity.GetBytes(), 0, bytes, i, 12); i += 12; ba = BitConverter.GetBytes(SunPhase); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(SunDirection == null) { Console.WriteLine("Warning: SunDirection is null, in " + this.GetType()); } Array.Copy(SunDirection.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TimeInfo --\n"; output += "SecPerDay: " + SecPerDay.ToString() + "\n"; output += "UsecSinceStart: " + UsecSinceStart.ToString() + "\n"; output += "SecPerYear: " + SecPerYear.ToString() + "\n"; output += "SunAngVelocity: " + SunAngVelocity.ToString() + "\n"; output += "SunPhase: " + SunPhase.ToString() + "\n"; output += "SunDirection: " + SunDirection.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SimulatorViewerTimeMessage public override PacketType Type { get { return PacketType.SimulatorViewerTimeMessage; } } /// TimeInfo block public TimeInfoBlock TimeInfo; /// Default constructor public SimulatorViewerTimeMessagePacket() { Header = new LowHeader(); Header.ID = 191; Header.Reliable = true; TimeInfo = new TimeInfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SimulatorViewerTimeMessagePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TimeInfo = new TimeInfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SimulatorViewerTimeMessagePacket(Header head, byte[] bytes, ref int i) { Header = head; TimeInfo = new TimeInfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TimeInfo.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TimeInfo.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SimulatorViewerTimeMessage ---\n"; output += TimeInfo.ToString() + "\n"; return output; } } /// EnableSimulator packet public class EnableSimulatorPacket : Packet { /// SimulatorInfo block public class SimulatorInfoBlock { /// IP field public uint IP; /// Port field public ushort Port; /// Handle field public ulong Handle; /// Length of this block serialized in bytes public int Length { get { return 14; } } /// Default constructor public SimulatorInfoBlock() { } /// Constructor for building the block from a byte array public SimulatorInfoBlock(byte[] bytes, ref int i) { try { IP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Port = (ushort)((bytes[i++] << 8) + bytes[i++]); Handle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(IP % 256); bytes[i++] = (byte)((IP >> 8) % 256); bytes[i++] = (byte)((IP >> 16) % 256); bytes[i++] = (byte)((IP >> 24) % 256); bytes[i++] = (byte)((Port >> 8) % 256); bytes[i++] = (byte)(Port % 256); bytes[i++] = (byte)(Handle % 256); bytes[i++] = (byte)((Handle >> 8) % 256); bytes[i++] = (byte)((Handle >> 16) % 256); bytes[i++] = (byte)((Handle >> 24) % 256); bytes[i++] = (byte)((Handle >> 32) % 256); bytes[i++] = (byte)((Handle >> 40) % 256); bytes[i++] = (byte)((Handle >> 48) % 256); bytes[i++] = (byte)((Handle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- SimulatorInfo --\n"; output += "IP: " + IP.ToString() + "\n"; output += "Port: " + Port.ToString() + "\n"; output += "Handle: " + Handle.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.EnableSimulator public override PacketType Type { get { return PacketType.EnableSimulator; } } /// SimulatorInfo block public SimulatorInfoBlock SimulatorInfo; /// Default constructor public EnableSimulatorPacket() { Header = new LowHeader(); Header.ID = 192; Header.Reliable = true; SimulatorInfo = new SimulatorInfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public EnableSimulatorPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); SimulatorInfo = new SimulatorInfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public EnableSimulatorPacket(Header head, byte[] bytes, ref int i) { Header = head; SimulatorInfo = new SimulatorInfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += SimulatorInfo.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); SimulatorInfo.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- EnableSimulator ---\n"; output += SimulatorInfo.ToString() + "\n"; return output; } } /// DisableSimulator packet public class DisableSimulatorPacket : Packet { private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DisableSimulator public override PacketType Type { get { return PacketType.DisableSimulator; } } /// Default constructor public DisableSimulatorPacket() { Header = new LowHeader(); Header.ID = 193; Header.Reliable = true; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DisableSimulatorPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); } /// Constructor that takes a byte array and a prebuilt header public DisableSimulatorPacket(Header head, byte[] bytes, ref int i) { Header = head; } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DisableSimulator ---\n"; return output; } } /// TransferRequest packet public class TransferRequestPacket : Packet { /// TransferInfo block public class TransferInfoBlock { /// TransferID field public LLUUID TransferID; private byte[] _params; /// Params field public byte[] Params { get { return _params; } set { if (value == null) { _params = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _params = new byte[value.Length]; Array.Copy(value, _params, value.Length); } } } /// ChannelType field public int ChannelType; /// SourceType field public int SourceType; /// Priority field public float Priority; /// Length of this block serialized in bytes public int Length { get { int length = 28; if (Params != null) { length += 2 + Params.Length; } return length; } } /// Default constructor public TransferInfoBlock() { } /// Constructor for building the block from a byte array public TransferInfoBlock(byte[] bytes, ref int i) { int length; try { TransferID = new LLUUID(bytes, i); i += 16; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _params = new byte[length]; Array.Copy(bytes, i, _params, 0, length); i += length; ChannelType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SourceType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Priority = BitConverter.ToSingle(bytes, i); i += 4; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; if(TransferID == null) { Console.WriteLine("Warning: TransferID is null, in " + this.GetType()); } Array.Copy(TransferID.GetBytes(), 0, bytes, i, 16); i += 16; if(Params == null) { Console.WriteLine("Warning: Params is null, in " + this.GetType()); } bytes[i++] = (byte)(Params.Length % 256); bytes[i++] = (byte)((Params.Length >> 8) % 256); Array.Copy(Params, 0, bytes, i, Params.Length); i += Params.Length; bytes[i++] = (byte)(ChannelType % 256); bytes[i++] = (byte)((ChannelType >> 8) % 256); bytes[i++] = (byte)((ChannelType >> 16) % 256); bytes[i++] = (byte)((ChannelType >> 24) % 256); bytes[i++] = (byte)(SourceType % 256); bytes[i++] = (byte)((SourceType >> 8) % 256); bytes[i++] = (byte)((SourceType >> 16) % 256); bytes[i++] = (byte)((SourceType >> 24) % 256); ba = BitConverter.GetBytes(Priority); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TransferInfo --\n"; output += "TransferID: " + TransferID.ToString() + "\n"; output += Helpers.FieldToString(Params, "Params") + "\n"; output += "ChannelType: " + ChannelType.ToString() + "\n"; output += "SourceType: " + SourceType.ToString() + "\n"; output += "Priority: " + Priority.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TransferRequest public override PacketType Type { get { return PacketType.TransferRequest; } } /// TransferInfo block public TransferInfoBlock TransferInfo; /// Default constructor public TransferRequestPacket() { Header = new LowHeader(); Header.ID = 194; Header.Reliable = true; Header.Zerocoded = true; TransferInfo = new TransferInfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TransferRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TransferInfo = new TransferInfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TransferRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; TransferInfo = new TransferInfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TransferInfo.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TransferInfo.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TransferRequest ---\n"; output += TransferInfo.ToString() + "\n"; return output; } } /// TransferInfo packet public class TransferInfoPacket : Packet { /// TransferInfo block public class TransferInfoBlock { /// TransferID field public LLUUID TransferID; /// Size field public int Size; /// ChannelType field public int ChannelType; /// TargetType field public int TargetType; /// Status field public int Status; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public TransferInfoBlock() { } /// Constructor for building the block from a byte array public TransferInfoBlock(byte[] bytes, ref int i) { try { TransferID = new LLUUID(bytes, i); i += 16; Size = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ChannelType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TargetType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Status = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TransferID == null) { Console.WriteLine("Warning: TransferID is null, in " + this.GetType()); } Array.Copy(TransferID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Size % 256); bytes[i++] = (byte)((Size >> 8) % 256); bytes[i++] = (byte)((Size >> 16) % 256); bytes[i++] = (byte)((Size >> 24) % 256); bytes[i++] = (byte)(ChannelType % 256); bytes[i++] = (byte)((ChannelType >> 8) % 256); bytes[i++] = (byte)((ChannelType >> 16) % 256); bytes[i++] = (byte)((ChannelType >> 24) % 256); bytes[i++] = (byte)(TargetType % 256); bytes[i++] = (byte)((TargetType >> 8) % 256); bytes[i++] = (byte)((TargetType >> 16) % 256); bytes[i++] = (byte)((TargetType >> 24) % 256); bytes[i++] = (byte)(Status % 256); bytes[i++] = (byte)((Status >> 8) % 256); bytes[i++] = (byte)((Status >> 16) % 256); bytes[i++] = (byte)((Status >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TransferInfo --\n"; output += "TransferID: " + TransferID.ToString() + "\n"; output += "Size: " + Size.ToString() + "\n"; output += "ChannelType: " + ChannelType.ToString() + "\n"; output += "TargetType: " + TargetType.ToString() + "\n"; output += "Status: " + Status.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TransferInfo public override PacketType Type { get { return PacketType.TransferInfo; } } /// TransferInfo block public TransferInfoBlock TransferInfo; /// Default constructor public TransferInfoPacket() { Header = new LowHeader(); Header.ID = 195; Header.Reliable = true; Header.Zerocoded = true; TransferInfo = new TransferInfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TransferInfoPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TransferInfo = new TransferInfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TransferInfoPacket(Header head, byte[] bytes, ref int i) { Header = head; TransferInfo = new TransferInfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TransferInfo.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TransferInfo.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TransferInfo ---\n"; output += TransferInfo.ToString() + "\n"; return output; } } /// TransferAbort packet public class TransferAbortPacket : Packet { /// TransferInfo block public class TransferInfoBlock { /// TransferID field public LLUUID TransferID; /// ChannelType field public int ChannelType; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public TransferInfoBlock() { } /// Constructor for building the block from a byte array public TransferInfoBlock(byte[] bytes, ref int i) { try { TransferID = new LLUUID(bytes, i); i += 16; ChannelType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TransferID == null) { Console.WriteLine("Warning: TransferID is null, in " + this.GetType()); } Array.Copy(TransferID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(ChannelType % 256); bytes[i++] = (byte)((ChannelType >> 8) % 256); bytes[i++] = (byte)((ChannelType >> 16) % 256); bytes[i++] = (byte)((ChannelType >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TransferInfo --\n"; output += "TransferID: " + TransferID.ToString() + "\n"; output += "ChannelType: " + ChannelType.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TransferAbort public override PacketType Type { get { return PacketType.TransferAbort; } } /// TransferInfo block public TransferInfoBlock TransferInfo; /// Default constructor public TransferAbortPacket() { Header = new LowHeader(); Header.ID = 196; Header.Reliable = true; Header.Zerocoded = true; TransferInfo = new TransferInfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TransferAbortPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TransferInfo = new TransferInfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TransferAbortPacket(Header head, byte[] bytes, ref int i) { Header = head; TransferInfo = new TransferInfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TransferInfo.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TransferInfo.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TransferAbort ---\n"; output += TransferInfo.ToString() + "\n"; return output; } } /// TransferPriority packet public class TransferPriorityPacket : Packet { /// TransferInfo block public class TransferInfoBlock { /// TransferID field public LLUUID TransferID; /// ChannelType field public int ChannelType; /// Priority field public float Priority; /// Length of this block serialized in bytes public int Length { get { return 24; } } /// Default constructor public TransferInfoBlock() { } /// Constructor for building the block from a byte array public TransferInfoBlock(byte[] bytes, ref int i) { try { TransferID = new LLUUID(bytes, i); i += 16; ChannelType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Priority = BitConverter.ToSingle(bytes, i); i += 4; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; if(TransferID == null) { Console.WriteLine("Warning: TransferID is null, in " + this.GetType()); } Array.Copy(TransferID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(ChannelType % 256); bytes[i++] = (byte)((ChannelType >> 8) % 256); bytes[i++] = (byte)((ChannelType >> 16) % 256); bytes[i++] = (byte)((ChannelType >> 24) % 256); ba = BitConverter.GetBytes(Priority); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TransferInfo --\n"; output += "TransferID: " + TransferID.ToString() + "\n"; output += "ChannelType: " + ChannelType.ToString() + "\n"; output += "Priority: " + Priority.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TransferPriority public override PacketType Type { get { return PacketType.TransferPriority; } } /// TransferInfo block public TransferInfoBlock TransferInfo; /// Default constructor public TransferPriorityPacket() { Header = new LowHeader(); Header.ID = 197; Header.Reliable = true; Header.Zerocoded = true; TransferInfo = new TransferInfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TransferPriorityPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TransferInfo = new TransferInfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TransferPriorityPacket(Header head, byte[] bytes, ref int i) { Header = head; TransferInfo = new TransferInfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TransferInfo.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TransferInfo.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TransferPriority ---\n"; output += TransferInfo.ToString() + "\n"; return output; } } /// RequestXfer packet public class RequestXferPacket : Packet { /// XferID block public class XferIDBlock { /// ID field public ulong ID; /// UseBigPackets field public bool UseBigPackets; /// DeleteOnCompletion field public bool DeleteOnCompletion; /// FilePath field public byte FilePath; private byte[] _filename; /// Filename field public byte[] Filename { get { return _filename; } set { if (value == null) { _filename = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _filename = new byte[value.Length]; Array.Copy(value, _filename, value.Length); } } } /// VFileID field public LLUUID VFileID; /// VFileType field public short VFileType; /// Length of this block serialized in bytes public int Length { get { int length = 29; if (Filename != null) { length += 1 + Filename.Length; } return length; } } /// Default constructor public XferIDBlock() { } /// Constructor for building the block from a byte array public XferIDBlock(byte[] bytes, ref int i) { int length; try { ID = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); UseBigPackets = (bytes[i++] != 0) ? (bool)true : (bool)false; DeleteOnCompletion = (bytes[i++] != 0) ? (bool)true : (bool)false; FilePath = (byte)bytes[i++]; length = (ushort)bytes[i++]; _filename = new byte[length]; Array.Copy(bytes, i, _filename, 0, length); i += length; VFileID = new LLUUID(bytes, i); i += 16; VFileType = (short)(bytes[i++] + (bytes[i++] << 8)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ID % 256); bytes[i++] = (byte)((ID >> 8) % 256); bytes[i++] = (byte)((ID >> 16) % 256); bytes[i++] = (byte)((ID >> 24) % 256); bytes[i++] = (byte)((ID >> 32) % 256); bytes[i++] = (byte)((ID >> 40) % 256); bytes[i++] = (byte)((ID >> 48) % 256); bytes[i++] = (byte)((ID >> 56) % 256); bytes[i++] = (byte)((UseBigPackets) ? 1 : 0); bytes[i++] = (byte)((DeleteOnCompletion) ? 1 : 0); bytes[i++] = FilePath; if(Filename == null) { Console.WriteLine("Warning: Filename is null, in " + this.GetType()); } bytes[i++] = (byte)Filename.Length; Array.Copy(Filename, 0, bytes, i, Filename.Length); i += Filename.Length; if(VFileID == null) { Console.WriteLine("Warning: VFileID is null, in " + this.GetType()); } Array.Copy(VFileID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(VFileType % 256); bytes[i++] = (byte)((VFileType >> 8) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- XferID --\n"; output += "ID: " + ID.ToString() + "\n"; output += "UseBigPackets: " + UseBigPackets.ToString() + "\n"; output += "DeleteOnCompletion: " + DeleteOnCompletion.ToString() + "\n"; output += "FilePath: " + FilePath.ToString() + "\n"; output += Helpers.FieldToString(Filename, "Filename") + "\n"; output += "VFileID: " + VFileID.ToString() + "\n"; output += "VFileType: " + VFileType.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RequestXfer public override PacketType Type { get { return PacketType.RequestXfer; } } /// XferID block public XferIDBlock XferID; /// Default constructor public RequestXferPacket() { Header = new LowHeader(); Header.ID = 198; Header.Reliable = true; Header.Zerocoded = true; XferID = new XferIDBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RequestXferPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); XferID = new XferIDBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RequestXferPacket(Header head, byte[] bytes, ref int i) { Header = head; XferID = new XferIDBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += XferID.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); XferID.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RequestXfer ---\n"; output += XferID.ToString() + "\n"; return output; } } /// AbortXfer packet public class AbortXferPacket : Packet { /// XferID block public class XferIDBlock { /// ID field public ulong ID; /// Result field public int Result; /// Length of this block serialized in bytes public int Length { get { return 12; } } /// Default constructor public XferIDBlock() { } /// Constructor for building the block from a byte array public XferIDBlock(byte[] bytes, ref int i) { try { ID = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); Result = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ID % 256); bytes[i++] = (byte)((ID >> 8) % 256); bytes[i++] = (byte)((ID >> 16) % 256); bytes[i++] = (byte)((ID >> 24) % 256); bytes[i++] = (byte)((ID >> 32) % 256); bytes[i++] = (byte)((ID >> 40) % 256); bytes[i++] = (byte)((ID >> 48) % 256); bytes[i++] = (byte)((ID >> 56) % 256); bytes[i++] = (byte)(Result % 256); bytes[i++] = (byte)((Result >> 8) % 256); bytes[i++] = (byte)((Result >> 16) % 256); bytes[i++] = (byte)((Result >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- XferID --\n"; output += "ID: " + ID.ToString() + "\n"; output += "Result: " + Result.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AbortXfer public override PacketType Type { get { return PacketType.AbortXfer; } } /// XferID block public XferIDBlock XferID; /// Default constructor public AbortXferPacket() { Header = new LowHeader(); Header.ID = 199; Header.Reliable = true; XferID = new XferIDBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AbortXferPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); XferID = new XferIDBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AbortXferPacket(Header head, byte[] bytes, ref int i) { Header = head; XferID = new XferIDBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += XferID.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); XferID.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AbortXfer ---\n"; output += XferID.ToString() + "\n"; return output; } } /// RequestAvatarInfo packet public class RequestAvatarInfoPacket : Packet { /// DataBlock block public class DataBlockBlock { /// FullID field public LLUUID FullID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { try { FullID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(FullID == null) { Console.WriteLine("Warning: FullID is null, in " + this.GetType()); } Array.Copy(FullID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "FullID: " + FullID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RequestAvatarInfo public override PacketType Type { get { return PacketType.RequestAvatarInfo; } } /// DataBlock block public DataBlockBlock DataBlock; /// Default constructor public RequestAvatarInfoPacket() { Header = new LowHeader(); Header.ID = 200; Header.Reliable = true; DataBlock = new DataBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RequestAvatarInfoPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); DataBlock = new DataBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RequestAvatarInfoPacket(Header head, byte[] bytes, ref int i) { Header = head; DataBlock = new DataBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += DataBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RequestAvatarInfo ---\n"; output += DataBlock.ToString() + "\n"; return output; } } /// AvatarAppearance packet public class AvatarAppearancePacket : Packet { /// VisualParam block public class VisualParamBlock { /// ParamValue field public byte ParamValue; /// Length of this block serialized in bytes public int Length { get { return 1; } } /// Default constructor public VisualParamBlock() { } /// Constructor for building the block from a byte array public VisualParamBlock(byte[] bytes, ref int i) { try { ParamValue = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = ParamValue; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- VisualParam --\n"; output += "ParamValue: " + ParamValue.ToString() + "\n"; output = output.Trim(); return output; } } /// ObjectData block public class ObjectDataBlock { private byte[] _textureentry; /// TextureEntry field public byte[] TextureEntry { get { return _textureentry; } set { if (value == null) { _textureentry = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _textureentry = new byte[value.Length]; Array.Copy(value, _textureentry, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (TextureEntry != null) { length += 2 + TextureEntry.Length; } return length; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _textureentry = new byte[length]; Array.Copy(bytes, i, _textureentry, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TextureEntry == null) { Console.WriteLine("Warning: TextureEntry is null, in " + this.GetType()); } bytes[i++] = (byte)(TextureEntry.Length % 256); bytes[i++] = (byte)((TextureEntry.Length >> 8) % 256); Array.Copy(TextureEntry, 0, bytes, i, TextureEntry.Length); i += TextureEntry.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += Helpers.FieldToString(TextureEntry, "TextureEntry") + "\n"; output = output.Trim(); return output; } } /// Sender block public class SenderBlock { /// ID field public LLUUID ID; /// IsTrial field public bool IsTrial; /// Length of this block serialized in bytes public int Length { get { return 17; } } /// Default constructor public SenderBlock() { } /// Constructor for building the block from a byte array public SenderBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; IsTrial = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((IsTrial) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Sender --\n"; output += "ID: " + ID.ToString() + "\n"; output += "IsTrial: " + IsTrial.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AvatarAppearance public override PacketType Type { get { return PacketType.AvatarAppearance; } } /// VisualParam block public VisualParamBlock[] VisualParam; /// ObjectData block public ObjectDataBlock ObjectData; /// Sender block public SenderBlock Sender; /// Default constructor public AvatarAppearancePacket() { Header = new LowHeader(); Header.ID = 201; Header.Reliable = true; Header.Zerocoded = true; VisualParam = new VisualParamBlock[0]; ObjectData = new ObjectDataBlock(); Sender = new SenderBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AvatarAppearancePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; VisualParam = new VisualParamBlock[count]; for (int j = 0; j < count; j++) { VisualParam[j] = new VisualParamBlock(bytes, ref i); } ObjectData = new ObjectDataBlock(bytes, ref i); Sender = new SenderBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AvatarAppearancePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; VisualParam = new VisualParamBlock[count]; for (int j = 0; j < count; j++) { VisualParam[j] = new VisualParamBlock(bytes, ref i); } ObjectData = new ObjectDataBlock(bytes, ref i); Sender = new SenderBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ObjectData.Length; length += Sender.Length;; length++; for (int j = 0; j < VisualParam.Length; j++) { length += VisualParam[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)VisualParam.Length; for (int j = 0; j < VisualParam.Length; j++) { VisualParam[j].ToBytes(bytes, ref i); } ObjectData.ToBytes(bytes, ref i); Sender.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AvatarAppearance ---\n"; for (int j = 0; j < VisualParam.Length; j++) { output += VisualParam[j].ToString() + "\n"; } output += ObjectData.ToString() + "\n"; output += Sender.ToString() + "\n"; return output; } } /// SetFollowCamProperties packet public class SetFollowCamPropertiesPacket : Packet { /// CameraProperty block public class CameraPropertyBlock { /// Type field public int Type; /// Value field public float Value; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public CameraPropertyBlock() { } /// Constructor for building the block from a byte array public CameraPropertyBlock(byte[] bytes, ref int i) { try { Type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Value = BitConverter.ToSingle(bytes, i); i += 4; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = (byte)(Type % 256); bytes[i++] = (byte)((Type >> 8) % 256); bytes[i++] = (byte)((Type >> 16) % 256); bytes[i++] = (byte)((Type >> 24) % 256); ba = BitConverter.GetBytes(Value); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- CameraProperty --\n"; output += "Type: " + Type.ToString() + "\n"; output += "Value: " + Value.ToString() + "\n"; output = output.Trim(); return output; } } /// ObjectData block public class ObjectDataBlock { /// ObjectID field public LLUUID ObjectID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SetFollowCamProperties public override PacketType Type { get { return PacketType.SetFollowCamProperties; } } /// CameraProperty block public CameraPropertyBlock[] CameraProperty; /// ObjectData block public ObjectDataBlock ObjectData; /// Default constructor public SetFollowCamPropertiesPacket() { Header = new LowHeader(); Header.ID = 202; Header.Reliable = true; CameraProperty = new CameraPropertyBlock[0]; ObjectData = new ObjectDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SetFollowCamPropertiesPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; CameraProperty = new CameraPropertyBlock[count]; for (int j = 0; j < count; j++) { CameraProperty[j] = new CameraPropertyBlock(bytes, ref i); } ObjectData = new ObjectDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SetFollowCamPropertiesPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; CameraProperty = new CameraPropertyBlock[count]; for (int j = 0; j < count; j++) { CameraProperty[j] = new CameraPropertyBlock(bytes, ref i); } ObjectData = new ObjectDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ObjectData.Length;; length++; for (int j = 0; j < CameraProperty.Length; j++) { length += CameraProperty[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)CameraProperty.Length; for (int j = 0; j < CameraProperty.Length; j++) { CameraProperty[j].ToBytes(bytes, ref i); } ObjectData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SetFollowCamProperties ---\n"; for (int j = 0; j < CameraProperty.Length; j++) { output += CameraProperty[j].ToString() + "\n"; } output += ObjectData.ToString() + "\n"; return output; } } /// ClearFollowCamProperties packet public class ClearFollowCamPropertiesPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectID field public LLUUID ObjectID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ClearFollowCamProperties public override PacketType Type { get { return PacketType.ClearFollowCamProperties; } } /// ObjectData block public ObjectDataBlock ObjectData; /// Default constructor public ClearFollowCamPropertiesPacket() { Header = new LowHeader(); Header.ID = 203; Header.Reliable = true; ObjectData = new ObjectDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ClearFollowCamPropertiesPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ObjectData = new ObjectDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ClearFollowCamPropertiesPacket(Header head, byte[] bytes, ref int i) { Header = head; ObjectData = new ObjectDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ObjectData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ObjectData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ClearFollowCamProperties ---\n"; output += ObjectData.ToString() + "\n"; return output; } } /// RequestPayPrice packet public class RequestPayPricePacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectID field public LLUUID ObjectID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RequestPayPrice public override PacketType Type { get { return PacketType.RequestPayPrice; } } /// ObjectData block public ObjectDataBlock ObjectData; /// Default constructor public RequestPayPricePacket() { Header = new LowHeader(); Header.ID = 204; Header.Reliable = true; ObjectData = new ObjectDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RequestPayPricePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ObjectData = new ObjectDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RequestPayPricePacket(Header head, byte[] bytes, ref int i) { Header = head; ObjectData = new ObjectDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ObjectData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ObjectData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RequestPayPrice ---\n"; output += ObjectData.ToString() + "\n"; return output; } } /// PayPriceReply packet public class PayPriceReplyPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectID field public LLUUID ObjectID; /// DefaultPayPrice field public int DefaultPayPrice; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; DefaultPayPrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(DefaultPayPrice % 256); bytes[i++] = (byte)((DefaultPayPrice >> 8) % 256); bytes[i++] = (byte)((DefaultPayPrice >> 16) % 256); bytes[i++] = (byte)((DefaultPayPrice >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "DefaultPayPrice: " + DefaultPayPrice.ToString() + "\n"; output = output.Trim(); return output; } } /// ButtonData block public class ButtonDataBlock { /// PayButton field public int PayButton; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public ButtonDataBlock() { } /// Constructor for building the block from a byte array public ButtonDataBlock(byte[] bytes, ref int i) { try { PayButton = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(PayButton % 256); bytes[i++] = (byte)((PayButton >> 8) % 256); bytes[i++] = (byte)((PayButton >> 16) % 256); bytes[i++] = (byte)((PayButton >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ButtonData --\n"; output += "PayButton: " + PayButton.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.PayPriceReply public override PacketType Type { get { return PacketType.PayPriceReply; } } /// ObjectData block public ObjectDataBlock ObjectData; /// ButtonData block public ButtonDataBlock[] ButtonData; /// Default constructor public PayPriceReplyPacket() { Header = new LowHeader(); Header.ID = 205; Header.Reliable = true; ObjectData = new ObjectDataBlock(); ButtonData = new ButtonDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public PayPriceReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ObjectData = new ObjectDataBlock(bytes, ref i); int count = (int)bytes[i++]; ButtonData = new ButtonDataBlock[count]; for (int j = 0; j < count; j++) { ButtonData[j] = new ButtonDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public PayPriceReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; ObjectData = new ObjectDataBlock(bytes, ref i); int count = (int)bytes[i++]; ButtonData = new ButtonDataBlock[count]; for (int j = 0; j < count; j++) { ButtonData[j] = new ButtonDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ObjectData.Length;; length++; for (int j = 0; j < ButtonData.Length; j++) { length += ButtonData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ObjectData.ToBytes(bytes, ref i); bytes[i++] = (byte)ButtonData.Length; for (int j = 0; j < ButtonData.Length; j++) { ButtonData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- PayPriceReply ---\n"; output += ObjectData.ToString() + "\n"; for (int j = 0; j < ButtonData.Length; j++) { output += ButtonData[j].ToString() + "\n"; } return output; } } /// KickUser packet public class KickUserPacket : Packet { /// TargetBlock block public class TargetBlockBlock { /// TargetIP field public uint TargetIP; /// TargetPort field public ushort TargetPort; /// Length of this block serialized in bytes public int Length { get { return 6; } } /// Default constructor public TargetBlockBlock() { } /// Constructor for building the block from a byte array public TargetBlockBlock(byte[] bytes, ref int i) { try { TargetIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TargetPort = (ushort)((bytes[i++] << 8) + bytes[i++]); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(TargetIP % 256); bytes[i++] = (byte)((TargetIP >> 8) % 256); bytes[i++] = (byte)((TargetIP >> 16) % 256); bytes[i++] = (byte)((TargetIP >> 24) % 256); bytes[i++] = (byte)((TargetPort >> 8) % 256); bytes[i++] = (byte)(TargetPort % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TargetBlock --\n"; output += "TargetIP: " + TargetIP.ToString() + "\n"; output += "TargetPort: " + TargetPort.ToString() + "\n"; output = output.Trim(); return output; } } /// UserInfo block public class UserInfoBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; private byte[] _reason; /// Reason field public byte[] Reason { get { return _reason; } set { if (value == null) { _reason = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _reason = new byte[value.Length]; Array.Copy(value, _reason, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 32; if (Reason != null) { length += 2 + Reason.Length; } return length; } } /// Default constructor public UserInfoBlock() { } /// Constructor for building the block from a byte array public UserInfoBlock(byte[] bytes, ref int i) { int length; try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _reason = new byte[length]; Array.Copy(bytes, i, _reason, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(Reason == null) { Console.WriteLine("Warning: Reason is null, in " + this.GetType()); } bytes[i++] = (byte)(Reason.Length % 256); bytes[i++] = (byte)((Reason.Length >> 8) % 256); Array.Copy(Reason, 0, bytes, i, Reason.Length); i += Reason.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- UserInfo --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += Helpers.FieldToString(Reason, "Reason") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.KickUser public override PacketType Type { get { return PacketType.KickUser; } } /// TargetBlock block public TargetBlockBlock TargetBlock; /// UserInfo block public UserInfoBlock UserInfo; /// Default constructor public KickUserPacket() { Header = new LowHeader(); Header.ID = 206; Header.Reliable = true; TargetBlock = new TargetBlockBlock(); UserInfo = new UserInfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public KickUserPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TargetBlock = new TargetBlockBlock(bytes, ref i); UserInfo = new UserInfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public KickUserPacket(Header head, byte[] bytes, ref int i) { Header = head; TargetBlock = new TargetBlockBlock(bytes, ref i); UserInfo = new UserInfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TargetBlock.Length; length += UserInfo.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TargetBlock.ToBytes(bytes, ref i); UserInfo.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- KickUser ---\n"; output += TargetBlock.ToString() + "\n"; output += UserInfo.ToString() + "\n"; return output; } } /// KickUserAck packet public class KickUserAckPacket : Packet { /// UserInfo block public class UserInfoBlock { /// SessionID field public LLUUID SessionID; /// Flags field public uint Flags; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public UserInfoBlock() { } /// Constructor for building the block from a byte array public UserInfoBlock(byte[] bytes, ref int i) { try { SessionID = new LLUUID(bytes, i); i += 16; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- UserInfo --\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.KickUserAck public override PacketType Type { get { return PacketType.KickUserAck; } } /// UserInfo block public UserInfoBlock UserInfo; /// Default constructor public KickUserAckPacket() { Header = new LowHeader(); Header.ID = 207; Header.Reliable = true; UserInfo = new UserInfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public KickUserAckPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); UserInfo = new UserInfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public KickUserAckPacket(Header head, byte[] bytes, ref int i) { Header = head; UserInfo = new UserInfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += UserInfo.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); UserInfo.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- KickUserAck ---\n"; output += UserInfo.ToString() + "\n"; return output; } } /// GodKickUser packet public class GodKickUserPacket : Packet { /// UserInfo block public class UserInfoBlock { /// GodSessionID field public LLUUID GodSessionID; /// AgentID field public LLUUID AgentID; private byte[] _reason; /// Reason field public byte[] Reason { get { return _reason; } set { if (value == null) { _reason = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _reason = new byte[value.Length]; Array.Copy(value, _reason, value.Length); } } } /// KickFlags field public uint KickFlags; /// GodID field public LLUUID GodID; /// Length of this block serialized in bytes public int Length { get { int length = 52; if (Reason != null) { length += 2 + Reason.Length; } return length; } } /// Default constructor public UserInfoBlock() { } /// Constructor for building the block from a byte array public UserInfoBlock(byte[] bytes, ref int i) { int length; try { GodSessionID = new LLUUID(bytes, i); i += 16; AgentID = new LLUUID(bytes, i); i += 16; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _reason = new byte[length]; Array.Copy(bytes, i, _reason, 0, length); i += length; KickFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GodID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GodSessionID == null) { Console.WriteLine("Warning: GodSessionID is null, in " + this.GetType()); } Array.Copy(GodSessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(Reason == null) { Console.WriteLine("Warning: Reason is null, in " + this.GetType()); } bytes[i++] = (byte)(Reason.Length % 256); bytes[i++] = (byte)((Reason.Length >> 8) % 256); Array.Copy(Reason, 0, bytes, i, Reason.Length); i += Reason.Length; bytes[i++] = (byte)(KickFlags % 256); bytes[i++] = (byte)((KickFlags >> 8) % 256); bytes[i++] = (byte)((KickFlags >> 16) % 256); bytes[i++] = (byte)((KickFlags >> 24) % 256); if(GodID == null) { Console.WriteLine("Warning: GodID is null, in " + this.GetType()); } Array.Copy(GodID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- UserInfo --\n"; output += "GodSessionID: " + GodSessionID.ToString() + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += Helpers.FieldToString(Reason, "Reason") + "\n"; output += "KickFlags: " + KickFlags.ToString() + "\n"; output += "GodID: " + GodID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GodKickUser public override PacketType Type { get { return PacketType.GodKickUser; } } /// UserInfo block public UserInfoBlock UserInfo; /// Default constructor public GodKickUserPacket() { Header = new LowHeader(); Header.ID = 208; Header.Reliable = true; UserInfo = new UserInfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GodKickUserPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); UserInfo = new UserInfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GodKickUserPacket(Header head, byte[] bytes, ref int i) { Header = head; UserInfo = new UserInfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += UserInfo.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); UserInfo.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GodKickUser ---\n"; output += UserInfo.ToString() + "\n"; return output; } } /// SystemKickUser packet public class SystemKickUserPacket : Packet { /// AgentInfo block public class AgentInfoBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentInfoBlock() { } /// Constructor for building the block from a byte array public AgentInfoBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentInfo --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SystemKickUser public override PacketType Type { get { return PacketType.SystemKickUser; } } /// AgentInfo block public AgentInfoBlock[] AgentInfo; /// Default constructor public SystemKickUserPacket() { Header = new LowHeader(); Header.ID = 209; Header.Reliable = true; AgentInfo = new AgentInfoBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SystemKickUserPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; AgentInfo = new AgentInfoBlock[count]; for (int j = 0; j < count; j++) { AgentInfo[j] = new AgentInfoBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public SystemKickUserPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; AgentInfo = new AgentInfoBlock[count]; for (int j = 0; j < count; j++) { AgentInfo[j] = new AgentInfoBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < AgentInfo.Length; j++) { length += AgentInfo[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)AgentInfo.Length; for (int j = 0; j < AgentInfo.Length; j++) { AgentInfo[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SystemKickUser ---\n"; for (int j = 0; j < AgentInfo.Length; j++) { output += AgentInfo[j].ToString() + "\n"; } return output; } } /// EjectUser packet public class EjectUserPacket : Packet { /// Data block public class DataBlock { /// TargetID field public LLUUID TargetID; /// Flags field public uint Flags; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { TargetID = new LLUUID(bytes, i); i += 16; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TargetID == null) { Console.WriteLine("Warning: TargetID is null, in " + this.GetType()); } Array.Copy(TargetID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "TargetID: " + TargetID.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.EjectUser public override PacketType Type { get { return PacketType.EjectUser; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public EjectUserPacket() { Header = new LowHeader(); Header.ID = 210; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public EjectUserPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public EjectUserPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- EjectUser ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// FreezeUser packet public class FreezeUserPacket : Packet { /// Data block public class DataBlock { /// TargetID field public LLUUID TargetID; /// Flags field public uint Flags; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { TargetID = new LLUUID(bytes, i); i += 16; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TargetID == null) { Console.WriteLine("Warning: TargetID is null, in " + this.GetType()); } Array.Copy(TargetID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "TargetID: " + TargetID.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.FreezeUser public override PacketType Type { get { return PacketType.FreezeUser; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public FreezeUserPacket() { Header = new LowHeader(); Header.ID = 211; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public FreezeUserPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public FreezeUserPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- FreezeUser ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// AvatarPropertiesRequest packet public class AvatarPropertiesRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// AvatarID field public LLUUID AvatarID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; AvatarID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(AvatarID == null) { Console.WriteLine("Warning: AvatarID is null, in " + this.GetType()); } Array.Copy(AvatarID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "AvatarID: " + AvatarID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AvatarPropertiesRequest public override PacketType Type { get { return PacketType.AvatarPropertiesRequest; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AvatarPropertiesRequestPacket() { Header = new LowHeader(); Header.ID = 212; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AvatarPropertiesRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AvatarPropertiesRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AvatarPropertiesRequest ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// AvatarPropertiesRequestBackend packet public class AvatarPropertiesRequestBackendPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// GodLevel field public byte GodLevel; /// WebProfilesDisabled field public bool WebProfilesDisabled; /// AvatarID field public LLUUID AvatarID; /// Length of this block serialized in bytes public int Length { get { return 34; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; GodLevel = (byte)bytes[i++]; WebProfilesDisabled = (bytes[i++] != 0) ? (bool)true : (bool)false; AvatarID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = GodLevel; bytes[i++] = (byte)((WebProfilesDisabled) ? 1 : 0); if(AvatarID == null) { Console.WriteLine("Warning: AvatarID is null, in " + this.GetType()); } Array.Copy(AvatarID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "GodLevel: " + GodLevel.ToString() + "\n"; output += "WebProfilesDisabled: " + WebProfilesDisabled.ToString() + "\n"; output += "AvatarID: " + AvatarID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AvatarPropertiesRequestBackend public override PacketType Type { get { return PacketType.AvatarPropertiesRequestBackend; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AvatarPropertiesRequestBackendPacket() { Header = new LowHeader(); Header.ID = 213; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AvatarPropertiesRequestBackendPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AvatarPropertiesRequestBackendPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AvatarPropertiesRequestBackend ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// AvatarPropertiesReply packet public class AvatarPropertiesReplyPacket : Packet { /// PropertiesData block public class PropertiesDataBlock { /// PartnerID field public LLUUID PartnerID; private byte[] _abouttext; /// AboutText field public byte[] AboutText { get { return _abouttext; } set { if (value == null) { _abouttext = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _abouttext = new byte[value.Length]; Array.Copy(value, _abouttext, value.Length); } } } /// Transacted field public bool Transacted; private byte[] _chartermember; /// CharterMember field public byte[] CharterMember { get { return _chartermember; } set { if (value == null) { _chartermember = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _chartermember = new byte[value.Length]; Array.Copy(value, _chartermember, value.Length); } } } private byte[] _flabouttext; /// FLAboutText field public byte[] FLAboutText { get { return _flabouttext; } set { if (value == null) { _flabouttext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _flabouttext = new byte[value.Length]; Array.Copy(value, _flabouttext, value.Length); } } } /// ImageID field public LLUUID ImageID; /// FLImageID field public LLUUID FLImageID; /// AllowPublish field public bool AllowPublish; private byte[] _profileurl; /// ProfileURL field public byte[] ProfileURL { get { return _profileurl; } set { if (value == null) { _profileurl = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _profileurl = new byte[value.Length]; Array.Copy(value, _profileurl, value.Length); } } } /// Identified field public bool Identified; private byte[] _bornon; /// BornOn field public byte[] BornOn { get { return _bornon; } set { if (value == null) { _bornon = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _bornon = new byte[value.Length]; Array.Copy(value, _bornon, value.Length); } } } /// MaturePublish field public bool MaturePublish; /// Length of this block serialized in bytes public int Length { get { int length = 52; if (AboutText != null) { length += 2 + AboutText.Length; } if (CharterMember != null) { length += 1 + CharterMember.Length; } if (FLAboutText != null) { length += 1 + FLAboutText.Length; } if (ProfileURL != null) { length += 1 + ProfileURL.Length; } if (BornOn != null) { length += 1 + BornOn.Length; } return length; } } /// Default constructor public PropertiesDataBlock() { } /// Constructor for building the block from a byte array public PropertiesDataBlock(byte[] bytes, ref int i) { int length; try { PartnerID = new LLUUID(bytes, i); i += 16; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _abouttext = new byte[length]; Array.Copy(bytes, i, _abouttext, 0, length); i += length; Transacted = (bytes[i++] != 0) ? (bool)true : (bool)false; length = (ushort)bytes[i++]; _chartermember = new byte[length]; Array.Copy(bytes, i, _chartermember, 0, length); i += length; length = (ushort)bytes[i++]; _flabouttext = new byte[length]; Array.Copy(bytes, i, _flabouttext, 0, length); i += length; ImageID = new LLUUID(bytes, i); i += 16; FLImageID = new LLUUID(bytes, i); i += 16; AllowPublish = (bytes[i++] != 0) ? (bool)true : (bool)false; length = (ushort)bytes[i++]; _profileurl = new byte[length]; Array.Copy(bytes, i, _profileurl, 0, length); i += length; Identified = (bytes[i++] != 0) ? (bool)true : (bool)false; length = (ushort)bytes[i++]; _bornon = new byte[length]; Array.Copy(bytes, i, _bornon, 0, length); i += length; MaturePublish = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(PartnerID == null) { Console.WriteLine("Warning: PartnerID is null, in " + this.GetType()); } Array.Copy(PartnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(AboutText == null) { Console.WriteLine("Warning: AboutText is null, in " + this.GetType()); } bytes[i++] = (byte)(AboutText.Length % 256); bytes[i++] = (byte)((AboutText.Length >> 8) % 256); Array.Copy(AboutText, 0, bytes, i, AboutText.Length); i += AboutText.Length; bytes[i++] = (byte)((Transacted) ? 1 : 0); if(CharterMember == null) { Console.WriteLine("Warning: CharterMember is null, in " + this.GetType()); } bytes[i++] = (byte)CharterMember.Length; Array.Copy(CharterMember, 0, bytes, i, CharterMember.Length); i += CharterMember.Length; if(FLAboutText == null) { Console.WriteLine("Warning: FLAboutText is null, in " + this.GetType()); } bytes[i++] = (byte)FLAboutText.Length; Array.Copy(FLAboutText, 0, bytes, i, FLAboutText.Length); i += FLAboutText.Length; if(ImageID == null) { Console.WriteLine("Warning: ImageID is null, in " + this.GetType()); } Array.Copy(ImageID.GetBytes(), 0, bytes, i, 16); i += 16; if(FLImageID == null) { Console.WriteLine("Warning: FLImageID is null, in " + this.GetType()); } Array.Copy(FLImageID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((AllowPublish) ? 1 : 0); if(ProfileURL == null) { Console.WriteLine("Warning: ProfileURL is null, in " + this.GetType()); } bytes[i++] = (byte)ProfileURL.Length; Array.Copy(ProfileURL, 0, bytes, i, ProfileURL.Length); i += ProfileURL.Length; bytes[i++] = (byte)((Identified) ? 1 : 0); if(BornOn == null) { Console.WriteLine("Warning: BornOn is null, in " + this.GetType()); } bytes[i++] = (byte)BornOn.Length; Array.Copy(BornOn, 0, bytes, i, BornOn.Length); i += BornOn.Length; bytes[i++] = (byte)((MaturePublish) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- PropertiesData --\n"; output += "PartnerID: " + PartnerID.ToString() + "\n"; output += Helpers.FieldToString(AboutText, "AboutText") + "\n"; output += "Transacted: " + Transacted.ToString() + "\n"; output += Helpers.FieldToString(CharterMember, "CharterMember") + "\n"; output += Helpers.FieldToString(FLAboutText, "FLAboutText") + "\n"; output += "ImageID: " + ImageID.ToString() + "\n"; output += "FLImageID: " + FLImageID.ToString() + "\n"; output += "AllowPublish: " + AllowPublish.ToString() + "\n"; output += Helpers.FieldToString(ProfileURL, "ProfileURL") + "\n"; output += "Identified: " + Identified.ToString() + "\n"; output += Helpers.FieldToString(BornOn, "BornOn") + "\n"; output += "MaturePublish: " + MaturePublish.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// AvatarID field public LLUUID AvatarID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; AvatarID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(AvatarID == null) { Console.WriteLine("Warning: AvatarID is null, in " + this.GetType()); } Array.Copy(AvatarID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "AvatarID: " + AvatarID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AvatarPropertiesReply public override PacketType Type { get { return PacketType.AvatarPropertiesReply; } } /// PropertiesData block public PropertiesDataBlock PropertiesData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AvatarPropertiesReplyPacket() { Header = new LowHeader(); Header.ID = 214; Header.Reliable = true; Header.Zerocoded = true; PropertiesData = new PropertiesDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AvatarPropertiesReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); PropertiesData = new PropertiesDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AvatarPropertiesReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; PropertiesData = new PropertiesDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += PropertiesData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); PropertiesData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AvatarPropertiesReply ---\n"; output += PropertiesData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// AvatarInterestsReply packet public class AvatarInterestsReplyPacket : Packet { /// PropertiesData block public class PropertiesDataBlock { /// WantToMask field public uint WantToMask; private byte[] _wanttotext; /// WantToText field public byte[] WantToText { get { return _wanttotext; } set { if (value == null) { _wanttotext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _wanttotext = new byte[value.Length]; Array.Copy(value, _wanttotext, value.Length); } } } /// SkillsMask field public uint SkillsMask; private byte[] _skillstext; /// SkillsText field public byte[] SkillsText { get { return _skillstext; } set { if (value == null) { _skillstext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _skillstext = new byte[value.Length]; Array.Copy(value, _skillstext, value.Length); } } } private byte[] _languagestext; /// LanguagesText field public byte[] LanguagesText { get { return _languagestext; } set { if (value == null) { _languagestext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _languagestext = new byte[value.Length]; Array.Copy(value, _languagestext, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 8; if (WantToText != null) { length += 1 + WantToText.Length; } if (SkillsText != null) { length += 1 + SkillsText.Length; } if (LanguagesText != null) { length += 1 + LanguagesText.Length; } return length; } } /// Default constructor public PropertiesDataBlock() { } /// Constructor for building the block from a byte array public PropertiesDataBlock(byte[] bytes, ref int i) { int length; try { WantToMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _wanttotext = new byte[length]; Array.Copy(bytes, i, _wanttotext, 0, length); i += length; SkillsMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _skillstext = new byte[length]; Array.Copy(bytes, i, _skillstext, 0, length); i += length; length = (ushort)bytes[i++]; _languagestext = new byte[length]; Array.Copy(bytes, i, _languagestext, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(WantToMask % 256); bytes[i++] = (byte)((WantToMask >> 8) % 256); bytes[i++] = (byte)((WantToMask >> 16) % 256); bytes[i++] = (byte)((WantToMask >> 24) % 256); if(WantToText == null) { Console.WriteLine("Warning: WantToText is null, in " + this.GetType()); } bytes[i++] = (byte)WantToText.Length; Array.Copy(WantToText, 0, bytes, i, WantToText.Length); i += WantToText.Length; bytes[i++] = (byte)(SkillsMask % 256); bytes[i++] = (byte)((SkillsMask >> 8) % 256); bytes[i++] = (byte)((SkillsMask >> 16) % 256); bytes[i++] = (byte)((SkillsMask >> 24) % 256); if(SkillsText == null) { Console.WriteLine("Warning: SkillsText is null, in " + this.GetType()); } bytes[i++] = (byte)SkillsText.Length; Array.Copy(SkillsText, 0, bytes, i, SkillsText.Length); i += SkillsText.Length; if(LanguagesText == null) { Console.WriteLine("Warning: LanguagesText is null, in " + this.GetType()); } bytes[i++] = (byte)LanguagesText.Length; Array.Copy(LanguagesText, 0, bytes, i, LanguagesText.Length); i += LanguagesText.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- PropertiesData --\n"; output += "WantToMask: " + WantToMask.ToString() + "\n"; output += Helpers.FieldToString(WantToText, "WantToText") + "\n"; output += "SkillsMask: " + SkillsMask.ToString() + "\n"; output += Helpers.FieldToString(SkillsText, "SkillsText") + "\n"; output += Helpers.FieldToString(LanguagesText, "LanguagesText") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// AvatarID field public LLUUID AvatarID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; AvatarID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(AvatarID == null) { Console.WriteLine("Warning: AvatarID is null, in " + this.GetType()); } Array.Copy(AvatarID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "AvatarID: " + AvatarID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AvatarInterestsReply public override PacketType Type { get { return PacketType.AvatarInterestsReply; } } /// PropertiesData block public PropertiesDataBlock PropertiesData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AvatarInterestsReplyPacket() { Header = new LowHeader(); Header.ID = 215; Header.Reliable = true; Header.Zerocoded = true; PropertiesData = new PropertiesDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AvatarInterestsReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); PropertiesData = new PropertiesDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AvatarInterestsReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; PropertiesData = new PropertiesDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += PropertiesData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); PropertiesData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AvatarInterestsReply ---\n"; output += PropertiesData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// AvatarGroupsReply packet public class AvatarGroupsReplyPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// AvatarID field public LLUUID AvatarID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; AvatarID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(AvatarID == null) { Console.WriteLine("Warning: AvatarID is null, in " + this.GetType()); } Array.Copy(AvatarID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "AvatarID: " + AvatarID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { private byte[] _grouptitle; /// GroupTitle field public byte[] GroupTitle { get { return _grouptitle; } set { if (value == null) { _grouptitle = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _grouptitle = new byte[value.Length]; Array.Copy(value, _grouptitle, value.Length); } } } /// GroupPowers field public ulong GroupPowers; /// GroupID field public LLUUID GroupID; /// GroupInsigniaID field public LLUUID GroupInsigniaID; /// AcceptNotices field public bool AcceptNotices; private byte[] _groupname; /// GroupName field public byte[] GroupName { get { return _groupname; } set { if (value == null) { _groupname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _groupname = new byte[value.Length]; Array.Copy(value, _groupname, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 41; if (GroupTitle != null) { length += 1 + GroupTitle.Length; } if (GroupName != null) { length += 1 + GroupName.Length; } return length; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _grouptitle = new byte[length]; Array.Copy(bytes, i, _grouptitle, 0, length); i += length; GroupPowers = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); GroupID = new LLUUID(bytes, i); i += 16; GroupInsigniaID = new LLUUID(bytes, i); i += 16; AcceptNotices = (bytes[i++] != 0) ? (bool)true : (bool)false; length = (ushort)bytes[i++]; _groupname = new byte[length]; Array.Copy(bytes, i, _groupname, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GroupTitle == null) { Console.WriteLine("Warning: GroupTitle is null, in " + this.GetType()); } bytes[i++] = (byte)GroupTitle.Length; Array.Copy(GroupTitle, 0, bytes, i, GroupTitle.Length); i += GroupTitle.Length; bytes[i++] = (byte)(GroupPowers % 256); bytes[i++] = (byte)((GroupPowers >> 8) % 256); bytes[i++] = (byte)((GroupPowers >> 16) % 256); bytes[i++] = (byte)((GroupPowers >> 24) % 256); bytes[i++] = (byte)((GroupPowers >> 32) % 256); bytes[i++] = (byte)((GroupPowers >> 40) % 256); bytes[i++] = (byte)((GroupPowers >> 48) % 256); bytes[i++] = (byte)((GroupPowers >> 56) % 256); if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupInsigniaID == null) { Console.WriteLine("Warning: GroupInsigniaID is null, in " + this.GetType()); } Array.Copy(GroupInsigniaID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((AcceptNotices) ? 1 : 0); if(GroupName == null) { Console.WriteLine("Warning: GroupName is null, in " + this.GetType()); } bytes[i++] = (byte)GroupName.Length; Array.Copy(GroupName, 0, bytes, i, GroupName.Length); i += GroupName.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += Helpers.FieldToString(GroupTitle, "GroupTitle") + "\n"; output += "GroupPowers: " + GroupPowers.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "GroupInsigniaID: " + GroupInsigniaID.ToString() + "\n"; output += "AcceptNotices: " + AcceptNotices.ToString() + "\n"; output += Helpers.FieldToString(GroupName, "GroupName") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AvatarGroupsReply public override PacketType Type { get { return PacketType.AvatarGroupsReply; } } /// AgentData block public AgentDataBlock AgentData; /// GroupData block public GroupDataBlock[] GroupData; /// Default constructor public AvatarGroupsReplyPacket() { Header = new LowHeader(); Header.ID = 216; Header.Reliable = true; Header.Zerocoded = true; AgentData = new AgentDataBlock(); GroupData = new GroupDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AvatarGroupsReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); int count = (int)bytes[i++]; GroupData = new GroupDataBlock[count]; for (int j = 0; j < count; j++) { GroupData[j] = new GroupDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public AvatarGroupsReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); int count = (int)bytes[i++]; GroupData = new GroupDataBlock[count]; for (int j = 0; j < count; j++) { GroupData[j] = new GroupDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < GroupData.Length; j++) { length += GroupData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); bytes[i++] = (byte)GroupData.Length; for (int j = 0; j < GroupData.Length; j++) { GroupData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AvatarGroupsReply ---\n"; output += AgentData.ToString() + "\n"; for (int j = 0; j < GroupData.Length; j++) { output += GroupData[j].ToString() + "\n"; } return output; } } /// AvatarPropertiesUpdate packet public class AvatarPropertiesUpdatePacket : Packet { /// PropertiesData block public class PropertiesDataBlock { private byte[] _abouttext; /// AboutText field public byte[] AboutText { get { return _abouttext; } set { if (value == null) { _abouttext = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _abouttext = new byte[value.Length]; Array.Copy(value, _abouttext, value.Length); } } } private byte[] _flabouttext; /// FLAboutText field public byte[] FLAboutText { get { return _flabouttext; } set { if (value == null) { _flabouttext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _flabouttext = new byte[value.Length]; Array.Copy(value, _flabouttext, value.Length); } } } /// ImageID field public LLUUID ImageID; /// FLImageID field public LLUUID FLImageID; /// AllowPublish field public bool AllowPublish; private byte[] _profileurl; /// ProfileURL field public byte[] ProfileURL { get { return _profileurl; } set { if (value == null) { _profileurl = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _profileurl = new byte[value.Length]; Array.Copy(value, _profileurl, value.Length); } } } /// MaturePublish field public bool MaturePublish; /// Length of this block serialized in bytes public int Length { get { int length = 34; if (AboutText != null) { length += 2 + AboutText.Length; } if (FLAboutText != null) { length += 1 + FLAboutText.Length; } if (ProfileURL != null) { length += 1 + ProfileURL.Length; } return length; } } /// Default constructor public PropertiesDataBlock() { } /// Constructor for building the block from a byte array public PropertiesDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _abouttext = new byte[length]; Array.Copy(bytes, i, _abouttext, 0, length); i += length; length = (ushort)bytes[i++]; _flabouttext = new byte[length]; Array.Copy(bytes, i, _flabouttext, 0, length); i += length; ImageID = new LLUUID(bytes, i); i += 16; FLImageID = new LLUUID(bytes, i); i += 16; AllowPublish = (bytes[i++] != 0) ? (bool)true : (bool)false; length = (ushort)bytes[i++]; _profileurl = new byte[length]; Array.Copy(bytes, i, _profileurl, 0, length); i += length; MaturePublish = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AboutText == null) { Console.WriteLine("Warning: AboutText is null, in " + this.GetType()); } bytes[i++] = (byte)(AboutText.Length % 256); bytes[i++] = (byte)((AboutText.Length >> 8) % 256); Array.Copy(AboutText, 0, bytes, i, AboutText.Length); i += AboutText.Length; if(FLAboutText == null) { Console.WriteLine("Warning: FLAboutText is null, in " + this.GetType()); } bytes[i++] = (byte)FLAboutText.Length; Array.Copy(FLAboutText, 0, bytes, i, FLAboutText.Length); i += FLAboutText.Length; if(ImageID == null) { Console.WriteLine("Warning: ImageID is null, in " + this.GetType()); } Array.Copy(ImageID.GetBytes(), 0, bytes, i, 16); i += 16; if(FLImageID == null) { Console.WriteLine("Warning: FLImageID is null, in " + this.GetType()); } Array.Copy(FLImageID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((AllowPublish) ? 1 : 0); if(ProfileURL == null) { Console.WriteLine("Warning: ProfileURL is null, in " + this.GetType()); } bytes[i++] = (byte)ProfileURL.Length; Array.Copy(ProfileURL, 0, bytes, i, ProfileURL.Length); i += ProfileURL.Length; bytes[i++] = (byte)((MaturePublish) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- PropertiesData --\n"; output += Helpers.FieldToString(AboutText, "AboutText") + "\n"; output += Helpers.FieldToString(FLAboutText, "FLAboutText") + "\n"; output += "ImageID: " + ImageID.ToString() + "\n"; output += "FLImageID: " + FLImageID.ToString() + "\n"; output += "AllowPublish: " + AllowPublish.ToString() + "\n"; output += Helpers.FieldToString(ProfileURL, "ProfileURL") + "\n"; output += "MaturePublish: " + MaturePublish.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AvatarPropertiesUpdate public override PacketType Type { get { return PacketType.AvatarPropertiesUpdate; } } /// PropertiesData block public PropertiesDataBlock PropertiesData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AvatarPropertiesUpdatePacket() { Header = new LowHeader(); Header.ID = 217; Header.Reliable = true; Header.Zerocoded = true; PropertiesData = new PropertiesDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AvatarPropertiesUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); PropertiesData = new PropertiesDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AvatarPropertiesUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; PropertiesData = new PropertiesDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += PropertiesData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); PropertiesData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AvatarPropertiesUpdate ---\n"; output += PropertiesData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// AvatarInterestsUpdate packet public class AvatarInterestsUpdatePacket : Packet { /// PropertiesData block public class PropertiesDataBlock { /// WantToMask field public uint WantToMask; private byte[] _wanttotext; /// WantToText field public byte[] WantToText { get { return _wanttotext; } set { if (value == null) { _wanttotext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _wanttotext = new byte[value.Length]; Array.Copy(value, _wanttotext, value.Length); } } } /// SkillsMask field public uint SkillsMask; private byte[] _skillstext; /// SkillsText field public byte[] SkillsText { get { return _skillstext; } set { if (value == null) { _skillstext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _skillstext = new byte[value.Length]; Array.Copy(value, _skillstext, value.Length); } } } private byte[] _languagestext; /// LanguagesText field public byte[] LanguagesText { get { return _languagestext; } set { if (value == null) { _languagestext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _languagestext = new byte[value.Length]; Array.Copy(value, _languagestext, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 8; if (WantToText != null) { length += 1 + WantToText.Length; } if (SkillsText != null) { length += 1 + SkillsText.Length; } if (LanguagesText != null) { length += 1 + LanguagesText.Length; } return length; } } /// Default constructor public PropertiesDataBlock() { } /// Constructor for building the block from a byte array public PropertiesDataBlock(byte[] bytes, ref int i) { int length; try { WantToMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _wanttotext = new byte[length]; Array.Copy(bytes, i, _wanttotext, 0, length); i += length; SkillsMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _skillstext = new byte[length]; Array.Copy(bytes, i, _skillstext, 0, length); i += length; length = (ushort)bytes[i++]; _languagestext = new byte[length]; Array.Copy(bytes, i, _languagestext, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(WantToMask % 256); bytes[i++] = (byte)((WantToMask >> 8) % 256); bytes[i++] = (byte)((WantToMask >> 16) % 256); bytes[i++] = (byte)((WantToMask >> 24) % 256); if(WantToText == null) { Console.WriteLine("Warning: WantToText is null, in " + this.GetType()); } bytes[i++] = (byte)WantToText.Length; Array.Copy(WantToText, 0, bytes, i, WantToText.Length); i += WantToText.Length; bytes[i++] = (byte)(SkillsMask % 256); bytes[i++] = (byte)((SkillsMask >> 8) % 256); bytes[i++] = (byte)((SkillsMask >> 16) % 256); bytes[i++] = (byte)((SkillsMask >> 24) % 256); if(SkillsText == null) { Console.WriteLine("Warning: SkillsText is null, in " + this.GetType()); } bytes[i++] = (byte)SkillsText.Length; Array.Copy(SkillsText, 0, bytes, i, SkillsText.Length); i += SkillsText.Length; if(LanguagesText == null) { Console.WriteLine("Warning: LanguagesText is null, in " + this.GetType()); } bytes[i++] = (byte)LanguagesText.Length; Array.Copy(LanguagesText, 0, bytes, i, LanguagesText.Length); i += LanguagesText.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- PropertiesData --\n"; output += "WantToMask: " + WantToMask.ToString() + "\n"; output += Helpers.FieldToString(WantToText, "WantToText") + "\n"; output += "SkillsMask: " + SkillsMask.ToString() + "\n"; output += Helpers.FieldToString(SkillsText, "SkillsText") + "\n"; output += Helpers.FieldToString(LanguagesText, "LanguagesText") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AvatarInterestsUpdate public override PacketType Type { get { return PacketType.AvatarInterestsUpdate; } } /// PropertiesData block public PropertiesDataBlock PropertiesData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AvatarInterestsUpdatePacket() { Header = new LowHeader(); Header.ID = 218; Header.Reliable = true; Header.Zerocoded = true; PropertiesData = new PropertiesDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AvatarInterestsUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); PropertiesData = new PropertiesDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AvatarInterestsUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; PropertiesData = new PropertiesDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += PropertiesData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); PropertiesData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AvatarInterestsUpdate ---\n"; output += PropertiesData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// AvatarStatisticsReply packet public class AvatarStatisticsReplyPacket : Packet { /// StatisticsData block public class StatisticsDataBlock { private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// Negative field public int Negative; /// Positive field public int Positive; /// Length of this block serialized in bytes public int Length { get { int length = 8; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public StatisticsDataBlock() { } /// Constructor for building the block from a byte array public StatisticsDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; Negative = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Positive = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)(Negative % 256); bytes[i++] = (byte)((Negative >> 8) % 256); bytes[i++] = (byte)((Negative >> 16) % 256); bytes[i++] = (byte)((Negative >> 24) % 256); bytes[i++] = (byte)(Positive % 256); bytes[i++] = (byte)((Positive >> 8) % 256); bytes[i++] = (byte)((Positive >> 16) % 256); bytes[i++] = (byte)((Positive >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- StatisticsData --\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "Negative: " + Negative.ToString() + "\n"; output += "Positive: " + Positive.ToString() + "\n"; output = output.Trim(); return output; } } /// AvatarData block public class AvatarDataBlock { /// AvatarID field public LLUUID AvatarID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AvatarDataBlock() { } /// Constructor for building the block from a byte array public AvatarDataBlock(byte[] bytes, ref int i) { try { AvatarID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AvatarID == null) { Console.WriteLine("Warning: AvatarID is null, in " + this.GetType()); } Array.Copy(AvatarID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AvatarData --\n"; output += "AvatarID: " + AvatarID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AvatarStatisticsReply public override PacketType Type { get { return PacketType.AvatarStatisticsReply; } } /// StatisticsData block public StatisticsDataBlock[] StatisticsData; /// AvatarData block public AvatarDataBlock AvatarData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AvatarStatisticsReplyPacket() { Header = new LowHeader(); Header.ID = 219; Header.Reliable = true; Header.Zerocoded = true; StatisticsData = new StatisticsDataBlock[0]; AvatarData = new AvatarDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AvatarStatisticsReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; StatisticsData = new StatisticsDataBlock[count]; for (int j = 0; j < count; j++) { StatisticsData[j] = new StatisticsDataBlock(bytes, ref i); } AvatarData = new AvatarDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AvatarStatisticsReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; StatisticsData = new StatisticsDataBlock[count]; for (int j = 0; j < count; j++) { StatisticsData[j] = new StatisticsDataBlock(bytes, ref i); } AvatarData = new AvatarDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AvatarData.Length; length += AgentData.Length;; length++; for (int j = 0; j < StatisticsData.Length; j++) { length += StatisticsData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)StatisticsData.Length; for (int j = 0; j < StatisticsData.Length; j++) { StatisticsData[j].ToBytes(bytes, ref i); } AvatarData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AvatarStatisticsReply ---\n"; for (int j = 0; j < StatisticsData.Length; j++) { output += StatisticsData[j].ToString() + "\n"; } output += AvatarData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// AvatarNotesReply packet public class AvatarNotesReplyPacket : Packet { /// Data block public class DataBlock { /// TargetID field public LLUUID TargetID; private byte[] _notes; /// Notes field public byte[] Notes { get { return _notes; } set { if (value == null) { _notes = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _notes = new byte[value.Length]; Array.Copy(value, _notes, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 16; if (Notes != null) { length += 2 + Notes.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { TargetID = new LLUUID(bytes, i); i += 16; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _notes = new byte[length]; Array.Copy(bytes, i, _notes, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TargetID == null) { Console.WriteLine("Warning: TargetID is null, in " + this.GetType()); } Array.Copy(TargetID.GetBytes(), 0, bytes, i, 16); i += 16; if(Notes == null) { Console.WriteLine("Warning: Notes is null, in " + this.GetType()); } bytes[i++] = (byte)(Notes.Length % 256); bytes[i++] = (byte)((Notes.Length >> 8) % 256); Array.Copy(Notes, 0, bytes, i, Notes.Length); i += Notes.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "TargetID: " + TargetID.ToString() + "\n"; output += Helpers.FieldToString(Notes, "Notes") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AvatarNotesReply public override PacketType Type { get { return PacketType.AvatarNotesReply; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AvatarNotesReplyPacket() { Header = new LowHeader(); Header.ID = 220; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AvatarNotesReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AvatarNotesReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AvatarNotesReply ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// AvatarNotesUpdate packet public class AvatarNotesUpdatePacket : Packet { /// Data block public class DataBlock { /// TargetID field public LLUUID TargetID; private byte[] _notes; /// Notes field public byte[] Notes { get { return _notes; } set { if (value == null) { _notes = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _notes = new byte[value.Length]; Array.Copy(value, _notes, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 16; if (Notes != null) { length += 2 + Notes.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { TargetID = new LLUUID(bytes, i); i += 16; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _notes = new byte[length]; Array.Copy(bytes, i, _notes, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TargetID == null) { Console.WriteLine("Warning: TargetID is null, in " + this.GetType()); } Array.Copy(TargetID.GetBytes(), 0, bytes, i, 16); i += 16; if(Notes == null) { Console.WriteLine("Warning: Notes is null, in " + this.GetType()); } bytes[i++] = (byte)(Notes.Length % 256); bytes[i++] = (byte)((Notes.Length >> 8) % 256); Array.Copy(Notes, 0, bytes, i, Notes.Length); i += Notes.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "TargetID: " + TargetID.ToString() + "\n"; output += Helpers.FieldToString(Notes, "Notes") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AvatarNotesUpdate public override PacketType Type { get { return PacketType.AvatarNotesUpdate; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AvatarNotesUpdatePacket() { Header = new LowHeader(); Header.ID = 221; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AvatarNotesUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AvatarNotesUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AvatarNotesUpdate ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// AvatarPicksReply packet public class AvatarPicksReplyPacket : Packet { /// Data block public class DataBlock { private byte[] _pickname; /// PickName field public byte[] PickName { get { return _pickname; } set { if (value == null) { _pickname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _pickname = new byte[value.Length]; Array.Copy(value, _pickname, value.Length); } } } /// PickID field public LLUUID PickID; /// Length of this block serialized in bytes public int Length { get { int length = 16; if (PickName != null) { length += 1 + PickName.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _pickname = new byte[length]; Array.Copy(bytes, i, _pickname, 0, length); i += length; PickID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(PickName == null) { Console.WriteLine("Warning: PickName is null, in " + this.GetType()); } bytes[i++] = (byte)PickName.Length; Array.Copy(PickName, 0, bytes, i, PickName.Length); i += PickName.Length; if(PickID == null) { Console.WriteLine("Warning: PickID is null, in " + this.GetType()); } Array.Copy(PickID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += Helpers.FieldToString(PickName, "PickName") + "\n"; output += "PickID: " + PickID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// TargetID field public LLUUID TargetID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; TargetID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(TargetID == null) { Console.WriteLine("Warning: TargetID is null, in " + this.GetType()); } Array.Copy(TargetID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "TargetID: " + TargetID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AvatarPicksReply public override PacketType Type { get { return PacketType.AvatarPicksReply; } } /// Data block public DataBlock[] Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AvatarPicksReplyPacket() { Header = new LowHeader(); Header.ID = 222; Header.Reliable = true; Data = new DataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AvatarPicksReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AvatarPicksReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)Data.Length; for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AvatarPicksReply ---\n"; for (int j = 0; j < Data.Length; j++) { output += Data[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// EventInfoRequest packet public class EventInfoRequestPacket : Packet { /// EventData block public class EventDataBlock { /// EventID field public uint EventID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public EventDataBlock() { } /// Constructor for building the block from a byte array public EventDataBlock(byte[] bytes, ref int i) { try { EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(EventID % 256); bytes[i++] = (byte)((EventID >> 8) % 256); bytes[i++] = (byte)((EventID >> 16) % 256); bytes[i++] = (byte)((EventID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- EventData --\n"; output += "EventID: " + EventID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.EventInfoRequest public override PacketType Type { get { return PacketType.EventInfoRequest; } } /// EventData block public EventDataBlock EventData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public EventInfoRequestPacket() { Header = new LowHeader(); Header.ID = 223; Header.Reliable = true; EventData = new EventDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public EventInfoRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); EventData = new EventDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public EventInfoRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; EventData = new EventDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += EventData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); EventData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- EventInfoRequest ---\n"; output += EventData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// EventInfoReply packet public class EventInfoReplyPacket : Packet { /// EventData block public class EventDataBlock { /// Duration field public uint Duration; /// DateUTC field public uint DateUTC; private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// GlobalPos field public LLVector3d GlobalPos; private byte[] _creator; /// Creator field public byte[] Creator { get { return _creator; } set { if (value == null) { _creator = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _creator = new byte[value.Length]; Array.Copy(value, _creator, value.Length); } } } private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } private byte[] _date; /// Date field public byte[] Date { get { return _date; } set { if (value == null) { _date = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _date = new byte[value.Length]; Array.Copy(value, _date, value.Length); } } } private byte[] _desc; /// Desc field public byte[] Desc { get { return _desc; } set { if (value == null) { _desc = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _desc = new byte[value.Length]; Array.Copy(value, _desc, value.Length); } } } /// EventID field public uint EventID; private byte[] _category; /// Category field public byte[] Category { get { return _category; } set { if (value == null) { _category = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _category = new byte[value.Length]; Array.Copy(value, _category, value.Length); } } } /// EventFlags field public uint EventFlags; /// Amount field public uint Amount; /// Cover field public uint Cover; /// Length of this block serialized in bytes public int Length { get { int length = 48; if (SimName != null) { length += 1 + SimName.Length; } if (Creator != null) { length += 1 + Creator.Length; } if (Name != null) { length += 1 + Name.Length; } if (Date != null) { length += 1 + Date.Length; } if (Desc != null) { length += 2 + Desc.Length; } if (Category != null) { length += 1 + Category.Length; } return length; } } /// Default constructor public EventDataBlock() { } /// Constructor for building the block from a byte array public EventDataBlock(byte[] bytes, ref int i) { int length; try { Duration = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); DateUTC = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; GlobalPos = new LLVector3d(bytes, i); i += 24; length = (ushort)bytes[i++]; _creator = new byte[length]; Array.Copy(bytes, i, _creator, 0, length); i += length; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; length = (ushort)bytes[i++]; _date = new byte[length]; Array.Copy(bytes, i, _date, 0, length); i += length; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _desc = new byte[length]; Array.Copy(bytes, i, _desc, 0, length); i += length; EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _category = new byte[length]; Array.Copy(bytes, i, _category, 0, length); i += length; EventFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Amount = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Cover = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Duration % 256); bytes[i++] = (byte)((Duration >> 8) % 256); bytes[i++] = (byte)((Duration >> 16) % 256); bytes[i++] = (byte)((Duration >> 24) % 256); bytes[i++] = (byte)(DateUTC % 256); bytes[i++] = (byte)((DateUTC >> 8) % 256); bytes[i++] = (byte)((DateUTC >> 16) % 256); bytes[i++] = (byte)((DateUTC >> 24) % 256); if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; if(GlobalPos == null) { Console.WriteLine("Warning: GlobalPos is null, in " + this.GetType()); } Array.Copy(GlobalPos.GetBytes(), 0, bytes, i, 24); i += 24; if(Creator == null) { Console.WriteLine("Warning: Creator is null, in " + this.GetType()); } bytes[i++] = (byte)Creator.Length; Array.Copy(Creator, 0, bytes, i, Creator.Length); i += Creator.Length; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(Date == null) { Console.WriteLine("Warning: Date is null, in " + this.GetType()); } bytes[i++] = (byte)Date.Length; Array.Copy(Date, 0, bytes, i, Date.Length); i += Date.Length; if(Desc == null) { Console.WriteLine("Warning: Desc is null, in " + this.GetType()); } bytes[i++] = (byte)(Desc.Length % 256); bytes[i++] = (byte)((Desc.Length >> 8) % 256); Array.Copy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; bytes[i++] = (byte)(EventID % 256); bytes[i++] = (byte)((EventID >> 8) % 256); bytes[i++] = (byte)((EventID >> 16) % 256); bytes[i++] = (byte)((EventID >> 24) % 256); if(Category == null) { Console.WriteLine("Warning: Category is null, in " + this.GetType()); } bytes[i++] = (byte)Category.Length; Array.Copy(Category, 0, bytes, i, Category.Length); i += Category.Length; bytes[i++] = (byte)(EventFlags % 256); bytes[i++] = (byte)((EventFlags >> 8) % 256); bytes[i++] = (byte)((EventFlags >> 16) % 256); bytes[i++] = (byte)((EventFlags >> 24) % 256); bytes[i++] = (byte)(Amount % 256); bytes[i++] = (byte)((Amount >> 8) % 256); bytes[i++] = (byte)((Amount >> 16) % 256); bytes[i++] = (byte)((Amount >> 24) % 256); bytes[i++] = (byte)(Cover % 256); bytes[i++] = (byte)((Cover >> 8) % 256); bytes[i++] = (byte)((Cover >> 16) % 256); bytes[i++] = (byte)((Cover >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- EventData --\n"; output += "Duration: " + Duration.ToString() + "\n"; output += "DateUTC: " + DateUTC.ToString() + "\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "GlobalPos: " + GlobalPos.ToString() + "\n"; output += Helpers.FieldToString(Creator, "Creator") + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += Helpers.FieldToString(Date, "Date") + "\n"; output += Helpers.FieldToString(Desc, "Desc") + "\n"; output += "EventID: " + EventID.ToString() + "\n"; output += Helpers.FieldToString(Category, "Category") + "\n"; output += "EventFlags: " + EventFlags.ToString() + "\n"; output += "Amount: " + Amount.ToString() + "\n"; output += "Cover: " + Cover.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.EventInfoReply public override PacketType Type { get { return PacketType.EventInfoReply; } } /// EventData block public EventDataBlock EventData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public EventInfoReplyPacket() { Header = new LowHeader(); Header.ID = 224; Header.Reliable = true; EventData = new EventDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public EventInfoReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); EventData = new EventDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public EventInfoReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; EventData = new EventDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += EventData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); EventData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- EventInfoReply ---\n"; output += EventData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// EventNotificationAddRequest packet public class EventNotificationAddRequestPacket : Packet { /// EventData block public class EventDataBlock { /// EventID field public uint EventID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public EventDataBlock() { } /// Constructor for building the block from a byte array public EventDataBlock(byte[] bytes, ref int i) { try { EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(EventID % 256); bytes[i++] = (byte)((EventID >> 8) % 256); bytes[i++] = (byte)((EventID >> 16) % 256); bytes[i++] = (byte)((EventID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- EventData --\n"; output += "EventID: " + EventID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.EventNotificationAddRequest public override PacketType Type { get { return PacketType.EventNotificationAddRequest; } } /// EventData block public EventDataBlock EventData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public EventNotificationAddRequestPacket() { Header = new LowHeader(); Header.ID = 225; Header.Reliable = true; EventData = new EventDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public EventNotificationAddRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); EventData = new EventDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public EventNotificationAddRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; EventData = new EventDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += EventData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); EventData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- EventNotificationAddRequest ---\n"; output += EventData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// EventNotificationRemoveRequest packet public class EventNotificationRemoveRequestPacket : Packet { /// EventData block public class EventDataBlock { /// EventID field public uint EventID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public EventDataBlock() { } /// Constructor for building the block from a byte array public EventDataBlock(byte[] bytes, ref int i) { try { EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(EventID % 256); bytes[i++] = (byte)((EventID >> 8) % 256); bytes[i++] = (byte)((EventID >> 16) % 256); bytes[i++] = (byte)((EventID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- EventData --\n"; output += "EventID: " + EventID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.EventNotificationRemoveRequest public override PacketType Type { get { return PacketType.EventNotificationRemoveRequest; } } /// EventData block public EventDataBlock EventData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public EventNotificationRemoveRequestPacket() { Header = new LowHeader(); Header.ID = 226; Header.Reliable = true; EventData = new EventDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public EventNotificationRemoveRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); EventData = new EventDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public EventNotificationRemoveRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; EventData = new EventDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += EventData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); EventData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- EventNotificationRemoveRequest ---\n"; output += EventData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// EventGodDelete packet public class EventGodDeletePacket : Packet { /// EventData block public class EventDataBlock { /// EventID field public uint EventID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public EventDataBlock() { } /// Constructor for building the block from a byte array public EventDataBlock(byte[] bytes, ref int i) { try { EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(EventID % 256); bytes[i++] = (byte)((EventID >> 8) % 256); bytes[i++] = (byte)((EventID >> 16) % 256); bytes[i++] = (byte)((EventID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- EventData --\n"; output += "EventID: " + EventID.ToString() + "\n"; output = output.Trim(); return output; } } /// QueryData block public class QueryDataBlock { /// QueryID field public LLUUID QueryID; /// QueryFlags field public uint QueryFlags; /// QueryStart field public int QueryStart; private byte[] _querytext; /// QueryText field public byte[] QueryText { get { return _querytext; } set { if (value == null) { _querytext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _querytext = new byte[value.Length]; Array.Copy(value, _querytext, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 24; if (QueryText != null) { length += 1 + QueryText.Length; } return length; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { int length; try { QueryID = new LLUUID(bytes, i); i += 16; QueryFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); QueryStart = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _querytext = new byte[length]; Array.Copy(bytes, i, _querytext, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(QueryFlags % 256); bytes[i++] = (byte)((QueryFlags >> 8) % 256); bytes[i++] = (byte)((QueryFlags >> 16) % 256); bytes[i++] = (byte)((QueryFlags >> 24) % 256); bytes[i++] = (byte)(QueryStart % 256); bytes[i++] = (byte)((QueryStart >> 8) % 256); bytes[i++] = (byte)((QueryStart >> 16) % 256); bytes[i++] = (byte)((QueryStart >> 24) % 256); if(QueryText == null) { Console.WriteLine("Warning: QueryText is null, in " + this.GetType()); } bytes[i++] = (byte)QueryText.Length; Array.Copy(QueryText, 0, bytes, i, QueryText.Length); i += QueryText.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += "QueryFlags: " + QueryFlags.ToString() + "\n"; output += "QueryStart: " + QueryStart.ToString() + "\n"; output += Helpers.FieldToString(QueryText, "QueryText") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.EventGodDelete public override PacketType Type { get { return PacketType.EventGodDelete; } } /// EventData block public EventDataBlock EventData; /// QueryData block public QueryDataBlock QueryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public EventGodDeletePacket() { Header = new LowHeader(); Header.ID = 227; Header.Reliable = true; EventData = new EventDataBlock(); QueryData = new QueryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public EventGodDeletePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); EventData = new EventDataBlock(bytes, ref i); QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public EventGodDeletePacket(Header head, byte[] bytes, ref int i) { Header = head; EventData = new EventDataBlock(bytes, ref i); QueryData = new QueryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += EventData.Length; length += QueryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); EventData.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- EventGodDelete ---\n"; output += EventData.ToString() + "\n"; output += QueryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// PickInfoRequest packet public class PickInfoRequestPacket : Packet { /// Data block public class DataBlock { /// PickID field public LLUUID PickID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { PickID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(PickID == null) { Console.WriteLine("Warning: PickID is null, in " + this.GetType()); } Array.Copy(PickID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "PickID: " + PickID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.PickInfoRequest public override PacketType Type { get { return PacketType.PickInfoRequest; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public PickInfoRequestPacket() { Header = new LowHeader(); Header.ID = 228; Header.Reliable = true; Header.Zerocoded = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public PickInfoRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public PickInfoRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- PickInfoRequest ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// PickInfoReply packet public class PickInfoReplyPacket : Packet { /// Data block public class DataBlock { private byte[] _originalname; /// OriginalName field public byte[] OriginalName { get { return _originalname; } set { if (value == null) { _originalname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _originalname = new byte[value.Length]; Array.Copy(value, _originalname, value.Length); } } } private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// Enabled field public bool Enabled; /// PosGlobal field public LLVector3d PosGlobal; /// TopPick field public bool TopPick; /// ParcelID field public LLUUID ParcelID; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } private byte[] _desc; /// Desc field public byte[] Desc { get { return _desc; } set { if (value == null) { _desc = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _desc = new byte[value.Length]; Array.Copy(value, _desc, value.Length); } } } private byte[] _user; /// User field public byte[] User { get { return _user; } set { if (value == null) { _user = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _user = new byte[value.Length]; Array.Copy(value, _user, value.Length); } } } /// CreatorID field public LLUUID CreatorID; /// PickID field public LLUUID PickID; /// SnapshotID field public LLUUID SnapshotID; /// SortOrder field public int SortOrder; /// Length of this block serialized in bytes public int Length { get { int length = 94; if (OriginalName != null) { length += 1 + OriginalName.Length; } if (SimName != null) { length += 1 + SimName.Length; } if (Name != null) { length += 1 + Name.Length; } if (Desc != null) { length += 2 + Desc.Length; } if (User != null) { length += 1 + User.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _originalname = new byte[length]; Array.Copy(bytes, i, _originalname, 0, length); i += length; length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; Enabled = (bytes[i++] != 0) ? (bool)true : (bool)false; PosGlobal = new LLVector3d(bytes, i); i += 24; TopPick = (bytes[i++] != 0) ? (bool)true : (bool)false; ParcelID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _desc = new byte[length]; Array.Copy(bytes, i, _desc, 0, length); i += length; length = (ushort)bytes[i++]; _user = new byte[length]; Array.Copy(bytes, i, _user, 0, length); i += length; CreatorID = new LLUUID(bytes, i); i += 16; PickID = new LLUUID(bytes, i); i += 16; SnapshotID = new LLUUID(bytes, i); i += 16; SortOrder = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(OriginalName == null) { Console.WriteLine("Warning: OriginalName is null, in " + this.GetType()); } bytes[i++] = (byte)OriginalName.Length; Array.Copy(OriginalName, 0, bytes, i, OriginalName.Length); i += OriginalName.Length; if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; bytes[i++] = (byte)((Enabled) ? 1 : 0); if(PosGlobal == null) { Console.WriteLine("Warning: PosGlobal is null, in " + this.GetType()); } Array.Copy(PosGlobal.GetBytes(), 0, bytes, i, 24); i += 24; bytes[i++] = (byte)((TopPick) ? 1 : 0); if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(Desc == null) { Console.WriteLine("Warning: Desc is null, in " + this.GetType()); } bytes[i++] = (byte)(Desc.Length % 256); bytes[i++] = (byte)((Desc.Length >> 8) % 256); Array.Copy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; if(User == null) { Console.WriteLine("Warning: User is null, in " + this.GetType()); } bytes[i++] = (byte)User.Length; Array.Copy(User, 0, bytes, i, User.Length); i += User.Length; if(CreatorID == null) { Console.WriteLine("Warning: CreatorID is null, in " + this.GetType()); } Array.Copy(CreatorID.GetBytes(), 0, bytes, i, 16); i += 16; if(PickID == null) { Console.WriteLine("Warning: PickID is null, in " + this.GetType()); } Array.Copy(PickID.GetBytes(), 0, bytes, i, 16); i += 16; if(SnapshotID == null) { Console.WriteLine("Warning: SnapshotID is null, in " + this.GetType()); } Array.Copy(SnapshotID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(SortOrder % 256); bytes[i++] = (byte)((SortOrder >> 8) % 256); bytes[i++] = (byte)((SortOrder >> 16) % 256); bytes[i++] = (byte)((SortOrder >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += Helpers.FieldToString(OriginalName, "OriginalName") + "\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "Enabled: " + Enabled.ToString() + "\n"; output += "PosGlobal: " + PosGlobal.ToString() + "\n"; output += "TopPick: " + TopPick.ToString() + "\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += Helpers.FieldToString(Desc, "Desc") + "\n"; output += Helpers.FieldToString(User, "User") + "\n"; output += "CreatorID: " + CreatorID.ToString() + "\n"; output += "PickID: " + PickID.ToString() + "\n"; output += "SnapshotID: " + SnapshotID.ToString() + "\n"; output += "SortOrder: " + SortOrder.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.PickInfoReply public override PacketType Type { get { return PacketType.PickInfoReply; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public PickInfoReplyPacket() { Header = new LowHeader(); Header.ID = 229; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public PickInfoReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public PickInfoReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- PickInfoReply ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// PickInfoUpdate packet public class PickInfoUpdatePacket : Packet { /// Data block public class DataBlock { /// Enabled field public bool Enabled; /// PosGlobal field public LLVector3d PosGlobal; /// TopPick field public bool TopPick; /// ParcelID field public LLUUID ParcelID; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } private byte[] _desc; /// Desc field public byte[] Desc { get { return _desc; } set { if (value == null) { _desc = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _desc = new byte[value.Length]; Array.Copy(value, _desc, value.Length); } } } /// CreatorID field public LLUUID CreatorID; /// PickID field public LLUUID PickID; /// SnapshotID field public LLUUID SnapshotID; /// SortOrder field public int SortOrder; /// Length of this block serialized in bytes public int Length { get { int length = 94; if (Name != null) { length += 1 + Name.Length; } if (Desc != null) { length += 2 + Desc.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { Enabled = (bytes[i++] != 0) ? (bool)true : (bool)false; PosGlobal = new LLVector3d(bytes, i); i += 24; TopPick = (bytes[i++] != 0) ? (bool)true : (bool)false; ParcelID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _desc = new byte[length]; Array.Copy(bytes, i, _desc, 0, length); i += length; CreatorID = new LLUUID(bytes, i); i += 16; PickID = new LLUUID(bytes, i); i += 16; SnapshotID = new LLUUID(bytes, i); i += 16; SortOrder = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((Enabled) ? 1 : 0); if(PosGlobal == null) { Console.WriteLine("Warning: PosGlobal is null, in " + this.GetType()); } Array.Copy(PosGlobal.GetBytes(), 0, bytes, i, 24); i += 24; bytes[i++] = (byte)((TopPick) ? 1 : 0); if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(Desc == null) { Console.WriteLine("Warning: Desc is null, in " + this.GetType()); } bytes[i++] = (byte)(Desc.Length % 256); bytes[i++] = (byte)((Desc.Length >> 8) % 256); Array.Copy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; if(CreatorID == null) { Console.WriteLine("Warning: CreatorID is null, in " + this.GetType()); } Array.Copy(CreatorID.GetBytes(), 0, bytes, i, 16); i += 16; if(PickID == null) { Console.WriteLine("Warning: PickID is null, in " + this.GetType()); } Array.Copy(PickID.GetBytes(), 0, bytes, i, 16); i += 16; if(SnapshotID == null) { Console.WriteLine("Warning: SnapshotID is null, in " + this.GetType()); } Array.Copy(SnapshotID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(SortOrder % 256); bytes[i++] = (byte)((SortOrder >> 8) % 256); bytes[i++] = (byte)((SortOrder >> 16) % 256); bytes[i++] = (byte)((SortOrder >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "Enabled: " + Enabled.ToString() + "\n"; output += "PosGlobal: " + PosGlobal.ToString() + "\n"; output += "TopPick: " + TopPick.ToString() + "\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += Helpers.FieldToString(Desc, "Desc") + "\n"; output += "CreatorID: " + CreatorID.ToString() + "\n"; output += "PickID: " + PickID.ToString() + "\n"; output += "SnapshotID: " + SnapshotID.ToString() + "\n"; output += "SortOrder: " + SortOrder.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.PickInfoUpdate public override PacketType Type { get { return PacketType.PickInfoUpdate; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public PickInfoUpdatePacket() { Header = new LowHeader(); Header.ID = 230; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public PickInfoUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public PickInfoUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- PickInfoUpdate ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// PickDelete packet public class PickDeletePacket : Packet { /// Data block public class DataBlock { /// PickID field public LLUUID PickID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { PickID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(PickID == null) { Console.WriteLine("Warning: PickID is null, in " + this.GetType()); } Array.Copy(PickID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "PickID: " + PickID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.PickDelete public override PacketType Type { get { return PacketType.PickDelete; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public PickDeletePacket() { Header = new LowHeader(); Header.ID = 231; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public PickDeletePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public PickDeletePacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- PickDelete ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// PickGodDelete packet public class PickGodDeletePacket : Packet { /// Data block public class DataBlock { /// QueryID field public LLUUID QueryID; /// PickID field public LLUUID PickID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { QueryID = new LLUUID(bytes, i); i += 16; PickID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; if(PickID == null) { Console.WriteLine("Warning: PickID is null, in " + this.GetType()); } Array.Copy(PickID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += "PickID: " + PickID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.PickGodDelete public override PacketType Type { get { return PacketType.PickGodDelete; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public PickGodDeletePacket() { Header = new LowHeader(); Header.ID = 232; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public PickGodDeletePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public PickGodDeletePacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- PickGodDelete ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ScriptQuestion packet public class ScriptQuestionPacket : Packet { /// Data block public class DataBlock { private byte[] _objectname; /// ObjectName field public byte[] ObjectName { get { return _objectname; } set { if (value == null) { _objectname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _objectname = new byte[value.Length]; Array.Copy(value, _objectname, value.Length); } } } private byte[] _objectowner; /// ObjectOwner field public byte[] ObjectOwner { get { return _objectowner; } set { if (value == null) { _objectowner = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _objectowner = new byte[value.Length]; Array.Copy(value, _objectowner, value.Length); } } } /// TaskID field public LLUUID TaskID; /// ItemID field public LLUUID ItemID; /// Questions field public int Questions; /// Length of this block serialized in bytes public int Length { get { int length = 36; if (ObjectName != null) { length += 1 + ObjectName.Length; } if (ObjectOwner != null) { length += 1 + ObjectOwner.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _objectname = new byte[length]; Array.Copy(bytes, i, _objectname, 0, length); i += length; length = (ushort)bytes[i++]; _objectowner = new byte[length]; Array.Copy(bytes, i, _objectowner, 0, length); i += length; TaskID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; Questions = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectName == null) { Console.WriteLine("Warning: ObjectName is null, in " + this.GetType()); } bytes[i++] = (byte)ObjectName.Length; Array.Copy(ObjectName, 0, bytes, i, ObjectName.Length); i += ObjectName.Length; if(ObjectOwner == null) { Console.WriteLine("Warning: ObjectOwner is null, in " + this.GetType()); } bytes[i++] = (byte)ObjectOwner.Length; Array.Copy(ObjectOwner, 0, bytes, i, ObjectOwner.Length); i += ObjectOwner.Length; if(TaskID == null) { Console.WriteLine("Warning: TaskID is null, in " + this.GetType()); } Array.Copy(TaskID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Questions % 256); bytes[i++] = (byte)((Questions >> 8) % 256); bytes[i++] = (byte)((Questions >> 16) % 256); bytes[i++] = (byte)((Questions >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += Helpers.FieldToString(ObjectName, "ObjectName") + "\n"; output += Helpers.FieldToString(ObjectOwner, "ObjectOwner") + "\n"; output += "TaskID: " + TaskID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "Questions: " + Questions.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ScriptQuestion public override PacketType Type { get { return PacketType.ScriptQuestion; } } /// Data block public DataBlock Data; /// Default constructor public ScriptQuestionPacket() { Header = new LowHeader(); Header.ID = 233; Header.Reliable = true; Data = new DataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ScriptQuestionPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ScriptQuestionPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ScriptQuestion ---\n"; output += Data.ToString() + "\n"; return output; } } /// ScriptControlChange packet public class ScriptControlChangePacket : Packet { /// Data block public class DataBlock { /// PassToAgent field public bool PassToAgent; /// Controls field public uint Controls; /// TakeControls field public bool TakeControls; /// Length of this block serialized in bytes public int Length { get { return 6; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { PassToAgent = (bytes[i++] != 0) ? (bool)true : (bool)false; Controls = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TakeControls = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((PassToAgent) ? 1 : 0); bytes[i++] = (byte)(Controls % 256); bytes[i++] = (byte)((Controls >> 8) % 256); bytes[i++] = (byte)((Controls >> 16) % 256); bytes[i++] = (byte)((Controls >> 24) % 256); bytes[i++] = (byte)((TakeControls) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "PassToAgent: " + PassToAgent.ToString() + "\n"; output += "Controls: " + Controls.ToString() + "\n"; output += "TakeControls: " + TakeControls.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ScriptControlChange public override PacketType Type { get { return PacketType.ScriptControlChange; } } /// Data block public DataBlock[] Data; /// Default constructor public ScriptControlChangePacket() { Header = new LowHeader(); Header.ID = 234; Header.Reliable = true; Data = new DataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ScriptControlChangePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public ScriptControlChangePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)Data.Length; for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ScriptControlChange ---\n"; for (int j = 0; j < Data.Length; j++) { output += Data[j].ToString() + "\n"; } return output; } } /// ScriptDialog packet public class ScriptDialogPacket : Packet { /// Data block public class DataBlock { private byte[] _objectname; /// ObjectName field public byte[] ObjectName { get { return _objectname; } set { if (value == null) { _objectname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _objectname = new byte[value.Length]; Array.Copy(value, _objectname, value.Length); } } } /// ImageID field public LLUUID ImageID; /// ObjectID field public LLUUID ObjectID; private byte[] _message; /// Message field public byte[] Message { get { return _message; } set { if (value == null) { _message = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _message = new byte[value.Length]; Array.Copy(value, _message, value.Length); } } } private byte[] _lastname; /// LastName field public byte[] LastName { get { return _lastname; } set { if (value == null) { _lastname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _lastname = new byte[value.Length]; Array.Copy(value, _lastname, value.Length); } } } private byte[] _firstname; /// FirstName field public byte[] FirstName { get { return _firstname; } set { if (value == null) { _firstname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _firstname = new byte[value.Length]; Array.Copy(value, _firstname, value.Length); } } } /// ChatChannel field public int ChatChannel; /// Length of this block serialized in bytes public int Length { get { int length = 36; if (ObjectName != null) { length += 1 + ObjectName.Length; } if (Message != null) { length += 2 + Message.Length; } if (LastName != null) { length += 1 + LastName.Length; } if (FirstName != null) { length += 1 + FirstName.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _objectname = new byte[length]; Array.Copy(bytes, i, _objectname, 0, length); i += length; ImageID = new LLUUID(bytes, i); i += 16; ObjectID = new LLUUID(bytes, i); i += 16; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _message = new byte[length]; Array.Copy(bytes, i, _message, 0, length); i += length; length = (ushort)bytes[i++]; _lastname = new byte[length]; Array.Copy(bytes, i, _lastname, 0, length); i += length; length = (ushort)bytes[i++]; _firstname = new byte[length]; Array.Copy(bytes, i, _firstname, 0, length); i += length; ChatChannel = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectName == null) { Console.WriteLine("Warning: ObjectName is null, in " + this.GetType()); } bytes[i++] = (byte)ObjectName.Length; Array.Copy(ObjectName, 0, bytes, i, ObjectName.Length); i += ObjectName.Length; if(ImageID == null) { Console.WriteLine("Warning: ImageID is null, in " + this.GetType()); } Array.Copy(ImageID.GetBytes(), 0, bytes, i, 16); i += 16; if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; if(Message == null) { Console.WriteLine("Warning: Message is null, in " + this.GetType()); } bytes[i++] = (byte)(Message.Length % 256); bytes[i++] = (byte)((Message.Length >> 8) % 256); Array.Copy(Message, 0, bytes, i, Message.Length); i += Message.Length; if(LastName == null) { Console.WriteLine("Warning: LastName is null, in " + this.GetType()); } bytes[i++] = (byte)LastName.Length; Array.Copy(LastName, 0, bytes, i, LastName.Length); i += LastName.Length; if(FirstName == null) { Console.WriteLine("Warning: FirstName is null, in " + this.GetType()); } bytes[i++] = (byte)FirstName.Length; Array.Copy(FirstName, 0, bytes, i, FirstName.Length); i += FirstName.Length; bytes[i++] = (byte)(ChatChannel % 256); bytes[i++] = (byte)((ChatChannel >> 8) % 256); bytes[i++] = (byte)((ChatChannel >> 16) % 256); bytes[i++] = (byte)((ChatChannel >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += Helpers.FieldToString(ObjectName, "ObjectName") + "\n"; output += "ImageID: " + ImageID.ToString() + "\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += Helpers.FieldToString(Message, "Message") + "\n"; output += Helpers.FieldToString(LastName, "LastName") + "\n"; output += Helpers.FieldToString(FirstName, "FirstName") + "\n"; output += "ChatChannel: " + ChatChannel.ToString() + "\n"; output = output.Trim(); return output; } } /// Buttons block public class ButtonsBlock { private byte[] _buttonlabel; /// ButtonLabel field public byte[] ButtonLabel { get { return _buttonlabel; } set { if (value == null) { _buttonlabel = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _buttonlabel = new byte[value.Length]; Array.Copy(value, _buttonlabel, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (ButtonLabel != null) { length += 1 + ButtonLabel.Length; } return length; } } /// Default constructor public ButtonsBlock() { } /// Constructor for building the block from a byte array public ButtonsBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _buttonlabel = new byte[length]; Array.Copy(bytes, i, _buttonlabel, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ButtonLabel == null) { Console.WriteLine("Warning: ButtonLabel is null, in " + this.GetType()); } bytes[i++] = (byte)ButtonLabel.Length; Array.Copy(ButtonLabel, 0, bytes, i, ButtonLabel.Length); i += ButtonLabel.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Buttons --\n"; output += Helpers.FieldToString(ButtonLabel, "ButtonLabel") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ScriptDialog public override PacketType Type { get { return PacketType.ScriptDialog; } } /// Data block public DataBlock Data; /// Buttons block public ButtonsBlock[] Buttons; /// Default constructor public ScriptDialogPacket() { Header = new LowHeader(); Header.ID = 235; Header.Reliable = true; Header.Zerocoded = true; Data = new DataBlock(); Buttons = new ButtonsBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ScriptDialogPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); int count = (int)bytes[i++]; Buttons = new ButtonsBlock[count]; for (int j = 0; j < count; j++) { Buttons[j] = new ButtonsBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public ScriptDialogPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); int count = (int)bytes[i++]; Buttons = new ButtonsBlock[count]; for (int j = 0; j < count; j++) { Buttons[j] = new ButtonsBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length;; length++; for (int j = 0; j < Buttons.Length; j++) { length += Buttons[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); bytes[i++] = (byte)Buttons.Length; for (int j = 0; j < Buttons.Length; j++) { Buttons[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ScriptDialog ---\n"; output += Data.ToString() + "\n"; for (int j = 0; j < Buttons.Length; j++) { output += Buttons[j].ToString() + "\n"; } return output; } } /// ScriptDialogReply packet public class ScriptDialogReplyPacket : Packet { /// Data block public class DataBlock { /// ObjectID field public LLUUID ObjectID; private byte[] _buttonlabel; /// ButtonLabel field public byte[] ButtonLabel { get { return _buttonlabel; } set { if (value == null) { _buttonlabel = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _buttonlabel = new byte[value.Length]; Array.Copy(value, _buttonlabel, value.Length); } } } /// ButtonIndex field public int ButtonIndex; /// ChatChannel field public int ChatChannel; /// Length of this block serialized in bytes public int Length { get { int length = 24; if (ButtonLabel != null) { length += 1 + ButtonLabel.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { ObjectID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _buttonlabel = new byte[length]; Array.Copy(bytes, i, _buttonlabel, 0, length); i += length; ButtonIndex = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ChatChannel = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; if(ButtonLabel == null) { Console.WriteLine("Warning: ButtonLabel is null, in " + this.GetType()); } bytes[i++] = (byte)ButtonLabel.Length; Array.Copy(ButtonLabel, 0, bytes, i, ButtonLabel.Length); i += ButtonLabel.Length; bytes[i++] = (byte)(ButtonIndex % 256); bytes[i++] = (byte)((ButtonIndex >> 8) % 256); bytes[i++] = (byte)((ButtonIndex >> 16) % 256); bytes[i++] = (byte)((ButtonIndex >> 24) % 256); bytes[i++] = (byte)(ChatChannel % 256); bytes[i++] = (byte)((ChatChannel >> 8) % 256); bytes[i++] = (byte)((ChatChannel >> 16) % 256); bytes[i++] = (byte)((ChatChannel >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += Helpers.FieldToString(ButtonLabel, "ButtonLabel") + "\n"; output += "ButtonIndex: " + ButtonIndex.ToString() + "\n"; output += "ChatChannel: " + ChatChannel.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ScriptDialogReply public override PacketType Type { get { return PacketType.ScriptDialogReply; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ScriptDialogReplyPacket() { Header = new LowHeader(); Header.ID = 236; Header.Reliable = true; Header.Zerocoded = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ScriptDialogReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ScriptDialogReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ScriptDialogReply ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ForceScriptControlRelease packet public class ForceScriptControlReleasePacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ForceScriptControlRelease public override PacketType Type { get { return PacketType.ForceScriptControlRelease; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ForceScriptControlReleasePacket() { Header = new LowHeader(); Header.ID = 237; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ForceScriptControlReleasePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ForceScriptControlReleasePacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ForceScriptControlRelease ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// RevokePermissions packet public class RevokePermissionsPacket : Packet { /// Data block public class DataBlock { /// ObjectPermissions field public uint ObjectPermissions; /// ObjectID field public LLUUID ObjectID; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { ObjectPermissions = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ObjectID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ObjectPermissions % 256); bytes[i++] = (byte)((ObjectPermissions >> 8) % 256); bytes[i++] = (byte)((ObjectPermissions >> 16) % 256); bytes[i++] = (byte)((ObjectPermissions >> 24) % 256); if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "ObjectPermissions: " + ObjectPermissions.ToString() + "\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RevokePermissions public override PacketType Type { get { return PacketType.RevokePermissions; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RevokePermissionsPacket() { Header = new LowHeader(); Header.ID = 238; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RevokePermissionsPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RevokePermissionsPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RevokePermissions ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// LoadURL packet public class LoadURLPacket : Packet { /// Data block public class DataBlock { private byte[] _url; /// URL field public byte[] URL { get { return _url; } set { if (value == null) { _url = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _url = new byte[value.Length]; Array.Copy(value, _url, value.Length); } } } private byte[] _objectname; /// ObjectName field public byte[] ObjectName { get { return _objectname; } set { if (value == null) { _objectname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _objectname = new byte[value.Length]; Array.Copy(value, _objectname, value.Length); } } } /// OwnerIsGroup field public bool OwnerIsGroup; /// ObjectID field public LLUUID ObjectID; private byte[] _message; /// Message field public byte[] Message { get { return _message; } set { if (value == null) { _message = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _message = new byte[value.Length]; Array.Copy(value, _message, value.Length); } } } /// OwnerID field public LLUUID OwnerID; /// Length of this block serialized in bytes public int Length { get { int length = 33; if (URL != null) { length += 1 + URL.Length; } if (ObjectName != null) { length += 1 + ObjectName.Length; } if (Message != null) { length += 1 + Message.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _url = new byte[length]; Array.Copy(bytes, i, _url, 0, length); i += length; length = (ushort)bytes[i++]; _objectname = new byte[length]; Array.Copy(bytes, i, _objectname, 0, length); i += length; OwnerIsGroup = (bytes[i++] != 0) ? (bool)true : (bool)false; ObjectID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _message = new byte[length]; Array.Copy(bytes, i, _message, 0, length); i += length; OwnerID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(URL == null) { Console.WriteLine("Warning: URL is null, in " + this.GetType()); } bytes[i++] = (byte)URL.Length; Array.Copy(URL, 0, bytes, i, URL.Length); i += URL.Length; if(ObjectName == null) { Console.WriteLine("Warning: ObjectName is null, in " + this.GetType()); } bytes[i++] = (byte)ObjectName.Length; Array.Copy(ObjectName, 0, bytes, i, ObjectName.Length); i += ObjectName.Length; bytes[i++] = (byte)((OwnerIsGroup) ? 1 : 0); if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; if(Message == null) { Console.WriteLine("Warning: Message is null, in " + this.GetType()); } bytes[i++] = (byte)Message.Length; Array.Copy(Message, 0, bytes, i, Message.Length); i += Message.Length; if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += Helpers.FieldToString(URL, "URL") + "\n"; output += Helpers.FieldToString(ObjectName, "ObjectName") + "\n"; output += "OwnerIsGroup: " + OwnerIsGroup.ToString() + "\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += Helpers.FieldToString(Message, "Message") + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.LoadURL public override PacketType Type { get { return PacketType.LoadURL; } } /// Data block public DataBlock Data; /// Default constructor public LoadURLPacket() { Header = new LowHeader(); Header.ID = 239; Header.Reliable = true; Data = new DataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public LoadURLPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public LoadURLPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- LoadURL ---\n"; output += Data.ToString() + "\n"; return output; } } /// ScriptTeleportRequest packet public class ScriptTeleportRequestPacket : Packet { /// Data block public class DataBlock { private byte[] _objectname; /// ObjectName field public byte[] ObjectName { get { return _objectname; } set { if (value == null) { _objectname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _objectname = new byte[value.Length]; Array.Copy(value, _objectname, value.Length); } } } private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// LookAt field public LLVector3 LookAt; /// SimPosition field public LLVector3 SimPosition; /// Length of this block serialized in bytes public int Length { get { int length = 24; if (ObjectName != null) { length += 1 + ObjectName.Length; } if (SimName != null) { length += 1 + SimName.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _objectname = new byte[length]; Array.Copy(bytes, i, _objectname, 0, length); i += length; length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; LookAt = new LLVector3(bytes, i); i += 12; SimPosition = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectName == null) { Console.WriteLine("Warning: ObjectName is null, in " + this.GetType()); } bytes[i++] = (byte)ObjectName.Length; Array.Copy(ObjectName, 0, bytes, i, ObjectName.Length); i += ObjectName.Length; if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; if(LookAt == null) { Console.WriteLine("Warning: LookAt is null, in " + this.GetType()); } Array.Copy(LookAt.GetBytes(), 0, bytes, i, 12); i += 12; if(SimPosition == null) { Console.WriteLine("Warning: SimPosition is null, in " + this.GetType()); } Array.Copy(SimPosition.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += Helpers.FieldToString(ObjectName, "ObjectName") + "\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "LookAt: " + LookAt.ToString() + "\n"; output += "SimPosition: " + SimPosition.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ScriptTeleportRequest public override PacketType Type { get { return PacketType.ScriptTeleportRequest; } } /// Data block public DataBlock Data; /// Default constructor public ScriptTeleportRequestPacket() { Header = new LowHeader(); Header.ID = 240; Header.Reliable = true; Data = new DataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ScriptTeleportRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ScriptTeleportRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ScriptTeleportRequest ---\n"; output += Data.ToString() + "\n"; return output; } } /// ParcelOverlay packet public class ParcelOverlayPacket : Packet { /// ParcelData block public class ParcelDataBlock { private byte[] _data; /// Data field public byte[] Data { get { return _data; } set { if (value == null) { _data = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _data = new byte[value.Length]; Array.Copy(value, _data, value.Length); } } } /// SequenceID field public int SequenceID; /// Length of this block serialized in bytes public int Length { get { int length = 4; if (Data != null) { length += 2 + Data.Length; } return length; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _data = new byte[length]; Array.Copy(bytes, i, _data, 0, length); i += length; SequenceID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Data == null) { Console.WriteLine("Warning: Data is null, in " + this.GetType()); } bytes[i++] = (byte)(Data.Length % 256); bytes[i++] = (byte)((Data.Length >> 8) % 256); Array.Copy(Data, 0, bytes, i, Data.Length); i += Data.Length; bytes[i++] = (byte)(SequenceID % 256); bytes[i++] = (byte)((SequenceID >> 8) % 256); bytes[i++] = (byte)((SequenceID >> 16) % 256); bytes[i++] = (byte)((SequenceID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += Helpers.FieldToString(Data, "Data") + "\n"; output += "SequenceID: " + SequenceID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelOverlay public override PacketType Type { get { return PacketType.ParcelOverlay; } } /// ParcelData block public ParcelDataBlock ParcelData; /// Default constructor public ParcelOverlayPacket() { Header = new LowHeader(); Header.ID = 241; Header.Reliable = true; Header.Zerocoded = true; ParcelData = new ParcelDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelOverlayPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ParcelData = new ParcelDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelOverlayPacket(Header head, byte[] bytes, ref int i) { Header = head; ParcelData = new ParcelDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ParcelData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ParcelData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelOverlay ---\n"; output += ParcelData.ToString() + "\n"; return output; } } /// ParcelPropertiesRequestByID packet public class ParcelPropertiesRequestByIDPacket : Packet { /// ParcelData block public class ParcelDataBlock { /// LocalID field public int LocalID; /// SequenceID field public int SequenceID; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SequenceID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); bytes[i++] = (byte)(SequenceID % 256); bytes[i++] = (byte)((SequenceID >> 8) % 256); bytes[i++] = (byte)((SequenceID >> 16) % 256); bytes[i++] = (byte)((SequenceID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "SequenceID: " + SequenceID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelPropertiesRequestByID public override PacketType Type { get { return PacketType.ParcelPropertiesRequestByID; } } /// ParcelData block public ParcelDataBlock ParcelData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelPropertiesRequestByIDPacket() { Header = new LowHeader(); Header.ID = 242; Header.Reliable = true; Header.Zerocoded = true; ParcelData = new ParcelDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelPropertiesRequestByIDPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelPropertiesRequestByIDPacket(Header head, byte[] bytes, ref int i) { Header = head; ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ParcelData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ParcelData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelPropertiesRequestByID ---\n"; output += ParcelData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ParcelPropertiesUpdate packet public class ParcelPropertiesUpdatePacket : Packet { /// ParcelData block public class ParcelDataBlock { /// MediaID field public LLUUID MediaID; /// UserLookAt field public LLVector3 UserLookAt; private byte[] _mediaurl; /// MediaURL field public byte[] MediaURL { get { return _mediaurl; } set { if (value == null) { _mediaurl = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _mediaurl = new byte[value.Length]; Array.Copy(value, _mediaurl, value.Length); } } } /// LocalID field public int LocalID; /// UserLocation field public LLVector3 UserLocation; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } private byte[] _desc; /// Desc field public byte[] Desc { get { return _desc; } set { if (value == null) { _desc = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _desc = new byte[value.Length]; Array.Copy(value, _desc, value.Length); } } } /// Category field public byte Category; /// GroupID field public LLUUID GroupID; /// SalePrice field public int SalePrice; /// SnapshotID field public LLUUID SnapshotID; /// Flags field public uint Flags; /// LandingType field public byte LandingType; /// AuthBuyerID field public LLUUID AuthBuyerID; /// PassHours field public float PassHours; /// ParcelFlags field public uint ParcelFlags; /// PassPrice field public int PassPrice; /// MediaAutoScale field public byte MediaAutoScale; private byte[] _musicurl; /// MusicURL field public byte[] MusicURL { get { return _musicurl; } set { if (value == null) { _musicurl = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _musicurl = new byte[value.Length]; Array.Copy(value, _musicurl, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 115; if (MediaURL != null) { length += 1 + MediaURL.Length; } if (Name != null) { length += 1 + Name.Length; } if (Desc != null) { length += 1 + Desc.Length; } if (MusicURL != null) { length += 1 + MusicURL.Length; } return length; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { int length; try { MediaID = new LLUUID(bytes, i); i += 16; UserLookAt = new LLVector3(bytes, i); i += 12; length = (ushort)bytes[i++]; _mediaurl = new byte[length]; Array.Copy(bytes, i, _mediaurl, 0, length); i += length; LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); UserLocation = new LLVector3(bytes, i); i += 12; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; length = (ushort)bytes[i++]; _desc = new byte[length]; Array.Copy(bytes, i, _desc, 0, length); i += length; Category = (byte)bytes[i++]; GroupID = new LLUUID(bytes, i); i += 16; SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SnapshotID = new LLUUID(bytes, i); i += 16; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); LandingType = (byte)bytes[i++]; AuthBuyerID = new LLUUID(bytes, i); i += 16; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); PassHours = BitConverter.ToSingle(bytes, i); i += 4; ParcelFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); PassPrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); MediaAutoScale = (byte)bytes[i++]; length = (ushort)bytes[i++]; _musicurl = new byte[length]; Array.Copy(bytes, i, _musicurl, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; if(MediaID == null) { Console.WriteLine("Warning: MediaID is null, in " + this.GetType()); } Array.Copy(MediaID.GetBytes(), 0, bytes, i, 16); i += 16; if(UserLookAt == null) { Console.WriteLine("Warning: UserLookAt is null, in " + this.GetType()); } Array.Copy(UserLookAt.GetBytes(), 0, bytes, i, 12); i += 12; if(MediaURL == null) { Console.WriteLine("Warning: MediaURL is null, in " + this.GetType()); } bytes[i++] = (byte)MediaURL.Length; Array.Copy(MediaURL, 0, bytes, i, MediaURL.Length); i += MediaURL.Length; bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); if(UserLocation == null) { Console.WriteLine("Warning: UserLocation is null, in " + this.GetType()); } Array.Copy(UserLocation.GetBytes(), 0, bytes, i, 12); i += 12; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(Desc == null) { Console.WriteLine("Warning: Desc is null, in " + this.GetType()); } bytes[i++] = (byte)Desc.Length; Array.Copy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; bytes[i++] = Category; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(SalePrice % 256); bytes[i++] = (byte)((SalePrice >> 8) % 256); bytes[i++] = (byte)((SalePrice >> 16) % 256); bytes[i++] = (byte)((SalePrice >> 24) % 256); if(SnapshotID == null) { Console.WriteLine("Warning: SnapshotID is null, in " + this.GetType()); } Array.Copy(SnapshotID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); bytes[i++] = LandingType; if(AuthBuyerID == null) { Console.WriteLine("Warning: AuthBuyerID is null, in " + this.GetType()); } Array.Copy(AuthBuyerID.GetBytes(), 0, bytes, i, 16); i += 16; ba = BitConverter.GetBytes(PassHours); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(ParcelFlags % 256); bytes[i++] = (byte)((ParcelFlags >> 8) % 256); bytes[i++] = (byte)((ParcelFlags >> 16) % 256); bytes[i++] = (byte)((ParcelFlags >> 24) % 256); bytes[i++] = (byte)(PassPrice % 256); bytes[i++] = (byte)((PassPrice >> 8) % 256); bytes[i++] = (byte)((PassPrice >> 16) % 256); bytes[i++] = (byte)((PassPrice >> 24) % 256); bytes[i++] = MediaAutoScale; if(MusicURL == null) { Console.WriteLine("Warning: MusicURL is null, in " + this.GetType()); } bytes[i++] = (byte)MusicURL.Length; Array.Copy(MusicURL, 0, bytes, i, MusicURL.Length); i += MusicURL.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "MediaID: " + MediaID.ToString() + "\n"; output += "UserLookAt: " + UserLookAt.ToString() + "\n"; output += Helpers.FieldToString(MediaURL, "MediaURL") + "\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "UserLocation: " + UserLocation.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += Helpers.FieldToString(Desc, "Desc") + "\n"; output += "Category: " + Category.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "SalePrice: " + SalePrice.ToString() + "\n"; output += "SnapshotID: " + SnapshotID.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "LandingType: " + LandingType.ToString() + "\n"; output += "AuthBuyerID: " + AuthBuyerID.ToString() + "\n"; output += "PassHours: " + PassHours.ToString() + "\n"; output += "ParcelFlags: " + ParcelFlags.ToString() + "\n"; output += "PassPrice: " + PassPrice.ToString() + "\n"; output += "MediaAutoScale: " + MediaAutoScale.ToString() + "\n"; output += Helpers.FieldToString(MusicURL, "MusicURL") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelPropertiesUpdate public override PacketType Type { get { return PacketType.ParcelPropertiesUpdate; } } /// ParcelData block public ParcelDataBlock ParcelData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelPropertiesUpdatePacket() { Header = new LowHeader(); Header.ID = 243; Header.Reliable = true; Header.Zerocoded = true; ParcelData = new ParcelDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelPropertiesUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelPropertiesUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ParcelData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ParcelData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelPropertiesUpdate ---\n"; output += ParcelData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ParcelReturnObjects packet public class ParcelReturnObjectsPacket : Packet { /// TaskIDs block public class TaskIDsBlock { /// TaskID field public LLUUID TaskID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public TaskIDsBlock() { } /// Constructor for building the block from a byte array public TaskIDsBlock(byte[] bytes, ref int i) { try { TaskID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TaskID == null) { Console.WriteLine("Warning: TaskID is null, in " + this.GetType()); } Array.Copy(TaskID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TaskIDs --\n"; output += "TaskID: " + TaskID.ToString() + "\n"; output = output.Trim(); return output; } } /// ParcelData block public class ParcelDataBlock { /// LocalID field public int LocalID; /// ReturnType field public uint ReturnType; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ReturnType = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); bytes[i++] = (byte)(ReturnType % 256); bytes[i++] = (byte)((ReturnType >> 8) % 256); bytes[i++] = (byte)((ReturnType >> 16) % 256); bytes[i++] = (byte)((ReturnType >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "ReturnType: " + ReturnType.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// OwnerIDs block public class OwnerIDsBlock { /// OwnerID field public LLUUID OwnerID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public OwnerIDsBlock() { } /// Constructor for building the block from a byte array public OwnerIDsBlock(byte[] bytes, ref int i) { try { OwnerID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- OwnerIDs --\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelReturnObjects public override PacketType Type { get { return PacketType.ParcelReturnObjects; } } /// TaskIDs block public TaskIDsBlock[] TaskIDs; /// ParcelData block public ParcelDataBlock ParcelData; /// AgentData block public AgentDataBlock AgentData; /// OwnerIDs block public OwnerIDsBlock[] OwnerIDs; /// Default constructor public ParcelReturnObjectsPacket() { Header = new LowHeader(); Header.ID = 244; Header.Reliable = true; Header.Zerocoded = true; TaskIDs = new TaskIDsBlock[0]; ParcelData = new ParcelDataBlock(); AgentData = new AgentDataBlock(); OwnerIDs = new OwnerIDsBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelReturnObjectsPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; TaskIDs = new TaskIDsBlock[count]; for (int j = 0; j < count; j++) { TaskIDs[j] = new TaskIDsBlock(bytes, ref i); } ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); count = (int)bytes[i++]; OwnerIDs = new OwnerIDsBlock[count]; for (int j = 0; j < count; j++) { OwnerIDs[j] = new OwnerIDsBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public ParcelReturnObjectsPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; TaskIDs = new TaskIDsBlock[count]; for (int j = 0; j < count; j++) { TaskIDs[j] = new TaskIDsBlock(bytes, ref i); } ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); count = (int)bytes[i++]; OwnerIDs = new OwnerIDsBlock[count]; for (int j = 0; j < count; j++) { OwnerIDs[j] = new OwnerIDsBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ParcelData.Length; length += AgentData.Length;; length++; for (int j = 0; j < TaskIDs.Length; j++) { length += TaskIDs[j].Length; } length++; for (int j = 0; j < OwnerIDs.Length; j++) { length += OwnerIDs[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)TaskIDs.Length; for (int j = 0; j < TaskIDs.Length; j++) { TaskIDs[j].ToBytes(bytes, ref i); } ParcelData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); bytes[i++] = (byte)OwnerIDs.Length; for (int j = 0; j < OwnerIDs.Length; j++) { OwnerIDs[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelReturnObjects ---\n"; for (int j = 0; j < TaskIDs.Length; j++) { output += TaskIDs[j].ToString() + "\n"; } output += ParcelData.ToString() + "\n"; output += AgentData.ToString() + "\n"; for (int j = 0; j < OwnerIDs.Length; j++) { output += OwnerIDs[j].ToString() + "\n"; } return output; } } /// ParcelSetOtherCleanTime packet public class ParcelSetOtherCleanTimePacket : Packet { /// ParcelData block public class ParcelDataBlock { /// LocalID field public int LocalID; /// OtherCleanTime field public int OtherCleanTime; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OtherCleanTime = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); bytes[i++] = (byte)(OtherCleanTime % 256); bytes[i++] = (byte)((OtherCleanTime >> 8) % 256); bytes[i++] = (byte)((OtherCleanTime >> 16) % 256); bytes[i++] = (byte)((OtherCleanTime >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "OtherCleanTime: " + OtherCleanTime.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelSetOtherCleanTime public override PacketType Type { get { return PacketType.ParcelSetOtherCleanTime; } } /// ParcelData block public ParcelDataBlock ParcelData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelSetOtherCleanTimePacket() { Header = new LowHeader(); Header.ID = 245; Header.Reliable = true; Header.Zerocoded = true; ParcelData = new ParcelDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelSetOtherCleanTimePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelSetOtherCleanTimePacket(Header head, byte[] bytes, ref int i) { Header = head; ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ParcelData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ParcelData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelSetOtherCleanTime ---\n"; output += ParcelData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ParcelDisableObjects packet public class ParcelDisableObjectsPacket : Packet { /// TaskIDs block public class TaskIDsBlock { /// TaskID field public LLUUID TaskID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public TaskIDsBlock() { } /// Constructor for building the block from a byte array public TaskIDsBlock(byte[] bytes, ref int i) { try { TaskID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TaskID == null) { Console.WriteLine("Warning: TaskID is null, in " + this.GetType()); } Array.Copy(TaskID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TaskIDs --\n"; output += "TaskID: " + TaskID.ToString() + "\n"; output = output.Trim(); return output; } } /// ParcelData block public class ParcelDataBlock { /// LocalID field public int LocalID; /// ReturnType field public uint ReturnType; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ReturnType = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); bytes[i++] = (byte)(ReturnType % 256); bytes[i++] = (byte)((ReturnType >> 8) % 256); bytes[i++] = (byte)((ReturnType >> 16) % 256); bytes[i++] = (byte)((ReturnType >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "ReturnType: " + ReturnType.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// OwnerIDs block public class OwnerIDsBlock { /// OwnerID field public LLUUID OwnerID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public OwnerIDsBlock() { } /// Constructor for building the block from a byte array public OwnerIDsBlock(byte[] bytes, ref int i) { try { OwnerID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- OwnerIDs --\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelDisableObjects public override PacketType Type { get { return PacketType.ParcelDisableObjects; } } /// TaskIDs block public TaskIDsBlock[] TaskIDs; /// ParcelData block public ParcelDataBlock ParcelData; /// AgentData block public AgentDataBlock AgentData; /// OwnerIDs block public OwnerIDsBlock[] OwnerIDs; /// Default constructor public ParcelDisableObjectsPacket() { Header = new LowHeader(); Header.ID = 246; Header.Reliable = true; Header.Zerocoded = true; TaskIDs = new TaskIDsBlock[0]; ParcelData = new ParcelDataBlock(); AgentData = new AgentDataBlock(); OwnerIDs = new OwnerIDsBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelDisableObjectsPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; TaskIDs = new TaskIDsBlock[count]; for (int j = 0; j < count; j++) { TaskIDs[j] = new TaskIDsBlock(bytes, ref i); } ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); count = (int)bytes[i++]; OwnerIDs = new OwnerIDsBlock[count]; for (int j = 0; j < count; j++) { OwnerIDs[j] = new OwnerIDsBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public ParcelDisableObjectsPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; TaskIDs = new TaskIDsBlock[count]; for (int j = 0; j < count; j++) { TaskIDs[j] = new TaskIDsBlock(bytes, ref i); } ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); count = (int)bytes[i++]; OwnerIDs = new OwnerIDsBlock[count]; for (int j = 0; j < count; j++) { OwnerIDs[j] = new OwnerIDsBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ParcelData.Length; length += AgentData.Length;; length++; for (int j = 0; j < TaskIDs.Length; j++) { length += TaskIDs[j].Length; } length++; for (int j = 0; j < OwnerIDs.Length; j++) { length += OwnerIDs[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)TaskIDs.Length; for (int j = 0; j < TaskIDs.Length; j++) { TaskIDs[j].ToBytes(bytes, ref i); } ParcelData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); bytes[i++] = (byte)OwnerIDs.Length; for (int j = 0; j < OwnerIDs.Length; j++) { OwnerIDs[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelDisableObjects ---\n"; for (int j = 0; j < TaskIDs.Length; j++) { output += TaskIDs[j].ToString() + "\n"; } output += ParcelData.ToString() + "\n"; output += AgentData.ToString() + "\n"; for (int j = 0; j < OwnerIDs.Length; j++) { output += OwnerIDs[j].ToString() + "\n"; } return output; } } /// ParcelSelectObjects packet public class ParcelSelectObjectsPacket : Packet { /// ReturnIDs block public class ReturnIDsBlock { /// ReturnID field public LLUUID ReturnID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ReturnIDsBlock() { } /// Constructor for building the block from a byte array public ReturnIDsBlock(byte[] bytes, ref int i) { try { ReturnID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ReturnID == null) { Console.WriteLine("Warning: ReturnID is null, in " + this.GetType()); } Array.Copy(ReturnID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ReturnIDs --\n"; output += "ReturnID: " + ReturnID.ToString() + "\n"; output = output.Trim(); return output; } } /// ParcelData block public class ParcelDataBlock { /// LocalID field public int LocalID; /// ReturnType field public uint ReturnType; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ReturnType = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); bytes[i++] = (byte)(ReturnType % 256); bytes[i++] = (byte)((ReturnType >> 8) % 256); bytes[i++] = (byte)((ReturnType >> 16) % 256); bytes[i++] = (byte)((ReturnType >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "ReturnType: " + ReturnType.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelSelectObjects public override PacketType Type { get { return PacketType.ParcelSelectObjects; } } /// ReturnIDs block public ReturnIDsBlock[] ReturnIDs; /// ParcelData block public ParcelDataBlock ParcelData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelSelectObjectsPacket() { Header = new LowHeader(); Header.ID = 247; Header.Reliable = true; Header.Zerocoded = true; ReturnIDs = new ReturnIDsBlock[0]; ParcelData = new ParcelDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelSelectObjectsPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ReturnIDs = new ReturnIDsBlock[count]; for (int j = 0; j < count; j++) { ReturnIDs[j] = new ReturnIDsBlock(bytes, ref i); } ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelSelectObjectsPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ReturnIDs = new ReturnIDsBlock[count]; for (int j = 0; j < count; j++) { ReturnIDs[j] = new ReturnIDsBlock(bytes, ref i); } ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ParcelData.Length; length += AgentData.Length;; length++; for (int j = 0; j < ReturnIDs.Length; j++) { length += ReturnIDs[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ReturnIDs.Length; for (int j = 0; j < ReturnIDs.Length; j++) { ReturnIDs[j].ToBytes(bytes, ref i); } ParcelData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelSelectObjects ---\n"; for (int j = 0; j < ReturnIDs.Length; j++) { output += ReturnIDs[j].ToString() + "\n"; } output += ParcelData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// EstateCovenantRequest packet public class EstateCovenantRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.EstateCovenantRequest public override PacketType Type { get { return PacketType.EstateCovenantRequest; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public EstateCovenantRequestPacket() { Header = new LowHeader(); Header.ID = 248; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public EstateCovenantRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public EstateCovenantRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- EstateCovenantRequest ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// EstateCovenantReply packet public class EstateCovenantReplyPacket : Packet { /// Data block public class DataBlock { /// CovenantID field public LLUUID CovenantID; /// CovenantTimestamp field public uint CovenantTimestamp; private byte[] _estatename; /// EstateName field public byte[] EstateName { get { return _estatename; } set { if (value == null) { _estatename = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _estatename = new byte[value.Length]; Array.Copy(value, _estatename, value.Length); } } } /// EstateOwnerID field public LLUUID EstateOwnerID; /// Length of this block serialized in bytes public int Length { get { int length = 36; if (EstateName != null) { length += 1 + EstateName.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { CovenantID = new LLUUID(bytes, i); i += 16; CovenantTimestamp = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _estatename = new byte[length]; Array.Copy(bytes, i, _estatename, 0, length); i += length; EstateOwnerID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(CovenantID == null) { Console.WriteLine("Warning: CovenantID is null, in " + this.GetType()); } Array.Copy(CovenantID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(CovenantTimestamp % 256); bytes[i++] = (byte)((CovenantTimestamp >> 8) % 256); bytes[i++] = (byte)((CovenantTimestamp >> 16) % 256); bytes[i++] = (byte)((CovenantTimestamp >> 24) % 256); if(EstateName == null) { Console.WriteLine("Warning: EstateName is null, in " + this.GetType()); } bytes[i++] = (byte)EstateName.Length; Array.Copy(EstateName, 0, bytes, i, EstateName.Length); i += EstateName.Length; if(EstateOwnerID == null) { Console.WriteLine("Warning: EstateOwnerID is null, in " + this.GetType()); } Array.Copy(EstateOwnerID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "CovenantID: " + CovenantID.ToString() + "\n"; output += "CovenantTimestamp: " + CovenantTimestamp.ToString() + "\n"; output += Helpers.FieldToString(EstateName, "EstateName") + "\n"; output += "EstateOwnerID: " + EstateOwnerID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.EstateCovenantReply public override PacketType Type { get { return PacketType.EstateCovenantReply; } } /// Data block public DataBlock Data; /// Default constructor public EstateCovenantReplyPacket() { Header = new LowHeader(); Header.ID = 249; Header.Reliable = true; Data = new DataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public EstateCovenantReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public EstateCovenantReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- EstateCovenantReply ---\n"; output += Data.ToString() + "\n"; return output; } } /// ForceObjectSelect packet public class ForceObjectSelectPacket : Packet { /// Data block public class DataBlock { /// LocalID field public uint LocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// Header block public class HeaderBlock { /// ResetList field public bool ResetList; /// Length of this block serialized in bytes public int Length { get { return 1; } } /// Default constructor public HeaderBlock() { } /// Constructor for building the block from a byte array public HeaderBlock(byte[] bytes, ref int i) { try { ResetList = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((ResetList) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Header --\n"; output += "ResetList: " + ResetList.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ForceObjectSelect public override PacketType Type { get { return PacketType.ForceObjectSelect; } } /// Data block public DataBlock[] Data; /// Header block public HeaderBlock _Header; /// Default constructor public ForceObjectSelectPacket() { Header = new LowHeader(); Header.ID = 250; Header.Reliable = true; Data = new DataBlock[0]; _Header = new HeaderBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ForceObjectSelectPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } _Header = new HeaderBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ForceObjectSelectPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } _Header = new HeaderBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += _Header.Length;; length++; for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)Data.Length; for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } _Header.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ForceObjectSelect ---\n"; for (int j = 0; j < Data.Length; j++) { output += Data[j].ToString() + "\n"; } output += _Header.ToString() + "\n"; return output; } } /// ParcelBuyPass packet public class ParcelBuyPassPacket : Packet { /// ParcelData block public class ParcelDataBlock { /// LocalID field public int LocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelBuyPass public override PacketType Type { get { return PacketType.ParcelBuyPass; } } /// ParcelData block public ParcelDataBlock ParcelData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelBuyPassPacket() { Header = new LowHeader(); Header.ID = 251; Header.Reliable = true; ParcelData = new ParcelDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelBuyPassPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelBuyPassPacket(Header head, byte[] bytes, ref int i) { Header = head; ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ParcelData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ParcelData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelBuyPass ---\n"; output += ParcelData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ParcelDeedToGroup packet public class ParcelDeedToGroupPacket : Packet { /// Data block public class DataBlock { /// LocalID field public int LocalID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelDeedToGroup public override PacketType Type { get { return PacketType.ParcelDeedToGroup; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelDeedToGroupPacket() { Header = new LowHeader(); Header.ID = 252; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelDeedToGroupPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelDeedToGroupPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelDeedToGroup ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ParcelReclaim packet public class ParcelReclaimPacket : Packet { /// Data block public class DataBlock { /// LocalID field public int LocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelReclaim public override PacketType Type { get { return PacketType.ParcelReclaim; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelReclaimPacket() { Header = new LowHeader(); Header.ID = 253; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelReclaimPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelReclaimPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelReclaim ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ParcelClaim packet public class ParcelClaimPacket : Packet { /// Data block public class DataBlock { /// IsGroupOwned field public bool IsGroupOwned; /// GroupID field public LLUUID GroupID; /// Final field public bool Final; /// Length of this block serialized in bytes public int Length { get { return 18; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { IsGroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; GroupID = new LLUUID(bytes, i); i += 16; Final = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((IsGroupOwned) ? 1 : 0); if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((Final) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "IsGroupOwned: " + IsGroupOwned.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "Final: " + Final.ToString() + "\n"; output = output.Trim(); return output; } } /// ParcelData block public class ParcelDataBlock { /// East field public float East; /// West field public float West; /// North field public float North; /// South field public float South; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); East = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); West = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); North = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); South = BitConverter.ToSingle(bytes, i); i += 4; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(East); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(West); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(North); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(South); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "East: " + East.ToString() + "\n"; output += "West: " + West.ToString() + "\n"; output += "North: " + North.ToString() + "\n"; output += "South: " + South.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelClaim public override PacketType Type { get { return PacketType.ParcelClaim; } } /// Data block public DataBlock Data; /// ParcelData block public ParcelDataBlock[] ParcelData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelClaimPacket() { Header = new LowHeader(); Header.ID = 254; Header.Reliable = true; Header.Zerocoded = true; Data = new DataBlock(); ParcelData = new ParcelDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelClaimPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelClaimPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; length++; for (int j = 0; j < ParcelData.Length; j++) { length += ParcelData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); bytes[i++] = (byte)ParcelData.Length; for (int j = 0; j < ParcelData.Length; j++) { ParcelData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelClaim ---\n"; output += Data.ToString() + "\n"; for (int j = 0; j < ParcelData.Length; j++) { output += ParcelData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ParcelJoin packet public class ParcelJoinPacket : Packet { /// ParcelData block public class ParcelDataBlock { /// East field public float East; /// West field public float West; /// North field public float North; /// South field public float South; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); East = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); West = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); North = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); South = BitConverter.ToSingle(bytes, i); i += 4; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(East); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(West); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(North); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(South); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "East: " + East.ToString() + "\n"; output += "West: " + West.ToString() + "\n"; output += "North: " + North.ToString() + "\n"; output += "South: " + South.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelJoin public override PacketType Type { get { return PacketType.ParcelJoin; } } /// ParcelData block public ParcelDataBlock ParcelData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelJoinPacket() { Header = new LowHeader(); Header.ID = 255; Header.Reliable = true; ParcelData = new ParcelDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelJoinPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelJoinPacket(Header head, byte[] bytes, ref int i) { Header = head; ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ParcelData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ParcelData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelJoin ---\n"; output += ParcelData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ParcelDivide packet public class ParcelDividePacket : Packet { /// ParcelData block public class ParcelDataBlock { /// East field public float East; /// West field public float West; /// North field public float North; /// South field public float South; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); East = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); West = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); North = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); South = BitConverter.ToSingle(bytes, i); i += 4; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(East); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(West); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(North); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(South); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "East: " + East.ToString() + "\n"; output += "West: " + West.ToString() + "\n"; output += "North: " + North.ToString() + "\n"; output += "South: " + South.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelDivide public override PacketType Type { get { return PacketType.ParcelDivide; } } /// ParcelData block public ParcelDataBlock ParcelData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelDividePacket() { Header = new LowHeader(); Header.ID = 256; Header.Reliable = true; ParcelData = new ParcelDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelDividePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelDividePacket(Header head, byte[] bytes, ref int i) { Header = head; ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ParcelData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ParcelData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelDivide ---\n"; output += ParcelData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ParcelRelease packet public class ParcelReleasePacket : Packet { /// Data block public class DataBlock { /// LocalID field public int LocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelRelease public override PacketType Type { get { return PacketType.ParcelRelease; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelReleasePacket() { Header = new LowHeader(); Header.ID = 257; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelReleasePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelReleasePacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelRelease ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ParcelBuy packet public class ParcelBuyPacket : Packet { /// Data block public class DataBlock { /// RemoveContribution field public bool RemoveContribution; /// LocalID field public int LocalID; /// IsGroupOwned field public bool IsGroupOwned; /// GroupID field public LLUUID GroupID; /// Final field public bool Final; /// Length of this block serialized in bytes public int Length { get { return 23; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { RemoveContribution = (bytes[i++] != 0) ? (bool)true : (bool)false; LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); IsGroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; GroupID = new LLUUID(bytes, i); i += 16; Final = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((RemoveContribution) ? 1 : 0); bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); bytes[i++] = (byte)((IsGroupOwned) ? 1 : 0); if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((Final) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "RemoveContribution: " + RemoveContribution.ToString() + "\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "IsGroupOwned: " + IsGroupOwned.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "Final: " + Final.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelBuy public override PacketType Type { get { return PacketType.ParcelBuy; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelBuyPacket() { Header = new LowHeader(); Header.ID = 258; Header.Reliable = true; Header.Zerocoded = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelBuyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelBuyPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelBuy ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ParcelGodForceOwner packet public class ParcelGodForceOwnerPacket : Packet { /// Data block public class DataBlock { /// LocalID field public int LocalID; /// OwnerID field public LLUUID OwnerID; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelGodForceOwner public override PacketType Type { get { return PacketType.ParcelGodForceOwner; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelGodForceOwnerPacket() { Header = new LowHeader(); Header.ID = 259; Header.Reliable = true; Header.Zerocoded = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelGodForceOwnerPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelGodForceOwnerPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelGodForceOwner ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ParcelAccessListRequest packet public class ParcelAccessListRequestPacket : Packet { /// Data block public class DataBlock { /// LocalID field public int LocalID; /// SequenceID field public int SequenceID; /// Flags field public uint Flags; /// Length of this block serialized in bytes public int Length { get { return 12; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SequenceID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); bytes[i++] = (byte)(SequenceID % 256); bytes[i++] = (byte)((SequenceID >> 8) % 256); bytes[i++] = (byte)((SequenceID >> 16) % 256); bytes[i++] = (byte)((SequenceID >> 24) % 256); bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "SequenceID: " + SequenceID.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelAccessListRequest public override PacketType Type { get { return PacketType.ParcelAccessListRequest; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelAccessListRequestPacket() { Header = new LowHeader(); Header.ID = 260; Header.Reliable = true; Header.Zerocoded = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelAccessListRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelAccessListRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelAccessListRequest ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ParcelAccessListReply packet public class ParcelAccessListReplyPacket : Packet { /// Data block public class DataBlock { /// AgentID field public LLUUID AgentID; /// LocalID field public int LocalID; /// SequenceID field public int SequenceID; /// Flags field public uint Flags; /// Length of this block serialized in bytes public int Length { get { return 28; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SequenceID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); bytes[i++] = (byte)(SequenceID % 256); bytes[i++] = (byte)((SequenceID >> 8) % 256); bytes[i++] = (byte)((SequenceID >> 16) % 256); bytes[i++] = (byte)((SequenceID >> 24) % 256); bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "SequenceID: " + SequenceID.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output = output.Trim(); return output; } } /// List block public class ListBlock { /// ID field public LLUUID ID; /// Time field public int Time; /// Flags field public uint Flags; /// Length of this block serialized in bytes public int Length { get { return 24; } } /// Default constructor public ListBlock() { } /// Constructor for building the block from a byte array public ListBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; Time = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Time % 256); bytes[i++] = (byte)((Time >> 8) % 256); bytes[i++] = (byte)((Time >> 16) % 256); bytes[i++] = (byte)((Time >> 24) % 256); bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- List --\n"; output += "ID: " + ID.ToString() + "\n"; output += "Time: " + Time.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelAccessListReply public override PacketType Type { get { return PacketType.ParcelAccessListReply; } } /// Data block public DataBlock Data; /// List block public ListBlock[] List; /// Default constructor public ParcelAccessListReplyPacket() { Header = new LowHeader(); Header.ID = 261; Header.Reliable = true; Header.Zerocoded = true; Data = new DataBlock(); List = new ListBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelAccessListReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); int count = (int)bytes[i++]; List = new ListBlock[count]; for (int j = 0; j < count; j++) { List[j] = new ListBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public ParcelAccessListReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); int count = (int)bytes[i++]; List = new ListBlock[count]; for (int j = 0; j < count; j++) { List[j] = new ListBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length;; length++; for (int j = 0; j < List.Length; j++) { length += List[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); bytes[i++] = (byte)List.Length; for (int j = 0; j < List.Length; j++) { List[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelAccessListReply ---\n"; output += Data.ToString() + "\n"; for (int j = 0; j < List.Length; j++) { output += List[j].ToString() + "\n"; } return output; } } /// ParcelAccessListUpdate packet public class ParcelAccessListUpdatePacket : Packet { /// Data block public class DataBlock { /// LocalID field public int LocalID; /// Sections field public int Sections; /// SequenceID field public int SequenceID; /// Flags field public uint Flags; /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Sections = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SequenceID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); bytes[i++] = (byte)(Sections % 256); bytes[i++] = (byte)((Sections >> 8) % 256); bytes[i++] = (byte)((Sections >> 16) % 256); bytes[i++] = (byte)((Sections >> 24) % 256); bytes[i++] = (byte)(SequenceID % 256); bytes[i++] = (byte)((SequenceID >> 8) % 256); bytes[i++] = (byte)((SequenceID >> 16) % 256); bytes[i++] = (byte)((SequenceID >> 24) % 256); bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "Sections: " + Sections.ToString() + "\n"; output += "SequenceID: " + SequenceID.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } /// List block public class ListBlock { /// ID field public LLUUID ID; /// Time field public int Time; /// Flags field public uint Flags; /// Length of this block serialized in bytes public int Length { get { return 24; } } /// Default constructor public ListBlock() { } /// Constructor for building the block from a byte array public ListBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; Time = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Time % 256); bytes[i++] = (byte)((Time >> 8) % 256); bytes[i++] = (byte)((Time >> 16) % 256); bytes[i++] = (byte)((Time >> 24) % 256); bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- List --\n"; output += "ID: " + ID.ToString() + "\n"; output += "Time: " + Time.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelAccessListUpdate public override PacketType Type { get { return PacketType.ParcelAccessListUpdate; } } /// Data block public DataBlock Data; /// List block public ListBlock[] List; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelAccessListUpdatePacket() { Header = new LowHeader(); Header.ID = 262; Header.Reliable = true; Header.Zerocoded = true; Data = new DataBlock(); List = new ListBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelAccessListUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); int count = (int)bytes[i++]; List = new ListBlock[count]; for (int j = 0; j < count; j++) { List[j] = new ListBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelAccessListUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); int count = (int)bytes[i++]; List = new ListBlock[count]; for (int j = 0; j < count; j++) { List[j] = new ListBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; length++; for (int j = 0; j < List.Length; j++) { length += List[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); bytes[i++] = (byte)List.Length; for (int j = 0; j < List.Length; j++) { List[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelAccessListUpdate ---\n"; output += Data.ToString() + "\n"; for (int j = 0; j < List.Length; j++) { output += List[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ParcelDwellRequest packet public class ParcelDwellRequestPacket : Packet { /// Data block public class DataBlock { /// LocalID field public int LocalID; /// ParcelID field public LLUUID ParcelID; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ParcelID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelDwellRequest public override PacketType Type { get { return PacketType.ParcelDwellRequest; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelDwellRequestPacket() { Header = new LowHeader(); Header.ID = 263; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelDwellRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelDwellRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelDwellRequest ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ParcelDwellReply packet public class ParcelDwellReplyPacket : Packet { /// Data block public class DataBlock { /// LocalID field public int LocalID; /// ParcelID field public LLUUID ParcelID; /// Dwell field public float Dwell; /// Length of this block serialized in bytes public int Length { get { return 24; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ParcelID = new LLUUID(bytes, i); i += 16; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Dwell = BitConverter.ToSingle(bytes, i); i += 4; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; ba = BitConverter.GetBytes(Dwell); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output += "Dwell: " + Dwell.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelDwellReply public override PacketType Type { get { return PacketType.ParcelDwellReply; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelDwellReplyPacket() { Header = new LowHeader(); Header.ID = 264; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelDwellReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelDwellReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelDwellReply ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// RequestParcelTransfer packet public class RequestParcelTransferPacket : Packet { /// Data block public class DataBlock { /// ReservedNewbie field public bool ReservedNewbie; /// BillableArea field public int BillableArea; /// ActualArea field public int ActualArea; /// OwnerID field public LLUUID OwnerID; /// DestID field public LLUUID DestID; /// Amount field public int Amount; /// Flags field public byte Flags; /// Final field public bool Final; /// SourceID field public LLUUID SourceID; /// TransactionID field public LLUUID TransactionID; /// TransactionTime field public uint TransactionTime; /// TransactionType field public int TransactionType; /// Length of this block serialized in bytes public int Length { get { return 87; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { ReservedNewbie = (bytes[i++] != 0) ? (bool)true : (bool)false; BillableArea = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ActualArea = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerID = new LLUUID(bytes, i); i += 16; DestID = new LLUUID(bytes, i); i += 16; Amount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Flags = (byte)bytes[i++]; Final = (bytes[i++] != 0) ? (bool)true : (bool)false; SourceID = new LLUUID(bytes, i); i += 16; TransactionID = new LLUUID(bytes, i); i += 16; TransactionTime = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TransactionType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((ReservedNewbie) ? 1 : 0); bytes[i++] = (byte)(BillableArea % 256); bytes[i++] = (byte)((BillableArea >> 8) % 256); bytes[i++] = (byte)((BillableArea >> 16) % 256); bytes[i++] = (byte)((BillableArea >> 24) % 256); bytes[i++] = (byte)(ActualArea % 256); bytes[i++] = (byte)((ActualArea >> 8) % 256); bytes[i++] = (byte)((ActualArea >> 16) % 256); bytes[i++] = (byte)((ActualArea >> 24) % 256); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(DestID == null) { Console.WriteLine("Warning: DestID is null, in " + this.GetType()); } Array.Copy(DestID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Amount % 256); bytes[i++] = (byte)((Amount >> 8) % 256); bytes[i++] = (byte)((Amount >> 16) % 256); bytes[i++] = (byte)((Amount >> 24) % 256); bytes[i++] = Flags; bytes[i++] = (byte)((Final) ? 1 : 0); if(SourceID == null) { Console.WriteLine("Warning: SourceID is null, in " + this.GetType()); } Array.Copy(SourceID.GetBytes(), 0, bytes, i, 16); i += 16; if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(TransactionTime % 256); bytes[i++] = (byte)((TransactionTime >> 8) % 256); bytes[i++] = (byte)((TransactionTime >> 16) % 256); bytes[i++] = (byte)((TransactionTime >> 24) % 256); bytes[i++] = (byte)(TransactionType % 256); bytes[i++] = (byte)((TransactionType >> 8) % 256); bytes[i++] = (byte)((TransactionType >> 16) % 256); bytes[i++] = (byte)((TransactionType >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "ReservedNewbie: " + ReservedNewbie.ToString() + "\n"; output += "BillableArea: " + BillableArea.ToString() + "\n"; output += "ActualArea: " + ActualArea.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "DestID: " + DestID.ToString() + "\n"; output += "Amount: " + Amount.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "Final: " + Final.ToString() + "\n"; output += "SourceID: " + SourceID.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output += "TransactionTime: " + TransactionTime.ToString() + "\n"; output += "TransactionType: " + TransactionType.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RequestParcelTransfer public override PacketType Type { get { return PacketType.RequestParcelTransfer; } } /// Data block public DataBlock Data; /// Default constructor public RequestParcelTransferPacket() { Header = new LowHeader(); Header.ID = 265; Header.Reliable = true; Header.Zerocoded = true; Data = new DataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RequestParcelTransferPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RequestParcelTransferPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RequestParcelTransfer ---\n"; output += Data.ToString() + "\n"; return output; } } /// UpdateParcel packet public class UpdateParcelPacket : Packet { /// ParcelData block public class ParcelDataBlock { /// ReservedNewbie field public bool ReservedNewbie; /// GroupOwned field public bool GroupOwned; /// RegionX field public float RegionX; /// RegionY field public float RegionY; /// AllowPublish field public bool AllowPublish; /// BillableArea field public int BillableArea; /// ShowDir field public bool ShowDir; /// ActualArea field public int ActualArea; /// ParcelID field public LLUUID ParcelID; /// UserLocation field public LLVector3 UserLocation; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// RegionHandle field public ulong RegionHandle; /// Category field public byte Category; /// AuthorizedBuyerID field public LLUUID AuthorizedBuyerID; /// SalePrice field public int SalePrice; /// OwnerID field public LLUUID OwnerID; /// IsForSale field public bool IsForSale; /// Status field public byte Status; /// SnapshotID field public LLUUID SnapshotID; /// MaturePublish field public bool MaturePublish; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } private byte[] _musicurl; /// MusicURL field public byte[] MusicURL { get { return _musicurl; } set { if (value == null) { _musicurl = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _musicurl = new byte[value.Length]; Array.Copy(value, _musicurl, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 112; if (Name != null) { length += 1 + Name.Length; } if (Description != null) { length += 1 + Description.Length; } if (MusicURL != null) { length += 1 + MusicURL.Length; } return length; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { int length; try { ReservedNewbie = (bytes[i++] != 0) ? (bool)true : (bool)false; GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); RegionX = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); RegionY = BitConverter.ToSingle(bytes, i); i += 4; AllowPublish = (bytes[i++] != 0) ? (bool)true : (bool)false; BillableArea = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ShowDir = (bytes[i++] != 0) ? (bool)true : (bool)false; ActualArea = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ParcelID = new LLUUID(bytes, i); i += 16; UserLocation = new LLVector3(bytes, i); i += 12; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); Category = (byte)bytes[i++]; AuthorizedBuyerID = new LLUUID(bytes, i); i += 16; SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerID = new LLUUID(bytes, i); i += 16; IsForSale = (bytes[i++] != 0) ? (bool)true : (bool)false; Status = (byte)bytes[i++]; SnapshotID = new LLUUID(bytes, i); i += 16; MaturePublish = (bytes[i++] != 0) ? (bool)true : (bool)false; length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; length = (ushort)bytes[i++]; _musicurl = new byte[length]; Array.Copy(bytes, i, _musicurl, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = (byte)((ReservedNewbie) ? 1 : 0); bytes[i++] = (byte)((GroupOwned) ? 1 : 0); ba = BitConverter.GetBytes(RegionX); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(RegionY); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)((AllowPublish) ? 1 : 0); bytes[i++] = (byte)(BillableArea % 256); bytes[i++] = (byte)((BillableArea >> 8) % 256); bytes[i++] = (byte)((BillableArea >> 16) % 256); bytes[i++] = (byte)((BillableArea >> 24) % 256); bytes[i++] = (byte)((ShowDir) ? 1 : 0); bytes[i++] = (byte)(ActualArea % 256); bytes[i++] = (byte)((ActualArea >> 8) % 256); bytes[i++] = (byte)((ActualArea >> 16) % 256); bytes[i++] = (byte)((ActualArea >> 24) % 256); if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; if(UserLocation == null) { Console.WriteLine("Warning: UserLocation is null, in " + this.GetType()); } Array.Copy(UserLocation.GetBytes(), 0, bytes, i, 12); i += 12; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); bytes[i++] = Category; if(AuthorizedBuyerID == null) { Console.WriteLine("Warning: AuthorizedBuyerID is null, in " + this.GetType()); } Array.Copy(AuthorizedBuyerID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(SalePrice % 256); bytes[i++] = (byte)((SalePrice >> 8) % 256); bytes[i++] = (byte)((SalePrice >> 16) % 256); bytes[i++] = (byte)((SalePrice >> 24) % 256); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((IsForSale) ? 1 : 0); bytes[i++] = Status; if(SnapshotID == null) { Console.WriteLine("Warning: SnapshotID is null, in " + this.GetType()); } Array.Copy(SnapshotID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((MaturePublish) ? 1 : 0); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; if(MusicURL == null) { Console.WriteLine("Warning: MusicURL is null, in " + this.GetType()); } bytes[i++] = (byte)MusicURL.Length; Array.Copy(MusicURL, 0, bytes, i, MusicURL.Length); i += MusicURL.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "ReservedNewbie: " + ReservedNewbie.ToString() + "\n"; output += "GroupOwned: " + GroupOwned.ToString() + "\n"; output += "RegionX: " + RegionX.ToString() + "\n"; output += "RegionY: " + RegionY.ToString() + "\n"; output += "AllowPublish: " + AllowPublish.ToString() + "\n"; output += "BillableArea: " + BillableArea.ToString() + "\n"; output += "ShowDir: " + ShowDir.ToString() + "\n"; output += "ActualArea: " + ActualArea.ToString() + "\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output += "UserLocation: " + UserLocation.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output += "Category: " + Category.ToString() + "\n"; output += "AuthorizedBuyerID: " + AuthorizedBuyerID.ToString() + "\n"; output += "SalePrice: " + SalePrice.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "IsForSale: " + IsForSale.ToString() + "\n"; output += "Status: " + Status.ToString() + "\n"; output += "SnapshotID: " + SnapshotID.ToString() + "\n"; output += "MaturePublish: " + MaturePublish.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += Helpers.FieldToString(MusicURL, "MusicURL") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UpdateParcel public override PacketType Type { get { return PacketType.UpdateParcel; } } /// ParcelData block public ParcelDataBlock ParcelData; /// Default constructor public UpdateParcelPacket() { Header = new LowHeader(); Header.ID = 266; Header.Reliable = true; Header.Zerocoded = true; ParcelData = new ParcelDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UpdateParcelPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ParcelData = new ParcelDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public UpdateParcelPacket(Header head, byte[] bytes, ref int i) { Header = head; ParcelData = new ParcelDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ParcelData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ParcelData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UpdateParcel ---\n"; output += ParcelData.ToString() + "\n"; return output; } } /// RemoveParcel packet public class RemoveParcelPacket : Packet { /// ParcelData block public class ParcelDataBlock { /// ParcelID field public LLUUID ParcelID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { ParcelID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RemoveParcel public override PacketType Type { get { return PacketType.RemoveParcel; } } /// ParcelData block public ParcelDataBlock[] ParcelData; /// Default constructor public RemoveParcelPacket() { Header = new LowHeader(); Header.ID = 267; Header.Reliable = true; ParcelData = new ParcelDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RemoveParcelPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public RemoveParcelPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < ParcelData.Length; j++) { length += ParcelData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ParcelData.Length; for (int j = 0; j < ParcelData.Length; j++) { ParcelData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RemoveParcel ---\n"; for (int j = 0; j < ParcelData.Length; j++) { output += ParcelData[j].ToString() + "\n"; } return output; } } /// MergeParcel packet public class MergeParcelPacket : Packet { /// MasterParcelData block public class MasterParcelDataBlock { /// MasterID field public LLUUID MasterID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public MasterParcelDataBlock() { } /// Constructor for building the block from a byte array public MasterParcelDataBlock(byte[] bytes, ref int i) { try { MasterID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(MasterID == null) { Console.WriteLine("Warning: MasterID is null, in " + this.GetType()); } Array.Copy(MasterID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MasterParcelData --\n"; output += "MasterID: " + MasterID.ToString() + "\n"; output = output.Trim(); return output; } } /// SlaveParcelData block public class SlaveParcelDataBlock { /// SlaveID field public LLUUID SlaveID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public SlaveParcelDataBlock() { } /// Constructor for building the block from a byte array public SlaveParcelDataBlock(byte[] bytes, ref int i) { try { SlaveID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(SlaveID == null) { Console.WriteLine("Warning: SlaveID is null, in " + this.GetType()); } Array.Copy(SlaveID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- SlaveParcelData --\n"; output += "SlaveID: " + SlaveID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MergeParcel public override PacketType Type { get { return PacketType.MergeParcel; } } /// MasterParcelData block public MasterParcelDataBlock MasterParcelData; /// SlaveParcelData block public SlaveParcelDataBlock[] SlaveParcelData; /// Default constructor public MergeParcelPacket() { Header = new LowHeader(); Header.ID = 268; Header.Reliable = true; MasterParcelData = new MasterParcelDataBlock(); SlaveParcelData = new SlaveParcelDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MergeParcelPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MasterParcelData = new MasterParcelDataBlock(bytes, ref i); int count = (int)bytes[i++]; SlaveParcelData = new SlaveParcelDataBlock[count]; for (int j = 0; j < count; j++) { SlaveParcelData[j] = new SlaveParcelDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public MergeParcelPacket(Header head, byte[] bytes, ref int i) { Header = head; MasterParcelData = new MasterParcelDataBlock(bytes, ref i); int count = (int)bytes[i++]; SlaveParcelData = new SlaveParcelDataBlock[count]; for (int j = 0; j < count; j++) { SlaveParcelData[j] = new SlaveParcelDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MasterParcelData.Length;; length++; for (int j = 0; j < SlaveParcelData.Length; j++) { length += SlaveParcelData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MasterParcelData.ToBytes(bytes, ref i); bytes[i++] = (byte)SlaveParcelData.Length; for (int j = 0; j < SlaveParcelData.Length; j++) { SlaveParcelData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MergeParcel ---\n"; output += MasterParcelData.ToString() + "\n"; for (int j = 0; j < SlaveParcelData.Length; j++) { output += SlaveParcelData[j].ToString() + "\n"; } return output; } } /// LogParcelChanges packet public class LogParcelChangesPacket : Packet { /// ParcelData block public class ParcelDataBlock { /// ActualArea field public int ActualArea; /// ParcelID field public LLUUID ParcelID; /// IsOwnerGroup field public bool IsOwnerGroup; /// OwnerID field public LLUUID OwnerID; /// Action field public sbyte Action; /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { return 54; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { ActualArea = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ParcelID = new LLUUID(bytes, i); i += 16; IsOwnerGroup = (bytes[i++] != 0) ? (bool)true : (bool)false; OwnerID = new LLUUID(bytes, i); i += 16; Action = (sbyte)bytes[i++]; TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ActualArea % 256); bytes[i++] = (byte)((ActualArea >> 8) % 256); bytes[i++] = (byte)((ActualArea >> 16) % 256); bytes[i++] = (byte)((ActualArea >> 24) % 256); if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((IsOwnerGroup) ? 1 : 0); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)Action; if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "ActualArea: " + ActualArea.ToString() + "\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output += "IsOwnerGroup: " + IsOwnerGroup.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "Action: " + Action.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } /// RegionData block public class RegionDataBlock { /// RegionHandle field public ulong RegionHandle; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public RegionDataBlock() { } /// Constructor for building the block from a byte array public RegionDataBlock(byte[] bytes, ref int i) { try { RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionData --\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.LogParcelChanges public override PacketType Type { get { return PacketType.LogParcelChanges; } } /// ParcelData block public ParcelDataBlock[] ParcelData; /// RegionData block public RegionDataBlock RegionData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public LogParcelChangesPacket() { Header = new LowHeader(); Header.ID = 269; Header.Reliable = true; Header.Zerocoded = true; ParcelData = new ParcelDataBlock[0]; RegionData = new RegionDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public LogParcelChangesPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } RegionData = new RegionDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public LogParcelChangesPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } RegionData = new RegionDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += RegionData.Length; length += AgentData.Length;; length++; for (int j = 0; j < ParcelData.Length; j++) { length += ParcelData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ParcelData.Length; for (int j = 0; j < ParcelData.Length; j++) { ParcelData[j].ToBytes(bytes, ref i); } RegionData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- LogParcelChanges ---\n"; for (int j = 0; j < ParcelData.Length; j++) { output += ParcelData[j].ToString() + "\n"; } output += RegionData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// CheckParcelSales packet public class CheckParcelSalesPacket : Packet { /// RegionData block public class RegionDataBlock { /// RegionHandle field public ulong RegionHandle; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public RegionDataBlock() { } /// Constructor for building the block from a byte array public RegionDataBlock(byte[] bytes, ref int i) { try { RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionData --\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.CheckParcelSales public override PacketType Type { get { return PacketType.CheckParcelSales; } } /// RegionData block public RegionDataBlock[] RegionData; /// Default constructor public CheckParcelSalesPacket() { Header = new LowHeader(); Header.ID = 270; Header.Reliable = true; RegionData = new RegionDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public CheckParcelSalesPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; RegionData = new RegionDataBlock[count]; for (int j = 0; j < count; j++) { RegionData[j] = new RegionDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public CheckParcelSalesPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; RegionData = new RegionDataBlock[count]; for (int j = 0; j < count; j++) { RegionData[j] = new RegionDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < RegionData.Length; j++) { length += RegionData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)RegionData.Length; for (int j = 0; j < RegionData.Length; j++) { RegionData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- CheckParcelSales ---\n"; for (int j = 0; j < RegionData.Length; j++) { output += RegionData[j].ToString() + "\n"; } return output; } } /// ParcelSales packet public class ParcelSalesPacket : Packet { /// ParcelData block public class ParcelDataBlock { /// ParcelID field public LLUUID ParcelID; /// BuyerID field public LLUUID BuyerID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { ParcelID = new LLUUID(bytes, i); i += 16; BuyerID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; if(BuyerID == null) { Console.WriteLine("Warning: BuyerID is null, in " + this.GetType()); } Array.Copy(BuyerID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output += "BuyerID: " + BuyerID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelSales public override PacketType Type { get { return PacketType.ParcelSales; } } /// ParcelData block public ParcelDataBlock[] ParcelData; /// Default constructor public ParcelSalesPacket() { Header = new LowHeader(); Header.ID = 271; Header.Reliable = true; ParcelData = new ParcelDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelSalesPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public ParcelSalesPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < ParcelData.Length; j++) { length += ParcelData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ParcelData.Length; for (int j = 0; j < ParcelData.Length; j++) { ParcelData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelSales ---\n"; for (int j = 0; j < ParcelData.Length; j++) { output += ParcelData[j].ToString() + "\n"; } return output; } } /// ParcelGodMarkAsContent packet public class ParcelGodMarkAsContentPacket : Packet { /// ParcelData block public class ParcelDataBlock { /// LocalID field public int LocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelGodMarkAsContent public override PacketType Type { get { return PacketType.ParcelGodMarkAsContent; } } /// ParcelData block public ParcelDataBlock ParcelData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelGodMarkAsContentPacket() { Header = new LowHeader(); Header.ID = 272; Header.Reliable = true; ParcelData = new ParcelDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelGodMarkAsContentPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelGodMarkAsContentPacket(Header head, byte[] bytes, ref int i) { Header = head; ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ParcelData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ParcelData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelGodMarkAsContent ---\n"; output += ParcelData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ParcelGodReserveForNewbie packet public class ParcelGodReserveForNewbiePacket : Packet { /// ParcelData block public class ParcelDataBlock { /// LocalID field public int LocalID; /// SnapshotID field public LLUUID SnapshotID; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SnapshotID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); if(SnapshotID == null) { Console.WriteLine("Warning: SnapshotID is null, in " + this.GetType()); } Array.Copy(SnapshotID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "SnapshotID: " + SnapshotID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelGodReserveForNewbie public override PacketType Type { get { return PacketType.ParcelGodReserveForNewbie; } } /// ParcelData block public ParcelDataBlock ParcelData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelGodReserveForNewbiePacket() { Header = new LowHeader(); Header.ID = 273; Header.Reliable = true; ParcelData = new ParcelDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelGodReserveForNewbiePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelGodReserveForNewbiePacket(Header head, byte[] bytes, ref int i) { Header = head; ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ParcelData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ParcelData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelGodReserveForNewbie ---\n"; output += ParcelData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ViewerStartAuction packet public class ViewerStartAuctionPacket : Packet { /// ParcelData block public class ParcelDataBlock { /// LocalID field public int LocalID; /// SnapshotID field public LLUUID SnapshotID; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SnapshotID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); if(SnapshotID == null) { Console.WriteLine("Warning: SnapshotID is null, in " + this.GetType()); } Array.Copy(SnapshotID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "SnapshotID: " + SnapshotID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ViewerStartAuction public override PacketType Type { get { return PacketType.ViewerStartAuction; } } /// ParcelData block public ParcelDataBlock ParcelData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ViewerStartAuctionPacket() { Header = new LowHeader(); Header.ID = 274; Header.Reliable = true; ParcelData = new ParcelDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ViewerStartAuctionPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ViewerStartAuctionPacket(Header head, byte[] bytes, ref int i) { Header = head; ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ParcelData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ParcelData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ViewerStartAuction ---\n"; output += ParcelData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// StartAuction packet public class StartAuctionPacket : Packet { /// ParcelData block public class ParcelDataBlock { /// ParcelID field public LLUUID ParcelID; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// SnapshotID field public LLUUID SnapshotID; /// Length of this block serialized in bytes public int Length { get { int length = 32; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { int length; try { ParcelID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; SnapshotID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(SnapshotID == null) { Console.WriteLine("Warning: SnapshotID is null, in " + this.GetType()); } Array.Copy(SnapshotID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "SnapshotID: " + SnapshotID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.StartAuction public override PacketType Type { get { return PacketType.StartAuction; } } /// ParcelData block public ParcelDataBlock ParcelData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public StartAuctionPacket() { Header = new LowHeader(); Header.ID = 275; Header.Reliable = true; ParcelData = new ParcelDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public StartAuctionPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public StartAuctionPacket(Header head, byte[] bytes, ref int i) { Header = head; ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ParcelData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ParcelData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- StartAuction ---\n"; output += ParcelData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ConfirmAuctionStart packet public class ConfirmAuctionStartPacket : Packet { /// AuctionData block public class AuctionDataBlock { /// ParcelID field public LLUUID ParcelID; /// AuctionID field public uint AuctionID; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public AuctionDataBlock() { } /// Constructor for building the block from a byte array public AuctionDataBlock(byte[] bytes, ref int i) { try { ParcelID = new LLUUID(bytes, i); i += 16; AuctionID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(AuctionID % 256); bytes[i++] = (byte)((AuctionID >> 8) % 256); bytes[i++] = (byte)((AuctionID >> 16) % 256); bytes[i++] = (byte)((AuctionID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AuctionData --\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output += "AuctionID: " + AuctionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ConfirmAuctionStart public override PacketType Type { get { return PacketType.ConfirmAuctionStart; } } /// AuctionData block public AuctionDataBlock AuctionData; /// Default constructor public ConfirmAuctionStartPacket() { Header = new LowHeader(); Header.ID = 276; Header.Reliable = true; AuctionData = new AuctionDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ConfirmAuctionStartPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AuctionData = new AuctionDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ConfirmAuctionStartPacket(Header head, byte[] bytes, ref int i) { Header = head; AuctionData = new AuctionDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AuctionData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AuctionData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ConfirmAuctionStart ---\n"; output += AuctionData.ToString() + "\n"; return output; } } /// CompleteAuction packet public class CompleteAuctionPacket : Packet { /// ParcelData block public class ParcelDataBlock { /// ParcelID field public LLUUID ParcelID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { ParcelID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.CompleteAuction public override PacketType Type { get { return PacketType.CompleteAuction; } } /// ParcelData block public ParcelDataBlock[] ParcelData; /// Default constructor public CompleteAuctionPacket() { Header = new LowHeader(); Header.ID = 277; Header.Reliable = true; ParcelData = new ParcelDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public CompleteAuctionPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public CompleteAuctionPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < ParcelData.Length; j++) { length += ParcelData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ParcelData.Length; for (int j = 0; j < ParcelData.Length; j++) { ParcelData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- CompleteAuction ---\n"; for (int j = 0; j < ParcelData.Length; j++) { output += ParcelData[j].ToString() + "\n"; } return output; } } /// CancelAuction packet public class CancelAuctionPacket : Packet { /// ParcelData block public class ParcelDataBlock { /// ParcelID field public LLUUID ParcelID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { ParcelID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.CancelAuction public override PacketType Type { get { return PacketType.CancelAuction; } } /// ParcelData block public ParcelDataBlock[] ParcelData; /// Default constructor public CancelAuctionPacket() { Header = new LowHeader(); Header.ID = 278; Header.Reliable = true; ParcelData = new ParcelDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public CancelAuctionPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public CancelAuctionPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < ParcelData.Length; j++) { length += ParcelData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ParcelData.Length; for (int j = 0; j < ParcelData.Length; j++) { ParcelData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- CancelAuction ---\n"; for (int j = 0; j < ParcelData.Length; j++) { output += ParcelData[j].ToString() + "\n"; } return output; } } /// CheckParcelAuctions packet public class CheckParcelAuctionsPacket : Packet { /// RegionData block public class RegionDataBlock { /// RegionHandle field public ulong RegionHandle; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public RegionDataBlock() { } /// Constructor for building the block from a byte array public RegionDataBlock(byte[] bytes, ref int i) { try { RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionData --\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.CheckParcelAuctions public override PacketType Type { get { return PacketType.CheckParcelAuctions; } } /// RegionData block public RegionDataBlock[] RegionData; /// Default constructor public CheckParcelAuctionsPacket() { Header = new LowHeader(); Header.ID = 279; Header.Reliable = true; RegionData = new RegionDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public CheckParcelAuctionsPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; RegionData = new RegionDataBlock[count]; for (int j = 0; j < count; j++) { RegionData[j] = new RegionDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public CheckParcelAuctionsPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; RegionData = new RegionDataBlock[count]; for (int j = 0; j < count; j++) { RegionData[j] = new RegionDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < RegionData.Length; j++) { length += RegionData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)RegionData.Length; for (int j = 0; j < RegionData.Length; j++) { RegionData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- CheckParcelAuctions ---\n"; for (int j = 0; j < RegionData.Length; j++) { output += RegionData[j].ToString() + "\n"; } return output; } } /// ParcelAuctions packet public class ParcelAuctionsPacket : Packet { /// ParcelData block public class ParcelDataBlock { /// ParcelID field public LLUUID ParcelID; /// WinnerID field public LLUUID WinnerID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { ParcelID = new LLUUID(bytes, i); i += 16; WinnerID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; if(WinnerID == null) { Console.WriteLine("Warning: WinnerID is null, in " + this.GetType()); } Array.Copy(WinnerID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output += "WinnerID: " + WinnerID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelAuctions public override PacketType Type { get { return PacketType.ParcelAuctions; } } /// ParcelData block public ParcelDataBlock[] ParcelData; /// Default constructor public ParcelAuctionsPacket() { Header = new LowHeader(); Header.ID = 280; Header.Reliable = true; ParcelData = new ParcelDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelAuctionsPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public ParcelAuctionsPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < ParcelData.Length; j++) { length += ParcelData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ParcelData.Length; for (int j = 0; j < ParcelData.Length; j++) { ParcelData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelAuctions ---\n"; for (int j = 0; j < ParcelData.Length; j++) { output += ParcelData[j].ToString() + "\n"; } return output; } } /// UUIDNameRequest packet public class UUIDNameRequestPacket : Packet { /// UUIDNameBlock block public class UUIDNameBlockBlock { /// ID field public LLUUID ID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public UUIDNameBlockBlock() { } /// Constructor for building the block from a byte array public UUIDNameBlockBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- UUIDNameBlock --\n"; output += "ID: " + ID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UUIDNameRequest public override PacketType Type { get { return PacketType.UUIDNameRequest; } } /// UUIDNameBlock block public UUIDNameBlockBlock[] UUIDNameBlock; /// Default constructor public UUIDNameRequestPacket() { Header = new LowHeader(); Header.ID = 281; Header.Reliable = true; UUIDNameBlock = new UUIDNameBlockBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UUIDNameRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; UUIDNameBlock = new UUIDNameBlockBlock[count]; for (int j = 0; j < count; j++) { UUIDNameBlock[j] = new UUIDNameBlockBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public UUIDNameRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; UUIDNameBlock = new UUIDNameBlockBlock[count]; for (int j = 0; j < count; j++) { UUIDNameBlock[j] = new UUIDNameBlockBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < UUIDNameBlock.Length; j++) { length += UUIDNameBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)UUIDNameBlock.Length; for (int j = 0; j < UUIDNameBlock.Length; j++) { UUIDNameBlock[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UUIDNameRequest ---\n"; for (int j = 0; j < UUIDNameBlock.Length; j++) { output += UUIDNameBlock[j].ToString() + "\n"; } return output; } } /// UUIDNameReply packet public class UUIDNameReplyPacket : Packet { /// UUIDNameBlock block public class UUIDNameBlockBlock { /// ID field public LLUUID ID; private byte[] _lastname; /// LastName field public byte[] LastName { get { return _lastname; } set { if (value == null) { _lastname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _lastname = new byte[value.Length]; Array.Copy(value, _lastname, value.Length); } } } private byte[] _firstname; /// FirstName field public byte[] FirstName { get { return _firstname; } set { if (value == null) { _firstname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _firstname = new byte[value.Length]; Array.Copy(value, _firstname, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 16; if (LastName != null) { length += 1 + LastName.Length; } if (FirstName != null) { length += 1 + FirstName.Length; } return length; } } /// Default constructor public UUIDNameBlockBlock() { } /// Constructor for building the block from a byte array public UUIDNameBlockBlock(byte[] bytes, ref int i) { int length; try { ID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _lastname = new byte[length]; Array.Copy(bytes, i, _lastname, 0, length); i += length; length = (ushort)bytes[i++]; _firstname = new byte[length]; Array.Copy(bytes, i, _firstname, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; if(LastName == null) { Console.WriteLine("Warning: LastName is null, in " + this.GetType()); } bytes[i++] = (byte)LastName.Length; Array.Copy(LastName, 0, bytes, i, LastName.Length); i += LastName.Length; if(FirstName == null) { Console.WriteLine("Warning: FirstName is null, in " + this.GetType()); } bytes[i++] = (byte)FirstName.Length; Array.Copy(FirstName, 0, bytes, i, FirstName.Length); i += FirstName.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- UUIDNameBlock --\n"; output += "ID: " + ID.ToString() + "\n"; output += Helpers.FieldToString(LastName, "LastName") + "\n"; output += Helpers.FieldToString(FirstName, "FirstName") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UUIDNameReply public override PacketType Type { get { return PacketType.UUIDNameReply; } } /// UUIDNameBlock block public UUIDNameBlockBlock[] UUIDNameBlock; /// Default constructor public UUIDNameReplyPacket() { Header = new LowHeader(); Header.ID = 282; Header.Reliable = true; UUIDNameBlock = new UUIDNameBlockBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UUIDNameReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; UUIDNameBlock = new UUIDNameBlockBlock[count]; for (int j = 0; j < count; j++) { UUIDNameBlock[j] = new UUIDNameBlockBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public UUIDNameReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; UUIDNameBlock = new UUIDNameBlockBlock[count]; for (int j = 0; j < count; j++) { UUIDNameBlock[j] = new UUIDNameBlockBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < UUIDNameBlock.Length; j++) { length += UUIDNameBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)UUIDNameBlock.Length; for (int j = 0; j < UUIDNameBlock.Length; j++) { UUIDNameBlock[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UUIDNameReply ---\n"; for (int j = 0; j < UUIDNameBlock.Length; j++) { output += UUIDNameBlock[j].ToString() + "\n"; } return output; } } /// UUIDGroupNameRequest packet public class UUIDGroupNameRequestPacket : Packet { /// UUIDNameBlock block public class UUIDNameBlockBlock { /// ID field public LLUUID ID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public UUIDNameBlockBlock() { } /// Constructor for building the block from a byte array public UUIDNameBlockBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- UUIDNameBlock --\n"; output += "ID: " + ID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UUIDGroupNameRequest public override PacketType Type { get { return PacketType.UUIDGroupNameRequest; } } /// UUIDNameBlock block public UUIDNameBlockBlock[] UUIDNameBlock; /// Default constructor public UUIDGroupNameRequestPacket() { Header = new LowHeader(); Header.ID = 283; Header.Reliable = true; UUIDNameBlock = new UUIDNameBlockBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UUIDGroupNameRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; UUIDNameBlock = new UUIDNameBlockBlock[count]; for (int j = 0; j < count; j++) { UUIDNameBlock[j] = new UUIDNameBlockBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public UUIDGroupNameRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; UUIDNameBlock = new UUIDNameBlockBlock[count]; for (int j = 0; j < count; j++) { UUIDNameBlock[j] = new UUIDNameBlockBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < UUIDNameBlock.Length; j++) { length += UUIDNameBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)UUIDNameBlock.Length; for (int j = 0; j < UUIDNameBlock.Length; j++) { UUIDNameBlock[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UUIDGroupNameRequest ---\n"; for (int j = 0; j < UUIDNameBlock.Length; j++) { output += UUIDNameBlock[j].ToString() + "\n"; } return output; } } /// UUIDGroupNameReply packet public class UUIDGroupNameReplyPacket : Packet { /// UUIDNameBlock block public class UUIDNameBlockBlock { /// ID field public LLUUID ID; private byte[] _groupname; /// GroupName field public byte[] GroupName { get { return _groupname; } set { if (value == null) { _groupname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _groupname = new byte[value.Length]; Array.Copy(value, _groupname, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 16; if (GroupName != null) { length += 1 + GroupName.Length; } return length; } } /// Default constructor public UUIDNameBlockBlock() { } /// Constructor for building the block from a byte array public UUIDNameBlockBlock(byte[] bytes, ref int i) { int length; try { ID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _groupname = new byte[length]; Array.Copy(bytes, i, _groupname, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupName == null) { Console.WriteLine("Warning: GroupName is null, in " + this.GetType()); } bytes[i++] = (byte)GroupName.Length; Array.Copy(GroupName, 0, bytes, i, GroupName.Length); i += GroupName.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- UUIDNameBlock --\n"; output += "ID: " + ID.ToString() + "\n"; output += Helpers.FieldToString(GroupName, "GroupName") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UUIDGroupNameReply public override PacketType Type { get { return PacketType.UUIDGroupNameReply; } } /// UUIDNameBlock block public UUIDNameBlockBlock[] UUIDNameBlock; /// Default constructor public UUIDGroupNameReplyPacket() { Header = new LowHeader(); Header.ID = 284; Header.Reliable = true; UUIDNameBlock = new UUIDNameBlockBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UUIDGroupNameReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; UUIDNameBlock = new UUIDNameBlockBlock[count]; for (int j = 0; j < count; j++) { UUIDNameBlock[j] = new UUIDNameBlockBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public UUIDGroupNameReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; UUIDNameBlock = new UUIDNameBlockBlock[count]; for (int j = 0; j < count; j++) { UUIDNameBlock[j] = new UUIDNameBlockBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < UUIDNameBlock.Length; j++) { length += UUIDNameBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)UUIDNameBlock.Length; for (int j = 0; j < UUIDNameBlock.Length; j++) { UUIDNameBlock[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UUIDGroupNameReply ---\n"; for (int j = 0; j < UUIDNameBlock.Length; j++) { output += UUIDNameBlock[j].ToString() + "\n"; } return output; } } /// ChatPass packet public class ChatPassPacket : Packet { /// ChatData block public class ChatDataBlock { /// ID field public LLUUID ID; /// Channel field public int Channel; private byte[] _message; /// Message field public byte[] Message { get { return _message; } set { if (value == null) { _message = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _message = new byte[value.Length]; Array.Copy(value, _message, value.Length); } } } private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// Type field public byte Type; /// OwnerID field public LLUUID OwnerID; /// SimAccess field public byte SimAccess; /// Radius field public float Radius; /// SourceType field public byte SourceType; /// Position field public LLVector3 Position; /// Length of this block serialized in bytes public int Length { get { int length = 55; if (Message != null) { length += 2 + Message.Length; } if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public ChatDataBlock() { } /// Constructor for building the block from a byte array public ChatDataBlock(byte[] bytes, ref int i) { int length; try { ID = new LLUUID(bytes, i); i += 16; Channel = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _message = new byte[length]; Array.Copy(bytes, i, _message, 0, length); i += length; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; Type = (byte)bytes[i++]; OwnerID = new LLUUID(bytes, i); i += 16; SimAccess = (byte)bytes[i++]; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Radius = BitConverter.ToSingle(bytes, i); i += 4; SourceType = (byte)bytes[i++]; Position = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Channel % 256); bytes[i++] = (byte)((Channel >> 8) % 256); bytes[i++] = (byte)((Channel >> 16) % 256); bytes[i++] = (byte)((Channel >> 24) % 256); if(Message == null) { Console.WriteLine("Warning: Message is null, in " + this.GetType()); } bytes[i++] = (byte)(Message.Length % 256); bytes[i++] = (byte)((Message.Length >> 8) % 256); Array.Copy(Message, 0, bytes, i, Message.Length); i += Message.Length; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = Type; if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = SimAccess; ba = BitConverter.GetBytes(Radius); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = SourceType; if(Position == null) { Console.WriteLine("Warning: Position is null, in " + this.GetType()); } Array.Copy(Position.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ChatData --\n"; output += "ID: " + ID.ToString() + "\n"; output += "Channel: " + Channel.ToString() + "\n"; output += Helpers.FieldToString(Message, "Message") + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "SimAccess: " + SimAccess.ToString() + "\n"; output += "Radius: " + Radius.ToString() + "\n"; output += "SourceType: " + SourceType.ToString() + "\n"; output += "Position: " + Position.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ChatPass public override PacketType Type { get { return PacketType.ChatPass; } } /// ChatData block public ChatDataBlock ChatData; /// Default constructor public ChatPassPacket() { Header = new LowHeader(); Header.ID = 285; Header.Reliable = true; Header.Zerocoded = true; ChatData = new ChatDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ChatPassPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ChatData = new ChatDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ChatPassPacket(Header head, byte[] bytes, ref int i) { Header = head; ChatData = new ChatDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ChatData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ChatData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ChatPass ---\n"; output += ChatData.ToString() + "\n"; return output; } } /// ChildAgentDying packet public class ChildAgentDyingPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ChildAgentDying public override PacketType Type { get { return PacketType.ChildAgentDying; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ChildAgentDyingPacket() { Header = new LowHeader(); Header.ID = 286; Header.Reliable = true; Header.Zerocoded = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ChildAgentDyingPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ChildAgentDyingPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ChildAgentDying ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// ChildAgentUnknown packet public class ChildAgentUnknownPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ChildAgentUnknown public override PacketType Type { get { return PacketType.ChildAgentUnknown; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ChildAgentUnknownPacket() { Header = new LowHeader(); Header.ID = 287; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ChildAgentUnknownPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ChildAgentUnknownPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ChildAgentUnknown ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// KillChildAgents packet public class KillChildAgentsPacket : Packet { /// IDBlock block public class IDBlockBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public IDBlockBlock() { } /// Constructor for building the block from a byte array public IDBlockBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- IDBlock --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.KillChildAgents public override PacketType Type { get { return PacketType.KillChildAgents; } } /// IDBlock block public IDBlockBlock IDBlock; /// Default constructor public KillChildAgentsPacket() { Header = new LowHeader(); Header.ID = 288; Header.Reliable = true; IDBlock = new IDBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public KillChildAgentsPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); IDBlock = new IDBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public KillChildAgentsPacket(Header head, byte[] bytes, ref int i) { Header = head; IDBlock = new IDBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += IDBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); IDBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- KillChildAgents ---\n"; output += IDBlock.ToString() + "\n"; return output; } } /// GetScriptRunning packet public class GetScriptRunningPacket : Packet { /// Script block public class ScriptBlock { /// ObjectID field public LLUUID ObjectID; /// ItemID field public LLUUID ItemID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public ScriptBlock() { } /// Constructor for building the block from a byte array public ScriptBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Script --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GetScriptRunning public override PacketType Type { get { return PacketType.GetScriptRunning; } } /// Script block public ScriptBlock Script; /// Default constructor public GetScriptRunningPacket() { Header = new LowHeader(); Header.ID = 289; Header.Reliable = true; Script = new ScriptBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GetScriptRunningPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Script = new ScriptBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GetScriptRunningPacket(Header head, byte[] bytes, ref int i) { Header = head; Script = new ScriptBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Script.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Script.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GetScriptRunning ---\n"; output += Script.ToString() + "\n"; return output; } } /// ScriptRunningReply packet public class ScriptRunningReplyPacket : Packet { /// Script block public class ScriptBlock { /// ObjectID field public LLUUID ObjectID; /// Running field public bool Running; /// ItemID field public LLUUID ItemID; /// Length of this block serialized in bytes public int Length { get { return 33; } } /// Default constructor public ScriptBlock() { } /// Constructor for building the block from a byte array public ScriptBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; Running = (bytes[i++] != 0) ? (bool)true : (bool)false; ItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((Running) ? 1 : 0); if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Script --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "Running: " + Running.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ScriptRunningReply public override PacketType Type { get { return PacketType.ScriptRunningReply; } } /// Script block public ScriptBlock Script; /// Default constructor public ScriptRunningReplyPacket() { Header = new LowHeader(); Header.ID = 290; Header.Reliable = true; Script = new ScriptBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ScriptRunningReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Script = new ScriptBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ScriptRunningReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; Script = new ScriptBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Script.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Script.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ScriptRunningReply ---\n"; output += Script.ToString() + "\n"; return output; } } /// SetScriptRunning packet public class SetScriptRunningPacket : Packet { /// Script block public class ScriptBlock { /// ObjectID field public LLUUID ObjectID; /// Running field public bool Running; /// ItemID field public LLUUID ItemID; /// Length of this block serialized in bytes public int Length { get { return 33; } } /// Default constructor public ScriptBlock() { } /// Constructor for building the block from a byte array public ScriptBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; Running = (bytes[i++] != 0) ? (bool)true : (bool)false; ItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((Running) ? 1 : 0); if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Script --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "Running: " + Running.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SetScriptRunning public override PacketType Type { get { return PacketType.SetScriptRunning; } } /// Script block public ScriptBlock Script; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public SetScriptRunningPacket() { Header = new LowHeader(); Header.ID = 291; Header.Reliable = true; Script = new ScriptBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SetScriptRunningPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Script = new ScriptBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SetScriptRunningPacket(Header head, byte[] bytes, ref int i) { Header = head; Script = new ScriptBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Script.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Script.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SetScriptRunning ---\n"; output += Script.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ScriptReset packet public class ScriptResetPacket : Packet { /// Script block public class ScriptBlock { /// ObjectID field public LLUUID ObjectID; /// ItemID field public LLUUID ItemID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public ScriptBlock() { } /// Constructor for building the block from a byte array public ScriptBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Script --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ScriptReset public override PacketType Type { get { return PacketType.ScriptReset; } } /// Script block public ScriptBlock Script; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ScriptResetPacket() { Header = new LowHeader(); Header.ID = 292; Header.Reliable = true; Script = new ScriptBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ScriptResetPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Script = new ScriptBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ScriptResetPacket(Header head, byte[] bytes, ref int i) { Header = head; Script = new ScriptBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Script.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Script.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ScriptReset ---\n"; output += Script.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ScriptSensorRequest packet public class ScriptSensorRequestPacket : Packet { /// Requester block public class RequesterBlock { /// Arc field public float Arc; /// RequestID field public LLUUID RequestID; /// SearchID field public LLUUID SearchID; private byte[] _searchname; /// SearchName field public byte[] SearchName { get { return _searchname; } set { if (value == null) { _searchname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _searchname = new byte[value.Length]; Array.Copy(value, _searchname, value.Length); } } } /// Type field public int Type; /// RegionHandle field public ulong RegionHandle; /// SearchDir field public LLQuaternion SearchDir; /// SearchRegions field public byte SearchRegions; /// SearchPos field public LLVector3 SearchPos; /// Range field public float Range; /// SourceID field public LLUUID SourceID; /// Length of this block serialized in bytes public int Length { get { int length = 93; if (SearchName != null) { length += 1 + SearchName.Length; } return length; } } /// Default constructor public RequesterBlock() { } /// Constructor for building the block from a byte array public RequesterBlock(byte[] bytes, ref int i) { int length; try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Arc = BitConverter.ToSingle(bytes, i); i += 4; RequestID = new LLUUID(bytes, i); i += 16; SearchID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _searchname = new byte[length]; Array.Copy(bytes, i, _searchname, 0, length); i += length; Type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); SearchDir = new LLQuaternion(bytes, i, true); i += 12; SearchRegions = (byte)bytes[i++]; SearchPos = new LLVector3(bytes, i); i += 12; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Range = BitConverter.ToSingle(bytes, i); i += 4; SourceID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(Arc); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; if(SearchID == null) { Console.WriteLine("Warning: SearchID is null, in " + this.GetType()); } Array.Copy(SearchID.GetBytes(), 0, bytes, i, 16); i += 16; if(SearchName == null) { Console.WriteLine("Warning: SearchName is null, in " + this.GetType()); } bytes[i++] = (byte)SearchName.Length; Array.Copy(SearchName, 0, bytes, i, SearchName.Length); i += SearchName.Length; bytes[i++] = (byte)(Type % 256); bytes[i++] = (byte)((Type >> 8) % 256); bytes[i++] = (byte)((Type >> 16) % 256); bytes[i++] = (byte)((Type >> 24) % 256); bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); if(SearchDir == null) { Console.WriteLine("Warning: SearchDir is null, in " + this.GetType()); } Array.Copy(SearchDir.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = SearchRegions; if(SearchPos == null) { Console.WriteLine("Warning: SearchPos is null, in " + this.GetType()); } Array.Copy(SearchPos.GetBytes(), 0, bytes, i, 12); i += 12; ba = BitConverter.GetBytes(Range); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(SourceID == null) { Console.WriteLine("Warning: SourceID is null, in " + this.GetType()); } Array.Copy(SourceID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Requester --\n"; output += "Arc: " + Arc.ToString() + "\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "SearchID: " + SearchID.ToString() + "\n"; output += Helpers.FieldToString(SearchName, "SearchName") + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output += "SearchDir: " + SearchDir.ToString() + "\n"; output += "SearchRegions: " + SearchRegions.ToString() + "\n"; output += "SearchPos: " + SearchPos.ToString() + "\n"; output += "Range: " + Range.ToString() + "\n"; output += "SourceID: " + SourceID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ScriptSensorRequest public override PacketType Type { get { return PacketType.ScriptSensorRequest; } } /// Requester block public RequesterBlock Requester; /// Default constructor public ScriptSensorRequestPacket() { Header = new LowHeader(); Header.ID = 293; Header.Reliable = true; Header.Zerocoded = true; Requester = new RequesterBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ScriptSensorRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Requester = new RequesterBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ScriptSensorRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; Requester = new RequesterBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Requester.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Requester.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ScriptSensorRequest ---\n"; output += Requester.ToString() + "\n"; return output; } } /// ScriptSensorReply packet public class ScriptSensorReplyPacket : Packet { /// SensedData block public class SensedDataBlock { /// ObjectID field public LLUUID ObjectID; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// Type field public int Type; /// GroupID field public LLUUID GroupID; /// OwnerID field public LLUUID OwnerID; /// Velocity field public LLVector3 Velocity; /// Range field public float Range; /// Rotation field public LLQuaternion Rotation; /// Position field public LLVector3 Position; /// Length of this block serialized in bytes public int Length { get { int length = 92; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public SensedDataBlock() { } /// Constructor for building the block from a byte array public SensedDataBlock(byte[] bytes, ref int i) { int length; try { ObjectID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; Type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupID = new LLUUID(bytes, i); i += 16; OwnerID = new LLUUID(bytes, i); i += 16; Velocity = new LLVector3(bytes, i); i += 12; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Range = BitConverter.ToSingle(bytes, i); i += 4; Rotation = new LLQuaternion(bytes, i, true); i += 12; Position = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)(Type % 256); bytes[i++] = (byte)((Type >> 8) % 256); bytes[i++] = (byte)((Type >> 16) % 256); bytes[i++] = (byte)((Type >> 24) % 256); if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(Velocity == null) { Console.WriteLine("Warning: Velocity is null, in " + this.GetType()); } Array.Copy(Velocity.GetBytes(), 0, bytes, i, 12); i += 12; ba = BitConverter.GetBytes(Range); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(Rotation == null) { Console.WriteLine("Warning: Rotation is null, in " + this.GetType()); } Array.Copy(Rotation.GetBytes(), 0, bytes, i, 12); i += 12; if(Position == null) { Console.WriteLine("Warning: Position is null, in " + this.GetType()); } Array.Copy(Position.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- SensedData --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "Velocity: " + Velocity.ToString() + "\n"; output += "Range: " + Range.ToString() + "\n"; output += "Rotation: " + Rotation.ToString() + "\n"; output += "Position: " + Position.ToString() + "\n"; output = output.Trim(); return output; } } /// Requester block public class RequesterBlock { /// SourceID field public LLUUID SourceID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public RequesterBlock() { } /// Constructor for building the block from a byte array public RequesterBlock(byte[] bytes, ref int i) { try { SourceID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(SourceID == null) { Console.WriteLine("Warning: SourceID is null, in " + this.GetType()); } Array.Copy(SourceID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Requester --\n"; output += "SourceID: " + SourceID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ScriptSensorReply public override PacketType Type { get { return PacketType.ScriptSensorReply; } } /// SensedData block public SensedDataBlock[] SensedData; /// Requester block public RequesterBlock Requester; /// Default constructor public ScriptSensorReplyPacket() { Header = new LowHeader(); Header.ID = 294; Header.Reliable = true; Header.Zerocoded = true; SensedData = new SensedDataBlock[0]; Requester = new RequesterBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ScriptSensorReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; SensedData = new SensedDataBlock[count]; for (int j = 0; j < count; j++) { SensedData[j] = new SensedDataBlock(bytes, ref i); } Requester = new RequesterBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ScriptSensorReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; SensedData = new SensedDataBlock[count]; for (int j = 0; j < count; j++) { SensedData[j] = new SensedDataBlock(bytes, ref i); } Requester = new RequesterBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Requester.Length;; length++; for (int j = 0; j < SensedData.Length; j++) { length += SensedData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)SensedData.Length; for (int j = 0; j < SensedData.Length; j++) { SensedData[j].ToBytes(bytes, ref i); } Requester.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ScriptSensorReply ---\n"; for (int j = 0; j < SensedData.Length; j++) { output += SensedData[j].ToString() + "\n"; } output += Requester.ToString() + "\n"; return output; } } /// CompleteAgentMovement packet public class CompleteAgentMovementPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// CircuitCode field public uint CircuitCode; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; CircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(CircuitCode % 256); bytes[i++] = (byte)((CircuitCode >> 8) % 256); bytes[i++] = (byte)((CircuitCode >> 16) % 256); bytes[i++] = (byte)((CircuitCode >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "CircuitCode: " + CircuitCode.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.CompleteAgentMovement public override PacketType Type { get { return PacketType.CompleteAgentMovement; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public CompleteAgentMovementPacket() { Header = new LowHeader(); Header.ID = 295; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public CompleteAgentMovementPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public CompleteAgentMovementPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- CompleteAgentMovement ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// AgentMovementComplete packet public class AgentMovementCompletePacket : Packet { /// Data block public class DataBlock { /// Timestamp field public uint Timestamp; /// RegionHandle field public ulong RegionHandle; /// LookAt field public LLVector3 LookAt; /// Position field public LLVector3 Position; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { Timestamp = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); LookAt = new LLVector3(bytes, i); i += 12; Position = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Timestamp % 256); bytes[i++] = (byte)((Timestamp >> 8) % 256); bytes[i++] = (byte)((Timestamp >> 16) % 256); bytes[i++] = (byte)((Timestamp >> 24) % 256); bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); if(LookAt == null) { Console.WriteLine("Warning: LookAt is null, in " + this.GetType()); } Array.Copy(LookAt.GetBytes(), 0, bytes, i, 12); i += 12; if(Position == null) { Console.WriteLine("Warning: Position is null, in " + this.GetType()); } Array.Copy(Position.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "Timestamp: " + Timestamp.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output += "LookAt: " + LookAt.ToString() + "\n"; output += "Position: " + Position.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentMovementComplete public override PacketType Type { get { return PacketType.AgentMovementComplete; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentMovementCompletePacket() { Header = new LowHeader(); Header.ID = 296; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentMovementCompletePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentMovementCompletePacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentMovementComplete ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// LogLogin packet public class LogLoginPacket : Packet { /// Data block public class DataBlock { /// ViewerDigest field public LLUUID ViewerDigest; /// SpaceIP field public uint SpaceIP; /// LastExecFroze field public bool LastExecFroze; /// Length of this block serialized in bytes public int Length { get { return 21; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { ViewerDigest = new LLUUID(bytes, i); i += 16; SpaceIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); LastExecFroze = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ViewerDigest == null) { Console.WriteLine("Warning: ViewerDigest is null, in " + this.GetType()); } Array.Copy(ViewerDigest.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(SpaceIP % 256); bytes[i++] = (byte)((SpaceIP >> 8) % 256); bytes[i++] = (byte)((SpaceIP >> 16) % 256); bytes[i++] = (byte)((SpaceIP >> 24) % 256); bytes[i++] = (byte)((LastExecFroze) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "ViewerDigest: " + ViewerDigest.ToString() + "\n"; output += "SpaceIP: " + SpaceIP.ToString() + "\n"; output += "LastExecFroze: " + LastExecFroze.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.LogLogin public override PacketType Type { get { return PacketType.LogLogin; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public LogLoginPacket() { Header = new LowHeader(); Header.ID = 297; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public LogLoginPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public LogLoginPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- LogLogin ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ConnectAgentToUserserver packet public class ConnectAgentToUserserverPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ConnectAgentToUserserver public override PacketType Type { get { return PacketType.ConnectAgentToUserserver; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ConnectAgentToUserserverPacket() { Header = new LowHeader(); Header.ID = 298; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ConnectAgentToUserserverPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ConnectAgentToUserserverPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ConnectAgentToUserserver ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// ConnectToUserserver packet public class ConnectToUserserverPacket : Packet { private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ConnectToUserserver public override PacketType Type { get { return PacketType.ConnectToUserserver; } } /// Default constructor public ConnectToUserserverPacket() { Header = new LowHeader(); Header.ID = 299; Header.Reliable = true; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ConnectToUserserverPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); } /// Constructor that takes a byte array and a prebuilt header public ConnectToUserserverPacket(Header head, byte[] bytes, ref int i) { Header = head; } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ConnectToUserserver ---\n"; return output; } } /// DataServerLogout packet public class DataServerLogoutPacket : Packet { /// UserData block public class UserDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// ViewerIP field public uint ViewerIP; /// Disconnect field public bool Disconnect; /// Length of this block serialized in bytes public int Length { get { return 37; } } /// Default constructor public UserDataBlock() { } /// Constructor for building the block from a byte array public UserDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; ViewerIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Disconnect = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(ViewerIP % 256); bytes[i++] = (byte)((ViewerIP >> 8) % 256); bytes[i++] = (byte)((ViewerIP >> 16) % 256); bytes[i++] = (byte)((ViewerIP >> 24) % 256); bytes[i++] = (byte)((Disconnect) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- UserData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "ViewerIP: " + ViewerIP.ToString() + "\n"; output += "Disconnect: " + Disconnect.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DataServerLogout public override PacketType Type { get { return PacketType.DataServerLogout; } } /// UserData block public UserDataBlock UserData; /// Default constructor public DataServerLogoutPacket() { Header = new LowHeader(); Header.ID = 300; Header.Reliable = true; UserData = new UserDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DataServerLogoutPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); UserData = new UserDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DataServerLogoutPacket(Header head, byte[] bytes, ref int i) { Header = head; UserData = new UserDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += UserData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); UserData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DataServerLogout ---\n"; output += UserData.ToString() + "\n"; return output; } } /// LogoutRequest packet public class LogoutRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.LogoutRequest public override PacketType Type { get { return PacketType.LogoutRequest; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public LogoutRequestPacket() { Header = new LowHeader(); Header.ID = 301; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public LogoutRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public LogoutRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- LogoutRequest ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// FinalizeLogout packet public class FinalizeLogoutPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.FinalizeLogout public override PacketType Type { get { return PacketType.FinalizeLogout; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public FinalizeLogoutPacket() { Header = new LowHeader(); Header.ID = 302; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public FinalizeLogoutPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public FinalizeLogoutPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- FinalizeLogout ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// LogoutReply packet public class LogoutReplyPacket : Packet { /// InventoryData block public class InventoryDataBlock { /// NewAssetID field public LLUUID NewAssetID; /// ItemID field public LLUUID ItemID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { try { NewAssetID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(NewAssetID == null) { Console.WriteLine("Warning: NewAssetID is null, in " + this.GetType()); } Array.Copy(NewAssetID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "NewAssetID: " + NewAssetID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.LogoutReply public override PacketType Type { get { return PacketType.LogoutReply; } } /// InventoryData block public InventoryDataBlock[] InventoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public LogoutReplyPacket() { Header = new LowHeader(); Header.ID = 303; Header.Reliable = true; Header.Zerocoded = true; InventoryData = new InventoryDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public LogoutReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public LogoutReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)InventoryData.Length; for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- LogoutReply ---\n"; for (int j = 0; j < InventoryData.Length; j++) { output += InventoryData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// LogoutDemand packet public class LogoutDemandPacket : Packet { /// LogoutBlock block public class LogoutBlockBlock { /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public LogoutBlockBlock() { } /// Constructor for building the block from a byte array public LogoutBlockBlock(byte[] bytes, ref int i) { try { SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- LogoutBlock --\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.LogoutDemand public override PacketType Type { get { return PacketType.LogoutDemand; } } /// LogoutBlock block public LogoutBlockBlock LogoutBlock; /// Default constructor public LogoutDemandPacket() { Header = new LowHeader(); Header.ID = 304; Header.Reliable = true; LogoutBlock = new LogoutBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public LogoutDemandPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); LogoutBlock = new LogoutBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public LogoutDemandPacket(Header head, byte[] bytes, ref int i) { Header = head; LogoutBlock = new LogoutBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += LogoutBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); LogoutBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- LogoutDemand ---\n"; output += LogoutBlock.ToString() + "\n"; return output; } } /// ImprovedInstantMessage packet public class ImprovedInstantMessagePacket : Packet { /// MessageBlock block public class MessageBlockBlock { /// ID field public LLUUID ID; /// ToAgentID field public LLUUID ToAgentID; /// Offline field public byte Offline; /// Timestamp field public uint Timestamp; private byte[] _message; /// Message field public byte[] Message { get { return _message; } set { if (value == null) { _message = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _message = new byte[value.Length]; Array.Copy(value, _message, value.Length); } } } /// RegionID field public LLUUID RegionID; /// Dialog field public byte Dialog; /// FromGroup field public bool FromGroup; private byte[] _binarybucket; /// BinaryBucket field public byte[] BinaryBucket { get { return _binarybucket; } set { if (value == null) { _binarybucket = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _binarybucket = new byte[value.Length]; Array.Copy(value, _binarybucket, value.Length); } } } /// ParentEstateID field public uint ParentEstateID; private byte[] _fromagentname; /// FromAgentName field public byte[] FromAgentName { get { return _fromagentname; } set { if (value == null) { _fromagentname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _fromagentname = new byte[value.Length]; Array.Copy(value, _fromagentname, value.Length); } } } /// Position field public LLVector3 Position; /// Length of this block serialized in bytes public int Length { get { int length = 71; if (Message != null) { length += 2 + Message.Length; } if (BinaryBucket != null) { length += 2 + BinaryBucket.Length; } if (FromAgentName != null) { length += 1 + FromAgentName.Length; } return length; } } /// Default constructor public MessageBlockBlock() { } /// Constructor for building the block from a byte array public MessageBlockBlock(byte[] bytes, ref int i) { int length; try { ID = new LLUUID(bytes, i); i += 16; ToAgentID = new LLUUID(bytes, i); i += 16; Offline = (byte)bytes[i++]; Timestamp = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _message = new byte[length]; Array.Copy(bytes, i, _message, 0, length); i += length; RegionID = new LLUUID(bytes, i); i += 16; Dialog = (byte)bytes[i++]; FromGroup = (bytes[i++] != 0) ? (bool)true : (bool)false; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _binarybucket = new byte[length]; Array.Copy(bytes, i, _binarybucket, 0, length); i += length; ParentEstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _fromagentname = new byte[length]; Array.Copy(bytes, i, _fromagentname, 0, length); i += length; Position = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; if(ToAgentID == null) { Console.WriteLine("Warning: ToAgentID is null, in " + this.GetType()); } Array.Copy(ToAgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = Offline; bytes[i++] = (byte)(Timestamp % 256); bytes[i++] = (byte)((Timestamp >> 8) % 256); bytes[i++] = (byte)((Timestamp >> 16) % 256); bytes[i++] = (byte)((Timestamp >> 24) % 256); if(Message == null) { Console.WriteLine("Warning: Message is null, in " + this.GetType()); } bytes[i++] = (byte)(Message.Length % 256); bytes[i++] = (byte)((Message.Length >> 8) % 256); Array.Copy(Message, 0, bytes, i, Message.Length); i += Message.Length; if(RegionID == null) { Console.WriteLine("Warning: RegionID is null, in " + this.GetType()); } Array.Copy(RegionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = Dialog; bytes[i++] = (byte)((FromGroup) ? 1 : 0); if(BinaryBucket == null) { Console.WriteLine("Warning: BinaryBucket is null, in " + this.GetType()); } bytes[i++] = (byte)(BinaryBucket.Length % 256); bytes[i++] = (byte)((BinaryBucket.Length >> 8) % 256); Array.Copy(BinaryBucket, 0, bytes, i, BinaryBucket.Length); i += BinaryBucket.Length; bytes[i++] = (byte)(ParentEstateID % 256); bytes[i++] = (byte)((ParentEstateID >> 8) % 256); bytes[i++] = (byte)((ParentEstateID >> 16) % 256); bytes[i++] = (byte)((ParentEstateID >> 24) % 256); if(FromAgentName == null) { Console.WriteLine("Warning: FromAgentName is null, in " + this.GetType()); } bytes[i++] = (byte)FromAgentName.Length; Array.Copy(FromAgentName, 0, bytes, i, FromAgentName.Length); i += FromAgentName.Length; if(Position == null) { Console.WriteLine("Warning: Position is null, in " + this.GetType()); } Array.Copy(Position.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MessageBlock --\n"; output += "ID: " + ID.ToString() + "\n"; output += "ToAgentID: " + ToAgentID.ToString() + "\n"; output += "Offline: " + Offline.ToString() + "\n"; output += "Timestamp: " + Timestamp.ToString() + "\n"; output += Helpers.FieldToString(Message, "Message") + "\n"; output += "RegionID: " + RegionID.ToString() + "\n"; output += "Dialog: " + Dialog.ToString() + "\n"; output += "FromGroup: " + FromGroup.ToString() + "\n"; output += Helpers.FieldToString(BinaryBucket, "BinaryBucket") + "\n"; output += "ParentEstateID: " + ParentEstateID.ToString() + "\n"; output += Helpers.FieldToString(FromAgentName, "FromAgentName") + "\n"; output += "Position: " + Position.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ImprovedInstantMessage public override PacketType Type { get { return PacketType.ImprovedInstantMessage; } } /// MessageBlock block public MessageBlockBlock MessageBlock; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ImprovedInstantMessagePacket() { Header = new LowHeader(); Header.ID = 305; Header.Reliable = true; Header.Zerocoded = true; MessageBlock = new MessageBlockBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ImprovedInstantMessagePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MessageBlock = new MessageBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ImprovedInstantMessagePacket(Header head, byte[] bytes, ref int i) { Header = head; MessageBlock = new MessageBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MessageBlock.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MessageBlock.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ImprovedInstantMessage ---\n"; output += MessageBlock.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// RetrieveInstantMessages packet public class RetrieveInstantMessagesPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RetrieveInstantMessages public override PacketType Type { get { return PacketType.RetrieveInstantMessages; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RetrieveInstantMessagesPacket() { Header = new LowHeader(); Header.ID = 306; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RetrieveInstantMessagesPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RetrieveInstantMessagesPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RetrieveInstantMessages ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// DequeueInstantMessages packet public class DequeueInstantMessagesPacket : Packet { private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DequeueInstantMessages public override PacketType Type { get { return PacketType.DequeueInstantMessages; } } /// Default constructor public DequeueInstantMessagesPacket() { Header = new LowHeader(); Header.ID = 307; Header.Reliable = true; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DequeueInstantMessagesPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); } /// Constructor that takes a byte array and a prebuilt header public DequeueInstantMessagesPacket(Header head, byte[] bytes, ref int i) { Header = head; } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DequeueInstantMessages ---\n"; return output; } } /// FindAgent packet public class FindAgentPacket : Packet { /// LocationBlock block public class LocationBlockBlock { /// GlobalX field public double GlobalX; /// GlobalY field public double GlobalY; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public LocationBlockBlock() { } /// Constructor for building the block from a byte array public LocationBlockBlock(byte[] bytes, ref int i) { try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 8); GlobalX = BitConverter.ToDouble(bytes, i); i += 8; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 8); GlobalY = BitConverter.ToDouble(bytes, i); i += 8; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(GlobalX); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 8); } Array.Copy(ba, 0, bytes, i, 8); i += 8; ba = BitConverter.GetBytes(GlobalY); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 8); } Array.Copy(ba, 0, bytes, i, 8); i += 8; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- LocationBlock --\n"; output += "GlobalX: " + GlobalX.ToString() + "\n"; output += "GlobalY: " + GlobalY.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentBlock block public class AgentBlockBlock { /// SpaceIP field public uint SpaceIP; /// Prey field public LLUUID Prey; /// Hunter field public LLUUID Hunter; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public AgentBlockBlock() { } /// Constructor for building the block from a byte array public AgentBlockBlock(byte[] bytes, ref int i) { try { SpaceIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Prey = new LLUUID(bytes, i); i += 16; Hunter = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(SpaceIP % 256); bytes[i++] = (byte)((SpaceIP >> 8) % 256); bytes[i++] = (byte)((SpaceIP >> 16) % 256); bytes[i++] = (byte)((SpaceIP >> 24) % 256); if(Prey == null) { Console.WriteLine("Warning: Prey is null, in " + this.GetType()); } Array.Copy(Prey.GetBytes(), 0, bytes, i, 16); i += 16; if(Hunter == null) { Console.WriteLine("Warning: Hunter is null, in " + this.GetType()); } Array.Copy(Hunter.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentBlock --\n"; output += "SpaceIP: " + SpaceIP.ToString() + "\n"; output += "Prey: " + Prey.ToString() + "\n"; output += "Hunter: " + Hunter.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.FindAgent public override PacketType Type { get { return PacketType.FindAgent; } } /// LocationBlock block public LocationBlockBlock[] LocationBlock; /// AgentBlock block public AgentBlockBlock AgentBlock; /// Default constructor public FindAgentPacket() { Header = new LowHeader(); Header.ID = 308; Header.Reliable = true; LocationBlock = new LocationBlockBlock[0]; AgentBlock = new AgentBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public FindAgentPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; LocationBlock = new LocationBlockBlock[count]; for (int j = 0; j < count; j++) { LocationBlock[j] = new LocationBlockBlock(bytes, ref i); } AgentBlock = new AgentBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public FindAgentPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; LocationBlock = new LocationBlockBlock[count]; for (int j = 0; j < count; j++) { LocationBlock[j] = new LocationBlockBlock(bytes, ref i); } AgentBlock = new AgentBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentBlock.Length;; length++; for (int j = 0; j < LocationBlock.Length; j++) { length += LocationBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)LocationBlock.Length; for (int j = 0; j < LocationBlock.Length; j++) { LocationBlock[j].ToBytes(bytes, ref i); } AgentBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- FindAgent ---\n"; for (int j = 0; j < LocationBlock.Length; j++) { output += LocationBlock[j].ToString() + "\n"; } output += AgentBlock.ToString() + "\n"; return output; } } /// RequestGodlikePowers packet public class RequestGodlikePowersPacket : Packet { /// RequestBlock block public class RequestBlockBlock { /// Godlike field public bool Godlike; /// Token field public LLUUID Token; /// Length of this block serialized in bytes public int Length { get { return 17; } } /// Default constructor public RequestBlockBlock() { } /// Constructor for building the block from a byte array public RequestBlockBlock(byte[] bytes, ref int i) { try { Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; Token = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((Godlike) ? 1 : 0); if(Token == null) { Console.WriteLine("Warning: Token is null, in " + this.GetType()); } Array.Copy(Token.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RequestBlock --\n"; output += "Godlike: " + Godlike.ToString() + "\n"; output += "Token: " + Token.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RequestGodlikePowers public override PacketType Type { get { return PacketType.RequestGodlikePowers; } } /// RequestBlock block public RequestBlockBlock RequestBlock; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RequestGodlikePowersPacket() { Header = new LowHeader(); Header.ID = 309; Header.Reliable = true; RequestBlock = new RequestBlockBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RequestGodlikePowersPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); RequestBlock = new RequestBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RequestGodlikePowersPacket(Header head, byte[] bytes, ref int i) { Header = head; RequestBlock = new RequestBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += RequestBlock.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); RequestBlock.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RequestGodlikePowers ---\n"; output += RequestBlock.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// GrantGodlikePowers packet public class GrantGodlikePowersPacket : Packet { /// GrantData block public class GrantDataBlock { /// GodLevel field public byte GodLevel; /// Token field public LLUUID Token; /// Length of this block serialized in bytes public int Length { get { return 17; } } /// Default constructor public GrantDataBlock() { } /// Constructor for building the block from a byte array public GrantDataBlock(byte[] bytes, ref int i) { try { GodLevel = (byte)bytes[i++]; Token = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = GodLevel; if(Token == null) { Console.WriteLine("Warning: Token is null, in " + this.GetType()); } Array.Copy(Token.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GrantData --\n"; output += "GodLevel: " + GodLevel.ToString() + "\n"; output += "Token: " + Token.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GrantGodlikePowers public override PacketType Type { get { return PacketType.GrantGodlikePowers; } } /// GrantData block public GrantDataBlock GrantData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GrantGodlikePowersPacket() { Header = new LowHeader(); Header.ID = 310; Header.Reliable = true; GrantData = new GrantDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GrantGodlikePowersPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); GrantData = new GrantDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GrantGodlikePowersPacket(Header head, byte[] bytes, ref int i) { Header = head; GrantData = new GrantDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += GrantData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); GrantData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GrantGodlikePowers ---\n"; output += GrantData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// GodlikeMessage packet public class GodlikeMessagePacket : Packet { /// MethodData block public class MethodDataBlock { /// Invoice field public LLUUID Invoice; private byte[] _method; /// Method field public byte[] Method { get { return _method; } set { if (value == null) { _method = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _method = new byte[value.Length]; Array.Copy(value, _method, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 16; if (Method != null) { length += 1 + Method.Length; } return length; } } /// Default constructor public MethodDataBlock() { } /// Constructor for building the block from a byte array public MethodDataBlock(byte[] bytes, ref int i) { int length; try { Invoice = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _method = new byte[length]; Array.Copy(bytes, i, _method, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Invoice == null) { Console.WriteLine("Warning: Invoice is null, in " + this.GetType()); } Array.Copy(Invoice.GetBytes(), 0, bytes, i, 16); i += 16; if(Method == null) { Console.WriteLine("Warning: Method is null, in " + this.GetType()); } bytes[i++] = (byte)Method.Length; Array.Copy(Method, 0, bytes, i, Method.Length); i += Method.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MethodData --\n"; output += "Invoice: " + Invoice.ToString() + "\n"; output += Helpers.FieldToString(Method, "Method") + "\n"; output = output.Trim(); return output; } } /// ParamList block public class ParamListBlock { private byte[] _parameter; /// Parameter field public byte[] Parameter { get { return _parameter; } set { if (value == null) { _parameter = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _parameter = new byte[value.Length]; Array.Copy(value, _parameter, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (Parameter != null) { length += 1 + Parameter.Length; } return length; } } /// Default constructor public ParamListBlock() { } /// Constructor for building the block from a byte array public ParamListBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _parameter = new byte[length]; Array.Copy(bytes, i, _parameter, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Parameter == null) { Console.WriteLine("Warning: Parameter is null, in " + this.GetType()); } bytes[i++] = (byte)Parameter.Length; Array.Copy(Parameter, 0, bytes, i, Parameter.Length); i += Parameter.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParamList --\n"; output += Helpers.FieldToString(Parameter, "Parameter") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GodlikeMessage public override PacketType Type { get { return PacketType.GodlikeMessage; } } /// MethodData block public MethodDataBlock MethodData; /// ParamList block public ParamListBlock[] ParamList; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GodlikeMessagePacket() { Header = new LowHeader(); Header.ID = 311; Header.Reliable = true; Header.Zerocoded = true; MethodData = new MethodDataBlock(); ParamList = new ParamListBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GodlikeMessagePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MethodData = new MethodDataBlock(bytes, ref i); int count = (int)bytes[i++]; ParamList = new ParamListBlock[count]; for (int j = 0; j < count; j++) { ParamList[j] = new ParamListBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GodlikeMessagePacket(Header head, byte[] bytes, ref int i) { Header = head; MethodData = new MethodDataBlock(bytes, ref i); int count = (int)bytes[i++]; ParamList = new ParamListBlock[count]; for (int j = 0; j < count; j++) { ParamList[j] = new ParamListBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MethodData.Length; length += AgentData.Length;; length++; for (int j = 0; j < ParamList.Length; j++) { length += ParamList[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MethodData.ToBytes(bytes, ref i); bytes[i++] = (byte)ParamList.Length; for (int j = 0; j < ParamList.Length; j++) { ParamList[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GodlikeMessage ---\n"; output += MethodData.ToString() + "\n"; for (int j = 0; j < ParamList.Length; j++) { output += ParamList[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// EstateOwnerMessage packet public class EstateOwnerMessagePacket : Packet { /// MethodData block public class MethodDataBlock { /// Invoice field public LLUUID Invoice; private byte[] _method; /// Method field public byte[] Method { get { return _method; } set { if (value == null) { _method = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _method = new byte[value.Length]; Array.Copy(value, _method, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 16; if (Method != null) { length += 1 + Method.Length; } return length; } } /// Default constructor public MethodDataBlock() { } /// Constructor for building the block from a byte array public MethodDataBlock(byte[] bytes, ref int i) { int length; try { Invoice = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _method = new byte[length]; Array.Copy(bytes, i, _method, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Invoice == null) { Console.WriteLine("Warning: Invoice is null, in " + this.GetType()); } Array.Copy(Invoice.GetBytes(), 0, bytes, i, 16); i += 16; if(Method == null) { Console.WriteLine("Warning: Method is null, in " + this.GetType()); } bytes[i++] = (byte)Method.Length; Array.Copy(Method, 0, bytes, i, Method.Length); i += Method.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MethodData --\n"; output += "Invoice: " + Invoice.ToString() + "\n"; output += Helpers.FieldToString(Method, "Method") + "\n"; output = output.Trim(); return output; } } /// ParamList block public class ParamListBlock { private byte[] _parameter; /// Parameter field public byte[] Parameter { get { return _parameter; } set { if (value == null) { _parameter = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _parameter = new byte[value.Length]; Array.Copy(value, _parameter, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (Parameter != null) { length += 1 + Parameter.Length; } return length; } } /// Default constructor public ParamListBlock() { } /// Constructor for building the block from a byte array public ParamListBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _parameter = new byte[length]; Array.Copy(bytes, i, _parameter, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Parameter == null) { Console.WriteLine("Warning: Parameter is null, in " + this.GetType()); } bytes[i++] = (byte)Parameter.Length; Array.Copy(Parameter, 0, bytes, i, Parameter.Length); i += Parameter.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParamList --\n"; output += Helpers.FieldToString(Parameter, "Parameter") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.EstateOwnerMessage public override PacketType Type { get { return PacketType.EstateOwnerMessage; } } /// MethodData block public MethodDataBlock MethodData; /// ParamList block public ParamListBlock[] ParamList; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public EstateOwnerMessagePacket() { Header = new LowHeader(); Header.ID = 312; Header.Reliable = true; Header.Zerocoded = true; MethodData = new MethodDataBlock(); ParamList = new ParamListBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public EstateOwnerMessagePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MethodData = new MethodDataBlock(bytes, ref i); int count = (int)bytes[i++]; ParamList = new ParamListBlock[count]; for (int j = 0; j < count; j++) { ParamList[j] = new ParamListBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public EstateOwnerMessagePacket(Header head, byte[] bytes, ref int i) { Header = head; MethodData = new MethodDataBlock(bytes, ref i); int count = (int)bytes[i++]; ParamList = new ParamListBlock[count]; for (int j = 0; j < count; j++) { ParamList[j] = new ParamListBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MethodData.Length; length += AgentData.Length;; length++; for (int j = 0; j < ParamList.Length; j++) { length += ParamList[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MethodData.ToBytes(bytes, ref i); bytes[i++] = (byte)ParamList.Length; for (int j = 0; j < ParamList.Length; j++) { ParamList[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- EstateOwnerMessage ---\n"; output += MethodData.ToString() + "\n"; for (int j = 0; j < ParamList.Length; j++) { output += ParamList[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// GenericMessage packet public class GenericMessagePacket : Packet { /// MethodData block public class MethodDataBlock { /// Invoice field public LLUUID Invoice; private byte[] _method; /// Method field public byte[] Method { get { return _method; } set { if (value == null) { _method = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _method = new byte[value.Length]; Array.Copy(value, _method, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 16; if (Method != null) { length += 1 + Method.Length; } return length; } } /// Default constructor public MethodDataBlock() { } /// Constructor for building the block from a byte array public MethodDataBlock(byte[] bytes, ref int i) { int length; try { Invoice = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _method = new byte[length]; Array.Copy(bytes, i, _method, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Invoice == null) { Console.WriteLine("Warning: Invoice is null, in " + this.GetType()); } Array.Copy(Invoice.GetBytes(), 0, bytes, i, 16); i += 16; if(Method == null) { Console.WriteLine("Warning: Method is null, in " + this.GetType()); } bytes[i++] = (byte)Method.Length; Array.Copy(Method, 0, bytes, i, Method.Length); i += Method.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MethodData --\n"; output += "Invoice: " + Invoice.ToString() + "\n"; output += Helpers.FieldToString(Method, "Method") + "\n"; output = output.Trim(); return output; } } /// ParamList block public class ParamListBlock { private byte[] _parameter; /// Parameter field public byte[] Parameter { get { return _parameter; } set { if (value == null) { _parameter = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _parameter = new byte[value.Length]; Array.Copy(value, _parameter, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (Parameter != null) { length += 1 + Parameter.Length; } return length; } } /// Default constructor public ParamListBlock() { } /// Constructor for building the block from a byte array public ParamListBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _parameter = new byte[length]; Array.Copy(bytes, i, _parameter, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Parameter == null) { Console.WriteLine("Warning: Parameter is null, in " + this.GetType()); } bytes[i++] = (byte)Parameter.Length; Array.Copy(Parameter, 0, bytes, i, Parameter.Length); i += Parameter.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParamList --\n"; output += Helpers.FieldToString(Parameter, "Parameter") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GenericMessage public override PacketType Type { get { return PacketType.GenericMessage; } } /// MethodData block public MethodDataBlock MethodData; /// ParamList block public ParamListBlock[] ParamList; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GenericMessagePacket() { Header = new LowHeader(); Header.ID = 313; Header.Reliable = true; Header.Zerocoded = true; MethodData = new MethodDataBlock(); ParamList = new ParamListBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GenericMessagePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MethodData = new MethodDataBlock(bytes, ref i); int count = (int)bytes[i++]; ParamList = new ParamListBlock[count]; for (int j = 0; j < count; j++) { ParamList[j] = new ParamListBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GenericMessagePacket(Header head, byte[] bytes, ref int i) { Header = head; MethodData = new MethodDataBlock(bytes, ref i); int count = (int)bytes[i++]; ParamList = new ParamListBlock[count]; for (int j = 0; j < count; j++) { ParamList[j] = new ParamListBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MethodData.Length; length += AgentData.Length;; length++; for (int j = 0; j < ParamList.Length; j++) { length += ParamList[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MethodData.ToBytes(bytes, ref i); bytes[i++] = (byte)ParamList.Length; for (int j = 0; j < ParamList.Length; j++) { ParamList[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GenericMessage ---\n"; output += MethodData.ToString() + "\n"; for (int j = 0; j < ParamList.Length; j++) { output += ParamList[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// MuteListRequest packet public class MuteListRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// MuteData block public class MuteDataBlock { /// MuteCRC field public uint MuteCRC; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public MuteDataBlock() { } /// Constructor for building the block from a byte array public MuteDataBlock(byte[] bytes, ref int i) { try { MuteCRC = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(MuteCRC % 256); bytes[i++] = (byte)((MuteCRC >> 8) % 256); bytes[i++] = (byte)((MuteCRC >> 16) % 256); bytes[i++] = (byte)((MuteCRC >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MuteData --\n"; output += "MuteCRC: " + MuteCRC.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MuteListRequest public override PacketType Type { get { return PacketType.MuteListRequest; } } /// AgentData block public AgentDataBlock AgentData; /// MuteData block public MuteDataBlock MuteData; /// Default constructor public MuteListRequestPacket() { Header = new LowHeader(); Header.ID = 314; Header.Reliable = true; AgentData = new AgentDataBlock(); MuteData = new MuteDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MuteListRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); MuteData = new MuteDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MuteListRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); MuteData = new MuteDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += MuteData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); MuteData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MuteListRequest ---\n"; output += AgentData.ToString() + "\n"; output += MuteData.ToString() + "\n"; return output; } } /// UpdateMuteListEntry packet public class UpdateMuteListEntryPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// MuteData block public class MuteDataBlock { /// MuteID field public LLUUID MuteID; /// MuteFlags field public uint MuteFlags; private byte[] _mutename; /// MuteName field public byte[] MuteName { get { return _mutename; } set { if (value == null) { _mutename = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _mutename = new byte[value.Length]; Array.Copy(value, _mutename, value.Length); } } } /// MuteType field public int MuteType; /// Length of this block serialized in bytes public int Length { get { int length = 24; if (MuteName != null) { length += 1 + MuteName.Length; } return length; } } /// Default constructor public MuteDataBlock() { } /// Constructor for building the block from a byte array public MuteDataBlock(byte[] bytes, ref int i) { int length; try { MuteID = new LLUUID(bytes, i); i += 16; MuteFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _mutename = new byte[length]; Array.Copy(bytes, i, _mutename, 0, length); i += length; MuteType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(MuteID == null) { Console.WriteLine("Warning: MuteID is null, in " + this.GetType()); } Array.Copy(MuteID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(MuteFlags % 256); bytes[i++] = (byte)((MuteFlags >> 8) % 256); bytes[i++] = (byte)((MuteFlags >> 16) % 256); bytes[i++] = (byte)((MuteFlags >> 24) % 256); if(MuteName == null) { Console.WriteLine("Warning: MuteName is null, in " + this.GetType()); } bytes[i++] = (byte)MuteName.Length; Array.Copy(MuteName, 0, bytes, i, MuteName.Length); i += MuteName.Length; bytes[i++] = (byte)(MuteType % 256); bytes[i++] = (byte)((MuteType >> 8) % 256); bytes[i++] = (byte)((MuteType >> 16) % 256); bytes[i++] = (byte)((MuteType >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MuteData --\n"; output += "MuteID: " + MuteID.ToString() + "\n"; output += "MuteFlags: " + MuteFlags.ToString() + "\n"; output += Helpers.FieldToString(MuteName, "MuteName") + "\n"; output += "MuteType: " + MuteType.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UpdateMuteListEntry public override PacketType Type { get { return PacketType.UpdateMuteListEntry; } } /// AgentData block public AgentDataBlock AgentData; /// MuteData block public MuteDataBlock MuteData; /// Default constructor public UpdateMuteListEntryPacket() { Header = new LowHeader(); Header.ID = 315; Header.Reliable = true; AgentData = new AgentDataBlock(); MuteData = new MuteDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UpdateMuteListEntryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); MuteData = new MuteDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public UpdateMuteListEntryPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); MuteData = new MuteDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += MuteData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); MuteData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UpdateMuteListEntry ---\n"; output += AgentData.ToString() + "\n"; output += MuteData.ToString() + "\n"; return output; } } /// RemoveMuteListEntry packet public class RemoveMuteListEntryPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// MuteData block public class MuteDataBlock { /// MuteID field public LLUUID MuteID; private byte[] _mutename; /// MuteName field public byte[] MuteName { get { return _mutename; } set { if (value == null) { _mutename = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _mutename = new byte[value.Length]; Array.Copy(value, _mutename, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 16; if (MuteName != null) { length += 1 + MuteName.Length; } return length; } } /// Default constructor public MuteDataBlock() { } /// Constructor for building the block from a byte array public MuteDataBlock(byte[] bytes, ref int i) { int length; try { MuteID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _mutename = new byte[length]; Array.Copy(bytes, i, _mutename, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(MuteID == null) { Console.WriteLine("Warning: MuteID is null, in " + this.GetType()); } Array.Copy(MuteID.GetBytes(), 0, bytes, i, 16); i += 16; if(MuteName == null) { Console.WriteLine("Warning: MuteName is null, in " + this.GetType()); } bytes[i++] = (byte)MuteName.Length; Array.Copy(MuteName, 0, bytes, i, MuteName.Length); i += MuteName.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MuteData --\n"; output += "MuteID: " + MuteID.ToString() + "\n"; output += Helpers.FieldToString(MuteName, "MuteName") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RemoveMuteListEntry public override PacketType Type { get { return PacketType.RemoveMuteListEntry; } } /// AgentData block public AgentDataBlock AgentData; /// MuteData block public MuteDataBlock MuteData; /// Default constructor public RemoveMuteListEntryPacket() { Header = new LowHeader(); Header.ID = 316; Header.Reliable = true; AgentData = new AgentDataBlock(); MuteData = new MuteDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RemoveMuteListEntryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); MuteData = new MuteDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RemoveMuteListEntryPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); MuteData = new MuteDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += MuteData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); MuteData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RemoveMuteListEntry ---\n"; output += AgentData.ToString() + "\n"; output += MuteData.ToString() + "\n"; return output; } } /// CopyInventoryFromNotecard packet public class CopyInventoryFromNotecardPacket : Packet { /// InventoryData block public class InventoryDataBlock { /// ItemID field public LLUUID ItemID; /// FolderID field public LLUUID FolderID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { try { ItemID = new LLUUID(bytes, i); i += 16; FolderID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output = output.Trim(); return output; } } /// NotecardData block public class NotecardDataBlock { /// ObjectID field public LLUUID ObjectID; /// NotecardItemID field public LLUUID NotecardItemID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public NotecardDataBlock() { } /// Constructor for building the block from a byte array public NotecardDataBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; NotecardItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; if(NotecardItemID == null) { Console.WriteLine("Warning: NotecardItemID is null, in " + this.GetType()); } Array.Copy(NotecardItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- NotecardData --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "NotecardItemID: " + NotecardItemID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.CopyInventoryFromNotecard public override PacketType Type { get { return PacketType.CopyInventoryFromNotecard; } } /// InventoryData block public InventoryDataBlock[] InventoryData; /// NotecardData block public NotecardDataBlock NotecardData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public CopyInventoryFromNotecardPacket() { Header = new LowHeader(); Header.ID = 317; Header.Reliable = true; Header.Zerocoded = true; InventoryData = new InventoryDataBlock[0]; NotecardData = new NotecardDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public CopyInventoryFromNotecardPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } NotecardData = new NotecardDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public CopyInventoryFromNotecardPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } NotecardData = new NotecardDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += NotecardData.Length; length += AgentData.Length;; length++; for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)InventoryData.Length; for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } NotecardData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- CopyInventoryFromNotecard ---\n"; for (int j = 0; j < InventoryData.Length; j++) { output += InventoryData[j].ToString() + "\n"; } output += NotecardData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// UpdateInventoryItem packet public class UpdateInventoryItemPacket : Packet { /// InventoryData block public class InventoryDataBlock { /// GroupOwned field public bool GroupOwned; /// CRC field public uint CRC; /// CreationDate field public int CreationDate; /// SaleType field public byte SaleType; /// CallbackID field public uint CallbackID; /// BaseMask field public uint BaseMask; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// InvType field public sbyte InvType; /// Type field public sbyte Type; /// GroupID field public LLUUID GroupID; /// SalePrice field public int SalePrice; /// OwnerID field public LLUUID OwnerID; /// CreatorID field public LLUUID CreatorID; /// ItemID field public LLUUID ItemID; /// FolderID field public LLUUID FolderID; /// EveryoneMask field public uint EveryoneMask; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// Flags field public uint Flags; /// NextOwnerMask field public uint NextOwnerMask; /// TransactionID field public LLUUID TransactionID; /// GroupMask field public uint GroupMask; /// OwnerMask field public uint OwnerMask; /// Length of this block serialized in bytes public int Length { get { int length = 140; if (Name != null) { length += 1 + Name.Length; } if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { int length; try { GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; CRC = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CreationDate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SaleType = (byte)bytes[i++]; CallbackID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); BaseMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; InvType = (sbyte)bytes[i++]; Type = (sbyte)bytes[i++]; GroupID = new LLUUID(bytes, i); i += 16; SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerID = new LLUUID(bytes, i); i += 16; CreatorID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; FolderID = new LLUUID(bytes, i); i += 16; EveryoneMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); NextOwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TransactionID = new LLUUID(bytes, i); i += 16; GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((GroupOwned) ? 1 : 0); bytes[i++] = (byte)(CRC % 256); bytes[i++] = (byte)((CRC >> 8) % 256); bytes[i++] = (byte)((CRC >> 16) % 256); bytes[i++] = (byte)((CRC >> 24) % 256); bytes[i++] = (byte)(CreationDate % 256); bytes[i++] = (byte)((CreationDate >> 8) % 256); bytes[i++] = (byte)((CreationDate >> 16) % 256); bytes[i++] = (byte)((CreationDate >> 24) % 256); bytes[i++] = SaleType; bytes[i++] = (byte)(CallbackID % 256); bytes[i++] = (byte)((CallbackID >> 8) % 256); bytes[i++] = (byte)((CallbackID >> 16) % 256); bytes[i++] = (byte)((CallbackID >> 24) % 256); bytes[i++] = (byte)(BaseMask % 256); bytes[i++] = (byte)((BaseMask >> 8) % 256); bytes[i++] = (byte)((BaseMask >> 16) % 256); bytes[i++] = (byte)((BaseMask >> 24) % 256); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)InvType; bytes[i++] = (byte)Type; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(SalePrice % 256); bytes[i++] = (byte)((SalePrice >> 8) % 256); bytes[i++] = (byte)((SalePrice >> 16) % 256); bytes[i++] = (byte)((SalePrice >> 24) % 256); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(CreatorID == null) { Console.WriteLine("Warning: CreatorID is null, in " + this.GetType()); } Array.Copy(CreatorID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(EveryoneMask % 256); bytes[i++] = (byte)((EveryoneMask >> 8) % 256); bytes[i++] = (byte)((EveryoneMask >> 16) % 256); bytes[i++] = (byte)((EveryoneMask >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); bytes[i++] = (byte)(NextOwnerMask % 256); bytes[i++] = (byte)((NextOwnerMask >> 8) % 256); bytes[i++] = (byte)((NextOwnerMask >> 16) % 256); bytes[i++] = (byte)((NextOwnerMask >> 24) % 256); if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(GroupMask % 256); bytes[i++] = (byte)((GroupMask >> 8) % 256); bytes[i++] = (byte)((GroupMask >> 16) % 256); bytes[i++] = (byte)((GroupMask >> 24) % 256); bytes[i++] = (byte)(OwnerMask % 256); bytes[i++] = (byte)((OwnerMask >> 8) % 256); bytes[i++] = (byte)((OwnerMask >> 16) % 256); bytes[i++] = (byte)((OwnerMask >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "GroupOwned: " + GroupOwned.ToString() + "\n"; output += "CRC: " + CRC.ToString() + "\n"; output += "CreationDate: " + CreationDate.ToString() + "\n"; output += "SaleType: " + SaleType.ToString() + "\n"; output += "CallbackID: " + CallbackID.ToString() + "\n"; output += "BaseMask: " + BaseMask.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "InvType: " + InvType.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "SalePrice: " + SalePrice.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "CreatorID: " + CreatorID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output += "EveryoneMask: " + EveryoneMask.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "NextOwnerMask: " + NextOwnerMask.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output += "GroupMask: " + GroupMask.ToString() + "\n"; output += "OwnerMask: " + OwnerMask.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UpdateInventoryItem public override PacketType Type { get { return PacketType.UpdateInventoryItem; } } /// InventoryData block public InventoryDataBlock[] InventoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public UpdateInventoryItemPacket() { Header = new LowHeader(); Header.ID = 318; Header.Reliable = true; Header.Zerocoded = true; InventoryData = new InventoryDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UpdateInventoryItemPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public UpdateInventoryItemPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)InventoryData.Length; for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UpdateInventoryItem ---\n"; for (int j = 0; j < InventoryData.Length; j++) { output += InventoryData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// UpdateCreateInventoryItem packet public class UpdateCreateInventoryItemPacket : Packet { /// InventoryData block public class InventoryDataBlock { /// GroupOwned field public bool GroupOwned; /// CRC field public uint CRC; /// CreationDate field public int CreationDate; /// SaleType field public byte SaleType; /// CallbackID field public uint CallbackID; /// BaseMask field public uint BaseMask; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// InvType field public sbyte InvType; /// Type field public sbyte Type; /// AssetID field public LLUUID AssetID; /// GroupID field public LLUUID GroupID; /// SalePrice field public int SalePrice; /// OwnerID field public LLUUID OwnerID; /// CreatorID field public LLUUID CreatorID; /// ItemID field public LLUUID ItemID; /// FolderID field public LLUUID FolderID; /// EveryoneMask field public uint EveryoneMask; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// Flags field public uint Flags; /// NextOwnerMask field public uint NextOwnerMask; /// GroupMask field public uint GroupMask; /// OwnerMask field public uint OwnerMask; /// Length of this block serialized in bytes public int Length { get { int length = 140; if (Name != null) { length += 1 + Name.Length; } if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { int length; try { GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; CRC = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CreationDate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SaleType = (byte)bytes[i++]; CallbackID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); BaseMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; InvType = (sbyte)bytes[i++]; Type = (sbyte)bytes[i++]; AssetID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerID = new LLUUID(bytes, i); i += 16; CreatorID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; FolderID = new LLUUID(bytes, i); i += 16; EveryoneMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); NextOwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((GroupOwned) ? 1 : 0); bytes[i++] = (byte)(CRC % 256); bytes[i++] = (byte)((CRC >> 8) % 256); bytes[i++] = (byte)((CRC >> 16) % 256); bytes[i++] = (byte)((CRC >> 24) % 256); bytes[i++] = (byte)(CreationDate % 256); bytes[i++] = (byte)((CreationDate >> 8) % 256); bytes[i++] = (byte)((CreationDate >> 16) % 256); bytes[i++] = (byte)((CreationDate >> 24) % 256); bytes[i++] = SaleType; bytes[i++] = (byte)(CallbackID % 256); bytes[i++] = (byte)((CallbackID >> 8) % 256); bytes[i++] = (byte)((CallbackID >> 16) % 256); bytes[i++] = (byte)((CallbackID >> 24) % 256); bytes[i++] = (byte)(BaseMask % 256); bytes[i++] = (byte)((BaseMask >> 8) % 256); bytes[i++] = (byte)((BaseMask >> 16) % 256); bytes[i++] = (byte)((BaseMask >> 24) % 256); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)InvType; bytes[i++] = (byte)Type; if(AssetID == null) { Console.WriteLine("Warning: AssetID is null, in " + this.GetType()); } Array.Copy(AssetID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(SalePrice % 256); bytes[i++] = (byte)((SalePrice >> 8) % 256); bytes[i++] = (byte)((SalePrice >> 16) % 256); bytes[i++] = (byte)((SalePrice >> 24) % 256); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(CreatorID == null) { Console.WriteLine("Warning: CreatorID is null, in " + this.GetType()); } Array.Copy(CreatorID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(EveryoneMask % 256); bytes[i++] = (byte)((EveryoneMask >> 8) % 256); bytes[i++] = (byte)((EveryoneMask >> 16) % 256); bytes[i++] = (byte)((EveryoneMask >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); bytes[i++] = (byte)(NextOwnerMask % 256); bytes[i++] = (byte)((NextOwnerMask >> 8) % 256); bytes[i++] = (byte)((NextOwnerMask >> 16) % 256); bytes[i++] = (byte)((NextOwnerMask >> 24) % 256); bytes[i++] = (byte)(GroupMask % 256); bytes[i++] = (byte)((GroupMask >> 8) % 256); bytes[i++] = (byte)((GroupMask >> 16) % 256); bytes[i++] = (byte)((GroupMask >> 24) % 256); bytes[i++] = (byte)(OwnerMask % 256); bytes[i++] = (byte)((OwnerMask >> 8) % 256); bytes[i++] = (byte)((OwnerMask >> 16) % 256); bytes[i++] = (byte)((OwnerMask >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "GroupOwned: " + GroupOwned.ToString() + "\n"; output += "CRC: " + CRC.ToString() + "\n"; output += "CreationDate: " + CreationDate.ToString() + "\n"; output += "SaleType: " + SaleType.ToString() + "\n"; output += "CallbackID: " + CallbackID.ToString() + "\n"; output += "BaseMask: " + BaseMask.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "InvType: " + InvType.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "AssetID: " + AssetID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "SalePrice: " + SalePrice.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "CreatorID: " + CreatorID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output += "EveryoneMask: " + EveryoneMask.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "NextOwnerMask: " + NextOwnerMask.ToString() + "\n"; output += "GroupMask: " + GroupMask.ToString() + "\n"; output += "OwnerMask: " + OwnerMask.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SimApproved field public bool SimApproved; /// Length of this block serialized in bytes public int Length { get { return 17; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SimApproved = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((SimApproved) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SimApproved: " + SimApproved.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UpdateCreateInventoryItem public override PacketType Type { get { return PacketType.UpdateCreateInventoryItem; } } /// InventoryData block public InventoryDataBlock[] InventoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public UpdateCreateInventoryItemPacket() { Header = new LowHeader(); Header.ID = 319; Header.Reliable = true; Header.Zerocoded = true; InventoryData = new InventoryDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UpdateCreateInventoryItemPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public UpdateCreateInventoryItemPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)InventoryData.Length; for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UpdateCreateInventoryItem ---\n"; for (int j = 0; j < InventoryData.Length; j++) { output += InventoryData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// MoveInventoryItem packet public class MoveInventoryItemPacket : Packet { /// InventoryData block public class InventoryDataBlock { private byte[] _newname; /// NewName field public byte[] NewName { get { return _newname; } set { if (value == null) { _newname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _newname = new byte[value.Length]; Array.Copy(value, _newname, value.Length); } } } /// ItemID field public LLUUID ItemID; /// FolderID field public LLUUID FolderID; /// Length of this block serialized in bytes public int Length { get { int length = 32; if (NewName != null) { length += 1 + NewName.Length; } return length; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _newname = new byte[length]; Array.Copy(bytes, i, _newname, 0, length); i += length; ItemID = new LLUUID(bytes, i); i += 16; FolderID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(NewName == null) { Console.WriteLine("Warning: NewName is null, in " + this.GetType()); } bytes[i++] = (byte)NewName.Length; Array.Copy(NewName, 0, bytes, i, NewName.Length); i += NewName.Length; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += Helpers.FieldToString(NewName, "NewName") + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Stamp field public bool Stamp; /// Length of this block serialized in bytes public int Length { get { return 33; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; Stamp = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((Stamp) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "Stamp: " + Stamp.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MoveInventoryItem public override PacketType Type { get { return PacketType.MoveInventoryItem; } } /// InventoryData block public InventoryDataBlock[] InventoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public MoveInventoryItemPacket() { Header = new LowHeader(); Header.ID = 320; Header.Reliable = true; Header.Zerocoded = true; InventoryData = new InventoryDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MoveInventoryItemPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MoveInventoryItemPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)InventoryData.Length; for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MoveInventoryItem ---\n"; for (int j = 0; j < InventoryData.Length; j++) { output += InventoryData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// CopyInventoryItem packet public class CopyInventoryItemPacket : Packet { /// InventoryData block public class InventoryDataBlock { private byte[] _newname; /// NewName field public byte[] NewName { get { return _newname; } set { if (value == null) { _newname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _newname = new byte[value.Length]; Array.Copy(value, _newname, value.Length); } } } /// NewFolderID field public LLUUID NewFolderID; /// CallbackID field public uint CallbackID; /// OldItemID field public LLUUID OldItemID; /// OldAgentID field public LLUUID OldAgentID; /// Length of this block serialized in bytes public int Length { get { int length = 52; if (NewName != null) { length += 1 + NewName.Length; } return length; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _newname = new byte[length]; Array.Copy(bytes, i, _newname, 0, length); i += length; NewFolderID = new LLUUID(bytes, i); i += 16; CallbackID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OldItemID = new LLUUID(bytes, i); i += 16; OldAgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(NewName == null) { Console.WriteLine("Warning: NewName is null, in " + this.GetType()); } bytes[i++] = (byte)NewName.Length; Array.Copy(NewName, 0, bytes, i, NewName.Length); i += NewName.Length; if(NewFolderID == null) { Console.WriteLine("Warning: NewFolderID is null, in " + this.GetType()); } Array.Copy(NewFolderID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(CallbackID % 256); bytes[i++] = (byte)((CallbackID >> 8) % 256); bytes[i++] = (byte)((CallbackID >> 16) % 256); bytes[i++] = (byte)((CallbackID >> 24) % 256); if(OldItemID == null) { Console.WriteLine("Warning: OldItemID is null, in " + this.GetType()); } Array.Copy(OldItemID.GetBytes(), 0, bytes, i, 16); i += 16; if(OldAgentID == null) { Console.WriteLine("Warning: OldAgentID is null, in " + this.GetType()); } Array.Copy(OldAgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += Helpers.FieldToString(NewName, "NewName") + "\n"; output += "NewFolderID: " + NewFolderID.ToString() + "\n"; output += "CallbackID: " + CallbackID.ToString() + "\n"; output += "OldItemID: " + OldItemID.ToString() + "\n"; output += "OldAgentID: " + OldAgentID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.CopyInventoryItem public override PacketType Type { get { return PacketType.CopyInventoryItem; } } /// InventoryData block public InventoryDataBlock[] InventoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public CopyInventoryItemPacket() { Header = new LowHeader(); Header.ID = 321; Header.Reliable = true; Header.Zerocoded = true; InventoryData = new InventoryDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public CopyInventoryItemPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public CopyInventoryItemPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)InventoryData.Length; for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- CopyInventoryItem ---\n"; for (int j = 0; j < InventoryData.Length; j++) { output += InventoryData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// RemoveInventoryItem packet public class RemoveInventoryItemPacket : Packet { /// InventoryData block public class InventoryDataBlock { /// ItemID field public LLUUID ItemID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { try { ItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RemoveInventoryItem public override PacketType Type { get { return PacketType.RemoveInventoryItem; } } /// InventoryData block public InventoryDataBlock[] InventoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RemoveInventoryItemPacket() { Header = new LowHeader(); Header.ID = 322; Header.Reliable = true; InventoryData = new InventoryDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RemoveInventoryItemPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RemoveInventoryItemPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)InventoryData.Length; for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RemoveInventoryItem ---\n"; for (int j = 0; j < InventoryData.Length; j++) { output += InventoryData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ChangeInventoryItemFlags packet public class ChangeInventoryItemFlagsPacket : Packet { /// InventoryData block public class InventoryDataBlock { /// ItemID field public LLUUID ItemID; /// Flags field public uint Flags; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { try { ItemID = new LLUUID(bytes, i); i += 16; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ChangeInventoryItemFlags public override PacketType Type { get { return PacketType.ChangeInventoryItemFlags; } } /// InventoryData block public InventoryDataBlock[] InventoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ChangeInventoryItemFlagsPacket() { Header = new LowHeader(); Header.ID = 323; Header.Reliable = true; InventoryData = new InventoryDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ChangeInventoryItemFlagsPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ChangeInventoryItemFlagsPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)InventoryData.Length; for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ChangeInventoryItemFlags ---\n"; for (int j = 0; j < InventoryData.Length; j++) { output += InventoryData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// SaveAssetIntoInventory packet public class SaveAssetIntoInventoryPacket : Packet { /// InventoryData block public class InventoryDataBlock { /// NewAssetID field public LLUUID NewAssetID; /// ItemID field public LLUUID ItemID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { try { NewAssetID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(NewAssetID == null) { Console.WriteLine("Warning: NewAssetID is null, in " + this.GetType()); } Array.Copy(NewAssetID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "NewAssetID: " + NewAssetID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SaveAssetIntoInventory public override PacketType Type { get { return PacketType.SaveAssetIntoInventory; } } /// InventoryData block public InventoryDataBlock InventoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public SaveAssetIntoInventoryPacket() { Header = new LowHeader(); Header.ID = 324; Header.Reliable = true; InventoryData = new InventoryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SaveAssetIntoInventoryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); InventoryData = new InventoryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SaveAssetIntoInventoryPacket(Header head, byte[] bytes, ref int i) { Header = head; InventoryData = new InventoryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += InventoryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); InventoryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SaveAssetIntoInventory ---\n"; output += InventoryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// CreateInventoryFolder packet public class CreateInventoryFolderPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// FolderData block public class FolderDataBlock { private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// ParentID field public LLUUID ParentID; /// Type field public sbyte Type; /// FolderID field public LLUUID FolderID; /// Length of this block serialized in bytes public int Length { get { int length = 33; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public FolderDataBlock() { } /// Constructor for building the block from a byte array public FolderDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; ParentID = new LLUUID(bytes, i); i += 16; Type = (sbyte)bytes[i++]; FolderID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(ParentID == null) { Console.WriteLine("Warning: ParentID is null, in " + this.GetType()); } Array.Copy(ParentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)Type; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- FolderData --\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "ParentID: " + ParentID.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.CreateInventoryFolder public override PacketType Type { get { return PacketType.CreateInventoryFolder; } } /// AgentData block public AgentDataBlock AgentData; /// FolderData block public FolderDataBlock FolderData; /// Default constructor public CreateInventoryFolderPacket() { Header = new LowHeader(); Header.ID = 325; Header.Reliable = true; AgentData = new AgentDataBlock(); FolderData = new FolderDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public CreateInventoryFolderPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); FolderData = new FolderDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public CreateInventoryFolderPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); FolderData = new FolderDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += FolderData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); FolderData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- CreateInventoryFolder ---\n"; output += AgentData.ToString() + "\n"; output += FolderData.ToString() + "\n"; return output; } } /// UpdateInventoryFolder packet public class UpdateInventoryFolderPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// FolderData block public class FolderDataBlock { private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// ParentID field public LLUUID ParentID; /// Type field public sbyte Type; /// FolderID field public LLUUID FolderID; /// Length of this block serialized in bytes public int Length { get { int length = 33; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public FolderDataBlock() { } /// Constructor for building the block from a byte array public FolderDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; ParentID = new LLUUID(bytes, i); i += 16; Type = (sbyte)bytes[i++]; FolderID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(ParentID == null) { Console.WriteLine("Warning: ParentID is null, in " + this.GetType()); } Array.Copy(ParentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)Type; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- FolderData --\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "ParentID: " + ParentID.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UpdateInventoryFolder public override PacketType Type { get { return PacketType.UpdateInventoryFolder; } } /// AgentData block public AgentDataBlock AgentData; /// FolderData block public FolderDataBlock[] FolderData; /// Default constructor public UpdateInventoryFolderPacket() { Header = new LowHeader(); Header.ID = 326; Header.Reliable = true; AgentData = new AgentDataBlock(); FolderData = new FolderDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UpdateInventoryFolderPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); int count = (int)bytes[i++]; FolderData = new FolderDataBlock[count]; for (int j = 0; j < count; j++) { FolderData[j] = new FolderDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public UpdateInventoryFolderPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); int count = (int)bytes[i++]; FolderData = new FolderDataBlock[count]; for (int j = 0; j < count; j++) { FolderData[j] = new FolderDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); bytes[i++] = (byte)FolderData.Length; for (int j = 0; j < FolderData.Length; j++) { FolderData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UpdateInventoryFolder ---\n"; output += AgentData.ToString() + "\n"; for (int j = 0; j < FolderData.Length; j++) { output += FolderData[j].ToString() + "\n"; } return output; } } /// MoveInventoryFolder packet public class MoveInventoryFolderPacket : Packet { /// InventoryData block public class InventoryDataBlock { /// ParentID field public LLUUID ParentID; /// FolderID field public LLUUID FolderID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { try { ParentID = new LLUUID(bytes, i); i += 16; FolderID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ParentID == null) { Console.WriteLine("Warning: ParentID is null, in " + this.GetType()); } Array.Copy(ParentID.GetBytes(), 0, bytes, i, 16); i += 16; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "ParentID: " + ParentID.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Stamp field public bool Stamp; /// Length of this block serialized in bytes public int Length { get { return 33; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; Stamp = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((Stamp) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "Stamp: " + Stamp.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MoveInventoryFolder public override PacketType Type { get { return PacketType.MoveInventoryFolder; } } /// InventoryData block public InventoryDataBlock[] InventoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public MoveInventoryFolderPacket() { Header = new LowHeader(); Header.ID = 327; Header.Reliable = true; Header.Zerocoded = true; InventoryData = new InventoryDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MoveInventoryFolderPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MoveInventoryFolderPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)InventoryData.Length; for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MoveInventoryFolder ---\n"; for (int j = 0; j < InventoryData.Length; j++) { output += InventoryData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// RemoveInventoryFolder packet public class RemoveInventoryFolderPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// FolderData block public class FolderDataBlock { /// FolderID field public LLUUID FolderID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public FolderDataBlock() { } /// Constructor for building the block from a byte array public FolderDataBlock(byte[] bytes, ref int i) { try { FolderID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- FolderData --\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RemoveInventoryFolder public override PacketType Type { get { return PacketType.RemoveInventoryFolder; } } /// AgentData block public AgentDataBlock AgentData; /// FolderData block public FolderDataBlock[] FolderData; /// Default constructor public RemoveInventoryFolderPacket() { Header = new LowHeader(); Header.ID = 328; Header.Reliable = true; AgentData = new AgentDataBlock(); FolderData = new FolderDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RemoveInventoryFolderPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); int count = (int)bytes[i++]; FolderData = new FolderDataBlock[count]; for (int j = 0; j < count; j++) { FolderData[j] = new FolderDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public RemoveInventoryFolderPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); int count = (int)bytes[i++]; FolderData = new FolderDataBlock[count]; for (int j = 0; j < count; j++) { FolderData[j] = new FolderDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); bytes[i++] = (byte)FolderData.Length; for (int j = 0; j < FolderData.Length; j++) { FolderData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RemoveInventoryFolder ---\n"; output += AgentData.ToString() + "\n"; for (int j = 0; j < FolderData.Length; j++) { output += FolderData[j].ToString() + "\n"; } return output; } } /// FetchInventoryDescendents packet public class FetchInventoryDescendentsPacket : Packet { /// InventoryData block public class InventoryDataBlock { /// OwnerID field public LLUUID OwnerID; /// FolderID field public LLUUID FolderID; /// SortOrder field public int SortOrder; /// FetchFolders field public bool FetchFolders; /// FetchItems field public bool FetchItems; /// Length of this block serialized in bytes public int Length { get { return 38; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { try { OwnerID = new LLUUID(bytes, i); i += 16; FolderID = new LLUUID(bytes, i); i += 16; SortOrder = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); FetchFolders = (bytes[i++] != 0) ? (bool)true : (bool)false; FetchItems = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(SortOrder % 256); bytes[i++] = (byte)((SortOrder >> 8) % 256); bytes[i++] = (byte)((SortOrder >> 16) % 256); bytes[i++] = (byte)((SortOrder >> 24) % 256); bytes[i++] = (byte)((FetchFolders) ? 1 : 0); bytes[i++] = (byte)((FetchItems) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output += "SortOrder: " + SortOrder.ToString() + "\n"; output += "FetchFolders: " + FetchFolders.ToString() + "\n"; output += "FetchItems: " + FetchItems.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.FetchInventoryDescendents public override PacketType Type { get { return PacketType.FetchInventoryDescendents; } } /// InventoryData block public InventoryDataBlock InventoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public FetchInventoryDescendentsPacket() { Header = new LowHeader(); Header.ID = 329; Header.Reliable = true; Header.Zerocoded = true; InventoryData = new InventoryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public FetchInventoryDescendentsPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); InventoryData = new InventoryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public FetchInventoryDescendentsPacket(Header head, byte[] bytes, ref int i) { Header = head; InventoryData = new InventoryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += InventoryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); InventoryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- FetchInventoryDescendents ---\n"; output += InventoryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// InventoryDescendents packet public class InventoryDescendentsPacket : Packet { /// ItemData block public class ItemDataBlock { /// GroupOwned field public bool GroupOwned; /// CRC field public uint CRC; /// CreationDate field public int CreationDate; /// SaleType field public byte SaleType; /// BaseMask field public uint BaseMask; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// InvType field public sbyte InvType; /// Type field public sbyte Type; /// AssetID field public LLUUID AssetID; /// GroupID field public LLUUID GroupID; /// SalePrice field public int SalePrice; /// OwnerID field public LLUUID OwnerID; /// CreatorID field public LLUUID CreatorID; /// ItemID field public LLUUID ItemID; /// FolderID field public LLUUID FolderID; /// EveryoneMask field public uint EveryoneMask; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// Flags field public uint Flags; /// NextOwnerMask field public uint NextOwnerMask; /// GroupMask field public uint GroupMask; /// OwnerMask field public uint OwnerMask; /// Length of this block serialized in bytes public int Length { get { int length = 136; if (Name != null) { length += 1 + Name.Length; } if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public ItemDataBlock() { } /// Constructor for building the block from a byte array public ItemDataBlock(byte[] bytes, ref int i) { int length; try { GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; CRC = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CreationDate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SaleType = (byte)bytes[i++]; BaseMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; InvType = (sbyte)bytes[i++]; Type = (sbyte)bytes[i++]; AssetID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerID = new LLUUID(bytes, i); i += 16; CreatorID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; FolderID = new LLUUID(bytes, i); i += 16; EveryoneMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); NextOwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((GroupOwned) ? 1 : 0); bytes[i++] = (byte)(CRC % 256); bytes[i++] = (byte)((CRC >> 8) % 256); bytes[i++] = (byte)((CRC >> 16) % 256); bytes[i++] = (byte)((CRC >> 24) % 256); bytes[i++] = (byte)(CreationDate % 256); bytes[i++] = (byte)((CreationDate >> 8) % 256); bytes[i++] = (byte)((CreationDate >> 16) % 256); bytes[i++] = (byte)((CreationDate >> 24) % 256); bytes[i++] = SaleType; bytes[i++] = (byte)(BaseMask % 256); bytes[i++] = (byte)((BaseMask >> 8) % 256); bytes[i++] = (byte)((BaseMask >> 16) % 256); bytes[i++] = (byte)((BaseMask >> 24) % 256); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)InvType; bytes[i++] = (byte)Type; if(AssetID == null) { Console.WriteLine("Warning: AssetID is null, in " + this.GetType()); } Array.Copy(AssetID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(SalePrice % 256); bytes[i++] = (byte)((SalePrice >> 8) % 256); bytes[i++] = (byte)((SalePrice >> 16) % 256); bytes[i++] = (byte)((SalePrice >> 24) % 256); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(CreatorID == null) { Console.WriteLine("Warning: CreatorID is null, in " + this.GetType()); } Array.Copy(CreatorID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(EveryoneMask % 256); bytes[i++] = (byte)((EveryoneMask >> 8) % 256); bytes[i++] = (byte)((EveryoneMask >> 16) % 256); bytes[i++] = (byte)((EveryoneMask >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); bytes[i++] = (byte)(NextOwnerMask % 256); bytes[i++] = (byte)((NextOwnerMask >> 8) % 256); bytes[i++] = (byte)((NextOwnerMask >> 16) % 256); bytes[i++] = (byte)((NextOwnerMask >> 24) % 256); bytes[i++] = (byte)(GroupMask % 256); bytes[i++] = (byte)((GroupMask >> 8) % 256); bytes[i++] = (byte)((GroupMask >> 16) % 256); bytes[i++] = (byte)((GroupMask >> 24) % 256); bytes[i++] = (byte)(OwnerMask % 256); bytes[i++] = (byte)((OwnerMask >> 8) % 256); bytes[i++] = (byte)((OwnerMask >> 16) % 256); bytes[i++] = (byte)((OwnerMask >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ItemData --\n"; output += "GroupOwned: " + GroupOwned.ToString() + "\n"; output += "CRC: " + CRC.ToString() + "\n"; output += "CreationDate: " + CreationDate.ToString() + "\n"; output += "SaleType: " + SaleType.ToString() + "\n"; output += "BaseMask: " + BaseMask.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "InvType: " + InvType.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "AssetID: " + AssetID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "SalePrice: " + SalePrice.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "CreatorID: " + CreatorID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output += "EveryoneMask: " + EveryoneMask.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "NextOwnerMask: " + NextOwnerMask.ToString() + "\n"; output += "GroupMask: " + GroupMask.ToString() + "\n"; output += "OwnerMask: " + OwnerMask.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Descendents field public int Descendents; /// Version field public int Version; /// OwnerID field public LLUUID OwnerID; /// FolderID field public LLUUID FolderID; /// Length of this block serialized in bytes public int Length { get { return 56; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; Descendents = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Version = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerID = new LLUUID(bytes, i); i += 16; FolderID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Descendents % 256); bytes[i++] = (byte)((Descendents >> 8) % 256); bytes[i++] = (byte)((Descendents >> 16) % 256); bytes[i++] = (byte)((Descendents >> 24) % 256); bytes[i++] = (byte)(Version % 256); bytes[i++] = (byte)((Version >> 8) % 256); bytes[i++] = (byte)((Version >> 16) % 256); bytes[i++] = (byte)((Version >> 24) % 256); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "Descendents: " + Descendents.ToString() + "\n"; output += "Version: " + Version.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output = output.Trim(); return output; } } /// FolderData block public class FolderDataBlock { private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// ParentID field public LLUUID ParentID; /// Type field public sbyte Type; /// FolderID field public LLUUID FolderID; /// Length of this block serialized in bytes public int Length { get { int length = 33; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public FolderDataBlock() { } /// Constructor for building the block from a byte array public FolderDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; ParentID = new LLUUID(bytes, i); i += 16; Type = (sbyte)bytes[i++]; FolderID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(ParentID == null) { Console.WriteLine("Warning: ParentID is null, in " + this.GetType()); } Array.Copy(ParentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)Type; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- FolderData --\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "ParentID: " + ParentID.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.InventoryDescendents public override PacketType Type { get { return PacketType.InventoryDescendents; } } /// ItemData block public ItemDataBlock[] ItemData; /// AgentData block public AgentDataBlock AgentData; /// FolderData block public FolderDataBlock[] FolderData; /// Default constructor public InventoryDescendentsPacket() { Header = new LowHeader(); Header.ID = 330; Header.Reliable = true; Header.Zerocoded = true; ItemData = new ItemDataBlock[0]; AgentData = new AgentDataBlock(); FolderData = new FolderDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public InventoryDescendentsPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ItemData = new ItemDataBlock[count]; for (int j = 0; j < count; j++) { ItemData[j] = new ItemDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); count = (int)bytes[i++]; FolderData = new FolderDataBlock[count]; for (int j = 0; j < count; j++) { FolderData[j] = new FolderDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public InventoryDescendentsPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ItemData = new ItemDataBlock[count]; for (int j = 0; j < count; j++) { ItemData[j] = new ItemDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); count = (int)bytes[i++]; FolderData = new FolderDataBlock[count]; for (int j = 0; j < count; j++) { FolderData[j] = new FolderDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ItemData.Length; j++) { length += ItemData[j].Length; } length++; for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ItemData.Length; for (int j = 0; j < ItemData.Length; j++) { ItemData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); bytes[i++] = (byte)FolderData.Length; for (int j = 0; j < FolderData.Length; j++) { FolderData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- InventoryDescendents ---\n"; for (int j = 0; j < ItemData.Length; j++) { output += ItemData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; for (int j = 0; j < FolderData.Length; j++) { output += FolderData[j].ToString() + "\n"; } return output; } } /// FetchInventory packet public class FetchInventoryPacket : Packet { /// InventoryData block public class InventoryDataBlock { /// OwnerID field public LLUUID OwnerID; /// ItemID field public LLUUID ItemID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { try { OwnerID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.FetchInventory public override PacketType Type { get { return PacketType.FetchInventory; } } /// InventoryData block public InventoryDataBlock[] InventoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public FetchInventoryPacket() { Header = new LowHeader(); Header.ID = 331; Header.Reliable = true; Header.Zerocoded = true; InventoryData = new InventoryDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public FetchInventoryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public FetchInventoryPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)InventoryData.Length; for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- FetchInventory ---\n"; for (int j = 0; j < InventoryData.Length; j++) { output += InventoryData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// FetchInventoryReply packet public class FetchInventoryReplyPacket : Packet { /// InventoryData block public class InventoryDataBlock { /// GroupOwned field public bool GroupOwned; /// CRC field public uint CRC; /// CreationDate field public int CreationDate; /// SaleType field public byte SaleType; /// BaseMask field public uint BaseMask; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// InvType field public sbyte InvType; /// Type field public sbyte Type; /// AssetID field public LLUUID AssetID; /// GroupID field public LLUUID GroupID; /// SalePrice field public int SalePrice; /// OwnerID field public LLUUID OwnerID; /// CreatorID field public LLUUID CreatorID; /// ItemID field public LLUUID ItemID; /// FolderID field public LLUUID FolderID; /// EveryoneMask field public uint EveryoneMask; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// Flags field public uint Flags; /// NextOwnerMask field public uint NextOwnerMask; /// GroupMask field public uint GroupMask; /// OwnerMask field public uint OwnerMask; /// Length of this block serialized in bytes public int Length { get { int length = 136; if (Name != null) { length += 1 + Name.Length; } if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { int length; try { GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; CRC = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CreationDate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SaleType = (byte)bytes[i++]; BaseMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; InvType = (sbyte)bytes[i++]; Type = (sbyte)bytes[i++]; AssetID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerID = new LLUUID(bytes, i); i += 16; CreatorID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; FolderID = new LLUUID(bytes, i); i += 16; EveryoneMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); NextOwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((GroupOwned) ? 1 : 0); bytes[i++] = (byte)(CRC % 256); bytes[i++] = (byte)((CRC >> 8) % 256); bytes[i++] = (byte)((CRC >> 16) % 256); bytes[i++] = (byte)((CRC >> 24) % 256); bytes[i++] = (byte)(CreationDate % 256); bytes[i++] = (byte)((CreationDate >> 8) % 256); bytes[i++] = (byte)((CreationDate >> 16) % 256); bytes[i++] = (byte)((CreationDate >> 24) % 256); bytes[i++] = SaleType; bytes[i++] = (byte)(BaseMask % 256); bytes[i++] = (byte)((BaseMask >> 8) % 256); bytes[i++] = (byte)((BaseMask >> 16) % 256); bytes[i++] = (byte)((BaseMask >> 24) % 256); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)InvType; bytes[i++] = (byte)Type; if(AssetID == null) { Console.WriteLine("Warning: AssetID is null, in " + this.GetType()); } Array.Copy(AssetID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(SalePrice % 256); bytes[i++] = (byte)((SalePrice >> 8) % 256); bytes[i++] = (byte)((SalePrice >> 16) % 256); bytes[i++] = (byte)((SalePrice >> 24) % 256); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(CreatorID == null) { Console.WriteLine("Warning: CreatorID is null, in " + this.GetType()); } Array.Copy(CreatorID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(EveryoneMask % 256); bytes[i++] = (byte)((EveryoneMask >> 8) % 256); bytes[i++] = (byte)((EveryoneMask >> 16) % 256); bytes[i++] = (byte)((EveryoneMask >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); bytes[i++] = (byte)(NextOwnerMask % 256); bytes[i++] = (byte)((NextOwnerMask >> 8) % 256); bytes[i++] = (byte)((NextOwnerMask >> 16) % 256); bytes[i++] = (byte)((NextOwnerMask >> 24) % 256); bytes[i++] = (byte)(GroupMask % 256); bytes[i++] = (byte)((GroupMask >> 8) % 256); bytes[i++] = (byte)((GroupMask >> 16) % 256); bytes[i++] = (byte)((GroupMask >> 24) % 256); bytes[i++] = (byte)(OwnerMask % 256); bytes[i++] = (byte)((OwnerMask >> 8) % 256); bytes[i++] = (byte)((OwnerMask >> 16) % 256); bytes[i++] = (byte)((OwnerMask >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "GroupOwned: " + GroupOwned.ToString() + "\n"; output += "CRC: " + CRC.ToString() + "\n"; output += "CreationDate: " + CreationDate.ToString() + "\n"; output += "SaleType: " + SaleType.ToString() + "\n"; output += "BaseMask: " + BaseMask.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "InvType: " + InvType.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "AssetID: " + AssetID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "SalePrice: " + SalePrice.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "CreatorID: " + CreatorID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output += "EveryoneMask: " + EveryoneMask.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "NextOwnerMask: " + NextOwnerMask.ToString() + "\n"; output += "GroupMask: " + GroupMask.ToString() + "\n"; output += "OwnerMask: " + OwnerMask.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.FetchInventoryReply public override PacketType Type { get { return PacketType.FetchInventoryReply; } } /// InventoryData block public InventoryDataBlock[] InventoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public FetchInventoryReplyPacket() { Header = new LowHeader(); Header.ID = 332; Header.Reliable = true; Header.Zerocoded = true; InventoryData = new InventoryDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public FetchInventoryReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public FetchInventoryReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)InventoryData.Length; for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- FetchInventoryReply ---\n"; for (int j = 0; j < InventoryData.Length; j++) { output += InventoryData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// BulkUpdateInventory packet public class BulkUpdateInventoryPacket : Packet { /// ItemData block public class ItemDataBlock { /// GroupOwned field public bool GroupOwned; /// CRC field public uint CRC; /// CreationDate field public int CreationDate; /// SaleType field public byte SaleType; /// CallbackID field public uint CallbackID; /// BaseMask field public uint BaseMask; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// InvType field public sbyte InvType; /// Type field public sbyte Type; /// AssetID field public LLUUID AssetID; /// GroupID field public LLUUID GroupID; /// SalePrice field public int SalePrice; /// OwnerID field public LLUUID OwnerID; /// CreatorID field public LLUUID CreatorID; /// ItemID field public LLUUID ItemID; /// FolderID field public LLUUID FolderID; /// EveryoneMask field public uint EveryoneMask; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// Flags field public uint Flags; /// NextOwnerMask field public uint NextOwnerMask; /// GroupMask field public uint GroupMask; /// OwnerMask field public uint OwnerMask; /// Length of this block serialized in bytes public int Length { get { int length = 140; if (Name != null) { length += 1 + Name.Length; } if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public ItemDataBlock() { } /// Constructor for building the block from a byte array public ItemDataBlock(byte[] bytes, ref int i) { int length; try { GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; CRC = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CreationDate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SaleType = (byte)bytes[i++]; CallbackID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); BaseMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; InvType = (sbyte)bytes[i++]; Type = (sbyte)bytes[i++]; AssetID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerID = new LLUUID(bytes, i); i += 16; CreatorID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; FolderID = new LLUUID(bytes, i); i += 16; EveryoneMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); NextOwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((GroupOwned) ? 1 : 0); bytes[i++] = (byte)(CRC % 256); bytes[i++] = (byte)((CRC >> 8) % 256); bytes[i++] = (byte)((CRC >> 16) % 256); bytes[i++] = (byte)((CRC >> 24) % 256); bytes[i++] = (byte)(CreationDate % 256); bytes[i++] = (byte)((CreationDate >> 8) % 256); bytes[i++] = (byte)((CreationDate >> 16) % 256); bytes[i++] = (byte)((CreationDate >> 24) % 256); bytes[i++] = SaleType; bytes[i++] = (byte)(CallbackID % 256); bytes[i++] = (byte)((CallbackID >> 8) % 256); bytes[i++] = (byte)((CallbackID >> 16) % 256); bytes[i++] = (byte)((CallbackID >> 24) % 256); bytes[i++] = (byte)(BaseMask % 256); bytes[i++] = (byte)((BaseMask >> 8) % 256); bytes[i++] = (byte)((BaseMask >> 16) % 256); bytes[i++] = (byte)((BaseMask >> 24) % 256); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)InvType; bytes[i++] = (byte)Type; if(AssetID == null) { Console.WriteLine("Warning: AssetID is null, in " + this.GetType()); } Array.Copy(AssetID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(SalePrice % 256); bytes[i++] = (byte)((SalePrice >> 8) % 256); bytes[i++] = (byte)((SalePrice >> 16) % 256); bytes[i++] = (byte)((SalePrice >> 24) % 256); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(CreatorID == null) { Console.WriteLine("Warning: CreatorID is null, in " + this.GetType()); } Array.Copy(CreatorID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(EveryoneMask % 256); bytes[i++] = (byte)((EveryoneMask >> 8) % 256); bytes[i++] = (byte)((EveryoneMask >> 16) % 256); bytes[i++] = (byte)((EveryoneMask >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); bytes[i++] = (byte)(NextOwnerMask % 256); bytes[i++] = (byte)((NextOwnerMask >> 8) % 256); bytes[i++] = (byte)((NextOwnerMask >> 16) % 256); bytes[i++] = (byte)((NextOwnerMask >> 24) % 256); bytes[i++] = (byte)(GroupMask % 256); bytes[i++] = (byte)((GroupMask >> 8) % 256); bytes[i++] = (byte)((GroupMask >> 16) % 256); bytes[i++] = (byte)((GroupMask >> 24) % 256); bytes[i++] = (byte)(OwnerMask % 256); bytes[i++] = (byte)((OwnerMask >> 8) % 256); bytes[i++] = (byte)((OwnerMask >> 16) % 256); bytes[i++] = (byte)((OwnerMask >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ItemData --\n"; output += "GroupOwned: " + GroupOwned.ToString() + "\n"; output += "CRC: " + CRC.ToString() + "\n"; output += "CreationDate: " + CreationDate.ToString() + "\n"; output += "SaleType: " + SaleType.ToString() + "\n"; output += "CallbackID: " + CallbackID.ToString() + "\n"; output += "BaseMask: " + BaseMask.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "InvType: " + InvType.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "AssetID: " + AssetID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "SalePrice: " + SalePrice.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "CreatorID: " + CreatorID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output += "EveryoneMask: " + EveryoneMask.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "NextOwnerMask: " + NextOwnerMask.ToString() + "\n"; output += "GroupMask: " + GroupMask.ToString() + "\n"; output += "OwnerMask: " + OwnerMask.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } /// FolderData block public class FolderDataBlock { private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// ParentID field public LLUUID ParentID; /// Type field public sbyte Type; /// FolderID field public LLUUID FolderID; /// Length of this block serialized in bytes public int Length { get { int length = 33; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public FolderDataBlock() { } /// Constructor for building the block from a byte array public FolderDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; ParentID = new LLUUID(bytes, i); i += 16; Type = (sbyte)bytes[i++]; FolderID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(ParentID == null) { Console.WriteLine("Warning: ParentID is null, in " + this.GetType()); } Array.Copy(ParentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)Type; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- FolderData --\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "ParentID: " + ParentID.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.BulkUpdateInventory public override PacketType Type { get { return PacketType.BulkUpdateInventory; } } /// ItemData block public ItemDataBlock[] ItemData; /// AgentData block public AgentDataBlock AgentData; /// FolderData block public FolderDataBlock[] FolderData; /// Default constructor public BulkUpdateInventoryPacket() { Header = new LowHeader(); Header.ID = 333; Header.Reliable = true; Header.Zerocoded = true; ItemData = new ItemDataBlock[0]; AgentData = new AgentDataBlock(); FolderData = new FolderDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public BulkUpdateInventoryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ItemData = new ItemDataBlock[count]; for (int j = 0; j < count; j++) { ItemData[j] = new ItemDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); count = (int)bytes[i++]; FolderData = new FolderDataBlock[count]; for (int j = 0; j < count; j++) { FolderData[j] = new FolderDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public BulkUpdateInventoryPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ItemData = new ItemDataBlock[count]; for (int j = 0; j < count; j++) { ItemData[j] = new ItemDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); count = (int)bytes[i++]; FolderData = new FolderDataBlock[count]; for (int j = 0; j < count; j++) { FolderData[j] = new FolderDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ItemData.Length; j++) { length += ItemData[j].Length; } length++; for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ItemData.Length; for (int j = 0; j < ItemData.Length; j++) { ItemData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); bytes[i++] = (byte)FolderData.Length; for (int j = 0; j < FolderData.Length; j++) { FolderData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- BulkUpdateInventory ---\n"; for (int j = 0; j < ItemData.Length; j++) { output += ItemData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; for (int j = 0; j < FolderData.Length; j++) { output += FolderData[j].ToString() + "\n"; } return output; } } /// RequestInventoryAsset packet public class RequestInventoryAssetPacket : Packet { /// QueryData block public class QueryDataBlock { /// AgentID field public LLUUID AgentID; /// QueryID field public LLUUID QueryID; /// OwnerID field public LLUUID OwnerID; /// ItemID field public LLUUID ItemID; /// Length of this block serialized in bytes public int Length { get { return 64; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; QueryID = new LLUUID(bytes, i); i += 16; OwnerID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RequestInventoryAsset public override PacketType Type { get { return PacketType.RequestInventoryAsset; } } /// QueryData block public QueryDataBlock QueryData; /// Default constructor public RequestInventoryAssetPacket() { Header = new LowHeader(); Header.ID = 334; Header.Reliable = true; QueryData = new QueryDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RequestInventoryAssetPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); QueryData = new QueryDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RequestInventoryAssetPacket(Header head, byte[] bytes, ref int i) { Header = head; QueryData = new QueryDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RequestInventoryAsset ---\n"; output += QueryData.ToString() + "\n"; return output; } } /// InventoryAssetResponse packet public class InventoryAssetResponsePacket : Packet { /// QueryData block public class QueryDataBlock { /// QueryID field public LLUUID QueryID; /// AssetID field public LLUUID AssetID; /// IsReadable field public bool IsReadable; /// Length of this block serialized in bytes public int Length { get { return 33; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { try { QueryID = new LLUUID(bytes, i); i += 16; AssetID = new LLUUID(bytes, i); i += 16; IsReadable = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; if(AssetID == null) { Console.WriteLine("Warning: AssetID is null, in " + this.GetType()); } Array.Copy(AssetID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((IsReadable) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output += "AssetID: " + AssetID.ToString() + "\n"; output += "IsReadable: " + IsReadable.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.InventoryAssetResponse public override PacketType Type { get { return PacketType.InventoryAssetResponse; } } /// QueryData block public QueryDataBlock QueryData; /// Default constructor public InventoryAssetResponsePacket() { Header = new LowHeader(); Header.ID = 335; Header.Reliable = true; QueryData = new QueryDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public InventoryAssetResponsePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); QueryData = new QueryDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public InventoryAssetResponsePacket(Header head, byte[] bytes, ref int i) { Header = head; QueryData = new QueryDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += QueryData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- InventoryAssetResponse ---\n"; output += QueryData.ToString() + "\n"; return output; } } /// RemoveInventoryObjects packet public class RemoveInventoryObjectsPacket : Packet { /// ItemData block public class ItemDataBlock { /// ItemID field public LLUUID ItemID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ItemDataBlock() { } /// Constructor for building the block from a byte array public ItemDataBlock(byte[] bytes, ref int i) { try { ItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ItemData --\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// FolderData block public class FolderDataBlock { /// FolderID field public LLUUID FolderID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public FolderDataBlock() { } /// Constructor for building the block from a byte array public FolderDataBlock(byte[] bytes, ref int i) { try { FolderID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- FolderData --\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RemoveInventoryObjects public override PacketType Type { get { return PacketType.RemoveInventoryObjects; } } /// ItemData block public ItemDataBlock[] ItemData; /// AgentData block public AgentDataBlock AgentData; /// FolderData block public FolderDataBlock[] FolderData; /// Default constructor public RemoveInventoryObjectsPacket() { Header = new LowHeader(); Header.ID = 336; Header.Reliable = true; ItemData = new ItemDataBlock[0]; AgentData = new AgentDataBlock(); FolderData = new FolderDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RemoveInventoryObjectsPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ItemData = new ItemDataBlock[count]; for (int j = 0; j < count; j++) { ItemData[j] = new ItemDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); count = (int)bytes[i++]; FolderData = new FolderDataBlock[count]; for (int j = 0; j < count; j++) { FolderData[j] = new FolderDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public RemoveInventoryObjectsPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ItemData = new ItemDataBlock[count]; for (int j = 0; j < count; j++) { ItemData[j] = new ItemDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); count = (int)bytes[i++]; FolderData = new FolderDataBlock[count]; for (int j = 0; j < count; j++) { FolderData[j] = new FolderDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ItemData.Length; j++) { length += ItemData[j].Length; } length++; for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ItemData.Length; for (int j = 0; j < ItemData.Length; j++) { ItemData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); bytes[i++] = (byte)FolderData.Length; for (int j = 0; j < FolderData.Length; j++) { FolderData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RemoveInventoryObjects ---\n"; for (int j = 0; j < ItemData.Length; j++) { output += ItemData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; for (int j = 0; j < FolderData.Length; j++) { output += FolderData[j].ToString() + "\n"; } return output; } } /// PurgeInventoryDescendents packet public class PurgeInventoryDescendentsPacket : Packet { /// InventoryData block public class InventoryDataBlock { /// FolderID field public LLUUID FolderID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { try { FolderID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.PurgeInventoryDescendents public override PacketType Type { get { return PacketType.PurgeInventoryDescendents; } } /// InventoryData block public InventoryDataBlock InventoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public PurgeInventoryDescendentsPacket() { Header = new LowHeader(); Header.ID = 337; Header.Reliable = true; Header.Zerocoded = true; InventoryData = new InventoryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public PurgeInventoryDescendentsPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); InventoryData = new InventoryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public PurgeInventoryDescendentsPacket(Header head, byte[] bytes, ref int i) { Header = head; InventoryData = new InventoryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += InventoryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); InventoryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- PurgeInventoryDescendents ---\n"; output += InventoryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// UpdateTaskInventory packet public class UpdateTaskInventoryPacket : Packet { /// InventoryData block public class InventoryDataBlock { /// GroupOwned field public bool GroupOwned; /// CRC field public uint CRC; /// CreationDate field public int CreationDate; /// SaleType field public byte SaleType; /// BaseMask field public uint BaseMask; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// InvType field public sbyte InvType; /// Type field public sbyte Type; /// GroupID field public LLUUID GroupID; /// SalePrice field public int SalePrice; /// OwnerID field public LLUUID OwnerID; /// CreatorID field public LLUUID CreatorID; /// ItemID field public LLUUID ItemID; /// FolderID field public LLUUID FolderID; /// EveryoneMask field public uint EveryoneMask; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// Flags field public uint Flags; /// NextOwnerMask field public uint NextOwnerMask; /// TransactionID field public LLUUID TransactionID; /// GroupMask field public uint GroupMask; /// OwnerMask field public uint OwnerMask; /// Length of this block serialized in bytes public int Length { get { int length = 136; if (Name != null) { length += 1 + Name.Length; } if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { int length; try { GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; CRC = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CreationDate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SaleType = (byte)bytes[i++]; BaseMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; InvType = (sbyte)bytes[i++]; Type = (sbyte)bytes[i++]; GroupID = new LLUUID(bytes, i); i += 16; SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerID = new LLUUID(bytes, i); i += 16; CreatorID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; FolderID = new LLUUID(bytes, i); i += 16; EveryoneMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); NextOwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TransactionID = new LLUUID(bytes, i); i += 16; GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((GroupOwned) ? 1 : 0); bytes[i++] = (byte)(CRC % 256); bytes[i++] = (byte)((CRC >> 8) % 256); bytes[i++] = (byte)((CRC >> 16) % 256); bytes[i++] = (byte)((CRC >> 24) % 256); bytes[i++] = (byte)(CreationDate % 256); bytes[i++] = (byte)((CreationDate >> 8) % 256); bytes[i++] = (byte)((CreationDate >> 16) % 256); bytes[i++] = (byte)((CreationDate >> 24) % 256); bytes[i++] = SaleType; bytes[i++] = (byte)(BaseMask % 256); bytes[i++] = (byte)((BaseMask >> 8) % 256); bytes[i++] = (byte)((BaseMask >> 16) % 256); bytes[i++] = (byte)((BaseMask >> 24) % 256); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)InvType; bytes[i++] = (byte)Type; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(SalePrice % 256); bytes[i++] = (byte)((SalePrice >> 8) % 256); bytes[i++] = (byte)((SalePrice >> 16) % 256); bytes[i++] = (byte)((SalePrice >> 24) % 256); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(CreatorID == null) { Console.WriteLine("Warning: CreatorID is null, in " + this.GetType()); } Array.Copy(CreatorID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(EveryoneMask % 256); bytes[i++] = (byte)((EveryoneMask >> 8) % 256); bytes[i++] = (byte)((EveryoneMask >> 16) % 256); bytes[i++] = (byte)((EveryoneMask >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); bytes[i++] = (byte)(NextOwnerMask % 256); bytes[i++] = (byte)((NextOwnerMask >> 8) % 256); bytes[i++] = (byte)((NextOwnerMask >> 16) % 256); bytes[i++] = (byte)((NextOwnerMask >> 24) % 256); if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(GroupMask % 256); bytes[i++] = (byte)((GroupMask >> 8) % 256); bytes[i++] = (byte)((GroupMask >> 16) % 256); bytes[i++] = (byte)((GroupMask >> 24) % 256); bytes[i++] = (byte)(OwnerMask % 256); bytes[i++] = (byte)((OwnerMask >> 8) % 256); bytes[i++] = (byte)((OwnerMask >> 16) % 256); bytes[i++] = (byte)((OwnerMask >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "GroupOwned: " + GroupOwned.ToString() + "\n"; output += "CRC: " + CRC.ToString() + "\n"; output += "CreationDate: " + CreationDate.ToString() + "\n"; output += "SaleType: " + SaleType.ToString() + "\n"; output += "BaseMask: " + BaseMask.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "InvType: " + InvType.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "SalePrice: " + SalePrice.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "CreatorID: " + CreatorID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output += "EveryoneMask: " + EveryoneMask.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "NextOwnerMask: " + NextOwnerMask.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output += "GroupMask: " + GroupMask.ToString() + "\n"; output += "OwnerMask: " + OwnerMask.ToString() + "\n"; output = output.Trim(); return output; } } /// UpdateData block public class UpdateDataBlock { /// Key field public byte Key; /// LocalID field public uint LocalID; /// Length of this block serialized in bytes public int Length { get { return 5; } } /// Default constructor public UpdateDataBlock() { } /// Constructor for building the block from a byte array public UpdateDataBlock(byte[] bytes, ref int i) { try { Key = (byte)bytes[i++]; LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = Key; bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- UpdateData --\n"; output += "Key: " + Key.ToString() + "\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UpdateTaskInventory public override PacketType Type { get { return PacketType.UpdateTaskInventory; } } /// InventoryData block public InventoryDataBlock InventoryData; /// UpdateData block public UpdateDataBlock UpdateData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public UpdateTaskInventoryPacket() { Header = new LowHeader(); Header.ID = 338; Header.Reliable = true; Header.Zerocoded = true; InventoryData = new InventoryDataBlock(); UpdateData = new UpdateDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UpdateTaskInventoryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); InventoryData = new InventoryDataBlock(bytes, ref i); UpdateData = new UpdateDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public UpdateTaskInventoryPacket(Header head, byte[] bytes, ref int i) { Header = head; InventoryData = new InventoryDataBlock(bytes, ref i); UpdateData = new UpdateDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += InventoryData.Length; length += UpdateData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); InventoryData.ToBytes(bytes, ref i); UpdateData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UpdateTaskInventory ---\n"; output += InventoryData.ToString() + "\n"; output += UpdateData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// RemoveTaskInventory packet public class RemoveTaskInventoryPacket : Packet { /// InventoryData block public class InventoryDataBlock { /// LocalID field public uint LocalID; /// ItemID field public LLUUID ItemID; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { try { LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RemoveTaskInventory public override PacketType Type { get { return PacketType.RemoveTaskInventory; } } /// InventoryData block public InventoryDataBlock InventoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RemoveTaskInventoryPacket() { Header = new LowHeader(); Header.ID = 339; Header.Reliable = true; Header.Zerocoded = true; InventoryData = new InventoryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RemoveTaskInventoryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); InventoryData = new InventoryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RemoveTaskInventoryPacket(Header head, byte[] bytes, ref int i) { Header = head; InventoryData = new InventoryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += InventoryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); InventoryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RemoveTaskInventory ---\n"; output += InventoryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// MoveTaskInventory packet public class MoveTaskInventoryPacket : Packet { /// InventoryData block public class InventoryDataBlock { /// LocalID field public uint LocalID; /// ItemID field public LLUUID ItemID; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { try { LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// FolderID field public LLUUID FolderID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; FolderID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MoveTaskInventory public override PacketType Type { get { return PacketType.MoveTaskInventory; } } /// InventoryData block public InventoryDataBlock InventoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public MoveTaskInventoryPacket() { Header = new LowHeader(); Header.ID = 340; Header.Reliable = true; InventoryData = new InventoryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MoveTaskInventoryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); InventoryData = new InventoryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MoveTaskInventoryPacket(Header head, byte[] bytes, ref int i) { Header = head; InventoryData = new InventoryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += InventoryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); InventoryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MoveTaskInventory ---\n"; output += InventoryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// RequestTaskInventory packet public class RequestTaskInventoryPacket : Packet { /// InventoryData block public class InventoryDataBlock { /// LocalID field public uint LocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { try { LocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RequestTaskInventory public override PacketType Type { get { return PacketType.RequestTaskInventory; } } /// InventoryData block public InventoryDataBlock InventoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RequestTaskInventoryPacket() { Header = new LowHeader(); Header.ID = 341; Header.Reliable = true; InventoryData = new InventoryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RequestTaskInventoryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); InventoryData = new InventoryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RequestTaskInventoryPacket(Header head, byte[] bytes, ref int i) { Header = head; InventoryData = new InventoryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += InventoryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); InventoryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RequestTaskInventory ---\n"; output += InventoryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ReplyTaskInventory packet public class ReplyTaskInventoryPacket : Packet { /// InventoryData block public class InventoryDataBlock { /// TaskID field public LLUUID TaskID; private byte[] _filename; /// Filename field public byte[] Filename { get { return _filename; } set { if (value == null) { _filename = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _filename = new byte[value.Length]; Array.Copy(value, _filename, value.Length); } } } /// Serial field public short Serial; /// Length of this block serialized in bytes public int Length { get { int length = 18; if (Filename != null) { length += 1 + Filename.Length; } return length; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { int length; try { TaskID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _filename = new byte[length]; Array.Copy(bytes, i, _filename, 0, length); i += length; Serial = (short)(bytes[i++] + (bytes[i++] << 8)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TaskID == null) { Console.WriteLine("Warning: TaskID is null, in " + this.GetType()); } Array.Copy(TaskID.GetBytes(), 0, bytes, i, 16); i += 16; if(Filename == null) { Console.WriteLine("Warning: Filename is null, in " + this.GetType()); } bytes[i++] = (byte)Filename.Length; Array.Copy(Filename, 0, bytes, i, Filename.Length); i += Filename.Length; bytes[i++] = (byte)(Serial % 256); bytes[i++] = (byte)((Serial >> 8) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "TaskID: " + TaskID.ToString() + "\n"; output += Helpers.FieldToString(Filename, "Filename") + "\n"; output += "Serial: " + Serial.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ReplyTaskInventory public override PacketType Type { get { return PacketType.ReplyTaskInventory; } } /// InventoryData block public InventoryDataBlock InventoryData; /// Default constructor public ReplyTaskInventoryPacket() { Header = new LowHeader(); Header.ID = 342; Header.Reliable = true; Header.Zerocoded = true; InventoryData = new InventoryDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ReplyTaskInventoryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); InventoryData = new InventoryDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ReplyTaskInventoryPacket(Header head, byte[] bytes, ref int i) { Header = head; InventoryData = new InventoryDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += InventoryData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); InventoryData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ReplyTaskInventory ---\n"; output += InventoryData.ToString() + "\n"; return output; } } /// DeRezObject packet public class DeRezObjectPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectLocalID field public uint ObjectLocalID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentBlock block public class AgentBlockBlock { /// GroupID field public LLUUID GroupID; /// Destination field public byte Destination; /// PacketNumber field public byte PacketNumber; /// PacketCount field public byte PacketCount; /// TransactionID field public LLUUID TransactionID; /// DestinationID field public LLUUID DestinationID; /// Length of this block serialized in bytes public int Length { get { return 51; } } /// Default constructor public AgentBlockBlock() { } /// Constructor for building the block from a byte array public AgentBlockBlock(byte[] bytes, ref int i) { try { GroupID = new LLUUID(bytes, i); i += 16; Destination = (byte)bytes[i++]; PacketNumber = (byte)bytes[i++]; PacketCount = (byte)bytes[i++]; TransactionID = new LLUUID(bytes, i); i += 16; DestinationID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = Destination; bytes[i++] = PacketNumber; bytes[i++] = PacketCount; if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; if(DestinationID == null) { Console.WriteLine("Warning: DestinationID is null, in " + this.GetType()); } Array.Copy(DestinationID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentBlock --\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "Destination: " + Destination.ToString() + "\n"; output += "PacketNumber: " + PacketNumber.ToString() + "\n"; output += "PacketCount: " + PacketCount.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output += "DestinationID: " + DestinationID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DeRezObject public override PacketType Type { get { return PacketType.DeRezObject; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentBlock block public AgentBlockBlock AgentBlock; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DeRezObjectPacket() { Header = new LowHeader(); Header.ID = 343; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentBlock = new AgentBlockBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DeRezObjectPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentBlock = new AgentBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DeRezObjectPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentBlock = new AgentBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentBlock.Length; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentBlock.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DeRezObject ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentBlock.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DeRezAck packet public class DeRezAckPacket : Packet { private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DeRezAck public override PacketType Type { get { return PacketType.DeRezAck; } } /// Default constructor public DeRezAckPacket() { Header = new LowHeader(); Header.ID = 344; Header.Reliable = true; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DeRezAckPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); } /// Constructor that takes a byte array and a prebuilt header public DeRezAckPacket(Header head, byte[] bytes, ref int i) { Header = head; } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DeRezAck ---\n"; return output; } } /// RezObject packet public class RezObjectPacket : Packet { /// InventoryData block public class InventoryDataBlock { /// GroupOwned field public bool GroupOwned; /// CRC field public uint CRC; /// CreationDate field public int CreationDate; /// SaleType field public byte SaleType; /// BaseMask field public uint BaseMask; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// InvType field public sbyte InvType; /// Type field public sbyte Type; /// GroupID field public LLUUID GroupID; /// SalePrice field public int SalePrice; /// OwnerID field public LLUUID OwnerID; /// CreatorID field public LLUUID CreatorID; /// ItemID field public LLUUID ItemID; /// FolderID field public LLUUID FolderID; /// EveryoneMask field public uint EveryoneMask; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// Flags field public uint Flags; /// NextOwnerMask field public uint NextOwnerMask; /// TransactionID field public LLUUID TransactionID; /// GroupMask field public uint GroupMask; /// OwnerMask field public uint OwnerMask; /// Length of this block serialized in bytes public int Length { get { int length = 136; if (Name != null) { length += 1 + Name.Length; } if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { int length; try { GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; CRC = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CreationDate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SaleType = (byte)bytes[i++]; BaseMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; InvType = (sbyte)bytes[i++]; Type = (sbyte)bytes[i++]; GroupID = new LLUUID(bytes, i); i += 16; SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerID = new LLUUID(bytes, i); i += 16; CreatorID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; FolderID = new LLUUID(bytes, i); i += 16; EveryoneMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); NextOwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TransactionID = new LLUUID(bytes, i); i += 16; GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((GroupOwned) ? 1 : 0); bytes[i++] = (byte)(CRC % 256); bytes[i++] = (byte)((CRC >> 8) % 256); bytes[i++] = (byte)((CRC >> 16) % 256); bytes[i++] = (byte)((CRC >> 24) % 256); bytes[i++] = (byte)(CreationDate % 256); bytes[i++] = (byte)((CreationDate >> 8) % 256); bytes[i++] = (byte)((CreationDate >> 16) % 256); bytes[i++] = (byte)((CreationDate >> 24) % 256); bytes[i++] = SaleType; bytes[i++] = (byte)(BaseMask % 256); bytes[i++] = (byte)((BaseMask >> 8) % 256); bytes[i++] = (byte)((BaseMask >> 16) % 256); bytes[i++] = (byte)((BaseMask >> 24) % 256); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)InvType; bytes[i++] = (byte)Type; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(SalePrice % 256); bytes[i++] = (byte)((SalePrice >> 8) % 256); bytes[i++] = (byte)((SalePrice >> 16) % 256); bytes[i++] = (byte)((SalePrice >> 24) % 256); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(CreatorID == null) { Console.WriteLine("Warning: CreatorID is null, in " + this.GetType()); } Array.Copy(CreatorID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(EveryoneMask % 256); bytes[i++] = (byte)((EveryoneMask >> 8) % 256); bytes[i++] = (byte)((EveryoneMask >> 16) % 256); bytes[i++] = (byte)((EveryoneMask >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); bytes[i++] = (byte)(NextOwnerMask % 256); bytes[i++] = (byte)((NextOwnerMask >> 8) % 256); bytes[i++] = (byte)((NextOwnerMask >> 16) % 256); bytes[i++] = (byte)((NextOwnerMask >> 24) % 256); if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(GroupMask % 256); bytes[i++] = (byte)((GroupMask >> 8) % 256); bytes[i++] = (byte)((GroupMask >> 16) % 256); bytes[i++] = (byte)((GroupMask >> 24) % 256); bytes[i++] = (byte)(OwnerMask % 256); bytes[i++] = (byte)((OwnerMask >> 8) % 256); bytes[i++] = (byte)((OwnerMask >> 16) % 256); bytes[i++] = (byte)((OwnerMask >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "GroupOwned: " + GroupOwned.ToString() + "\n"; output += "CRC: " + CRC.ToString() + "\n"; output += "CreationDate: " + CreationDate.ToString() + "\n"; output += "SaleType: " + SaleType.ToString() + "\n"; output += "BaseMask: " + BaseMask.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "InvType: " + InvType.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "SalePrice: " + SalePrice.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "CreatorID: " + CreatorID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output += "EveryoneMask: " + EveryoneMask.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "NextOwnerMask: " + NextOwnerMask.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output += "GroupMask: " + GroupMask.ToString() + "\n"; output += "OwnerMask: " + OwnerMask.ToString() + "\n"; output = output.Trim(); return output; } } /// RezData block public class RezDataBlock { /// RezSelected field public bool RezSelected; /// RemoveItem field public bool RemoveItem; /// RayStart field public LLVector3 RayStart; /// ItemFlags field public uint ItemFlags; /// FromTaskID field public LLUUID FromTaskID; /// RayEndIsIntersection field public bool RayEndIsIntersection; /// RayEnd field public LLVector3 RayEnd; /// BypassRaycast field public byte BypassRaycast; /// EveryoneMask field public uint EveryoneMask; /// NextOwnerMask field public uint NextOwnerMask; /// GroupMask field public uint GroupMask; /// RayTargetID field public LLUUID RayTargetID; /// Length of this block serialized in bytes public int Length { get { return 76; } } /// Default constructor public RezDataBlock() { } /// Constructor for building the block from a byte array public RezDataBlock(byte[] bytes, ref int i) { try { RezSelected = (bytes[i++] != 0) ? (bool)true : (bool)false; RemoveItem = (bytes[i++] != 0) ? (bool)true : (bool)false; RayStart = new LLVector3(bytes, i); i += 12; ItemFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); FromTaskID = new LLUUID(bytes, i); i += 16; RayEndIsIntersection = (bytes[i++] != 0) ? (bool)true : (bool)false; RayEnd = new LLVector3(bytes, i); i += 12; BypassRaycast = (byte)bytes[i++]; EveryoneMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); NextOwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RayTargetID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((RezSelected) ? 1 : 0); bytes[i++] = (byte)((RemoveItem) ? 1 : 0); if(RayStart == null) { Console.WriteLine("Warning: RayStart is null, in " + this.GetType()); } Array.Copy(RayStart.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = (byte)(ItemFlags % 256); bytes[i++] = (byte)((ItemFlags >> 8) % 256); bytes[i++] = (byte)((ItemFlags >> 16) % 256); bytes[i++] = (byte)((ItemFlags >> 24) % 256); if(FromTaskID == null) { Console.WriteLine("Warning: FromTaskID is null, in " + this.GetType()); } Array.Copy(FromTaskID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((RayEndIsIntersection) ? 1 : 0); if(RayEnd == null) { Console.WriteLine("Warning: RayEnd is null, in " + this.GetType()); } Array.Copy(RayEnd.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = BypassRaycast; bytes[i++] = (byte)(EveryoneMask % 256); bytes[i++] = (byte)((EveryoneMask >> 8) % 256); bytes[i++] = (byte)((EveryoneMask >> 16) % 256); bytes[i++] = (byte)((EveryoneMask >> 24) % 256); bytes[i++] = (byte)(NextOwnerMask % 256); bytes[i++] = (byte)((NextOwnerMask >> 8) % 256); bytes[i++] = (byte)((NextOwnerMask >> 16) % 256); bytes[i++] = (byte)((NextOwnerMask >> 24) % 256); bytes[i++] = (byte)(GroupMask % 256); bytes[i++] = (byte)((GroupMask >> 8) % 256); bytes[i++] = (byte)((GroupMask >> 16) % 256); bytes[i++] = (byte)((GroupMask >> 24) % 256); if(RayTargetID == null) { Console.WriteLine("Warning: RayTargetID is null, in " + this.GetType()); } Array.Copy(RayTargetID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RezData --\n"; output += "RezSelected: " + RezSelected.ToString() + "\n"; output += "RemoveItem: " + RemoveItem.ToString() + "\n"; output += "RayStart: " + RayStart.ToString() + "\n"; output += "ItemFlags: " + ItemFlags.ToString() + "\n"; output += "FromTaskID: " + FromTaskID.ToString() + "\n"; output += "RayEndIsIntersection: " + RayEndIsIntersection.ToString() + "\n"; output += "RayEnd: " + RayEnd.ToString() + "\n"; output += "BypassRaycast: " + BypassRaycast.ToString() + "\n"; output += "EveryoneMask: " + EveryoneMask.ToString() + "\n"; output += "NextOwnerMask: " + NextOwnerMask.ToString() + "\n"; output += "GroupMask: " + GroupMask.ToString() + "\n"; output += "RayTargetID: " + RayTargetID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RezObject public override PacketType Type { get { return PacketType.RezObject; } } /// InventoryData block public InventoryDataBlock InventoryData; /// RezData block public RezDataBlock RezData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RezObjectPacket() { Header = new LowHeader(); Header.ID = 345; Header.Reliable = true; Header.Zerocoded = true; InventoryData = new InventoryDataBlock(); RezData = new RezDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RezObjectPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); InventoryData = new InventoryDataBlock(bytes, ref i); RezData = new RezDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RezObjectPacket(Header head, byte[] bytes, ref int i) { Header = head; InventoryData = new InventoryDataBlock(bytes, ref i); RezData = new RezDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += InventoryData.Length; length += RezData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); InventoryData.ToBytes(bytes, ref i); RezData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RezObject ---\n"; output += InventoryData.ToString() + "\n"; output += RezData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// RezObjectFromNotecard packet public class RezObjectFromNotecardPacket : Packet { /// InventoryData block public class InventoryDataBlock { /// ItemID field public LLUUID ItemID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { try { ItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output = output.Trim(); return output; } } /// RezData block public class RezDataBlock { /// RezSelected field public bool RezSelected; /// RemoveItem field public bool RemoveItem; /// RayStart field public LLVector3 RayStart; /// ItemFlags field public uint ItemFlags; /// FromTaskID field public LLUUID FromTaskID; /// RayEndIsIntersection field public bool RayEndIsIntersection; /// RayEnd field public LLVector3 RayEnd; /// BypassRaycast field public byte BypassRaycast; /// EveryoneMask field public uint EveryoneMask; /// NextOwnerMask field public uint NextOwnerMask; /// GroupMask field public uint GroupMask; /// RayTargetID field public LLUUID RayTargetID; /// Length of this block serialized in bytes public int Length { get { return 76; } } /// Default constructor public RezDataBlock() { } /// Constructor for building the block from a byte array public RezDataBlock(byte[] bytes, ref int i) { try { RezSelected = (bytes[i++] != 0) ? (bool)true : (bool)false; RemoveItem = (bytes[i++] != 0) ? (bool)true : (bool)false; RayStart = new LLVector3(bytes, i); i += 12; ItemFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); FromTaskID = new LLUUID(bytes, i); i += 16; RayEndIsIntersection = (bytes[i++] != 0) ? (bool)true : (bool)false; RayEnd = new LLVector3(bytes, i); i += 12; BypassRaycast = (byte)bytes[i++]; EveryoneMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); NextOwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RayTargetID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((RezSelected) ? 1 : 0); bytes[i++] = (byte)((RemoveItem) ? 1 : 0); if(RayStart == null) { Console.WriteLine("Warning: RayStart is null, in " + this.GetType()); } Array.Copy(RayStart.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = (byte)(ItemFlags % 256); bytes[i++] = (byte)((ItemFlags >> 8) % 256); bytes[i++] = (byte)((ItemFlags >> 16) % 256); bytes[i++] = (byte)((ItemFlags >> 24) % 256); if(FromTaskID == null) { Console.WriteLine("Warning: FromTaskID is null, in " + this.GetType()); } Array.Copy(FromTaskID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((RayEndIsIntersection) ? 1 : 0); if(RayEnd == null) { Console.WriteLine("Warning: RayEnd is null, in " + this.GetType()); } Array.Copy(RayEnd.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = BypassRaycast; bytes[i++] = (byte)(EveryoneMask % 256); bytes[i++] = (byte)((EveryoneMask >> 8) % 256); bytes[i++] = (byte)((EveryoneMask >> 16) % 256); bytes[i++] = (byte)((EveryoneMask >> 24) % 256); bytes[i++] = (byte)(NextOwnerMask % 256); bytes[i++] = (byte)((NextOwnerMask >> 8) % 256); bytes[i++] = (byte)((NextOwnerMask >> 16) % 256); bytes[i++] = (byte)((NextOwnerMask >> 24) % 256); bytes[i++] = (byte)(GroupMask % 256); bytes[i++] = (byte)((GroupMask >> 8) % 256); bytes[i++] = (byte)((GroupMask >> 16) % 256); bytes[i++] = (byte)((GroupMask >> 24) % 256); if(RayTargetID == null) { Console.WriteLine("Warning: RayTargetID is null, in " + this.GetType()); } Array.Copy(RayTargetID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RezData --\n"; output += "RezSelected: " + RezSelected.ToString() + "\n"; output += "RemoveItem: " + RemoveItem.ToString() + "\n"; output += "RayStart: " + RayStart.ToString() + "\n"; output += "ItemFlags: " + ItemFlags.ToString() + "\n"; output += "FromTaskID: " + FromTaskID.ToString() + "\n"; output += "RayEndIsIntersection: " + RayEndIsIntersection.ToString() + "\n"; output += "RayEnd: " + RayEnd.ToString() + "\n"; output += "BypassRaycast: " + BypassRaycast.ToString() + "\n"; output += "EveryoneMask: " + EveryoneMask.ToString() + "\n"; output += "NextOwnerMask: " + NextOwnerMask.ToString() + "\n"; output += "GroupMask: " + GroupMask.ToString() + "\n"; output += "RayTargetID: " + RayTargetID.ToString() + "\n"; output = output.Trim(); return output; } } /// NotecardData block public class NotecardDataBlock { /// ObjectID field public LLUUID ObjectID; /// NotecardItemID field public LLUUID NotecardItemID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public NotecardDataBlock() { } /// Constructor for building the block from a byte array public NotecardDataBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; NotecardItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; if(NotecardItemID == null) { Console.WriteLine("Warning: NotecardItemID is null, in " + this.GetType()); } Array.Copy(NotecardItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- NotecardData --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "NotecardItemID: " + NotecardItemID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RezObjectFromNotecard public override PacketType Type { get { return PacketType.RezObjectFromNotecard; } } /// InventoryData block public InventoryDataBlock[] InventoryData; /// RezData block public RezDataBlock RezData; /// NotecardData block public NotecardDataBlock NotecardData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RezObjectFromNotecardPacket() { Header = new LowHeader(); Header.ID = 346; Header.Reliable = true; Header.Zerocoded = true; InventoryData = new InventoryDataBlock[0]; RezData = new RezDataBlock(); NotecardData = new NotecardDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RezObjectFromNotecardPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } RezData = new RezDataBlock(bytes, ref i); NotecardData = new NotecardDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RezObjectFromNotecardPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; InventoryData = new InventoryDataBlock[count]; for (int j = 0; j < count; j++) { InventoryData[j] = new InventoryDataBlock(bytes, ref i); } RezData = new RezDataBlock(bytes, ref i); NotecardData = new NotecardDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += RezData.Length; length += NotecardData.Length; length += AgentData.Length;; length++; for (int j = 0; j < InventoryData.Length; j++) { length += InventoryData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)InventoryData.Length; for (int j = 0; j < InventoryData.Length; j++) { InventoryData[j].ToBytes(bytes, ref i); } RezData.ToBytes(bytes, ref i); NotecardData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RezObjectFromNotecard ---\n"; for (int j = 0; j < InventoryData.Length; j++) { output += InventoryData[j].ToString() + "\n"; } output += RezData.ToString() + "\n"; output += NotecardData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// DeclineInventory packet public class DeclineInventoryPacket : Packet { /// InfoBlock block public class InfoBlockBlock { /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public InfoBlockBlock() { } /// Constructor for building the block from a byte array public InfoBlockBlock(byte[] bytes, ref int i) { try { TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InfoBlock --\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DeclineInventory public override PacketType Type { get { return PacketType.DeclineInventory; } } /// InfoBlock block public InfoBlockBlock InfoBlock; /// Default constructor public DeclineInventoryPacket() { Header = new LowHeader(); Header.ID = 347; Header.Reliable = true; InfoBlock = new InfoBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DeclineInventoryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); InfoBlock = new InfoBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DeclineInventoryPacket(Header head, byte[] bytes, ref int i) { Header = head; InfoBlock = new InfoBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += InfoBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); InfoBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DeclineInventory ---\n"; output += InfoBlock.ToString() + "\n"; return output; } } /// TransferInventory packet public class TransferInventoryPacket : Packet { /// InfoBlock block public class InfoBlockBlock { /// DestID field public LLUUID DestID; /// SourceID field public LLUUID SourceID; /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public InfoBlockBlock() { } /// Constructor for building the block from a byte array public InfoBlockBlock(byte[] bytes, ref int i) { try { DestID = new LLUUID(bytes, i); i += 16; SourceID = new LLUUID(bytes, i); i += 16; TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(DestID == null) { Console.WriteLine("Warning: DestID is null, in " + this.GetType()); } Array.Copy(DestID.GetBytes(), 0, bytes, i, 16); i += 16; if(SourceID == null) { Console.WriteLine("Warning: SourceID is null, in " + this.GetType()); } Array.Copy(SourceID.GetBytes(), 0, bytes, i, 16); i += 16; if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InfoBlock --\n"; output += "DestID: " + DestID.ToString() + "\n"; output += "SourceID: " + SourceID.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } /// InventoryBlock block public class InventoryBlockBlock { /// Type field public sbyte Type; /// InventoryID field public LLUUID InventoryID; /// Length of this block serialized in bytes public int Length { get { return 17; } } /// Default constructor public InventoryBlockBlock() { } /// Constructor for building the block from a byte array public InventoryBlockBlock(byte[] bytes, ref int i) { try { Type = (sbyte)bytes[i++]; InventoryID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)Type; if(InventoryID == null) { Console.WriteLine("Warning: InventoryID is null, in " + this.GetType()); } Array.Copy(InventoryID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryBlock --\n"; output += "Type: " + Type.ToString() + "\n"; output += "InventoryID: " + InventoryID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TransferInventory public override PacketType Type { get { return PacketType.TransferInventory; } } /// InfoBlock block public InfoBlockBlock InfoBlock; /// InventoryBlock block public InventoryBlockBlock[] InventoryBlock; /// Default constructor public TransferInventoryPacket() { Header = new LowHeader(); Header.ID = 348; Header.Reliable = true; Header.Zerocoded = true; InfoBlock = new InfoBlockBlock(); InventoryBlock = new InventoryBlockBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TransferInventoryPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); InfoBlock = new InfoBlockBlock(bytes, ref i); int count = (int)bytes[i++]; InventoryBlock = new InventoryBlockBlock[count]; for (int j = 0; j < count; j++) { InventoryBlock[j] = new InventoryBlockBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public TransferInventoryPacket(Header head, byte[] bytes, ref int i) { Header = head; InfoBlock = new InfoBlockBlock(bytes, ref i); int count = (int)bytes[i++]; InventoryBlock = new InventoryBlockBlock[count]; for (int j = 0; j < count; j++) { InventoryBlock[j] = new InventoryBlockBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += InfoBlock.Length;; length++; for (int j = 0; j < InventoryBlock.Length; j++) { length += InventoryBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); InfoBlock.ToBytes(bytes, ref i); bytes[i++] = (byte)InventoryBlock.Length; for (int j = 0; j < InventoryBlock.Length; j++) { InventoryBlock[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TransferInventory ---\n"; output += InfoBlock.ToString() + "\n"; for (int j = 0; j < InventoryBlock.Length; j++) { output += InventoryBlock[j].ToString() + "\n"; } return output; } } /// TransferInventoryAck packet public class TransferInventoryAckPacket : Packet { /// InfoBlock block public class InfoBlockBlock { /// InventoryID field public LLUUID InventoryID; /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public InfoBlockBlock() { } /// Constructor for building the block from a byte array public InfoBlockBlock(byte[] bytes, ref int i) { try { InventoryID = new LLUUID(bytes, i); i += 16; TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(InventoryID == null) { Console.WriteLine("Warning: InventoryID is null, in " + this.GetType()); } Array.Copy(InventoryID.GetBytes(), 0, bytes, i, 16); i += 16; if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InfoBlock --\n"; output += "InventoryID: " + InventoryID.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TransferInventoryAck public override PacketType Type { get { return PacketType.TransferInventoryAck; } } /// InfoBlock block public InfoBlockBlock InfoBlock; /// Default constructor public TransferInventoryAckPacket() { Header = new LowHeader(); Header.ID = 349; Header.Reliable = true; Header.Zerocoded = true; InfoBlock = new InfoBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TransferInventoryAckPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); InfoBlock = new InfoBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TransferInventoryAckPacket(Header head, byte[] bytes, ref int i) { Header = head; InfoBlock = new InfoBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += InfoBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); InfoBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TransferInventoryAck ---\n"; output += InfoBlock.ToString() + "\n"; return output; } } /// RequestFriendship packet public class RequestFriendshipPacket : Packet { /// AgentBlock block public class AgentBlockBlock { /// DestID field public LLUUID DestID; /// FolderID field public LLUUID FolderID; /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentBlockBlock() { } /// Constructor for building the block from a byte array public AgentBlockBlock(byte[] bytes, ref int i) { try { DestID = new LLUUID(bytes, i); i += 16; FolderID = new LLUUID(bytes, i); i += 16; TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(DestID == null) { Console.WriteLine("Warning: DestID is null, in " + this.GetType()); } Array.Copy(DestID.GetBytes(), 0, bytes, i, 16); i += 16; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentBlock --\n"; output += "DestID: " + DestID.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RequestFriendship public override PacketType Type { get { return PacketType.RequestFriendship; } } /// AgentBlock block public AgentBlockBlock AgentBlock; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RequestFriendshipPacket() { Header = new LowHeader(); Header.ID = 350; Header.Reliable = true; AgentBlock = new AgentBlockBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RequestFriendshipPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentBlock = new AgentBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RequestFriendshipPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentBlock = new AgentBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentBlock.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentBlock.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RequestFriendship ---\n"; output += AgentBlock.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// AcceptFriendship packet public class AcceptFriendshipPacket : Packet { /// TransactionBlock block public class TransactionBlockBlock { /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public TransactionBlockBlock() { } /// Constructor for building the block from a byte array public TransactionBlockBlock(byte[] bytes, ref int i) { try { TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TransactionBlock --\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// FolderData block public class FolderDataBlock { /// FolderID field public LLUUID FolderID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public FolderDataBlock() { } /// Constructor for building the block from a byte array public FolderDataBlock(byte[] bytes, ref int i) { try { FolderID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- FolderData --\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AcceptFriendship public override PacketType Type { get { return PacketType.AcceptFriendship; } } /// TransactionBlock block public TransactionBlockBlock TransactionBlock; /// AgentData block public AgentDataBlock AgentData; /// FolderData block public FolderDataBlock[] FolderData; /// Default constructor public AcceptFriendshipPacket() { Header = new LowHeader(); Header.ID = 351; Header.Reliable = true; TransactionBlock = new TransactionBlockBlock(); AgentData = new AgentDataBlock(); FolderData = new FolderDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AcceptFriendshipPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TransactionBlock = new TransactionBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); int count = (int)bytes[i++]; FolderData = new FolderDataBlock[count]; for (int j = 0; j < count; j++) { FolderData[j] = new FolderDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public AcceptFriendshipPacket(Header head, byte[] bytes, ref int i) { Header = head; TransactionBlock = new TransactionBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); int count = (int)bytes[i++]; FolderData = new FolderDataBlock[count]; for (int j = 0; j < count; j++) { FolderData[j] = new FolderDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TransactionBlock.Length; length += AgentData.Length;; length++; for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TransactionBlock.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); bytes[i++] = (byte)FolderData.Length; for (int j = 0; j < FolderData.Length; j++) { FolderData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AcceptFriendship ---\n"; output += TransactionBlock.ToString() + "\n"; output += AgentData.ToString() + "\n"; for (int j = 0; j < FolderData.Length; j++) { output += FolderData[j].ToString() + "\n"; } return output; } } /// DeclineFriendship packet public class DeclineFriendshipPacket : Packet { /// TransactionBlock block public class TransactionBlockBlock { /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public TransactionBlockBlock() { } /// Constructor for building the block from a byte array public TransactionBlockBlock(byte[] bytes, ref int i) { try { TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TransactionBlock --\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DeclineFriendship public override PacketType Type { get { return PacketType.DeclineFriendship; } } /// TransactionBlock block public TransactionBlockBlock TransactionBlock; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DeclineFriendshipPacket() { Header = new LowHeader(); Header.ID = 352; Header.Reliable = true; TransactionBlock = new TransactionBlockBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DeclineFriendshipPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TransactionBlock = new TransactionBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DeclineFriendshipPacket(Header head, byte[] bytes, ref int i) { Header = head; TransactionBlock = new TransactionBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TransactionBlock.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TransactionBlock.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DeclineFriendship ---\n"; output += TransactionBlock.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// FormFriendship packet public class FormFriendshipPacket : Packet { /// AgentBlock block public class AgentBlockBlock { /// DestID field public LLUUID DestID; /// SourceID field public LLUUID SourceID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentBlockBlock() { } /// Constructor for building the block from a byte array public AgentBlockBlock(byte[] bytes, ref int i) { try { DestID = new LLUUID(bytes, i); i += 16; SourceID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(DestID == null) { Console.WriteLine("Warning: DestID is null, in " + this.GetType()); } Array.Copy(DestID.GetBytes(), 0, bytes, i, 16); i += 16; if(SourceID == null) { Console.WriteLine("Warning: SourceID is null, in " + this.GetType()); } Array.Copy(SourceID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentBlock --\n"; output += "DestID: " + DestID.ToString() + "\n"; output += "SourceID: " + SourceID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.FormFriendship public override PacketType Type { get { return PacketType.FormFriendship; } } /// AgentBlock block public AgentBlockBlock AgentBlock; /// Default constructor public FormFriendshipPacket() { Header = new LowHeader(); Header.ID = 353; Header.Reliable = true; AgentBlock = new AgentBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public FormFriendshipPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentBlock = new AgentBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public FormFriendshipPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentBlock = new AgentBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- FormFriendship ---\n"; output += AgentBlock.ToString() + "\n"; return output; } } /// TerminateFriendship packet public class TerminateFriendshipPacket : Packet { /// ExBlock block public class ExBlockBlock { /// OtherID field public LLUUID OtherID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ExBlockBlock() { } /// Constructor for building the block from a byte array public ExBlockBlock(byte[] bytes, ref int i) { try { OtherID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(OtherID == null) { Console.WriteLine("Warning: OtherID is null, in " + this.GetType()); } Array.Copy(OtherID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ExBlock --\n"; output += "OtherID: " + OtherID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TerminateFriendship public override PacketType Type { get { return PacketType.TerminateFriendship; } } /// ExBlock block public ExBlockBlock ExBlock; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public TerminateFriendshipPacket() { Header = new LowHeader(); Header.ID = 354; Header.Reliable = true; ExBlock = new ExBlockBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TerminateFriendshipPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ExBlock = new ExBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TerminateFriendshipPacket(Header head, byte[] bytes, ref int i) { Header = head; ExBlock = new ExBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ExBlock.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ExBlock.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TerminateFriendship ---\n"; output += ExBlock.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// OfferCallingCard packet public class OfferCallingCardPacket : Packet { /// AgentBlock block public class AgentBlockBlock { /// DestID field public LLUUID DestID; /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentBlockBlock() { } /// Constructor for building the block from a byte array public AgentBlockBlock(byte[] bytes, ref int i) { try { DestID = new LLUUID(bytes, i); i += 16; TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(DestID == null) { Console.WriteLine("Warning: DestID is null, in " + this.GetType()); } Array.Copy(DestID.GetBytes(), 0, bytes, i, 16); i += 16; if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentBlock --\n"; output += "DestID: " + DestID.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.OfferCallingCard public override PacketType Type { get { return PacketType.OfferCallingCard; } } /// AgentBlock block public AgentBlockBlock AgentBlock; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public OfferCallingCardPacket() { Header = new LowHeader(); Header.ID = 355; Header.Reliable = true; AgentBlock = new AgentBlockBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public OfferCallingCardPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentBlock = new AgentBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public OfferCallingCardPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentBlock = new AgentBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentBlock.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentBlock.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- OfferCallingCard ---\n"; output += AgentBlock.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// AcceptCallingCard packet public class AcceptCallingCardPacket : Packet { /// TransactionBlock block public class TransactionBlockBlock { /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public TransactionBlockBlock() { } /// Constructor for building the block from a byte array public TransactionBlockBlock(byte[] bytes, ref int i) { try { TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TransactionBlock --\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// FolderData block public class FolderDataBlock { /// FolderID field public LLUUID FolderID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public FolderDataBlock() { } /// Constructor for building the block from a byte array public FolderDataBlock(byte[] bytes, ref int i) { try { FolderID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- FolderData --\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AcceptCallingCard public override PacketType Type { get { return PacketType.AcceptCallingCard; } } /// TransactionBlock block public TransactionBlockBlock TransactionBlock; /// AgentData block public AgentDataBlock AgentData; /// FolderData block public FolderDataBlock[] FolderData; /// Default constructor public AcceptCallingCardPacket() { Header = new LowHeader(); Header.ID = 356; Header.Reliable = true; TransactionBlock = new TransactionBlockBlock(); AgentData = new AgentDataBlock(); FolderData = new FolderDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AcceptCallingCardPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TransactionBlock = new TransactionBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); int count = (int)bytes[i++]; FolderData = new FolderDataBlock[count]; for (int j = 0; j < count; j++) { FolderData[j] = new FolderDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public AcceptCallingCardPacket(Header head, byte[] bytes, ref int i) { Header = head; TransactionBlock = new TransactionBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); int count = (int)bytes[i++]; FolderData = new FolderDataBlock[count]; for (int j = 0; j < count; j++) { FolderData[j] = new FolderDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TransactionBlock.Length; length += AgentData.Length;; length++; for (int j = 0; j < FolderData.Length; j++) { length += FolderData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TransactionBlock.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); bytes[i++] = (byte)FolderData.Length; for (int j = 0; j < FolderData.Length; j++) { FolderData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AcceptCallingCard ---\n"; output += TransactionBlock.ToString() + "\n"; output += AgentData.ToString() + "\n"; for (int j = 0; j < FolderData.Length; j++) { output += FolderData[j].ToString() + "\n"; } return output; } } /// DeclineCallingCard packet public class DeclineCallingCardPacket : Packet { /// TransactionBlock block public class TransactionBlockBlock { /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public TransactionBlockBlock() { } /// Constructor for building the block from a byte array public TransactionBlockBlock(byte[] bytes, ref int i) { try { TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TransactionBlock --\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DeclineCallingCard public override PacketType Type { get { return PacketType.DeclineCallingCard; } } /// TransactionBlock block public TransactionBlockBlock TransactionBlock; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DeclineCallingCardPacket() { Header = new LowHeader(); Header.ID = 357; Header.Reliable = true; TransactionBlock = new TransactionBlockBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DeclineCallingCardPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TransactionBlock = new TransactionBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DeclineCallingCardPacket(Header head, byte[] bytes, ref int i) { Header = head; TransactionBlock = new TransactionBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TransactionBlock.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TransactionBlock.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DeclineCallingCard ---\n"; output += TransactionBlock.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// RezScript packet public class RezScriptPacket : Packet { /// UpdateBlock block public class UpdateBlockBlock { /// Enabled field public bool Enabled; /// ObjectLocalID field public uint ObjectLocalID; /// Length of this block serialized in bytes public int Length { get { return 5; } } /// Default constructor public UpdateBlockBlock() { } /// Constructor for building the block from a byte array public UpdateBlockBlock(byte[] bytes, ref int i) { try { Enabled = (bytes[i++] != 0) ? (bool)true : (bool)false; ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((Enabled) ? 1 : 0); bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- UpdateBlock --\n"; output += "Enabled: " + Enabled.ToString() + "\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// InventoryBlock block public class InventoryBlockBlock { /// GroupOwned field public bool GroupOwned; /// CRC field public uint CRC; /// CreationDate field public int CreationDate; /// SaleType field public byte SaleType; /// BaseMask field public uint BaseMask; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// InvType field public sbyte InvType; /// Type field public sbyte Type; /// GroupID field public LLUUID GroupID; /// SalePrice field public int SalePrice; /// OwnerID field public LLUUID OwnerID; /// CreatorID field public LLUUID CreatorID; /// ItemID field public LLUUID ItemID; /// FolderID field public LLUUID FolderID; /// EveryoneMask field public uint EveryoneMask; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// Flags field public uint Flags; /// NextOwnerMask field public uint NextOwnerMask; /// TransactionID field public LLUUID TransactionID; /// GroupMask field public uint GroupMask; /// OwnerMask field public uint OwnerMask; /// Length of this block serialized in bytes public int Length { get { int length = 136; if (Name != null) { length += 1 + Name.Length; } if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public InventoryBlockBlock() { } /// Constructor for building the block from a byte array public InventoryBlockBlock(byte[] bytes, ref int i) { int length; try { GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; CRC = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CreationDate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SaleType = (byte)bytes[i++]; BaseMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; InvType = (sbyte)bytes[i++]; Type = (sbyte)bytes[i++]; GroupID = new LLUUID(bytes, i); i += 16; SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerID = new LLUUID(bytes, i); i += 16; CreatorID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; FolderID = new LLUUID(bytes, i); i += 16; EveryoneMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); NextOwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TransactionID = new LLUUID(bytes, i); i += 16; GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((GroupOwned) ? 1 : 0); bytes[i++] = (byte)(CRC % 256); bytes[i++] = (byte)((CRC >> 8) % 256); bytes[i++] = (byte)((CRC >> 16) % 256); bytes[i++] = (byte)((CRC >> 24) % 256); bytes[i++] = (byte)(CreationDate % 256); bytes[i++] = (byte)((CreationDate >> 8) % 256); bytes[i++] = (byte)((CreationDate >> 16) % 256); bytes[i++] = (byte)((CreationDate >> 24) % 256); bytes[i++] = SaleType; bytes[i++] = (byte)(BaseMask % 256); bytes[i++] = (byte)((BaseMask >> 8) % 256); bytes[i++] = (byte)((BaseMask >> 16) % 256); bytes[i++] = (byte)((BaseMask >> 24) % 256); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)InvType; bytes[i++] = (byte)Type; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(SalePrice % 256); bytes[i++] = (byte)((SalePrice >> 8) % 256); bytes[i++] = (byte)((SalePrice >> 16) % 256); bytes[i++] = (byte)((SalePrice >> 24) % 256); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(CreatorID == null) { Console.WriteLine("Warning: CreatorID is null, in " + this.GetType()); } Array.Copy(CreatorID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(EveryoneMask % 256); bytes[i++] = (byte)((EveryoneMask >> 8) % 256); bytes[i++] = (byte)((EveryoneMask >> 16) % 256); bytes[i++] = (byte)((EveryoneMask >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); bytes[i++] = (byte)(NextOwnerMask % 256); bytes[i++] = (byte)((NextOwnerMask >> 8) % 256); bytes[i++] = (byte)((NextOwnerMask >> 16) % 256); bytes[i++] = (byte)((NextOwnerMask >> 24) % 256); if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(GroupMask % 256); bytes[i++] = (byte)((GroupMask >> 8) % 256); bytes[i++] = (byte)((GroupMask >> 16) % 256); bytes[i++] = (byte)((GroupMask >> 24) % 256); bytes[i++] = (byte)(OwnerMask % 256); bytes[i++] = (byte)((OwnerMask >> 8) % 256); bytes[i++] = (byte)((OwnerMask >> 16) % 256); bytes[i++] = (byte)((OwnerMask >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryBlock --\n"; output += "GroupOwned: " + GroupOwned.ToString() + "\n"; output += "CRC: " + CRC.ToString() + "\n"; output += "CreationDate: " + CreationDate.ToString() + "\n"; output += "SaleType: " + SaleType.ToString() + "\n"; output += "BaseMask: " + BaseMask.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "InvType: " + InvType.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "SalePrice: " + SalePrice.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "CreatorID: " + CreatorID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output += "EveryoneMask: " + EveryoneMask.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "NextOwnerMask: " + NextOwnerMask.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output += "GroupMask: " + GroupMask.ToString() + "\n"; output += "OwnerMask: " + OwnerMask.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RezScript public override PacketType Type { get { return PacketType.RezScript; } } /// UpdateBlock block public UpdateBlockBlock UpdateBlock; /// InventoryBlock block public InventoryBlockBlock InventoryBlock; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RezScriptPacket() { Header = new LowHeader(); Header.ID = 358; Header.Reliable = true; Header.Zerocoded = true; UpdateBlock = new UpdateBlockBlock(); InventoryBlock = new InventoryBlockBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RezScriptPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); UpdateBlock = new UpdateBlockBlock(bytes, ref i); InventoryBlock = new InventoryBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RezScriptPacket(Header head, byte[] bytes, ref int i) { Header = head; UpdateBlock = new UpdateBlockBlock(bytes, ref i); InventoryBlock = new InventoryBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += UpdateBlock.Length; length += InventoryBlock.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); UpdateBlock.ToBytes(bytes, ref i); InventoryBlock.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RezScript ---\n"; output += UpdateBlock.ToString() + "\n"; output += InventoryBlock.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// CreateInventoryItem packet public class CreateInventoryItemPacket : Packet { /// InventoryBlock block public class InventoryBlockBlock { /// CallbackID field public uint CallbackID; /// WearableType field public byte WearableType; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// InvType field public sbyte InvType; /// Type field public sbyte Type; /// FolderID field public LLUUID FolderID; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// NextOwnerMask field public uint NextOwnerMask; /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { int length = 43; if (Name != null) { length += 1 + Name.Length; } if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public InventoryBlockBlock() { } /// Constructor for building the block from a byte array public InventoryBlockBlock(byte[] bytes, ref int i) { int length; try { CallbackID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); WearableType = (byte)bytes[i++]; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; InvType = (sbyte)bytes[i++]; Type = (sbyte)bytes[i++]; FolderID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; NextOwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(CallbackID % 256); bytes[i++] = (byte)((CallbackID >> 8) % 256); bytes[i++] = (byte)((CallbackID >> 16) % 256); bytes[i++] = (byte)((CallbackID >> 24) % 256); bytes[i++] = WearableType; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)InvType; bytes[i++] = (byte)Type; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; bytes[i++] = (byte)(NextOwnerMask % 256); bytes[i++] = (byte)((NextOwnerMask >> 8) % 256); bytes[i++] = (byte)((NextOwnerMask >> 16) % 256); bytes[i++] = (byte)((NextOwnerMask >> 24) % 256); if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryBlock --\n"; output += "CallbackID: " + CallbackID.ToString() + "\n"; output += "WearableType: " + WearableType.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "InvType: " + InvType.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += "NextOwnerMask: " + NextOwnerMask.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.CreateInventoryItem public override PacketType Type { get { return PacketType.CreateInventoryItem; } } /// InventoryBlock block public InventoryBlockBlock InventoryBlock; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public CreateInventoryItemPacket() { Header = new LowHeader(); Header.ID = 359; Header.Reliable = true; Header.Zerocoded = true; InventoryBlock = new InventoryBlockBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public CreateInventoryItemPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); InventoryBlock = new InventoryBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public CreateInventoryItemPacket(Header head, byte[] bytes, ref int i) { Header = head; InventoryBlock = new InventoryBlockBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += InventoryBlock.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); InventoryBlock.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- CreateInventoryItem ---\n"; output += InventoryBlock.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// CreateLandmarkForEvent packet public class CreateLandmarkForEventPacket : Packet { /// InventoryBlock block public class InventoryBlockBlock { private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// FolderID field public LLUUID FolderID; /// Length of this block serialized in bytes public int Length { get { int length = 16; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public InventoryBlockBlock() { } /// Constructor for building the block from a byte array public InventoryBlockBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; FolderID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryBlock --\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output = output.Trim(); return output; } } /// EventData block public class EventDataBlock { /// EventID field public uint EventID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public EventDataBlock() { } /// Constructor for building the block from a byte array public EventDataBlock(byte[] bytes, ref int i) { try { EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(EventID % 256); bytes[i++] = (byte)((EventID >> 8) % 256); bytes[i++] = (byte)((EventID >> 16) % 256); bytes[i++] = (byte)((EventID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- EventData --\n"; output += "EventID: " + EventID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.CreateLandmarkForEvent public override PacketType Type { get { return PacketType.CreateLandmarkForEvent; } } /// InventoryBlock block public InventoryBlockBlock InventoryBlock; /// EventData block public EventDataBlock EventData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public CreateLandmarkForEventPacket() { Header = new LowHeader(); Header.ID = 360; Header.Reliable = true; Header.Zerocoded = true; InventoryBlock = new InventoryBlockBlock(); EventData = new EventDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public CreateLandmarkForEventPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); InventoryBlock = new InventoryBlockBlock(bytes, ref i); EventData = new EventDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public CreateLandmarkForEventPacket(Header head, byte[] bytes, ref int i) { Header = head; InventoryBlock = new InventoryBlockBlock(bytes, ref i); EventData = new EventDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += InventoryBlock.Length; length += EventData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); InventoryBlock.ToBytes(bytes, ref i); EventData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- CreateLandmarkForEvent ---\n"; output += InventoryBlock.ToString() + "\n"; output += EventData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// EventLocationRequest packet public class EventLocationRequestPacket : Packet { /// EventData block public class EventDataBlock { /// EventID field public uint EventID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public EventDataBlock() { } /// Constructor for building the block from a byte array public EventDataBlock(byte[] bytes, ref int i) { try { EventID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(EventID % 256); bytes[i++] = (byte)((EventID >> 8) % 256); bytes[i++] = (byte)((EventID >> 16) % 256); bytes[i++] = (byte)((EventID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- EventData --\n"; output += "EventID: " + EventID.ToString() + "\n"; output = output.Trim(); return output; } } /// QueryData block public class QueryDataBlock { /// QueryID field public LLUUID QueryID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { try { QueryID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.EventLocationRequest public override PacketType Type { get { return PacketType.EventLocationRequest; } } /// EventData block public EventDataBlock EventData; /// QueryData block public QueryDataBlock QueryData; /// Default constructor public EventLocationRequestPacket() { Header = new LowHeader(); Header.ID = 361; Header.Reliable = true; Header.Zerocoded = true; EventData = new EventDataBlock(); QueryData = new QueryDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public EventLocationRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); EventData = new EventDataBlock(bytes, ref i); QueryData = new QueryDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public EventLocationRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; EventData = new EventDataBlock(bytes, ref i); QueryData = new QueryDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += EventData.Length; length += QueryData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); EventData.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- EventLocationRequest ---\n"; output += EventData.ToString() + "\n"; output += QueryData.ToString() + "\n"; return output; } } /// EventLocationReply packet public class EventLocationReplyPacket : Packet { /// EventData block public class EventDataBlock { /// RegionID field public LLUUID RegionID; /// Success field public bool Success; /// RegionPos field public LLVector3 RegionPos; /// Length of this block serialized in bytes public int Length { get { return 29; } } /// Default constructor public EventDataBlock() { } /// Constructor for building the block from a byte array public EventDataBlock(byte[] bytes, ref int i) { try { RegionID = new LLUUID(bytes, i); i += 16; Success = (bytes[i++] != 0) ? (bool)true : (bool)false; RegionPos = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RegionID == null) { Console.WriteLine("Warning: RegionID is null, in " + this.GetType()); } Array.Copy(RegionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((Success) ? 1 : 0); if(RegionPos == null) { Console.WriteLine("Warning: RegionPos is null, in " + this.GetType()); } Array.Copy(RegionPos.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- EventData --\n"; output += "RegionID: " + RegionID.ToString() + "\n"; output += "Success: " + Success.ToString() + "\n"; output += "RegionPos: " + RegionPos.ToString() + "\n"; output = output.Trim(); return output; } } /// QueryData block public class QueryDataBlock { /// QueryID field public LLUUID QueryID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public QueryDataBlock() { } /// Constructor for building the block from a byte array public QueryDataBlock(byte[] bytes, ref int i) { try { QueryID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(QueryID == null) { Console.WriteLine("Warning: QueryID is null, in " + this.GetType()); } Array.Copy(QueryID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- QueryData --\n"; output += "QueryID: " + QueryID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.EventLocationReply public override PacketType Type { get { return PacketType.EventLocationReply; } } /// EventData block public EventDataBlock EventData; /// QueryData block public QueryDataBlock QueryData; /// Default constructor public EventLocationReplyPacket() { Header = new LowHeader(); Header.ID = 362; Header.Reliable = true; Header.Zerocoded = true; EventData = new EventDataBlock(); QueryData = new QueryDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public EventLocationReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); EventData = new EventDataBlock(bytes, ref i); QueryData = new QueryDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public EventLocationReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; EventData = new EventDataBlock(bytes, ref i); QueryData = new QueryDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += EventData.Length; length += QueryData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); EventData.ToBytes(bytes, ref i); QueryData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- EventLocationReply ---\n"; output += EventData.ToString() + "\n"; output += QueryData.ToString() + "\n"; return output; } } /// RegionHandleRequest packet public class RegionHandleRequestPacket : Packet { /// RequestBlock block public class RequestBlockBlock { /// RegionID field public LLUUID RegionID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public RequestBlockBlock() { } /// Constructor for building the block from a byte array public RequestBlockBlock(byte[] bytes, ref int i) { try { RegionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RegionID == null) { Console.WriteLine("Warning: RegionID is null, in " + this.GetType()); } Array.Copy(RegionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RequestBlock --\n"; output += "RegionID: " + RegionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RegionHandleRequest public override PacketType Type { get { return PacketType.RegionHandleRequest; } } /// RequestBlock block public RequestBlockBlock RequestBlock; /// Default constructor public RegionHandleRequestPacket() { Header = new LowHeader(); Header.ID = 363; Header.Reliable = true; RequestBlock = new RequestBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RegionHandleRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); RequestBlock = new RequestBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RegionHandleRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; RequestBlock = new RequestBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += RequestBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); RequestBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RegionHandleRequest ---\n"; output += RequestBlock.ToString() + "\n"; return output; } } /// RegionIDAndHandleReply packet public class RegionIDAndHandleReplyPacket : Packet { /// ReplyBlock block public class ReplyBlockBlock { /// RegionID field public LLUUID RegionID; /// RegionHandle field public ulong RegionHandle; /// Length of this block serialized in bytes public int Length { get { return 24; } } /// Default constructor public ReplyBlockBlock() { } /// Constructor for building the block from a byte array public ReplyBlockBlock(byte[] bytes, ref int i) { try { RegionID = new LLUUID(bytes, i); i += 16; RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RegionID == null) { Console.WriteLine("Warning: RegionID is null, in " + this.GetType()); } Array.Copy(RegionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ReplyBlock --\n"; output += "RegionID: " + RegionID.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RegionIDAndHandleReply public override PacketType Type { get { return PacketType.RegionIDAndHandleReply; } } /// ReplyBlock block public ReplyBlockBlock ReplyBlock; /// Default constructor public RegionIDAndHandleReplyPacket() { Header = new LowHeader(); Header.ID = 364; Header.Reliable = true; ReplyBlock = new ReplyBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RegionIDAndHandleReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ReplyBlock = new ReplyBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RegionIDAndHandleReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; ReplyBlock = new ReplyBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ReplyBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ReplyBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RegionIDAndHandleReply ---\n"; output += ReplyBlock.ToString() + "\n"; return output; } } /// MoneyTransferRequest packet public class MoneyTransferRequestPacket : Packet { /// MoneyData block public class MoneyDataBlock { /// AggregatePermInventory field public byte AggregatePermInventory; /// AggregatePermNextOwner field public byte AggregatePermNextOwner; /// DestID field public LLUUID DestID; /// Amount field public int Amount; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// Flags field public byte Flags; /// SourceID field public LLUUID SourceID; /// TransactionType field public int TransactionType; /// Length of this block serialized in bytes public int Length { get { int length = 43; if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public MoneyDataBlock() { } /// Constructor for building the block from a byte array public MoneyDataBlock(byte[] bytes, ref int i) { int length; try { AggregatePermInventory = (byte)bytes[i++]; AggregatePermNextOwner = (byte)bytes[i++]; DestID = new LLUUID(bytes, i); i += 16; Amount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; Flags = (byte)bytes[i++]; SourceID = new LLUUID(bytes, i); i += 16; TransactionType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = AggregatePermInventory; bytes[i++] = AggregatePermNextOwner; if(DestID == null) { Console.WriteLine("Warning: DestID is null, in " + this.GetType()); } Array.Copy(DestID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Amount % 256); bytes[i++] = (byte)((Amount >> 8) % 256); bytes[i++] = (byte)((Amount >> 16) % 256); bytes[i++] = (byte)((Amount >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; bytes[i++] = Flags; if(SourceID == null) { Console.WriteLine("Warning: SourceID is null, in " + this.GetType()); } Array.Copy(SourceID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(TransactionType % 256); bytes[i++] = (byte)((TransactionType >> 8) % 256); bytes[i++] = (byte)((TransactionType >> 16) % 256); bytes[i++] = (byte)((TransactionType >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MoneyData --\n"; output += "AggregatePermInventory: " + AggregatePermInventory.ToString() + "\n"; output += "AggregatePermNextOwner: " + AggregatePermNextOwner.ToString() + "\n"; output += "DestID: " + DestID.ToString() + "\n"; output += "Amount: " + Amount.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "SourceID: " + SourceID.ToString() + "\n"; output += "TransactionType: " + TransactionType.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MoneyTransferRequest public override PacketType Type { get { return PacketType.MoneyTransferRequest; } } /// MoneyData block public MoneyDataBlock MoneyData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public MoneyTransferRequestPacket() { Header = new LowHeader(); Header.ID = 365; Header.Reliable = true; Header.Zerocoded = true; MoneyData = new MoneyDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MoneyTransferRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MoneyData = new MoneyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MoneyTransferRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; MoneyData = new MoneyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MoneyData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MoneyData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MoneyTransferRequest ---\n"; output += MoneyData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// MoneyTransferBackend packet public class MoneyTransferBackendPacket : Packet { /// MoneyData block public class MoneyDataBlock { /// AggregatePermInventory field public byte AggregatePermInventory; /// AggregatePermNextOwner field public byte AggregatePermNextOwner; /// DestID field public LLUUID DestID; /// Amount field public int Amount; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// Flags field public byte Flags; /// SourceID field public LLUUID SourceID; /// TransactionID field public LLUUID TransactionID; /// TransactionTime field public uint TransactionTime; /// TransactionType field public int TransactionType; /// Length of this block serialized in bytes public int Length { get { int length = 63; if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public MoneyDataBlock() { } /// Constructor for building the block from a byte array public MoneyDataBlock(byte[] bytes, ref int i) { int length; try { AggregatePermInventory = (byte)bytes[i++]; AggregatePermNextOwner = (byte)bytes[i++]; DestID = new LLUUID(bytes, i); i += 16; Amount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; Flags = (byte)bytes[i++]; SourceID = new LLUUID(bytes, i); i += 16; TransactionID = new LLUUID(bytes, i); i += 16; TransactionTime = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TransactionType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = AggregatePermInventory; bytes[i++] = AggregatePermNextOwner; if(DestID == null) { Console.WriteLine("Warning: DestID is null, in " + this.GetType()); } Array.Copy(DestID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Amount % 256); bytes[i++] = (byte)((Amount >> 8) % 256); bytes[i++] = (byte)((Amount >> 16) % 256); bytes[i++] = (byte)((Amount >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; bytes[i++] = Flags; if(SourceID == null) { Console.WriteLine("Warning: SourceID is null, in " + this.GetType()); } Array.Copy(SourceID.GetBytes(), 0, bytes, i, 16); i += 16; if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(TransactionTime % 256); bytes[i++] = (byte)((TransactionTime >> 8) % 256); bytes[i++] = (byte)((TransactionTime >> 16) % 256); bytes[i++] = (byte)((TransactionTime >> 24) % 256); bytes[i++] = (byte)(TransactionType % 256); bytes[i++] = (byte)((TransactionType >> 8) % 256); bytes[i++] = (byte)((TransactionType >> 16) % 256); bytes[i++] = (byte)((TransactionType >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MoneyData --\n"; output += "AggregatePermInventory: " + AggregatePermInventory.ToString() + "\n"; output += "AggregatePermNextOwner: " + AggregatePermNextOwner.ToString() + "\n"; output += "DestID: " + DestID.ToString() + "\n"; output += "Amount: " + Amount.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "SourceID: " + SourceID.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output += "TransactionTime: " + TransactionTime.ToString() + "\n"; output += "TransactionType: " + TransactionType.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MoneyTransferBackend public override PacketType Type { get { return PacketType.MoneyTransferBackend; } } /// MoneyData block public MoneyDataBlock MoneyData; /// Default constructor public MoneyTransferBackendPacket() { Header = new LowHeader(); Header.ID = 366; Header.Reliable = true; Header.Zerocoded = true; MoneyData = new MoneyDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MoneyTransferBackendPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MoneyData = new MoneyDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MoneyTransferBackendPacket(Header head, byte[] bytes, ref int i) { Header = head; MoneyData = new MoneyDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MoneyData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MoneyData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MoneyTransferBackend ---\n"; output += MoneyData.ToString() + "\n"; return output; } } /// BulkMoneyTransfer packet public class BulkMoneyTransferPacket : Packet { /// MoneyData block public class MoneyDataBlock { /// DestID field public LLUUID DestID; /// Amount field public int Amount; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// Flags field public byte Flags; /// TransactionID field public LLUUID TransactionID; /// TransactionType field public int TransactionType; /// Length of this block serialized in bytes public int Length { get { int length = 41; if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public MoneyDataBlock() { } /// Constructor for building the block from a byte array public MoneyDataBlock(byte[] bytes, ref int i) { int length; try { DestID = new LLUUID(bytes, i); i += 16; Amount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; Flags = (byte)bytes[i++]; TransactionID = new LLUUID(bytes, i); i += 16; TransactionType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(DestID == null) { Console.WriteLine("Warning: DestID is null, in " + this.GetType()); } Array.Copy(DestID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Amount % 256); bytes[i++] = (byte)((Amount >> 8) % 256); bytes[i++] = (byte)((Amount >> 16) % 256); bytes[i++] = (byte)((Amount >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; bytes[i++] = Flags; if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(TransactionType % 256); bytes[i++] = (byte)((TransactionType >> 8) % 256); bytes[i++] = (byte)((TransactionType >> 16) % 256); bytes[i++] = (byte)((TransactionType >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MoneyData --\n"; output += "DestID: " + DestID.ToString() + "\n"; output += "Amount: " + Amount.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output += "TransactionType: " + TransactionType.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// RegionX field public uint RegionX; /// RegionY field public uint RegionY; /// Length of this block serialized in bytes public int Length { get { return 24; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; RegionX = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RegionY = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(RegionX % 256); bytes[i++] = (byte)((RegionX >> 8) % 256); bytes[i++] = (byte)((RegionX >> 16) % 256); bytes[i++] = (byte)((RegionX >> 24) % 256); bytes[i++] = (byte)(RegionY % 256); bytes[i++] = (byte)((RegionY >> 8) % 256); bytes[i++] = (byte)((RegionY >> 16) % 256); bytes[i++] = (byte)((RegionY >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "RegionX: " + RegionX.ToString() + "\n"; output += "RegionY: " + RegionY.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.BulkMoneyTransfer public override PacketType Type { get { return PacketType.BulkMoneyTransfer; } } /// MoneyData block public MoneyDataBlock[] MoneyData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public BulkMoneyTransferPacket() { Header = new LowHeader(); Header.ID = 367; Header.Reliable = true; Header.Zerocoded = true; MoneyData = new MoneyDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public BulkMoneyTransferPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; MoneyData = new MoneyDataBlock[count]; for (int j = 0; j < count; j++) { MoneyData[j] = new MoneyDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public BulkMoneyTransferPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; MoneyData = new MoneyDataBlock[count]; for (int j = 0; j < count; j++) { MoneyData[j] = new MoneyDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < MoneyData.Length; j++) { length += MoneyData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)MoneyData.Length; for (int j = 0; j < MoneyData.Length; j++) { MoneyData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- BulkMoneyTransfer ---\n"; for (int j = 0; j < MoneyData.Length; j++) { output += MoneyData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// AdjustBalance packet public class AdjustBalancePacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Delta field public int Delta; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; Delta = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Delta % 256); bytes[i++] = (byte)((Delta >> 8) % 256); bytes[i++] = (byte)((Delta >> 16) % 256); bytes[i++] = (byte)((Delta >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "Delta: " + Delta.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AdjustBalance public override PacketType Type { get { return PacketType.AdjustBalance; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AdjustBalancePacket() { Header = new LowHeader(); Header.ID = 368; Header.Reliable = true; Header.Zerocoded = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AdjustBalancePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AdjustBalancePacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AdjustBalance ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// MoneyBalanceRequest packet public class MoneyBalanceRequestPacket : Packet { /// MoneyData block public class MoneyDataBlock { /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public MoneyDataBlock() { } /// Constructor for building the block from a byte array public MoneyDataBlock(byte[] bytes, ref int i) { try { TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MoneyData --\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MoneyBalanceRequest public override PacketType Type { get { return PacketType.MoneyBalanceRequest; } } /// MoneyData block public MoneyDataBlock MoneyData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public MoneyBalanceRequestPacket() { Header = new LowHeader(); Header.ID = 369; Header.Reliable = true; Header.Zerocoded = true; MoneyData = new MoneyDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MoneyBalanceRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MoneyData = new MoneyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MoneyBalanceRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; MoneyData = new MoneyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MoneyData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MoneyData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MoneyBalanceRequest ---\n"; output += MoneyData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// MoneyBalanceReply packet public class MoneyBalanceReplyPacket : Packet { /// MoneyData block public class MoneyDataBlock { /// AgentID field public LLUUID AgentID; /// MoneyBalance field public int MoneyBalance; /// SquareMetersCredit field public int SquareMetersCredit; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// SquareMetersCommitted field public int SquareMetersCommitted; /// TransactionID field public LLUUID TransactionID; /// TransactionSuccess field public bool TransactionSuccess; /// Length of this block serialized in bytes public int Length { get { int length = 45; if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public MoneyDataBlock() { } /// Constructor for building the block from a byte array public MoneyDataBlock(byte[] bytes, ref int i) { int length; try { AgentID = new LLUUID(bytes, i); i += 16; MoneyBalance = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SquareMetersCredit = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; SquareMetersCommitted = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TransactionID = new LLUUID(bytes, i); i += 16; TransactionSuccess = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(MoneyBalance % 256); bytes[i++] = (byte)((MoneyBalance >> 8) % 256); bytes[i++] = (byte)((MoneyBalance >> 16) % 256); bytes[i++] = (byte)((MoneyBalance >> 24) % 256); bytes[i++] = (byte)(SquareMetersCredit % 256); bytes[i++] = (byte)((SquareMetersCredit >> 8) % 256); bytes[i++] = (byte)((SquareMetersCredit >> 16) % 256); bytes[i++] = (byte)((SquareMetersCredit >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; bytes[i++] = (byte)(SquareMetersCommitted % 256); bytes[i++] = (byte)((SquareMetersCommitted >> 8) % 256); bytes[i++] = (byte)((SquareMetersCommitted >> 16) % 256); bytes[i++] = (byte)((SquareMetersCommitted >> 24) % 256); if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((TransactionSuccess) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MoneyData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "MoneyBalance: " + MoneyBalance.ToString() + "\n"; output += "SquareMetersCredit: " + SquareMetersCredit.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += "SquareMetersCommitted: " + SquareMetersCommitted.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output += "TransactionSuccess: " + TransactionSuccess.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MoneyBalanceReply public override PacketType Type { get { return PacketType.MoneyBalanceReply; } } /// MoneyData block public MoneyDataBlock MoneyData; /// Default constructor public MoneyBalanceReplyPacket() { Header = new LowHeader(); Header.ID = 370; Header.Reliable = true; Header.Zerocoded = true; MoneyData = new MoneyDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MoneyBalanceReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MoneyData = new MoneyDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MoneyBalanceReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; MoneyData = new MoneyDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MoneyData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MoneyData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MoneyBalanceReply ---\n"; output += MoneyData.ToString() + "\n"; return output; } } /// RoutedMoneyBalanceReply packet public class RoutedMoneyBalanceReplyPacket : Packet { /// TargetBlock block public class TargetBlockBlock { /// TargetIP field public uint TargetIP; /// TargetPort field public ushort TargetPort; /// Length of this block serialized in bytes public int Length { get { return 6; } } /// Default constructor public TargetBlockBlock() { } /// Constructor for building the block from a byte array public TargetBlockBlock(byte[] bytes, ref int i) { try { TargetIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TargetPort = (ushort)((bytes[i++] << 8) + bytes[i++]); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(TargetIP % 256); bytes[i++] = (byte)((TargetIP >> 8) % 256); bytes[i++] = (byte)((TargetIP >> 16) % 256); bytes[i++] = (byte)((TargetIP >> 24) % 256); bytes[i++] = (byte)((TargetPort >> 8) % 256); bytes[i++] = (byte)(TargetPort % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TargetBlock --\n"; output += "TargetIP: " + TargetIP.ToString() + "\n"; output += "TargetPort: " + TargetPort.ToString() + "\n"; output = output.Trim(); return output; } } /// MoneyData block public class MoneyDataBlock { /// AgentID field public LLUUID AgentID; /// MoneyBalance field public int MoneyBalance; /// SquareMetersCredit field public int SquareMetersCredit; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// SquareMetersCommitted field public int SquareMetersCommitted; /// TransactionID field public LLUUID TransactionID; /// TransactionSuccess field public bool TransactionSuccess; /// Length of this block serialized in bytes public int Length { get { int length = 45; if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public MoneyDataBlock() { } /// Constructor for building the block from a byte array public MoneyDataBlock(byte[] bytes, ref int i) { int length; try { AgentID = new LLUUID(bytes, i); i += 16; MoneyBalance = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SquareMetersCredit = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; SquareMetersCommitted = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TransactionID = new LLUUID(bytes, i); i += 16; TransactionSuccess = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(MoneyBalance % 256); bytes[i++] = (byte)((MoneyBalance >> 8) % 256); bytes[i++] = (byte)((MoneyBalance >> 16) % 256); bytes[i++] = (byte)((MoneyBalance >> 24) % 256); bytes[i++] = (byte)(SquareMetersCredit % 256); bytes[i++] = (byte)((SquareMetersCredit >> 8) % 256); bytes[i++] = (byte)((SquareMetersCredit >> 16) % 256); bytes[i++] = (byte)((SquareMetersCredit >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; bytes[i++] = (byte)(SquareMetersCommitted % 256); bytes[i++] = (byte)((SquareMetersCommitted >> 8) % 256); bytes[i++] = (byte)((SquareMetersCommitted >> 16) % 256); bytes[i++] = (byte)((SquareMetersCommitted >> 24) % 256); if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((TransactionSuccess) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MoneyData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "MoneyBalance: " + MoneyBalance.ToString() + "\n"; output += "SquareMetersCredit: " + SquareMetersCredit.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += "SquareMetersCommitted: " + SquareMetersCommitted.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output += "TransactionSuccess: " + TransactionSuccess.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RoutedMoneyBalanceReply public override PacketType Type { get { return PacketType.RoutedMoneyBalanceReply; } } /// TargetBlock block public TargetBlockBlock TargetBlock; /// MoneyData block public MoneyDataBlock MoneyData; /// Default constructor public RoutedMoneyBalanceReplyPacket() { Header = new LowHeader(); Header.ID = 371; Header.Reliable = true; Header.Zerocoded = true; TargetBlock = new TargetBlockBlock(); MoneyData = new MoneyDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RoutedMoneyBalanceReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TargetBlock = new TargetBlockBlock(bytes, ref i); MoneyData = new MoneyDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RoutedMoneyBalanceReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; TargetBlock = new TargetBlockBlock(bytes, ref i); MoneyData = new MoneyDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TargetBlock.Length; length += MoneyData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TargetBlock.ToBytes(bytes, ref i); MoneyData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RoutedMoneyBalanceReply ---\n"; output += TargetBlock.ToString() + "\n"; output += MoneyData.ToString() + "\n"; return output; } } /// MoneyHistoryRequest packet public class MoneyHistoryRequestPacket : Packet { /// MoneyData block public class MoneyDataBlock { /// AgentID field public LLUUID AgentID; /// StartPeriod field public int StartPeriod; /// EndPeriod field public int EndPeriod; /// Length of this block serialized in bytes public int Length { get { return 24; } } /// Default constructor public MoneyDataBlock() { } /// Constructor for building the block from a byte array public MoneyDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; StartPeriod = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); EndPeriod = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(StartPeriod % 256); bytes[i++] = (byte)((StartPeriod >> 8) % 256); bytes[i++] = (byte)((StartPeriod >> 16) % 256); bytes[i++] = (byte)((StartPeriod >> 24) % 256); bytes[i++] = (byte)(EndPeriod % 256); bytes[i++] = (byte)((EndPeriod >> 8) % 256); bytes[i++] = (byte)((EndPeriod >> 16) % 256); bytes[i++] = (byte)((EndPeriod >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MoneyData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "StartPeriod: " + StartPeriod.ToString() + "\n"; output += "EndPeriod: " + EndPeriod.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MoneyHistoryRequest public override PacketType Type { get { return PacketType.MoneyHistoryRequest; } } /// MoneyData block public MoneyDataBlock MoneyData; /// Default constructor public MoneyHistoryRequestPacket() { Header = new LowHeader(); Header.ID = 372; Header.Reliable = true; MoneyData = new MoneyDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MoneyHistoryRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MoneyData = new MoneyDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MoneyHistoryRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; MoneyData = new MoneyDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MoneyData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MoneyData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MoneyHistoryRequest ---\n"; output += MoneyData.ToString() + "\n"; return output; } } /// MoneyHistoryReply packet public class MoneyHistoryReplyPacket : Packet { /// MoneyData block public class MoneyDataBlock { /// Balance field public int Balance; /// TaxEstimate field public int TaxEstimate; private byte[] _startdate; /// StartDate field public byte[] StartDate { get { return _startdate; } set { if (value == null) { _startdate = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _startdate = new byte[value.Length]; Array.Copy(value, _startdate, value.Length); } } } /// StartPeriod field public int StartPeriod; /// StipendEstimate field public int StipendEstimate; /// EndPeriod field public int EndPeriod; /// BonusEstimate field public int BonusEstimate; /// Length of this block serialized in bytes public int Length { get { int length = 24; if (StartDate != null) { length += 1 + StartDate.Length; } return length; } } /// Default constructor public MoneyDataBlock() { } /// Constructor for building the block from a byte array public MoneyDataBlock(byte[] bytes, ref int i) { int length; try { Balance = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TaxEstimate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _startdate = new byte[length]; Array.Copy(bytes, i, _startdate, 0, length); i += length; StartPeriod = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); StipendEstimate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); EndPeriod = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); BonusEstimate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Balance % 256); bytes[i++] = (byte)((Balance >> 8) % 256); bytes[i++] = (byte)((Balance >> 16) % 256); bytes[i++] = (byte)((Balance >> 24) % 256); bytes[i++] = (byte)(TaxEstimate % 256); bytes[i++] = (byte)((TaxEstimate >> 8) % 256); bytes[i++] = (byte)((TaxEstimate >> 16) % 256); bytes[i++] = (byte)((TaxEstimate >> 24) % 256); if(StartDate == null) { Console.WriteLine("Warning: StartDate is null, in " + this.GetType()); } bytes[i++] = (byte)StartDate.Length; Array.Copy(StartDate, 0, bytes, i, StartDate.Length); i += StartDate.Length; bytes[i++] = (byte)(StartPeriod % 256); bytes[i++] = (byte)((StartPeriod >> 8) % 256); bytes[i++] = (byte)((StartPeriod >> 16) % 256); bytes[i++] = (byte)((StartPeriod >> 24) % 256); bytes[i++] = (byte)(StipendEstimate % 256); bytes[i++] = (byte)((StipendEstimate >> 8) % 256); bytes[i++] = (byte)((StipendEstimate >> 16) % 256); bytes[i++] = (byte)((StipendEstimate >> 24) % 256); bytes[i++] = (byte)(EndPeriod % 256); bytes[i++] = (byte)((EndPeriod >> 8) % 256); bytes[i++] = (byte)((EndPeriod >> 16) % 256); bytes[i++] = (byte)((EndPeriod >> 24) % 256); bytes[i++] = (byte)(BonusEstimate % 256); bytes[i++] = (byte)((BonusEstimate >> 8) % 256); bytes[i++] = (byte)((BonusEstimate >> 16) % 256); bytes[i++] = (byte)((BonusEstimate >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MoneyData --\n"; output += "Balance: " + Balance.ToString() + "\n"; output += "TaxEstimate: " + TaxEstimate.ToString() + "\n"; output += Helpers.FieldToString(StartDate, "StartDate") + "\n"; output += "StartPeriod: " + StartPeriod.ToString() + "\n"; output += "StipendEstimate: " + StipendEstimate.ToString() + "\n"; output += "EndPeriod: " + EndPeriod.ToString() + "\n"; output += "BonusEstimate: " + BonusEstimate.ToString() + "\n"; output = output.Trim(); return output; } } /// HistoryData block public class HistoryDataBlock { /// Amount field public int Amount; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 4; if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public HistoryDataBlock() { } /// Constructor for building the block from a byte array public HistoryDataBlock(byte[] bytes, ref int i) { int length; try { Amount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Amount % 256); bytes[i++] = (byte)((Amount >> 8) % 256); bytes[i++] = (byte)((Amount >> 16) % 256); bytes[i++] = (byte)((Amount >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- HistoryData --\n"; output += "Amount: " + Amount.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MoneyHistoryReply public override PacketType Type { get { return PacketType.MoneyHistoryReply; } } /// MoneyData block public MoneyDataBlock MoneyData; /// HistoryData block public HistoryDataBlock[] HistoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public MoneyHistoryReplyPacket() { Header = new LowHeader(); Header.ID = 373; Header.Reliable = true; Header.Zerocoded = true; MoneyData = new MoneyDataBlock(); HistoryData = new HistoryDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MoneyHistoryReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MoneyData = new MoneyDataBlock(bytes, ref i); int count = (int)bytes[i++]; HistoryData = new HistoryDataBlock[count]; for (int j = 0; j < count; j++) { HistoryData[j] = new HistoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MoneyHistoryReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; MoneyData = new MoneyDataBlock(bytes, ref i); int count = (int)bytes[i++]; HistoryData = new HistoryDataBlock[count]; for (int j = 0; j < count; j++) { HistoryData[j] = new HistoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MoneyData.Length; length += AgentData.Length;; length++; for (int j = 0; j < HistoryData.Length; j++) { length += HistoryData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MoneyData.ToBytes(bytes, ref i); bytes[i++] = (byte)HistoryData.Length; for (int j = 0; j < HistoryData.Length; j++) { HistoryData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MoneyHistoryReply ---\n"; output += MoneyData.ToString() + "\n"; for (int j = 0; j < HistoryData.Length; j++) { output += HistoryData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// MoneySummaryRequest packet public class MoneySummaryRequestPacket : Packet { /// MoneyData block public class MoneyDataBlock { /// RequestID field public LLUUID RequestID; /// IntervalDays field public int IntervalDays; /// CurrentInterval field public int CurrentInterval; /// Length of this block serialized in bytes public int Length { get { return 24; } } /// Default constructor public MoneyDataBlock() { } /// Constructor for building the block from a byte array public MoneyDataBlock(byte[] bytes, ref int i) { try { RequestID = new LLUUID(bytes, i); i += 16; IntervalDays = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CurrentInterval = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(IntervalDays % 256); bytes[i++] = (byte)((IntervalDays >> 8) % 256); bytes[i++] = (byte)((IntervalDays >> 16) % 256); bytes[i++] = (byte)((IntervalDays >> 24) % 256); bytes[i++] = (byte)(CurrentInterval % 256); bytes[i++] = (byte)((CurrentInterval >> 8) % 256); bytes[i++] = (byte)((CurrentInterval >> 16) % 256); bytes[i++] = (byte)((CurrentInterval >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MoneyData --\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "IntervalDays: " + IntervalDays.ToString() + "\n"; output += "CurrentInterval: " + CurrentInterval.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MoneySummaryRequest public override PacketType Type { get { return PacketType.MoneySummaryRequest; } } /// MoneyData block public MoneyDataBlock MoneyData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public MoneySummaryRequestPacket() { Header = new LowHeader(); Header.ID = 374; Header.Reliable = true; MoneyData = new MoneyDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MoneySummaryRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MoneyData = new MoneyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MoneySummaryRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; MoneyData = new MoneyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MoneyData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MoneyData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MoneySummaryRequest ---\n"; output += MoneyData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// MoneySummaryReply packet public class MoneySummaryReplyPacket : Packet { /// MoneyData block public class MoneyDataBlock { /// ParcelDirFeeCurrent field public int ParcelDirFeeCurrent; private byte[] _taxdate; /// TaxDate field public byte[] TaxDate { get { return _taxdate; } set { if (value == null) { _taxdate = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _taxdate = new byte[value.Length]; Array.Copy(value, _taxdate, value.Length); } } } /// Balance field public int Balance; /// ParcelDirFeeEstimate field public int ParcelDirFeeEstimate; /// RequestID field public LLUUID RequestID; /// ObjectTaxCurrent field public int ObjectTaxCurrent; /// LightTaxCurrent field public int LightTaxCurrent; /// LandTaxCurrent field public int LandTaxCurrent; /// GroupTaxCurrent field public int GroupTaxCurrent; /// TotalDebits field public int TotalDebits; /// IntervalDays field public int IntervalDays; /// ObjectTaxEstimate field public int ObjectTaxEstimate; /// LightTaxEstimate field public int LightTaxEstimate; /// LandTaxEstimate field public int LandTaxEstimate; /// GroupTaxEstimate field public int GroupTaxEstimate; private byte[] _lasttaxdate; /// LastTaxDate field public byte[] LastTaxDate { get { return _lasttaxdate; } set { if (value == null) { _lasttaxdate = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _lasttaxdate = new byte[value.Length]; Array.Copy(value, _lasttaxdate, value.Length); } } } private byte[] _startdate; /// StartDate field public byte[] StartDate { get { return _startdate; } set { if (value == null) { _startdate = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _startdate = new byte[value.Length]; Array.Copy(value, _startdate, value.Length); } } } /// TotalCredits field public int TotalCredits; /// StipendEstimate field public int StipendEstimate; /// CurrentInterval field public int CurrentInterval; /// BonusEstimate field public int BonusEstimate; /// Length of this block serialized in bytes public int Length { get { int length = 84; if (TaxDate != null) { length += 1 + TaxDate.Length; } if (LastTaxDate != null) { length += 1 + LastTaxDate.Length; } if (StartDate != null) { length += 1 + StartDate.Length; } return length; } } /// Default constructor public MoneyDataBlock() { } /// Constructor for building the block from a byte array public MoneyDataBlock(byte[] bytes, ref int i) { int length; try { ParcelDirFeeCurrent = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _taxdate = new byte[length]; Array.Copy(bytes, i, _taxdate, 0, length); i += length; Balance = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ParcelDirFeeEstimate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RequestID = new LLUUID(bytes, i); i += 16; ObjectTaxCurrent = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); LightTaxCurrent = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); LandTaxCurrent = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupTaxCurrent = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TotalDebits = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); IntervalDays = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ObjectTaxEstimate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); LightTaxEstimate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); LandTaxEstimate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupTaxEstimate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _lasttaxdate = new byte[length]; Array.Copy(bytes, i, _lasttaxdate, 0, length); i += length; length = (ushort)bytes[i++]; _startdate = new byte[length]; Array.Copy(bytes, i, _startdate, 0, length); i += length; TotalCredits = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); StipendEstimate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CurrentInterval = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); BonusEstimate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ParcelDirFeeCurrent % 256); bytes[i++] = (byte)((ParcelDirFeeCurrent >> 8) % 256); bytes[i++] = (byte)((ParcelDirFeeCurrent >> 16) % 256); bytes[i++] = (byte)((ParcelDirFeeCurrent >> 24) % 256); if(TaxDate == null) { Console.WriteLine("Warning: TaxDate is null, in " + this.GetType()); } bytes[i++] = (byte)TaxDate.Length; Array.Copy(TaxDate, 0, bytes, i, TaxDate.Length); i += TaxDate.Length; bytes[i++] = (byte)(Balance % 256); bytes[i++] = (byte)((Balance >> 8) % 256); bytes[i++] = (byte)((Balance >> 16) % 256); bytes[i++] = (byte)((Balance >> 24) % 256); bytes[i++] = (byte)(ParcelDirFeeEstimate % 256); bytes[i++] = (byte)((ParcelDirFeeEstimate >> 8) % 256); bytes[i++] = (byte)((ParcelDirFeeEstimate >> 16) % 256); bytes[i++] = (byte)((ParcelDirFeeEstimate >> 24) % 256); if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(ObjectTaxCurrent % 256); bytes[i++] = (byte)((ObjectTaxCurrent >> 8) % 256); bytes[i++] = (byte)((ObjectTaxCurrent >> 16) % 256); bytes[i++] = (byte)((ObjectTaxCurrent >> 24) % 256); bytes[i++] = (byte)(LightTaxCurrent % 256); bytes[i++] = (byte)((LightTaxCurrent >> 8) % 256); bytes[i++] = (byte)((LightTaxCurrent >> 16) % 256); bytes[i++] = (byte)((LightTaxCurrent >> 24) % 256); bytes[i++] = (byte)(LandTaxCurrent % 256); bytes[i++] = (byte)((LandTaxCurrent >> 8) % 256); bytes[i++] = (byte)((LandTaxCurrent >> 16) % 256); bytes[i++] = (byte)((LandTaxCurrent >> 24) % 256); bytes[i++] = (byte)(GroupTaxCurrent % 256); bytes[i++] = (byte)((GroupTaxCurrent >> 8) % 256); bytes[i++] = (byte)((GroupTaxCurrent >> 16) % 256); bytes[i++] = (byte)((GroupTaxCurrent >> 24) % 256); bytes[i++] = (byte)(TotalDebits % 256); bytes[i++] = (byte)((TotalDebits >> 8) % 256); bytes[i++] = (byte)((TotalDebits >> 16) % 256); bytes[i++] = (byte)((TotalDebits >> 24) % 256); bytes[i++] = (byte)(IntervalDays % 256); bytes[i++] = (byte)((IntervalDays >> 8) % 256); bytes[i++] = (byte)((IntervalDays >> 16) % 256); bytes[i++] = (byte)((IntervalDays >> 24) % 256); bytes[i++] = (byte)(ObjectTaxEstimate % 256); bytes[i++] = (byte)((ObjectTaxEstimate >> 8) % 256); bytes[i++] = (byte)((ObjectTaxEstimate >> 16) % 256); bytes[i++] = (byte)((ObjectTaxEstimate >> 24) % 256); bytes[i++] = (byte)(LightTaxEstimate % 256); bytes[i++] = (byte)((LightTaxEstimate >> 8) % 256); bytes[i++] = (byte)((LightTaxEstimate >> 16) % 256); bytes[i++] = (byte)((LightTaxEstimate >> 24) % 256); bytes[i++] = (byte)(LandTaxEstimate % 256); bytes[i++] = (byte)((LandTaxEstimate >> 8) % 256); bytes[i++] = (byte)((LandTaxEstimate >> 16) % 256); bytes[i++] = (byte)((LandTaxEstimate >> 24) % 256); bytes[i++] = (byte)(GroupTaxEstimate % 256); bytes[i++] = (byte)((GroupTaxEstimate >> 8) % 256); bytes[i++] = (byte)((GroupTaxEstimate >> 16) % 256); bytes[i++] = (byte)((GroupTaxEstimate >> 24) % 256); if(LastTaxDate == null) { Console.WriteLine("Warning: LastTaxDate is null, in " + this.GetType()); } bytes[i++] = (byte)LastTaxDate.Length; Array.Copy(LastTaxDate, 0, bytes, i, LastTaxDate.Length); i += LastTaxDate.Length; if(StartDate == null) { Console.WriteLine("Warning: StartDate is null, in " + this.GetType()); } bytes[i++] = (byte)StartDate.Length; Array.Copy(StartDate, 0, bytes, i, StartDate.Length); i += StartDate.Length; bytes[i++] = (byte)(TotalCredits % 256); bytes[i++] = (byte)((TotalCredits >> 8) % 256); bytes[i++] = (byte)((TotalCredits >> 16) % 256); bytes[i++] = (byte)((TotalCredits >> 24) % 256); bytes[i++] = (byte)(StipendEstimate % 256); bytes[i++] = (byte)((StipendEstimate >> 8) % 256); bytes[i++] = (byte)((StipendEstimate >> 16) % 256); bytes[i++] = (byte)((StipendEstimate >> 24) % 256); bytes[i++] = (byte)(CurrentInterval % 256); bytes[i++] = (byte)((CurrentInterval >> 8) % 256); bytes[i++] = (byte)((CurrentInterval >> 16) % 256); bytes[i++] = (byte)((CurrentInterval >> 24) % 256); bytes[i++] = (byte)(BonusEstimate % 256); bytes[i++] = (byte)((BonusEstimate >> 8) % 256); bytes[i++] = (byte)((BonusEstimate >> 16) % 256); bytes[i++] = (byte)((BonusEstimate >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MoneyData --\n"; output += "ParcelDirFeeCurrent: " + ParcelDirFeeCurrent.ToString() + "\n"; output += Helpers.FieldToString(TaxDate, "TaxDate") + "\n"; output += "Balance: " + Balance.ToString() + "\n"; output += "ParcelDirFeeEstimate: " + ParcelDirFeeEstimate.ToString() + "\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "ObjectTaxCurrent: " + ObjectTaxCurrent.ToString() + "\n"; output += "LightTaxCurrent: " + LightTaxCurrent.ToString() + "\n"; output += "LandTaxCurrent: " + LandTaxCurrent.ToString() + "\n"; output += "GroupTaxCurrent: " + GroupTaxCurrent.ToString() + "\n"; output += "TotalDebits: " + TotalDebits.ToString() + "\n"; output += "IntervalDays: " + IntervalDays.ToString() + "\n"; output += "ObjectTaxEstimate: " + ObjectTaxEstimate.ToString() + "\n"; output += "LightTaxEstimate: " + LightTaxEstimate.ToString() + "\n"; output += "LandTaxEstimate: " + LandTaxEstimate.ToString() + "\n"; output += "GroupTaxEstimate: " + GroupTaxEstimate.ToString() + "\n"; output += Helpers.FieldToString(LastTaxDate, "LastTaxDate") + "\n"; output += Helpers.FieldToString(StartDate, "StartDate") + "\n"; output += "TotalCredits: " + TotalCredits.ToString() + "\n"; output += "StipendEstimate: " + StipendEstimate.ToString() + "\n"; output += "CurrentInterval: " + CurrentInterval.ToString() + "\n"; output += "BonusEstimate: " + BonusEstimate.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MoneySummaryReply public override PacketType Type { get { return PacketType.MoneySummaryReply; } } /// MoneyData block public MoneyDataBlock MoneyData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public MoneySummaryReplyPacket() { Header = new LowHeader(); Header.ID = 375; Header.Reliable = true; Header.Zerocoded = true; MoneyData = new MoneyDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MoneySummaryReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MoneyData = new MoneyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MoneySummaryReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; MoneyData = new MoneyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MoneyData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MoneyData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MoneySummaryReply ---\n"; output += MoneyData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// MoneyDetailsRequest packet public class MoneyDetailsRequestPacket : Packet { /// MoneyData block public class MoneyDataBlock { /// RequestID field public LLUUID RequestID; /// IntervalDays field public int IntervalDays; /// CurrentInterval field public int CurrentInterval; /// Length of this block serialized in bytes public int Length { get { return 24; } } /// Default constructor public MoneyDataBlock() { } /// Constructor for building the block from a byte array public MoneyDataBlock(byte[] bytes, ref int i) { try { RequestID = new LLUUID(bytes, i); i += 16; IntervalDays = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CurrentInterval = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(IntervalDays % 256); bytes[i++] = (byte)((IntervalDays >> 8) % 256); bytes[i++] = (byte)((IntervalDays >> 16) % 256); bytes[i++] = (byte)((IntervalDays >> 24) % 256); bytes[i++] = (byte)(CurrentInterval % 256); bytes[i++] = (byte)((CurrentInterval >> 8) % 256); bytes[i++] = (byte)((CurrentInterval >> 16) % 256); bytes[i++] = (byte)((CurrentInterval >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MoneyData --\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "IntervalDays: " + IntervalDays.ToString() + "\n"; output += "CurrentInterval: " + CurrentInterval.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MoneyDetailsRequest public override PacketType Type { get { return PacketType.MoneyDetailsRequest; } } /// MoneyData block public MoneyDataBlock MoneyData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public MoneyDetailsRequestPacket() { Header = new LowHeader(); Header.ID = 376; Header.Reliable = true; MoneyData = new MoneyDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MoneyDetailsRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MoneyData = new MoneyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MoneyDetailsRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; MoneyData = new MoneyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MoneyData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MoneyData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MoneyDetailsRequest ---\n"; output += MoneyData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// MoneyDetailsReply packet public class MoneyDetailsReplyPacket : Packet { /// MoneyData block public class MoneyDataBlock { /// RequestID field public LLUUID RequestID; /// IntervalDays field public int IntervalDays; private byte[] _startdate; /// StartDate field public byte[] StartDate { get { return _startdate; } set { if (value == null) { _startdate = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _startdate = new byte[value.Length]; Array.Copy(value, _startdate, value.Length); } } } /// CurrentInterval field public int CurrentInterval; /// Length of this block serialized in bytes public int Length { get { int length = 24; if (StartDate != null) { length += 1 + StartDate.Length; } return length; } } /// Default constructor public MoneyDataBlock() { } /// Constructor for building the block from a byte array public MoneyDataBlock(byte[] bytes, ref int i) { int length; try { RequestID = new LLUUID(bytes, i); i += 16; IntervalDays = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _startdate = new byte[length]; Array.Copy(bytes, i, _startdate, 0, length); i += length; CurrentInterval = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(IntervalDays % 256); bytes[i++] = (byte)((IntervalDays >> 8) % 256); bytes[i++] = (byte)((IntervalDays >> 16) % 256); bytes[i++] = (byte)((IntervalDays >> 24) % 256); if(StartDate == null) { Console.WriteLine("Warning: StartDate is null, in " + this.GetType()); } bytes[i++] = (byte)StartDate.Length; Array.Copy(StartDate, 0, bytes, i, StartDate.Length); i += StartDate.Length; bytes[i++] = (byte)(CurrentInterval % 256); bytes[i++] = (byte)((CurrentInterval >> 8) % 256); bytes[i++] = (byte)((CurrentInterval >> 16) % 256); bytes[i++] = (byte)((CurrentInterval >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MoneyData --\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "IntervalDays: " + IntervalDays.ToString() + "\n"; output += Helpers.FieldToString(StartDate, "StartDate") + "\n"; output += "CurrentInterval: " + CurrentInterval.ToString() + "\n"; output = output.Trim(); return output; } } /// HistoryData block public class HistoryDataBlock { /// Amount field public int Amount; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 4; if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public HistoryDataBlock() { } /// Constructor for building the block from a byte array public HistoryDataBlock(byte[] bytes, ref int i) { int length; try { Amount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Amount % 256); bytes[i++] = (byte)((Amount >> 8) % 256); bytes[i++] = (byte)((Amount >> 16) % 256); bytes[i++] = (byte)((Amount >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- HistoryData --\n"; output += "Amount: " + Amount.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MoneyDetailsReply public override PacketType Type { get { return PacketType.MoneyDetailsReply; } } /// MoneyData block public MoneyDataBlock MoneyData; /// HistoryData block public HistoryDataBlock[] HistoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public MoneyDetailsReplyPacket() { Header = new LowHeader(); Header.ID = 377; Header.Reliable = true; Header.Zerocoded = true; MoneyData = new MoneyDataBlock(); HistoryData = new HistoryDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MoneyDetailsReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MoneyData = new MoneyDataBlock(bytes, ref i); int count = (int)bytes[i++]; HistoryData = new HistoryDataBlock[count]; for (int j = 0; j < count; j++) { HistoryData[j] = new HistoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MoneyDetailsReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; MoneyData = new MoneyDataBlock(bytes, ref i); int count = (int)bytes[i++]; HistoryData = new HistoryDataBlock[count]; for (int j = 0; j < count; j++) { HistoryData[j] = new HistoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MoneyData.Length; length += AgentData.Length;; length++; for (int j = 0; j < HistoryData.Length; j++) { length += HistoryData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MoneyData.ToBytes(bytes, ref i); bytes[i++] = (byte)HistoryData.Length; for (int j = 0; j < HistoryData.Length; j++) { HistoryData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MoneyDetailsReply ---\n"; output += MoneyData.ToString() + "\n"; for (int j = 0; j < HistoryData.Length; j++) { output += HistoryData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// MoneyTransactionsRequest packet public class MoneyTransactionsRequestPacket : Packet { /// MoneyData block public class MoneyDataBlock { /// RequestID field public LLUUID RequestID; /// IntervalDays field public int IntervalDays; /// CurrentInterval field public int CurrentInterval; /// Length of this block serialized in bytes public int Length { get { return 24; } } /// Default constructor public MoneyDataBlock() { } /// Constructor for building the block from a byte array public MoneyDataBlock(byte[] bytes, ref int i) { try { RequestID = new LLUUID(bytes, i); i += 16; IntervalDays = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CurrentInterval = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(IntervalDays % 256); bytes[i++] = (byte)((IntervalDays >> 8) % 256); bytes[i++] = (byte)((IntervalDays >> 16) % 256); bytes[i++] = (byte)((IntervalDays >> 24) % 256); bytes[i++] = (byte)(CurrentInterval % 256); bytes[i++] = (byte)((CurrentInterval >> 8) % 256); bytes[i++] = (byte)((CurrentInterval >> 16) % 256); bytes[i++] = (byte)((CurrentInterval >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MoneyData --\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "IntervalDays: " + IntervalDays.ToString() + "\n"; output += "CurrentInterval: " + CurrentInterval.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MoneyTransactionsRequest public override PacketType Type { get { return PacketType.MoneyTransactionsRequest; } } /// MoneyData block public MoneyDataBlock MoneyData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public MoneyTransactionsRequestPacket() { Header = new LowHeader(); Header.ID = 378; Header.Reliable = true; MoneyData = new MoneyDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MoneyTransactionsRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MoneyData = new MoneyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MoneyTransactionsRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; MoneyData = new MoneyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MoneyData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MoneyData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MoneyTransactionsRequest ---\n"; output += MoneyData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// MoneyTransactionsReply packet public class MoneyTransactionsReplyPacket : Packet { /// MoneyData block public class MoneyDataBlock { /// RequestID field public LLUUID RequestID; /// IntervalDays field public int IntervalDays; private byte[] _startdate; /// StartDate field public byte[] StartDate { get { return _startdate; } set { if (value == null) { _startdate = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _startdate = new byte[value.Length]; Array.Copy(value, _startdate, value.Length); } } } /// CurrentInterval field public int CurrentInterval; /// Length of this block serialized in bytes public int Length { get { int length = 24; if (StartDate != null) { length += 1 + StartDate.Length; } return length; } } /// Default constructor public MoneyDataBlock() { } /// Constructor for building the block from a byte array public MoneyDataBlock(byte[] bytes, ref int i) { int length; try { RequestID = new LLUUID(bytes, i); i += 16; IntervalDays = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _startdate = new byte[length]; Array.Copy(bytes, i, _startdate, 0, length); i += length; CurrentInterval = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(IntervalDays % 256); bytes[i++] = (byte)((IntervalDays >> 8) % 256); bytes[i++] = (byte)((IntervalDays >> 16) % 256); bytes[i++] = (byte)((IntervalDays >> 24) % 256); if(StartDate == null) { Console.WriteLine("Warning: StartDate is null, in " + this.GetType()); } bytes[i++] = (byte)StartDate.Length; Array.Copy(StartDate, 0, bytes, i, StartDate.Length); i += StartDate.Length; bytes[i++] = (byte)(CurrentInterval % 256); bytes[i++] = (byte)((CurrentInterval >> 8) % 256); bytes[i++] = (byte)((CurrentInterval >> 16) % 256); bytes[i++] = (byte)((CurrentInterval >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MoneyData --\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "IntervalDays: " + IntervalDays.ToString() + "\n"; output += Helpers.FieldToString(StartDate, "StartDate") + "\n"; output += "CurrentInterval: " + CurrentInterval.ToString() + "\n"; output = output.Trim(); return output; } } /// HistoryData block public class HistoryDataBlock { private byte[] _time; /// Time field public byte[] Time { get { return _time; } set { if (value == null) { _time = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _time = new byte[value.Length]; Array.Copy(value, _time, value.Length); } } } private byte[] _item; /// Item field public byte[] Item { get { return _item; } set { if (value == null) { _item = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _item = new byte[value.Length]; Array.Copy(value, _item, value.Length); } } } private byte[] _user; /// User field public byte[] User { get { return _user; } set { if (value == null) { _user = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _user = new byte[value.Length]; Array.Copy(value, _user, value.Length); } } } /// Type field public int Type; /// Amount field public int Amount; /// Length of this block serialized in bytes public int Length { get { int length = 8; if (Time != null) { length += 1 + Time.Length; } if (Item != null) { length += 1 + Item.Length; } if (User != null) { length += 1 + User.Length; } return length; } } /// Default constructor public HistoryDataBlock() { } /// Constructor for building the block from a byte array public HistoryDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _time = new byte[length]; Array.Copy(bytes, i, _time, 0, length); i += length; length = (ushort)bytes[i++]; _item = new byte[length]; Array.Copy(bytes, i, _item, 0, length); i += length; length = (ushort)bytes[i++]; _user = new byte[length]; Array.Copy(bytes, i, _user, 0, length); i += length; Type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Amount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Time == null) { Console.WriteLine("Warning: Time is null, in " + this.GetType()); } bytes[i++] = (byte)Time.Length; Array.Copy(Time, 0, bytes, i, Time.Length); i += Time.Length; if(Item == null) { Console.WriteLine("Warning: Item is null, in " + this.GetType()); } bytes[i++] = (byte)Item.Length; Array.Copy(Item, 0, bytes, i, Item.Length); i += Item.Length; if(User == null) { Console.WriteLine("Warning: User is null, in " + this.GetType()); } bytes[i++] = (byte)User.Length; Array.Copy(User, 0, bytes, i, User.Length); i += User.Length; bytes[i++] = (byte)(Type % 256); bytes[i++] = (byte)((Type >> 8) % 256); bytes[i++] = (byte)((Type >> 16) % 256); bytes[i++] = (byte)((Type >> 24) % 256); bytes[i++] = (byte)(Amount % 256); bytes[i++] = (byte)((Amount >> 8) % 256); bytes[i++] = (byte)((Amount >> 16) % 256); bytes[i++] = (byte)((Amount >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- HistoryData --\n"; output += Helpers.FieldToString(Time, "Time") + "\n"; output += Helpers.FieldToString(Item, "Item") + "\n"; output += Helpers.FieldToString(User, "User") + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "Amount: " + Amount.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MoneyTransactionsReply public override PacketType Type { get { return PacketType.MoneyTransactionsReply; } } /// MoneyData block public MoneyDataBlock MoneyData; /// HistoryData block public HistoryDataBlock[] HistoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public MoneyTransactionsReplyPacket() { Header = new LowHeader(); Header.ID = 379; Header.Reliable = true; Header.Zerocoded = true; MoneyData = new MoneyDataBlock(); HistoryData = new HistoryDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MoneyTransactionsReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MoneyData = new MoneyDataBlock(bytes, ref i); int count = (int)bytes[i++]; HistoryData = new HistoryDataBlock[count]; for (int j = 0; j < count; j++) { HistoryData[j] = new HistoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MoneyTransactionsReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; MoneyData = new MoneyDataBlock(bytes, ref i); int count = (int)bytes[i++]; HistoryData = new HistoryDataBlock[count]; for (int j = 0; j < count; j++) { HistoryData[j] = new HistoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MoneyData.Length; length += AgentData.Length;; length++; for (int j = 0; j < HistoryData.Length; j++) { length += HistoryData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MoneyData.ToBytes(bytes, ref i); bytes[i++] = (byte)HistoryData.Length; for (int j = 0; j < HistoryData.Length; j++) { HistoryData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MoneyTransactionsReply ---\n"; output += MoneyData.ToString() + "\n"; for (int j = 0; j < HistoryData.Length; j++) { output += HistoryData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// GestureRequest packet public class GestureRequestPacket : Packet { /// AgentBlock block public class AgentBlockBlock { /// AgentID field public LLUUID AgentID; /// Reset field public bool Reset; /// Length of this block serialized in bytes public int Length { get { return 17; } } /// Default constructor public AgentBlockBlock() { } /// Constructor for building the block from a byte array public AgentBlockBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; Reset = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((Reset) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentBlock --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "Reset: " + Reset.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GestureRequest public override PacketType Type { get { return PacketType.GestureRequest; } } /// AgentBlock block public AgentBlockBlock AgentBlock; /// Default constructor public GestureRequestPacket() { Header = new LowHeader(); Header.ID = 380; Header.Reliable = true; AgentBlock = new AgentBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GestureRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentBlock = new AgentBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GestureRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentBlock = new AgentBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GestureRequest ---\n"; output += AgentBlock.ToString() + "\n"; return output; } } /// ActivateGestures packet public class ActivateGesturesPacket : Packet { /// Data block public class DataBlock { /// AssetID field public LLUUID AssetID; /// GestureFlags field public uint GestureFlags; /// ItemID field public LLUUID ItemID; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { AssetID = new LLUUID(bytes, i); i += 16; GestureFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AssetID == null) { Console.WriteLine("Warning: AssetID is null, in " + this.GetType()); } Array.Copy(AssetID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(GestureFlags % 256); bytes[i++] = (byte)((GestureFlags >> 8) % 256); bytes[i++] = (byte)((GestureFlags >> 16) % 256); bytes[i++] = (byte)((GestureFlags >> 24) % 256); if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "AssetID: " + AssetID.ToString() + "\n"; output += "GestureFlags: " + GestureFlags.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Flags field public uint Flags; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ActivateGestures public override PacketType Type { get { return PacketType.ActivateGestures; } } /// Data block public DataBlock[] Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ActivateGesturesPacket() { Header = new LowHeader(); Header.ID = 381; Header.Reliable = true; Data = new DataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ActivateGesturesPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ActivateGesturesPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)Data.Length; for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ActivateGestures ---\n"; for (int j = 0; j < Data.Length; j++) { output += Data[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// DeactivateGestures packet public class DeactivateGesturesPacket : Packet { /// Data block public class DataBlock { /// GestureFlags field public uint GestureFlags; /// ItemID field public LLUUID ItemID; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { GestureFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(GestureFlags % 256); bytes[i++] = (byte)((GestureFlags >> 8) % 256); bytes[i++] = (byte)((GestureFlags >> 16) % 256); bytes[i++] = (byte)((GestureFlags >> 24) % 256); if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "GestureFlags: " + GestureFlags.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Flags field public uint Flags; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DeactivateGestures public override PacketType Type { get { return PacketType.DeactivateGestures; } } /// Data block public DataBlock[] Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public DeactivateGesturesPacket() { Header = new LowHeader(); Header.ID = 382; Header.Reliable = true; Data = new DataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DeactivateGesturesPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DeactivateGesturesPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)Data.Length; for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DeactivateGestures ---\n"; for (int j = 0; j < Data.Length; j++) { output += Data[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// InventoryUpdate packet public class InventoryUpdatePacket : Packet { /// InventoryData block public class InventoryDataBlock { /// IsComplete field public byte IsComplete; private byte[] _filename; /// Filename field public byte[] Filename { get { return _filename; } set { if (value == null) { _filename = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _filename = new byte[value.Length]; Array.Copy(value, _filename, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 1; if (Filename != null) { length += 1 + Filename.Length; } return length; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { int length; try { IsComplete = (byte)bytes[i++]; length = (ushort)bytes[i++]; _filename = new byte[length]; Array.Copy(bytes, i, _filename, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = IsComplete; if(Filename == null) { Console.WriteLine("Warning: Filename is null, in " + this.GetType()); } bytes[i++] = (byte)Filename.Length; Array.Copy(Filename, 0, bytes, i, Filename.Length); i += Filename.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "IsComplete: " + IsComplete.ToString() + "\n"; output += Helpers.FieldToString(Filename, "Filename") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.InventoryUpdate public override PacketType Type { get { return PacketType.InventoryUpdate; } } /// InventoryData block public InventoryDataBlock InventoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public InventoryUpdatePacket() { Header = new LowHeader(); Header.ID = 383; Header.Reliable = true; InventoryData = new InventoryDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public InventoryUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); InventoryData = new InventoryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public InventoryUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; InventoryData = new InventoryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += InventoryData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); InventoryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- InventoryUpdate ---\n"; output += InventoryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// MuteListUpdate packet public class MuteListUpdatePacket : Packet { /// MuteData block public class MuteDataBlock { /// AgentID field public LLUUID AgentID; private byte[] _filename; /// Filename field public byte[] Filename { get { return _filename; } set { if (value == null) { _filename = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _filename = new byte[value.Length]; Array.Copy(value, _filename, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 16; if (Filename != null) { length += 1 + Filename.Length; } return length; } } /// Default constructor public MuteDataBlock() { } /// Constructor for building the block from a byte array public MuteDataBlock(byte[] bytes, ref int i) { int length; try { AgentID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _filename = new byte[length]; Array.Copy(bytes, i, _filename, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(Filename == null) { Console.WriteLine("Warning: Filename is null, in " + this.GetType()); } bytes[i++] = (byte)Filename.Length; Array.Copy(Filename, 0, bytes, i, Filename.Length); i += Filename.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MuteData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += Helpers.FieldToString(Filename, "Filename") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MuteListUpdate public override PacketType Type { get { return PacketType.MuteListUpdate; } } /// MuteData block public MuteDataBlock MuteData; /// Default constructor public MuteListUpdatePacket() { Header = new LowHeader(); Header.ID = 384; Header.Reliable = true; MuteData = new MuteDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MuteListUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MuteData = new MuteDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MuteListUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; MuteData = new MuteDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MuteData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MuteData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MuteListUpdate ---\n"; output += MuteData.ToString() + "\n"; return output; } } /// UseCachedMuteList packet public class UseCachedMuteListPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UseCachedMuteList public override PacketType Type { get { return PacketType.UseCachedMuteList; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public UseCachedMuteListPacket() { Header = new LowHeader(); Header.ID = 385; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UseCachedMuteListPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public UseCachedMuteListPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UseCachedMuteList ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// UserLoginLocationReply packet public class UserLoginLocationReplyPacket : Packet { /// URLBlock block public class URLBlockBlock { /// LocationID field public uint LocationID; /// LocationLookAt field public LLVector3 LocationLookAt; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public URLBlockBlock() { } /// Constructor for building the block from a byte array public URLBlockBlock(byte[] bytes, ref int i) { try { LocationID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); LocationLookAt = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(LocationID % 256); bytes[i++] = (byte)((LocationID >> 8) % 256); bytes[i++] = (byte)((LocationID >> 16) % 256); bytes[i++] = (byte)((LocationID >> 24) % 256); if(LocationLookAt == null) { Console.WriteLine("Warning: LocationLookAt is null, in " + this.GetType()); } Array.Copy(LocationLookAt.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- URLBlock --\n"; output += "LocationID: " + LocationID.ToString() + "\n"; output += "LocationLookAt: " + LocationLookAt.ToString() + "\n"; output = output.Trim(); return output; } } /// SimulatorBlock block public class SimulatorBlockBlock { /// IP field public uint IP; /// Port field public ushort Port; /// Length of this block serialized in bytes public int Length { get { return 6; } } /// Default constructor public SimulatorBlockBlock() { } /// Constructor for building the block from a byte array public SimulatorBlockBlock(byte[] bytes, ref int i) { try { IP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Port = (ushort)((bytes[i++] << 8) + bytes[i++]); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(IP % 256); bytes[i++] = (byte)((IP >> 8) % 256); bytes[i++] = (byte)((IP >> 16) % 256); bytes[i++] = (byte)((IP >> 24) % 256); bytes[i++] = (byte)((Port >> 8) % 256); bytes[i++] = (byte)(Port % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- SimulatorBlock --\n"; output += "IP: " + IP.ToString() + "\n"; output += "Port: " + Port.ToString() + "\n"; output = output.Trim(); return output; } } /// RegionInfo block public class RegionInfoBlock { /// SecPerDay field public uint SecPerDay; /// MetersPerGrid field public float MetersPerGrid; /// UsecSinceStart field public ulong UsecSinceStart; /// LocationValid field public bool LocationValid; /// SecPerYear field public uint SecPerYear; /// GridsPerEdge field public uint GridsPerEdge; /// Handle field public ulong Handle; /// SunAngVelocity field public LLVector3 SunAngVelocity; /// SunDirection field public LLVector3 SunDirection; /// Length of this block serialized in bytes public int Length { get { return 57; } } /// Default constructor public RegionInfoBlock() { } /// Constructor for building the block from a byte array public RegionInfoBlock(byte[] bytes, ref int i) { try { SecPerDay = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); MetersPerGrid = BitConverter.ToSingle(bytes, i); i += 4; UsecSinceStart = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); LocationValid = (bytes[i++] != 0) ? (bool)true : (bool)false; SecPerYear = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GridsPerEdge = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Handle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); SunAngVelocity = new LLVector3(bytes, i); i += 12; SunDirection = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = (byte)(SecPerDay % 256); bytes[i++] = (byte)((SecPerDay >> 8) % 256); bytes[i++] = (byte)((SecPerDay >> 16) % 256); bytes[i++] = (byte)((SecPerDay >> 24) % 256); ba = BitConverter.GetBytes(MetersPerGrid); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(UsecSinceStart % 256); bytes[i++] = (byte)((UsecSinceStart >> 8) % 256); bytes[i++] = (byte)((UsecSinceStart >> 16) % 256); bytes[i++] = (byte)((UsecSinceStart >> 24) % 256); bytes[i++] = (byte)((UsecSinceStart >> 32) % 256); bytes[i++] = (byte)((UsecSinceStart >> 40) % 256); bytes[i++] = (byte)((UsecSinceStart >> 48) % 256); bytes[i++] = (byte)((UsecSinceStart >> 56) % 256); bytes[i++] = (byte)((LocationValid) ? 1 : 0); bytes[i++] = (byte)(SecPerYear % 256); bytes[i++] = (byte)((SecPerYear >> 8) % 256); bytes[i++] = (byte)((SecPerYear >> 16) % 256); bytes[i++] = (byte)((SecPerYear >> 24) % 256); bytes[i++] = (byte)(GridsPerEdge % 256); bytes[i++] = (byte)((GridsPerEdge >> 8) % 256); bytes[i++] = (byte)((GridsPerEdge >> 16) % 256); bytes[i++] = (byte)((GridsPerEdge >> 24) % 256); bytes[i++] = (byte)(Handle % 256); bytes[i++] = (byte)((Handle >> 8) % 256); bytes[i++] = (byte)((Handle >> 16) % 256); bytes[i++] = (byte)((Handle >> 24) % 256); bytes[i++] = (byte)((Handle >> 32) % 256); bytes[i++] = (byte)((Handle >> 40) % 256); bytes[i++] = (byte)((Handle >> 48) % 256); bytes[i++] = (byte)((Handle >> 56) % 256); if(SunAngVelocity == null) { Console.WriteLine("Warning: SunAngVelocity is null, in " + this.GetType()); } Array.Copy(SunAngVelocity.GetBytes(), 0, bytes, i, 12); i += 12; if(SunDirection == null) { Console.WriteLine("Warning: SunDirection is null, in " + this.GetType()); } Array.Copy(SunDirection.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionInfo --\n"; output += "SecPerDay: " + SecPerDay.ToString() + "\n"; output += "MetersPerGrid: " + MetersPerGrid.ToString() + "\n"; output += "UsecSinceStart: " + UsecSinceStart.ToString() + "\n"; output += "LocationValid: " + LocationValid.ToString() + "\n"; output += "SecPerYear: " + SecPerYear.ToString() + "\n"; output += "GridsPerEdge: " + GridsPerEdge.ToString() + "\n"; output += "Handle: " + Handle.ToString() + "\n"; output += "SunAngVelocity: " + SunAngVelocity.ToString() + "\n"; output += "SunDirection: " + SunDirection.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { private byte[] _message; /// Message field public byte[] Message { get { return _message; } set { if (value == null) { _message = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _message = new byte[value.Length]; Array.Copy(value, _message, value.Length); } } } /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { int length = 16; if (Message != null) { length += 1 + Message.Length; } return length; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _message = new byte[length]; Array.Copy(bytes, i, _message, 0, length); i += length; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Message == null) { Console.WriteLine("Warning: Message is null, in " + this.GetType()); } bytes[i++] = (byte)Message.Length; Array.Copy(Message, 0, bytes, i, Message.Length); i += Message.Length; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += Helpers.FieldToString(Message, "Message") + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UserLoginLocationReply public override PacketType Type { get { return PacketType.UserLoginLocationReply; } } /// URLBlock block public URLBlockBlock URLBlock; /// SimulatorBlock block public SimulatorBlockBlock SimulatorBlock; /// RegionInfo block public RegionInfoBlock RegionInfo; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public UserLoginLocationReplyPacket() { Header = new LowHeader(); Header.ID = 386; Header.Reliable = true; Header.Zerocoded = true; URLBlock = new URLBlockBlock(); SimulatorBlock = new SimulatorBlockBlock(); RegionInfo = new RegionInfoBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UserLoginLocationReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); URLBlock = new URLBlockBlock(bytes, ref i); SimulatorBlock = new SimulatorBlockBlock(bytes, ref i); RegionInfo = new RegionInfoBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public UserLoginLocationReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; URLBlock = new URLBlockBlock(bytes, ref i); SimulatorBlock = new SimulatorBlockBlock(bytes, ref i); RegionInfo = new RegionInfoBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += URLBlock.Length; length += SimulatorBlock.Length; length += RegionInfo.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); URLBlock.ToBytes(bytes, ref i); SimulatorBlock.ToBytes(bytes, ref i); RegionInfo.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UserLoginLocationReply ---\n"; output += URLBlock.ToString() + "\n"; output += SimulatorBlock.ToString() + "\n"; output += RegionInfo.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// UserSimLocationReply packet public class UserSimLocationReplyPacket : Packet { /// SimulatorBlock block public class SimulatorBlockBlock { private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// AccessOK field public byte AccessOK; /// SimHandle field public ulong SimHandle; /// Length of this block serialized in bytes public int Length { get { int length = 9; if (SimName != null) { length += 1 + SimName.Length; } return length; } } /// Default constructor public SimulatorBlockBlock() { } /// Constructor for building the block from a byte array public SimulatorBlockBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; AccessOK = (byte)bytes[i++]; SimHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; bytes[i++] = AccessOK; bytes[i++] = (byte)(SimHandle % 256); bytes[i++] = (byte)((SimHandle >> 8) % 256); bytes[i++] = (byte)((SimHandle >> 16) % 256); bytes[i++] = (byte)((SimHandle >> 24) % 256); bytes[i++] = (byte)((SimHandle >> 32) % 256); bytes[i++] = (byte)((SimHandle >> 40) % 256); bytes[i++] = (byte)((SimHandle >> 48) % 256); bytes[i++] = (byte)((SimHandle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- SimulatorBlock --\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "AccessOK: " + AccessOK.ToString() + "\n"; output += "SimHandle: " + SimHandle.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UserSimLocationReply public override PacketType Type { get { return PacketType.UserSimLocationReply; } } /// SimulatorBlock block public SimulatorBlockBlock SimulatorBlock; /// Default constructor public UserSimLocationReplyPacket() { Header = new LowHeader(); Header.ID = 387; Header.Reliable = true; SimulatorBlock = new SimulatorBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UserSimLocationReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); SimulatorBlock = new SimulatorBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public UserSimLocationReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; SimulatorBlock = new SimulatorBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += SimulatorBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); SimulatorBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UserSimLocationReply ---\n"; output += SimulatorBlock.ToString() + "\n"; return output; } } /// UserListReply packet public class UserListReplyPacket : Packet { /// UserBlock block public class UserBlockBlock { private byte[] _lastname; /// LastName field public byte[] LastName { get { return _lastname; } set { if (value == null) { _lastname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _lastname = new byte[value.Length]; Array.Copy(value, _lastname, value.Length); } } } private byte[] _firstname; /// FirstName field public byte[] FirstName { get { return _firstname; } set { if (value == null) { _firstname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _firstname = new byte[value.Length]; Array.Copy(value, _firstname, value.Length); } } } /// Status field public byte Status; /// Length of this block serialized in bytes public int Length { get { int length = 1; if (LastName != null) { length += 1 + LastName.Length; } if (FirstName != null) { length += 1 + FirstName.Length; } return length; } } /// Default constructor public UserBlockBlock() { } /// Constructor for building the block from a byte array public UserBlockBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _lastname = new byte[length]; Array.Copy(bytes, i, _lastname, 0, length); i += length; length = (ushort)bytes[i++]; _firstname = new byte[length]; Array.Copy(bytes, i, _firstname, 0, length); i += length; Status = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(LastName == null) { Console.WriteLine("Warning: LastName is null, in " + this.GetType()); } bytes[i++] = (byte)LastName.Length; Array.Copy(LastName, 0, bytes, i, LastName.Length); i += LastName.Length; if(FirstName == null) { Console.WriteLine("Warning: FirstName is null, in " + this.GetType()); } bytes[i++] = (byte)FirstName.Length; Array.Copy(FirstName, 0, bytes, i, FirstName.Length); i += FirstName.Length; bytes[i++] = Status; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- UserBlock --\n"; output += Helpers.FieldToString(LastName, "LastName") + "\n"; output += Helpers.FieldToString(FirstName, "FirstName") + "\n"; output += "Status: " + Status.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UserListReply public override PacketType Type { get { return PacketType.UserListReply; } } /// UserBlock block public UserBlockBlock[] UserBlock; /// Default constructor public UserListReplyPacket() { Header = new LowHeader(); Header.ID = 388; Header.Reliable = true; UserBlock = new UserBlockBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UserListReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; UserBlock = new UserBlockBlock[count]; for (int j = 0; j < count; j++) { UserBlock[j] = new UserBlockBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public UserListReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; UserBlock = new UserBlockBlock[count]; for (int j = 0; j < count; j++) { UserBlock[j] = new UserBlockBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < UserBlock.Length; j++) { length += UserBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)UserBlock.Length; for (int j = 0; j < UserBlock.Length; j++) { UserBlock[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UserListReply ---\n"; for (int j = 0; j < UserBlock.Length; j++) { output += UserBlock[j].ToString() + "\n"; } return output; } } /// OnlineNotification packet public class OnlineNotificationPacket : Packet { /// AgentBlock block public class AgentBlockBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentBlockBlock() { } /// Constructor for building the block from a byte array public AgentBlockBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentBlock --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.OnlineNotification public override PacketType Type { get { return PacketType.OnlineNotification; } } /// AgentBlock block public AgentBlockBlock[] AgentBlock; /// Default constructor public OnlineNotificationPacket() { Header = new LowHeader(); Header.ID = 389; Header.Reliable = true; AgentBlock = new AgentBlockBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public OnlineNotificationPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; AgentBlock = new AgentBlockBlock[count]; for (int j = 0; j < count; j++) { AgentBlock[j] = new AgentBlockBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public OnlineNotificationPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; AgentBlock = new AgentBlockBlock[count]; for (int j = 0; j < count; j++) { AgentBlock[j] = new AgentBlockBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < AgentBlock.Length; j++) { length += AgentBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)AgentBlock.Length; for (int j = 0; j < AgentBlock.Length; j++) { AgentBlock[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- OnlineNotification ---\n"; for (int j = 0; j < AgentBlock.Length; j++) { output += AgentBlock[j].ToString() + "\n"; } return output; } } /// OfflineNotification packet public class OfflineNotificationPacket : Packet { /// AgentBlock block public class AgentBlockBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentBlockBlock() { } /// Constructor for building the block from a byte array public AgentBlockBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentBlock --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.OfflineNotification public override PacketType Type { get { return PacketType.OfflineNotification; } } /// AgentBlock block public AgentBlockBlock[] AgentBlock; /// Default constructor public OfflineNotificationPacket() { Header = new LowHeader(); Header.ID = 390; Header.Reliable = true; AgentBlock = new AgentBlockBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public OfflineNotificationPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; AgentBlock = new AgentBlockBlock[count]; for (int j = 0; j < count; j++) { AgentBlock[j] = new AgentBlockBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public OfflineNotificationPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; AgentBlock = new AgentBlockBlock[count]; for (int j = 0; j < count; j++) { AgentBlock[j] = new AgentBlockBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < AgentBlock.Length; j++) { length += AgentBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)AgentBlock.Length; for (int j = 0; j < AgentBlock.Length; j++) { AgentBlock[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- OfflineNotification ---\n"; for (int j = 0; j < AgentBlock.Length; j++) { output += AgentBlock[j].ToString() + "\n"; } return output; } } /// SetStartLocationRequest packet public class SetStartLocationRequestPacket : Packet { /// StartLocationData block public class StartLocationDataBlock { /// LocationPos field public LLVector3 LocationPos; private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// LocationID field public uint LocationID; /// LocationLookAt field public LLVector3 LocationLookAt; /// Length of this block serialized in bytes public int Length { get { int length = 28; if (SimName != null) { length += 1 + SimName.Length; } return length; } } /// Default constructor public StartLocationDataBlock() { } /// Constructor for building the block from a byte array public StartLocationDataBlock(byte[] bytes, ref int i) { int length; try { LocationPos = new LLVector3(bytes, i); i += 12; length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; LocationID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); LocationLookAt = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(LocationPos == null) { Console.WriteLine("Warning: LocationPos is null, in " + this.GetType()); } Array.Copy(LocationPos.GetBytes(), 0, bytes, i, 12); i += 12; if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; bytes[i++] = (byte)(LocationID % 256); bytes[i++] = (byte)((LocationID >> 8) % 256); bytes[i++] = (byte)((LocationID >> 16) % 256); bytes[i++] = (byte)((LocationID >> 24) % 256); if(LocationLookAt == null) { Console.WriteLine("Warning: LocationLookAt is null, in " + this.GetType()); } Array.Copy(LocationLookAt.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- StartLocationData --\n"; output += "LocationPos: " + LocationPos.ToString() + "\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "LocationID: " + LocationID.ToString() + "\n"; output += "LocationLookAt: " + LocationLookAt.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SetStartLocationRequest public override PacketType Type { get { return PacketType.SetStartLocationRequest; } } /// StartLocationData block public StartLocationDataBlock StartLocationData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public SetStartLocationRequestPacket() { Header = new LowHeader(); Header.ID = 391; Header.Reliable = true; Header.Zerocoded = true; StartLocationData = new StartLocationDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SetStartLocationRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); StartLocationData = new StartLocationDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SetStartLocationRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; StartLocationData = new StartLocationDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += StartLocationData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); StartLocationData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SetStartLocationRequest ---\n"; output += StartLocationData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// SetStartLocation packet public class SetStartLocationPacket : Packet { /// StartLocationData block public class StartLocationDataBlock { /// LocationPos field public LLVector3 LocationPos; /// AgentID field public LLUUID AgentID; /// RegionID field public LLUUID RegionID; /// RegionHandle field public ulong RegionHandle; /// LocationID field public uint LocationID; /// LocationLookAt field public LLVector3 LocationLookAt; /// Length of this block serialized in bytes public int Length { get { return 68; } } /// Default constructor public StartLocationDataBlock() { } /// Constructor for building the block from a byte array public StartLocationDataBlock(byte[] bytes, ref int i) { try { LocationPos = new LLVector3(bytes, i); i += 12; AgentID = new LLUUID(bytes, i); i += 16; RegionID = new LLUUID(bytes, i); i += 16; RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); LocationID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); LocationLookAt = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(LocationPos == null) { Console.WriteLine("Warning: LocationPos is null, in " + this.GetType()); } Array.Copy(LocationPos.GetBytes(), 0, bytes, i, 12); i += 12; if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(RegionID == null) { Console.WriteLine("Warning: RegionID is null, in " + this.GetType()); } Array.Copy(RegionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); bytes[i++] = (byte)(LocationID % 256); bytes[i++] = (byte)((LocationID >> 8) % 256); bytes[i++] = (byte)((LocationID >> 16) % 256); bytes[i++] = (byte)((LocationID >> 24) % 256); if(LocationLookAt == null) { Console.WriteLine("Warning: LocationLookAt is null, in " + this.GetType()); } Array.Copy(LocationLookAt.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- StartLocationData --\n"; output += "LocationPos: " + LocationPos.ToString() + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "RegionID: " + RegionID.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output += "LocationID: " + LocationID.ToString() + "\n"; output += "LocationLookAt: " + LocationLookAt.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SetStartLocation public override PacketType Type { get { return PacketType.SetStartLocation; } } /// StartLocationData block public StartLocationDataBlock StartLocationData; /// Default constructor public SetStartLocationPacket() { Header = new LowHeader(); Header.ID = 392; Header.Reliable = true; Header.Zerocoded = true; StartLocationData = new StartLocationDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SetStartLocationPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); StartLocationData = new StartLocationDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SetStartLocationPacket(Header head, byte[] bytes, ref int i) { Header = head; StartLocationData = new StartLocationDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += StartLocationData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); StartLocationData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SetStartLocation ---\n"; output += StartLocationData.ToString() + "\n"; return output; } } /// UserLoginLocationRequest packet public class UserLoginLocationRequestPacket : Packet { /// URLBlock block public class URLBlockBlock { private byte[] _simname; /// SimName field public byte[] SimName { get { return _simname; } set { if (value == null) { _simname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simname = new byte[value.Length]; Array.Copy(value, _simname, value.Length); } } } /// Pos field public LLVector3 Pos; /// Length of this block serialized in bytes public int Length { get { int length = 12; if (SimName != null) { length += 1 + SimName.Length; } return length; } } /// Default constructor public URLBlockBlock() { } /// Constructor for building the block from a byte array public URLBlockBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _simname = new byte[length]; Array.Copy(bytes, i, _simname, 0, length); i += length; Pos = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(SimName == null) { Console.WriteLine("Warning: SimName is null, in " + this.GetType()); } bytes[i++] = (byte)SimName.Length; Array.Copy(SimName, 0, bytes, i, SimName.Length); i += SimName.Length; if(Pos == null) { Console.WriteLine("Warning: Pos is null, in " + this.GetType()); } Array.Copy(Pos.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- URLBlock --\n"; output += Helpers.FieldToString(SimName, "SimName") + "\n"; output += "Pos: " + Pos.ToString() + "\n"; output = output.Trim(); return output; } } /// PositionBlock block public class PositionBlockBlock { /// ViewerRegion field public ulong ViewerRegion; /// ViewerPosition field public LLVector3 ViewerPosition; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public PositionBlockBlock() { } /// Constructor for building the block from a byte array public PositionBlockBlock(byte[] bytes, ref int i) { try { ViewerRegion = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); ViewerPosition = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ViewerRegion % 256); bytes[i++] = (byte)((ViewerRegion >> 8) % 256); bytes[i++] = (byte)((ViewerRegion >> 16) % 256); bytes[i++] = (byte)((ViewerRegion >> 24) % 256); bytes[i++] = (byte)((ViewerRegion >> 32) % 256); bytes[i++] = (byte)((ViewerRegion >> 40) % 256); bytes[i++] = (byte)((ViewerRegion >> 48) % 256); bytes[i++] = (byte)((ViewerRegion >> 56) % 256); if(ViewerPosition == null) { Console.WriteLine("Warning: ViewerPosition is null, in " + this.GetType()); } Array.Copy(ViewerPosition.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- PositionBlock --\n"; output += "ViewerRegion: " + ViewerRegion.ToString() + "\n"; output += "ViewerPosition: " + ViewerPosition.ToString() + "\n"; output = output.Trim(); return output; } } /// UserBlock block public class UserBlockBlock { /// FirstLogin field public bool FirstLogin; /// TravelAccess field public byte TravelAccess; /// LimitedToEstate field public uint LimitedToEstate; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 22; } } /// Default constructor public UserBlockBlock() { } /// Constructor for building the block from a byte array public UserBlockBlock(byte[] bytes, ref int i) { try { FirstLogin = (bytes[i++] != 0) ? (bool)true : (bool)false; TravelAccess = (byte)bytes[i++]; LimitedToEstate = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((FirstLogin) ? 1 : 0); bytes[i++] = TravelAccess; bytes[i++] = (byte)(LimitedToEstate % 256); bytes[i++] = (byte)((LimitedToEstate >> 8) % 256); bytes[i++] = (byte)((LimitedToEstate >> 16) % 256); bytes[i++] = (byte)((LimitedToEstate >> 24) % 256); if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- UserBlock --\n"; output += "FirstLogin: " + FirstLogin.ToString() + "\n"; output += "TravelAccess: " + TravelAccess.ToString() + "\n"; output += "LimitedToEstate: " + LimitedToEstate.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UserLoginLocationRequest public override PacketType Type { get { return PacketType.UserLoginLocationRequest; } } /// URLBlock block public URLBlockBlock URLBlock; /// PositionBlock block public PositionBlockBlock PositionBlock; /// UserBlock block public UserBlockBlock UserBlock; /// Default constructor public UserLoginLocationRequestPacket() { Header = new LowHeader(); Header.ID = 393; Header.Reliable = true; Header.Zerocoded = true; URLBlock = new URLBlockBlock(); PositionBlock = new PositionBlockBlock(); UserBlock = new UserBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UserLoginLocationRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); URLBlock = new URLBlockBlock(bytes, ref i); PositionBlock = new PositionBlockBlock(bytes, ref i); UserBlock = new UserBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public UserLoginLocationRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; URLBlock = new URLBlockBlock(bytes, ref i); PositionBlock = new PositionBlockBlock(bytes, ref i); UserBlock = new UserBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += URLBlock.Length; length += PositionBlock.Length; length += UserBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); URLBlock.ToBytes(bytes, ref i); PositionBlock.ToBytes(bytes, ref i); UserBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UserLoginLocationRequest ---\n"; output += URLBlock.ToString() + "\n"; output += PositionBlock.ToString() + "\n"; output += UserBlock.ToString() + "\n"; return output; } } /// SpaceLoginLocationReply packet public class SpaceLoginLocationReplyPacket : Packet { /// SimulatorBlock block public class SimulatorBlockBlock { /// IP field public uint IP; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// Port field public ushort Port; /// SimAccess field public byte SimAccess; /// CircuitCode field public uint CircuitCode; /// Length of this block serialized in bytes public int Length { get { int length = 11; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public SimulatorBlockBlock() { } /// Constructor for building the block from a byte array public SimulatorBlockBlock(byte[] bytes, ref int i) { int length; try { IP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; Port = (ushort)((bytes[i++] << 8) + bytes[i++]); SimAccess = (byte)bytes[i++]; CircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(IP % 256); bytes[i++] = (byte)((IP >> 8) % 256); bytes[i++] = (byte)((IP >> 16) % 256); bytes[i++] = (byte)((IP >> 24) % 256); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)((Port >> 8) % 256); bytes[i++] = (byte)(Port % 256); bytes[i++] = SimAccess; bytes[i++] = (byte)(CircuitCode % 256); bytes[i++] = (byte)((CircuitCode >> 8) % 256); bytes[i++] = (byte)((CircuitCode >> 16) % 256); bytes[i++] = (byte)((CircuitCode >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- SimulatorBlock --\n"; output += "IP: " + IP.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "Port: " + Port.ToString() + "\n"; output += "SimAccess: " + SimAccess.ToString() + "\n"; output += "CircuitCode: " + CircuitCode.ToString() + "\n"; output = output.Trim(); return output; } } /// UserBlock block public class UserBlockBlock { /// LocationPos field public LLVector3 LocationPos; /// SessionID field public LLUUID SessionID; /// LocationID field public uint LocationID; /// LocationLookAt field public LLVector3 LocationLookAt; /// Length of this block serialized in bytes public int Length { get { return 44; } } /// Default constructor public UserBlockBlock() { } /// Constructor for building the block from a byte array public UserBlockBlock(byte[] bytes, ref int i) { try { LocationPos = new LLVector3(bytes, i); i += 12; SessionID = new LLUUID(bytes, i); i += 16; LocationID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); LocationLookAt = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(LocationPos == null) { Console.WriteLine("Warning: LocationPos is null, in " + this.GetType()); } Array.Copy(LocationPos.GetBytes(), 0, bytes, i, 12); i += 12; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(LocationID % 256); bytes[i++] = (byte)((LocationID >> 8) % 256); bytes[i++] = (byte)((LocationID >> 16) % 256); bytes[i++] = (byte)((LocationID >> 24) % 256); if(LocationLookAt == null) { Console.WriteLine("Warning: LocationLookAt is null, in " + this.GetType()); } Array.Copy(LocationLookAt.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- UserBlock --\n"; output += "LocationPos: " + LocationPos.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "LocationID: " + LocationID.ToString() + "\n"; output += "LocationLookAt: " + LocationLookAt.ToString() + "\n"; output = output.Trim(); return output; } } /// RegionInfo block public class RegionInfoBlock { /// SecPerDay field public uint SecPerDay; /// MetersPerGrid field public float MetersPerGrid; /// UsecSinceStart field public ulong UsecSinceStart; /// SecPerYear field public uint SecPerYear; /// GridsPerEdge field public uint GridsPerEdge; /// Handle field public ulong Handle; /// SunAngVelocity field public LLVector3 SunAngVelocity; /// SunDirection field public LLVector3 SunDirection; /// Length of this block serialized in bytes public int Length { get { return 56; } } /// Default constructor public RegionInfoBlock() { } /// Constructor for building the block from a byte array public RegionInfoBlock(byte[] bytes, ref int i) { try { SecPerDay = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); MetersPerGrid = BitConverter.ToSingle(bytes, i); i += 4; UsecSinceStart = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); SecPerYear = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GridsPerEdge = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Handle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); SunAngVelocity = new LLVector3(bytes, i); i += 12; SunDirection = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = (byte)(SecPerDay % 256); bytes[i++] = (byte)((SecPerDay >> 8) % 256); bytes[i++] = (byte)((SecPerDay >> 16) % 256); bytes[i++] = (byte)((SecPerDay >> 24) % 256); ba = BitConverter.GetBytes(MetersPerGrid); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(UsecSinceStart % 256); bytes[i++] = (byte)((UsecSinceStart >> 8) % 256); bytes[i++] = (byte)((UsecSinceStart >> 16) % 256); bytes[i++] = (byte)((UsecSinceStart >> 24) % 256); bytes[i++] = (byte)((UsecSinceStart >> 32) % 256); bytes[i++] = (byte)((UsecSinceStart >> 40) % 256); bytes[i++] = (byte)((UsecSinceStart >> 48) % 256); bytes[i++] = (byte)((UsecSinceStart >> 56) % 256); bytes[i++] = (byte)(SecPerYear % 256); bytes[i++] = (byte)((SecPerYear >> 8) % 256); bytes[i++] = (byte)((SecPerYear >> 16) % 256); bytes[i++] = (byte)((SecPerYear >> 24) % 256); bytes[i++] = (byte)(GridsPerEdge % 256); bytes[i++] = (byte)((GridsPerEdge >> 8) % 256); bytes[i++] = (byte)((GridsPerEdge >> 16) % 256); bytes[i++] = (byte)((GridsPerEdge >> 24) % 256); bytes[i++] = (byte)(Handle % 256); bytes[i++] = (byte)((Handle >> 8) % 256); bytes[i++] = (byte)((Handle >> 16) % 256); bytes[i++] = (byte)((Handle >> 24) % 256); bytes[i++] = (byte)((Handle >> 32) % 256); bytes[i++] = (byte)((Handle >> 40) % 256); bytes[i++] = (byte)((Handle >> 48) % 256); bytes[i++] = (byte)((Handle >> 56) % 256); if(SunAngVelocity == null) { Console.WriteLine("Warning: SunAngVelocity is null, in " + this.GetType()); } Array.Copy(SunAngVelocity.GetBytes(), 0, bytes, i, 12); i += 12; if(SunDirection == null) { Console.WriteLine("Warning: SunDirection is null, in " + this.GetType()); } Array.Copy(SunDirection.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionInfo --\n"; output += "SecPerDay: " + SecPerDay.ToString() + "\n"; output += "MetersPerGrid: " + MetersPerGrid.ToString() + "\n"; output += "UsecSinceStart: " + UsecSinceStart.ToString() + "\n"; output += "SecPerYear: " + SecPerYear.ToString() + "\n"; output += "GridsPerEdge: " + GridsPerEdge.ToString() + "\n"; output += "Handle: " + Handle.ToString() + "\n"; output += "SunAngVelocity: " + SunAngVelocity.ToString() + "\n"; output += "SunDirection: " + SunDirection.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SpaceLoginLocationReply public override PacketType Type { get { return PacketType.SpaceLoginLocationReply; } } /// SimulatorBlock block public SimulatorBlockBlock SimulatorBlock; /// UserBlock block public UserBlockBlock UserBlock; /// RegionInfo block public RegionInfoBlock RegionInfo; /// Default constructor public SpaceLoginLocationReplyPacket() { Header = new LowHeader(); Header.ID = 394; Header.Reliable = true; Header.Zerocoded = true; SimulatorBlock = new SimulatorBlockBlock(); UserBlock = new UserBlockBlock(); RegionInfo = new RegionInfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SpaceLoginLocationReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); SimulatorBlock = new SimulatorBlockBlock(bytes, ref i); UserBlock = new UserBlockBlock(bytes, ref i); RegionInfo = new RegionInfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SpaceLoginLocationReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; SimulatorBlock = new SimulatorBlockBlock(bytes, ref i); UserBlock = new UserBlockBlock(bytes, ref i); RegionInfo = new RegionInfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += SimulatorBlock.Length; length += UserBlock.Length; length += RegionInfo.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); SimulatorBlock.ToBytes(bytes, ref i); UserBlock.ToBytes(bytes, ref i); RegionInfo.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SpaceLoginLocationReply ---\n"; output += SimulatorBlock.ToString() + "\n"; output += UserBlock.ToString() + "\n"; output += RegionInfo.ToString() + "\n"; return output; } } /// NetTest packet public class NetTestPacket : Packet { /// NetBlock block public class NetBlockBlock { /// Port field public ushort Port; /// Length of this block serialized in bytes public int Length { get { return 2; } } /// Default constructor public NetBlockBlock() { } /// Constructor for building the block from a byte array public NetBlockBlock(byte[] bytes, ref int i) { try { Port = (ushort)((bytes[i++] << 8) + bytes[i++]); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((Port >> 8) % 256); bytes[i++] = (byte)(Port % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- NetBlock --\n"; output += "Port: " + Port.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.NetTest public override PacketType Type { get { return PacketType.NetTest; } } /// NetBlock block public NetBlockBlock NetBlock; /// Default constructor public NetTestPacket() { Header = new LowHeader(); Header.ID = 395; Header.Reliable = true; NetBlock = new NetBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public NetTestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); NetBlock = new NetBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public NetTestPacket(Header head, byte[] bytes, ref int i) { Header = head; NetBlock = new NetBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += NetBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); NetBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- NetTest ---\n"; output += NetBlock.ToString() + "\n"; return output; } } /// SetCPURatio packet public class SetCPURatioPacket : Packet { /// Data block public class DataBlock { /// Ratio field public byte Ratio; /// Length of this block serialized in bytes public int Length { get { return 1; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { Ratio = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = Ratio; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "Ratio: " + Ratio.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SetCPURatio public override PacketType Type { get { return PacketType.SetCPURatio; } } /// Data block public DataBlock Data; /// Default constructor public SetCPURatioPacket() { Header = new LowHeader(); Header.ID = 396; Header.Reliable = true; Data = new DataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SetCPURatioPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SetCPURatioPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SetCPURatio ---\n"; output += Data.ToString() + "\n"; return output; } } /// SimCrashed packet public class SimCrashedPacket : Packet { /// Data block public class DataBlock { /// RegionX field public uint RegionX; /// RegionY field public uint RegionY; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { RegionX = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RegionY = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(RegionX % 256); bytes[i++] = (byte)((RegionX >> 8) % 256); bytes[i++] = (byte)((RegionX >> 16) % 256); bytes[i++] = (byte)((RegionX >> 24) % 256); bytes[i++] = (byte)(RegionY % 256); bytes[i++] = (byte)((RegionY >> 8) % 256); bytes[i++] = (byte)((RegionY >> 16) % 256); bytes[i++] = (byte)((RegionY >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "RegionX: " + RegionX.ToString() + "\n"; output += "RegionY: " + RegionY.ToString() + "\n"; output = output.Trim(); return output; } } /// Users block public class UsersBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public UsersBlock() { } /// Constructor for building the block from a byte array public UsersBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Users --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SimCrashed public override PacketType Type { get { return PacketType.SimCrashed; } } /// Data block public DataBlock Data; /// Users block public UsersBlock[] Users; /// Default constructor public SimCrashedPacket() { Header = new LowHeader(); Header.ID = 397; Header.Reliable = true; Data = new DataBlock(); Users = new UsersBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SimCrashedPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); int count = (int)bytes[i++]; Users = new UsersBlock[count]; for (int j = 0; j < count; j++) { Users[j] = new UsersBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public SimCrashedPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); int count = (int)bytes[i++]; Users = new UsersBlock[count]; for (int j = 0; j < count; j++) { Users[j] = new UsersBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length;; length++; for (int j = 0; j < Users.Length; j++) { length += Users[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); bytes[i++] = (byte)Users.Length; for (int j = 0; j < Users.Length; j++) { Users[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SimCrashed ---\n"; output += Data.ToString() + "\n"; for (int j = 0; j < Users.Length; j++) { output += Users[j].ToString() + "\n"; } return output; } } /// SimulatorPauseState packet public class SimulatorPauseStatePacket : Packet { /// PauseBlock block public class PauseBlockBlock { /// TasksPaused field public uint TasksPaused; /// SimPaused field public uint SimPaused; /// LayersPaused field public uint LayersPaused; /// Length of this block serialized in bytes public int Length { get { return 12; } } /// Default constructor public PauseBlockBlock() { } /// Constructor for building the block from a byte array public PauseBlockBlock(byte[] bytes, ref int i) { try { TasksPaused = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SimPaused = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); LayersPaused = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(TasksPaused % 256); bytes[i++] = (byte)((TasksPaused >> 8) % 256); bytes[i++] = (byte)((TasksPaused >> 16) % 256); bytes[i++] = (byte)((TasksPaused >> 24) % 256); bytes[i++] = (byte)(SimPaused % 256); bytes[i++] = (byte)((SimPaused >> 8) % 256); bytes[i++] = (byte)((SimPaused >> 16) % 256); bytes[i++] = (byte)((SimPaused >> 24) % 256); bytes[i++] = (byte)(LayersPaused % 256); bytes[i++] = (byte)((LayersPaused >> 8) % 256); bytes[i++] = (byte)((LayersPaused >> 16) % 256); bytes[i++] = (byte)((LayersPaused >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- PauseBlock --\n"; output += "TasksPaused: " + TasksPaused.ToString() + "\n"; output += "SimPaused: " + SimPaused.ToString() + "\n"; output += "LayersPaused: " + LayersPaused.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SimulatorPauseState public override PacketType Type { get { return PacketType.SimulatorPauseState; } } /// PauseBlock block public PauseBlockBlock PauseBlock; /// Default constructor public SimulatorPauseStatePacket() { Header = new LowHeader(); Header.ID = 398; Header.Reliable = true; PauseBlock = new PauseBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SimulatorPauseStatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); PauseBlock = new PauseBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SimulatorPauseStatePacket(Header head, byte[] bytes, ref int i) { Header = head; PauseBlock = new PauseBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += PauseBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); PauseBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SimulatorPauseState ---\n"; output += PauseBlock.ToString() + "\n"; return output; } } /// SimulatorThrottleSettings packet public class SimulatorThrottleSettingsPacket : Packet { /// Sender block public class SenderBlock { /// ID field public LLUUID ID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public SenderBlock() { } /// Constructor for building the block from a byte array public SenderBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Sender --\n"; output += "ID: " + ID.ToString() + "\n"; output = output.Trim(); return output; } } /// Throttle block public class ThrottleBlock { private byte[] _throttles; /// Throttles field public byte[] Throttles { get { return _throttles; } set { if (value == null) { _throttles = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _throttles = new byte[value.Length]; Array.Copy(value, _throttles, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (Throttles != null) { length += 1 + Throttles.Length; } return length; } } /// Default constructor public ThrottleBlock() { } /// Constructor for building the block from a byte array public ThrottleBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _throttles = new byte[length]; Array.Copy(bytes, i, _throttles, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Throttles == null) { Console.WriteLine("Warning: Throttles is null, in " + this.GetType()); } bytes[i++] = (byte)Throttles.Length; Array.Copy(Throttles, 0, bytes, i, Throttles.Length); i += Throttles.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Throttle --\n"; output += Helpers.FieldToString(Throttles, "Throttles") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SimulatorThrottleSettings public override PacketType Type { get { return PacketType.SimulatorThrottleSettings; } } /// Sender block public SenderBlock Sender; /// Throttle block public ThrottleBlock Throttle; /// Default constructor public SimulatorThrottleSettingsPacket() { Header = new LowHeader(); Header.ID = 399; Header.Reliable = true; Sender = new SenderBlock(); Throttle = new ThrottleBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SimulatorThrottleSettingsPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Sender = new SenderBlock(bytes, ref i); Throttle = new ThrottleBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SimulatorThrottleSettingsPacket(Header head, byte[] bytes, ref int i) { Header = head; Sender = new SenderBlock(bytes, ref i); Throttle = new ThrottleBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Sender.Length; length += Throttle.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Sender.ToBytes(bytes, ref i); Throttle.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SimulatorThrottleSettings ---\n"; output += Sender.ToString() + "\n"; output += Throttle.ToString() + "\n"; return output; } } /// NameValuePair packet public class NameValuePairPacket : Packet { /// NameValueData block public class NameValueDataBlock { private byte[] _nvpair; /// NVPair field public byte[] NVPair { get { return _nvpair; } set { if (value == null) { _nvpair = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _nvpair = new byte[value.Length]; Array.Copy(value, _nvpair, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (NVPair != null) { length += 2 + NVPair.Length; } return length; } } /// Default constructor public NameValueDataBlock() { } /// Constructor for building the block from a byte array public NameValueDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _nvpair = new byte[length]; Array.Copy(bytes, i, _nvpair, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(NVPair == null) { Console.WriteLine("Warning: NVPair is null, in " + this.GetType()); } bytes[i++] = (byte)(NVPair.Length % 256); bytes[i++] = (byte)((NVPair.Length >> 8) % 256); Array.Copy(NVPair, 0, bytes, i, NVPair.Length); i += NVPair.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- NameValueData --\n"; output += Helpers.FieldToString(NVPair, "NVPair") + "\n"; output = output.Trim(); return output; } } /// TaskData block public class TaskDataBlock { /// ID field public LLUUID ID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public TaskDataBlock() { } /// Constructor for building the block from a byte array public TaskDataBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TaskData --\n"; output += "ID: " + ID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.NameValuePair public override PacketType Type { get { return PacketType.NameValuePair; } } /// NameValueData block public NameValueDataBlock[] NameValueData; /// TaskData block public TaskDataBlock TaskData; /// Default constructor public NameValuePairPacket() { Header = new LowHeader(); Header.ID = 400; Header.Reliable = true; NameValueData = new NameValueDataBlock[0]; TaskData = new TaskDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public NameValuePairPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; NameValueData = new NameValueDataBlock[count]; for (int j = 0; j < count; j++) { NameValueData[j] = new NameValueDataBlock(bytes, ref i); } TaskData = new TaskDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public NameValuePairPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; NameValueData = new NameValueDataBlock[count]; for (int j = 0; j < count; j++) { NameValueData[j] = new NameValueDataBlock(bytes, ref i); } TaskData = new TaskDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TaskData.Length;; length++; for (int j = 0; j < NameValueData.Length; j++) { length += NameValueData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)NameValueData.Length; for (int j = 0; j < NameValueData.Length; j++) { NameValueData[j].ToBytes(bytes, ref i); } TaskData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- NameValuePair ---\n"; for (int j = 0; j < NameValueData.Length; j++) { output += NameValueData[j].ToString() + "\n"; } output += TaskData.ToString() + "\n"; return output; } } /// RemoveNameValuePair packet public class RemoveNameValuePairPacket : Packet { /// NameValueData block public class NameValueDataBlock { private byte[] _nvpair; /// NVPair field public byte[] NVPair { get { return _nvpair; } set { if (value == null) { _nvpair = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _nvpair = new byte[value.Length]; Array.Copy(value, _nvpair, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (NVPair != null) { length += 2 + NVPair.Length; } return length; } } /// Default constructor public NameValueDataBlock() { } /// Constructor for building the block from a byte array public NameValueDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _nvpair = new byte[length]; Array.Copy(bytes, i, _nvpair, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(NVPair == null) { Console.WriteLine("Warning: NVPair is null, in " + this.GetType()); } bytes[i++] = (byte)(NVPair.Length % 256); bytes[i++] = (byte)((NVPair.Length >> 8) % 256); Array.Copy(NVPair, 0, bytes, i, NVPair.Length); i += NVPair.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- NameValueData --\n"; output += Helpers.FieldToString(NVPair, "NVPair") + "\n"; output = output.Trim(); return output; } } /// TaskData block public class TaskDataBlock { /// ID field public LLUUID ID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public TaskDataBlock() { } /// Constructor for building the block from a byte array public TaskDataBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TaskData --\n"; output += "ID: " + ID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RemoveNameValuePair public override PacketType Type { get { return PacketType.RemoveNameValuePair; } } /// NameValueData block public NameValueDataBlock[] NameValueData; /// TaskData block public TaskDataBlock TaskData; /// Default constructor public RemoveNameValuePairPacket() { Header = new LowHeader(); Header.ID = 401; Header.Reliable = true; NameValueData = new NameValueDataBlock[0]; TaskData = new TaskDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RemoveNameValuePairPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; NameValueData = new NameValueDataBlock[count]; for (int j = 0; j < count; j++) { NameValueData[j] = new NameValueDataBlock(bytes, ref i); } TaskData = new TaskDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RemoveNameValuePairPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; NameValueData = new NameValueDataBlock[count]; for (int j = 0; j < count; j++) { NameValueData[j] = new NameValueDataBlock(bytes, ref i); } TaskData = new TaskDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TaskData.Length;; length++; for (int j = 0; j < NameValueData.Length; j++) { length += NameValueData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)NameValueData.Length; for (int j = 0; j < NameValueData.Length; j++) { NameValueData[j].ToBytes(bytes, ref i); } TaskData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RemoveNameValuePair ---\n"; for (int j = 0; j < NameValueData.Length; j++) { output += NameValueData[j].ToString() + "\n"; } output += TaskData.ToString() + "\n"; return output; } } /// GetNameValuePair packet public class GetNameValuePairPacket : Packet { /// NameValueName block public class NameValueNameBlock { private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (Name != null) { length += 2 + Name.Length; } return length; } } /// Default constructor public NameValueNameBlock() { } /// Constructor for building the block from a byte array public NameValueNameBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)(Name.Length % 256); bytes[i++] = (byte)((Name.Length >> 8) % 256); Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- NameValueName --\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output = output.Trim(); return output; } } /// TaskData block public class TaskDataBlock { /// ID field public LLUUID ID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public TaskDataBlock() { } /// Constructor for building the block from a byte array public TaskDataBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TaskData --\n"; output += "ID: " + ID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GetNameValuePair public override PacketType Type { get { return PacketType.GetNameValuePair; } } /// NameValueName block public NameValueNameBlock[] NameValueName; /// TaskData block public TaskDataBlock TaskData; /// Default constructor public GetNameValuePairPacket() { Header = new LowHeader(); Header.ID = 402; Header.Reliable = true; NameValueName = new NameValueNameBlock[0]; TaskData = new TaskDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GetNameValuePairPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; NameValueName = new NameValueNameBlock[count]; for (int j = 0; j < count; j++) { NameValueName[j] = new NameValueNameBlock(bytes, ref i); } TaskData = new TaskDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GetNameValuePairPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; NameValueName = new NameValueNameBlock[count]; for (int j = 0; j < count; j++) { NameValueName[j] = new NameValueNameBlock(bytes, ref i); } TaskData = new TaskDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TaskData.Length;; length++; for (int j = 0; j < NameValueName.Length; j++) { length += NameValueName[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)NameValueName.Length; for (int j = 0; j < NameValueName.Length; j++) { NameValueName[j].ToBytes(bytes, ref i); } TaskData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GetNameValuePair ---\n"; for (int j = 0; j < NameValueName.Length; j++) { output += NameValueName[j].ToString() + "\n"; } output += TaskData.ToString() + "\n"; return output; } } /// UpdateAttachment packet public class UpdateAttachmentPacket : Packet { /// InventoryData block public class InventoryDataBlock { /// GroupOwned field public bool GroupOwned; /// CRC field public uint CRC; /// CreationDate field public int CreationDate; /// SaleType field public byte SaleType; /// BaseMask field public uint BaseMask; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// InvType field public sbyte InvType; /// Type field public sbyte Type; /// AssetID field public LLUUID AssetID; /// GroupID field public LLUUID GroupID; /// SalePrice field public int SalePrice; /// OwnerID field public LLUUID OwnerID; /// CreatorID field public LLUUID CreatorID; /// ItemID field public LLUUID ItemID; /// FolderID field public LLUUID FolderID; /// EveryoneMask field public uint EveryoneMask; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// Flags field public uint Flags; /// NextOwnerMask field public uint NextOwnerMask; /// GroupMask field public uint GroupMask; /// OwnerMask field public uint OwnerMask; /// Length of this block serialized in bytes public int Length { get { int length = 136; if (Name != null) { length += 1 + Name.Length; } if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public InventoryDataBlock() { } /// Constructor for building the block from a byte array public InventoryDataBlock(byte[] bytes, ref int i) { int length; try { GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; CRC = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CreationDate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SaleType = (byte)bytes[i++]; BaseMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; InvType = (sbyte)bytes[i++]; Type = (sbyte)bytes[i++]; AssetID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerID = new LLUUID(bytes, i); i += 16; CreatorID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; FolderID = new LLUUID(bytes, i); i += 16; EveryoneMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); NextOwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((GroupOwned) ? 1 : 0); bytes[i++] = (byte)(CRC % 256); bytes[i++] = (byte)((CRC >> 8) % 256); bytes[i++] = (byte)((CRC >> 16) % 256); bytes[i++] = (byte)((CRC >> 24) % 256); bytes[i++] = (byte)(CreationDate % 256); bytes[i++] = (byte)((CreationDate >> 8) % 256); bytes[i++] = (byte)((CreationDate >> 16) % 256); bytes[i++] = (byte)((CreationDate >> 24) % 256); bytes[i++] = SaleType; bytes[i++] = (byte)(BaseMask % 256); bytes[i++] = (byte)((BaseMask >> 8) % 256); bytes[i++] = (byte)((BaseMask >> 16) % 256); bytes[i++] = (byte)((BaseMask >> 24) % 256); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)InvType; bytes[i++] = (byte)Type; if(AssetID == null) { Console.WriteLine("Warning: AssetID is null, in " + this.GetType()); } Array.Copy(AssetID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(SalePrice % 256); bytes[i++] = (byte)((SalePrice >> 8) % 256); bytes[i++] = (byte)((SalePrice >> 16) % 256); bytes[i++] = (byte)((SalePrice >> 24) % 256); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(CreatorID == null) { Console.WriteLine("Warning: CreatorID is null, in " + this.GetType()); } Array.Copy(CreatorID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(EveryoneMask % 256); bytes[i++] = (byte)((EveryoneMask >> 8) % 256); bytes[i++] = (byte)((EveryoneMask >> 16) % 256); bytes[i++] = (byte)((EveryoneMask >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); bytes[i++] = (byte)(NextOwnerMask % 256); bytes[i++] = (byte)((NextOwnerMask >> 8) % 256); bytes[i++] = (byte)((NextOwnerMask >> 16) % 256); bytes[i++] = (byte)((NextOwnerMask >> 24) % 256); bytes[i++] = (byte)(GroupMask % 256); bytes[i++] = (byte)((GroupMask >> 8) % 256); bytes[i++] = (byte)((GroupMask >> 16) % 256); bytes[i++] = (byte)((GroupMask >> 24) % 256); bytes[i++] = (byte)(OwnerMask % 256); bytes[i++] = (byte)((OwnerMask >> 8) % 256); bytes[i++] = (byte)((OwnerMask >> 16) % 256); bytes[i++] = (byte)((OwnerMask >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InventoryData --\n"; output += "GroupOwned: " + GroupOwned.ToString() + "\n"; output += "CRC: " + CRC.ToString() + "\n"; output += "CreationDate: " + CreationDate.ToString() + "\n"; output += "SaleType: " + SaleType.ToString() + "\n"; output += "BaseMask: " + BaseMask.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "InvType: " + InvType.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "AssetID: " + AssetID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "SalePrice: " + SalePrice.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "CreatorID: " + CreatorID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output += "EveryoneMask: " + EveryoneMask.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "NextOwnerMask: " + NextOwnerMask.ToString() + "\n"; output += "GroupMask: " + GroupMask.ToString() + "\n"; output += "OwnerMask: " + OwnerMask.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// OperationData block public class OperationDataBlock { /// AddItem field public bool AddItem; /// UseExistingAsset field public bool UseExistingAsset; /// Length of this block serialized in bytes public int Length { get { return 2; } } /// Default constructor public OperationDataBlock() { } /// Constructor for building the block from a byte array public OperationDataBlock(byte[] bytes, ref int i) { try { AddItem = (bytes[i++] != 0) ? (bool)true : (bool)false; UseExistingAsset = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((AddItem) ? 1 : 0); bytes[i++] = (byte)((UseExistingAsset) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- OperationData --\n"; output += "AddItem: " + AddItem.ToString() + "\n"; output += "UseExistingAsset: " + UseExistingAsset.ToString() + "\n"; output = output.Trim(); return output; } } /// AttachmentBlock block public class AttachmentBlockBlock { /// AttachmentPoint field public byte AttachmentPoint; /// Length of this block serialized in bytes public int Length { get { return 1; } } /// Default constructor public AttachmentBlockBlock() { } /// Constructor for building the block from a byte array public AttachmentBlockBlock(byte[] bytes, ref int i) { try { AttachmentPoint = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = AttachmentPoint; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AttachmentBlock --\n"; output += "AttachmentPoint: " + AttachmentPoint.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UpdateAttachment public override PacketType Type { get { return PacketType.UpdateAttachment; } } /// InventoryData block public InventoryDataBlock InventoryData; /// AgentData block public AgentDataBlock AgentData; /// OperationData block public OperationDataBlock OperationData; /// AttachmentBlock block public AttachmentBlockBlock AttachmentBlock; /// Default constructor public UpdateAttachmentPacket() { Header = new LowHeader(); Header.ID = 403; Header.Reliable = true; Header.Zerocoded = true; InventoryData = new InventoryDataBlock(); AgentData = new AgentDataBlock(); OperationData = new OperationDataBlock(); AttachmentBlock = new AttachmentBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UpdateAttachmentPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); InventoryData = new InventoryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); OperationData = new OperationDataBlock(bytes, ref i); AttachmentBlock = new AttachmentBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public UpdateAttachmentPacket(Header head, byte[] bytes, ref int i) { Header = head; InventoryData = new InventoryDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); OperationData = new OperationDataBlock(bytes, ref i); AttachmentBlock = new AttachmentBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += InventoryData.Length; length += AgentData.Length; length += OperationData.Length; length += AttachmentBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); InventoryData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); OperationData.ToBytes(bytes, ref i); AttachmentBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UpdateAttachment ---\n"; output += InventoryData.ToString() + "\n"; output += AgentData.ToString() + "\n"; output += OperationData.ToString() + "\n"; output += AttachmentBlock.ToString() + "\n"; return output; } } /// RemoveAttachment packet public class RemoveAttachmentPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// AttachmentBlock block public class AttachmentBlockBlock { /// AttachmentPoint field public byte AttachmentPoint; /// ItemID field public LLUUID ItemID; /// Length of this block serialized in bytes public int Length { get { return 17; } } /// Default constructor public AttachmentBlockBlock() { } /// Constructor for building the block from a byte array public AttachmentBlockBlock(byte[] bytes, ref int i) { try { AttachmentPoint = (byte)bytes[i++]; ItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = AttachmentPoint; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AttachmentBlock --\n"; output += "AttachmentPoint: " + AttachmentPoint.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RemoveAttachment public override PacketType Type { get { return PacketType.RemoveAttachment; } } /// AgentData block public AgentDataBlock AgentData; /// AttachmentBlock block public AttachmentBlockBlock AttachmentBlock; /// Default constructor public RemoveAttachmentPacket() { Header = new LowHeader(); Header.ID = 404; Header.Reliable = true; AgentData = new AgentDataBlock(); AttachmentBlock = new AttachmentBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RemoveAttachmentPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); AttachmentBlock = new AttachmentBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RemoveAttachmentPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); AttachmentBlock = new AttachmentBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += AttachmentBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); AttachmentBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RemoveAttachment ---\n"; output += AgentData.ToString() + "\n"; output += AttachmentBlock.ToString() + "\n"; return output; } } /// AssetUploadRequest packet public class AssetUploadRequestPacket : Packet { /// AssetBlock block public class AssetBlockBlock { /// Type field public sbyte Type; /// Tempfile field public bool Tempfile; private byte[] _assetdata; /// AssetData field public byte[] AssetData { get { return _assetdata; } set { if (value == null) { _assetdata = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _assetdata = new byte[value.Length]; Array.Copy(value, _assetdata, value.Length); } } } /// TransactionID field public LLUUID TransactionID; /// StoreLocal field public bool StoreLocal; /// Length of this block serialized in bytes public int Length { get { int length = 19; if (AssetData != null) { length += 2 + AssetData.Length; } return length; } } /// Default constructor public AssetBlockBlock() { } /// Constructor for building the block from a byte array public AssetBlockBlock(byte[] bytes, ref int i) { int length; try { Type = (sbyte)bytes[i++]; Tempfile = (bytes[i++] != 0) ? (bool)true : (bool)false; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _assetdata = new byte[length]; Array.Copy(bytes, i, _assetdata, 0, length); i += length; TransactionID = new LLUUID(bytes, i); i += 16; StoreLocal = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)Type; bytes[i++] = (byte)((Tempfile) ? 1 : 0); if(AssetData == null) { Console.WriteLine("Warning: AssetData is null, in " + this.GetType()); } bytes[i++] = (byte)(AssetData.Length % 256); bytes[i++] = (byte)((AssetData.Length >> 8) % 256); Array.Copy(AssetData, 0, bytes, i, AssetData.Length); i += AssetData.Length; if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((StoreLocal) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AssetBlock --\n"; output += "Type: " + Type.ToString() + "\n"; output += "Tempfile: " + Tempfile.ToString() + "\n"; output += Helpers.FieldToString(AssetData, "AssetData") + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output += "StoreLocal: " + StoreLocal.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AssetUploadRequest public override PacketType Type { get { return PacketType.AssetUploadRequest; } } /// AssetBlock block public AssetBlockBlock AssetBlock; /// Default constructor public AssetUploadRequestPacket() { Header = new LowHeader(); Header.ID = 405; Header.Reliable = true; AssetBlock = new AssetBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AssetUploadRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AssetBlock = new AssetBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AssetUploadRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AssetBlock = new AssetBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AssetBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AssetBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AssetUploadRequest ---\n"; output += AssetBlock.ToString() + "\n"; return output; } } /// AssetUploadComplete packet public class AssetUploadCompletePacket : Packet { /// AssetBlock block public class AssetBlockBlock { /// UUID field public LLUUID UUID; /// Success field public bool Success; /// Type field public sbyte Type; /// Length of this block serialized in bytes public int Length { get { return 18; } } /// Default constructor public AssetBlockBlock() { } /// Constructor for building the block from a byte array public AssetBlockBlock(byte[] bytes, ref int i) { try { UUID = new LLUUID(bytes, i); i += 16; Success = (bytes[i++] != 0) ? (bool)true : (bool)false; Type = (sbyte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(UUID == null) { Console.WriteLine("Warning: UUID is null, in " + this.GetType()); } Array.Copy(UUID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((Success) ? 1 : 0); bytes[i++] = (byte)Type; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AssetBlock --\n"; output += "UUID: " + UUID.ToString() + "\n"; output += "Success: " + Success.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AssetUploadComplete public override PacketType Type { get { return PacketType.AssetUploadComplete; } } /// AssetBlock block public AssetBlockBlock AssetBlock; /// Default constructor public AssetUploadCompletePacket() { Header = new LowHeader(); Header.ID = 406; Header.Reliable = true; AssetBlock = new AssetBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AssetUploadCompletePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AssetBlock = new AssetBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AssetUploadCompletePacket(Header head, byte[] bytes, ref int i) { Header = head; AssetBlock = new AssetBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AssetBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AssetBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AssetUploadComplete ---\n"; output += AssetBlock.ToString() + "\n"; return output; } } /// ReputationAgentAssign packet public class ReputationAgentAssignPacket : Packet { /// DataBlock block public class DataBlockBlock { /// RateeID field public LLUUID RateeID; /// RatorID field public LLUUID RatorID; /// Appearance field public float Appearance; /// Behavior field public float Behavior; /// Building field public float Building; /// Length of this block serialized in bytes public int Length { get { return 44; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { try { RateeID = new LLUUID(bytes, i); i += 16; RatorID = new LLUUID(bytes, i); i += 16; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Appearance = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Behavior = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Building = BitConverter.ToSingle(bytes, i); i += 4; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; if(RateeID == null) { Console.WriteLine("Warning: RateeID is null, in " + this.GetType()); } Array.Copy(RateeID.GetBytes(), 0, bytes, i, 16); i += 16; if(RatorID == null) { Console.WriteLine("Warning: RatorID is null, in " + this.GetType()); } Array.Copy(RatorID.GetBytes(), 0, bytes, i, 16); i += 16; ba = BitConverter.GetBytes(Appearance); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(Behavior); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(Building); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "RateeID: " + RateeID.ToString() + "\n"; output += "RatorID: " + RatorID.ToString() + "\n"; output += "Appearance: " + Appearance.ToString() + "\n"; output += "Behavior: " + Behavior.ToString() + "\n"; output += "Building: " + Building.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ReputationAgentAssign public override PacketType Type { get { return PacketType.ReputationAgentAssign; } } /// DataBlock block public DataBlockBlock DataBlock; /// Default constructor public ReputationAgentAssignPacket() { Header = new LowHeader(); Header.ID = 407; Header.Reliable = true; DataBlock = new DataBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ReputationAgentAssignPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); DataBlock = new DataBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ReputationAgentAssignPacket(Header head, byte[] bytes, ref int i) { Header = head; DataBlock = new DataBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += DataBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ReputationAgentAssign ---\n"; output += DataBlock.ToString() + "\n"; return output; } } /// ReputationIndividualRequest packet public class ReputationIndividualRequestPacket : Packet { /// ReputationData block public class ReputationDataBlock { /// ToID field public LLUUID ToID; /// FromID field public LLUUID FromID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public ReputationDataBlock() { } /// Constructor for building the block from a byte array public ReputationDataBlock(byte[] bytes, ref int i) { try { ToID = new LLUUID(bytes, i); i += 16; FromID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ToID == null) { Console.WriteLine("Warning: ToID is null, in " + this.GetType()); } Array.Copy(ToID.GetBytes(), 0, bytes, i, 16); i += 16; if(FromID == null) { Console.WriteLine("Warning: FromID is null, in " + this.GetType()); } Array.Copy(FromID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ReputationData --\n"; output += "ToID: " + ToID.ToString() + "\n"; output += "FromID: " + FromID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ReputationIndividualRequest public override PacketType Type { get { return PacketType.ReputationIndividualRequest; } } /// ReputationData block public ReputationDataBlock ReputationData; /// Default constructor public ReputationIndividualRequestPacket() { Header = new LowHeader(); Header.ID = 408; Header.Reliable = true; ReputationData = new ReputationDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ReputationIndividualRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ReputationData = new ReputationDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ReputationIndividualRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; ReputationData = new ReputationDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ReputationData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ReputationData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ReputationIndividualRequest ---\n"; output += ReputationData.ToString() + "\n"; return output; } } /// ReputationIndividualReply packet public class ReputationIndividualReplyPacket : Packet { /// ReputationData block public class ReputationDataBlock { /// Appearance field public float Appearance; /// ToID field public LLUUID ToID; /// Behavior field public float Behavior; /// FromID field public LLUUID FromID; /// Building field public float Building; /// Length of this block serialized in bytes public int Length { get { return 44; } } /// Default constructor public ReputationDataBlock() { } /// Constructor for building the block from a byte array public ReputationDataBlock(byte[] bytes, ref int i) { try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Appearance = BitConverter.ToSingle(bytes, i); i += 4; ToID = new LLUUID(bytes, i); i += 16; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Behavior = BitConverter.ToSingle(bytes, i); i += 4; FromID = new LLUUID(bytes, i); i += 16; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Building = BitConverter.ToSingle(bytes, i); i += 4; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(Appearance); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(ToID == null) { Console.WriteLine("Warning: ToID is null, in " + this.GetType()); } Array.Copy(ToID.GetBytes(), 0, bytes, i, 16); i += 16; ba = BitConverter.GetBytes(Behavior); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(FromID == null) { Console.WriteLine("Warning: FromID is null, in " + this.GetType()); } Array.Copy(FromID.GetBytes(), 0, bytes, i, 16); i += 16; ba = BitConverter.GetBytes(Building); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ReputationData --\n"; output += "Appearance: " + Appearance.ToString() + "\n"; output += "ToID: " + ToID.ToString() + "\n"; output += "Behavior: " + Behavior.ToString() + "\n"; output += "FromID: " + FromID.ToString() + "\n"; output += "Building: " + Building.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ReputationIndividualReply public override PacketType Type { get { return PacketType.ReputationIndividualReply; } } /// ReputationData block public ReputationDataBlock ReputationData; /// Default constructor public ReputationIndividualReplyPacket() { Header = new LowHeader(); Header.ID = 409; Header.Reliable = true; ReputationData = new ReputationDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ReputationIndividualReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ReputationData = new ReputationDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ReputationIndividualReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; ReputationData = new ReputationDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ReputationData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ReputationData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ReputationIndividualReply ---\n"; output += ReputationData.ToString() + "\n"; return output; } } /// EmailMessageRequest packet public class EmailMessageRequestPacket : Packet { /// DataBlock block public class DataBlockBlock { /// ObjectID field public LLUUID ObjectID; private byte[] _subject; /// Subject field public byte[] Subject { get { return _subject; } set { if (value == null) { _subject = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _subject = new byte[value.Length]; Array.Copy(value, _subject, value.Length); } } } private byte[] _fromaddress; /// FromAddress field public byte[] FromAddress { get { return _fromaddress; } set { if (value == null) { _fromaddress = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _fromaddress = new byte[value.Length]; Array.Copy(value, _fromaddress, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 16; if (Subject != null) { length += 1 + Subject.Length; } if (FromAddress != null) { length += 1 + FromAddress.Length; } return length; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { int length; try { ObjectID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _subject = new byte[length]; Array.Copy(bytes, i, _subject, 0, length); i += length; length = (ushort)bytes[i++]; _fromaddress = new byte[length]; Array.Copy(bytes, i, _fromaddress, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; if(Subject == null) { Console.WriteLine("Warning: Subject is null, in " + this.GetType()); } bytes[i++] = (byte)Subject.Length; Array.Copy(Subject, 0, bytes, i, Subject.Length); i += Subject.Length; if(FromAddress == null) { Console.WriteLine("Warning: FromAddress is null, in " + this.GetType()); } bytes[i++] = (byte)FromAddress.Length; Array.Copy(FromAddress, 0, bytes, i, FromAddress.Length); i += FromAddress.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += Helpers.FieldToString(Subject, "Subject") + "\n"; output += Helpers.FieldToString(FromAddress, "FromAddress") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.EmailMessageRequest public override PacketType Type { get { return PacketType.EmailMessageRequest; } } /// DataBlock block public DataBlockBlock DataBlock; /// Default constructor public EmailMessageRequestPacket() { Header = new LowHeader(); Header.ID = 410; Header.Reliable = true; DataBlock = new DataBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public EmailMessageRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); DataBlock = new DataBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public EmailMessageRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; DataBlock = new DataBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += DataBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- EmailMessageRequest ---\n"; output += DataBlock.ToString() + "\n"; return output; } } /// EmailMessageReply packet public class EmailMessageReplyPacket : Packet { /// DataBlock block public class DataBlockBlock { /// ObjectID field public LLUUID ObjectID; private byte[] _data; /// Data field public byte[] Data { get { return _data; } set { if (value == null) { _data = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _data = new byte[value.Length]; Array.Copy(value, _data, value.Length); } } } private byte[] _subject; /// Subject field public byte[] Subject { get { return _subject; } set { if (value == null) { _subject = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _subject = new byte[value.Length]; Array.Copy(value, _subject, value.Length); } } } /// Time field public uint Time; private byte[] _fromaddress; /// FromAddress field public byte[] FromAddress { get { return _fromaddress; } set { if (value == null) { _fromaddress = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _fromaddress = new byte[value.Length]; Array.Copy(value, _fromaddress, value.Length); } } } /// More field public uint More; private byte[] _mailfilter; /// MailFilter field public byte[] MailFilter { get { return _mailfilter; } set { if (value == null) { _mailfilter = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _mailfilter = new byte[value.Length]; Array.Copy(value, _mailfilter, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 24; if (Data != null) { length += 2 + Data.Length; } if (Subject != null) { length += 1 + Subject.Length; } if (FromAddress != null) { length += 1 + FromAddress.Length; } if (MailFilter != null) { length += 1 + MailFilter.Length; } return length; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { int length; try { ObjectID = new LLUUID(bytes, i); i += 16; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _data = new byte[length]; Array.Copy(bytes, i, _data, 0, length); i += length; length = (ushort)bytes[i++]; _subject = new byte[length]; Array.Copy(bytes, i, _subject, 0, length); i += length; Time = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _fromaddress = new byte[length]; Array.Copy(bytes, i, _fromaddress, 0, length); i += length; More = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _mailfilter = new byte[length]; Array.Copy(bytes, i, _mailfilter, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; if(Data == null) { Console.WriteLine("Warning: Data is null, in " + this.GetType()); } bytes[i++] = (byte)(Data.Length % 256); bytes[i++] = (byte)((Data.Length >> 8) % 256); Array.Copy(Data, 0, bytes, i, Data.Length); i += Data.Length; if(Subject == null) { Console.WriteLine("Warning: Subject is null, in " + this.GetType()); } bytes[i++] = (byte)Subject.Length; Array.Copy(Subject, 0, bytes, i, Subject.Length); i += Subject.Length; bytes[i++] = (byte)(Time % 256); bytes[i++] = (byte)((Time >> 8) % 256); bytes[i++] = (byte)((Time >> 16) % 256); bytes[i++] = (byte)((Time >> 24) % 256); if(FromAddress == null) { Console.WriteLine("Warning: FromAddress is null, in " + this.GetType()); } bytes[i++] = (byte)FromAddress.Length; Array.Copy(FromAddress, 0, bytes, i, FromAddress.Length); i += FromAddress.Length; bytes[i++] = (byte)(More % 256); bytes[i++] = (byte)((More >> 8) % 256); bytes[i++] = (byte)((More >> 16) % 256); bytes[i++] = (byte)((More >> 24) % 256); if(MailFilter == null) { Console.WriteLine("Warning: MailFilter is null, in " + this.GetType()); } bytes[i++] = (byte)MailFilter.Length; Array.Copy(MailFilter, 0, bytes, i, MailFilter.Length); i += MailFilter.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += Helpers.FieldToString(Data, "Data") + "\n"; output += Helpers.FieldToString(Subject, "Subject") + "\n"; output += "Time: " + Time.ToString() + "\n"; output += Helpers.FieldToString(FromAddress, "FromAddress") + "\n"; output += "More: " + More.ToString() + "\n"; output += Helpers.FieldToString(MailFilter, "MailFilter") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.EmailMessageReply public override PacketType Type { get { return PacketType.EmailMessageReply; } } /// DataBlock block public DataBlockBlock DataBlock; /// Default constructor public EmailMessageReplyPacket() { Header = new LowHeader(); Header.ID = 411; Header.Reliable = true; DataBlock = new DataBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public EmailMessageReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); DataBlock = new DataBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public EmailMessageReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; DataBlock = new DataBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += DataBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- EmailMessageReply ---\n"; output += DataBlock.ToString() + "\n"; return output; } } /// ScriptDataRequest packet public class ScriptDataRequestPacket : Packet { /// DataBlock block public class DataBlockBlock { /// RequestType field public sbyte RequestType; private byte[] _request; /// Request field public byte[] Request { get { return _request; } set { if (value == null) { _request = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _request = new byte[value.Length]; Array.Copy(value, _request, value.Length); } } } /// Hash field public ulong Hash; /// Length of this block serialized in bytes public int Length { get { int length = 9; if (Request != null) { length += 2 + Request.Length; } return length; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { int length; try { RequestType = (sbyte)bytes[i++]; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _request = new byte[length]; Array.Copy(bytes, i, _request, 0, length); i += length; Hash = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)RequestType; if(Request == null) { Console.WriteLine("Warning: Request is null, in " + this.GetType()); } bytes[i++] = (byte)(Request.Length % 256); bytes[i++] = (byte)((Request.Length >> 8) % 256); Array.Copy(Request, 0, bytes, i, Request.Length); i += Request.Length; bytes[i++] = (byte)(Hash % 256); bytes[i++] = (byte)((Hash >> 8) % 256); bytes[i++] = (byte)((Hash >> 16) % 256); bytes[i++] = (byte)((Hash >> 24) % 256); bytes[i++] = (byte)((Hash >> 32) % 256); bytes[i++] = (byte)((Hash >> 40) % 256); bytes[i++] = (byte)((Hash >> 48) % 256); bytes[i++] = (byte)((Hash >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "RequestType: " + RequestType.ToString() + "\n"; output += Helpers.FieldToString(Request, "Request") + "\n"; output += "Hash: " + Hash.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ScriptDataRequest public override PacketType Type { get { return PacketType.ScriptDataRequest; } } /// DataBlock block public DataBlockBlock[] DataBlock; /// Default constructor public ScriptDataRequestPacket() { Header = new LowHeader(); Header.ID = 412; Header.Reliable = true; DataBlock = new DataBlockBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ScriptDataRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; DataBlock = new DataBlockBlock[count]; for (int j = 0; j < count; j++) { DataBlock[j] = new DataBlockBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public ScriptDataRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; DataBlock = new DataBlockBlock[count]; for (int j = 0; j < count; j++) { DataBlock[j] = new DataBlockBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < DataBlock.Length; j++) { length += DataBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)DataBlock.Length; for (int j = 0; j < DataBlock.Length; j++) { DataBlock[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ScriptDataRequest ---\n"; for (int j = 0; j < DataBlock.Length; j++) { output += DataBlock[j].ToString() + "\n"; } return output; } } /// ScriptDataReply packet public class ScriptDataReplyPacket : Packet { /// DataBlock block public class DataBlockBlock { /// Hash field public ulong Hash; private byte[] _reply; /// Reply field public byte[] Reply { get { return _reply; } set { if (value == null) { _reply = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _reply = new byte[value.Length]; Array.Copy(value, _reply, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 8; if (Reply != null) { length += 2 + Reply.Length; } return length; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { int length; try { Hash = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _reply = new byte[length]; Array.Copy(bytes, i, _reply, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Hash % 256); bytes[i++] = (byte)((Hash >> 8) % 256); bytes[i++] = (byte)((Hash >> 16) % 256); bytes[i++] = (byte)((Hash >> 24) % 256); bytes[i++] = (byte)((Hash >> 32) % 256); bytes[i++] = (byte)((Hash >> 40) % 256); bytes[i++] = (byte)((Hash >> 48) % 256); bytes[i++] = (byte)((Hash >> 56) % 256); if(Reply == null) { Console.WriteLine("Warning: Reply is null, in " + this.GetType()); } bytes[i++] = (byte)(Reply.Length % 256); bytes[i++] = (byte)((Reply.Length >> 8) % 256); Array.Copy(Reply, 0, bytes, i, Reply.Length); i += Reply.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "Hash: " + Hash.ToString() + "\n"; output += Helpers.FieldToString(Reply, "Reply") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ScriptDataReply public override PacketType Type { get { return PacketType.ScriptDataReply; } } /// DataBlock block public DataBlockBlock[] DataBlock; /// Default constructor public ScriptDataReplyPacket() { Header = new LowHeader(); Header.ID = 413; Header.Reliable = true; DataBlock = new DataBlockBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ScriptDataReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; DataBlock = new DataBlockBlock[count]; for (int j = 0; j < count; j++) { DataBlock[j] = new DataBlockBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public ScriptDataReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; DataBlock = new DataBlockBlock[count]; for (int j = 0; j < count; j++) { DataBlock[j] = new DataBlockBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < DataBlock.Length; j++) { length += DataBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)DataBlock.Length; for (int j = 0; j < DataBlock.Length; j++) { DataBlock[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ScriptDataReply ---\n"; for (int j = 0; j < DataBlock.Length; j++) { output += DataBlock[j].ToString() + "\n"; } return output; } } /// CreateGroupRequest packet public class CreateGroupRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// AllowPublish field public bool AllowPublish; private byte[] _charter; /// Charter field public byte[] Charter { get { return _charter; } set { if (value == null) { _charter = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _charter = new byte[value.Length]; Array.Copy(value, _charter, value.Length); } } } /// ShowInList field public bool ShowInList; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// InsigniaID field public LLUUID InsigniaID; /// MembershipFee field public int MembershipFee; /// MaturePublish field public bool MaturePublish; /// OpenEnrollment field public bool OpenEnrollment; /// Length of this block serialized in bytes public int Length { get { int length = 24; if (Charter != null) { length += 2 + Charter.Length; } if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { int length; try { AllowPublish = (bytes[i++] != 0) ? (bool)true : (bool)false; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _charter = new byte[length]; Array.Copy(bytes, i, _charter, 0, length); i += length; ShowInList = (bytes[i++] != 0) ? (bool)true : (bool)false; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; InsigniaID = new LLUUID(bytes, i); i += 16; MembershipFee = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); MaturePublish = (bytes[i++] != 0) ? (bool)true : (bool)false; OpenEnrollment = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((AllowPublish) ? 1 : 0); if(Charter == null) { Console.WriteLine("Warning: Charter is null, in " + this.GetType()); } bytes[i++] = (byte)(Charter.Length % 256); bytes[i++] = (byte)((Charter.Length >> 8) % 256); Array.Copy(Charter, 0, bytes, i, Charter.Length); i += Charter.Length; bytes[i++] = (byte)((ShowInList) ? 1 : 0); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(InsigniaID == null) { Console.WriteLine("Warning: InsigniaID is null, in " + this.GetType()); } Array.Copy(InsigniaID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(MembershipFee % 256); bytes[i++] = (byte)((MembershipFee >> 8) % 256); bytes[i++] = (byte)((MembershipFee >> 16) % 256); bytes[i++] = (byte)((MembershipFee >> 24) % 256); bytes[i++] = (byte)((MaturePublish) ? 1 : 0); bytes[i++] = (byte)((OpenEnrollment) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "AllowPublish: " + AllowPublish.ToString() + "\n"; output += Helpers.FieldToString(Charter, "Charter") + "\n"; output += "ShowInList: " + ShowInList.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "InsigniaID: " + InsigniaID.ToString() + "\n"; output += "MembershipFee: " + MembershipFee.ToString() + "\n"; output += "MaturePublish: " + MaturePublish.ToString() + "\n"; output += "OpenEnrollment: " + OpenEnrollment.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.CreateGroupRequest public override PacketType Type { get { return PacketType.CreateGroupRequest; } } /// AgentData block public AgentDataBlock AgentData; /// GroupData block public GroupDataBlock GroupData; /// Default constructor public CreateGroupRequestPacket() { Header = new LowHeader(); Header.ID = 414; Header.Reliable = true; Header.Zerocoded = true; AgentData = new AgentDataBlock(); GroupData = new GroupDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public CreateGroupRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public CreateGroupRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += GroupData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); GroupData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- CreateGroupRequest ---\n"; output += AgentData.ToString() + "\n"; output += GroupData.ToString() + "\n"; return output; } } /// CreateGroupReply packet public class CreateGroupReplyPacket : Packet { /// ReplyData block public class ReplyDataBlock { private byte[] _message; /// Message field public byte[] Message { get { return _message; } set { if (value == null) { _message = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _message = new byte[value.Length]; Array.Copy(value, _message, value.Length); } } } /// Success field public bool Success; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { int length = 17; if (Message != null) { length += 1 + Message.Length; } return length; } } /// Default constructor public ReplyDataBlock() { } /// Constructor for building the block from a byte array public ReplyDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _message = new byte[length]; Array.Copy(bytes, i, _message, 0, length); i += length; Success = (bytes[i++] != 0) ? (bool)true : (bool)false; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Message == null) { Console.WriteLine("Warning: Message is null, in " + this.GetType()); } bytes[i++] = (byte)Message.Length; Array.Copy(Message, 0, bytes, i, Message.Length); i += Message.Length; bytes[i++] = (byte)((Success) ? 1 : 0); if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ReplyData --\n"; output += Helpers.FieldToString(Message, "Message") + "\n"; output += "Success: " + Success.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.CreateGroupReply public override PacketType Type { get { return PacketType.CreateGroupReply; } } /// ReplyData block public ReplyDataBlock ReplyData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public CreateGroupReplyPacket() { Header = new LowHeader(); Header.ID = 415; Header.Reliable = true; ReplyData = new ReplyDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public CreateGroupReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ReplyData = new ReplyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public CreateGroupReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; ReplyData = new ReplyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ReplyData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ReplyData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- CreateGroupReply ---\n"; output += ReplyData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// UpdateGroupInfo packet public class UpdateGroupInfoPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// AllowPublish field public bool AllowPublish; private byte[] _charter; /// Charter field public byte[] Charter { get { return _charter; } set { if (value == null) { _charter = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _charter = new byte[value.Length]; Array.Copy(value, _charter, value.Length); } } } /// ShowInList field public bool ShowInList; /// InsigniaID field public LLUUID InsigniaID; /// GroupID field public LLUUID GroupID; /// MembershipFee field public int MembershipFee; /// MaturePublish field public bool MaturePublish; /// OpenEnrollment field public bool OpenEnrollment; /// Length of this block serialized in bytes public int Length { get { int length = 40; if (Charter != null) { length += 2 + Charter.Length; } return length; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { int length; try { AllowPublish = (bytes[i++] != 0) ? (bool)true : (bool)false; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _charter = new byte[length]; Array.Copy(bytes, i, _charter, 0, length); i += length; ShowInList = (bytes[i++] != 0) ? (bool)true : (bool)false; InsigniaID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; MembershipFee = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); MaturePublish = (bytes[i++] != 0) ? (bool)true : (bool)false; OpenEnrollment = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((AllowPublish) ? 1 : 0); if(Charter == null) { Console.WriteLine("Warning: Charter is null, in " + this.GetType()); } bytes[i++] = (byte)(Charter.Length % 256); bytes[i++] = (byte)((Charter.Length >> 8) % 256); Array.Copy(Charter, 0, bytes, i, Charter.Length); i += Charter.Length; bytes[i++] = (byte)((ShowInList) ? 1 : 0); if(InsigniaID == null) { Console.WriteLine("Warning: InsigniaID is null, in " + this.GetType()); } Array.Copy(InsigniaID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(MembershipFee % 256); bytes[i++] = (byte)((MembershipFee >> 8) % 256); bytes[i++] = (byte)((MembershipFee >> 16) % 256); bytes[i++] = (byte)((MembershipFee >> 24) % 256); bytes[i++] = (byte)((MaturePublish) ? 1 : 0); bytes[i++] = (byte)((OpenEnrollment) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "AllowPublish: " + AllowPublish.ToString() + "\n"; output += Helpers.FieldToString(Charter, "Charter") + "\n"; output += "ShowInList: " + ShowInList.ToString() + "\n"; output += "InsigniaID: " + InsigniaID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "MembershipFee: " + MembershipFee.ToString() + "\n"; output += "MaturePublish: " + MaturePublish.ToString() + "\n"; output += "OpenEnrollment: " + OpenEnrollment.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UpdateGroupInfo public override PacketType Type { get { return PacketType.UpdateGroupInfo; } } /// AgentData block public AgentDataBlock AgentData; /// GroupData block public GroupDataBlock GroupData; /// Default constructor public UpdateGroupInfoPacket() { Header = new LowHeader(); Header.ID = 416; Header.Reliable = true; Header.Zerocoded = true; AgentData = new AgentDataBlock(); GroupData = new GroupDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UpdateGroupInfoPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public UpdateGroupInfoPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += GroupData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); GroupData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UpdateGroupInfo ---\n"; output += AgentData.ToString() + "\n"; output += GroupData.ToString() + "\n"; return output; } } /// GroupRoleChanges packet public class GroupRoleChangesPacket : Packet { /// RoleChange block public class RoleChangeBlock { /// MemberID field public LLUUID MemberID; /// Change field public uint Change; /// RoleID field public LLUUID RoleID; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public RoleChangeBlock() { } /// Constructor for building the block from a byte array public RoleChangeBlock(byte[] bytes, ref int i) { try { MemberID = new LLUUID(bytes, i); i += 16; Change = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RoleID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(MemberID == null) { Console.WriteLine("Warning: MemberID is null, in " + this.GetType()); } Array.Copy(MemberID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Change % 256); bytes[i++] = (byte)((Change >> 8) % 256); bytes[i++] = (byte)((Change >> 16) % 256); bytes[i++] = (byte)((Change >> 24) % 256); if(RoleID == null) { Console.WriteLine("Warning: RoleID is null, in " + this.GetType()); } Array.Copy(RoleID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RoleChange --\n"; output += "MemberID: " + MemberID.ToString() + "\n"; output += "Change: " + Change.ToString() + "\n"; output += "RoleID: " + RoleID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupRoleChanges public override PacketType Type { get { return PacketType.GroupRoleChanges; } } /// RoleChange block public RoleChangeBlock[] RoleChange; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GroupRoleChangesPacket() { Header = new LowHeader(); Header.ID = 417; Header.Reliable = true; RoleChange = new RoleChangeBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupRoleChangesPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; RoleChange = new RoleChangeBlock[count]; for (int j = 0; j < count; j++) { RoleChange[j] = new RoleChangeBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupRoleChangesPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; RoleChange = new RoleChangeBlock[count]; for (int j = 0; j < count; j++) { RoleChange[j] = new RoleChangeBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < RoleChange.Length; j++) { length += RoleChange[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)RoleChange.Length; for (int j = 0; j < RoleChange.Length; j++) { RoleChange[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupRoleChanges ---\n"; for (int j = 0; j < RoleChange.Length; j++) { output += RoleChange[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// JoinGroupRequest packet public class JoinGroupRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { try { GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.JoinGroupRequest public override PacketType Type { get { return PacketType.JoinGroupRequest; } } /// AgentData block public AgentDataBlock AgentData; /// GroupData block public GroupDataBlock GroupData; /// Default constructor public JoinGroupRequestPacket() { Header = new LowHeader(); Header.ID = 418; Header.Reliable = true; Header.Zerocoded = true; AgentData = new AgentDataBlock(); GroupData = new GroupDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public JoinGroupRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public JoinGroupRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += GroupData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); GroupData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- JoinGroupRequest ---\n"; output += AgentData.ToString() + "\n"; output += GroupData.ToString() + "\n"; return output; } } /// JoinGroupReply packet public class JoinGroupReplyPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// Success field public bool Success; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 17; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { try { Success = (bytes[i++] != 0) ? (bool)true : (bool)false; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((Success) ? 1 : 0); if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "Success: " + Success.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.JoinGroupReply public override PacketType Type { get { return PacketType.JoinGroupReply; } } /// AgentData block public AgentDataBlock AgentData; /// GroupData block public GroupDataBlock GroupData; /// Default constructor public JoinGroupReplyPacket() { Header = new LowHeader(); Header.ID = 419; Header.Reliable = true; AgentData = new AgentDataBlock(); GroupData = new GroupDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public JoinGroupReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public JoinGroupReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += GroupData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); GroupData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- JoinGroupReply ---\n"; output += AgentData.ToString() + "\n"; output += GroupData.ToString() + "\n"; return output; } } /// EjectGroupMemberRequest packet public class EjectGroupMemberRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// EjectData block public class EjectDataBlock { /// EjecteeID field public LLUUID EjecteeID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public EjectDataBlock() { } /// Constructor for building the block from a byte array public EjectDataBlock(byte[] bytes, ref int i) { try { EjecteeID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(EjecteeID == null) { Console.WriteLine("Warning: EjecteeID is null, in " + this.GetType()); } Array.Copy(EjecteeID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- EjectData --\n"; output += "EjecteeID: " + EjecteeID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { try { GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.EjectGroupMemberRequest public override PacketType Type { get { return PacketType.EjectGroupMemberRequest; } } /// AgentData block public AgentDataBlock AgentData; /// EjectData block public EjectDataBlock[] EjectData; /// GroupData block public GroupDataBlock GroupData; /// Default constructor public EjectGroupMemberRequestPacket() { Header = new LowHeader(); Header.ID = 420; Header.Reliable = true; AgentData = new AgentDataBlock(); EjectData = new EjectDataBlock[0]; GroupData = new GroupDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public EjectGroupMemberRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); int count = (int)bytes[i++]; EjectData = new EjectDataBlock[count]; for (int j = 0; j < count; j++) { EjectData[j] = new EjectDataBlock(bytes, ref i); } GroupData = new GroupDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public EjectGroupMemberRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); int count = (int)bytes[i++]; EjectData = new EjectDataBlock[count]; for (int j = 0; j < count; j++) { EjectData[j] = new EjectDataBlock(bytes, ref i); } GroupData = new GroupDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += GroupData.Length;; length++; for (int j = 0; j < EjectData.Length; j++) { length += EjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); bytes[i++] = (byte)EjectData.Length; for (int j = 0; j < EjectData.Length; j++) { EjectData[j].ToBytes(bytes, ref i); } GroupData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- EjectGroupMemberRequest ---\n"; output += AgentData.ToString() + "\n"; for (int j = 0; j < EjectData.Length; j++) { output += EjectData[j].ToString() + "\n"; } output += GroupData.ToString() + "\n"; return output; } } /// EjectGroupMemberReply packet public class EjectGroupMemberReplyPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } /// EjectData block public class EjectDataBlock { /// Success field public bool Success; /// Length of this block serialized in bytes public int Length { get { return 1; } } /// Default constructor public EjectDataBlock() { } /// Constructor for building the block from a byte array public EjectDataBlock(byte[] bytes, ref int i) { try { Success = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((Success) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- EjectData --\n"; output += "Success: " + Success.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { try { GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.EjectGroupMemberReply public override PacketType Type { get { return PacketType.EjectGroupMemberReply; } } /// AgentData block public AgentDataBlock AgentData; /// EjectData block public EjectDataBlock EjectData; /// GroupData block public GroupDataBlock GroupData; /// Default constructor public EjectGroupMemberReplyPacket() { Header = new LowHeader(); Header.ID = 421; Header.Reliable = true; AgentData = new AgentDataBlock(); EjectData = new EjectDataBlock(); GroupData = new GroupDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public EjectGroupMemberReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); EjectData = new EjectDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public EjectGroupMemberReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); EjectData = new EjectDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += EjectData.Length; length += GroupData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); EjectData.ToBytes(bytes, ref i); GroupData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- EjectGroupMemberReply ---\n"; output += AgentData.ToString() + "\n"; output += EjectData.ToString() + "\n"; output += GroupData.ToString() + "\n"; return output; } } /// LeaveGroupRequest packet public class LeaveGroupRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { try { GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.LeaveGroupRequest public override PacketType Type { get { return PacketType.LeaveGroupRequest; } } /// AgentData block public AgentDataBlock AgentData; /// GroupData block public GroupDataBlock GroupData; /// Default constructor public LeaveGroupRequestPacket() { Header = new LowHeader(); Header.ID = 422; Header.Reliable = true; AgentData = new AgentDataBlock(); GroupData = new GroupDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public LeaveGroupRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public LeaveGroupRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += GroupData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); GroupData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- LeaveGroupRequest ---\n"; output += AgentData.ToString() + "\n"; output += GroupData.ToString() + "\n"; return output; } } /// LeaveGroupReply packet public class LeaveGroupReplyPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// Success field public bool Success; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 17; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { try { Success = (bytes[i++] != 0) ? (bool)true : (bool)false; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((Success) ? 1 : 0); if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "Success: " + Success.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.LeaveGroupReply public override PacketType Type { get { return PacketType.LeaveGroupReply; } } /// AgentData block public AgentDataBlock AgentData; /// GroupData block public GroupDataBlock GroupData; /// Default constructor public LeaveGroupReplyPacket() { Header = new LowHeader(); Header.ID = 423; Header.Reliable = true; AgentData = new AgentDataBlock(); GroupData = new GroupDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public LeaveGroupReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public LeaveGroupReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += GroupData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); GroupData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- LeaveGroupReply ---\n"; output += AgentData.ToString() + "\n"; output += GroupData.ToString() + "\n"; return output; } } /// InviteGroupRequest packet public class InviteGroupRequestPacket : Packet { /// InviteData block public class InviteDataBlock { /// RoleID field public LLUUID RoleID; /// InviteeID field public LLUUID InviteeID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public InviteDataBlock() { } /// Constructor for building the block from a byte array public InviteDataBlock(byte[] bytes, ref int i) { try { RoleID = new LLUUID(bytes, i); i += 16; InviteeID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RoleID == null) { Console.WriteLine("Warning: RoleID is null, in " + this.GetType()); } Array.Copy(RoleID.GetBytes(), 0, bytes, i, 16); i += 16; if(InviteeID == null) { Console.WriteLine("Warning: InviteeID is null, in " + this.GetType()); } Array.Copy(InviteeID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InviteData --\n"; output += "RoleID: " + RoleID.ToString() + "\n"; output += "InviteeID: " + InviteeID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { try { GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.InviteGroupRequest public override PacketType Type { get { return PacketType.InviteGroupRequest; } } /// InviteData block public InviteDataBlock[] InviteData; /// AgentData block public AgentDataBlock AgentData; /// GroupData block public GroupDataBlock GroupData; /// Default constructor public InviteGroupRequestPacket() { Header = new LowHeader(); Header.ID = 424; Header.Reliable = true; InviteData = new InviteDataBlock[0]; AgentData = new AgentDataBlock(); GroupData = new GroupDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public InviteGroupRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; InviteData = new InviteDataBlock[count]; for (int j = 0; j < count; j++) { InviteData[j] = new InviteDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public InviteGroupRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; InviteData = new InviteDataBlock[count]; for (int j = 0; j < count; j++) { InviteData[j] = new InviteDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += GroupData.Length;; length++; for (int j = 0; j < InviteData.Length; j++) { length += InviteData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)InviteData.Length; for (int j = 0; j < InviteData.Length; j++) { InviteData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); GroupData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- InviteGroupRequest ---\n"; for (int j = 0; j < InviteData.Length; j++) { output += InviteData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; output += GroupData.ToString() + "\n"; return output; } } /// InviteGroupResponse packet public class InviteGroupResponsePacket : Packet { /// InviteData block public class InviteDataBlock { /// AgentID field public LLUUID AgentID; /// GroupID field public LLUUID GroupID; /// MembershipFee field public int MembershipFee; /// RoleID field public LLUUID RoleID; /// InviteeID field public LLUUID InviteeID; /// Length of this block serialized in bytes public int Length { get { return 68; } } /// Default constructor public InviteDataBlock() { } /// Constructor for building the block from a byte array public InviteDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; MembershipFee = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RoleID = new LLUUID(bytes, i); i += 16; InviteeID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(MembershipFee % 256); bytes[i++] = (byte)((MembershipFee >> 8) % 256); bytes[i++] = (byte)((MembershipFee >> 16) % 256); bytes[i++] = (byte)((MembershipFee >> 24) % 256); if(RoleID == null) { Console.WriteLine("Warning: RoleID is null, in " + this.GetType()); } Array.Copy(RoleID.GetBytes(), 0, bytes, i, 16); i += 16; if(InviteeID == null) { Console.WriteLine("Warning: InviteeID is null, in " + this.GetType()); } Array.Copy(InviteeID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- InviteData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "MembershipFee: " + MembershipFee.ToString() + "\n"; output += "RoleID: " + RoleID.ToString() + "\n"; output += "InviteeID: " + InviteeID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.InviteGroupResponse public override PacketType Type { get { return PacketType.InviteGroupResponse; } } /// InviteData block public InviteDataBlock InviteData; /// Default constructor public InviteGroupResponsePacket() { Header = new LowHeader(); Header.ID = 425; Header.Reliable = true; InviteData = new InviteDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public InviteGroupResponsePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); InviteData = new InviteDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public InviteGroupResponsePacket(Header head, byte[] bytes, ref int i) { Header = head; InviteData = new InviteDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += InviteData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); InviteData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- InviteGroupResponse ---\n"; output += InviteData.ToString() + "\n"; return output; } } /// GroupProfileRequest packet public class GroupProfileRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { try { GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupProfileRequest public override PacketType Type { get { return PacketType.GroupProfileRequest; } } /// AgentData block public AgentDataBlock AgentData; /// GroupData block public GroupDataBlock GroupData; /// Default constructor public GroupProfileRequestPacket() { Header = new LowHeader(); Header.ID = 426; Header.Reliable = true; AgentData = new AgentDataBlock(); GroupData = new GroupDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupProfileRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupProfileRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += GroupData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); GroupData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupProfileRequest ---\n"; output += AgentData.ToString() + "\n"; output += GroupData.ToString() + "\n"; return output; } } /// GroupProfileReply packet public class GroupProfileReplyPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// OwnerRole field public LLUUID OwnerRole; /// AllowPublish field public bool AllowPublish; private byte[] _charter; /// Charter field public byte[] Charter { get { return _charter; } set { if (value == null) { _charter = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _charter = new byte[value.Length]; Array.Copy(value, _charter, value.Length); } } } /// GroupMembershipCount field public int GroupMembershipCount; /// ShowInList field public bool ShowInList; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } private byte[] _membertitle; /// MemberTitle field public byte[] MemberTitle { get { return _membertitle; } set { if (value == null) { _membertitle = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _membertitle = new byte[value.Length]; Array.Copy(value, _membertitle, value.Length); } } } /// InsigniaID field public LLUUID InsigniaID; /// GroupRolesCount field public int GroupRolesCount; /// GroupID field public LLUUID GroupID; /// MembershipFee field public int MembershipFee; /// MaturePublish field public bool MaturePublish; /// PowersMask field public ulong PowersMask; /// Money field public int Money; /// FounderID field public LLUUID FounderID; /// OpenEnrollment field public bool OpenEnrollment; /// Length of this block serialized in bytes public int Length { get { int length = 92; if (Charter != null) { length += 2 + Charter.Length; } if (Name != null) { length += 1 + Name.Length; } if (MemberTitle != null) { length += 1 + MemberTitle.Length; } return length; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { int length; try { OwnerRole = new LLUUID(bytes, i); i += 16; AllowPublish = (bytes[i++] != 0) ? (bool)true : (bool)false; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _charter = new byte[length]; Array.Copy(bytes, i, _charter, 0, length); i += length; GroupMembershipCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ShowInList = (bytes[i++] != 0) ? (bool)true : (bool)false; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; length = (ushort)bytes[i++]; _membertitle = new byte[length]; Array.Copy(bytes, i, _membertitle, 0, length); i += length; InsigniaID = new LLUUID(bytes, i); i += 16; GroupRolesCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupID = new LLUUID(bytes, i); i += 16; MembershipFee = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); MaturePublish = (bytes[i++] != 0) ? (bool)true : (bool)false; PowersMask = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); Money = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); FounderID = new LLUUID(bytes, i); i += 16; OpenEnrollment = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(OwnerRole == null) { Console.WriteLine("Warning: OwnerRole is null, in " + this.GetType()); } Array.Copy(OwnerRole.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((AllowPublish) ? 1 : 0); if(Charter == null) { Console.WriteLine("Warning: Charter is null, in " + this.GetType()); } bytes[i++] = (byte)(Charter.Length % 256); bytes[i++] = (byte)((Charter.Length >> 8) % 256); Array.Copy(Charter, 0, bytes, i, Charter.Length); i += Charter.Length; bytes[i++] = (byte)(GroupMembershipCount % 256); bytes[i++] = (byte)((GroupMembershipCount >> 8) % 256); bytes[i++] = (byte)((GroupMembershipCount >> 16) % 256); bytes[i++] = (byte)((GroupMembershipCount >> 24) % 256); bytes[i++] = (byte)((ShowInList) ? 1 : 0); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(MemberTitle == null) { Console.WriteLine("Warning: MemberTitle is null, in " + this.GetType()); } bytes[i++] = (byte)MemberTitle.Length; Array.Copy(MemberTitle, 0, bytes, i, MemberTitle.Length); i += MemberTitle.Length; if(InsigniaID == null) { Console.WriteLine("Warning: InsigniaID is null, in " + this.GetType()); } Array.Copy(InsigniaID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(GroupRolesCount % 256); bytes[i++] = (byte)((GroupRolesCount >> 8) % 256); bytes[i++] = (byte)((GroupRolesCount >> 16) % 256); bytes[i++] = (byte)((GroupRolesCount >> 24) % 256); if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(MembershipFee % 256); bytes[i++] = (byte)((MembershipFee >> 8) % 256); bytes[i++] = (byte)((MembershipFee >> 16) % 256); bytes[i++] = (byte)((MembershipFee >> 24) % 256); bytes[i++] = (byte)((MaturePublish) ? 1 : 0); bytes[i++] = (byte)(PowersMask % 256); bytes[i++] = (byte)((PowersMask >> 8) % 256); bytes[i++] = (byte)((PowersMask >> 16) % 256); bytes[i++] = (byte)((PowersMask >> 24) % 256); bytes[i++] = (byte)((PowersMask >> 32) % 256); bytes[i++] = (byte)((PowersMask >> 40) % 256); bytes[i++] = (byte)((PowersMask >> 48) % 256); bytes[i++] = (byte)((PowersMask >> 56) % 256); bytes[i++] = (byte)(Money % 256); bytes[i++] = (byte)((Money >> 8) % 256); bytes[i++] = (byte)((Money >> 16) % 256); bytes[i++] = (byte)((Money >> 24) % 256); if(FounderID == null) { Console.WriteLine("Warning: FounderID is null, in " + this.GetType()); } Array.Copy(FounderID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((OpenEnrollment) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "OwnerRole: " + OwnerRole.ToString() + "\n"; output += "AllowPublish: " + AllowPublish.ToString() + "\n"; output += Helpers.FieldToString(Charter, "Charter") + "\n"; output += "GroupMembershipCount: " + GroupMembershipCount.ToString() + "\n"; output += "ShowInList: " + ShowInList.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += Helpers.FieldToString(MemberTitle, "MemberTitle") + "\n"; output += "InsigniaID: " + InsigniaID.ToString() + "\n"; output += "GroupRolesCount: " + GroupRolesCount.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "MembershipFee: " + MembershipFee.ToString() + "\n"; output += "MaturePublish: " + MaturePublish.ToString() + "\n"; output += "PowersMask: " + PowersMask.ToString() + "\n"; output += "Money: " + Money.ToString() + "\n"; output += "FounderID: " + FounderID.ToString() + "\n"; output += "OpenEnrollment: " + OpenEnrollment.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupProfileReply public override PacketType Type { get { return PacketType.GroupProfileReply; } } /// AgentData block public AgentDataBlock AgentData; /// GroupData block public GroupDataBlock GroupData; /// Default constructor public GroupProfileReplyPacket() { Header = new LowHeader(); Header.ID = 427; Header.Reliable = true; Header.Zerocoded = true; AgentData = new AgentDataBlock(); GroupData = new GroupDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupProfileReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupProfileReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += GroupData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); GroupData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupProfileReply ---\n"; output += AgentData.ToString() + "\n"; output += GroupData.ToString() + "\n"; return output; } } /// GroupAccountSummaryRequest packet public class GroupAccountSummaryRequestPacket : Packet { /// MoneyData block public class MoneyDataBlock { /// RequestID field public LLUUID RequestID; /// IntervalDays field public int IntervalDays; /// CurrentInterval field public int CurrentInterval; /// Length of this block serialized in bytes public int Length { get { return 24; } } /// Default constructor public MoneyDataBlock() { } /// Constructor for building the block from a byte array public MoneyDataBlock(byte[] bytes, ref int i) { try { RequestID = new LLUUID(bytes, i); i += 16; IntervalDays = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CurrentInterval = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(IntervalDays % 256); bytes[i++] = (byte)((IntervalDays >> 8) % 256); bytes[i++] = (byte)((IntervalDays >> 16) % 256); bytes[i++] = (byte)((IntervalDays >> 24) % 256); bytes[i++] = (byte)(CurrentInterval % 256); bytes[i++] = (byte)((CurrentInterval >> 8) % 256); bytes[i++] = (byte)((CurrentInterval >> 16) % 256); bytes[i++] = (byte)((CurrentInterval >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MoneyData --\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "IntervalDays: " + IntervalDays.ToString() + "\n"; output += "CurrentInterval: " + CurrentInterval.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupAccountSummaryRequest public override PacketType Type { get { return PacketType.GroupAccountSummaryRequest; } } /// MoneyData block public MoneyDataBlock MoneyData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GroupAccountSummaryRequestPacket() { Header = new LowHeader(); Header.ID = 428; Header.Reliable = true; Header.Zerocoded = true; MoneyData = new MoneyDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupAccountSummaryRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MoneyData = new MoneyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupAccountSummaryRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; MoneyData = new MoneyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MoneyData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MoneyData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupAccountSummaryRequest ---\n"; output += MoneyData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// GroupAccountSummaryReply packet public class GroupAccountSummaryReplyPacket : Packet { /// MoneyData block public class MoneyDataBlock { /// ParcelDirFeeCurrent field public int ParcelDirFeeCurrent; private byte[] _taxdate; /// TaxDate field public byte[] TaxDate { get { return _taxdate; } set { if (value == null) { _taxdate = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _taxdate = new byte[value.Length]; Array.Copy(value, _taxdate, value.Length); } } } /// Balance field public int Balance; /// ParcelDirFeeEstimate field public int ParcelDirFeeEstimate; /// RequestID field public LLUUID RequestID; /// ObjectTaxCurrent field public int ObjectTaxCurrent; /// LightTaxCurrent field public int LightTaxCurrent; /// LandTaxCurrent field public int LandTaxCurrent; /// GroupTaxCurrent field public int GroupTaxCurrent; /// TotalDebits field public int TotalDebits; /// IntervalDays field public int IntervalDays; /// ObjectTaxEstimate field public int ObjectTaxEstimate; /// LightTaxEstimate field public int LightTaxEstimate; /// LandTaxEstimate field public int LandTaxEstimate; /// GroupTaxEstimate field public int GroupTaxEstimate; private byte[] _lasttaxdate; /// LastTaxDate field public byte[] LastTaxDate { get { return _lasttaxdate; } set { if (value == null) { _lasttaxdate = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _lasttaxdate = new byte[value.Length]; Array.Copy(value, _lasttaxdate, value.Length); } } } /// NonExemptMembers field public int NonExemptMembers; private byte[] _startdate; /// StartDate field public byte[] StartDate { get { return _startdate; } set { if (value == null) { _startdate = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _startdate = new byte[value.Length]; Array.Copy(value, _startdate, value.Length); } } } /// TotalCredits field public int TotalCredits; /// CurrentInterval field public int CurrentInterval; /// Length of this block serialized in bytes public int Length { get { int length = 80; if (TaxDate != null) { length += 1 + TaxDate.Length; } if (LastTaxDate != null) { length += 1 + LastTaxDate.Length; } if (StartDate != null) { length += 1 + StartDate.Length; } return length; } } /// Default constructor public MoneyDataBlock() { } /// Constructor for building the block from a byte array public MoneyDataBlock(byte[] bytes, ref int i) { int length; try { ParcelDirFeeCurrent = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _taxdate = new byte[length]; Array.Copy(bytes, i, _taxdate, 0, length); i += length; Balance = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ParcelDirFeeEstimate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RequestID = new LLUUID(bytes, i); i += 16; ObjectTaxCurrent = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); LightTaxCurrent = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); LandTaxCurrent = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupTaxCurrent = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TotalDebits = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); IntervalDays = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ObjectTaxEstimate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); LightTaxEstimate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); LandTaxEstimate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupTaxEstimate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _lasttaxdate = new byte[length]; Array.Copy(bytes, i, _lasttaxdate, 0, length); i += length; NonExemptMembers = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _startdate = new byte[length]; Array.Copy(bytes, i, _startdate, 0, length); i += length; TotalCredits = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CurrentInterval = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ParcelDirFeeCurrent % 256); bytes[i++] = (byte)((ParcelDirFeeCurrent >> 8) % 256); bytes[i++] = (byte)((ParcelDirFeeCurrent >> 16) % 256); bytes[i++] = (byte)((ParcelDirFeeCurrent >> 24) % 256); if(TaxDate == null) { Console.WriteLine("Warning: TaxDate is null, in " + this.GetType()); } bytes[i++] = (byte)TaxDate.Length; Array.Copy(TaxDate, 0, bytes, i, TaxDate.Length); i += TaxDate.Length; bytes[i++] = (byte)(Balance % 256); bytes[i++] = (byte)((Balance >> 8) % 256); bytes[i++] = (byte)((Balance >> 16) % 256); bytes[i++] = (byte)((Balance >> 24) % 256); bytes[i++] = (byte)(ParcelDirFeeEstimate % 256); bytes[i++] = (byte)((ParcelDirFeeEstimate >> 8) % 256); bytes[i++] = (byte)((ParcelDirFeeEstimate >> 16) % 256); bytes[i++] = (byte)((ParcelDirFeeEstimate >> 24) % 256); if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(ObjectTaxCurrent % 256); bytes[i++] = (byte)((ObjectTaxCurrent >> 8) % 256); bytes[i++] = (byte)((ObjectTaxCurrent >> 16) % 256); bytes[i++] = (byte)((ObjectTaxCurrent >> 24) % 256); bytes[i++] = (byte)(LightTaxCurrent % 256); bytes[i++] = (byte)((LightTaxCurrent >> 8) % 256); bytes[i++] = (byte)((LightTaxCurrent >> 16) % 256); bytes[i++] = (byte)((LightTaxCurrent >> 24) % 256); bytes[i++] = (byte)(LandTaxCurrent % 256); bytes[i++] = (byte)((LandTaxCurrent >> 8) % 256); bytes[i++] = (byte)((LandTaxCurrent >> 16) % 256); bytes[i++] = (byte)((LandTaxCurrent >> 24) % 256); bytes[i++] = (byte)(GroupTaxCurrent % 256); bytes[i++] = (byte)((GroupTaxCurrent >> 8) % 256); bytes[i++] = (byte)((GroupTaxCurrent >> 16) % 256); bytes[i++] = (byte)((GroupTaxCurrent >> 24) % 256); bytes[i++] = (byte)(TotalDebits % 256); bytes[i++] = (byte)((TotalDebits >> 8) % 256); bytes[i++] = (byte)((TotalDebits >> 16) % 256); bytes[i++] = (byte)((TotalDebits >> 24) % 256); bytes[i++] = (byte)(IntervalDays % 256); bytes[i++] = (byte)((IntervalDays >> 8) % 256); bytes[i++] = (byte)((IntervalDays >> 16) % 256); bytes[i++] = (byte)((IntervalDays >> 24) % 256); bytes[i++] = (byte)(ObjectTaxEstimate % 256); bytes[i++] = (byte)((ObjectTaxEstimate >> 8) % 256); bytes[i++] = (byte)((ObjectTaxEstimate >> 16) % 256); bytes[i++] = (byte)((ObjectTaxEstimate >> 24) % 256); bytes[i++] = (byte)(LightTaxEstimate % 256); bytes[i++] = (byte)((LightTaxEstimate >> 8) % 256); bytes[i++] = (byte)((LightTaxEstimate >> 16) % 256); bytes[i++] = (byte)((LightTaxEstimate >> 24) % 256); bytes[i++] = (byte)(LandTaxEstimate % 256); bytes[i++] = (byte)((LandTaxEstimate >> 8) % 256); bytes[i++] = (byte)((LandTaxEstimate >> 16) % 256); bytes[i++] = (byte)((LandTaxEstimate >> 24) % 256); bytes[i++] = (byte)(GroupTaxEstimate % 256); bytes[i++] = (byte)((GroupTaxEstimate >> 8) % 256); bytes[i++] = (byte)((GroupTaxEstimate >> 16) % 256); bytes[i++] = (byte)((GroupTaxEstimate >> 24) % 256); if(LastTaxDate == null) { Console.WriteLine("Warning: LastTaxDate is null, in " + this.GetType()); } bytes[i++] = (byte)LastTaxDate.Length; Array.Copy(LastTaxDate, 0, bytes, i, LastTaxDate.Length); i += LastTaxDate.Length; bytes[i++] = (byte)(NonExemptMembers % 256); bytes[i++] = (byte)((NonExemptMembers >> 8) % 256); bytes[i++] = (byte)((NonExemptMembers >> 16) % 256); bytes[i++] = (byte)((NonExemptMembers >> 24) % 256); if(StartDate == null) { Console.WriteLine("Warning: StartDate is null, in " + this.GetType()); } bytes[i++] = (byte)StartDate.Length; Array.Copy(StartDate, 0, bytes, i, StartDate.Length); i += StartDate.Length; bytes[i++] = (byte)(TotalCredits % 256); bytes[i++] = (byte)((TotalCredits >> 8) % 256); bytes[i++] = (byte)((TotalCredits >> 16) % 256); bytes[i++] = (byte)((TotalCredits >> 24) % 256); bytes[i++] = (byte)(CurrentInterval % 256); bytes[i++] = (byte)((CurrentInterval >> 8) % 256); bytes[i++] = (byte)((CurrentInterval >> 16) % 256); bytes[i++] = (byte)((CurrentInterval >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MoneyData --\n"; output += "ParcelDirFeeCurrent: " + ParcelDirFeeCurrent.ToString() + "\n"; output += Helpers.FieldToString(TaxDate, "TaxDate") + "\n"; output += "Balance: " + Balance.ToString() + "\n"; output += "ParcelDirFeeEstimate: " + ParcelDirFeeEstimate.ToString() + "\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "ObjectTaxCurrent: " + ObjectTaxCurrent.ToString() + "\n"; output += "LightTaxCurrent: " + LightTaxCurrent.ToString() + "\n"; output += "LandTaxCurrent: " + LandTaxCurrent.ToString() + "\n"; output += "GroupTaxCurrent: " + GroupTaxCurrent.ToString() + "\n"; output += "TotalDebits: " + TotalDebits.ToString() + "\n"; output += "IntervalDays: " + IntervalDays.ToString() + "\n"; output += "ObjectTaxEstimate: " + ObjectTaxEstimate.ToString() + "\n"; output += "LightTaxEstimate: " + LightTaxEstimate.ToString() + "\n"; output += "LandTaxEstimate: " + LandTaxEstimate.ToString() + "\n"; output += "GroupTaxEstimate: " + GroupTaxEstimate.ToString() + "\n"; output += Helpers.FieldToString(LastTaxDate, "LastTaxDate") + "\n"; output += "NonExemptMembers: " + NonExemptMembers.ToString() + "\n"; output += Helpers.FieldToString(StartDate, "StartDate") + "\n"; output += "TotalCredits: " + TotalCredits.ToString() + "\n"; output += "CurrentInterval: " + CurrentInterval.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupAccountSummaryReply public override PacketType Type { get { return PacketType.GroupAccountSummaryReply; } } /// MoneyData block public MoneyDataBlock MoneyData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GroupAccountSummaryReplyPacket() { Header = new LowHeader(); Header.ID = 429; Header.Reliable = true; Header.Zerocoded = true; MoneyData = new MoneyDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupAccountSummaryReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MoneyData = new MoneyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupAccountSummaryReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; MoneyData = new MoneyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MoneyData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MoneyData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupAccountSummaryReply ---\n"; output += MoneyData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// GroupAccountDetailsRequest packet public class GroupAccountDetailsRequestPacket : Packet { /// MoneyData block public class MoneyDataBlock { /// RequestID field public LLUUID RequestID; /// IntervalDays field public int IntervalDays; /// CurrentInterval field public int CurrentInterval; /// Length of this block serialized in bytes public int Length { get { return 24; } } /// Default constructor public MoneyDataBlock() { } /// Constructor for building the block from a byte array public MoneyDataBlock(byte[] bytes, ref int i) { try { RequestID = new LLUUID(bytes, i); i += 16; IntervalDays = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CurrentInterval = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(IntervalDays % 256); bytes[i++] = (byte)((IntervalDays >> 8) % 256); bytes[i++] = (byte)((IntervalDays >> 16) % 256); bytes[i++] = (byte)((IntervalDays >> 24) % 256); bytes[i++] = (byte)(CurrentInterval % 256); bytes[i++] = (byte)((CurrentInterval >> 8) % 256); bytes[i++] = (byte)((CurrentInterval >> 16) % 256); bytes[i++] = (byte)((CurrentInterval >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MoneyData --\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "IntervalDays: " + IntervalDays.ToString() + "\n"; output += "CurrentInterval: " + CurrentInterval.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupAccountDetailsRequest public override PacketType Type { get { return PacketType.GroupAccountDetailsRequest; } } /// MoneyData block public MoneyDataBlock MoneyData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GroupAccountDetailsRequestPacket() { Header = new LowHeader(); Header.ID = 430; Header.Reliable = true; Header.Zerocoded = true; MoneyData = new MoneyDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupAccountDetailsRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MoneyData = new MoneyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupAccountDetailsRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; MoneyData = new MoneyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MoneyData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MoneyData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupAccountDetailsRequest ---\n"; output += MoneyData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// GroupAccountDetailsReply packet public class GroupAccountDetailsReplyPacket : Packet { /// MoneyData block public class MoneyDataBlock { /// RequestID field public LLUUID RequestID; /// IntervalDays field public int IntervalDays; private byte[] _startdate; /// StartDate field public byte[] StartDate { get { return _startdate; } set { if (value == null) { _startdate = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _startdate = new byte[value.Length]; Array.Copy(value, _startdate, value.Length); } } } /// CurrentInterval field public int CurrentInterval; /// Length of this block serialized in bytes public int Length { get { int length = 24; if (StartDate != null) { length += 1 + StartDate.Length; } return length; } } /// Default constructor public MoneyDataBlock() { } /// Constructor for building the block from a byte array public MoneyDataBlock(byte[] bytes, ref int i) { int length; try { RequestID = new LLUUID(bytes, i); i += 16; IntervalDays = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _startdate = new byte[length]; Array.Copy(bytes, i, _startdate, 0, length); i += length; CurrentInterval = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(IntervalDays % 256); bytes[i++] = (byte)((IntervalDays >> 8) % 256); bytes[i++] = (byte)((IntervalDays >> 16) % 256); bytes[i++] = (byte)((IntervalDays >> 24) % 256); if(StartDate == null) { Console.WriteLine("Warning: StartDate is null, in " + this.GetType()); } bytes[i++] = (byte)StartDate.Length; Array.Copy(StartDate, 0, bytes, i, StartDate.Length); i += StartDate.Length; bytes[i++] = (byte)(CurrentInterval % 256); bytes[i++] = (byte)((CurrentInterval >> 8) % 256); bytes[i++] = (byte)((CurrentInterval >> 16) % 256); bytes[i++] = (byte)((CurrentInterval >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MoneyData --\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "IntervalDays: " + IntervalDays.ToString() + "\n"; output += Helpers.FieldToString(StartDate, "StartDate") + "\n"; output += "CurrentInterval: " + CurrentInterval.ToString() + "\n"; output = output.Trim(); return output; } } /// HistoryData block public class HistoryDataBlock { /// Amount field public int Amount; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 4; if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public HistoryDataBlock() { } /// Constructor for building the block from a byte array public HistoryDataBlock(byte[] bytes, ref int i) { int length; try { Amount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Amount % 256); bytes[i++] = (byte)((Amount >> 8) % 256); bytes[i++] = (byte)((Amount >> 16) % 256); bytes[i++] = (byte)((Amount >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- HistoryData --\n"; output += "Amount: " + Amount.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupAccountDetailsReply public override PacketType Type { get { return PacketType.GroupAccountDetailsReply; } } /// MoneyData block public MoneyDataBlock MoneyData; /// HistoryData block public HistoryDataBlock[] HistoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GroupAccountDetailsReplyPacket() { Header = new LowHeader(); Header.ID = 431; Header.Reliable = true; Header.Zerocoded = true; MoneyData = new MoneyDataBlock(); HistoryData = new HistoryDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupAccountDetailsReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MoneyData = new MoneyDataBlock(bytes, ref i); int count = (int)bytes[i++]; HistoryData = new HistoryDataBlock[count]; for (int j = 0; j < count; j++) { HistoryData[j] = new HistoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupAccountDetailsReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; MoneyData = new MoneyDataBlock(bytes, ref i); int count = (int)bytes[i++]; HistoryData = new HistoryDataBlock[count]; for (int j = 0; j < count; j++) { HistoryData[j] = new HistoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MoneyData.Length; length += AgentData.Length;; length++; for (int j = 0; j < HistoryData.Length; j++) { length += HistoryData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MoneyData.ToBytes(bytes, ref i); bytes[i++] = (byte)HistoryData.Length; for (int j = 0; j < HistoryData.Length; j++) { HistoryData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupAccountDetailsReply ---\n"; output += MoneyData.ToString() + "\n"; for (int j = 0; j < HistoryData.Length; j++) { output += HistoryData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// GroupAccountTransactionsRequest packet public class GroupAccountTransactionsRequestPacket : Packet { /// MoneyData block public class MoneyDataBlock { /// RequestID field public LLUUID RequestID; /// IntervalDays field public int IntervalDays; /// CurrentInterval field public int CurrentInterval; /// Length of this block serialized in bytes public int Length { get { return 24; } } /// Default constructor public MoneyDataBlock() { } /// Constructor for building the block from a byte array public MoneyDataBlock(byte[] bytes, ref int i) { try { RequestID = new LLUUID(bytes, i); i += 16; IntervalDays = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CurrentInterval = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(IntervalDays % 256); bytes[i++] = (byte)((IntervalDays >> 8) % 256); bytes[i++] = (byte)((IntervalDays >> 16) % 256); bytes[i++] = (byte)((IntervalDays >> 24) % 256); bytes[i++] = (byte)(CurrentInterval % 256); bytes[i++] = (byte)((CurrentInterval >> 8) % 256); bytes[i++] = (byte)((CurrentInterval >> 16) % 256); bytes[i++] = (byte)((CurrentInterval >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MoneyData --\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "IntervalDays: " + IntervalDays.ToString() + "\n"; output += "CurrentInterval: " + CurrentInterval.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupAccountTransactionsRequest public override PacketType Type { get { return PacketType.GroupAccountTransactionsRequest; } } /// MoneyData block public MoneyDataBlock MoneyData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GroupAccountTransactionsRequestPacket() { Header = new LowHeader(); Header.ID = 432; Header.Reliable = true; Header.Zerocoded = true; MoneyData = new MoneyDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupAccountTransactionsRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MoneyData = new MoneyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupAccountTransactionsRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; MoneyData = new MoneyDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MoneyData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MoneyData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupAccountTransactionsRequest ---\n"; output += MoneyData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// GroupAccountTransactionsReply packet public class GroupAccountTransactionsReplyPacket : Packet { /// MoneyData block public class MoneyDataBlock { /// RequestID field public LLUUID RequestID; /// IntervalDays field public int IntervalDays; private byte[] _startdate; /// StartDate field public byte[] StartDate { get { return _startdate; } set { if (value == null) { _startdate = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _startdate = new byte[value.Length]; Array.Copy(value, _startdate, value.Length); } } } /// CurrentInterval field public int CurrentInterval; /// Length of this block serialized in bytes public int Length { get { int length = 24; if (StartDate != null) { length += 1 + StartDate.Length; } return length; } } /// Default constructor public MoneyDataBlock() { } /// Constructor for building the block from a byte array public MoneyDataBlock(byte[] bytes, ref int i) { int length; try { RequestID = new LLUUID(bytes, i); i += 16; IntervalDays = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _startdate = new byte[length]; Array.Copy(bytes, i, _startdate, 0, length); i += length; CurrentInterval = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(IntervalDays % 256); bytes[i++] = (byte)((IntervalDays >> 8) % 256); bytes[i++] = (byte)((IntervalDays >> 16) % 256); bytes[i++] = (byte)((IntervalDays >> 24) % 256); if(StartDate == null) { Console.WriteLine("Warning: StartDate is null, in " + this.GetType()); } bytes[i++] = (byte)StartDate.Length; Array.Copy(StartDate, 0, bytes, i, StartDate.Length); i += StartDate.Length; bytes[i++] = (byte)(CurrentInterval % 256); bytes[i++] = (byte)((CurrentInterval >> 8) % 256); bytes[i++] = (byte)((CurrentInterval >> 16) % 256); bytes[i++] = (byte)((CurrentInterval >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MoneyData --\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "IntervalDays: " + IntervalDays.ToString() + "\n"; output += Helpers.FieldToString(StartDate, "StartDate") + "\n"; output += "CurrentInterval: " + CurrentInterval.ToString() + "\n"; output = output.Trim(); return output; } } /// HistoryData block public class HistoryDataBlock { private byte[] _time; /// Time field public byte[] Time { get { return _time; } set { if (value == null) { _time = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _time = new byte[value.Length]; Array.Copy(value, _time, value.Length); } } } private byte[] _item; /// Item field public byte[] Item { get { return _item; } set { if (value == null) { _item = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _item = new byte[value.Length]; Array.Copy(value, _item, value.Length); } } } private byte[] _user; /// User field public byte[] User { get { return _user; } set { if (value == null) { _user = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _user = new byte[value.Length]; Array.Copy(value, _user, value.Length); } } } /// Type field public int Type; /// Amount field public int Amount; /// Length of this block serialized in bytes public int Length { get { int length = 8; if (Time != null) { length += 1 + Time.Length; } if (Item != null) { length += 1 + Item.Length; } if (User != null) { length += 1 + User.Length; } return length; } } /// Default constructor public HistoryDataBlock() { } /// Constructor for building the block from a byte array public HistoryDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _time = new byte[length]; Array.Copy(bytes, i, _time, 0, length); i += length; length = (ushort)bytes[i++]; _item = new byte[length]; Array.Copy(bytes, i, _item, 0, length); i += length; length = (ushort)bytes[i++]; _user = new byte[length]; Array.Copy(bytes, i, _user, 0, length); i += length; Type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Amount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Time == null) { Console.WriteLine("Warning: Time is null, in " + this.GetType()); } bytes[i++] = (byte)Time.Length; Array.Copy(Time, 0, bytes, i, Time.Length); i += Time.Length; if(Item == null) { Console.WriteLine("Warning: Item is null, in " + this.GetType()); } bytes[i++] = (byte)Item.Length; Array.Copy(Item, 0, bytes, i, Item.Length); i += Item.Length; if(User == null) { Console.WriteLine("Warning: User is null, in " + this.GetType()); } bytes[i++] = (byte)User.Length; Array.Copy(User, 0, bytes, i, User.Length); i += User.Length; bytes[i++] = (byte)(Type % 256); bytes[i++] = (byte)((Type >> 8) % 256); bytes[i++] = (byte)((Type >> 16) % 256); bytes[i++] = (byte)((Type >> 24) % 256); bytes[i++] = (byte)(Amount % 256); bytes[i++] = (byte)((Amount >> 8) % 256); bytes[i++] = (byte)((Amount >> 16) % 256); bytes[i++] = (byte)((Amount >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- HistoryData --\n"; output += Helpers.FieldToString(Time, "Time") + "\n"; output += Helpers.FieldToString(Item, "Item") + "\n"; output += Helpers.FieldToString(User, "User") + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "Amount: " + Amount.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupAccountTransactionsReply public override PacketType Type { get { return PacketType.GroupAccountTransactionsReply; } } /// MoneyData block public MoneyDataBlock MoneyData; /// HistoryData block public HistoryDataBlock[] HistoryData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GroupAccountTransactionsReplyPacket() { Header = new LowHeader(); Header.ID = 433; Header.Reliable = true; Header.Zerocoded = true; MoneyData = new MoneyDataBlock(); HistoryData = new HistoryDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupAccountTransactionsReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MoneyData = new MoneyDataBlock(bytes, ref i); int count = (int)bytes[i++]; HistoryData = new HistoryDataBlock[count]; for (int j = 0; j < count; j++) { HistoryData[j] = new HistoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupAccountTransactionsReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; MoneyData = new MoneyDataBlock(bytes, ref i); int count = (int)bytes[i++]; HistoryData = new HistoryDataBlock[count]; for (int j = 0; j < count; j++) { HistoryData[j] = new HistoryDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MoneyData.Length; length += AgentData.Length;; length++; for (int j = 0; j < HistoryData.Length; j++) { length += HistoryData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MoneyData.ToBytes(bytes, ref i); bytes[i++] = (byte)HistoryData.Length; for (int j = 0; j < HistoryData.Length; j++) { HistoryData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupAccountTransactionsReply ---\n"; output += MoneyData.ToString() + "\n"; for (int j = 0; j < HistoryData.Length; j++) { output += HistoryData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// GroupActiveProposalsRequest packet public class GroupActiveProposalsRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// TransactionData block public class TransactionDataBlock { /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public TransactionDataBlock() { } /// Constructor for building the block from a byte array public TransactionDataBlock(byte[] bytes, ref int i) { try { TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TransactionData --\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { try { GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupActiveProposalsRequest public override PacketType Type { get { return PacketType.GroupActiveProposalsRequest; } } /// AgentData block public AgentDataBlock AgentData; /// TransactionData block public TransactionDataBlock TransactionData; /// GroupData block public GroupDataBlock GroupData; /// Default constructor public GroupActiveProposalsRequestPacket() { Header = new LowHeader(); Header.ID = 434; Header.Reliable = true; AgentData = new AgentDataBlock(); TransactionData = new TransactionDataBlock(); GroupData = new GroupDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupActiveProposalsRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); TransactionData = new TransactionDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupActiveProposalsRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); TransactionData = new TransactionDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += TransactionData.Length; length += GroupData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); TransactionData.ToBytes(bytes, ref i); GroupData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupActiveProposalsRequest ---\n"; output += AgentData.ToString() + "\n"; output += TransactionData.ToString() + "\n"; output += GroupData.ToString() + "\n"; return output; } } /// GroupActiveProposalItemReply packet public class GroupActiveProposalItemReplyPacket : Packet { /// ProposalData block public class ProposalDataBlock { private byte[] _startdatetime; /// StartDateTime field public byte[] StartDateTime { get { return _startdatetime; } set { if (value == null) { _startdatetime = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _startdatetime = new byte[value.Length]; Array.Copy(value, _startdatetime, value.Length); } } } private byte[] _proposaltext; /// ProposalText field public byte[] ProposalText { get { return _proposaltext; } set { if (value == null) { _proposaltext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _proposaltext = new byte[value.Length]; Array.Copy(value, _proposaltext, value.Length); } } } /// Majority field public float Majority; private byte[] _tersedateid; /// TerseDateID field public byte[] TerseDateID { get { return _tersedateid; } set { if (value == null) { _tersedateid = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _tersedateid = new byte[value.Length]; Array.Copy(value, _tersedateid, value.Length); } } } private byte[] _enddatetime; /// EndDateTime field public byte[] EndDateTime { get { return _enddatetime; } set { if (value == null) { _enddatetime = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _enddatetime = new byte[value.Length]; Array.Copy(value, _enddatetime, value.Length); } } } /// VoteID field public LLUUID VoteID; /// AlreadyVoted field public bool AlreadyVoted; private byte[] _votecast; /// VoteCast field public byte[] VoteCast { get { return _votecast; } set { if (value == null) { _votecast = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _votecast = new byte[value.Length]; Array.Copy(value, _votecast, value.Length); } } } /// Quorum field public int Quorum; /// VoteInitiator field public LLUUID VoteInitiator; /// Length of this block serialized in bytes public int Length { get { int length = 41; if (StartDateTime != null) { length += 1 + StartDateTime.Length; } if (ProposalText != null) { length += 1 + ProposalText.Length; } if (TerseDateID != null) { length += 1 + TerseDateID.Length; } if (EndDateTime != null) { length += 1 + EndDateTime.Length; } if (VoteCast != null) { length += 1 + VoteCast.Length; } return length; } } /// Default constructor public ProposalDataBlock() { } /// Constructor for building the block from a byte array public ProposalDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _startdatetime = new byte[length]; Array.Copy(bytes, i, _startdatetime, 0, length); i += length; length = (ushort)bytes[i++]; _proposaltext = new byte[length]; Array.Copy(bytes, i, _proposaltext, 0, length); i += length; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Majority = BitConverter.ToSingle(bytes, i); i += 4; length = (ushort)bytes[i++]; _tersedateid = new byte[length]; Array.Copy(bytes, i, _tersedateid, 0, length); i += length; length = (ushort)bytes[i++]; _enddatetime = new byte[length]; Array.Copy(bytes, i, _enddatetime, 0, length); i += length; VoteID = new LLUUID(bytes, i); i += 16; AlreadyVoted = (bytes[i++] != 0) ? (bool)true : (bool)false; length = (ushort)bytes[i++]; _votecast = new byte[length]; Array.Copy(bytes, i, _votecast, 0, length); i += length; Quorum = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); VoteInitiator = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; if(StartDateTime == null) { Console.WriteLine("Warning: StartDateTime is null, in " + this.GetType()); } bytes[i++] = (byte)StartDateTime.Length; Array.Copy(StartDateTime, 0, bytes, i, StartDateTime.Length); i += StartDateTime.Length; if(ProposalText == null) { Console.WriteLine("Warning: ProposalText is null, in " + this.GetType()); } bytes[i++] = (byte)ProposalText.Length; Array.Copy(ProposalText, 0, bytes, i, ProposalText.Length); i += ProposalText.Length; ba = BitConverter.GetBytes(Majority); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(TerseDateID == null) { Console.WriteLine("Warning: TerseDateID is null, in " + this.GetType()); } bytes[i++] = (byte)TerseDateID.Length; Array.Copy(TerseDateID, 0, bytes, i, TerseDateID.Length); i += TerseDateID.Length; if(EndDateTime == null) { Console.WriteLine("Warning: EndDateTime is null, in " + this.GetType()); } bytes[i++] = (byte)EndDateTime.Length; Array.Copy(EndDateTime, 0, bytes, i, EndDateTime.Length); i += EndDateTime.Length; if(VoteID == null) { Console.WriteLine("Warning: VoteID is null, in " + this.GetType()); } Array.Copy(VoteID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((AlreadyVoted) ? 1 : 0); if(VoteCast == null) { Console.WriteLine("Warning: VoteCast is null, in " + this.GetType()); } bytes[i++] = (byte)VoteCast.Length; Array.Copy(VoteCast, 0, bytes, i, VoteCast.Length); i += VoteCast.Length; bytes[i++] = (byte)(Quorum % 256); bytes[i++] = (byte)((Quorum >> 8) % 256); bytes[i++] = (byte)((Quorum >> 16) % 256); bytes[i++] = (byte)((Quorum >> 24) % 256); if(VoteInitiator == null) { Console.WriteLine("Warning: VoteInitiator is null, in " + this.GetType()); } Array.Copy(VoteInitiator.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ProposalData --\n"; output += Helpers.FieldToString(StartDateTime, "StartDateTime") + "\n"; output += Helpers.FieldToString(ProposalText, "ProposalText") + "\n"; output += "Majority: " + Majority.ToString() + "\n"; output += Helpers.FieldToString(TerseDateID, "TerseDateID") + "\n"; output += Helpers.FieldToString(EndDateTime, "EndDateTime") + "\n"; output += "VoteID: " + VoteID.ToString() + "\n"; output += "AlreadyVoted: " + AlreadyVoted.ToString() + "\n"; output += Helpers.FieldToString(VoteCast, "VoteCast") + "\n"; output += "Quorum: " + Quorum.ToString() + "\n"; output += "VoteInitiator: " + VoteInitiator.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } /// TransactionData block public class TransactionDataBlock { /// TotalNumItems field public uint TotalNumItems; /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public TransactionDataBlock() { } /// Constructor for building the block from a byte array public TransactionDataBlock(byte[] bytes, ref int i) { try { TotalNumItems = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(TotalNumItems % 256); bytes[i++] = (byte)((TotalNumItems >> 8) % 256); bytes[i++] = (byte)((TotalNumItems >> 16) % 256); bytes[i++] = (byte)((TotalNumItems >> 24) % 256); if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TransactionData --\n"; output += "TotalNumItems: " + TotalNumItems.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupActiveProposalItemReply public override PacketType Type { get { return PacketType.GroupActiveProposalItemReply; } } /// ProposalData block public ProposalDataBlock[] ProposalData; /// AgentData block public AgentDataBlock AgentData; /// TransactionData block public TransactionDataBlock TransactionData; /// Default constructor public GroupActiveProposalItemReplyPacket() { Header = new LowHeader(); Header.ID = 435; Header.Reliable = true; Header.Zerocoded = true; ProposalData = new ProposalDataBlock[0]; AgentData = new AgentDataBlock(); TransactionData = new TransactionDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupActiveProposalItemReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ProposalData = new ProposalDataBlock[count]; for (int j = 0; j < count; j++) { ProposalData[j] = new ProposalDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); TransactionData = new TransactionDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupActiveProposalItemReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ProposalData = new ProposalDataBlock[count]; for (int j = 0; j < count; j++) { ProposalData[j] = new ProposalDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); TransactionData = new TransactionDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += TransactionData.Length;; length++; for (int j = 0; j < ProposalData.Length; j++) { length += ProposalData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ProposalData.Length; for (int j = 0; j < ProposalData.Length; j++) { ProposalData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); TransactionData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupActiveProposalItemReply ---\n"; for (int j = 0; j < ProposalData.Length; j++) { output += ProposalData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; output += TransactionData.ToString() + "\n"; return output; } } /// GroupVoteHistoryRequest packet public class GroupVoteHistoryRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// TransactionData block public class TransactionDataBlock { /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public TransactionDataBlock() { } /// Constructor for building the block from a byte array public TransactionDataBlock(byte[] bytes, ref int i) { try { TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TransactionData --\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { try { GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupVoteHistoryRequest public override PacketType Type { get { return PacketType.GroupVoteHistoryRequest; } } /// AgentData block public AgentDataBlock AgentData; /// TransactionData block public TransactionDataBlock TransactionData; /// GroupData block public GroupDataBlock GroupData; /// Default constructor public GroupVoteHistoryRequestPacket() { Header = new LowHeader(); Header.ID = 436; Header.Reliable = true; AgentData = new AgentDataBlock(); TransactionData = new TransactionDataBlock(); GroupData = new GroupDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupVoteHistoryRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); TransactionData = new TransactionDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupVoteHistoryRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); TransactionData = new TransactionDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += TransactionData.Length; length += GroupData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); TransactionData.ToBytes(bytes, ref i); GroupData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupVoteHistoryRequest ---\n"; output += AgentData.ToString() + "\n"; output += TransactionData.ToString() + "\n"; output += GroupData.ToString() + "\n"; return output; } } /// GroupVoteHistoryItemReply packet public class GroupVoteHistoryItemReplyPacket : Packet { /// HistoryItemData block public class HistoryItemDataBlock { private byte[] _startdatetime; /// StartDateTime field public byte[] StartDateTime { get { return _startdatetime; } set { if (value == null) { _startdatetime = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _startdatetime = new byte[value.Length]; Array.Copy(value, _startdatetime, value.Length); } } } private byte[] _voteresult; /// VoteResult field public byte[] VoteResult { get { return _voteresult; } set { if (value == null) { _voteresult = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _voteresult = new byte[value.Length]; Array.Copy(value, _voteresult, value.Length); } } } private byte[] _proposaltext; /// ProposalText field public byte[] ProposalText { get { return _proposaltext; } set { if (value == null) { _proposaltext = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _proposaltext = new byte[value.Length]; Array.Copy(value, _proposaltext, value.Length); } } } /// Majority field public float Majority; private byte[] _tersedateid; /// TerseDateID field public byte[] TerseDateID { get { return _tersedateid; } set { if (value == null) { _tersedateid = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _tersedateid = new byte[value.Length]; Array.Copy(value, _tersedateid, value.Length); } } } private byte[] _enddatetime; /// EndDateTime field public byte[] EndDateTime { get { return _enddatetime; } set { if (value == null) { _enddatetime = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _enddatetime = new byte[value.Length]; Array.Copy(value, _enddatetime, value.Length); } } } /// VoteID field public LLUUID VoteID; /// Quorum field public int Quorum; private byte[] _votetype; /// VoteType field public byte[] VoteType { get { return _votetype; } set { if (value == null) { _votetype = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _votetype = new byte[value.Length]; Array.Copy(value, _votetype, value.Length); } } } /// VoteInitiator field public LLUUID VoteInitiator; /// Length of this block serialized in bytes public int Length { get { int length = 40; if (StartDateTime != null) { length += 1 + StartDateTime.Length; } if (VoteResult != null) { length += 1 + VoteResult.Length; } if (ProposalText != null) { length += 2 + ProposalText.Length; } if (TerseDateID != null) { length += 1 + TerseDateID.Length; } if (EndDateTime != null) { length += 1 + EndDateTime.Length; } if (VoteType != null) { length += 1 + VoteType.Length; } return length; } } /// Default constructor public HistoryItemDataBlock() { } /// Constructor for building the block from a byte array public HistoryItemDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _startdatetime = new byte[length]; Array.Copy(bytes, i, _startdatetime, 0, length); i += length; length = (ushort)bytes[i++]; _voteresult = new byte[length]; Array.Copy(bytes, i, _voteresult, 0, length); i += length; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _proposaltext = new byte[length]; Array.Copy(bytes, i, _proposaltext, 0, length); i += length; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Majority = BitConverter.ToSingle(bytes, i); i += 4; length = (ushort)bytes[i++]; _tersedateid = new byte[length]; Array.Copy(bytes, i, _tersedateid, 0, length); i += length; length = (ushort)bytes[i++]; _enddatetime = new byte[length]; Array.Copy(bytes, i, _enddatetime, 0, length); i += length; VoteID = new LLUUID(bytes, i); i += 16; Quorum = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _votetype = new byte[length]; Array.Copy(bytes, i, _votetype, 0, length); i += length; VoteInitiator = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; if(StartDateTime == null) { Console.WriteLine("Warning: StartDateTime is null, in " + this.GetType()); } bytes[i++] = (byte)StartDateTime.Length; Array.Copy(StartDateTime, 0, bytes, i, StartDateTime.Length); i += StartDateTime.Length; if(VoteResult == null) { Console.WriteLine("Warning: VoteResult is null, in " + this.GetType()); } bytes[i++] = (byte)VoteResult.Length; Array.Copy(VoteResult, 0, bytes, i, VoteResult.Length); i += VoteResult.Length; if(ProposalText == null) { Console.WriteLine("Warning: ProposalText is null, in " + this.GetType()); } bytes[i++] = (byte)(ProposalText.Length % 256); bytes[i++] = (byte)((ProposalText.Length >> 8) % 256); Array.Copy(ProposalText, 0, bytes, i, ProposalText.Length); i += ProposalText.Length; ba = BitConverter.GetBytes(Majority); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(TerseDateID == null) { Console.WriteLine("Warning: TerseDateID is null, in " + this.GetType()); } bytes[i++] = (byte)TerseDateID.Length; Array.Copy(TerseDateID, 0, bytes, i, TerseDateID.Length); i += TerseDateID.Length; if(EndDateTime == null) { Console.WriteLine("Warning: EndDateTime is null, in " + this.GetType()); } bytes[i++] = (byte)EndDateTime.Length; Array.Copy(EndDateTime, 0, bytes, i, EndDateTime.Length); i += EndDateTime.Length; if(VoteID == null) { Console.WriteLine("Warning: VoteID is null, in " + this.GetType()); } Array.Copy(VoteID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Quorum % 256); bytes[i++] = (byte)((Quorum >> 8) % 256); bytes[i++] = (byte)((Quorum >> 16) % 256); bytes[i++] = (byte)((Quorum >> 24) % 256); if(VoteType == null) { Console.WriteLine("Warning: VoteType is null, in " + this.GetType()); } bytes[i++] = (byte)VoteType.Length; Array.Copy(VoteType, 0, bytes, i, VoteType.Length); i += VoteType.Length; if(VoteInitiator == null) { Console.WriteLine("Warning: VoteInitiator is null, in " + this.GetType()); } Array.Copy(VoteInitiator.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- HistoryItemData --\n"; output += Helpers.FieldToString(StartDateTime, "StartDateTime") + "\n"; output += Helpers.FieldToString(VoteResult, "VoteResult") + "\n"; output += Helpers.FieldToString(ProposalText, "ProposalText") + "\n"; output += "Majority: " + Majority.ToString() + "\n"; output += Helpers.FieldToString(TerseDateID, "TerseDateID") + "\n"; output += Helpers.FieldToString(EndDateTime, "EndDateTime") + "\n"; output += "VoteID: " + VoteID.ToString() + "\n"; output += "Quorum: " + Quorum.ToString() + "\n"; output += Helpers.FieldToString(VoteType, "VoteType") + "\n"; output += "VoteInitiator: " + VoteInitiator.ToString() + "\n"; output = output.Trim(); return output; } } /// VoteItem block public class VoteItemBlock { /// CandidateID field public LLUUID CandidateID; private byte[] _votecast; /// VoteCast field public byte[] VoteCast { get { return _votecast; } set { if (value == null) { _votecast = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _votecast = new byte[value.Length]; Array.Copy(value, _votecast, value.Length); } } } /// NumVotes field public int NumVotes; /// Length of this block serialized in bytes public int Length { get { int length = 20; if (VoteCast != null) { length += 1 + VoteCast.Length; } return length; } } /// Default constructor public VoteItemBlock() { } /// Constructor for building the block from a byte array public VoteItemBlock(byte[] bytes, ref int i) { int length; try { CandidateID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _votecast = new byte[length]; Array.Copy(bytes, i, _votecast, 0, length); i += length; NumVotes = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(CandidateID == null) { Console.WriteLine("Warning: CandidateID is null, in " + this.GetType()); } Array.Copy(CandidateID.GetBytes(), 0, bytes, i, 16); i += 16; if(VoteCast == null) { Console.WriteLine("Warning: VoteCast is null, in " + this.GetType()); } bytes[i++] = (byte)VoteCast.Length; Array.Copy(VoteCast, 0, bytes, i, VoteCast.Length); i += VoteCast.Length; bytes[i++] = (byte)(NumVotes % 256); bytes[i++] = (byte)((NumVotes >> 8) % 256); bytes[i++] = (byte)((NumVotes >> 16) % 256); bytes[i++] = (byte)((NumVotes >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- VoteItem --\n"; output += "CandidateID: " + CandidateID.ToString() + "\n"; output += Helpers.FieldToString(VoteCast, "VoteCast") + "\n"; output += "NumVotes: " + NumVotes.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } /// TransactionData block public class TransactionDataBlock { /// TotalNumItems field public uint TotalNumItems; /// TransactionID field public LLUUID TransactionID; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public TransactionDataBlock() { } /// Constructor for building the block from a byte array public TransactionDataBlock(byte[] bytes, ref int i) { try { TotalNumItems = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TransactionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(TotalNumItems % 256); bytes[i++] = (byte)((TotalNumItems >> 8) % 256); bytes[i++] = (byte)((TotalNumItems >> 16) % 256); bytes[i++] = (byte)((TotalNumItems >> 24) % 256); if(TransactionID == null) { Console.WriteLine("Warning: TransactionID is null, in " + this.GetType()); } Array.Copy(TransactionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TransactionData --\n"; output += "TotalNumItems: " + TotalNumItems.ToString() + "\n"; output += "TransactionID: " + TransactionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupVoteHistoryItemReply public override PacketType Type { get { return PacketType.GroupVoteHistoryItemReply; } } /// HistoryItemData block public HistoryItemDataBlock HistoryItemData; /// VoteItem block public VoteItemBlock[] VoteItem; /// AgentData block public AgentDataBlock AgentData; /// TransactionData block public TransactionDataBlock TransactionData; /// Default constructor public GroupVoteHistoryItemReplyPacket() { Header = new LowHeader(); Header.ID = 437; Header.Reliable = true; Header.Zerocoded = true; HistoryItemData = new HistoryItemDataBlock(); VoteItem = new VoteItemBlock[0]; AgentData = new AgentDataBlock(); TransactionData = new TransactionDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupVoteHistoryItemReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); HistoryItemData = new HistoryItemDataBlock(bytes, ref i); int count = (int)bytes[i++]; VoteItem = new VoteItemBlock[count]; for (int j = 0; j < count; j++) { VoteItem[j] = new VoteItemBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); TransactionData = new TransactionDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupVoteHistoryItemReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; HistoryItemData = new HistoryItemDataBlock(bytes, ref i); int count = (int)bytes[i++]; VoteItem = new VoteItemBlock[count]; for (int j = 0; j < count; j++) { VoteItem[j] = new VoteItemBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); TransactionData = new TransactionDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += HistoryItemData.Length; length += AgentData.Length; length += TransactionData.Length;; length++; for (int j = 0; j < VoteItem.Length; j++) { length += VoteItem[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); HistoryItemData.ToBytes(bytes, ref i); bytes[i++] = (byte)VoteItem.Length; for (int j = 0; j < VoteItem.Length; j++) { VoteItem[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); TransactionData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupVoteHistoryItemReply ---\n"; output += HistoryItemData.ToString() + "\n"; for (int j = 0; j < VoteItem.Length; j++) { output += VoteItem[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; output += TransactionData.ToString() + "\n"; return output; } } /// StartGroupProposal packet public class StartGroupProposalPacket : Packet { /// ProposalData block public class ProposalDataBlock { /// Duration field public int Duration; private byte[] _proposaltext; /// ProposalText field public byte[] ProposalText { get { return _proposaltext; } set { if (value == null) { _proposaltext = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _proposaltext = new byte[value.Length]; Array.Copy(value, _proposaltext, value.Length); } } } /// Majority field public float Majority; /// GroupID field public LLUUID GroupID; /// Quorum field public int Quorum; /// Length of this block serialized in bytes public int Length { get { int length = 28; if (ProposalText != null) { length += 1 + ProposalText.Length; } return length; } } /// Default constructor public ProposalDataBlock() { } /// Constructor for building the block from a byte array public ProposalDataBlock(byte[] bytes, ref int i) { int length; try { Duration = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _proposaltext = new byte[length]; Array.Copy(bytes, i, _proposaltext, 0, length); i += length; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Majority = BitConverter.ToSingle(bytes, i); i += 4; GroupID = new LLUUID(bytes, i); i += 16; Quorum = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = (byte)(Duration % 256); bytes[i++] = (byte)((Duration >> 8) % 256); bytes[i++] = (byte)((Duration >> 16) % 256); bytes[i++] = (byte)((Duration >> 24) % 256); if(ProposalText == null) { Console.WriteLine("Warning: ProposalText is null, in " + this.GetType()); } bytes[i++] = (byte)ProposalText.Length; Array.Copy(ProposalText, 0, bytes, i, ProposalText.Length); i += ProposalText.Length; ba = BitConverter.GetBytes(Majority); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Quorum % 256); bytes[i++] = (byte)((Quorum >> 8) % 256); bytes[i++] = (byte)((Quorum >> 16) % 256); bytes[i++] = (byte)((Quorum >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ProposalData --\n"; output += "Duration: " + Duration.ToString() + "\n"; output += Helpers.FieldToString(ProposalText, "ProposalText") + "\n"; output += "Majority: " + Majority.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "Quorum: " + Quorum.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.StartGroupProposal public override PacketType Type { get { return PacketType.StartGroupProposal; } } /// ProposalData block public ProposalDataBlock ProposalData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public StartGroupProposalPacket() { Header = new LowHeader(); Header.ID = 438; Header.Reliable = true; Header.Zerocoded = true; ProposalData = new ProposalDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public StartGroupProposalPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ProposalData = new ProposalDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public StartGroupProposalPacket(Header head, byte[] bytes, ref int i) { Header = head; ProposalData = new ProposalDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ProposalData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ProposalData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- StartGroupProposal ---\n"; output += ProposalData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// GroupProposalBallot packet public class GroupProposalBallotPacket : Packet { /// ProposalData block public class ProposalDataBlock { /// ProposalID field public LLUUID ProposalID; /// GroupID field public LLUUID GroupID; private byte[] _votecast; /// VoteCast field public byte[] VoteCast { get { return _votecast; } set { if (value == null) { _votecast = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _votecast = new byte[value.Length]; Array.Copy(value, _votecast, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 32; if (VoteCast != null) { length += 1 + VoteCast.Length; } return length; } } /// Default constructor public ProposalDataBlock() { } /// Constructor for building the block from a byte array public ProposalDataBlock(byte[] bytes, ref int i) { int length; try { ProposalID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _votecast = new byte[length]; Array.Copy(bytes, i, _votecast, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ProposalID == null) { Console.WriteLine("Warning: ProposalID is null, in " + this.GetType()); } Array.Copy(ProposalID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; if(VoteCast == null) { Console.WriteLine("Warning: VoteCast is null, in " + this.GetType()); } bytes[i++] = (byte)VoteCast.Length; Array.Copy(VoteCast, 0, bytes, i, VoteCast.Length); i += VoteCast.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ProposalData --\n"; output += "ProposalID: " + ProposalID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += Helpers.FieldToString(VoteCast, "VoteCast") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupProposalBallot public override PacketType Type { get { return PacketType.GroupProposalBallot; } } /// ProposalData block public ProposalDataBlock ProposalData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GroupProposalBallotPacket() { Header = new LowHeader(); Header.ID = 439; Header.Reliable = true; ProposalData = new ProposalDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupProposalBallotPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ProposalData = new ProposalDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupProposalBallotPacket(Header head, byte[] bytes, ref int i) { Header = head; ProposalData = new ProposalDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ProposalData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ProposalData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupProposalBallot ---\n"; output += ProposalData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// TallyVotes packet public class TallyVotesPacket : Packet { private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TallyVotes public override PacketType Type { get { return PacketType.TallyVotes; } } /// Default constructor public TallyVotesPacket() { Header = new LowHeader(); Header.ID = 440; Header.Reliable = true; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TallyVotesPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); } /// Constructor that takes a byte array and a prebuilt header public TallyVotesPacket(Header head, byte[] bytes, ref int i) { Header = head; } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TallyVotes ---\n"; return output; } } /// GroupMembersRequest packet public class GroupMembersRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// RequestID field public LLUUID RequestID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { try { RequestID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupMembersRequest public override PacketType Type { get { return PacketType.GroupMembersRequest; } } /// AgentData block public AgentDataBlock AgentData; /// GroupData block public GroupDataBlock GroupData; /// Default constructor public GroupMembersRequestPacket() { Header = new LowHeader(); Header.ID = 441; Header.Reliable = true; AgentData = new AgentDataBlock(); GroupData = new GroupDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupMembersRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupMembersRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += GroupData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); GroupData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupMembersRequest ---\n"; output += AgentData.ToString() + "\n"; output += GroupData.ToString() + "\n"; return output; } } /// GroupMembersReply packet public class GroupMembersReplyPacket : Packet { /// MemberData block public class MemberDataBlock { private byte[] _onlinestatus; /// OnlineStatus field public byte[] OnlineStatus { get { return _onlinestatus; } set { if (value == null) { _onlinestatus = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _onlinestatus = new byte[value.Length]; Array.Copy(value, _onlinestatus, value.Length); } } } /// AgentID field public LLUUID AgentID; /// Contribution field public int Contribution; /// IsOwner field public bool IsOwner; private byte[] _title; /// Title field public byte[] Title { get { return _title; } set { if (value == null) { _title = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _title = new byte[value.Length]; Array.Copy(value, _title, value.Length); } } } /// AgentPowers field public ulong AgentPowers; /// Length of this block serialized in bytes public int Length { get { int length = 29; if (OnlineStatus != null) { length += 1 + OnlineStatus.Length; } if (Title != null) { length += 1 + Title.Length; } return length; } } /// Default constructor public MemberDataBlock() { } /// Constructor for building the block from a byte array public MemberDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _onlinestatus = new byte[length]; Array.Copy(bytes, i, _onlinestatus, 0, length); i += length; AgentID = new LLUUID(bytes, i); i += 16; Contribution = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); IsOwner = (bytes[i++] != 0) ? (bool)true : (bool)false; length = (ushort)bytes[i++]; _title = new byte[length]; Array.Copy(bytes, i, _title, 0, length); i += length; AgentPowers = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(OnlineStatus == null) { Console.WriteLine("Warning: OnlineStatus is null, in " + this.GetType()); } bytes[i++] = (byte)OnlineStatus.Length; Array.Copy(OnlineStatus, 0, bytes, i, OnlineStatus.Length); i += OnlineStatus.Length; if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Contribution % 256); bytes[i++] = (byte)((Contribution >> 8) % 256); bytes[i++] = (byte)((Contribution >> 16) % 256); bytes[i++] = (byte)((Contribution >> 24) % 256); bytes[i++] = (byte)((IsOwner) ? 1 : 0); if(Title == null) { Console.WriteLine("Warning: Title is null, in " + this.GetType()); } bytes[i++] = (byte)Title.Length; Array.Copy(Title, 0, bytes, i, Title.Length); i += Title.Length; bytes[i++] = (byte)(AgentPowers % 256); bytes[i++] = (byte)((AgentPowers >> 8) % 256); bytes[i++] = (byte)((AgentPowers >> 16) % 256); bytes[i++] = (byte)((AgentPowers >> 24) % 256); bytes[i++] = (byte)((AgentPowers >> 32) % 256); bytes[i++] = (byte)((AgentPowers >> 40) % 256); bytes[i++] = (byte)((AgentPowers >> 48) % 256); bytes[i++] = (byte)((AgentPowers >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MemberData --\n"; output += Helpers.FieldToString(OnlineStatus, "OnlineStatus") + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "Contribution: " + Contribution.ToString() + "\n"; output += "IsOwner: " + IsOwner.ToString() + "\n"; output += Helpers.FieldToString(Title, "Title") + "\n"; output += "AgentPowers: " + AgentPowers.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// RequestID field public LLUUID RequestID; /// MemberCount field public int MemberCount; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { try { RequestID = new LLUUID(bytes, i); i += 16; MemberCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(MemberCount % 256); bytes[i++] = (byte)((MemberCount >> 8) % 256); bytes[i++] = (byte)((MemberCount >> 16) % 256); bytes[i++] = (byte)((MemberCount >> 24) % 256); if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "MemberCount: " + MemberCount.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupMembersReply public override PacketType Type { get { return PacketType.GroupMembersReply; } } /// MemberData block public MemberDataBlock[] MemberData; /// AgentData block public AgentDataBlock AgentData; /// GroupData block public GroupDataBlock GroupData; /// Default constructor public GroupMembersReplyPacket() { Header = new LowHeader(); Header.ID = 442; Header.Reliable = true; Header.Zerocoded = true; MemberData = new MemberDataBlock[0]; AgentData = new AgentDataBlock(); GroupData = new GroupDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupMembersReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; MemberData = new MemberDataBlock[count]; for (int j = 0; j < count; j++) { MemberData[j] = new MemberDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupMembersReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; MemberData = new MemberDataBlock[count]; for (int j = 0; j < count; j++) { MemberData[j] = new MemberDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += GroupData.Length;; length++; for (int j = 0; j < MemberData.Length; j++) { length += MemberData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)MemberData.Length; for (int j = 0; j < MemberData.Length; j++) { MemberData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); GroupData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupMembersReply ---\n"; for (int j = 0; j < MemberData.Length; j++) { output += MemberData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; output += GroupData.ToString() + "\n"; return output; } } /// ActivateGroup packet public class ActivateGroupPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ActivateGroup public override PacketType Type { get { return PacketType.ActivateGroup; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ActivateGroupPacket() { Header = new LowHeader(); Header.ID = 443; Header.Reliable = true; Header.Zerocoded = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ActivateGroupPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ActivateGroupPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ActivateGroup ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// SetGroupContribution packet public class SetGroupContributionPacket : Packet { /// Data block public class DataBlock { /// Contribution field public int Contribution; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { Contribution = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Contribution % 256); bytes[i++] = (byte)((Contribution >> 8) % 256); bytes[i++] = (byte)((Contribution >> 16) % 256); bytes[i++] = (byte)((Contribution >> 24) % 256); if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "Contribution: " + Contribution.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SetGroupContribution public override PacketType Type { get { return PacketType.SetGroupContribution; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public SetGroupContributionPacket() { Header = new LowHeader(); Header.ID = 444; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SetGroupContributionPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SetGroupContributionPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SetGroupContribution ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// SetGroupAcceptNotices packet public class SetGroupAcceptNoticesPacket : Packet { /// Data block public class DataBlock { /// GroupID field public LLUUID GroupID; /// AcceptNotices field public bool AcceptNotices; /// Length of this block serialized in bytes public int Length { get { return 17; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { GroupID = new LLUUID(bytes, i); i += 16; AcceptNotices = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((AcceptNotices) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "AcceptNotices: " + AcceptNotices.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SetGroupAcceptNotices public override PacketType Type { get { return PacketType.SetGroupAcceptNotices; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public SetGroupAcceptNoticesPacket() { Header = new LowHeader(); Header.ID = 445; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SetGroupAcceptNoticesPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SetGroupAcceptNoticesPacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SetGroupAcceptNotices ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// GroupRoleDataRequest packet public class GroupRoleDataRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// RequestID field public LLUUID RequestID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { try { RequestID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupRoleDataRequest public override PacketType Type { get { return PacketType.GroupRoleDataRequest; } } /// AgentData block public AgentDataBlock AgentData; /// GroupData block public GroupDataBlock GroupData; /// Default constructor public GroupRoleDataRequestPacket() { Header = new LowHeader(); Header.ID = 446; Header.Reliable = true; AgentData = new AgentDataBlock(); GroupData = new GroupDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupRoleDataRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupRoleDataRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += GroupData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); GroupData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupRoleDataRequest ---\n"; output += AgentData.ToString() + "\n"; output += GroupData.ToString() + "\n"; return output; } } /// GroupRoleDataReply packet public class GroupRoleDataReplyPacket : Packet { /// RoleData block public class RoleDataBlock { /// Members field public uint Members; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// RoleID field public LLUUID RoleID; /// Powers field public ulong Powers; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } private byte[] _title; /// Title field public byte[] Title { get { return _title; } set { if (value == null) { _title = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _title = new byte[value.Length]; Array.Copy(value, _title, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 28; if (Name != null) { length += 1 + Name.Length; } if (Description != null) { length += 1 + Description.Length; } if (Title != null) { length += 1 + Title.Length; } return length; } } /// Default constructor public RoleDataBlock() { } /// Constructor for building the block from a byte array public RoleDataBlock(byte[] bytes, ref int i) { int length; try { Members = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; RoleID = new LLUUID(bytes, i); i += 16; Powers = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; length = (ushort)bytes[i++]; _title = new byte[length]; Array.Copy(bytes, i, _title, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Members % 256); bytes[i++] = (byte)((Members >> 8) % 256); bytes[i++] = (byte)((Members >> 16) % 256); bytes[i++] = (byte)((Members >> 24) % 256); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(RoleID == null) { Console.WriteLine("Warning: RoleID is null, in " + this.GetType()); } Array.Copy(RoleID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Powers % 256); bytes[i++] = (byte)((Powers >> 8) % 256); bytes[i++] = (byte)((Powers >> 16) % 256); bytes[i++] = (byte)((Powers >> 24) % 256); bytes[i++] = (byte)((Powers >> 32) % 256); bytes[i++] = (byte)((Powers >> 40) % 256); bytes[i++] = (byte)((Powers >> 48) % 256); bytes[i++] = (byte)((Powers >> 56) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; if(Title == null) { Console.WriteLine("Warning: Title is null, in " + this.GetType()); } bytes[i++] = (byte)Title.Length; Array.Copy(Title, 0, bytes, i, Title.Length); i += Title.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RoleData --\n"; output += "Members: " + Members.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "RoleID: " + RoleID.ToString() + "\n"; output += "Powers: " + Powers.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += Helpers.FieldToString(Title, "Title") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// RoleCount field public int RoleCount; /// RequestID field public LLUUID RequestID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { try { RoleCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RequestID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(RoleCount % 256); bytes[i++] = (byte)((RoleCount >> 8) % 256); bytes[i++] = (byte)((RoleCount >> 16) % 256); bytes[i++] = (byte)((RoleCount >> 24) % 256); if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "RoleCount: " + RoleCount.ToString() + "\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupRoleDataReply public override PacketType Type { get { return PacketType.GroupRoleDataReply; } } /// RoleData block public RoleDataBlock[] RoleData; /// AgentData block public AgentDataBlock AgentData; /// GroupData block public GroupDataBlock GroupData; /// Default constructor public GroupRoleDataReplyPacket() { Header = new LowHeader(); Header.ID = 447; Header.Reliable = true; RoleData = new RoleDataBlock[0]; AgentData = new AgentDataBlock(); GroupData = new GroupDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupRoleDataReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; RoleData = new RoleDataBlock[count]; for (int j = 0; j < count; j++) { RoleData[j] = new RoleDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupRoleDataReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; RoleData = new RoleDataBlock[count]; for (int j = 0; j < count; j++) { RoleData[j] = new RoleDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += GroupData.Length;; length++; for (int j = 0; j < RoleData.Length; j++) { length += RoleData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)RoleData.Length; for (int j = 0; j < RoleData.Length; j++) { RoleData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); GroupData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupRoleDataReply ---\n"; for (int j = 0; j < RoleData.Length; j++) { output += RoleData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; output += GroupData.ToString() + "\n"; return output; } } /// GroupRoleMembersRequest packet public class GroupRoleMembersRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// RequestID field public LLUUID RequestID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { try { RequestID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupRoleMembersRequest public override PacketType Type { get { return PacketType.GroupRoleMembersRequest; } } /// AgentData block public AgentDataBlock AgentData; /// GroupData block public GroupDataBlock GroupData; /// Default constructor public GroupRoleMembersRequestPacket() { Header = new LowHeader(); Header.ID = 448; Header.Reliable = true; AgentData = new AgentDataBlock(); GroupData = new GroupDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupRoleMembersRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupRoleMembersRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); GroupData = new GroupDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += GroupData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); GroupData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupRoleMembersRequest ---\n"; output += AgentData.ToString() + "\n"; output += GroupData.ToString() + "\n"; return output; } } /// GroupRoleMembersReply packet public class GroupRoleMembersReplyPacket : Packet { /// MemberData block public class MemberDataBlock { /// MemberID field public LLUUID MemberID; /// RoleID field public LLUUID RoleID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public MemberDataBlock() { } /// Constructor for building the block from a byte array public MemberDataBlock(byte[] bytes, ref int i) { try { MemberID = new LLUUID(bytes, i); i += 16; RoleID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(MemberID == null) { Console.WriteLine("Warning: MemberID is null, in " + this.GetType()); } Array.Copy(MemberID.GetBytes(), 0, bytes, i, 16); i += 16; if(RoleID == null) { Console.WriteLine("Warning: RoleID is null, in " + this.GetType()); } Array.Copy(RoleID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MemberData --\n"; output += "MemberID: " + MemberID.ToString() + "\n"; output += "RoleID: " + RoleID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// TotalPairs field public uint TotalPairs; /// RequestID field public LLUUID RequestID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 52; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; TotalPairs = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RequestID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(TotalPairs % 256); bytes[i++] = (byte)((TotalPairs >> 8) % 256); bytes[i++] = (byte)((TotalPairs >> 16) % 256); bytes[i++] = (byte)((TotalPairs >> 24) % 256); if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "TotalPairs: " + TotalPairs.ToString() + "\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupRoleMembersReply public override PacketType Type { get { return PacketType.GroupRoleMembersReply; } } /// MemberData block public MemberDataBlock[] MemberData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GroupRoleMembersReplyPacket() { Header = new LowHeader(); Header.ID = 449; Header.Reliable = true; MemberData = new MemberDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupRoleMembersReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; MemberData = new MemberDataBlock[count]; for (int j = 0; j < count; j++) { MemberData[j] = new MemberDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupRoleMembersReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; MemberData = new MemberDataBlock[count]; for (int j = 0; j < count; j++) { MemberData[j] = new MemberDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < MemberData.Length; j++) { length += MemberData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)MemberData.Length; for (int j = 0; j < MemberData.Length; j++) { MemberData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupRoleMembersReply ---\n"; for (int j = 0; j < MemberData.Length; j++) { output += MemberData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// GroupTitlesRequest packet public class GroupTitlesRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// RequestID field public LLUUID RequestID; /// SessionID field public LLUUID SessionID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 64; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; RequestID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupTitlesRequest public override PacketType Type { get { return PacketType.GroupTitlesRequest; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GroupTitlesRequestPacket() { Header = new LowHeader(); Header.ID = 450; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupTitlesRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupTitlesRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupTitlesRequest ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// GroupTitlesReply packet public class GroupTitlesReplyPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// RequestID field public LLUUID RequestID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; RequestID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// Selected field public bool Selected; /// RoleID field public LLUUID RoleID; private byte[] _title; /// Title field public byte[] Title { get { return _title; } set { if (value == null) { _title = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _title = new byte[value.Length]; Array.Copy(value, _title, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 17; if (Title != null) { length += 1 + Title.Length; } return length; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { int length; try { Selected = (bytes[i++] != 0) ? (bool)true : (bool)false; RoleID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _title = new byte[length]; Array.Copy(bytes, i, _title, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((Selected) ? 1 : 0); if(RoleID == null) { Console.WriteLine("Warning: RoleID is null, in " + this.GetType()); } Array.Copy(RoleID.GetBytes(), 0, bytes, i, 16); i += 16; if(Title == null) { Console.WriteLine("Warning: Title is null, in " + this.GetType()); } bytes[i++] = (byte)Title.Length; Array.Copy(Title, 0, bytes, i, Title.Length); i += Title.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "Selected: " + Selected.ToString() + "\n"; output += "RoleID: " + RoleID.ToString() + "\n"; output += Helpers.FieldToString(Title, "Title") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupTitlesReply public override PacketType Type { get { return PacketType.GroupTitlesReply; } } /// AgentData block public AgentDataBlock AgentData; /// GroupData block public GroupDataBlock[] GroupData; /// Default constructor public GroupTitlesReplyPacket() { Header = new LowHeader(); Header.ID = 451; Header.Reliable = true; Header.Zerocoded = true; AgentData = new AgentDataBlock(); GroupData = new GroupDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupTitlesReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); int count = (int)bytes[i++]; GroupData = new GroupDataBlock[count]; for (int j = 0; j < count; j++) { GroupData[j] = new GroupDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public GroupTitlesReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); int count = (int)bytes[i++]; GroupData = new GroupDataBlock[count]; for (int j = 0; j < count; j++) { GroupData[j] = new GroupDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < GroupData.Length; j++) { length += GroupData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); bytes[i++] = (byte)GroupData.Length; for (int j = 0; j < GroupData.Length; j++) { GroupData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupTitlesReply ---\n"; output += AgentData.ToString() + "\n"; for (int j = 0; j < GroupData.Length; j++) { output += GroupData[j].ToString() + "\n"; } return output; } } /// GroupTitleUpdate packet public class GroupTitleUpdatePacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// GroupID field public LLUUID GroupID; /// TitleRoleID field public LLUUID TitleRoleID; /// Length of this block serialized in bytes public int Length { get { return 64; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; TitleRoleID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; if(TitleRoleID == null) { Console.WriteLine("Warning: TitleRoleID is null, in " + this.GetType()); } Array.Copy(TitleRoleID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "TitleRoleID: " + TitleRoleID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupTitleUpdate public override PacketType Type { get { return PacketType.GroupTitleUpdate; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GroupTitleUpdatePacket() { Header = new LowHeader(); Header.ID = 452; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupTitleUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupTitleUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupTitleUpdate ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// GroupRoleUpdate packet public class GroupRoleUpdatePacket : Packet { /// RoleData block public class RoleDataBlock { private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// RoleID field public LLUUID RoleID; /// UpdateType field public byte UpdateType; /// Powers field public ulong Powers; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } private byte[] _title; /// Title field public byte[] Title { get { return _title; } set { if (value == null) { _title = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _title = new byte[value.Length]; Array.Copy(value, _title, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 25; if (Name != null) { length += 1 + Name.Length; } if (Description != null) { length += 1 + Description.Length; } if (Title != null) { length += 1 + Title.Length; } return length; } } /// Default constructor public RoleDataBlock() { } /// Constructor for building the block from a byte array public RoleDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; RoleID = new LLUUID(bytes, i); i += 16; UpdateType = (byte)bytes[i++]; Powers = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; length = (ushort)bytes[i++]; _title = new byte[length]; Array.Copy(bytes, i, _title, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(RoleID == null) { Console.WriteLine("Warning: RoleID is null, in " + this.GetType()); } Array.Copy(RoleID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = UpdateType; bytes[i++] = (byte)(Powers % 256); bytes[i++] = (byte)((Powers >> 8) % 256); bytes[i++] = (byte)((Powers >> 16) % 256); bytes[i++] = (byte)((Powers >> 24) % 256); bytes[i++] = (byte)((Powers >> 32) % 256); bytes[i++] = (byte)((Powers >> 40) % 256); bytes[i++] = (byte)((Powers >> 48) % 256); bytes[i++] = (byte)((Powers >> 56) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; if(Title == null) { Console.WriteLine("Warning: Title is null, in " + this.GetType()); } bytes[i++] = (byte)Title.Length; Array.Copy(Title, 0, bytes, i, Title.Length); i += Title.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RoleData --\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "RoleID: " + RoleID.ToString() + "\n"; output += "UpdateType: " + UpdateType.ToString() + "\n"; output += "Powers: " + Powers.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += Helpers.FieldToString(Title, "Title") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupRoleUpdate public override PacketType Type { get { return PacketType.GroupRoleUpdate; } } /// RoleData block public RoleDataBlock[] RoleData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GroupRoleUpdatePacket() { Header = new LowHeader(); Header.ID = 453; Header.Reliable = true; RoleData = new RoleDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupRoleUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; RoleData = new RoleDataBlock[count]; for (int j = 0; j < count; j++) { RoleData[j] = new RoleDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GroupRoleUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; RoleData = new RoleDataBlock[count]; for (int j = 0; j < count; j++) { RoleData[j] = new RoleDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < RoleData.Length; j++) { length += RoleData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)RoleData.Length; for (int j = 0; j < RoleData.Length; j++) { RoleData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupRoleUpdate ---\n"; for (int j = 0; j < RoleData.Length; j++) { output += RoleData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// LiveHelpGroupRequest packet public class LiveHelpGroupRequestPacket : Packet { /// RequestData block public class RequestDataBlock { /// AgentID field public LLUUID AgentID; /// RequestID field public LLUUID RequestID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public RequestDataBlock() { } /// Constructor for building the block from a byte array public RequestDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; RequestID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RequestData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.LiveHelpGroupRequest public override PacketType Type { get { return PacketType.LiveHelpGroupRequest; } } /// RequestData block public RequestDataBlock RequestData; /// Default constructor public LiveHelpGroupRequestPacket() { Header = new LowHeader(); Header.ID = 454; Header.Reliable = true; RequestData = new RequestDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public LiveHelpGroupRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); RequestData = new RequestDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public LiveHelpGroupRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; RequestData = new RequestDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += RequestData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); RequestData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- LiveHelpGroupRequest ---\n"; output += RequestData.ToString() + "\n"; return output; } } /// LiveHelpGroupReply packet public class LiveHelpGroupReplyPacket : Packet { /// ReplyData block public class ReplyDataBlock { /// RequestID field public LLUUID RequestID; /// GroupID field public LLUUID GroupID; private byte[] _selection; /// Selection field public byte[] Selection { get { return _selection; } set { if (value == null) { _selection = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _selection = new byte[value.Length]; Array.Copy(value, _selection, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 32; if (Selection != null) { length += 1 + Selection.Length; } return length; } } /// Default constructor public ReplyDataBlock() { } /// Constructor for building the block from a byte array public ReplyDataBlock(byte[] bytes, ref int i) { int length; try { RequestID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _selection = new byte[length]; Array.Copy(bytes, i, _selection, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(RequestID == null) { Console.WriteLine("Warning: RequestID is null, in " + this.GetType()); } Array.Copy(RequestID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; if(Selection == null) { Console.WriteLine("Warning: Selection is null, in " + this.GetType()); } bytes[i++] = (byte)Selection.Length; Array.Copy(Selection, 0, bytes, i, Selection.Length); i += Selection.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ReplyData --\n"; output += "RequestID: " + RequestID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += Helpers.FieldToString(Selection, "Selection") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.LiveHelpGroupReply public override PacketType Type { get { return PacketType.LiveHelpGroupReply; } } /// ReplyData block public ReplyDataBlock ReplyData; /// Default constructor public LiveHelpGroupReplyPacket() { Header = new LowHeader(); Header.ID = 455; Header.Reliable = true; ReplyData = new ReplyDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public LiveHelpGroupReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ReplyData = new ReplyDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public LiveHelpGroupReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; ReplyData = new ReplyDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ReplyData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ReplyData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- LiveHelpGroupReply ---\n"; output += ReplyData.ToString() + "\n"; return output; } } /// AgentWearablesRequest packet public class AgentWearablesRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentWearablesRequest public override PacketType Type { get { return PacketType.AgentWearablesRequest; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentWearablesRequestPacket() { Header = new LowHeader(); Header.ID = 456; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentWearablesRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentWearablesRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentWearablesRequest ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// AgentWearablesUpdate packet public class AgentWearablesUpdatePacket : Packet { /// WearableData block public class WearableDataBlock { /// WearableType field public byte WearableType; /// AssetID field public LLUUID AssetID; /// ItemID field public LLUUID ItemID; /// Length of this block serialized in bytes public int Length { get { return 33; } } /// Default constructor public WearableDataBlock() { } /// Constructor for building the block from a byte array public WearableDataBlock(byte[] bytes, ref int i) { try { WearableType = (byte)bytes[i++]; AssetID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = WearableType; if(AssetID == null) { Console.WriteLine("Warning: AssetID is null, in " + this.GetType()); } Array.Copy(AssetID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- WearableData --\n"; output += "WearableType: " + WearableType.ToString() + "\n"; output += "AssetID: " + AssetID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// SerialNum field public uint SerialNum; /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { SerialNum = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(SerialNum % 256); bytes[i++] = (byte)((SerialNum >> 8) % 256); bytes[i++] = (byte)((SerialNum >> 16) % 256); bytes[i++] = (byte)((SerialNum >> 24) % 256); if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "SerialNum: " + SerialNum.ToString() + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentWearablesUpdate public override PacketType Type { get { return PacketType.AgentWearablesUpdate; } } /// WearableData block public WearableDataBlock[] WearableData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentWearablesUpdatePacket() { Header = new LowHeader(); Header.ID = 457; Header.Reliable = true; Header.Zerocoded = true; WearableData = new WearableDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentWearablesUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; WearableData = new WearableDataBlock[count]; for (int j = 0; j < count; j++) { WearableData[j] = new WearableDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentWearablesUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; WearableData = new WearableDataBlock[count]; for (int j = 0; j < count; j++) { WearableData[j] = new WearableDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < WearableData.Length; j++) { length += WearableData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)WearableData.Length; for (int j = 0; j < WearableData.Length; j++) { WearableData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentWearablesUpdate ---\n"; for (int j = 0; j < WearableData.Length; j++) { output += WearableData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// AgentIsNowWearing packet public class AgentIsNowWearingPacket : Packet { /// WearableData block public class WearableDataBlock { /// WearableType field public byte WearableType; /// ItemID field public LLUUID ItemID; /// Length of this block serialized in bytes public int Length { get { return 17; } } /// Default constructor public WearableDataBlock() { } /// Constructor for building the block from a byte array public WearableDataBlock(byte[] bytes, ref int i) { try { WearableType = (byte)bytes[i++]; ItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = WearableType; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- WearableData --\n"; output += "WearableType: " + WearableType.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentIsNowWearing public override PacketType Type { get { return PacketType.AgentIsNowWearing; } } /// WearableData block public WearableDataBlock[] WearableData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentIsNowWearingPacket() { Header = new LowHeader(); Header.ID = 458; Header.Reliable = true; Header.Zerocoded = true; WearableData = new WearableDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentIsNowWearingPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; WearableData = new WearableDataBlock[count]; for (int j = 0; j < count; j++) { WearableData[j] = new WearableDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentIsNowWearingPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; WearableData = new WearableDataBlock[count]; for (int j = 0; j < count; j++) { WearableData[j] = new WearableDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < WearableData.Length; j++) { length += WearableData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)WearableData.Length; for (int j = 0; j < WearableData.Length; j++) { WearableData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentIsNowWearing ---\n"; for (int j = 0; j < WearableData.Length; j++) { output += WearableData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// AgentCachedTexture packet public class AgentCachedTexturePacket : Packet { /// WearableData block public class WearableDataBlock { /// ID field public LLUUID ID; /// TextureIndex field public byte TextureIndex; /// Length of this block serialized in bytes public int Length { get { return 17; } } /// Default constructor public WearableDataBlock() { } /// Constructor for building the block from a byte array public WearableDataBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; TextureIndex = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = TextureIndex; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- WearableData --\n"; output += "ID: " + ID.ToString() + "\n"; output += "TextureIndex: " + TextureIndex.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// SerialNum field public int SerialNum; /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { SerialNum = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(SerialNum % 256); bytes[i++] = (byte)((SerialNum >> 8) % 256); bytes[i++] = (byte)((SerialNum >> 16) % 256); bytes[i++] = (byte)((SerialNum >> 24) % 256); if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "SerialNum: " + SerialNum.ToString() + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentCachedTexture public override PacketType Type { get { return PacketType.AgentCachedTexture; } } /// WearableData block public WearableDataBlock[] WearableData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentCachedTexturePacket() { Header = new LowHeader(); Header.ID = 459; Header.Reliable = true; WearableData = new WearableDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentCachedTexturePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; WearableData = new WearableDataBlock[count]; for (int j = 0; j < count; j++) { WearableData[j] = new WearableDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentCachedTexturePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; WearableData = new WearableDataBlock[count]; for (int j = 0; j < count; j++) { WearableData[j] = new WearableDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < WearableData.Length; j++) { length += WearableData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)WearableData.Length; for (int j = 0; j < WearableData.Length; j++) { WearableData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentCachedTexture ---\n"; for (int j = 0; j < WearableData.Length; j++) { output += WearableData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// AgentCachedTextureResponse packet public class AgentCachedTextureResponsePacket : Packet { /// WearableData block public class WearableDataBlock { /// TextureID field public LLUUID TextureID; /// TextureIndex field public byte TextureIndex; private byte[] _hostname; /// HostName field public byte[] HostName { get { return _hostname; } set { if (value == null) { _hostname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _hostname = new byte[value.Length]; Array.Copy(value, _hostname, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 17; if (HostName != null) { length += 1 + HostName.Length; } return length; } } /// Default constructor public WearableDataBlock() { } /// Constructor for building the block from a byte array public WearableDataBlock(byte[] bytes, ref int i) { int length; try { TextureID = new LLUUID(bytes, i); i += 16; TextureIndex = (byte)bytes[i++]; length = (ushort)bytes[i++]; _hostname = new byte[length]; Array.Copy(bytes, i, _hostname, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TextureID == null) { Console.WriteLine("Warning: TextureID is null, in " + this.GetType()); } Array.Copy(TextureID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = TextureIndex; if(HostName == null) { Console.WriteLine("Warning: HostName is null, in " + this.GetType()); } bytes[i++] = (byte)HostName.Length; Array.Copy(HostName, 0, bytes, i, HostName.Length); i += HostName.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- WearableData --\n"; output += "TextureID: " + TextureID.ToString() + "\n"; output += "TextureIndex: " + TextureIndex.ToString() + "\n"; output += Helpers.FieldToString(HostName, "HostName") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// SerialNum field public int SerialNum; /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { SerialNum = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(SerialNum % 256); bytes[i++] = (byte)((SerialNum >> 8) % 256); bytes[i++] = (byte)((SerialNum >> 16) % 256); bytes[i++] = (byte)((SerialNum >> 24) % 256); if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "SerialNum: " + SerialNum.ToString() + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentCachedTextureResponse public override PacketType Type { get { return PacketType.AgentCachedTextureResponse; } } /// WearableData block public WearableDataBlock[] WearableData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentCachedTextureResponsePacket() { Header = new LowHeader(); Header.ID = 460; Header.Reliable = true; WearableData = new WearableDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentCachedTextureResponsePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; WearableData = new WearableDataBlock[count]; for (int j = 0; j < count; j++) { WearableData[j] = new WearableDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentCachedTextureResponsePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; WearableData = new WearableDataBlock[count]; for (int j = 0; j < count; j++) { WearableData[j] = new WearableDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < WearableData.Length; j++) { length += WearableData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)WearableData.Length; for (int j = 0; j < WearableData.Length; j++) { WearableData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentCachedTextureResponse ---\n"; for (int j = 0; j < WearableData.Length; j++) { output += WearableData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// AgentDataUpdateRequest packet public class AgentDataUpdateRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentDataUpdateRequest public override PacketType Type { get { return PacketType.AgentDataUpdateRequest; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentDataUpdateRequestPacket() { Header = new LowHeader(); Header.ID = 461; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentDataUpdateRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentDataUpdateRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentDataUpdateRequest ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// AgentDataUpdate packet public class AgentDataUpdatePacket : Packet { /// AgentData block public class AgentDataBlock { private byte[] _grouptitle; /// GroupTitle field public byte[] GroupTitle { get { return _grouptitle; } set { if (value == null) { _grouptitle = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _grouptitle = new byte[value.Length]; Array.Copy(value, _grouptitle, value.Length); } } } /// GroupPowers field public ulong GroupPowers; /// AgentID field public LLUUID AgentID; private byte[] _lastname; /// LastName field public byte[] LastName { get { return _lastname; } set { if (value == null) { _lastname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _lastname = new byte[value.Length]; Array.Copy(value, _lastname, value.Length); } } } private byte[] _firstname; /// FirstName field public byte[] FirstName { get { return _firstname; } set { if (value == null) { _firstname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _firstname = new byte[value.Length]; Array.Copy(value, _firstname, value.Length); } } } private byte[] _groupname; /// GroupName field public byte[] GroupName { get { return _groupname; } set { if (value == null) { _groupname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _groupname = new byte[value.Length]; Array.Copy(value, _groupname, value.Length); } } } /// ActiveGroupID field public LLUUID ActiveGroupID; /// Length of this block serialized in bytes public int Length { get { int length = 40; if (GroupTitle != null) { length += 1 + GroupTitle.Length; } if (LastName != null) { length += 1 + LastName.Length; } if (FirstName != null) { length += 1 + FirstName.Length; } if (GroupName != null) { length += 1 + GroupName.Length; } return length; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _grouptitle = new byte[length]; Array.Copy(bytes, i, _grouptitle, 0, length); i += length; GroupPowers = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); AgentID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _lastname = new byte[length]; Array.Copy(bytes, i, _lastname, 0, length); i += length; length = (ushort)bytes[i++]; _firstname = new byte[length]; Array.Copy(bytes, i, _firstname, 0, length); i += length; length = (ushort)bytes[i++]; _groupname = new byte[length]; Array.Copy(bytes, i, _groupname, 0, length); i += length; ActiveGroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GroupTitle == null) { Console.WriteLine("Warning: GroupTitle is null, in " + this.GetType()); } bytes[i++] = (byte)GroupTitle.Length; Array.Copy(GroupTitle, 0, bytes, i, GroupTitle.Length); i += GroupTitle.Length; bytes[i++] = (byte)(GroupPowers % 256); bytes[i++] = (byte)((GroupPowers >> 8) % 256); bytes[i++] = (byte)((GroupPowers >> 16) % 256); bytes[i++] = (byte)((GroupPowers >> 24) % 256); bytes[i++] = (byte)((GroupPowers >> 32) % 256); bytes[i++] = (byte)((GroupPowers >> 40) % 256); bytes[i++] = (byte)((GroupPowers >> 48) % 256); bytes[i++] = (byte)((GroupPowers >> 56) % 256); if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(LastName == null) { Console.WriteLine("Warning: LastName is null, in " + this.GetType()); } bytes[i++] = (byte)LastName.Length; Array.Copy(LastName, 0, bytes, i, LastName.Length); i += LastName.Length; if(FirstName == null) { Console.WriteLine("Warning: FirstName is null, in " + this.GetType()); } bytes[i++] = (byte)FirstName.Length; Array.Copy(FirstName, 0, bytes, i, FirstName.Length); i += FirstName.Length; if(GroupName == null) { Console.WriteLine("Warning: GroupName is null, in " + this.GetType()); } bytes[i++] = (byte)GroupName.Length; Array.Copy(GroupName, 0, bytes, i, GroupName.Length); i += GroupName.Length; if(ActiveGroupID == null) { Console.WriteLine("Warning: ActiveGroupID is null, in " + this.GetType()); } Array.Copy(ActiveGroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += Helpers.FieldToString(GroupTitle, "GroupTitle") + "\n"; output += "GroupPowers: " + GroupPowers.ToString() + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += Helpers.FieldToString(LastName, "LastName") + "\n"; output += Helpers.FieldToString(FirstName, "FirstName") + "\n"; output += Helpers.FieldToString(GroupName, "GroupName") + "\n"; output += "ActiveGroupID: " + ActiveGroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentDataUpdate public override PacketType Type { get { return PacketType.AgentDataUpdate; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentDataUpdatePacket() { Header = new LowHeader(); Header.ID = 462; Header.Reliable = true; Header.Zerocoded = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentDataUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentDataUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentDataUpdate ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// GroupDataUpdate packet public class GroupDataUpdatePacket : Packet { /// AgentGroupData block public class AgentGroupDataBlock { private byte[] _grouptitle; /// GroupTitle field public byte[] GroupTitle { get { return _grouptitle; } set { if (value == null) { _grouptitle = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _grouptitle = new byte[value.Length]; Array.Copy(value, _grouptitle, value.Length); } } } /// AgentID field public LLUUID AgentID; /// GroupID field public LLUUID GroupID; /// AgentPowers field public ulong AgentPowers; /// Length of this block serialized in bytes public int Length { get { int length = 40; if (GroupTitle != null) { length += 1 + GroupTitle.Length; } return length; } } /// Default constructor public AgentGroupDataBlock() { } /// Constructor for building the block from a byte array public AgentGroupDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _grouptitle = new byte[length]; Array.Copy(bytes, i, _grouptitle, 0, length); i += length; AgentID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; AgentPowers = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GroupTitle == null) { Console.WriteLine("Warning: GroupTitle is null, in " + this.GetType()); } bytes[i++] = (byte)GroupTitle.Length; Array.Copy(GroupTitle, 0, bytes, i, GroupTitle.Length); i += GroupTitle.Length; if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(AgentPowers % 256); bytes[i++] = (byte)((AgentPowers >> 8) % 256); bytes[i++] = (byte)((AgentPowers >> 16) % 256); bytes[i++] = (byte)((AgentPowers >> 24) % 256); bytes[i++] = (byte)((AgentPowers >> 32) % 256); bytes[i++] = (byte)((AgentPowers >> 40) % 256); bytes[i++] = (byte)((AgentPowers >> 48) % 256); bytes[i++] = (byte)((AgentPowers >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentGroupData --\n"; output += Helpers.FieldToString(GroupTitle, "GroupTitle") + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "AgentPowers: " + AgentPowers.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GroupDataUpdate public override PacketType Type { get { return PacketType.GroupDataUpdate; } } /// AgentGroupData block public AgentGroupDataBlock[] AgentGroupData; /// Default constructor public GroupDataUpdatePacket() { Header = new LowHeader(); Header.ID = 463; Header.Reliable = true; Header.Zerocoded = true; AgentGroupData = new AgentGroupDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GroupDataUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; AgentGroupData = new AgentGroupDataBlock[count]; for (int j = 0; j < count; j++) { AgentGroupData[j] = new AgentGroupDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public GroupDataUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; AgentGroupData = new AgentGroupDataBlock[count]; for (int j = 0; j < count; j++) { AgentGroupData[j] = new AgentGroupDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < AgentGroupData.Length; j++) { length += AgentGroupData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)AgentGroupData.Length; for (int j = 0; j < AgentGroupData.Length; j++) { AgentGroupData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GroupDataUpdate ---\n"; for (int j = 0; j < AgentGroupData.Length; j++) { output += AgentGroupData[j].ToString() + "\n"; } return output; } } /// AgentGroupDataUpdate packet public class AgentGroupDataUpdatePacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// GroupPowers field public ulong GroupPowers; /// Contribution field public int Contribution; /// GroupID field public LLUUID GroupID; /// GroupInsigniaID field public LLUUID GroupInsigniaID; /// AcceptNotices field public bool AcceptNotices; private byte[] _groupname; /// GroupName field public byte[] GroupName { get { return _groupname; } set { if (value == null) { _groupname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _groupname = new byte[value.Length]; Array.Copy(value, _groupname, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 45; if (GroupName != null) { length += 1 + GroupName.Length; } return length; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { int length; try { GroupPowers = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); Contribution = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupID = new LLUUID(bytes, i); i += 16; GroupInsigniaID = new LLUUID(bytes, i); i += 16; AcceptNotices = (bytes[i++] != 0) ? (bool)true : (bool)false; length = (ushort)bytes[i++]; _groupname = new byte[length]; Array.Copy(bytes, i, _groupname, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(GroupPowers % 256); bytes[i++] = (byte)((GroupPowers >> 8) % 256); bytes[i++] = (byte)((GroupPowers >> 16) % 256); bytes[i++] = (byte)((GroupPowers >> 24) % 256); bytes[i++] = (byte)((GroupPowers >> 32) % 256); bytes[i++] = (byte)((GroupPowers >> 40) % 256); bytes[i++] = (byte)((GroupPowers >> 48) % 256); bytes[i++] = (byte)((GroupPowers >> 56) % 256); bytes[i++] = (byte)(Contribution % 256); bytes[i++] = (byte)((Contribution >> 8) % 256); bytes[i++] = (byte)((Contribution >> 16) % 256); bytes[i++] = (byte)((Contribution >> 24) % 256); if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupInsigniaID == null) { Console.WriteLine("Warning: GroupInsigniaID is null, in " + this.GetType()); } Array.Copy(GroupInsigniaID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((AcceptNotices) ? 1 : 0); if(GroupName == null) { Console.WriteLine("Warning: GroupName is null, in " + this.GetType()); } bytes[i++] = (byte)GroupName.Length; Array.Copy(GroupName, 0, bytes, i, GroupName.Length); i += GroupName.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "GroupPowers: " + GroupPowers.ToString() + "\n"; output += "Contribution: " + Contribution.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "GroupInsigniaID: " + GroupInsigniaID.ToString() + "\n"; output += "AcceptNotices: " + AcceptNotices.ToString() + "\n"; output += Helpers.FieldToString(GroupName, "GroupName") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentGroupDataUpdate public override PacketType Type { get { return PacketType.AgentGroupDataUpdate; } } /// AgentData block public AgentDataBlock AgentData; /// GroupData block public GroupDataBlock[] GroupData; /// Default constructor public AgentGroupDataUpdatePacket() { Header = new LowHeader(); Header.ID = 464; Header.Reliable = true; Header.Zerocoded = true; AgentData = new AgentDataBlock(); GroupData = new GroupDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentGroupDataUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); int count = (int)bytes[i++]; GroupData = new GroupDataBlock[count]; for (int j = 0; j < count; j++) { GroupData[j] = new GroupDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public AgentGroupDataUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); int count = (int)bytes[i++]; GroupData = new GroupDataBlock[count]; for (int j = 0; j < count; j++) { GroupData[j] = new GroupDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < GroupData.Length; j++) { length += GroupData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); bytes[i++] = (byte)GroupData.Length; for (int j = 0; j < GroupData.Length; j++) { GroupData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentGroupDataUpdate ---\n"; output += AgentData.ToString() + "\n"; for (int j = 0; j < GroupData.Length; j++) { output += GroupData[j].ToString() + "\n"; } return output; } } /// AgentDropGroup packet public class AgentDropGroupPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentDropGroup public override PacketType Type { get { return PacketType.AgentDropGroup; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentDropGroupPacket() { Header = new LowHeader(); Header.ID = 465; Header.Reliable = true; Header.Zerocoded = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentDropGroupPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentDropGroupPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentDropGroup ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// LogTextMessage packet public class LogTextMessagePacket : Packet { /// DataBlock block public class DataBlockBlock { /// ToAgentId field public LLUUID ToAgentId; private byte[] _message; /// Message field public byte[] Message { get { return _message; } set { if (value == null) { _message = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _message = new byte[value.Length]; Array.Copy(value, _message, value.Length); } } } /// GlobalX field public double GlobalX; /// GlobalY field public double GlobalY; /// Time field public uint Time; /// FromAgentId field public LLUUID FromAgentId; /// Length of this block serialized in bytes public int Length { get { int length = 52; if (Message != null) { length += 2 + Message.Length; } return length; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { int length; try { ToAgentId = new LLUUID(bytes, i); i += 16; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _message = new byte[length]; Array.Copy(bytes, i, _message, 0, length); i += length; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 8); GlobalX = BitConverter.ToDouble(bytes, i); i += 8; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 8); GlobalY = BitConverter.ToDouble(bytes, i); i += 8; Time = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); FromAgentId = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; if(ToAgentId == null) { Console.WriteLine("Warning: ToAgentId is null, in " + this.GetType()); } Array.Copy(ToAgentId.GetBytes(), 0, bytes, i, 16); i += 16; if(Message == null) { Console.WriteLine("Warning: Message is null, in " + this.GetType()); } bytes[i++] = (byte)(Message.Length % 256); bytes[i++] = (byte)((Message.Length >> 8) % 256); Array.Copy(Message, 0, bytes, i, Message.Length); i += Message.Length; ba = BitConverter.GetBytes(GlobalX); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 8); } Array.Copy(ba, 0, bytes, i, 8); i += 8; ba = BitConverter.GetBytes(GlobalY); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 8); } Array.Copy(ba, 0, bytes, i, 8); i += 8; bytes[i++] = (byte)(Time % 256); bytes[i++] = (byte)((Time >> 8) % 256); bytes[i++] = (byte)((Time >> 16) % 256); bytes[i++] = (byte)((Time >> 24) % 256); if(FromAgentId == null) { Console.WriteLine("Warning: FromAgentId is null, in " + this.GetType()); } Array.Copy(FromAgentId.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "ToAgentId: " + ToAgentId.ToString() + "\n"; output += Helpers.FieldToString(Message, "Message") + "\n"; output += "GlobalX: " + GlobalX.ToString() + "\n"; output += "GlobalY: " + GlobalY.ToString() + "\n"; output += "Time: " + Time.ToString() + "\n"; output += "FromAgentId: " + FromAgentId.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.LogTextMessage public override PacketType Type { get { return PacketType.LogTextMessage; } } /// DataBlock block public DataBlockBlock[] DataBlock; /// Default constructor public LogTextMessagePacket() { Header = new LowHeader(); Header.ID = 466; Header.Reliable = true; Header.Zerocoded = true; DataBlock = new DataBlockBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public LogTextMessagePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; DataBlock = new DataBlockBlock[count]; for (int j = 0; j < count; j++) { DataBlock[j] = new DataBlockBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public LogTextMessagePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; DataBlock = new DataBlockBlock[count]; for (int j = 0; j < count; j++) { DataBlock[j] = new DataBlockBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < DataBlock.Length; j++) { length += DataBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)DataBlock.Length; for (int j = 0; j < DataBlock.Length; j++) { DataBlock[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- LogTextMessage ---\n"; for (int j = 0; j < DataBlock.Length; j++) { output += DataBlock[j].ToString() + "\n"; } return output; } } /// CreateTrustedCircuit packet public class CreateTrustedCircuitPacket : Packet { /// DataBlock block public class DataBlockBlock { /// Digest field public byte[] Digest; /// EndPointID field public LLUUID EndPointID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { try { Digest = new byte[32]; Array.Copy(bytes, i, Digest, 0, 32); i += 32; EndPointID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { Array.Copy(Digest, 0, bytes, i, 32);i += 32; if(EndPointID == null) { Console.WriteLine("Warning: EndPointID is null, in " + this.GetType()); } Array.Copy(EndPointID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += Helpers.FieldToString(Digest, "Digest") + "\n"; output += "EndPointID: " + EndPointID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.CreateTrustedCircuit public override PacketType Type { get { return PacketType.CreateTrustedCircuit; } } /// DataBlock block public DataBlockBlock DataBlock; /// Default constructor public CreateTrustedCircuitPacket() { Header = new LowHeader(); Header.ID = 467; Header.Reliable = true; DataBlock = new DataBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public CreateTrustedCircuitPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); DataBlock = new DataBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public CreateTrustedCircuitPacket(Header head, byte[] bytes, ref int i) { Header = head; DataBlock = new DataBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += DataBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- CreateTrustedCircuit ---\n"; output += DataBlock.ToString() + "\n"; return output; } } /// DenyTrustedCircuit packet public class DenyTrustedCircuitPacket : Packet { /// DataBlock block public class DataBlockBlock { /// EndPointID field public LLUUID EndPointID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { try { EndPointID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(EndPointID == null) { Console.WriteLine("Warning: EndPointID is null, in " + this.GetType()); } Array.Copy(EndPointID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "EndPointID: " + EndPointID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DenyTrustedCircuit public override PacketType Type { get { return PacketType.DenyTrustedCircuit; } } /// DataBlock block public DataBlockBlock DataBlock; /// Default constructor public DenyTrustedCircuitPacket() { Header = new LowHeader(); Header.ID = 468; Header.Reliable = true; DataBlock = new DataBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DenyTrustedCircuitPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); DataBlock = new DataBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DenyTrustedCircuitPacket(Header head, byte[] bytes, ref int i) { Header = head; DataBlock = new DataBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += DataBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DenyTrustedCircuit ---\n"; output += DataBlock.ToString() + "\n"; return output; } } /// RezSingleAttachmentFromInv packet public class RezSingleAttachmentFromInvPacket : Packet { /// ObjectData block public class ObjectDataBlock { private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// ItemFlags field public uint ItemFlags; /// OwnerID field public LLUUID OwnerID; /// ItemID field public LLUUID ItemID; /// EveryoneMask field public uint EveryoneMask; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// AttachmentPt field public byte AttachmentPt; /// NextOwnerMask field public uint NextOwnerMask; /// GroupMask field public uint GroupMask; /// Length of this block serialized in bytes public int Length { get { int length = 49; if (Name != null) { length += 1 + Name.Length; } if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; ItemFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; EveryoneMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; AttachmentPt = (byte)bytes[i++]; NextOwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)(ItemFlags % 256); bytes[i++] = (byte)((ItemFlags >> 8) % 256); bytes[i++] = (byte)((ItemFlags >> 16) % 256); bytes[i++] = (byte)((ItemFlags >> 24) % 256); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(EveryoneMask % 256); bytes[i++] = (byte)((EveryoneMask >> 8) % 256); bytes[i++] = (byte)((EveryoneMask >> 16) % 256); bytes[i++] = (byte)((EveryoneMask >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; bytes[i++] = AttachmentPt; bytes[i++] = (byte)(NextOwnerMask % 256); bytes[i++] = (byte)((NextOwnerMask >> 8) % 256); bytes[i++] = (byte)((NextOwnerMask >> 16) % 256); bytes[i++] = (byte)((NextOwnerMask >> 24) % 256); bytes[i++] = (byte)(GroupMask % 256); bytes[i++] = (byte)((GroupMask >> 8) % 256); bytes[i++] = (byte)((GroupMask >> 16) % 256); bytes[i++] = (byte)((GroupMask >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "ItemFlags: " + ItemFlags.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "EveryoneMask: " + EveryoneMask.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += "AttachmentPt: " + AttachmentPt.ToString() + "\n"; output += "NextOwnerMask: " + NextOwnerMask.ToString() + "\n"; output += "GroupMask: " + GroupMask.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RezSingleAttachmentFromInv public override PacketType Type { get { return PacketType.RezSingleAttachmentFromInv; } } /// ObjectData block public ObjectDataBlock ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RezSingleAttachmentFromInvPacket() { Header = new LowHeader(); Header.ID = 469; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RezSingleAttachmentFromInvPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ObjectData = new ObjectDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RezSingleAttachmentFromInvPacket(Header head, byte[] bytes, ref int i) { Header = head; ObjectData = new ObjectDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ObjectData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ObjectData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RezSingleAttachmentFromInv ---\n"; output += ObjectData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// RezMultipleAttachmentsFromInv packet public class RezMultipleAttachmentsFromInvPacket : Packet { /// ObjectData block public class ObjectDataBlock { private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// ItemFlags field public uint ItemFlags; /// OwnerID field public LLUUID OwnerID; /// ItemID field public LLUUID ItemID; /// EveryoneMask field public uint EveryoneMask; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// AttachmentPt field public byte AttachmentPt; /// NextOwnerMask field public uint NextOwnerMask; /// GroupMask field public uint GroupMask; /// Length of this block serialized in bytes public int Length { get { int length = 49; if (Name != null) { length += 1 + Name.Length; } if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; ItemFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; EveryoneMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; AttachmentPt = (byte)bytes[i++]; NextOwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)(ItemFlags % 256); bytes[i++] = (byte)((ItemFlags >> 8) % 256); bytes[i++] = (byte)((ItemFlags >> 16) % 256); bytes[i++] = (byte)((ItemFlags >> 24) % 256); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(EveryoneMask % 256); bytes[i++] = (byte)((EveryoneMask >> 8) % 256); bytes[i++] = (byte)((EveryoneMask >> 16) % 256); bytes[i++] = (byte)((EveryoneMask >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; bytes[i++] = AttachmentPt; bytes[i++] = (byte)(NextOwnerMask % 256); bytes[i++] = (byte)((NextOwnerMask >> 8) % 256); bytes[i++] = (byte)((NextOwnerMask >> 16) % 256); bytes[i++] = (byte)((NextOwnerMask >> 24) % 256); bytes[i++] = (byte)(GroupMask % 256); bytes[i++] = (byte)((GroupMask >> 8) % 256); bytes[i++] = (byte)((GroupMask >> 16) % 256); bytes[i++] = (byte)((GroupMask >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "ItemFlags: " + ItemFlags.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "EveryoneMask: " + EveryoneMask.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += "AttachmentPt: " + AttachmentPt.ToString() + "\n"; output += "NextOwnerMask: " + NextOwnerMask.ToString() + "\n"; output += "GroupMask: " + GroupMask.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// HeaderData block public class HeaderDataBlock { /// CompoundMsgID field public LLUUID CompoundMsgID; /// FirstDetachAll field public bool FirstDetachAll; /// TotalObjects field public byte TotalObjects; /// Length of this block serialized in bytes public int Length { get { return 18; } } /// Default constructor public HeaderDataBlock() { } /// Constructor for building the block from a byte array public HeaderDataBlock(byte[] bytes, ref int i) { try { CompoundMsgID = new LLUUID(bytes, i); i += 16; FirstDetachAll = (bytes[i++] != 0) ? (bool)true : (bool)false; TotalObjects = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(CompoundMsgID == null) { Console.WriteLine("Warning: CompoundMsgID is null, in " + this.GetType()); } Array.Copy(CompoundMsgID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((FirstDetachAll) ? 1 : 0); bytes[i++] = TotalObjects; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- HeaderData --\n"; output += "CompoundMsgID: " + CompoundMsgID.ToString() + "\n"; output += "FirstDetachAll: " + FirstDetachAll.ToString() + "\n"; output += "TotalObjects: " + TotalObjects.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RezMultipleAttachmentsFromInv public override PacketType Type { get { return PacketType.RezMultipleAttachmentsFromInv; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// HeaderData block public HeaderDataBlock HeaderData; /// Default constructor public RezMultipleAttachmentsFromInvPacket() { Header = new LowHeader(); Header.ID = 470; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); HeaderData = new HeaderDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RezMultipleAttachmentsFromInvPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); HeaderData = new HeaderDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RezMultipleAttachmentsFromInvPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); HeaderData = new HeaderDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += HeaderData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); HeaderData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RezMultipleAttachmentsFromInv ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; output += HeaderData.ToString() + "\n"; return output; } } /// DetachAttachmentIntoInv packet public class DetachAttachmentIntoInvPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// AgentID field public LLUUID AgentID; /// ItemID field public LLUUID ItemID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.DetachAttachmentIntoInv public override PacketType Type { get { return PacketType.DetachAttachmentIntoInv; } } /// ObjectData block public ObjectDataBlock ObjectData; /// Default constructor public DetachAttachmentIntoInvPacket() { Header = new LowHeader(); Header.ID = 471; Header.Reliable = true; ObjectData = new ObjectDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public DetachAttachmentIntoInvPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); ObjectData = new ObjectDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public DetachAttachmentIntoInvPacket(Header head, byte[] bytes, ref int i) { Header = head; ObjectData = new ObjectDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += ObjectData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ObjectData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- DetachAttachmentIntoInv ---\n"; output += ObjectData.ToString() + "\n"; return output; } } /// CreateNewOutfitAttachments packet public class CreateNewOutfitAttachmentsPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// OldFolderID field public LLUUID OldFolderID; /// OldItemID field public LLUUID OldItemID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { OldFolderID = new LLUUID(bytes, i); i += 16; OldItemID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(OldFolderID == null) { Console.WriteLine("Warning: OldFolderID is null, in " + this.GetType()); } Array.Copy(OldFolderID.GetBytes(), 0, bytes, i, 16); i += 16; if(OldItemID == null) { Console.WriteLine("Warning: OldItemID is null, in " + this.GetType()); } Array.Copy(OldItemID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "OldFolderID: " + OldFolderID.ToString() + "\n"; output += "OldItemID: " + OldItemID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } /// HeaderData block public class HeaderDataBlock { /// NewFolderID field public LLUUID NewFolderID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public HeaderDataBlock() { } /// Constructor for building the block from a byte array public HeaderDataBlock(byte[] bytes, ref int i) { try { NewFolderID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(NewFolderID == null) { Console.WriteLine("Warning: NewFolderID is null, in " + this.GetType()); } Array.Copy(NewFolderID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- HeaderData --\n"; output += "NewFolderID: " + NewFolderID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.CreateNewOutfitAttachments public override PacketType Type { get { return PacketType.CreateNewOutfitAttachments; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// HeaderData block public HeaderDataBlock HeaderData; /// Default constructor public CreateNewOutfitAttachmentsPacket() { Header = new LowHeader(); Header.ID = 472; Header.Reliable = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); HeaderData = new HeaderDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public CreateNewOutfitAttachmentsPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); HeaderData = new HeaderDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public CreateNewOutfitAttachmentsPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); HeaderData = new HeaderDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length; length += HeaderData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); HeaderData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- CreateNewOutfitAttachments ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; output += HeaderData.ToString() + "\n"; return output; } } /// UserInfoRequest packet public class UserInfoRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UserInfoRequest public override PacketType Type { get { return PacketType.UserInfoRequest; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public UserInfoRequestPacket() { Header = new LowHeader(); Header.ID = 473; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UserInfoRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public UserInfoRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UserInfoRequest ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// UserInfoReply packet public class UserInfoReplyPacket : Packet { /// UserData block public class UserDataBlock { private byte[] _email; /// EMail field public byte[] EMail { get { return _email; } set { if (value == null) { _email = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _email = new byte[value.Length]; Array.Copy(value, _email, value.Length); } } } /// IMViaEMail field public bool IMViaEMail; /// Length of this block serialized in bytes public int Length { get { int length = 1; if (EMail != null) { length += 2 + EMail.Length; } return length; } } /// Default constructor public UserDataBlock() { } /// Constructor for building the block from a byte array public UserDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _email = new byte[length]; Array.Copy(bytes, i, _email, 0, length); i += length; IMViaEMail = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(EMail == null) { Console.WriteLine("Warning: EMail is null, in " + this.GetType()); } bytes[i++] = (byte)(EMail.Length % 256); bytes[i++] = (byte)((EMail.Length >> 8) % 256); Array.Copy(EMail, 0, bytes, i, EMail.Length); i += EMail.Length; bytes[i++] = (byte)((IMViaEMail) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- UserData --\n"; output += Helpers.FieldToString(EMail, "EMail") + "\n"; output += "IMViaEMail: " + IMViaEMail.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UserInfoReply public override PacketType Type { get { return PacketType.UserInfoReply; } } /// UserData block public UserDataBlock UserData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public UserInfoReplyPacket() { Header = new LowHeader(); Header.ID = 474; Header.Reliable = true; UserData = new UserDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UserInfoReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); UserData = new UserDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public UserInfoReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; UserData = new UserDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += UserData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); UserData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UserInfoReply ---\n"; output += UserData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// UpdateUserInfo packet public class UpdateUserInfoPacket : Packet { /// UserData block public class UserDataBlock { /// IMViaEMail field public bool IMViaEMail; /// Length of this block serialized in bytes public int Length { get { return 1; } } /// Default constructor public UserDataBlock() { } /// Constructor for building the block from a byte array public UserDataBlock(byte[] bytes, ref int i) { try { IMViaEMail = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((IMViaEMail) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- UserData --\n"; output += "IMViaEMail: " + IMViaEMail.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.UpdateUserInfo public override PacketType Type { get { return PacketType.UpdateUserInfo; } } /// UserData block public UserDataBlock UserData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public UpdateUserInfoPacket() { Header = new LowHeader(); Header.ID = 475; Header.Reliable = true; UserData = new UserDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public UpdateUserInfoPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); UserData = new UserDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public UpdateUserInfoPacket(Header head, byte[] bytes, ref int i) { Header = head; UserData = new UserDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += UserData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); UserData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- UpdateUserInfo ---\n"; output += UserData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// GodExpungeUser packet public class GodExpungeUserPacket : Packet { /// ExpungeData block public class ExpungeDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ExpungeDataBlock() { } /// Constructor for building the block from a byte array public ExpungeDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ExpungeData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GodExpungeUser public override PacketType Type { get { return PacketType.GodExpungeUser; } } /// ExpungeData block public ExpungeDataBlock[] ExpungeData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public GodExpungeUserPacket() { Header = new LowHeader(); Header.ID = 476; Header.Reliable = true; Header.Zerocoded = true; ExpungeData = new ExpungeDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GodExpungeUserPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ExpungeData = new ExpungeDataBlock[count]; for (int j = 0; j < count; j++) { ExpungeData[j] = new ExpungeDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GodExpungeUserPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ExpungeData = new ExpungeDataBlock[count]; for (int j = 0; j < count; j++) { ExpungeData[j] = new ExpungeDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < ExpungeData.Length; j++) { length += ExpungeData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ExpungeData.Length; for (int j = 0; j < ExpungeData.Length; j++) { ExpungeData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GodExpungeUser ---\n"; for (int j = 0; j < ExpungeData.Length; j++) { output += ExpungeData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// StartExpungeProcess packet public class StartExpungeProcessPacket : Packet { /// ExpungeData block public class ExpungeDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ExpungeDataBlock() { } /// Constructor for building the block from a byte array public ExpungeDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ExpungeData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.StartExpungeProcess public override PacketType Type { get { return PacketType.StartExpungeProcess; } } /// ExpungeData block public ExpungeDataBlock[] ExpungeData; /// Default constructor public StartExpungeProcessPacket() { Header = new LowHeader(); Header.ID = 477; Header.Reliable = true; Header.Zerocoded = true; ExpungeData = new ExpungeDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public StartExpungeProcessPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ExpungeData = new ExpungeDataBlock[count]; for (int j = 0; j < count; j++) { ExpungeData[j] = new ExpungeDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public StartExpungeProcessPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ExpungeData = new ExpungeDataBlock[count]; for (int j = 0; j < count; j++) { ExpungeData[j] = new ExpungeDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < ExpungeData.Length; j++) { length += ExpungeData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ExpungeData.Length; for (int j = 0; j < ExpungeData.Length; j++) { ExpungeData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- StartExpungeProcess ---\n"; for (int j = 0; j < ExpungeData.Length; j++) { output += ExpungeData[j].ToString() + "\n"; } return output; } } /// StartExpungeProcessAck packet public class StartExpungeProcessAckPacket : Packet { private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.StartExpungeProcessAck public override PacketType Type { get { return PacketType.StartExpungeProcessAck; } } /// Default constructor public StartExpungeProcessAckPacket() { Header = new LowHeader(); Header.ID = 478; Header.Reliable = true; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public StartExpungeProcessAckPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); } /// Constructor that takes a byte array and a prebuilt header public StartExpungeProcessAckPacket(Header head, byte[] bytes, ref int i) { Header = head; } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- StartExpungeProcessAck ---\n"; return output; } } /// StartParcelRename packet public class StartParcelRenamePacket : Packet { /// ParcelData block public class ParcelDataBlock { private byte[] _newname; /// NewName field public byte[] NewName { get { return _newname; } set { if (value == null) { _newname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _newname = new byte[value.Length]; Array.Copy(value, _newname, value.Length); } } } /// ParcelID field public LLUUID ParcelID; /// Length of this block serialized in bytes public int Length { get { int length = 16; if (NewName != null) { length += 1 + NewName.Length; } return length; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _newname = new byte[length]; Array.Copy(bytes, i, _newname, 0, length); i += length; ParcelID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(NewName == null) { Console.WriteLine("Warning: NewName is null, in " + this.GetType()); } bytes[i++] = (byte)NewName.Length; Array.Copy(NewName, 0, bytes, i, NewName.Length); i += NewName.Length; if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += Helpers.FieldToString(NewName, "NewName") + "\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.StartParcelRename public override PacketType Type { get { return PacketType.StartParcelRename; } } /// ParcelData block public ParcelDataBlock[] ParcelData; /// Default constructor public StartParcelRenamePacket() { Header = new LowHeader(); Header.ID = 479; Header.Reliable = true; ParcelData = new ParcelDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public StartParcelRenamePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public StartParcelRenamePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < ParcelData.Length; j++) { length += ParcelData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ParcelData.Length; for (int j = 0; j < ParcelData.Length; j++) { ParcelData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- StartParcelRename ---\n"; for (int j = 0; j < ParcelData.Length; j++) { output += ParcelData[j].ToString() + "\n"; } return output; } } /// StartParcelRenameAck packet public class StartParcelRenameAckPacket : Packet { private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.StartParcelRenameAck public override PacketType Type { get { return PacketType.StartParcelRenameAck; } } /// Default constructor public StartParcelRenameAckPacket() { Header = new LowHeader(); Header.ID = 480; Header.Reliable = true; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public StartParcelRenameAckPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); } /// Constructor that takes a byte array and a prebuilt header public StartParcelRenameAckPacket(Header head, byte[] bytes, ref int i) { Header = head; } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- StartParcelRenameAck ---\n"; return output; } } /// BulkParcelRename packet public class BulkParcelRenamePacket : Packet { /// ParcelData block public class ParcelDataBlock { private byte[] _newname; /// NewName field public byte[] NewName { get { return _newname; } set { if (value == null) { _newname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _newname = new byte[value.Length]; Array.Copy(value, _newname, value.Length); } } } /// ParcelID field public LLUUID ParcelID; /// RegionHandle field public ulong RegionHandle; /// Length of this block serialized in bytes public int Length { get { int length = 24; if (NewName != null) { length += 1 + NewName.Length; } return length; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _newname = new byte[length]; Array.Copy(bytes, i, _newname, 0, length); i += length; ParcelID = new LLUUID(bytes, i); i += 16; RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(NewName == null) { Console.WriteLine("Warning: NewName is null, in " + this.GetType()); } bytes[i++] = (byte)NewName.Length; Array.Copy(NewName, 0, bytes, i, NewName.Length); i += NewName.Length; if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += Helpers.FieldToString(NewName, "NewName") + "\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.BulkParcelRename public override PacketType Type { get { return PacketType.BulkParcelRename; } } /// ParcelData block public ParcelDataBlock[] ParcelData; /// Default constructor public BulkParcelRenamePacket() { Header = new LowHeader(); Header.ID = 481; Header.Reliable = true; Header.Zerocoded = true; ParcelData = new ParcelDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public BulkParcelRenamePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public BulkParcelRenamePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < ParcelData.Length; j++) { length += ParcelData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ParcelData.Length; for (int j = 0; j < ParcelData.Length; j++) { ParcelData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- BulkParcelRename ---\n"; for (int j = 0; j < ParcelData.Length; j++) { output += ParcelData[j].ToString() + "\n"; } return output; } } /// ParcelRename packet public class ParcelRenamePacket : Packet { /// ParcelData block public class ParcelDataBlock { private byte[] _newname; /// NewName field public byte[] NewName { get { return _newname; } set { if (value == null) { _newname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _newname = new byte[value.Length]; Array.Copy(value, _newname, value.Length); } } } /// ParcelID field public LLUUID ParcelID; /// Length of this block serialized in bytes public int Length { get { int length = 16; if (NewName != null) { length += 1 + NewName.Length; } return length; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _newname = new byte[length]; Array.Copy(bytes, i, _newname, 0, length); i += length; ParcelID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(NewName == null) { Console.WriteLine("Warning: NewName is null, in " + this.GetType()); } bytes[i++] = (byte)NewName.Length; Array.Copy(NewName, 0, bytes, i, NewName.Length); i += NewName.Length; if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += Helpers.FieldToString(NewName, "NewName") + "\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelRename public override PacketType Type { get { return PacketType.ParcelRename; } } /// ParcelData block public ParcelDataBlock[] ParcelData; /// Default constructor public ParcelRenamePacket() { Header = new LowHeader(); Header.ID = 482; Header.Reliable = true; ParcelData = new ParcelDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelRenamePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public ParcelRenamePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < ParcelData.Length; j++) { length += ParcelData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ParcelData.Length; for (int j = 0; j < ParcelData.Length; j++) { ParcelData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelRename ---\n"; for (int j = 0; j < ParcelData.Length; j++) { output += ParcelData[j].ToString() + "\n"; } return output; } } /// StartParcelRemove packet public class StartParcelRemovePacket : Packet { /// ParcelData block public class ParcelDataBlock { /// ParcelID field public LLUUID ParcelID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { ParcelID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.StartParcelRemove public override PacketType Type { get { return PacketType.StartParcelRemove; } } /// ParcelData block public ParcelDataBlock[] ParcelData; /// Default constructor public StartParcelRemovePacket() { Header = new LowHeader(); Header.ID = 483; Header.Reliable = true; ParcelData = new ParcelDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public StartParcelRemovePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public StartParcelRemovePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < ParcelData.Length; j++) { length += ParcelData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ParcelData.Length; for (int j = 0; j < ParcelData.Length; j++) { ParcelData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- StartParcelRemove ---\n"; for (int j = 0; j < ParcelData.Length; j++) { output += ParcelData[j].ToString() + "\n"; } return output; } } /// StartParcelRemoveAck packet public class StartParcelRemoveAckPacket : Packet { private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.StartParcelRemoveAck public override PacketType Type { get { return PacketType.StartParcelRemoveAck; } } /// Default constructor public StartParcelRemoveAckPacket() { Header = new LowHeader(); Header.ID = 484; Header.Reliable = true; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public StartParcelRemoveAckPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); } /// Constructor that takes a byte array and a prebuilt header public StartParcelRemoveAckPacket(Header head, byte[] bytes, ref int i) { Header = head; } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- StartParcelRemoveAck ---\n"; return output; } } /// BulkParcelRemove packet public class BulkParcelRemovePacket : Packet { /// ParcelData block public class ParcelDataBlock { /// ParcelID field public LLUUID ParcelID; /// RegionHandle field public ulong RegionHandle; /// Length of this block serialized in bytes public int Length { get { return 24; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { ParcelID = new LLUUID(bytes, i); i += 16; RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ParcelID == null) { Console.WriteLine("Warning: ParcelID is null, in " + this.GetType()); } Array.Copy(ParcelID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "ParcelID: " + ParcelID.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.BulkParcelRemove public override PacketType Type { get { return PacketType.BulkParcelRemove; } } /// ParcelData block public ParcelDataBlock[] ParcelData; /// Default constructor public BulkParcelRemovePacket() { Header = new LowHeader(); Header.ID = 485; Header.Reliable = true; Header.Zerocoded = true; ParcelData = new ParcelDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public BulkParcelRemovePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public BulkParcelRemovePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ParcelData = new ParcelDataBlock[count]; for (int j = 0; j < count; j++) { ParcelData[j] = new ParcelDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < ParcelData.Length; j++) { length += ParcelData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ParcelData.Length; for (int j = 0; j < ParcelData.Length; j++) { ParcelData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- BulkParcelRemove ---\n"; for (int j = 0; j < ParcelData.Length; j++) { output += ParcelData[j].ToString() + "\n"; } return output; } } /// InitiateUpload packet public class InitiateUploadPacket : Packet { /// FileData block public class FileDataBlock { private byte[] _sourcefilename; /// SourceFilename field public byte[] SourceFilename { get { return _sourcefilename; } set { if (value == null) { _sourcefilename = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _sourcefilename = new byte[value.Length]; Array.Copy(value, _sourcefilename, value.Length); } } } private byte[] _basefilename; /// BaseFilename field public byte[] BaseFilename { get { return _basefilename; } set { if (value == null) { _basefilename = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _basefilename = new byte[value.Length]; Array.Copy(value, _basefilename, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (SourceFilename != null) { length += 1 + SourceFilename.Length; } if (BaseFilename != null) { length += 1 + BaseFilename.Length; } return length; } } /// Default constructor public FileDataBlock() { } /// Constructor for building the block from a byte array public FileDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _sourcefilename = new byte[length]; Array.Copy(bytes, i, _sourcefilename, 0, length); i += length; length = (ushort)bytes[i++]; _basefilename = new byte[length]; Array.Copy(bytes, i, _basefilename, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(SourceFilename == null) { Console.WriteLine("Warning: SourceFilename is null, in " + this.GetType()); } bytes[i++] = (byte)SourceFilename.Length; Array.Copy(SourceFilename, 0, bytes, i, SourceFilename.Length); i += SourceFilename.Length; if(BaseFilename == null) { Console.WriteLine("Warning: BaseFilename is null, in " + this.GetType()); } bytes[i++] = (byte)BaseFilename.Length; Array.Copy(BaseFilename, 0, bytes, i, BaseFilename.Length); i += BaseFilename.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- FileData --\n"; output += Helpers.FieldToString(SourceFilename, "SourceFilename") + "\n"; output += Helpers.FieldToString(BaseFilename, "BaseFilename") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.InitiateUpload public override PacketType Type { get { return PacketType.InitiateUpload; } } /// FileData block public FileDataBlock FileData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public InitiateUploadPacket() { Header = new LowHeader(); Header.ID = 486; Header.Reliable = true; FileData = new FileDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public InitiateUploadPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); FileData = new FileDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public InitiateUploadPacket(Header head, byte[] bytes, ref int i) { Header = head; FileData = new FileDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += FileData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); FileData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- InitiateUpload ---\n"; output += FileData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// InitiateDownload packet public class InitiateDownloadPacket : Packet { /// FileData block public class FileDataBlock { private byte[] _simfilename; /// SimFilename field public byte[] SimFilename { get { return _simfilename; } set { if (value == null) { _simfilename = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _simfilename = new byte[value.Length]; Array.Copy(value, _simfilename, value.Length); } } } private byte[] _viewerfilename; /// ViewerFilename field public byte[] ViewerFilename { get { return _viewerfilename; } set { if (value == null) { _viewerfilename = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _viewerfilename = new byte[value.Length]; Array.Copy(value, _viewerfilename, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (SimFilename != null) { length += 1 + SimFilename.Length; } if (ViewerFilename != null) { length += 1 + ViewerFilename.Length; } return length; } } /// Default constructor public FileDataBlock() { } /// Constructor for building the block from a byte array public FileDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _simfilename = new byte[length]; Array.Copy(bytes, i, _simfilename, 0, length); i += length; length = (ushort)bytes[i++]; _viewerfilename = new byte[length]; Array.Copy(bytes, i, _viewerfilename, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(SimFilename == null) { Console.WriteLine("Warning: SimFilename is null, in " + this.GetType()); } bytes[i++] = (byte)SimFilename.Length; Array.Copy(SimFilename, 0, bytes, i, SimFilename.Length); i += SimFilename.Length; if(ViewerFilename == null) { Console.WriteLine("Warning: ViewerFilename is null, in " + this.GetType()); } bytes[i++] = (byte)ViewerFilename.Length; Array.Copy(ViewerFilename, 0, bytes, i, ViewerFilename.Length); i += ViewerFilename.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- FileData --\n"; output += Helpers.FieldToString(SimFilename, "SimFilename") + "\n"; output += Helpers.FieldToString(ViewerFilename, "ViewerFilename") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.InitiateDownload public override PacketType Type { get { return PacketType.InitiateDownload; } } /// FileData block public FileDataBlock FileData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public InitiateDownloadPacket() { Header = new LowHeader(); Header.ID = 487; Header.Reliable = true; FileData = new FileDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public InitiateDownloadPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); FileData = new FileDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public InitiateDownloadPacket(Header head, byte[] bytes, ref int i) { Header = head; FileData = new FileDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += FileData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); FileData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- InitiateDownload ---\n"; output += FileData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// SystemMessage packet public class SystemMessagePacket : Packet { /// MethodData block public class MethodDataBlock { /// Invoice field public LLUUID Invoice; /// Digest field public byte[] Digest; private byte[] _method; /// Method field public byte[] Method { get { return _method; } set { if (value == null) { _method = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _method = new byte[value.Length]; Array.Copy(value, _method, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 48; if (Method != null) { length += 1 + Method.Length; } return length; } } /// Default constructor public MethodDataBlock() { } /// Constructor for building the block from a byte array public MethodDataBlock(byte[] bytes, ref int i) { int length; try { Invoice = new LLUUID(bytes, i); i += 16; Digest = new byte[32]; Array.Copy(bytes, i, Digest, 0, 32); i += 32; length = (ushort)bytes[i++]; _method = new byte[length]; Array.Copy(bytes, i, _method, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Invoice == null) { Console.WriteLine("Warning: Invoice is null, in " + this.GetType()); } Array.Copy(Invoice.GetBytes(), 0, bytes, i, 16); i += 16; Array.Copy(Digest, 0, bytes, i, 32);i += 32; if(Method == null) { Console.WriteLine("Warning: Method is null, in " + this.GetType()); } bytes[i++] = (byte)Method.Length; Array.Copy(Method, 0, bytes, i, Method.Length); i += Method.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- MethodData --\n"; output += "Invoice: " + Invoice.ToString() + "\n"; output += Helpers.FieldToString(Digest, "Digest") + "\n"; output += Helpers.FieldToString(Method, "Method") + "\n"; output = output.Trim(); return output; } } /// ParamList block public class ParamListBlock { private byte[] _parameter; /// Parameter field public byte[] Parameter { get { return _parameter; } set { if (value == null) { _parameter = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _parameter = new byte[value.Length]; Array.Copy(value, _parameter, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (Parameter != null) { length += 1 + Parameter.Length; } return length; } } /// Default constructor public ParamListBlock() { } /// Constructor for building the block from a byte array public ParamListBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _parameter = new byte[length]; Array.Copy(bytes, i, _parameter, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Parameter == null) { Console.WriteLine("Warning: Parameter is null, in " + this.GetType()); } bytes[i++] = (byte)Parameter.Length; Array.Copy(Parameter, 0, bytes, i, Parameter.Length); i += Parameter.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParamList --\n"; output += Helpers.FieldToString(Parameter, "Parameter") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SystemMessage public override PacketType Type { get { return PacketType.SystemMessage; } } /// MethodData block public MethodDataBlock MethodData; /// ParamList block public ParamListBlock[] ParamList; /// Default constructor public SystemMessagePacket() { Header = new LowHeader(); Header.ID = 488; Header.Reliable = true; Header.Zerocoded = true; MethodData = new MethodDataBlock(); ParamList = new ParamListBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SystemMessagePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); MethodData = new MethodDataBlock(bytes, ref i); int count = (int)bytes[i++]; ParamList = new ParamListBlock[count]; for (int j = 0; j < count; j++) { ParamList[j] = new ParamListBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public SystemMessagePacket(Header head, byte[] bytes, ref int i) { Header = head; MethodData = new MethodDataBlock(bytes, ref i); int count = (int)bytes[i++]; ParamList = new ParamListBlock[count]; for (int j = 0; j < count; j++) { ParamList[j] = new ParamListBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += MethodData.Length;; length++; for (int j = 0; j < ParamList.Length; j++) { length += ParamList[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); MethodData.ToBytes(bytes, ref i); bytes[i++] = (byte)ParamList.Length; for (int j = 0; j < ParamList.Length; j++) { ParamList[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SystemMessage ---\n"; output += MethodData.ToString() + "\n"; for (int j = 0; j < ParamList.Length; j++) { output += ParamList[j].ToString() + "\n"; } return output; } } /// MapLayerRequest packet public class MapLayerRequestPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Godlike field public bool Godlike; /// Flags field public uint Flags; /// EstateID field public uint EstateID; /// Length of this block serialized in bytes public int Length { get { return 41; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((Godlike) ? 1 : 0); bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "Godlike: " + Godlike.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MapLayerRequest public override PacketType Type { get { return PacketType.MapLayerRequest; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public MapLayerRequestPacket() { Header = new LowHeader(); Header.ID = 489; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MapLayerRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MapLayerRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MapLayerRequest ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// MapLayerReply packet public class MapLayerReplyPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Flags field public uint Flags; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output = output.Trim(); return output; } } /// LayerData block public class LayerDataBlock { /// Top field public uint Top; /// ImageID field public LLUUID ImageID; /// Left field public uint Left; /// Bottom field public uint Bottom; /// Right field public uint Right; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public LayerDataBlock() { } /// Constructor for building the block from a byte array public LayerDataBlock(byte[] bytes, ref int i) { try { Top = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ImageID = new LLUUID(bytes, i); i += 16; Left = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Bottom = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Right = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(Top % 256); bytes[i++] = (byte)((Top >> 8) % 256); bytes[i++] = (byte)((Top >> 16) % 256); bytes[i++] = (byte)((Top >> 24) % 256); if(ImageID == null) { Console.WriteLine("Warning: ImageID is null, in " + this.GetType()); } Array.Copy(ImageID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Left % 256); bytes[i++] = (byte)((Left >> 8) % 256); bytes[i++] = (byte)((Left >> 16) % 256); bytes[i++] = (byte)((Left >> 24) % 256); bytes[i++] = (byte)(Bottom % 256); bytes[i++] = (byte)((Bottom >> 8) % 256); bytes[i++] = (byte)((Bottom >> 16) % 256); bytes[i++] = (byte)((Bottom >> 24) % 256); bytes[i++] = (byte)(Right % 256); bytes[i++] = (byte)((Right >> 8) % 256); bytes[i++] = (byte)((Right >> 16) % 256); bytes[i++] = (byte)((Right >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- LayerData --\n"; output += "Top: " + Top.ToString() + "\n"; output += "ImageID: " + ImageID.ToString() + "\n"; output += "Left: " + Left.ToString() + "\n"; output += "Bottom: " + Bottom.ToString() + "\n"; output += "Right: " + Right.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MapLayerReply public override PacketType Type { get { return PacketType.MapLayerReply; } } /// AgentData block public AgentDataBlock AgentData; /// LayerData block public LayerDataBlock[] LayerData; /// Default constructor public MapLayerReplyPacket() { Header = new LowHeader(); Header.ID = 490; Header.Reliable = true; AgentData = new AgentDataBlock(); LayerData = new LayerDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MapLayerReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); int count = (int)bytes[i++]; LayerData = new LayerDataBlock[count]; for (int j = 0; j < count; j++) { LayerData[j] = new LayerDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public MapLayerReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); int count = (int)bytes[i++]; LayerData = new LayerDataBlock[count]; for (int j = 0; j < count; j++) { LayerData[j] = new LayerDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < LayerData.Length; j++) { length += LayerData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); bytes[i++] = (byte)LayerData.Length; for (int j = 0; j < LayerData.Length; j++) { LayerData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MapLayerReply ---\n"; output += AgentData.ToString() + "\n"; for (int j = 0; j < LayerData.Length; j++) { output += LayerData[j].ToString() + "\n"; } return output; } } /// MapBlockRequest packet public class MapBlockRequestPacket : Packet { /// PositionData block public class PositionDataBlock { /// MaxX field public ushort MaxX; /// MaxY field public ushort MaxY; /// MinX field public ushort MinX; /// MinY field public ushort MinY; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public PositionDataBlock() { } /// Constructor for building the block from a byte array public PositionDataBlock(byte[] bytes, ref int i) { try { MaxX = (ushort)(bytes[i++] + (bytes[i++] << 8)); MaxY = (ushort)(bytes[i++] + (bytes[i++] << 8)); MinX = (ushort)(bytes[i++] + (bytes[i++] << 8)); MinY = (ushort)(bytes[i++] + (bytes[i++] << 8)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(MaxX % 256); bytes[i++] = (byte)((MaxX >> 8) % 256); bytes[i++] = (byte)(MaxY % 256); bytes[i++] = (byte)((MaxY >> 8) % 256); bytes[i++] = (byte)(MinX % 256); bytes[i++] = (byte)((MinX >> 8) % 256); bytes[i++] = (byte)(MinY % 256); bytes[i++] = (byte)((MinY >> 8) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- PositionData --\n"; output += "MaxX: " + MaxX.ToString() + "\n"; output += "MaxY: " + MaxY.ToString() + "\n"; output += "MinX: " + MinX.ToString() + "\n"; output += "MinY: " + MinY.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Godlike field public bool Godlike; /// Flags field public uint Flags; /// EstateID field public uint EstateID; /// Length of this block serialized in bytes public int Length { get { return 41; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((Godlike) ? 1 : 0); bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "Godlike: " + Godlike.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MapBlockRequest public override PacketType Type { get { return PacketType.MapBlockRequest; } } /// PositionData block public PositionDataBlock PositionData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public MapBlockRequestPacket() { Header = new LowHeader(); Header.ID = 491; Header.Reliable = true; PositionData = new PositionDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MapBlockRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); PositionData = new PositionDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MapBlockRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; PositionData = new PositionDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += PositionData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); PositionData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MapBlockRequest ---\n"; output += PositionData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// MapNameRequest packet public class MapNameRequestPacket : Packet { /// NameData block public class NameDataBlock { private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public NameDataBlock() { } /// Constructor for building the block from a byte array public NameDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- NameData --\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Godlike field public bool Godlike; /// Flags field public uint Flags; /// EstateID field public uint EstateID; /// Length of this block serialized in bytes public int Length { get { return 41; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((Godlike) ? 1 : 0); bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "Godlike: " + Godlike.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MapNameRequest public override PacketType Type { get { return PacketType.MapNameRequest; } } /// NameData block public NameDataBlock NameData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public MapNameRequestPacket() { Header = new LowHeader(); Header.ID = 492; Header.Reliable = true; NameData = new NameDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MapNameRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); NameData = new NameDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MapNameRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; NameData = new NameDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += NameData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); NameData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MapNameRequest ---\n"; output += NameData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// MapBlockReply packet public class MapBlockReplyPacket : Packet { /// Data block public class DataBlock { /// X field public ushort X; /// Y field public ushort Y; /// RegionFlags field public uint RegionFlags; /// WaterHeight field public byte WaterHeight; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// Access field public byte Access; /// MapImageID field public LLUUID MapImageID; /// Agents field public byte Agents; /// Length of this block serialized in bytes public int Length { get { int length = 27; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { X = (ushort)(bytes[i++] + (bytes[i++] << 8)); Y = (ushort)(bytes[i++] + (bytes[i++] << 8)); RegionFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); WaterHeight = (byte)bytes[i++]; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; Access = (byte)bytes[i++]; MapImageID = new LLUUID(bytes, i); i += 16; Agents = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(X % 256); bytes[i++] = (byte)((X >> 8) % 256); bytes[i++] = (byte)(Y % 256); bytes[i++] = (byte)((Y >> 8) % 256); bytes[i++] = (byte)(RegionFlags % 256); bytes[i++] = (byte)((RegionFlags >> 8) % 256); bytes[i++] = (byte)((RegionFlags >> 16) % 256); bytes[i++] = (byte)((RegionFlags >> 24) % 256); bytes[i++] = WaterHeight; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = Access; if(MapImageID == null) { Console.WriteLine("Warning: MapImageID is null, in " + this.GetType()); } Array.Copy(MapImageID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = Agents; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "X: " + X.ToString() + "\n"; output += "Y: " + Y.ToString() + "\n"; output += "RegionFlags: " + RegionFlags.ToString() + "\n"; output += "WaterHeight: " + WaterHeight.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "Access: " + Access.ToString() + "\n"; output += "MapImageID: " + MapImageID.ToString() + "\n"; output += "Agents: " + Agents.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Flags field public uint Flags; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MapBlockReply public override PacketType Type { get { return PacketType.MapBlockReply; } } /// Data block public DataBlock[] Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public MapBlockReplyPacket() { Header = new LowHeader(); Header.ID = 493; Header.Reliable = true; Data = new DataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MapBlockReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MapBlockReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; length++; for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)Data.Length; for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MapBlockReply ---\n"; for (int j = 0; j < Data.Length; j++) { output += Data[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// MapItemRequest packet public class MapItemRequestPacket : Packet { /// RequestData block public class RequestDataBlock { /// RegionHandle field public ulong RegionHandle; /// ItemType field public uint ItemType; /// Length of this block serialized in bytes public int Length { get { return 12; } } /// Default constructor public RequestDataBlock() { } /// Constructor for building the block from a byte array public RequestDataBlock(byte[] bytes, ref int i) { try { RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); ItemType = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); bytes[i++] = (byte)(ItemType % 256); bytes[i++] = (byte)((ItemType >> 8) % 256); bytes[i++] = (byte)((ItemType >> 16) % 256); bytes[i++] = (byte)((ItemType >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RequestData --\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output += "ItemType: " + ItemType.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Godlike field public bool Godlike; /// Flags field public uint Flags; /// EstateID field public uint EstateID; /// Length of this block serialized in bytes public int Length { get { return 41; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; Godlike = (bytes[i++] != 0) ? (bool)true : (bool)false; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); EstateID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((Godlike) ? 1 : 0); bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); bytes[i++] = (byte)(EstateID % 256); bytes[i++] = (byte)((EstateID >> 8) % 256); bytes[i++] = (byte)((EstateID >> 16) % 256); bytes[i++] = (byte)((EstateID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "Godlike: " + Godlike.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "EstateID: " + EstateID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MapItemRequest public override PacketType Type { get { return PacketType.MapItemRequest; } } /// RequestData block public RequestDataBlock RequestData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public MapItemRequestPacket() { Header = new LowHeader(); Header.ID = 494; Header.Reliable = true; RequestData = new RequestDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MapItemRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); RequestData = new RequestDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MapItemRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; RequestData = new RequestDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += RequestData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); RequestData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MapItemRequest ---\n"; output += RequestData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// MapItemReply packet public class MapItemReplyPacket : Packet { /// RequestData block public class RequestDataBlock { /// ItemType field public uint ItemType; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public RequestDataBlock() { } /// Constructor for building the block from a byte array public RequestDataBlock(byte[] bytes, ref int i) { try { ItemType = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ItemType % 256); bytes[i++] = (byte)((ItemType >> 8) % 256); bytes[i++] = (byte)((ItemType >> 16) % 256); bytes[i++] = (byte)((ItemType >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RequestData --\n"; output += "ItemType: " + ItemType.ToString() + "\n"; output = output.Trim(); return output; } } /// Data block public class DataBlock { /// X field public uint X; /// Y field public uint Y; /// ID field public LLUUID ID; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// Extra2 field public int Extra2; /// Extra field public int Extra; /// Length of this block serialized in bytes public int Length { get { int length = 32; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { int length; try { X = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Y = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; Extra2 = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Extra = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(X % 256); bytes[i++] = (byte)((X >> 8) % 256); bytes[i++] = (byte)((X >> 16) % 256); bytes[i++] = (byte)((X >> 24) % 256); bytes[i++] = (byte)(Y % 256); bytes[i++] = (byte)((Y >> 8) % 256); bytes[i++] = (byte)((Y >> 16) % 256); bytes[i++] = (byte)((Y >> 24) % 256); if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)(Extra2 % 256); bytes[i++] = (byte)((Extra2 >> 8) % 256); bytes[i++] = (byte)((Extra2 >> 16) % 256); bytes[i++] = (byte)((Extra2 >> 24) % 256); bytes[i++] = (byte)(Extra % 256); bytes[i++] = (byte)((Extra >> 8) % 256); bytes[i++] = (byte)((Extra >> 16) % 256); bytes[i++] = (byte)((Extra >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "X: " + X.ToString() + "\n"; output += "Y: " + Y.ToString() + "\n"; output += "ID: " + ID.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "Extra2: " + Extra2.ToString() + "\n"; output += "Extra: " + Extra.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// Flags field public uint Flags; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MapItemReply public override PacketType Type { get { return PacketType.MapItemReply; } } /// RequestData block public RequestDataBlock RequestData; /// Data block public DataBlock[] Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public MapItemReplyPacket() { Header = new LowHeader(); Header.ID = 495; Header.Reliable = true; RequestData = new RequestDataBlock(); Data = new DataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MapItemReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); RequestData = new RequestDataBlock(bytes, ref i); int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MapItemReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; RequestData = new RequestDataBlock(bytes, ref i); int count = (int)bytes[i++]; Data = new DataBlock[count]; for (int j = 0; j < count; j++) { Data[j] = new DataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += RequestData.Length; length += AgentData.Length;; length++; for (int j = 0; j < Data.Length; j++) { length += Data[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); RequestData.ToBytes(bytes, ref i); bytes[i++] = (byte)Data.Length; for (int j = 0; j < Data.Length; j++) { Data[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MapItemReply ---\n"; output += RequestData.ToString() + "\n"; for (int j = 0; j < Data.Length; j++) { output += Data[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// SendPostcard packet public class SendPostcardPacket : Packet { /// AgentData block public class AgentDataBlock { private byte[] _to; /// To field public byte[] To { get { return _to; } set { if (value == null) { _to = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _to = new byte[value.Length]; Array.Copy(value, _to, value.Length); } } } /// AgentID field public LLUUID AgentID; private byte[] _msg; /// Msg field public byte[] Msg { get { return _msg; } set { if (value == null) { _msg = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _msg = new byte[value.Length]; Array.Copy(value, _msg, value.Length); } } } /// AllowPublish field public bool AllowPublish; /// PosGlobal field public LLVector3d PosGlobal; /// SessionID field public LLUUID SessionID; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } private byte[] _subject; /// Subject field public byte[] Subject { get { return _subject; } set { if (value == null) { _subject = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _subject = new byte[value.Length]; Array.Copy(value, _subject, value.Length); } } } private byte[] _from; /// From field public byte[] From { get { return _from; } set { if (value == null) { _from = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _from = new byte[value.Length]; Array.Copy(value, _from, value.Length); } } } /// AssetID field public LLUUID AssetID; /// MaturePublish field public bool MaturePublish; /// Length of this block serialized in bytes public int Length { get { int length = 74; if (To != null) { length += 1 + To.Length; } if (Msg != null) { length += 2 + Msg.Length; } if (Name != null) { length += 1 + Name.Length; } if (Subject != null) { length += 1 + Subject.Length; } if (From != null) { length += 1 + From.Length; } return length; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _to = new byte[length]; Array.Copy(bytes, i, _to, 0, length); i += length; AgentID = new LLUUID(bytes, i); i += 16; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _msg = new byte[length]; Array.Copy(bytes, i, _msg, 0, length); i += length; AllowPublish = (bytes[i++] != 0) ? (bool)true : (bool)false; PosGlobal = new LLVector3d(bytes, i); i += 24; SessionID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; length = (ushort)bytes[i++]; _subject = new byte[length]; Array.Copy(bytes, i, _subject, 0, length); i += length; length = (ushort)bytes[i++]; _from = new byte[length]; Array.Copy(bytes, i, _from, 0, length); i += length; AssetID = new LLUUID(bytes, i); i += 16; MaturePublish = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(To == null) { Console.WriteLine("Warning: To is null, in " + this.GetType()); } bytes[i++] = (byte)To.Length; Array.Copy(To, 0, bytes, i, To.Length); i += To.Length; if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(Msg == null) { Console.WriteLine("Warning: Msg is null, in " + this.GetType()); } bytes[i++] = (byte)(Msg.Length % 256); bytes[i++] = (byte)((Msg.Length >> 8) % 256); Array.Copy(Msg, 0, bytes, i, Msg.Length); i += Msg.Length; bytes[i++] = (byte)((AllowPublish) ? 1 : 0); if(PosGlobal == null) { Console.WriteLine("Warning: PosGlobal is null, in " + this.GetType()); } Array.Copy(PosGlobal.GetBytes(), 0, bytes, i, 24); i += 24; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; if(Subject == null) { Console.WriteLine("Warning: Subject is null, in " + this.GetType()); } bytes[i++] = (byte)Subject.Length; Array.Copy(Subject, 0, bytes, i, Subject.Length); i += Subject.Length; if(From == null) { Console.WriteLine("Warning: From is null, in " + this.GetType()); } bytes[i++] = (byte)From.Length; Array.Copy(From, 0, bytes, i, From.Length); i += From.Length; if(AssetID == null) { Console.WriteLine("Warning: AssetID is null, in " + this.GetType()); } Array.Copy(AssetID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((MaturePublish) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += Helpers.FieldToString(To, "To") + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += Helpers.FieldToString(Msg, "Msg") + "\n"; output += "AllowPublish: " + AllowPublish.ToString() + "\n"; output += "PosGlobal: " + PosGlobal.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += Helpers.FieldToString(Subject, "Subject") + "\n"; output += Helpers.FieldToString(From, "From") + "\n"; output += "AssetID: " + AssetID.ToString() + "\n"; output += "MaturePublish: " + MaturePublish.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SendPostcard public override PacketType Type { get { return PacketType.SendPostcard; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public SendPostcardPacket() { Header = new LowHeader(); Header.ID = 496; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SendPostcardPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SendPostcardPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SendPostcard ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// RpcChannelRequest packet public class RpcChannelRequestPacket : Packet { /// DataBlock block public class DataBlockBlock { /// TaskID field public LLUUID TaskID; /// ItemID field public LLUUID ItemID; /// GridX field public uint GridX; /// GridY field public uint GridY; /// Length of this block serialized in bytes public int Length { get { return 40; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { try { TaskID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; GridX = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GridY = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TaskID == null) { Console.WriteLine("Warning: TaskID is null, in " + this.GetType()); } Array.Copy(TaskID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(GridX % 256); bytes[i++] = (byte)((GridX >> 8) % 256); bytes[i++] = (byte)((GridX >> 16) % 256); bytes[i++] = (byte)((GridX >> 24) % 256); bytes[i++] = (byte)(GridY % 256); bytes[i++] = (byte)((GridY >> 8) % 256); bytes[i++] = (byte)((GridY >> 16) % 256); bytes[i++] = (byte)((GridY >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "TaskID: " + TaskID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "GridX: " + GridX.ToString() + "\n"; output += "GridY: " + GridY.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RpcChannelRequest public override PacketType Type { get { return PacketType.RpcChannelRequest; } } /// DataBlock block public DataBlockBlock DataBlock; /// Default constructor public RpcChannelRequestPacket() { Header = new LowHeader(); Header.ID = 497; Header.Reliable = true; DataBlock = new DataBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RpcChannelRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); DataBlock = new DataBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RpcChannelRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; DataBlock = new DataBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += DataBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RpcChannelRequest ---\n"; output += DataBlock.ToString() + "\n"; return output; } } /// RpcChannelReply packet public class RpcChannelReplyPacket : Packet { /// DataBlock block public class DataBlockBlock { /// TaskID field public LLUUID TaskID; /// ItemID field public LLUUID ItemID; /// ChannelID field public LLUUID ChannelID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { try { TaskID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; ChannelID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TaskID == null) { Console.WriteLine("Warning: TaskID is null, in " + this.GetType()); } Array.Copy(TaskID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; if(ChannelID == null) { Console.WriteLine("Warning: ChannelID is null, in " + this.GetType()); } Array.Copy(ChannelID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "TaskID: " + TaskID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "ChannelID: " + ChannelID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RpcChannelReply public override PacketType Type { get { return PacketType.RpcChannelReply; } } /// DataBlock block public DataBlockBlock DataBlock; /// Default constructor public RpcChannelReplyPacket() { Header = new LowHeader(); Header.ID = 498; Header.Reliable = true; DataBlock = new DataBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RpcChannelReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); DataBlock = new DataBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RpcChannelReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; DataBlock = new DataBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += DataBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RpcChannelReply ---\n"; output += DataBlock.ToString() + "\n"; return output; } } /// RpcScriptRequestInbound packet public class RpcScriptRequestInboundPacket : Packet { /// TargetBlock block public class TargetBlockBlock { /// GridX field public uint GridX; /// GridY field public uint GridY; /// Length of this block serialized in bytes public int Length { get { return 8; } } /// Default constructor public TargetBlockBlock() { } /// Constructor for building the block from a byte array public TargetBlockBlock(byte[] bytes, ref int i) { try { GridX = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GridY = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(GridX % 256); bytes[i++] = (byte)((GridX >> 8) % 256); bytes[i++] = (byte)((GridX >> 16) % 256); bytes[i++] = (byte)((GridX >> 24) % 256); bytes[i++] = (byte)(GridY % 256); bytes[i++] = (byte)((GridY >> 8) % 256); bytes[i++] = (byte)((GridY >> 16) % 256); bytes[i++] = (byte)((GridY >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TargetBlock --\n"; output += "GridX: " + GridX.ToString() + "\n"; output += "GridY: " + GridY.ToString() + "\n"; output = output.Trim(); return output; } } /// DataBlock block public class DataBlockBlock { private byte[] _stringvalue; /// StringValue field public byte[] StringValue { get { return _stringvalue; } set { if (value == null) { _stringvalue = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _stringvalue = new byte[value.Length]; Array.Copy(value, _stringvalue, value.Length); } } } /// TaskID field public LLUUID TaskID; /// ItemID field public LLUUID ItemID; /// IntValue field public uint IntValue; /// ChannelID field public LLUUID ChannelID; /// Length of this block serialized in bytes public int Length { get { int length = 52; if (StringValue != null) { length += 2 + StringValue.Length; } return length; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _stringvalue = new byte[length]; Array.Copy(bytes, i, _stringvalue, 0, length); i += length; TaskID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; IntValue = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ChannelID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(StringValue == null) { Console.WriteLine("Warning: StringValue is null, in " + this.GetType()); } bytes[i++] = (byte)(StringValue.Length % 256); bytes[i++] = (byte)((StringValue.Length >> 8) % 256); Array.Copy(StringValue, 0, bytes, i, StringValue.Length); i += StringValue.Length; if(TaskID == null) { Console.WriteLine("Warning: TaskID is null, in " + this.GetType()); } Array.Copy(TaskID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(IntValue % 256); bytes[i++] = (byte)((IntValue >> 8) % 256); bytes[i++] = (byte)((IntValue >> 16) % 256); bytes[i++] = (byte)((IntValue >> 24) % 256); if(ChannelID == null) { Console.WriteLine("Warning: ChannelID is null, in " + this.GetType()); } Array.Copy(ChannelID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += Helpers.FieldToString(StringValue, "StringValue") + "\n"; output += "TaskID: " + TaskID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "IntValue: " + IntValue.ToString() + "\n"; output += "ChannelID: " + ChannelID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RpcScriptRequestInbound public override PacketType Type { get { return PacketType.RpcScriptRequestInbound; } } /// TargetBlock block public TargetBlockBlock TargetBlock; /// DataBlock block public DataBlockBlock DataBlock; /// Default constructor public RpcScriptRequestInboundPacket() { Header = new LowHeader(); Header.ID = 499; Header.Reliable = true; TargetBlock = new TargetBlockBlock(); DataBlock = new DataBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RpcScriptRequestInboundPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TargetBlock = new TargetBlockBlock(bytes, ref i); DataBlock = new DataBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RpcScriptRequestInboundPacket(Header head, byte[] bytes, ref int i) { Header = head; TargetBlock = new TargetBlockBlock(bytes, ref i); DataBlock = new DataBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TargetBlock.Length; length += DataBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TargetBlock.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RpcScriptRequestInbound ---\n"; output += TargetBlock.ToString() + "\n"; output += DataBlock.ToString() + "\n"; return output; } } /// RpcScriptRequestInboundForward packet public class RpcScriptRequestInboundForwardPacket : Packet { /// DataBlock block public class DataBlockBlock { /// RPCServerIP field public uint RPCServerIP; private byte[] _stringvalue; /// StringValue field public byte[] StringValue { get { return _stringvalue; } set { if (value == null) { _stringvalue = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _stringvalue = new byte[value.Length]; Array.Copy(value, _stringvalue, value.Length); } } } /// TaskID field public LLUUID TaskID; /// ItemID field public LLUUID ItemID; /// IntValue field public uint IntValue; /// ChannelID field public LLUUID ChannelID; /// RPCServerPort field public ushort RPCServerPort; /// Length of this block serialized in bytes public int Length { get { int length = 58; if (StringValue != null) { length += 2 + StringValue.Length; } return length; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { int length; try { RPCServerIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _stringvalue = new byte[length]; Array.Copy(bytes, i, _stringvalue, 0, length); i += length; TaskID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; IntValue = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ChannelID = new LLUUID(bytes, i); i += 16; RPCServerPort = (ushort)((bytes[i++] << 8) + bytes[i++]); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(RPCServerIP % 256); bytes[i++] = (byte)((RPCServerIP >> 8) % 256); bytes[i++] = (byte)((RPCServerIP >> 16) % 256); bytes[i++] = (byte)((RPCServerIP >> 24) % 256); if(StringValue == null) { Console.WriteLine("Warning: StringValue is null, in " + this.GetType()); } bytes[i++] = (byte)(StringValue.Length % 256); bytes[i++] = (byte)((StringValue.Length >> 8) % 256); Array.Copy(StringValue, 0, bytes, i, StringValue.Length); i += StringValue.Length; if(TaskID == null) { Console.WriteLine("Warning: TaskID is null, in " + this.GetType()); } Array.Copy(TaskID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(IntValue % 256); bytes[i++] = (byte)((IntValue >> 8) % 256); bytes[i++] = (byte)((IntValue >> 16) % 256); bytes[i++] = (byte)((IntValue >> 24) % 256); if(ChannelID == null) { Console.WriteLine("Warning: ChannelID is null, in " + this.GetType()); } Array.Copy(ChannelID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((RPCServerPort >> 8) % 256); bytes[i++] = (byte)(RPCServerPort % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "RPCServerIP: " + RPCServerIP.ToString() + "\n"; output += Helpers.FieldToString(StringValue, "StringValue") + "\n"; output += "TaskID: " + TaskID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "IntValue: " + IntValue.ToString() + "\n"; output += "ChannelID: " + ChannelID.ToString() + "\n"; output += "RPCServerPort: " + RPCServerPort.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RpcScriptRequestInboundForward public override PacketType Type { get { return PacketType.RpcScriptRequestInboundForward; } } /// DataBlock block public DataBlockBlock DataBlock; /// Default constructor public RpcScriptRequestInboundForwardPacket() { Header = new LowHeader(); Header.ID = 500; Header.Reliable = true; DataBlock = new DataBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RpcScriptRequestInboundForwardPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); DataBlock = new DataBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RpcScriptRequestInboundForwardPacket(Header head, byte[] bytes, ref int i) { Header = head; DataBlock = new DataBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += DataBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RpcScriptRequestInboundForward ---\n"; output += DataBlock.ToString() + "\n"; return output; } } /// RpcScriptReplyInbound packet public class RpcScriptReplyInboundPacket : Packet { /// DataBlock block public class DataBlockBlock { private byte[] _stringvalue; /// StringValue field public byte[] StringValue { get { return _stringvalue; } set { if (value == null) { _stringvalue = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _stringvalue = new byte[value.Length]; Array.Copy(value, _stringvalue, value.Length); } } } /// TaskID field public LLUUID TaskID; /// ItemID field public LLUUID ItemID; /// IntValue field public uint IntValue; /// ChannelID field public LLUUID ChannelID; /// Length of this block serialized in bytes public int Length { get { int length = 52; if (StringValue != null) { length += 2 + StringValue.Length; } return length; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _stringvalue = new byte[length]; Array.Copy(bytes, i, _stringvalue, 0, length); i += length; TaskID = new LLUUID(bytes, i); i += 16; ItemID = new LLUUID(bytes, i); i += 16; IntValue = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ChannelID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(StringValue == null) { Console.WriteLine("Warning: StringValue is null, in " + this.GetType()); } bytes[i++] = (byte)(StringValue.Length % 256); bytes[i++] = (byte)((StringValue.Length >> 8) % 256); Array.Copy(StringValue, 0, bytes, i, StringValue.Length); i += StringValue.Length; if(TaskID == null) { Console.WriteLine("Warning: TaskID is null, in " + this.GetType()); } Array.Copy(TaskID.GetBytes(), 0, bytes, i, 16); i += 16; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(IntValue % 256); bytes[i++] = (byte)((IntValue >> 8) % 256); bytes[i++] = (byte)((IntValue >> 16) % 256); bytes[i++] = (byte)((IntValue >> 24) % 256); if(ChannelID == null) { Console.WriteLine("Warning: ChannelID is null, in " + this.GetType()); } Array.Copy(ChannelID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += Helpers.FieldToString(StringValue, "StringValue") + "\n"; output += "TaskID: " + TaskID.ToString() + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "IntValue: " + IntValue.ToString() + "\n"; output += "ChannelID: " + ChannelID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RpcScriptReplyInbound public override PacketType Type { get { return PacketType.RpcScriptReplyInbound; } } /// DataBlock block public DataBlockBlock DataBlock; /// Default constructor public RpcScriptReplyInboundPacket() { Header = new LowHeader(); Header.ID = 501; Header.Reliable = true; DataBlock = new DataBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RpcScriptReplyInboundPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); DataBlock = new DataBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RpcScriptReplyInboundPacket(Header head, byte[] bytes, ref int i) { Header = head; DataBlock = new DataBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += DataBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RpcScriptReplyInbound ---\n"; output += DataBlock.ToString() + "\n"; return output; } } /// MailTaskSimRequest packet public class MailTaskSimRequestPacket : Packet { /// DataBlock block public class DataBlockBlock { /// TaskID field public LLUUID TaskID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { try { TaskID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TaskID == null) { Console.WriteLine("Warning: TaskID is null, in " + this.GetType()); } Array.Copy(TaskID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "TaskID: " + TaskID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MailTaskSimRequest public override PacketType Type { get { return PacketType.MailTaskSimRequest; } } /// DataBlock block public DataBlockBlock DataBlock; /// Default constructor public MailTaskSimRequestPacket() { Header = new LowHeader(); Header.ID = 502; Header.Reliable = true; DataBlock = new DataBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MailTaskSimRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); DataBlock = new DataBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MailTaskSimRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; DataBlock = new DataBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += DataBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MailTaskSimRequest ---\n"; output += DataBlock.ToString() + "\n"; return output; } } /// MailTaskSimReply packet public class MailTaskSimReplyPacket : Packet { /// TargetBlock block public class TargetBlockBlock { private byte[] _targetip; /// TargetIP field public byte[] TargetIP { get { return _targetip; } set { if (value == null) { _targetip = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _targetip = new byte[value.Length]; Array.Copy(value, _targetip, value.Length); } } } /// TargetPort field public ushort TargetPort; /// Length of this block serialized in bytes public int Length { get { int length = 2; if (TargetIP != null) { length += 1 + TargetIP.Length; } return length; } } /// Default constructor public TargetBlockBlock() { } /// Constructor for building the block from a byte array public TargetBlockBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _targetip = new byte[length]; Array.Copy(bytes, i, _targetip, 0, length); i += length; TargetPort = (ushort)((bytes[i++] << 8) + bytes[i++]); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TargetIP == null) { Console.WriteLine("Warning: TargetIP is null, in " + this.GetType()); } bytes[i++] = (byte)TargetIP.Length; Array.Copy(TargetIP, 0, bytes, i, TargetIP.Length); i += TargetIP.Length; bytes[i++] = (byte)((TargetPort >> 8) % 256); bytes[i++] = (byte)(TargetPort % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TargetBlock --\n"; output += Helpers.FieldToString(TargetIP, "TargetIP") + "\n"; output += "TargetPort: " + TargetPort.ToString() + "\n"; output = output.Trim(); return output; } } /// DataBlock block public class DataBlockBlock { /// TaskID field public LLUUID TaskID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { try { TaskID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TaskID == null) { Console.WriteLine("Warning: TaskID is null, in " + this.GetType()); } Array.Copy(TaskID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "TaskID: " + TaskID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MailTaskSimReply public override PacketType Type { get { return PacketType.MailTaskSimReply; } } /// TargetBlock block public TargetBlockBlock TargetBlock; /// DataBlock block public DataBlockBlock DataBlock; /// Default constructor public MailTaskSimReplyPacket() { Header = new LowHeader(); Header.ID = 503; Header.Reliable = true; TargetBlock = new TargetBlockBlock(); DataBlock = new DataBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MailTaskSimReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TargetBlock = new TargetBlockBlock(bytes, ref i); DataBlock = new DataBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MailTaskSimReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; TargetBlock = new TargetBlockBlock(bytes, ref i); DataBlock = new DataBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TargetBlock.Length; length += DataBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TargetBlock.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MailTaskSimReply ---\n"; output += TargetBlock.ToString() + "\n"; output += DataBlock.ToString() + "\n"; return output; } } /// ScriptMailRegistration packet public class ScriptMailRegistrationPacket : Packet { /// DataBlock block public class DataBlockBlock { private byte[] _targetip; /// TargetIP field public byte[] TargetIP { get { return _targetip; } set { if (value == null) { _targetip = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _targetip = new byte[value.Length]; Array.Copy(value, _targetip, value.Length); } } } /// TaskID field public LLUUID TaskID; /// TargetPort field public ushort TargetPort; /// Flags field public uint Flags; /// Length of this block serialized in bytes public int Length { get { int length = 22; if (TargetIP != null) { length += 1 + TargetIP.Length; } return length; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _targetip = new byte[length]; Array.Copy(bytes, i, _targetip, 0, length); i += length; TaskID = new LLUUID(bytes, i); i += 16; TargetPort = (ushort)((bytes[i++] << 8) + bytes[i++]); Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TargetIP == null) { Console.WriteLine("Warning: TargetIP is null, in " + this.GetType()); } bytes[i++] = (byte)TargetIP.Length; Array.Copy(TargetIP, 0, bytes, i, TargetIP.Length); i += TargetIP.Length; if(TaskID == null) { Console.WriteLine("Warning: TaskID is null, in " + this.GetType()); } Array.Copy(TaskID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((TargetPort >> 8) % 256); bytes[i++] = (byte)(TargetPort % 256); bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += Helpers.FieldToString(TargetIP, "TargetIP") + "\n"; output += "TaskID: " + TaskID.ToString() + "\n"; output += "TargetPort: " + TargetPort.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ScriptMailRegistration public override PacketType Type { get { return PacketType.ScriptMailRegistration; } } /// DataBlock block public DataBlockBlock DataBlock; /// Default constructor public ScriptMailRegistrationPacket() { Header = new LowHeader(); Header.ID = 504; Header.Reliable = true; DataBlock = new DataBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ScriptMailRegistrationPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); DataBlock = new DataBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ScriptMailRegistrationPacket(Header head, byte[] bytes, ref int i) { Header = head; DataBlock = new DataBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += DataBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ScriptMailRegistration ---\n"; output += DataBlock.ToString() + "\n"; return output; } } /// ParcelMediaCommandMessage packet public class ParcelMediaCommandMessagePacket : Packet { /// CommandBlock block public class CommandBlockBlock { /// Command field public uint Command; /// Time field public float Time; /// Flags field public uint Flags; /// Length of this block serialized in bytes public int Length { get { return 12; } } /// Default constructor public CommandBlockBlock() { } /// Constructor for building the block from a byte array public CommandBlockBlock(byte[] bytes, ref int i) { try { Command = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Time = BitConverter.ToSingle(bytes, i); i += 4; Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = (byte)(Command % 256); bytes[i++] = (byte)((Command >> 8) % 256); bytes[i++] = (byte)((Command >> 16) % 256); bytes[i++] = (byte)((Command >> 24) % 256); ba = BitConverter.GetBytes(Time); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- CommandBlock --\n"; output += "Command: " + Command.ToString() + "\n"; output += "Time: " + Time.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelMediaCommandMessage public override PacketType Type { get { return PacketType.ParcelMediaCommandMessage; } } /// CommandBlock block public CommandBlockBlock CommandBlock; /// Default constructor public ParcelMediaCommandMessagePacket() { Header = new LowHeader(); Header.ID = 505; Header.Reliable = true; CommandBlock = new CommandBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelMediaCommandMessagePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); CommandBlock = new CommandBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelMediaCommandMessagePacket(Header head, byte[] bytes, ref int i) { Header = head; CommandBlock = new CommandBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += CommandBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); CommandBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelMediaCommandMessage ---\n"; output += CommandBlock.ToString() + "\n"; return output; } } /// ParcelMediaUpdate packet public class ParcelMediaUpdatePacket : Packet { /// DataBlock block public class DataBlockBlock { /// MediaID field public LLUUID MediaID; private byte[] _mediaurl; /// MediaURL field public byte[] MediaURL { get { return _mediaurl; } set { if (value == null) { _mediaurl = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _mediaurl = new byte[value.Length]; Array.Copy(value, _mediaurl, value.Length); } } } /// MediaAutoScale field public byte MediaAutoScale; /// Length of this block serialized in bytes public int Length { get { int length = 17; if (MediaURL != null) { length += 1 + MediaURL.Length; } return length; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { int length; try { MediaID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _mediaurl = new byte[length]; Array.Copy(bytes, i, _mediaurl, 0, length); i += length; MediaAutoScale = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(MediaID == null) { Console.WriteLine("Warning: MediaID is null, in " + this.GetType()); } Array.Copy(MediaID.GetBytes(), 0, bytes, i, 16); i += 16; if(MediaURL == null) { Console.WriteLine("Warning: MediaURL is null, in " + this.GetType()); } bytes[i++] = (byte)MediaURL.Length; Array.Copy(MediaURL, 0, bytes, i, MediaURL.Length); i += MediaURL.Length; bytes[i++] = MediaAutoScale; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "MediaID: " + MediaID.ToString() + "\n"; output += Helpers.FieldToString(MediaURL, "MediaURL") + "\n"; output += "MediaAutoScale: " + MediaAutoScale.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelMediaUpdate public override PacketType Type { get { return PacketType.ParcelMediaUpdate; } } /// DataBlock block public DataBlockBlock DataBlock; /// Default constructor public ParcelMediaUpdatePacket() { Header = new LowHeader(); Header.ID = 506; Header.Reliable = true; DataBlock = new DataBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelMediaUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); DataBlock = new DataBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelMediaUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; DataBlock = new DataBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += DataBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelMediaUpdate ---\n"; output += DataBlock.ToString() + "\n"; return output; } } /// LandStatRequest packet public class LandStatRequestPacket : Packet { /// RequestData block public class RequestDataBlock { /// RequestFlags field public uint RequestFlags; /// ReportType field public uint ReportType; private byte[] _filter; /// Filter field public byte[] Filter { get { return _filter; } set { if (value == null) { _filter = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _filter = new byte[value.Length]; Array.Copy(value, _filter, value.Length); } } } /// ParcelLocalID field public int ParcelLocalID; /// Length of this block serialized in bytes public int Length { get { int length = 12; if (Filter != null) { length += 1 + Filter.Length; } return length; } } /// Default constructor public RequestDataBlock() { } /// Constructor for building the block from a byte array public RequestDataBlock(byte[] bytes, ref int i) { int length; try { RequestFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ReportType = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _filter = new byte[length]; Array.Copy(bytes, i, _filter, 0, length); i += length; ParcelLocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(RequestFlags % 256); bytes[i++] = (byte)((RequestFlags >> 8) % 256); bytes[i++] = (byte)((RequestFlags >> 16) % 256); bytes[i++] = (byte)((RequestFlags >> 24) % 256); bytes[i++] = (byte)(ReportType % 256); bytes[i++] = (byte)((ReportType >> 8) % 256); bytes[i++] = (byte)((ReportType >> 16) % 256); bytes[i++] = (byte)((ReportType >> 24) % 256); if(Filter == null) { Console.WriteLine("Warning: Filter is null, in " + this.GetType()); } bytes[i++] = (byte)Filter.Length; Array.Copy(Filter, 0, bytes, i, Filter.Length); i += Filter.Length; bytes[i++] = (byte)(ParcelLocalID % 256); bytes[i++] = (byte)((ParcelLocalID >> 8) % 256); bytes[i++] = (byte)((ParcelLocalID >> 16) % 256); bytes[i++] = (byte)((ParcelLocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RequestData --\n"; output += "RequestFlags: " + RequestFlags.ToString() + "\n"; output += "ReportType: " + ReportType.ToString() + "\n"; output += Helpers.FieldToString(Filter, "Filter") + "\n"; output += "ParcelLocalID: " + ParcelLocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.LandStatRequest public override PacketType Type { get { return PacketType.LandStatRequest; } } /// RequestData block public RequestDataBlock RequestData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public LandStatRequestPacket() { Header = new LowHeader(); Header.ID = 507; Header.Reliable = true; RequestData = new RequestDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public LandStatRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); RequestData = new RequestDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public LandStatRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; RequestData = new RequestDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += RequestData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); RequestData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- LandStatRequest ---\n"; output += RequestData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// LandStatReply packet public class LandStatReplyPacket : Packet { /// RequestData block public class RequestDataBlock { /// RequestFlags field public uint RequestFlags; /// ReportType field public uint ReportType; /// TotalObjectCount field public uint TotalObjectCount; /// Length of this block serialized in bytes public int Length { get { return 12; } } /// Default constructor public RequestDataBlock() { } /// Constructor for building the block from a byte array public RequestDataBlock(byte[] bytes, ref int i) { try { RequestFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ReportType = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TotalObjectCount = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(RequestFlags % 256); bytes[i++] = (byte)((RequestFlags >> 8) % 256); bytes[i++] = (byte)((RequestFlags >> 16) % 256); bytes[i++] = (byte)((RequestFlags >> 24) % 256); bytes[i++] = (byte)(ReportType % 256); bytes[i++] = (byte)((ReportType >> 8) % 256); bytes[i++] = (byte)((ReportType >> 16) % 256); bytes[i++] = (byte)((ReportType >> 24) % 256); bytes[i++] = (byte)(TotalObjectCount % 256); bytes[i++] = (byte)((TotalObjectCount >> 8) % 256); bytes[i++] = (byte)((TotalObjectCount >> 16) % 256); bytes[i++] = (byte)((TotalObjectCount >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RequestData --\n"; output += "RequestFlags: " + RequestFlags.ToString() + "\n"; output += "ReportType: " + ReportType.ToString() + "\n"; output += "TotalObjectCount: " + TotalObjectCount.ToString() + "\n"; output = output.Trim(); return output; } } /// ReportData block public class ReportDataBlock { /// LocationX field public float LocationX; /// LocationY field public float LocationY; /// LocationZ field public float LocationZ; private byte[] _taskname; /// TaskName field public byte[] TaskName { get { return _taskname; } set { if (value == null) { _taskname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _taskname = new byte[value.Length]; Array.Copy(value, _taskname, value.Length); } } } /// TaskID field public LLUUID TaskID; /// Score field public float Score; /// TaskLocalID field public uint TaskLocalID; private byte[] _ownername; /// OwnerName field public byte[] OwnerName { get { return _ownername; } set { if (value == null) { _ownername = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _ownername = new byte[value.Length]; Array.Copy(value, _ownername, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 36; if (TaskName != null) { length += 1 + TaskName.Length; } if (OwnerName != null) { length += 1 + OwnerName.Length; } return length; } } /// Default constructor public ReportDataBlock() { } /// Constructor for building the block from a byte array public ReportDataBlock(byte[] bytes, ref int i) { int length; try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); LocationX = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); LocationY = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); LocationZ = BitConverter.ToSingle(bytes, i); i += 4; length = (ushort)bytes[i++]; _taskname = new byte[length]; Array.Copy(bytes, i, _taskname, 0, length); i += length; TaskID = new LLUUID(bytes, i); i += 16; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Score = BitConverter.ToSingle(bytes, i); i += 4; TaskLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _ownername = new byte[length]; Array.Copy(bytes, i, _ownername, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(LocationX); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(LocationY); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(LocationZ); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(TaskName == null) { Console.WriteLine("Warning: TaskName is null, in " + this.GetType()); } bytes[i++] = (byte)TaskName.Length; Array.Copy(TaskName, 0, bytes, i, TaskName.Length); i += TaskName.Length; if(TaskID == null) { Console.WriteLine("Warning: TaskID is null, in " + this.GetType()); } Array.Copy(TaskID.GetBytes(), 0, bytes, i, 16); i += 16; ba = BitConverter.GetBytes(Score); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(TaskLocalID % 256); bytes[i++] = (byte)((TaskLocalID >> 8) % 256); bytes[i++] = (byte)((TaskLocalID >> 16) % 256); bytes[i++] = (byte)((TaskLocalID >> 24) % 256); if(OwnerName == null) { Console.WriteLine("Warning: OwnerName is null, in " + this.GetType()); } bytes[i++] = (byte)OwnerName.Length; Array.Copy(OwnerName, 0, bytes, i, OwnerName.Length); i += OwnerName.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ReportData --\n"; output += "LocationX: " + LocationX.ToString() + "\n"; output += "LocationY: " + LocationY.ToString() + "\n"; output += "LocationZ: " + LocationZ.ToString() + "\n"; output += Helpers.FieldToString(TaskName, "TaskName") + "\n"; output += "TaskID: " + TaskID.ToString() + "\n"; output += "Score: " + Score.ToString() + "\n"; output += "TaskLocalID: " + TaskLocalID.ToString() + "\n"; output += Helpers.FieldToString(OwnerName, "OwnerName") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.LandStatReply public override PacketType Type { get { return PacketType.LandStatReply; } } /// RequestData block public RequestDataBlock RequestData; /// ReportData block public ReportDataBlock[] ReportData; /// Default constructor public LandStatReplyPacket() { Header = new LowHeader(); Header.ID = 508; Header.Reliable = true; RequestData = new RequestDataBlock(); ReportData = new ReportDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public LandStatReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); RequestData = new RequestDataBlock(bytes, ref i); int count = (int)bytes[i++]; ReportData = new ReportDataBlock[count]; for (int j = 0; j < count; j++) { ReportData[j] = new ReportDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public LandStatReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; RequestData = new RequestDataBlock(bytes, ref i); int count = (int)bytes[i++]; ReportData = new ReportDataBlock[count]; for (int j = 0; j < count; j++) { ReportData[j] = new ReportDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += RequestData.Length;; length++; for (int j = 0; j < ReportData.Length; j++) { length += ReportData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); RequestData.ToBytes(bytes, ref i); bytes[i++] = (byte)ReportData.Length; for (int j = 0; j < ReportData.Length; j++) { ReportData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- LandStatReply ---\n"; output += RequestData.ToString() + "\n"; for (int j = 0; j < ReportData.Length; j++) { output += ReportData[j].ToString() + "\n"; } return output; } } /// SecuredTemplateChecksumRequest packet public class SecuredTemplateChecksumRequestPacket : Packet { /// TokenBlock block public class TokenBlockBlock { /// Token field public LLUUID Token; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public TokenBlockBlock() { } /// Constructor for building the block from a byte array public TokenBlockBlock(byte[] bytes, ref int i) { try { Token = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Token == null) { Console.WriteLine("Warning: Token is null, in " + this.GetType()); } Array.Copy(Token.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TokenBlock --\n"; output += "Token: " + Token.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SecuredTemplateChecksumRequest public override PacketType Type { get { return PacketType.SecuredTemplateChecksumRequest; } } /// TokenBlock block public TokenBlockBlock TokenBlock; /// Default constructor public SecuredTemplateChecksumRequestPacket() { Header = new LowHeader(); Header.ID = 65530; Header.Reliable = true; TokenBlock = new TokenBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SecuredTemplateChecksumRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); TokenBlock = new TokenBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SecuredTemplateChecksumRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; TokenBlock = new TokenBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += TokenBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TokenBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SecuredTemplateChecksumRequest ---\n"; output += TokenBlock.ToString() + "\n"; return output; } } /// PacketAck packet public class PacketAckPacket : Packet { /// Packets block public class PacketsBlock { /// ID field public uint ID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public PacketsBlock() { } /// Constructor for building the block from a byte array public PacketsBlock(byte[] bytes, ref int i) { try { ID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ID % 256); bytes[i++] = (byte)((ID >> 8) % 256); bytes[i++] = (byte)((ID >> 16) % 256); bytes[i++] = (byte)((ID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Packets --\n"; output += "ID: " + ID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.PacketAck public override PacketType Type { get { return PacketType.PacketAck; } } /// Packets block public PacketsBlock[] Packets; /// Default constructor public PacketAckPacket() { Header = new LowHeader(); Header.ID = 65531; Header.Reliable = true; Packets = new PacketsBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public PacketAckPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; Packets = new PacketsBlock[count]; for (int j = 0; j < count; j++) { Packets[j] = new PacketsBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public PacketAckPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; Packets = new PacketsBlock[count]; for (int j = 0; j < count; j++) { Packets[j] = new PacketsBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; length++; for (int j = 0; j < Packets.Length; j++) { length += Packets[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)Packets.Length; for (int j = 0; j < Packets.Length; j++) { Packets[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- PacketAck ---\n"; for (int j = 0; j < Packets.Length; j++) { output += Packets[j].ToString() + "\n"; } return output; } } /// OpenCircuit packet public class OpenCircuitPacket : Packet { /// CircuitInfo block public class CircuitInfoBlock { /// IP field public uint IP; /// Port field public ushort Port; /// Length of this block serialized in bytes public int Length { get { return 6; } } /// Default constructor public CircuitInfoBlock() { } /// Constructor for building the block from a byte array public CircuitInfoBlock(byte[] bytes, ref int i) { try { IP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Port = (ushort)((bytes[i++] << 8) + bytes[i++]); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(IP % 256); bytes[i++] = (byte)((IP >> 8) % 256); bytes[i++] = (byte)((IP >> 16) % 256); bytes[i++] = (byte)((IP >> 24) % 256); bytes[i++] = (byte)((Port >> 8) % 256); bytes[i++] = (byte)(Port % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- CircuitInfo --\n"; output += "IP: " + IP.ToString() + "\n"; output += "Port: " + Port.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.OpenCircuit public override PacketType Type { get { return PacketType.OpenCircuit; } } /// CircuitInfo block public CircuitInfoBlock CircuitInfo; /// Default constructor public OpenCircuitPacket() { Header = new LowHeader(); Header.ID = 65532; Header.Reliable = true; CircuitInfo = new CircuitInfoBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public OpenCircuitPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); CircuitInfo = new CircuitInfoBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public OpenCircuitPacket(Header head, byte[] bytes, ref int i) { Header = head; CircuitInfo = new CircuitInfoBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += CircuitInfo.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); CircuitInfo.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- OpenCircuit ---\n"; output += CircuitInfo.ToString() + "\n"; return output; } } /// CloseCircuit packet public class CloseCircuitPacket : Packet { private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.CloseCircuit public override PacketType Type { get { return PacketType.CloseCircuit; } } /// Default constructor public CloseCircuitPacket() { Header = new LowHeader(); Header.ID = 65533; Header.Reliable = true; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public CloseCircuitPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); } /// Constructor that takes a byte array and a prebuilt header public CloseCircuitPacket(Header head, byte[] bytes, ref int i) { Header = head; } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- CloseCircuit ---\n"; return output; } } /// TemplateChecksumRequest packet public class TemplateChecksumRequestPacket : Packet { private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TemplateChecksumRequest public override PacketType Type { get { return PacketType.TemplateChecksumRequest; } } /// Default constructor public TemplateChecksumRequestPacket() { Header = new LowHeader(); Header.ID = 65534; Header.Reliable = true; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TemplateChecksumRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); } /// Constructor that takes a byte array and a prebuilt header public TemplateChecksumRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; ; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TemplateChecksumRequest ---\n"; return output; } } /// TemplateChecksumReply packet public class TemplateChecksumReplyPacket : Packet { /// DataBlock block public class DataBlockBlock { /// ServerVersion field public byte ServerVersion; /// PatchVersion field public byte PatchVersion; /// Checksum field public uint Checksum; /// Flags field public uint Flags; /// MajorVersion field public byte MajorVersion; /// MinorVersion field public byte MinorVersion; /// Length of this block serialized in bytes public int Length { get { return 12; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { try { ServerVersion = (byte)bytes[i++]; PatchVersion = (byte)bytes[i++]; Checksum = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Flags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); MajorVersion = (byte)bytes[i++]; MinorVersion = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = ServerVersion; bytes[i++] = PatchVersion; bytes[i++] = (byte)(Checksum % 256); bytes[i++] = (byte)((Checksum >> 8) % 256); bytes[i++] = (byte)((Checksum >> 16) % 256); bytes[i++] = (byte)((Checksum >> 24) % 256); bytes[i++] = (byte)(Flags % 256); bytes[i++] = (byte)((Flags >> 8) % 256); bytes[i++] = (byte)((Flags >> 16) % 256); bytes[i++] = (byte)((Flags >> 24) % 256); bytes[i++] = MajorVersion; bytes[i++] = MinorVersion; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "ServerVersion: " + ServerVersion.ToString() + "\n"; output += "PatchVersion: " + PatchVersion.ToString() + "\n"; output += "Checksum: " + Checksum.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "MajorVersion: " + MajorVersion.ToString() + "\n"; output += "MinorVersion: " + MinorVersion.ToString() + "\n"; output = output.Trim(); return output; } } /// TokenBlock block public class TokenBlockBlock { /// Token field public LLUUID Token; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public TokenBlockBlock() { } /// Constructor for building the block from a byte array public TokenBlockBlock(byte[] bytes, ref int i) { try { Token = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Token == null) { Console.WriteLine("Warning: Token is null, in " + this.GetType()); } Array.Copy(Token.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TokenBlock --\n"; output += "Token: " + Token.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TemplateChecksumReply public override PacketType Type { get { return PacketType.TemplateChecksumReply; } } /// DataBlock block public DataBlockBlock DataBlock; /// TokenBlock block public TokenBlockBlock TokenBlock; /// Default constructor public TemplateChecksumReplyPacket() { Header = new LowHeader(); Header.ID = 65535; Header.Reliable = true; DataBlock = new DataBlockBlock(); TokenBlock = new TokenBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TemplateChecksumReplyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new LowHeader(bytes, ref i, ref packetEnd); DataBlock = new DataBlockBlock(bytes, ref i); TokenBlock = new TokenBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TemplateChecksumReplyPacket(Header head, byte[] bytes, ref int i) { Header = head; DataBlock = new DataBlockBlock(bytes, ref i); TokenBlock = new TokenBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 8; length += DataBlock.Length; length += TokenBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); TokenBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TemplateChecksumReply ---\n"; output += DataBlock.ToString() + "\n"; output += TokenBlock.ToString() + "\n"; return output; } } /// ClosestSimulator packet public class ClosestSimulatorPacket : Packet { /// SimulatorBlock block public class SimulatorBlockBlock { /// IP field public uint IP; /// Port field public ushort Port; /// Handle field public ulong Handle; /// Length of this block serialized in bytes public int Length { get { return 14; } } /// Default constructor public SimulatorBlockBlock() { } /// Constructor for building the block from a byte array public SimulatorBlockBlock(byte[] bytes, ref int i) { try { IP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Port = (ushort)((bytes[i++] << 8) + bytes[i++]); Handle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(IP % 256); bytes[i++] = (byte)((IP >> 8) % 256); bytes[i++] = (byte)((IP >> 16) % 256); bytes[i++] = (byte)((IP >> 24) % 256); bytes[i++] = (byte)((Port >> 8) % 256); bytes[i++] = (byte)(Port % 256); bytes[i++] = (byte)(Handle % 256); bytes[i++] = (byte)((Handle >> 8) % 256); bytes[i++] = (byte)((Handle >> 16) % 256); bytes[i++] = (byte)((Handle >> 24) % 256); bytes[i++] = (byte)((Handle >> 32) % 256); bytes[i++] = (byte)((Handle >> 40) % 256); bytes[i++] = (byte)((Handle >> 48) % 256); bytes[i++] = (byte)((Handle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- SimulatorBlock --\n"; output += "IP: " + IP.ToString() + "\n"; output += "Port: " + Port.ToString() + "\n"; output += "Handle: " + Handle.ToString() + "\n"; output = output.Trim(); return output; } } /// Viewer block public class ViewerBlock { /// ID field public LLUUID ID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ViewerBlock() { } /// Constructor for building the block from a byte array public ViewerBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Viewer --\n"; output += "ID: " + ID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ClosestSimulator public override PacketType Type { get { return PacketType.ClosestSimulator; } } /// SimulatorBlock block public SimulatorBlockBlock SimulatorBlock; /// Viewer block public ViewerBlock Viewer; /// Default constructor public ClosestSimulatorPacket() { Header = new MediumHeader(); Header.ID = 1; Header.Reliable = true; SimulatorBlock = new SimulatorBlockBlock(); Viewer = new ViewerBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ClosestSimulatorPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); SimulatorBlock = new SimulatorBlockBlock(bytes, ref i); Viewer = new ViewerBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ClosestSimulatorPacket(Header head, byte[] bytes, ref int i) { Header = head; SimulatorBlock = new SimulatorBlockBlock(bytes, ref i); Viewer = new ViewerBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; length += SimulatorBlock.Length; length += Viewer.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); SimulatorBlock.ToBytes(bytes, ref i); Viewer.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ClosestSimulator ---\n"; output += SimulatorBlock.ToString() + "\n"; output += Viewer.ToString() + "\n"; return output; } } /// ObjectAdd packet public class ObjectAddPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// AddFlags field public uint AddFlags; /// PathTwistBegin field public sbyte PathTwistBegin; /// PathEnd field public byte PathEnd; /// ProfileBegin field public byte ProfileBegin; /// PathRadiusOffset field public sbyte PathRadiusOffset; /// PathSkew field public sbyte PathSkew; /// RayStart field public LLVector3 RayStart; /// ProfileCurve field public byte ProfileCurve; /// PathScaleX field public byte PathScaleX; /// PathScaleY field public byte PathScaleY; /// Material field public byte Material; /// PathShearX field public byte PathShearX; /// PathShearY field public byte PathShearY; /// PathTaperX field public sbyte PathTaperX; /// PathTaperY field public sbyte PathTaperY; /// RayEndIsIntersection field public byte RayEndIsIntersection; /// RayEnd field public LLVector3 RayEnd; /// ProfileEnd field public byte ProfileEnd; /// PathBegin field public byte PathBegin; /// BypassRaycast field public byte BypassRaycast; /// PCode field public byte PCode; /// PathCurve field public byte PathCurve; /// Scale field public LLVector3 Scale; /// State field public byte State; /// PathTwist field public sbyte PathTwist; private byte[] _textureentry; /// TextureEntry field public byte[] TextureEntry { get { return _textureentry; } set { if (value == null) { _textureentry = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _textureentry = new byte[value.Length]; Array.Copy(value, _textureentry, value.Length); } } } /// ProfileHollow field public byte ProfileHollow; /// PathRevolutions field public byte PathRevolutions; /// Rotation field public LLQuaternion Rotation; /// RayTargetID field public LLUUID RayTargetID; /// Length of this block serialized in bytes public int Length { get { int length = 91; if (TextureEntry != null) { length += 2 + TextureEntry.Length; } return length; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { int length; try { AddFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); PathTwistBegin = (sbyte)bytes[i++]; PathEnd = (byte)bytes[i++]; ProfileBegin = (byte)bytes[i++]; PathRadiusOffset = (sbyte)bytes[i++]; PathSkew = (sbyte)bytes[i++]; RayStart = new LLVector3(bytes, i); i += 12; ProfileCurve = (byte)bytes[i++]; PathScaleX = (byte)bytes[i++]; PathScaleY = (byte)bytes[i++]; Material = (byte)bytes[i++]; PathShearX = (byte)bytes[i++]; PathShearY = (byte)bytes[i++]; PathTaperX = (sbyte)bytes[i++]; PathTaperY = (sbyte)bytes[i++]; RayEndIsIntersection = (byte)bytes[i++]; RayEnd = new LLVector3(bytes, i); i += 12; ProfileEnd = (byte)bytes[i++]; PathBegin = (byte)bytes[i++]; BypassRaycast = (byte)bytes[i++]; PCode = (byte)bytes[i++]; PathCurve = (byte)bytes[i++]; Scale = new LLVector3(bytes, i); i += 12; State = (byte)bytes[i++]; PathTwist = (sbyte)bytes[i++]; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _textureentry = new byte[length]; Array.Copy(bytes, i, _textureentry, 0, length); i += length; ProfileHollow = (byte)bytes[i++]; PathRevolutions = (byte)bytes[i++]; Rotation = new LLQuaternion(bytes, i, true); i += 12; RayTargetID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(AddFlags % 256); bytes[i++] = (byte)((AddFlags >> 8) % 256); bytes[i++] = (byte)((AddFlags >> 16) % 256); bytes[i++] = (byte)((AddFlags >> 24) % 256); bytes[i++] = (byte)PathTwistBegin; bytes[i++] = PathEnd; bytes[i++] = ProfileBegin; bytes[i++] = (byte)PathRadiusOffset; bytes[i++] = (byte)PathSkew; if(RayStart == null) { Console.WriteLine("Warning: RayStart is null, in " + this.GetType()); } Array.Copy(RayStart.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = ProfileCurve; bytes[i++] = PathScaleX; bytes[i++] = PathScaleY; bytes[i++] = Material; bytes[i++] = PathShearX; bytes[i++] = PathShearY; bytes[i++] = (byte)PathTaperX; bytes[i++] = (byte)PathTaperY; bytes[i++] = RayEndIsIntersection; if(RayEnd == null) { Console.WriteLine("Warning: RayEnd is null, in " + this.GetType()); } Array.Copy(RayEnd.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = ProfileEnd; bytes[i++] = PathBegin; bytes[i++] = BypassRaycast; bytes[i++] = PCode; bytes[i++] = PathCurve; if(Scale == null) { Console.WriteLine("Warning: Scale is null, in " + this.GetType()); } Array.Copy(Scale.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = State; bytes[i++] = (byte)PathTwist; if(TextureEntry == null) { Console.WriteLine("Warning: TextureEntry is null, in " + this.GetType()); } bytes[i++] = (byte)(TextureEntry.Length % 256); bytes[i++] = (byte)((TextureEntry.Length >> 8) % 256); Array.Copy(TextureEntry, 0, bytes, i, TextureEntry.Length); i += TextureEntry.Length; bytes[i++] = ProfileHollow; bytes[i++] = PathRevolutions; if(Rotation == null) { Console.WriteLine("Warning: Rotation is null, in " + this.GetType()); } Array.Copy(Rotation.GetBytes(), 0, bytes, i, 12); i += 12; if(RayTargetID == null) { Console.WriteLine("Warning: RayTargetID is null, in " + this.GetType()); } Array.Copy(RayTargetID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "AddFlags: " + AddFlags.ToString() + "\n"; output += "PathTwistBegin: " + PathTwistBegin.ToString() + "\n"; output += "PathEnd: " + PathEnd.ToString() + "\n"; output += "ProfileBegin: " + ProfileBegin.ToString() + "\n"; output += "PathRadiusOffset: " + PathRadiusOffset.ToString() + "\n"; output += "PathSkew: " + PathSkew.ToString() + "\n"; output += "RayStart: " + RayStart.ToString() + "\n"; output += "ProfileCurve: " + ProfileCurve.ToString() + "\n"; output += "PathScaleX: " + PathScaleX.ToString() + "\n"; output += "PathScaleY: " + PathScaleY.ToString() + "\n"; output += "Material: " + Material.ToString() + "\n"; output += "PathShearX: " + PathShearX.ToString() + "\n"; output += "PathShearY: " + PathShearY.ToString() + "\n"; output += "PathTaperX: " + PathTaperX.ToString() + "\n"; output += "PathTaperY: " + PathTaperY.ToString() + "\n"; output += "RayEndIsIntersection: " + RayEndIsIntersection.ToString() + "\n"; output += "RayEnd: " + RayEnd.ToString() + "\n"; output += "ProfileEnd: " + ProfileEnd.ToString() + "\n"; output += "PathBegin: " + PathBegin.ToString() + "\n"; output += "BypassRaycast: " + BypassRaycast.ToString() + "\n"; output += "PCode: " + PCode.ToString() + "\n"; output += "PathCurve: " + PathCurve.ToString() + "\n"; output += "Scale: " + Scale.ToString() + "\n"; output += "State: " + State.ToString() + "\n"; output += "PathTwist: " + PathTwist.ToString() + "\n"; output += Helpers.FieldToString(TextureEntry, "TextureEntry") + "\n"; output += "ProfileHollow: " + ProfileHollow.ToString() + "\n"; output += "PathRevolutions: " + PathRevolutions.ToString() + "\n"; output += "Rotation: " + Rotation.ToString() + "\n"; output += "RayTargetID: " + RayTargetID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// GroupID field public LLUUID GroupID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectAdd public override PacketType Type { get { return PacketType.ObjectAdd; } } /// ObjectData block public ObjectDataBlock ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectAddPacket() { Header = new MediumHeader(); Header.ID = 2; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectAddPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); ObjectData = new ObjectDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectAddPacket(Header head, byte[] bytes, ref int i) { Header = head; ObjectData = new ObjectDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; length += ObjectData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ObjectData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectAdd ---\n"; output += ObjectData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// MultipleObjectUpdate packet public class MultipleObjectUpdatePacket : Packet { /// ObjectData block public class ObjectDataBlock { private byte[] _data; /// Data field public byte[] Data { get { return _data; } set { if (value == null) { _data = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _data = new byte[value.Length]; Array.Copy(value, _data, value.Length); } } } /// Type field public byte Type; /// ObjectLocalID field public uint ObjectLocalID; /// Length of this block serialized in bytes public int Length { get { int length = 5; if (Data != null) { length += 1 + Data.Length; } return length; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _data = new byte[length]; Array.Copy(bytes, i, _data, 0, length); i += length; Type = (byte)bytes[i++]; ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Data == null) { Console.WriteLine("Warning: Data is null, in " + this.GetType()); } bytes[i++] = (byte)Data.Length; Array.Copy(Data, 0, bytes, i, Data.Length); i += Data.Length; bytes[i++] = Type; bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += Helpers.FieldToString(Data, "Data") + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MultipleObjectUpdate public override PacketType Type { get { return PacketType.MultipleObjectUpdate; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public MultipleObjectUpdatePacket() { Header = new MediumHeader(); Header.ID = 3; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MultipleObjectUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MultipleObjectUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MultipleObjectUpdate ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// RequestMultipleObjects packet public class RequestMultipleObjectsPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ID field public uint ID; /// CacheMissType field public byte CacheMissType; /// Length of this block serialized in bytes public int Length { get { return 5; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CacheMissType = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ID % 256); bytes[i++] = (byte)((ID >> 8) % 256); bytes[i++] = (byte)((ID >> 16) % 256); bytes[i++] = (byte)((ID >> 24) % 256); bytes[i++] = CacheMissType; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ID: " + ID.ToString() + "\n"; output += "CacheMissType: " + CacheMissType.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RequestMultipleObjects public override PacketType Type { get { return PacketType.RequestMultipleObjects; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RequestMultipleObjectsPacket() { Header = new MediumHeader(); Header.ID = 4; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RequestMultipleObjectsPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RequestMultipleObjectsPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RequestMultipleObjects ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ObjectPosition packet public class ObjectPositionPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectLocalID field public uint ObjectLocalID; /// Position field public LLVector3 Position; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectLocalID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Position = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ObjectLocalID % 256); bytes[i++] = (byte)((ObjectLocalID >> 8) % 256); bytes[i++] = (byte)((ObjectLocalID >> 16) % 256); bytes[i++] = (byte)((ObjectLocalID >> 24) % 256); if(Position == null) { Console.WriteLine("Warning: Position is null, in " + this.GetType()); } Array.Copy(Position.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectLocalID: " + ObjectLocalID.ToString() + "\n"; output += "Position: " + Position.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectPosition public override PacketType Type { get { return PacketType.ObjectPosition; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ObjectPositionPacket() { Header = new MediumHeader(); Header.ID = 5; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectPositionPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectPositionPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; length += AgentData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectPosition ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// RequestObjectPropertiesFamily packet public class RequestObjectPropertiesFamilyPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ObjectID field public LLUUID ObjectID; /// RequestFlags field public uint RequestFlags; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; RequestFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(RequestFlags % 256); bytes[i++] = (byte)((RequestFlags >> 8) % 256); bytes[i++] = (byte)((RequestFlags >> 16) % 256); bytes[i++] = (byte)((RequestFlags >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "RequestFlags: " + RequestFlags.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RequestObjectPropertiesFamily public override PacketType Type { get { return PacketType.RequestObjectPropertiesFamily; } } /// ObjectData block public ObjectDataBlock ObjectData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RequestObjectPropertiesFamilyPacket() { Header = new MediumHeader(); Header.ID = 6; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RequestObjectPropertiesFamilyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); ObjectData = new ObjectDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RequestObjectPropertiesFamilyPacket(Header head, byte[] bytes, ref int i) { Header = head; ObjectData = new ObjectDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; length += ObjectData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ObjectData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RequestObjectPropertiesFamily ---\n"; output += ObjectData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// CoarseLocationUpdate packet public class CoarseLocationUpdatePacket : Packet { /// Location block public class LocationBlock { /// X field public byte X; /// Y field public byte Y; /// Z field public byte Z; /// Length of this block serialized in bytes public int Length { get { return 3; } } /// Default constructor public LocationBlock() { } /// Constructor for building the block from a byte array public LocationBlock(byte[] bytes, ref int i) { try { X = (byte)bytes[i++]; Y = (byte)bytes[i++]; Z = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = X; bytes[i++] = Y; bytes[i++] = Z; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Location --\n"; output += "X: " + X.ToString() + "\n"; output += "Y: " + Y.ToString() + "\n"; output += "Z: " + Z.ToString() + "\n"; output = output.Trim(); return output; } } /// Index block public class IndexBlock { /// You field public short You; /// Prey field public short Prey; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public IndexBlock() { } /// Constructor for building the block from a byte array public IndexBlock(byte[] bytes, ref int i) { try { You = (short)(bytes[i++] + (bytes[i++] << 8)); Prey = (short)(bytes[i++] + (bytes[i++] << 8)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(You % 256); bytes[i++] = (byte)((You >> 8) % 256); bytes[i++] = (byte)(Prey % 256); bytes[i++] = (byte)((Prey >> 8) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Index --\n"; output += "You: " + You.ToString() + "\n"; output += "Prey: " + Prey.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.CoarseLocationUpdate public override PacketType Type { get { return PacketType.CoarseLocationUpdate; } } /// Location block public LocationBlock[] Location; /// Index block public IndexBlock Index; /// Default constructor public CoarseLocationUpdatePacket() { Header = new MediumHeader(); Header.ID = 7; Header.Reliable = true; Location = new LocationBlock[0]; Index = new IndexBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public CoarseLocationUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; Location = new LocationBlock[count]; for (int j = 0; j < count; j++) { Location[j] = new LocationBlock(bytes, ref i); } Index = new IndexBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public CoarseLocationUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; Location = new LocationBlock[count]; for (int j = 0; j < count; j++) { Location[j] = new LocationBlock(bytes, ref i); } Index = new IndexBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; length += Index.Length;; length++; for (int j = 0; j < Location.Length; j++) { length += Location[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)Location.Length; for (int j = 0; j < Location.Length; j++) { Location[j].ToBytes(bytes, ref i); } Index.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- CoarseLocationUpdate ---\n"; for (int j = 0; j < Location.Length; j++) { output += Location[j].ToString() + "\n"; } output += Index.ToString() + "\n"; return output; } } /// CrossedRegion packet public class CrossedRegionPacket : Packet { /// Info block public class InfoBlock { /// LookAt field public LLVector3 LookAt; /// Position field public LLVector3 Position; /// Length of this block serialized in bytes public int Length { get { return 24; } } /// Default constructor public InfoBlock() { } /// Constructor for building the block from a byte array public InfoBlock(byte[] bytes, ref int i) { try { LookAt = new LLVector3(bytes, i); i += 12; Position = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(LookAt == null) { Console.WriteLine("Warning: LookAt is null, in " + this.GetType()); } Array.Copy(LookAt.GetBytes(), 0, bytes, i, 12); i += 12; if(Position == null) { Console.WriteLine("Warning: Position is null, in " + this.GetType()); } Array.Copy(Position.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Info --\n"; output += "LookAt: " + LookAt.ToString() + "\n"; output += "Position: " + Position.ToString() + "\n"; output = output.Trim(); return output; } } /// RegionData block public class RegionDataBlock { private byte[] _seedcapability; /// SeedCapability field public byte[] SeedCapability { get { return _seedcapability; } set { if (value == null) { _seedcapability = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _seedcapability = new byte[value.Length]; Array.Copy(value, _seedcapability, value.Length); } } } /// SimPort field public ushort SimPort; /// RegionHandle field public ulong RegionHandle; /// SimIP field public uint SimIP; /// Length of this block serialized in bytes public int Length { get { int length = 14; if (SeedCapability != null) { length += 2 + SeedCapability.Length; } return length; } } /// Default constructor public RegionDataBlock() { } /// Constructor for building the block from a byte array public RegionDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _seedcapability = new byte[length]; Array.Copy(bytes, i, _seedcapability, 0, length); i += length; SimPort = (ushort)((bytes[i++] << 8) + bytes[i++]); RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); SimIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(SeedCapability == null) { Console.WriteLine("Warning: SeedCapability is null, in " + this.GetType()); } bytes[i++] = (byte)(SeedCapability.Length % 256); bytes[i++] = (byte)((SeedCapability.Length >> 8) % 256); Array.Copy(SeedCapability, 0, bytes, i, SeedCapability.Length); i += SeedCapability.Length; bytes[i++] = (byte)((SimPort >> 8) % 256); bytes[i++] = (byte)(SimPort % 256); bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); bytes[i++] = (byte)(SimIP % 256); bytes[i++] = (byte)((SimIP >> 8) % 256); bytes[i++] = (byte)((SimIP >> 16) % 256); bytes[i++] = (byte)((SimIP >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionData --\n"; output += Helpers.FieldToString(SeedCapability, "SeedCapability") + "\n"; output += "SimPort: " + SimPort.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output += "SimIP: " + SimIP.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.CrossedRegion public override PacketType Type { get { return PacketType.CrossedRegion; } } /// Info block public InfoBlock Info; /// RegionData block public RegionDataBlock RegionData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public CrossedRegionPacket() { Header = new MediumHeader(); Header.ID = 8; Header.Reliable = true; Info = new InfoBlock(); RegionData = new RegionDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public CrossedRegionPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); Info = new InfoBlock(bytes, ref i); RegionData = new RegionDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public CrossedRegionPacket(Header head, byte[] bytes, ref int i) { Header = head; Info = new InfoBlock(bytes, ref i); RegionData = new RegionDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; length += Info.Length; length += RegionData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Info.ToBytes(bytes, ref i); RegionData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- CrossedRegion ---\n"; output += Info.ToString() + "\n"; output += RegionData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// ConfirmEnableSimulator packet public class ConfirmEnableSimulatorPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ConfirmEnableSimulator public override PacketType Type { get { return PacketType.ConfirmEnableSimulator; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ConfirmEnableSimulatorPacket() { Header = new MediumHeader(); Header.ID = 9; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ConfirmEnableSimulatorPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ConfirmEnableSimulatorPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ConfirmEnableSimulator ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// ObjectProperties packet public class ObjectPropertiesPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// OwnershipCost field public int OwnershipCost; /// AggregatePermTexturesOwner field public byte AggregatePermTexturesOwner; private byte[] _sitname; /// SitName field public byte[] SitName { get { return _sitname; } set { if (value == null) { _sitname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _sitname = new byte[value.Length]; Array.Copy(value, _sitname, value.Length); } } } /// ObjectID field public LLUUID ObjectID; /// SaleType field public byte SaleType; /// BaseMask field public uint BaseMask; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// Category field public uint Category; /// FromTaskID field public LLUUID FromTaskID; /// GroupID field public LLUUID GroupID; /// SalePrice field public int SalePrice; /// OwnerID field public LLUUID OwnerID; /// CreatorID field public LLUUID CreatorID; private byte[] _textureid; /// TextureID field public byte[] TextureID { get { return _textureid; } set { if (value == null) { _textureid = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _textureid = new byte[value.Length]; Array.Copy(value, _textureid, value.Length); } } } private byte[] _touchname; /// TouchName field public byte[] TouchName { get { return _touchname; } set { if (value == null) { _touchname = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _touchname = new byte[value.Length]; Array.Copy(value, _touchname, value.Length); } } } /// ItemID field public LLUUID ItemID; /// AggregatePermTextures field public byte AggregatePermTextures; /// FolderID field public LLUUID FolderID; /// InventorySerial field public short InventorySerial; /// EveryoneMask field public uint EveryoneMask; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// LastOwnerID field public LLUUID LastOwnerID; /// AggregatePerms field public byte AggregatePerms; /// NextOwnerMask field public uint NextOwnerMask; /// GroupMask field public uint GroupMask; /// OwnerMask field public uint OwnerMask; /// Length of this block serialized in bytes public int Length { get { int length = 166; if (SitName != null) { length += 1 + SitName.Length; } if (Name != null) { length += 1 + Name.Length; } if (TextureID != null) { length += 1 + TextureID.Length; } if (TouchName != null) { length += 1 + TouchName.Length; } if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { int length; try { OwnershipCost = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); AggregatePermTexturesOwner = (byte)bytes[i++]; length = (ushort)bytes[i++]; _sitname = new byte[length]; Array.Copy(bytes, i, _sitname, 0, length); i += length; ObjectID = new LLUUID(bytes, i); i += 16; SaleType = (byte)bytes[i++]; BaseMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; Category = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); FromTaskID = new LLUUID(bytes, i); i += 16; GroupID = new LLUUID(bytes, i); i += 16; SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerID = new LLUUID(bytes, i); i += 16; CreatorID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _textureid = new byte[length]; Array.Copy(bytes, i, _textureid, 0, length); i += length; length = (ushort)bytes[i++]; _touchname = new byte[length]; Array.Copy(bytes, i, _touchname, 0, length); i += length; ItemID = new LLUUID(bytes, i); i += 16; AggregatePermTextures = (byte)bytes[i++]; FolderID = new LLUUID(bytes, i); i += 16; InventorySerial = (short)(bytes[i++] + (bytes[i++] << 8)); EveryoneMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; LastOwnerID = new LLUUID(bytes, i); i += 16; AggregatePerms = (byte)bytes[i++]; NextOwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(OwnershipCost % 256); bytes[i++] = (byte)((OwnershipCost >> 8) % 256); bytes[i++] = (byte)((OwnershipCost >> 16) % 256); bytes[i++] = (byte)((OwnershipCost >> 24) % 256); bytes[i++] = AggregatePermTexturesOwner; if(SitName == null) { Console.WriteLine("Warning: SitName is null, in " + this.GetType()); } bytes[i++] = (byte)SitName.Length; Array.Copy(SitName, 0, bytes, i, SitName.Length); i += SitName.Length; if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = SaleType; bytes[i++] = (byte)(BaseMask % 256); bytes[i++] = (byte)((BaseMask >> 8) % 256); bytes[i++] = (byte)((BaseMask >> 16) % 256); bytes[i++] = (byte)((BaseMask >> 24) % 256); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)(Category % 256); bytes[i++] = (byte)((Category >> 8) % 256); bytes[i++] = (byte)((Category >> 16) % 256); bytes[i++] = (byte)((Category >> 24) % 256); if(FromTaskID == null) { Console.WriteLine("Warning: FromTaskID is null, in " + this.GetType()); } Array.Copy(FromTaskID.GetBytes(), 0, bytes, i, 16); i += 16; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(SalePrice % 256); bytes[i++] = (byte)((SalePrice >> 8) % 256); bytes[i++] = (byte)((SalePrice >> 16) % 256); bytes[i++] = (byte)((SalePrice >> 24) % 256); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(CreatorID == null) { Console.WriteLine("Warning: CreatorID is null, in " + this.GetType()); } Array.Copy(CreatorID.GetBytes(), 0, bytes, i, 16); i += 16; if(TextureID == null) { Console.WriteLine("Warning: TextureID is null, in " + this.GetType()); } bytes[i++] = (byte)TextureID.Length; Array.Copy(TextureID, 0, bytes, i, TextureID.Length); i += TextureID.Length; if(TouchName == null) { Console.WriteLine("Warning: TouchName is null, in " + this.GetType()); } bytes[i++] = (byte)TouchName.Length; Array.Copy(TouchName, 0, bytes, i, TouchName.Length); i += TouchName.Length; if(ItemID == null) { Console.WriteLine("Warning: ItemID is null, in " + this.GetType()); } Array.Copy(ItemID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = AggregatePermTextures; if(FolderID == null) { Console.WriteLine("Warning: FolderID is null, in " + this.GetType()); } Array.Copy(FolderID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(InventorySerial % 256); bytes[i++] = (byte)((InventorySerial >> 8) % 256); bytes[i++] = (byte)(EveryoneMask % 256); bytes[i++] = (byte)((EveryoneMask >> 8) % 256); bytes[i++] = (byte)((EveryoneMask >> 16) % 256); bytes[i++] = (byte)((EveryoneMask >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; if(LastOwnerID == null) { Console.WriteLine("Warning: LastOwnerID is null, in " + this.GetType()); } Array.Copy(LastOwnerID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = AggregatePerms; bytes[i++] = (byte)(NextOwnerMask % 256); bytes[i++] = (byte)((NextOwnerMask >> 8) % 256); bytes[i++] = (byte)((NextOwnerMask >> 16) % 256); bytes[i++] = (byte)((NextOwnerMask >> 24) % 256); bytes[i++] = (byte)(GroupMask % 256); bytes[i++] = (byte)((GroupMask >> 8) % 256); bytes[i++] = (byte)((GroupMask >> 16) % 256); bytes[i++] = (byte)((GroupMask >> 24) % 256); bytes[i++] = (byte)(OwnerMask % 256); bytes[i++] = (byte)((OwnerMask >> 8) % 256); bytes[i++] = (byte)((OwnerMask >> 16) % 256); bytes[i++] = (byte)((OwnerMask >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "OwnershipCost: " + OwnershipCost.ToString() + "\n"; output += "AggregatePermTexturesOwner: " + AggregatePermTexturesOwner.ToString() + "\n"; output += Helpers.FieldToString(SitName, "SitName") + "\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "SaleType: " + SaleType.ToString() + "\n"; output += "BaseMask: " + BaseMask.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "Category: " + Category.ToString() + "\n"; output += "FromTaskID: " + FromTaskID.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "SalePrice: " + SalePrice.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "CreatorID: " + CreatorID.ToString() + "\n"; output += Helpers.FieldToString(TextureID, "TextureID") + "\n"; output += Helpers.FieldToString(TouchName, "TouchName") + "\n"; output += "ItemID: " + ItemID.ToString() + "\n"; output += "AggregatePermTextures: " + AggregatePermTextures.ToString() + "\n"; output += "FolderID: " + FolderID.ToString() + "\n"; output += "InventorySerial: " + InventorySerial.ToString() + "\n"; output += "EveryoneMask: " + EveryoneMask.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += "LastOwnerID: " + LastOwnerID.ToString() + "\n"; output += "AggregatePerms: " + AggregatePerms.ToString() + "\n"; output += "NextOwnerMask: " + NextOwnerMask.ToString() + "\n"; output += "GroupMask: " + GroupMask.ToString() + "\n"; output += "OwnerMask: " + OwnerMask.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectProperties public override PacketType Type { get { return PacketType.ObjectProperties; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// Default constructor public ObjectPropertiesPacket() { Header = new MediumHeader(); Header.ID = 10; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectPropertiesPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public ObjectPropertiesPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; ; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectProperties ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } return output; } } /// ObjectPropertiesFamily packet public class ObjectPropertiesFamilyPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// OwnershipCost field public int OwnershipCost; /// ObjectID field public LLUUID ObjectID; /// SaleType field public byte SaleType; /// BaseMask field public uint BaseMask; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// RequestFlags field public uint RequestFlags; /// Category field public uint Category; /// GroupID field public LLUUID GroupID; /// SalePrice field public int SalePrice; /// OwnerID field public LLUUID OwnerID; /// EveryoneMask field public uint EveryoneMask; private byte[] _description; /// Description field public byte[] Description { get { return _description; } set { if (value == null) { _description = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _description = new byte[value.Length]; Array.Copy(value, _description, value.Length); } } } /// LastOwnerID field public LLUUID LastOwnerID; /// NextOwnerMask field public uint NextOwnerMask; /// GroupMask field public uint GroupMask; /// OwnerMask field public uint OwnerMask; /// Length of this block serialized in bytes public int Length { get { int length = 101; if (Name != null) { length += 1 + Name.Length; } if (Description != null) { length += 1 + Description.Length; } return length; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { int length; try { OwnershipCost = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ObjectID = new LLUUID(bytes, i); i += 16; SaleType = (byte)bytes[i++]; BaseMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; RequestFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Category = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupID = new LLUUID(bytes, i); i += 16; SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerID = new LLUUID(bytes, i); i += 16; EveryoneMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _description = new byte[length]; Array.Copy(bytes, i, _description, 0, length); i += length; LastOwnerID = new LLUUID(bytes, i); i += 16; NextOwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(OwnershipCost % 256); bytes[i++] = (byte)((OwnershipCost >> 8) % 256); bytes[i++] = (byte)((OwnershipCost >> 16) % 256); bytes[i++] = (byte)((OwnershipCost >> 24) % 256); if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = SaleType; bytes[i++] = (byte)(BaseMask % 256); bytes[i++] = (byte)((BaseMask >> 8) % 256); bytes[i++] = (byte)((BaseMask >> 16) % 256); bytes[i++] = (byte)((BaseMask >> 24) % 256); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)(RequestFlags % 256); bytes[i++] = (byte)((RequestFlags >> 8) % 256); bytes[i++] = (byte)((RequestFlags >> 16) % 256); bytes[i++] = (byte)((RequestFlags >> 24) % 256); bytes[i++] = (byte)(Category % 256); bytes[i++] = (byte)((Category >> 8) % 256); bytes[i++] = (byte)((Category >> 16) % 256); bytes[i++] = (byte)((Category >> 24) % 256); if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(SalePrice % 256); bytes[i++] = (byte)((SalePrice >> 8) % 256); bytes[i++] = (byte)((SalePrice >> 16) % 256); bytes[i++] = (byte)((SalePrice >> 24) % 256); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(EveryoneMask % 256); bytes[i++] = (byte)((EveryoneMask >> 8) % 256); bytes[i++] = (byte)((EveryoneMask >> 16) % 256); bytes[i++] = (byte)((EveryoneMask >> 24) % 256); if(Description == null) { Console.WriteLine("Warning: Description is null, in " + this.GetType()); } bytes[i++] = (byte)Description.Length; Array.Copy(Description, 0, bytes, i, Description.Length); i += Description.Length; if(LastOwnerID == null) { Console.WriteLine("Warning: LastOwnerID is null, in " + this.GetType()); } Array.Copy(LastOwnerID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(NextOwnerMask % 256); bytes[i++] = (byte)((NextOwnerMask >> 8) % 256); bytes[i++] = (byte)((NextOwnerMask >> 16) % 256); bytes[i++] = (byte)((NextOwnerMask >> 24) % 256); bytes[i++] = (byte)(GroupMask % 256); bytes[i++] = (byte)((GroupMask >> 8) % 256); bytes[i++] = (byte)((GroupMask >> 16) % 256); bytes[i++] = (byte)((GroupMask >> 24) % 256); bytes[i++] = (byte)(OwnerMask % 256); bytes[i++] = (byte)((OwnerMask >> 8) % 256); bytes[i++] = (byte)((OwnerMask >> 16) % 256); bytes[i++] = (byte)((OwnerMask >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "OwnershipCost: " + OwnershipCost.ToString() + "\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "SaleType: " + SaleType.ToString() + "\n"; output += "BaseMask: " + BaseMask.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "RequestFlags: " + RequestFlags.ToString() + "\n"; output += "Category: " + Category.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "SalePrice: " + SalePrice.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "EveryoneMask: " + EveryoneMask.ToString() + "\n"; output += Helpers.FieldToString(Description, "Description") + "\n"; output += "LastOwnerID: " + LastOwnerID.ToString() + "\n"; output += "NextOwnerMask: " + NextOwnerMask.ToString() + "\n"; output += "GroupMask: " + GroupMask.ToString() + "\n"; output += "OwnerMask: " + OwnerMask.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectPropertiesFamily public override PacketType Type { get { return PacketType.ObjectPropertiesFamily; } } /// ObjectData block public ObjectDataBlock ObjectData; /// Default constructor public ObjectPropertiesFamilyPacket() { Header = new MediumHeader(); Header.ID = 11; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectPropertiesFamilyPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); ObjectData = new ObjectDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectPropertiesFamilyPacket(Header head, byte[] bytes, ref int i) { Header = head; ObjectData = new ObjectDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; length += ObjectData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ObjectData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectPropertiesFamily ---\n"; output += ObjectData.ToString() + "\n"; return output; } } /// ParcelPropertiesRequest packet public class ParcelPropertiesRequestPacket : Packet { /// ParcelData block public class ParcelDataBlock { /// East field public float East; /// West field public float West; /// SequenceID field public int SequenceID; /// SnapSelection field public bool SnapSelection; /// North field public float North; /// South field public float South; /// Length of this block serialized in bytes public int Length { get { return 21; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); East = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); West = BitConverter.ToSingle(bytes, i); i += 4; SequenceID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SnapSelection = (bytes[i++] != 0) ? (bool)true : (bool)false; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); North = BitConverter.ToSingle(bytes, i); i += 4; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); South = BitConverter.ToSingle(bytes, i); i += 4; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(East); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(West); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(SequenceID % 256); bytes[i++] = (byte)((SequenceID >> 8) % 256); bytes[i++] = (byte)((SequenceID >> 16) % 256); bytes[i++] = (byte)((SequenceID >> 24) % 256); bytes[i++] = (byte)((SnapSelection) ? 1 : 0); ba = BitConverter.GetBytes(North); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; ba = BitConverter.GetBytes(South); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "East: " + East.ToString() + "\n"; output += "West: " + West.ToString() + "\n"; output += "SequenceID: " + SequenceID.ToString() + "\n"; output += "SnapSelection: " + SnapSelection.ToString() + "\n"; output += "North: " + North.ToString() + "\n"; output += "South: " + South.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelPropertiesRequest public override PacketType Type { get { return PacketType.ParcelPropertiesRequest; } } /// ParcelData block public ParcelDataBlock ParcelData; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ParcelPropertiesRequestPacket() { Header = new MediumHeader(); Header.ID = 12; Header.Reliable = true; Header.Zerocoded = true; ParcelData = new ParcelDataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelPropertiesRequestPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelPropertiesRequestPacket(Header head, byte[] bytes, ref int i) { Header = head; ParcelData = new ParcelDataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; length += ParcelData.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ParcelData.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelPropertiesRequest ---\n"; output += ParcelData.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// SimStatus packet public class SimStatusPacket : Packet { /// SimStatus block public class SimStatusBlock { /// CanAcceptAgents field public bool CanAcceptAgents; /// CanAcceptTasks field public bool CanAcceptTasks; /// Length of this block serialized in bytes public int Length { get { return 2; } } /// Default constructor public SimStatusBlock() { } /// Constructor for building the block from a byte array public SimStatusBlock(byte[] bytes, ref int i) { try { CanAcceptAgents = (bytes[i++] != 0) ? (bool)true : (bool)false; CanAcceptTasks = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((CanAcceptAgents) ? 1 : 0); bytes[i++] = (byte)((CanAcceptTasks) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- SimStatus --\n"; output += "CanAcceptAgents: " + CanAcceptAgents.ToString() + "\n"; output += "CanAcceptTasks: " + CanAcceptTasks.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SimStatus public override PacketType Type { get { return PacketType.SimStatus; } } /// SimStatus block public SimStatusBlock SimStatus; /// Default constructor public SimStatusPacket() { Header = new MediumHeader(); Header.ID = 13; Header.Reliable = true; SimStatus = new SimStatusBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SimStatusPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); SimStatus = new SimStatusBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SimStatusPacket(Header head, byte[] bytes, ref int i) { Header = head; SimStatus = new SimStatusBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; length += SimStatus.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); SimStatus.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SimStatus ---\n"; output += SimStatus.ToString() + "\n"; return output; } } /// GestureUpdate packet public class GestureUpdatePacket : Packet { /// AgentBlock block public class AgentBlockBlock { /// AgentID field public LLUUID AgentID; /// ToViewer field public bool ToViewer; private byte[] _filename; /// Filename field public byte[] Filename { get { return _filename; } set { if (value == null) { _filename = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _filename = new byte[value.Length]; Array.Copy(value, _filename, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 17; if (Filename != null) { length += 1 + Filename.Length; } return length; } } /// Default constructor public AgentBlockBlock() { } /// Constructor for building the block from a byte array public AgentBlockBlock(byte[] bytes, ref int i) { int length; try { AgentID = new LLUUID(bytes, i); i += 16; ToViewer = (bytes[i++] != 0) ? (bool)true : (bool)false; length = (ushort)bytes[i++]; _filename = new byte[length]; Array.Copy(bytes, i, _filename, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((ToViewer) ? 1 : 0); if(Filename == null) { Console.WriteLine("Warning: Filename is null, in " + this.GetType()); } bytes[i++] = (byte)Filename.Length; Array.Copy(Filename, 0, bytes, i, Filename.Length); i += Filename.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentBlock --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "ToViewer: " + ToViewer.ToString() + "\n"; output += Helpers.FieldToString(Filename, "Filename") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.GestureUpdate public override PacketType Type { get { return PacketType.GestureUpdate; } } /// AgentBlock block public AgentBlockBlock AgentBlock; /// Default constructor public GestureUpdatePacket() { Header = new MediumHeader(); Header.ID = 14; Header.Reliable = true; AgentBlock = new AgentBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public GestureUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); AgentBlock = new AgentBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public GestureUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; AgentBlock = new AgentBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; length += AgentBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- GestureUpdate ---\n"; output += AgentBlock.ToString() + "\n"; return output; } } /// AttachedSound packet public class AttachedSoundPacket : Packet { /// DataBlock block public class DataBlockBlock { /// ObjectID field public LLUUID ObjectID; /// Gain field public float Gain; /// SoundID field public LLUUID SoundID; /// OwnerID field public LLUUID OwnerID; /// Flags field public byte Flags; /// Length of this block serialized in bytes public int Length { get { return 53; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Gain = BitConverter.ToSingle(bytes, i); i += 4; SoundID = new LLUUID(bytes, i); i += 16; OwnerID = new LLUUID(bytes, i); i += 16; Flags = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; ba = BitConverter.GetBytes(Gain); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(SoundID == null) { Console.WriteLine("Warning: SoundID is null, in " + this.GetType()); } Array.Copy(SoundID.GetBytes(), 0, bytes, i, 16); i += 16; if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = Flags; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "Gain: " + Gain.ToString() + "\n"; output += "SoundID: " + SoundID.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AttachedSound public override PacketType Type { get { return PacketType.AttachedSound; } } /// DataBlock block public DataBlockBlock DataBlock; /// Default constructor public AttachedSoundPacket() { Header = new MediumHeader(); Header.ID = 15; Header.Reliable = true; DataBlock = new DataBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AttachedSoundPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); DataBlock = new DataBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AttachedSoundPacket(Header head, byte[] bytes, ref int i) { Header = head; DataBlock = new DataBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; length += DataBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AttachedSound ---\n"; output += DataBlock.ToString() + "\n"; return output; } } /// AttachedSoundGainChange packet public class AttachedSoundGainChangePacket : Packet { /// DataBlock block public class DataBlockBlock { /// ObjectID field public LLUUID ObjectID; /// Gain field public float Gain; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Gain = BitConverter.ToSingle(bytes, i); i += 4; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; ba = BitConverter.GetBytes(Gain); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "Gain: " + Gain.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AttachedSoundGainChange public override PacketType Type { get { return PacketType.AttachedSoundGainChange; } } /// DataBlock block public DataBlockBlock DataBlock; /// Default constructor public AttachedSoundGainChangePacket() { Header = new MediumHeader(); Header.ID = 16; Header.Reliable = true; DataBlock = new DataBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AttachedSoundGainChangePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); DataBlock = new DataBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AttachedSoundGainChangePacket(Header head, byte[] bytes, ref int i) { Header = head; DataBlock = new DataBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; length += DataBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AttachedSoundGainChange ---\n"; output += DataBlock.ToString() + "\n"; return output; } } /// AttachedSoundCutoffRadius packet public class AttachedSoundCutoffRadiusPacket : Packet { /// DataBlock block public class DataBlockBlock { /// ObjectID field public LLUUID ObjectID; /// Radius field public float Radius; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Radius = BitConverter.ToSingle(bytes, i); i += 4; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; ba = BitConverter.GetBytes(Radius); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "Radius: " + Radius.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AttachedSoundCutoffRadius public override PacketType Type { get { return PacketType.AttachedSoundCutoffRadius; } } /// DataBlock block public DataBlockBlock DataBlock; /// Default constructor public AttachedSoundCutoffRadiusPacket() { Header = new MediumHeader(); Header.ID = 17; Header.Reliable = true; DataBlock = new DataBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AttachedSoundCutoffRadiusPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); DataBlock = new DataBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AttachedSoundCutoffRadiusPacket(Header head, byte[] bytes, ref int i) { Header = head; DataBlock = new DataBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; length += DataBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AttachedSoundCutoffRadius ---\n"; output += DataBlock.ToString() + "\n"; return output; } } /// PreloadSound packet public class PreloadSoundPacket : Packet { /// DataBlock block public class DataBlockBlock { /// ObjectID field public LLUUID ObjectID; /// SoundID field public LLUUID SoundID; /// OwnerID field public LLUUID OwnerID; /// Length of this block serialized in bytes public int Length { get { return 48; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; SoundID = new LLUUID(bytes, i); i += 16; OwnerID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; if(SoundID == null) { Console.WriteLine("Warning: SoundID is null, in " + this.GetType()); } Array.Copy(SoundID.GetBytes(), 0, bytes, i, 16); i += 16; if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "SoundID: " + SoundID.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.PreloadSound public override PacketType Type { get { return PacketType.PreloadSound; } } /// DataBlock block public DataBlockBlock[] DataBlock; /// Default constructor public PreloadSoundPacket() { Header = new MediumHeader(); Header.ID = 18; Header.Reliable = true; DataBlock = new DataBlockBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public PreloadSoundPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; DataBlock = new DataBlockBlock[count]; for (int j = 0; j < count; j++) { DataBlock[j] = new DataBlockBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public PreloadSoundPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; DataBlock = new DataBlockBlock[count]; for (int j = 0; j < count; j++) { DataBlock[j] = new DataBlockBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; ; length++; for (int j = 0; j < DataBlock.Length; j++) { length += DataBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)DataBlock.Length; for (int j = 0; j < DataBlock.Length; j++) { DataBlock[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- PreloadSound ---\n"; for (int j = 0; j < DataBlock.Length; j++) { output += DataBlock[j].ToString() + "\n"; } return output; } } /// InternalScriptMail packet public class InternalScriptMailPacket : Packet { /// DataBlock block public class DataBlockBlock { /// To field public LLUUID To; private byte[] _subject; /// Subject field public byte[] Subject { get { return _subject; } set { if (value == null) { _subject = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _subject = new byte[value.Length]; Array.Copy(value, _subject, value.Length); } } } private byte[] _body; /// Body field public byte[] Body { get { return _body; } set { if (value == null) { _body = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _body = new byte[value.Length]; Array.Copy(value, _body, value.Length); } } } private byte[] _from; /// From field public byte[] From { get { return _from; } set { if (value == null) { _from = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _from = new byte[value.Length]; Array.Copy(value, _from, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 16; if (Subject != null) { length += 1 + Subject.Length; } if (Body != null) { length += 2 + Body.Length; } if (From != null) { length += 1 + From.Length; } return length; } } /// Default constructor public DataBlockBlock() { } /// Constructor for building the block from a byte array public DataBlockBlock(byte[] bytes, ref int i) { int length; try { To = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _subject = new byte[length]; Array.Copy(bytes, i, _subject, 0, length); i += length; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _body = new byte[length]; Array.Copy(bytes, i, _body, 0, length); i += length; length = (ushort)bytes[i++]; _from = new byte[length]; Array.Copy(bytes, i, _from, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(To == null) { Console.WriteLine("Warning: To is null, in " + this.GetType()); } Array.Copy(To.GetBytes(), 0, bytes, i, 16); i += 16; if(Subject == null) { Console.WriteLine("Warning: Subject is null, in " + this.GetType()); } bytes[i++] = (byte)Subject.Length; Array.Copy(Subject, 0, bytes, i, Subject.Length); i += Subject.Length; if(Body == null) { Console.WriteLine("Warning: Body is null, in " + this.GetType()); } bytes[i++] = (byte)(Body.Length % 256); bytes[i++] = (byte)((Body.Length >> 8) % 256); Array.Copy(Body, 0, bytes, i, Body.Length); i += Body.Length; if(From == null) { Console.WriteLine("Warning: From is null, in " + this.GetType()); } bytes[i++] = (byte)From.Length; Array.Copy(From, 0, bytes, i, From.Length); i += From.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataBlock --\n"; output += "To: " + To.ToString() + "\n"; output += Helpers.FieldToString(Subject, "Subject") + "\n"; output += Helpers.FieldToString(Body, "Body") + "\n"; output += Helpers.FieldToString(From, "From") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.InternalScriptMail public override PacketType Type { get { return PacketType.InternalScriptMail; } } /// DataBlock block public DataBlockBlock DataBlock; /// Default constructor public InternalScriptMailPacket() { Header = new MediumHeader(); Header.ID = 19; Header.Reliable = true; DataBlock = new DataBlockBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public InternalScriptMailPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); DataBlock = new DataBlockBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public InternalScriptMailPacket(Header head, byte[] bytes, ref int i) { Header = head; DataBlock = new DataBlockBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; length += DataBlock.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataBlock.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- InternalScriptMail ---\n"; output += DataBlock.ToString() + "\n"; return output; } } /// ViewerEffect packet public class ViewerEffectPacket : Packet { /// Effect block public class EffectBlock { /// Duration field public float Duration; /// ID field public LLUUID ID; /// Type field public byte Type; /// Color field public byte[] Color; private byte[] _typedata; /// TypeData field public byte[] TypeData { get { return _typedata; } set { if (value == null) { _typedata = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _typedata = new byte[value.Length]; Array.Copy(value, _typedata, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 25; if (TypeData != null) { length += 1 + TypeData.Length; } return length; } } /// Default constructor public EffectBlock() { } /// Constructor for building the block from a byte array public EffectBlock(byte[] bytes, ref int i) { int length; try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Duration = BitConverter.ToSingle(bytes, i); i += 4; ID = new LLUUID(bytes, i); i += 16; Type = (byte)bytes[i++]; Color = new byte[4]; Array.Copy(bytes, i, Color, 0, 4); i += 4; length = (ushort)bytes[i++]; _typedata = new byte[length]; Array.Copy(bytes, i, _typedata, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(Duration); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = Type; Array.Copy(Color, 0, bytes, i, 4);i += 4; if(TypeData == null) { Console.WriteLine("Warning: TypeData is null, in " + this.GetType()); } bytes[i++] = (byte)TypeData.Length; Array.Copy(TypeData, 0, bytes, i, TypeData.Length); i += TypeData.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Effect --\n"; output += "Duration: " + Duration.ToString() + "\n"; output += "ID: " + ID.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output += Helpers.FieldToString(Color, "Color") + "\n"; output += Helpers.FieldToString(TypeData, "TypeData") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ViewerEffect public override PacketType Type { get { return PacketType.ViewerEffect; } } /// Effect block public EffectBlock[] Effect; /// Default constructor public ViewerEffectPacket() { Header = new MediumHeader(); Header.ID = 20; Header.Reliable = true; Header.Zerocoded = true; Effect = new EffectBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ViewerEffectPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; Effect = new EffectBlock[count]; for (int j = 0; j < count; j++) { Effect[j] = new EffectBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public ViewerEffectPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; Effect = new EffectBlock[count]; for (int j = 0; j < count; j++) { Effect[j] = new EffectBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; ; length++; for (int j = 0; j < Effect.Length; j++) { length += Effect[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)Effect.Length; for (int j = 0; j < Effect.Length; j++) { Effect[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ViewerEffect ---\n"; for (int j = 0; j < Effect.Length; j++) { output += Effect[j].ToString() + "\n"; } return output; } } /// SetSunPhase packet public class SetSunPhasePacket : Packet { /// Data block public class DataBlock { /// Phase field public float Phase; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public DataBlock() { } /// Constructor for building the block from a byte array public DataBlock(byte[] bytes, ref int i) { try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Phase = BitConverter.ToSingle(bytes, i); i += 4; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(Phase); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Data --\n"; output += "Phase: " + Phase.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SetSunPhase public override PacketType Type { get { return PacketType.SetSunPhase; } } /// Data block public DataBlock Data; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public SetSunPhasePacket() { Header = new MediumHeader(); Header.ID = 21; Header.Reliable = true; Data = new DataBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SetSunPhasePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new MediumHeader(bytes, ref i, ref packetEnd); Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SetSunPhasePacket(Header head, byte[] bytes, ref int i) { Header = head; Data = new DataBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 6; length += Data.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Data.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SetSunPhase ---\n"; output += Data.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// StartPingCheck packet public class StartPingCheckPacket : Packet { /// PingID block public class PingIDBlock { /// PingID field public byte PingID; /// OldestUnacked field public uint OldestUnacked; /// Length of this block serialized in bytes public int Length { get { return 5; } } /// Default constructor public PingIDBlock() { } /// Constructor for building the block from a byte array public PingIDBlock(byte[] bytes, ref int i) { try { PingID = (byte)bytes[i++]; OldestUnacked = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = PingID; bytes[i++] = (byte)(OldestUnacked % 256); bytes[i++] = (byte)((OldestUnacked >> 8) % 256); bytes[i++] = (byte)((OldestUnacked >> 16) % 256); bytes[i++] = (byte)((OldestUnacked >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- PingID --\n"; output += "PingID: " + PingID.ToString() + "\n"; output += "OldestUnacked: " + OldestUnacked.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.StartPingCheck public override PacketType Type { get { return PacketType.StartPingCheck; } } /// PingID block public PingIDBlock PingID; /// Default constructor public StartPingCheckPacket() { Header = new HighHeader(); Header.ID = 1; Header.Reliable = true; PingID = new PingIDBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public StartPingCheckPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); PingID = new PingIDBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public StartPingCheckPacket(Header head, byte[] bytes, ref int i) { Header = head; PingID = new PingIDBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += PingID.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); PingID.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- StartPingCheck ---\n"; output += PingID.ToString() + "\n"; return output; } } /// CompletePingCheck packet public class CompletePingCheckPacket : Packet { /// PingID block public class PingIDBlock { /// PingID field public byte PingID; /// Length of this block serialized in bytes public int Length { get { return 1; } } /// Default constructor public PingIDBlock() { } /// Constructor for building the block from a byte array public PingIDBlock(byte[] bytes, ref int i) { try { PingID = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = PingID; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- PingID --\n"; output += "PingID: " + PingID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.CompletePingCheck public override PacketType Type { get { return PacketType.CompletePingCheck; } } /// PingID block public PingIDBlock PingID; /// Default constructor public CompletePingCheckPacket() { Header = new HighHeader(); Header.ID = 2; Header.Reliable = true; PingID = new PingIDBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public CompletePingCheckPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); PingID = new PingIDBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public CompletePingCheckPacket(Header head, byte[] bytes, ref int i) { Header = head; PingID = new PingIDBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += PingID.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); PingID.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- CompletePingCheck ---\n"; output += PingID.ToString() + "\n"; return output; } } /// NeighborList packet public class NeighborListPacket : Packet { /// NeighborBlock block public class NeighborBlockBlock { /// IP field public uint IP; /// PublicPort field public ushort PublicPort; /// RegionID field public LLUUID RegionID; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// Port field public ushort Port; /// SimAccess field public byte SimAccess; /// PublicIP field public uint PublicIP; /// Length of this block serialized in bytes public int Length { get { int length = 29; if (Name != null) { length += 1 + Name.Length; } return length; } } /// Default constructor public NeighborBlockBlock() { } /// Constructor for building the block from a byte array public NeighborBlockBlock(byte[] bytes, ref int i) { int length; try { IP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); PublicPort = (ushort)((bytes[i++] << 8) + bytes[i++]); RegionID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; Port = (ushort)((bytes[i++] << 8) + bytes[i++]); SimAccess = (byte)bytes[i++]; PublicIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(IP % 256); bytes[i++] = (byte)((IP >> 8) % 256); bytes[i++] = (byte)((IP >> 16) % 256); bytes[i++] = (byte)((IP >> 24) % 256); bytes[i++] = (byte)((PublicPort >> 8) % 256); bytes[i++] = (byte)(PublicPort % 256); if(RegionID == null) { Console.WriteLine("Warning: RegionID is null, in " + this.GetType()); } Array.Copy(RegionID.GetBytes(), 0, bytes, i, 16); i += 16; if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)((Port >> 8) % 256); bytes[i++] = (byte)(Port % 256); bytes[i++] = SimAccess; bytes[i++] = (byte)(PublicIP % 256); bytes[i++] = (byte)((PublicIP >> 8) % 256); bytes[i++] = (byte)((PublicIP >> 16) % 256); bytes[i++] = (byte)((PublicIP >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- NeighborBlock --\n"; output += "IP: " + IP.ToString() + "\n"; output += "PublicPort: " + PublicPort.ToString() + "\n"; output += "RegionID: " + RegionID.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "Port: " + Port.ToString() + "\n"; output += "SimAccess: " + SimAccess.ToString() + "\n"; output += "PublicIP: " + PublicIP.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.NeighborList public override PacketType Type { get { return PacketType.NeighborList; } } /// NeighborBlock block public NeighborBlockBlock[] NeighborBlock; /// Default constructor public NeighborListPacket() { Header = new HighHeader(); Header.ID = 3; Header.Reliable = true; NeighborBlock = new NeighborBlockBlock[4]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public NeighborListPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); NeighborBlock = new NeighborBlockBlock[4]; for (int j = 0; j < 4; j++) { NeighborBlock[j] = new NeighborBlockBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public NeighborListPacket(Header head, byte[] bytes, ref int i) { Header = head; NeighborBlock = new NeighborBlockBlock[4]; for (int j = 0; j < 4; j++) { NeighborBlock[j] = new NeighborBlockBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; ; for (int j = 0; j < 4; j++) { length += NeighborBlock[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); for (int j = 0; j < 4; j++) { NeighborBlock[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- NeighborList ---\n"; for (int j = 0; j < 4; j++) { output += NeighborBlock[j].ToString() + "\n"; } return output; } } /// MovedIntoSimulator packet public class MovedIntoSimulatorPacket : Packet { /// Sender block public class SenderBlock { /// ID field public LLUUID ID; /// SessionID field public LLUUID SessionID; /// CircuitCode field public uint CircuitCode; /// Length of this block serialized in bytes public int Length { get { return 36; } } /// Default constructor public SenderBlock() { } /// Constructor for building the block from a byte array public SenderBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; CircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(CircuitCode % 256); bytes[i++] = (byte)((CircuitCode >> 8) % 256); bytes[i++] = (byte)((CircuitCode >> 16) % 256); bytes[i++] = (byte)((CircuitCode >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Sender --\n"; output += "ID: " + ID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "CircuitCode: " + CircuitCode.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.MovedIntoSimulator public override PacketType Type { get { return PacketType.MovedIntoSimulator; } } /// Sender block public SenderBlock Sender; /// Default constructor public MovedIntoSimulatorPacket() { Header = new HighHeader(); Header.ID = 4; Header.Reliable = true; Sender = new SenderBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public MovedIntoSimulatorPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); Sender = new SenderBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public MovedIntoSimulatorPacket(Header head, byte[] bytes, ref int i) { Header = head; Sender = new SenderBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += Sender.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); Sender.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- MovedIntoSimulator ---\n"; output += Sender.ToString() + "\n"; return output; } } /// AgentUpdate packet public class AgentUpdatePacket : Packet { /// AgentData block public class AgentDataBlock { /// ControlFlags field public uint ControlFlags; /// CameraAtAxis field public LLVector3 CameraAtAxis; /// Far field public float Far; /// AgentID field public LLUUID AgentID; /// CameraCenter field public LLVector3 CameraCenter; /// CameraLeftAxis field public LLVector3 CameraLeftAxis; /// HeadRotation field public LLQuaternion HeadRotation; /// SessionID field public LLUUID SessionID; /// CameraUpAxis field public LLVector3 CameraUpAxis; /// BodyRotation field public LLQuaternion BodyRotation; /// Flags field public byte Flags; /// State field public byte State; /// Length of this block serialized in bytes public int Length { get { return 114; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { ControlFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CameraAtAxis = new LLVector3(bytes, i); i += 12; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Far = BitConverter.ToSingle(bytes, i); i += 4; AgentID = new LLUUID(bytes, i); i += 16; CameraCenter = new LLVector3(bytes, i); i += 12; CameraLeftAxis = new LLVector3(bytes, i); i += 12; HeadRotation = new LLQuaternion(bytes, i, true); i += 12; SessionID = new LLUUID(bytes, i); i += 16; CameraUpAxis = new LLVector3(bytes, i); i += 12; BodyRotation = new LLQuaternion(bytes, i, true); i += 12; Flags = (byte)bytes[i++]; State = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = (byte)(ControlFlags % 256); bytes[i++] = (byte)((ControlFlags >> 8) % 256); bytes[i++] = (byte)((ControlFlags >> 16) % 256); bytes[i++] = (byte)((ControlFlags >> 24) % 256); if(CameraAtAxis == null) { Console.WriteLine("Warning: CameraAtAxis is null, in " + this.GetType()); } Array.Copy(CameraAtAxis.GetBytes(), 0, bytes, i, 12); i += 12; ba = BitConverter.GetBytes(Far); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(CameraCenter == null) { Console.WriteLine("Warning: CameraCenter is null, in " + this.GetType()); } Array.Copy(CameraCenter.GetBytes(), 0, bytes, i, 12); i += 12; if(CameraLeftAxis == null) { Console.WriteLine("Warning: CameraLeftAxis is null, in " + this.GetType()); } Array.Copy(CameraLeftAxis.GetBytes(), 0, bytes, i, 12); i += 12; if(HeadRotation == null) { Console.WriteLine("Warning: HeadRotation is null, in " + this.GetType()); } Array.Copy(HeadRotation.GetBytes(), 0, bytes, i, 12); i += 12; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(CameraUpAxis == null) { Console.WriteLine("Warning: CameraUpAxis is null, in " + this.GetType()); } Array.Copy(CameraUpAxis.GetBytes(), 0, bytes, i, 12); i += 12; if(BodyRotation == null) { Console.WriteLine("Warning: BodyRotation is null, in " + this.GetType()); } Array.Copy(BodyRotation.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = Flags; bytes[i++] = State; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "ControlFlags: " + ControlFlags.ToString() + "\n"; output += "CameraAtAxis: " + CameraAtAxis.ToString() + "\n"; output += "Far: " + Far.ToString() + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "CameraCenter: " + CameraCenter.ToString() + "\n"; output += "CameraLeftAxis: " + CameraLeftAxis.ToString() + "\n"; output += "HeadRotation: " + HeadRotation.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "CameraUpAxis: " + CameraUpAxis.ToString() + "\n"; output += "BodyRotation: " + BodyRotation.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "State: " + State.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentUpdate public override PacketType Type { get { return PacketType.AgentUpdate; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentUpdatePacket() { Header = new HighHeader(); Header.ID = 5; Header.Reliable = true; Header.Zerocoded = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentUpdate ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// AgentAnimation packet public class AgentAnimationPacket : Packet { /// AnimationList block public class AnimationListBlock { /// AnimID field public LLUUID AnimID; /// StartAnim field public bool StartAnim; /// Length of this block serialized in bytes public int Length { get { return 17; } } /// Default constructor public AnimationListBlock() { } /// Constructor for building the block from a byte array public AnimationListBlock(byte[] bytes, ref int i) { try { AnimID = new LLUUID(bytes, i); i += 16; StartAnim = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AnimID == null) { Console.WriteLine("Warning: AnimID is null, in " + this.GetType()); } Array.Copy(AnimID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((StartAnim) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AnimationList --\n"; output += "AnimID: " + AnimID.ToString() + "\n"; output += "StartAnim: " + StartAnim.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentAnimation public override PacketType Type { get { return PacketType.AgentAnimation; } } /// AnimationList block public AnimationListBlock[] AnimationList; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentAnimationPacket() { Header = new HighHeader(); Header.ID = 6; Header.Reliable = true; AnimationList = new AnimationListBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentAnimationPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; AnimationList = new AnimationListBlock[count]; for (int j = 0; j < count; j++) { AnimationList[j] = new AnimationListBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentAnimationPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; AnimationList = new AnimationListBlock[count]; for (int j = 0; j < count; j++) { AnimationList[j] = new AnimationListBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += AgentData.Length;; length++; for (int j = 0; j < AnimationList.Length; j++) { length += AnimationList[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)AnimationList.Length; for (int j = 0; j < AnimationList.Length; j++) { AnimationList[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentAnimation ---\n"; for (int j = 0; j < AnimationList.Length; j++) { output += AnimationList[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// AgentRequestSit packet public class AgentRequestSitPacket : Packet { /// TargetObject block public class TargetObjectBlock { /// TargetID field public LLUUID TargetID; /// Offset field public LLVector3 Offset; /// Length of this block serialized in bytes public int Length { get { return 28; } } /// Default constructor public TargetObjectBlock() { } /// Constructor for building the block from a byte array public TargetObjectBlock(byte[] bytes, ref int i) { try { TargetID = new LLUUID(bytes, i); i += 16; Offset = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TargetID == null) { Console.WriteLine("Warning: TargetID is null, in " + this.GetType()); } Array.Copy(TargetID.GetBytes(), 0, bytes, i, 16); i += 16; if(Offset == null) { Console.WriteLine("Warning: Offset is null, in " + this.GetType()); } Array.Copy(Offset.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TargetObject --\n"; output += "TargetID: " + TargetID.ToString() + "\n"; output += "Offset: " + Offset.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentRequestSit public override PacketType Type { get { return PacketType.AgentRequestSit; } } /// TargetObject block public TargetObjectBlock TargetObject; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentRequestSitPacket() { Header = new HighHeader(); Header.ID = 7; Header.Reliable = true; Header.Zerocoded = true; TargetObject = new TargetObjectBlock(); AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentRequestSitPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); TargetObject = new TargetObjectBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentRequestSitPacket(Header head, byte[] bytes, ref int i) { Header = head; TargetObject = new TargetObjectBlock(bytes, ref i); AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += TargetObject.Length; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TargetObject.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentRequestSit ---\n"; output += TargetObject.ToString() + "\n"; output += AgentData.ToString() + "\n"; return output; } } /// AgentSit packet public class AgentSitPacket : Packet { /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentSit public override PacketType Type { get { return PacketType.AgentSit; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public AgentSitPacket() { Header = new HighHeader(); Header.ID = 8; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentSitPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentSitPacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentSit ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// RequestImage packet public class RequestImagePacket : Packet { /// RequestImage block public class RequestImageBlock { /// DownloadPriority field public float DownloadPriority; /// DiscardLevel field public sbyte DiscardLevel; /// Type field public byte Type; /// Packet field public uint Packet; /// Image field public LLUUID Image; /// Length of this block serialized in bytes public int Length { get { return 26; } } /// Default constructor public RequestImageBlock() { } /// Constructor for building the block from a byte array public RequestImageBlock(byte[] bytes, ref int i) { try { if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); DownloadPriority = BitConverter.ToSingle(bytes, i); i += 4; DiscardLevel = (sbyte)bytes[i++]; Type = (byte)bytes[i++]; Packet = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Image = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; ba = BitConverter.GetBytes(DownloadPriority); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)DiscardLevel; bytes[i++] = Type; bytes[i++] = (byte)(Packet % 256); bytes[i++] = (byte)((Packet >> 8) % 256); bytes[i++] = (byte)((Packet >> 16) % 256); bytes[i++] = (byte)((Packet >> 24) % 256); if(Image == null) { Console.WriteLine("Warning: Image is null, in " + this.GetType()); } Array.Copy(Image.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RequestImage --\n"; output += "DownloadPriority: " + DownloadPriority.ToString() + "\n"; output += "DiscardLevel: " + DiscardLevel.ToString() + "\n"; output += "Type: " + Type.ToString() + "\n"; output += "Packet: " + Packet.ToString() + "\n"; output += "Image: " + Image.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.RequestImage public override PacketType Type { get { return PacketType.RequestImage; } } /// RequestImage block public RequestImageBlock[] RequestImage; /// AgentData block public AgentDataBlock AgentData; /// Default constructor public RequestImagePacket() { Header = new HighHeader(); Header.ID = 9; Header.Reliable = true; RequestImage = new RequestImageBlock[0]; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public RequestImagePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; RequestImage = new RequestImageBlock[count]; for (int j = 0; j < count; j++) { RequestImage[j] = new RequestImageBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public RequestImagePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; RequestImage = new RequestImageBlock[count]; for (int j = 0; j < count; j++) { RequestImage[j] = new RequestImageBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += AgentData.Length;; length++; for (int j = 0; j < RequestImage.Length; j++) { length += RequestImage[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)RequestImage.Length; for (int j = 0; j < RequestImage.Length; j++) { RequestImage[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- RequestImage ---\n"; for (int j = 0; j < RequestImage.Length; j++) { output += RequestImage[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; return output; } } /// ImageData packet public class ImageDataPacket : Packet { /// ImageID block public class ImageIDBlock { /// ID field public LLUUID ID; /// Packets field public ushort Packets; /// Size field public uint Size; /// Codec field public byte Codec; /// Length of this block serialized in bytes public int Length { get { return 23; } } /// Default constructor public ImageIDBlock() { } /// Constructor for building the block from a byte array public ImageIDBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; Packets = (ushort)(bytes[i++] + (bytes[i++] << 8)); Size = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Codec = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Packets % 256); bytes[i++] = (byte)((Packets >> 8) % 256); bytes[i++] = (byte)(Size % 256); bytes[i++] = (byte)((Size >> 8) % 256); bytes[i++] = (byte)((Size >> 16) % 256); bytes[i++] = (byte)((Size >> 24) % 256); bytes[i++] = Codec; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ImageID --\n"; output += "ID: " + ID.ToString() + "\n"; output += "Packets: " + Packets.ToString() + "\n"; output += "Size: " + Size.ToString() + "\n"; output += "Codec: " + Codec.ToString() + "\n"; output = output.Trim(); return output; } } /// ImageData block public class ImageDataBlock { private byte[] _data; /// Data field public byte[] Data { get { return _data; } set { if (value == null) { _data = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _data = new byte[value.Length]; Array.Copy(value, _data, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (Data != null) { length += 2 + Data.Length; } return length; } } /// Default constructor public ImageDataBlock() { } /// Constructor for building the block from a byte array public ImageDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _data = new byte[length]; Array.Copy(bytes, i, _data, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Data == null) { Console.WriteLine("Warning: Data is null, in " + this.GetType()); } bytes[i++] = (byte)(Data.Length % 256); bytes[i++] = (byte)((Data.Length >> 8) % 256); Array.Copy(Data, 0, bytes, i, Data.Length); i += Data.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ImageData --\n"; output += Helpers.FieldToString(Data, "Data") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ImageData public override PacketType Type { get { return PacketType.ImageData; } } /// ImageID block public ImageIDBlock ImageID; /// ImageData block public ImageDataBlock ImageData; /// Default constructor public ImageDataPacket() { Header = new HighHeader(); Header.ID = 10; Header.Reliable = true; ImageID = new ImageIDBlock(); ImageData = new ImageDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ImageDataPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); ImageID = new ImageIDBlock(bytes, ref i); ImageData = new ImageDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ImageDataPacket(Header head, byte[] bytes, ref int i) { Header = head; ImageID = new ImageIDBlock(bytes, ref i); ImageData = new ImageDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += ImageID.Length; length += ImageData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ImageID.ToBytes(bytes, ref i); ImageData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ImageData ---\n"; output += ImageID.ToString() + "\n"; output += ImageData.ToString() + "\n"; return output; } } /// ImagePacket packet public class ImagePacketPacket : Packet { /// ImageID block public class ImageIDBlock { /// ID field public LLUUID ID; /// Packet field public ushort Packet; /// Length of this block serialized in bytes public int Length { get { return 18; } } /// Default constructor public ImageIDBlock() { } /// Constructor for building the block from a byte array public ImageIDBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; Packet = (ushort)(bytes[i++] + (bytes[i++] << 8)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Packet % 256); bytes[i++] = (byte)((Packet >> 8) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ImageID --\n"; output += "ID: " + ID.ToString() + "\n"; output += "Packet: " + Packet.ToString() + "\n"; output = output.Trim(); return output; } } /// ImageData block public class ImageDataBlock { private byte[] _data; /// Data field public byte[] Data { get { return _data; } set { if (value == null) { _data = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _data = new byte[value.Length]; Array.Copy(value, _data, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (Data != null) { length += 2 + Data.Length; } return length; } } /// Default constructor public ImageDataBlock() { } /// Constructor for building the block from a byte array public ImageDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _data = new byte[length]; Array.Copy(bytes, i, _data, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Data == null) { Console.WriteLine("Warning: Data is null, in " + this.GetType()); } bytes[i++] = (byte)(Data.Length % 256); bytes[i++] = (byte)((Data.Length >> 8) % 256); Array.Copy(Data, 0, bytes, i, Data.Length); i += Data.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ImageData --\n"; output += Helpers.FieldToString(Data, "Data") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ImagePacket public override PacketType Type { get { return PacketType.ImagePacket; } } /// ImageID block public ImageIDBlock ImageID; /// ImageData block public ImageDataBlock ImageData; /// Default constructor public ImagePacketPacket() { Header = new HighHeader(); Header.ID = 11; Header.Reliable = true; ImageID = new ImageIDBlock(); ImageData = new ImageDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ImagePacketPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); ImageID = new ImageIDBlock(bytes, ref i); ImageData = new ImageDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ImagePacketPacket(Header head, byte[] bytes, ref int i) { Header = head; ImageID = new ImageIDBlock(bytes, ref i); ImageData = new ImageDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += ImageID.Length; length += ImageData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ImageID.ToBytes(bytes, ref i); ImageData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ImagePacket ---\n"; output += ImageID.ToString() + "\n"; output += ImageData.ToString() + "\n"; return output; } } /// LayerData packet public class LayerDataPacket : Packet { /// LayerID block public class LayerIDBlock { /// Type field public byte Type; /// Length of this block serialized in bytes public int Length { get { return 1; } } /// Default constructor public LayerIDBlock() { } /// Constructor for building the block from a byte array public LayerIDBlock(byte[] bytes, ref int i) { try { Type = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = Type; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- LayerID --\n"; output += "Type: " + Type.ToString() + "\n"; output = output.Trim(); return output; } } /// LayerData block public class LayerDataBlock { private byte[] _data; /// Data field public byte[] Data { get { return _data; } set { if (value == null) { _data = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _data = new byte[value.Length]; Array.Copy(value, _data, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (Data != null) { length += 2 + Data.Length; } return length; } } /// Default constructor public LayerDataBlock() { } /// Constructor for building the block from a byte array public LayerDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _data = new byte[length]; Array.Copy(bytes, i, _data, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Data == null) { Console.WriteLine("Warning: Data is null, in " + this.GetType()); } bytes[i++] = (byte)(Data.Length % 256); bytes[i++] = (byte)((Data.Length >> 8) % 256); Array.Copy(Data, 0, bytes, i, Data.Length); i += Data.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- LayerData --\n"; output += Helpers.FieldToString(Data, "Data") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.LayerData public override PacketType Type { get { return PacketType.LayerData; } } /// LayerID block public LayerIDBlock LayerID; /// LayerData block public LayerDataBlock LayerData; /// Default constructor public LayerDataPacket() { Header = new HighHeader(); Header.ID = 12; Header.Reliable = true; LayerID = new LayerIDBlock(); LayerData = new LayerDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public LayerDataPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); LayerID = new LayerIDBlock(bytes, ref i); LayerData = new LayerDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public LayerDataPacket(Header head, byte[] bytes, ref int i) { Header = head; LayerID = new LayerIDBlock(bytes, ref i); LayerData = new LayerDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += LayerID.Length; length += LayerData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); LayerID.ToBytes(bytes, ref i); LayerData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- LayerData ---\n"; output += LayerID.ToString() + "\n"; output += LayerData.ToString() + "\n"; return output; } } /// ObjectUpdate packet public class ObjectUpdatePacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ID field public uint ID; /// UpdateFlags field public uint UpdateFlags; private byte[] _objectdata; /// ObjectData field public byte[] ObjectData { get { return _objectdata; } set { if (value == null) { _objectdata = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _objectdata = new byte[value.Length]; Array.Copy(value, _objectdata, value.Length); } } } /// PathTwistBegin field public sbyte PathTwistBegin; /// CRC field public uint CRC; /// JointPivot field public LLVector3 JointPivot; /// PathEnd field public byte PathEnd; private byte[] _mediaurl; /// MediaURL field public byte[] MediaURL { get { return _mediaurl; } set { if (value == null) { _mediaurl = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _mediaurl = new byte[value.Length]; Array.Copy(value, _mediaurl, value.Length); } } } /// TextColor field public byte[] TextColor; /// ClickAction field public byte ClickAction; /// ProfileBegin field public byte ProfileBegin; /// PathRadiusOffset field public sbyte PathRadiusOffset; /// Gain field public float Gain; /// PathSkew field public sbyte PathSkew; private byte[] _data; /// Data field public byte[] Data { get { return _data; } set { if (value == null) { _data = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _data = new byte[value.Length]; Array.Copy(value, _data, value.Length); } } } private byte[] _textureanim; /// TextureAnim field public byte[] TextureAnim { get { return _textureanim; } set { if (value == null) { _textureanim = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _textureanim = new byte[value.Length]; Array.Copy(value, _textureanim, value.Length); } } } /// ParentID field public uint ParentID; private byte[] _text; /// Text field public byte[] Text { get { return _text; } set { if (value == null) { _text = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _text = new byte[value.Length]; Array.Copy(value, _text, value.Length); } } } /// ProfileCurve field public byte ProfileCurve; /// PathScaleX field public byte PathScaleX; /// PathScaleY field public byte PathScaleY; /// Material field public byte Material; /// OwnerID field public LLUUID OwnerID; private byte[] _extraparams; /// ExtraParams field public byte[] ExtraParams { get { return _extraparams; } set { if (value == null) { _extraparams = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _extraparams = new byte[value.Length]; Array.Copy(value, _extraparams, value.Length); } } } private byte[] _namevalue; /// NameValue field public byte[] NameValue { get { return _namevalue; } set { if (value == null) { _namevalue = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _namevalue = new byte[value.Length]; Array.Copy(value, _namevalue, value.Length); } } } /// PathShearX field public byte PathShearX; /// PathShearY field public byte PathShearY; /// PathTaperX field public sbyte PathTaperX; /// PathTaperY field public sbyte PathTaperY; /// Radius field public float Radius; /// ProfileEnd field public byte ProfileEnd; /// JointType field public byte JointType; /// PathBegin field public byte PathBegin; private byte[] _psblock; /// PSBlock field public byte[] PSBlock { get { return _psblock; } set { if (value == null) { _psblock = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _psblock = new byte[value.Length]; Array.Copy(value, _psblock, value.Length); } } } /// PCode field public byte PCode; /// FullID field public LLUUID FullID; /// PathCurve field public byte PathCurve; /// Scale field public LLVector3 Scale; /// JointAxisOrAnchor field public LLVector3 JointAxisOrAnchor; /// Flags field public byte Flags; /// State field public byte State; /// PathTwist field public sbyte PathTwist; /// Sound field public LLUUID Sound; private byte[] _textureentry; /// TextureEntry field public byte[] TextureEntry { get { return _textureentry; } set { if (value == null) { _textureentry = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _textureentry = new byte[value.Length]; Array.Copy(value, _textureentry, value.Length); } } } /// ProfileHollow field public byte ProfileHollow; /// PathRevolutions field public byte PathRevolutions; /// Length of this block serialized in bytes public int Length { get { int length = 136; if (ObjectData != null) { length += 1 + ObjectData.Length; } if (MediaURL != null) { length += 1 + MediaURL.Length; } if (Data != null) { length += 2 + Data.Length; } if (TextureAnim != null) { length += 1 + TextureAnim.Length; } if (Text != null) { length += 1 + Text.Length; } if (ExtraParams != null) { length += 1 + ExtraParams.Length; } if (NameValue != null) { length += 2 + NameValue.Length; } if (PSBlock != null) { length += 1 + PSBlock.Length; } if (TextureEntry != null) { length += 2 + TextureEntry.Length; } return length; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { int length; try { ID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); UpdateFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _objectdata = new byte[length]; Array.Copy(bytes, i, _objectdata, 0, length); i += length; PathTwistBegin = (sbyte)bytes[i++]; CRC = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); JointPivot = new LLVector3(bytes, i); i += 12; PathEnd = (byte)bytes[i++]; length = (ushort)bytes[i++]; _mediaurl = new byte[length]; Array.Copy(bytes, i, _mediaurl, 0, length); i += length; TextColor = new byte[4]; Array.Copy(bytes, i, TextColor, 0, 4); i += 4; ClickAction = (byte)bytes[i++]; ProfileBegin = (byte)bytes[i++]; PathRadiusOffset = (sbyte)bytes[i++]; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Gain = BitConverter.ToSingle(bytes, i); i += 4; PathSkew = (sbyte)bytes[i++]; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _data = new byte[length]; Array.Copy(bytes, i, _data, 0, length); i += length; length = (ushort)bytes[i++]; _textureanim = new byte[length]; Array.Copy(bytes, i, _textureanim, 0, length); i += length; ParentID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _text = new byte[length]; Array.Copy(bytes, i, _text, 0, length); i += length; ProfileCurve = (byte)bytes[i++]; PathScaleX = (byte)bytes[i++]; PathScaleY = (byte)bytes[i++]; Material = (byte)bytes[i++]; OwnerID = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _extraparams = new byte[length]; Array.Copy(bytes, i, _extraparams, 0, length); i += length; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _namevalue = new byte[length]; Array.Copy(bytes, i, _namevalue, 0, length); i += length; PathShearX = (byte)bytes[i++]; PathShearY = (byte)bytes[i++]; PathTaperX = (sbyte)bytes[i++]; PathTaperY = (sbyte)bytes[i++]; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Radius = BitConverter.ToSingle(bytes, i); i += 4; ProfileEnd = (byte)bytes[i++]; JointType = (byte)bytes[i++]; PathBegin = (byte)bytes[i++]; length = (ushort)bytes[i++]; _psblock = new byte[length]; Array.Copy(bytes, i, _psblock, 0, length); i += length; PCode = (byte)bytes[i++]; FullID = new LLUUID(bytes, i); i += 16; PathCurve = (byte)bytes[i++]; Scale = new LLVector3(bytes, i); i += 12; JointAxisOrAnchor = new LLVector3(bytes, i); i += 12; Flags = (byte)bytes[i++]; State = (byte)bytes[i++]; PathTwist = (sbyte)bytes[i++]; Sound = new LLUUID(bytes, i); i += 16; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _textureentry = new byte[length]; Array.Copy(bytes, i, _textureentry, 0, length); i += length; ProfileHollow = (byte)bytes[i++]; PathRevolutions = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = (byte)(ID % 256); bytes[i++] = (byte)((ID >> 8) % 256); bytes[i++] = (byte)((ID >> 16) % 256); bytes[i++] = (byte)((ID >> 24) % 256); bytes[i++] = (byte)(UpdateFlags % 256); bytes[i++] = (byte)((UpdateFlags >> 8) % 256); bytes[i++] = (byte)((UpdateFlags >> 16) % 256); bytes[i++] = (byte)((UpdateFlags >> 24) % 256); if(ObjectData == null) { Console.WriteLine("Warning: ObjectData is null, in " + this.GetType()); } bytes[i++] = (byte)ObjectData.Length; Array.Copy(ObjectData, 0, bytes, i, ObjectData.Length); i += ObjectData.Length; bytes[i++] = (byte)PathTwistBegin; bytes[i++] = (byte)(CRC % 256); bytes[i++] = (byte)((CRC >> 8) % 256); bytes[i++] = (byte)((CRC >> 16) % 256); bytes[i++] = (byte)((CRC >> 24) % 256); if(JointPivot == null) { Console.WriteLine("Warning: JointPivot is null, in " + this.GetType()); } Array.Copy(JointPivot.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = PathEnd; if(MediaURL == null) { Console.WriteLine("Warning: MediaURL is null, in " + this.GetType()); } bytes[i++] = (byte)MediaURL.Length; Array.Copy(MediaURL, 0, bytes, i, MediaURL.Length); i += MediaURL.Length; Array.Copy(TextColor, 0, bytes, i, 4);i += 4; bytes[i++] = ClickAction; bytes[i++] = ProfileBegin; bytes[i++] = (byte)PathRadiusOffset; ba = BitConverter.GetBytes(Gain); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)PathSkew; if(Data == null) { Console.WriteLine("Warning: Data is null, in " + this.GetType()); } bytes[i++] = (byte)(Data.Length % 256); bytes[i++] = (byte)((Data.Length >> 8) % 256); Array.Copy(Data, 0, bytes, i, Data.Length); i += Data.Length; if(TextureAnim == null) { Console.WriteLine("Warning: TextureAnim is null, in " + this.GetType()); } bytes[i++] = (byte)TextureAnim.Length; Array.Copy(TextureAnim, 0, bytes, i, TextureAnim.Length); i += TextureAnim.Length; bytes[i++] = (byte)(ParentID % 256); bytes[i++] = (byte)((ParentID >> 8) % 256); bytes[i++] = (byte)((ParentID >> 16) % 256); bytes[i++] = (byte)((ParentID >> 24) % 256); if(Text == null) { Console.WriteLine("Warning: Text is null, in " + this.GetType()); } bytes[i++] = (byte)Text.Length; Array.Copy(Text, 0, bytes, i, Text.Length); i += Text.Length; bytes[i++] = ProfileCurve; bytes[i++] = PathScaleX; bytes[i++] = PathScaleY; bytes[i++] = Material; if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(ExtraParams == null) { Console.WriteLine("Warning: ExtraParams is null, in " + this.GetType()); } bytes[i++] = (byte)ExtraParams.Length; Array.Copy(ExtraParams, 0, bytes, i, ExtraParams.Length); i += ExtraParams.Length; if(NameValue == null) { Console.WriteLine("Warning: NameValue is null, in " + this.GetType()); } bytes[i++] = (byte)(NameValue.Length % 256); bytes[i++] = (byte)((NameValue.Length >> 8) % 256); Array.Copy(NameValue, 0, bytes, i, NameValue.Length); i += NameValue.Length; bytes[i++] = PathShearX; bytes[i++] = PathShearY; bytes[i++] = (byte)PathTaperX; bytes[i++] = (byte)PathTaperY; ba = BitConverter.GetBytes(Radius); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = ProfileEnd; bytes[i++] = JointType; bytes[i++] = PathBegin; if(PSBlock == null) { Console.WriteLine("Warning: PSBlock is null, in " + this.GetType()); } bytes[i++] = (byte)PSBlock.Length; Array.Copy(PSBlock, 0, bytes, i, PSBlock.Length); i += PSBlock.Length; bytes[i++] = PCode; if(FullID == null) { Console.WriteLine("Warning: FullID is null, in " + this.GetType()); } Array.Copy(FullID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = PathCurve; if(Scale == null) { Console.WriteLine("Warning: Scale is null, in " + this.GetType()); } Array.Copy(Scale.GetBytes(), 0, bytes, i, 12); i += 12; if(JointAxisOrAnchor == null) { Console.WriteLine("Warning: JointAxisOrAnchor is null, in " + this.GetType()); } Array.Copy(JointAxisOrAnchor.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = Flags; bytes[i++] = State; bytes[i++] = (byte)PathTwist; if(Sound == null) { Console.WriteLine("Warning: Sound is null, in " + this.GetType()); } Array.Copy(Sound.GetBytes(), 0, bytes, i, 16); i += 16; if(TextureEntry == null) { Console.WriteLine("Warning: TextureEntry is null, in " + this.GetType()); } bytes[i++] = (byte)(TextureEntry.Length % 256); bytes[i++] = (byte)((TextureEntry.Length >> 8) % 256); Array.Copy(TextureEntry, 0, bytes, i, TextureEntry.Length); i += TextureEntry.Length; bytes[i++] = ProfileHollow; bytes[i++] = PathRevolutions; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ID: " + ID.ToString() + "\n"; output += "UpdateFlags: " + UpdateFlags.ToString() + "\n"; output += Helpers.FieldToString(ObjectData, "ObjectData") + "\n"; output += "PathTwistBegin: " + PathTwistBegin.ToString() + "\n"; output += "CRC: " + CRC.ToString() + "\n"; output += "JointPivot: " + JointPivot.ToString() + "\n"; output += "PathEnd: " + PathEnd.ToString() + "\n"; output += Helpers.FieldToString(MediaURL, "MediaURL") + "\n"; output += Helpers.FieldToString(TextColor, "TextColor") + "\n"; output += "ClickAction: " + ClickAction.ToString() + "\n"; output += "ProfileBegin: " + ProfileBegin.ToString() + "\n"; output += "PathRadiusOffset: " + PathRadiusOffset.ToString() + "\n"; output += "Gain: " + Gain.ToString() + "\n"; output += "PathSkew: " + PathSkew.ToString() + "\n"; output += Helpers.FieldToString(Data, "Data") + "\n"; output += Helpers.FieldToString(TextureAnim, "TextureAnim") + "\n"; output += "ParentID: " + ParentID.ToString() + "\n"; output += Helpers.FieldToString(Text, "Text") + "\n"; output += "ProfileCurve: " + ProfileCurve.ToString() + "\n"; output += "PathScaleX: " + PathScaleX.ToString() + "\n"; output += "PathScaleY: " + PathScaleY.ToString() + "\n"; output += "Material: " + Material.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += Helpers.FieldToString(ExtraParams, "ExtraParams") + "\n"; output += Helpers.FieldToString(NameValue, "NameValue") + "\n"; output += "PathShearX: " + PathShearX.ToString() + "\n"; output += "PathShearY: " + PathShearY.ToString() + "\n"; output += "PathTaperX: " + PathTaperX.ToString() + "\n"; output += "PathTaperY: " + PathTaperY.ToString() + "\n"; output += "Radius: " + Radius.ToString() + "\n"; output += "ProfileEnd: " + ProfileEnd.ToString() + "\n"; output += "JointType: " + JointType.ToString() + "\n"; output += "PathBegin: " + PathBegin.ToString() + "\n"; output += Helpers.FieldToString(PSBlock, "PSBlock") + "\n"; output += "PCode: " + PCode.ToString() + "\n"; output += "FullID: " + FullID.ToString() + "\n"; output += "PathCurve: " + PathCurve.ToString() + "\n"; output += "Scale: " + Scale.ToString() + "\n"; output += "JointAxisOrAnchor: " + JointAxisOrAnchor.ToString() + "\n"; output += "Flags: " + Flags.ToString() + "\n"; output += "State: " + State.ToString() + "\n"; output += "PathTwist: " + PathTwist.ToString() + "\n"; output += "Sound: " + Sound.ToString() + "\n"; output += Helpers.FieldToString(TextureEntry, "TextureEntry") + "\n"; output += "ProfileHollow: " + ProfileHollow.ToString() + "\n"; output += "PathRevolutions: " + PathRevolutions.ToString() + "\n"; output = output.Trim(); return output; } } /// RegionData block public class RegionDataBlock { /// TimeDilation field public ushort TimeDilation; /// RegionHandle field public ulong RegionHandle; /// Length of this block serialized in bytes public int Length { get { return 10; } } /// Default constructor public RegionDataBlock() { } /// Constructor for building the block from a byte array public RegionDataBlock(byte[] bytes, ref int i) { try { TimeDilation = (ushort)(bytes[i++] + (bytes[i++] << 8)); RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(TimeDilation % 256); bytes[i++] = (byte)((TimeDilation >> 8) % 256); bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionData --\n"; output += "TimeDilation: " + TimeDilation.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectUpdate public override PacketType Type { get { return PacketType.ObjectUpdate; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// RegionData block public RegionDataBlock RegionData; /// Default constructor public ObjectUpdatePacket() { Header = new HighHeader(); Header.ID = 13; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock[0]; RegionData = new RegionDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } RegionData = new RegionDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } RegionData = new RegionDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += RegionData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } RegionData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectUpdate ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += RegionData.ToString() + "\n"; return output; } } /// ObjectUpdateCompressed packet public class ObjectUpdateCompressedPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// UpdateFlags field public uint UpdateFlags; private byte[] _data; /// Data field public byte[] Data { get { return _data; } set { if (value == null) { _data = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _data = new byte[value.Length]; Array.Copy(value, _data, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 4; if (Data != null) { length += 2 + Data.Length; } return length; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { int length; try { UpdateFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _data = new byte[length]; Array.Copy(bytes, i, _data, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(UpdateFlags % 256); bytes[i++] = (byte)((UpdateFlags >> 8) % 256); bytes[i++] = (byte)((UpdateFlags >> 16) % 256); bytes[i++] = (byte)((UpdateFlags >> 24) % 256); if(Data == null) { Console.WriteLine("Warning: Data is null, in " + this.GetType()); } bytes[i++] = (byte)(Data.Length % 256); bytes[i++] = (byte)((Data.Length >> 8) % 256); Array.Copy(Data, 0, bytes, i, Data.Length); i += Data.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "UpdateFlags: " + UpdateFlags.ToString() + "\n"; output += Helpers.FieldToString(Data, "Data") + "\n"; output = output.Trim(); return output; } } /// RegionData block public class RegionDataBlock { /// TimeDilation field public ushort TimeDilation; /// RegionHandle field public ulong RegionHandle; /// Length of this block serialized in bytes public int Length { get { return 10; } } /// Default constructor public RegionDataBlock() { } /// Constructor for building the block from a byte array public RegionDataBlock(byte[] bytes, ref int i) { try { TimeDilation = (ushort)(bytes[i++] + (bytes[i++] << 8)); RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(TimeDilation % 256); bytes[i++] = (byte)((TimeDilation >> 8) % 256); bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionData --\n"; output += "TimeDilation: " + TimeDilation.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectUpdateCompressed public override PacketType Type { get { return PacketType.ObjectUpdateCompressed; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// RegionData block public RegionDataBlock RegionData; /// Default constructor public ObjectUpdateCompressedPacket() { Header = new HighHeader(); Header.ID = 14; Header.Reliable = true; ObjectData = new ObjectDataBlock[0]; RegionData = new RegionDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectUpdateCompressedPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } RegionData = new RegionDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectUpdateCompressedPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } RegionData = new RegionDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += RegionData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } RegionData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectUpdateCompressed ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += RegionData.ToString() + "\n"; return output; } } /// ObjectUpdateCached packet public class ObjectUpdateCachedPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ID field public uint ID; /// UpdateFlags field public uint UpdateFlags; /// CRC field public uint CRC; /// Length of this block serialized in bytes public int Length { get { return 12; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); UpdateFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); CRC = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ID % 256); bytes[i++] = (byte)((ID >> 8) % 256); bytes[i++] = (byte)((ID >> 16) % 256); bytes[i++] = (byte)((ID >> 24) % 256); bytes[i++] = (byte)(UpdateFlags % 256); bytes[i++] = (byte)((UpdateFlags >> 8) % 256); bytes[i++] = (byte)((UpdateFlags >> 16) % 256); bytes[i++] = (byte)((UpdateFlags >> 24) % 256); bytes[i++] = (byte)(CRC % 256); bytes[i++] = (byte)((CRC >> 8) % 256); bytes[i++] = (byte)((CRC >> 16) % 256); bytes[i++] = (byte)((CRC >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ID: " + ID.ToString() + "\n"; output += "UpdateFlags: " + UpdateFlags.ToString() + "\n"; output += "CRC: " + CRC.ToString() + "\n"; output = output.Trim(); return output; } } /// RegionData block public class RegionDataBlock { /// TimeDilation field public ushort TimeDilation; /// RegionHandle field public ulong RegionHandle; /// Length of this block serialized in bytes public int Length { get { return 10; } } /// Default constructor public RegionDataBlock() { } /// Constructor for building the block from a byte array public RegionDataBlock(byte[] bytes, ref int i) { try { TimeDilation = (ushort)(bytes[i++] + (bytes[i++] << 8)); RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(TimeDilation % 256); bytes[i++] = (byte)((TimeDilation >> 8) % 256); bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionData --\n"; output += "TimeDilation: " + TimeDilation.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ObjectUpdateCached public override PacketType Type { get { return PacketType.ObjectUpdateCached; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// RegionData block public RegionDataBlock RegionData; /// Default constructor public ObjectUpdateCachedPacket() { Header = new HighHeader(); Header.ID = 15; Header.Reliable = true; ObjectData = new ObjectDataBlock[0]; RegionData = new RegionDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ObjectUpdateCachedPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } RegionData = new RegionDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ObjectUpdateCachedPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } RegionData = new RegionDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += RegionData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } RegionData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ObjectUpdateCached ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += RegionData.ToString() + "\n"; return output; } } /// ImprovedTerseObjectUpdate packet public class ImprovedTerseObjectUpdatePacket : Packet { /// ObjectData block public class ObjectDataBlock { private byte[] _data; /// Data field public byte[] Data { get { return _data; } set { if (value == null) { _data = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _data = new byte[value.Length]; Array.Copy(value, _data, value.Length); } } } private byte[] _textureentry; /// TextureEntry field public byte[] TextureEntry { get { return _textureentry; } set { if (value == null) { _textureentry = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _textureentry = new byte[value.Length]; Array.Copy(value, _textureentry, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (Data != null) { length += 1 + Data.Length; } if (TextureEntry != null) { length += 2 + TextureEntry.Length; } return length; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)bytes[i++]; _data = new byte[length]; Array.Copy(bytes, i, _data, 0, length); i += length; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _textureentry = new byte[length]; Array.Copy(bytes, i, _textureentry, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Data == null) { Console.WriteLine("Warning: Data is null, in " + this.GetType()); } bytes[i++] = (byte)Data.Length; Array.Copy(Data, 0, bytes, i, Data.Length); i += Data.Length; if(TextureEntry == null) { Console.WriteLine("Warning: TextureEntry is null, in " + this.GetType()); } bytes[i++] = (byte)(TextureEntry.Length % 256); bytes[i++] = (byte)((TextureEntry.Length >> 8) % 256); Array.Copy(TextureEntry, 0, bytes, i, TextureEntry.Length); i += TextureEntry.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += Helpers.FieldToString(Data, "Data") + "\n"; output += Helpers.FieldToString(TextureEntry, "TextureEntry") + "\n"; output = output.Trim(); return output; } } /// RegionData block public class RegionDataBlock { /// TimeDilation field public ushort TimeDilation; /// RegionHandle field public ulong RegionHandle; /// Length of this block serialized in bytes public int Length { get { return 10; } } /// Default constructor public RegionDataBlock() { } /// Constructor for building the block from a byte array public RegionDataBlock(byte[] bytes, ref int i) { try { TimeDilation = (ushort)(bytes[i++] + (bytes[i++] << 8)); RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(TimeDilation % 256); bytes[i++] = (byte)((TimeDilation >> 8) % 256); bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionData --\n"; output += "TimeDilation: " + TimeDilation.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ImprovedTerseObjectUpdate public override PacketType Type { get { return PacketType.ImprovedTerseObjectUpdate; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// RegionData block public RegionDataBlock RegionData; /// Default constructor public ImprovedTerseObjectUpdatePacket() { Header = new HighHeader(); Header.ID = 16; Header.Reliable = true; ObjectData = new ObjectDataBlock[0]; RegionData = new RegionDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ImprovedTerseObjectUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } RegionData = new RegionDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ImprovedTerseObjectUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } RegionData = new RegionDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += RegionData.Length;; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } RegionData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ImprovedTerseObjectUpdate ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } output += RegionData.ToString() + "\n"; return output; } } /// KillObject packet public class KillObjectPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ID field public uint ID; /// Length of this block serialized in bytes public int Length { get { return 4; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { try { ID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ID % 256); bytes[i++] = (byte)((ID >> 8) % 256); bytes[i++] = (byte)((ID >> 16) % 256); bytes[i++] = (byte)((ID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ID: " + ID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.KillObject public override PacketType Type { get { return PacketType.KillObject; } } /// ObjectData block public ObjectDataBlock[] ObjectData; /// Default constructor public KillObjectPacket() { Header = new HighHeader(); Header.ID = 17; Header.Reliable = true; ObjectData = new ObjectDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public KillObjectPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public KillObjectPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; ObjectData = new ObjectDataBlock[count]; for (int j = 0; j < count; j++) { ObjectData[j] = new ObjectDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; ; length++; for (int j = 0; j < ObjectData.Length; j++) { length += ObjectData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)ObjectData.Length; for (int j = 0; j < ObjectData.Length; j++) { ObjectData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- KillObject ---\n"; for (int j = 0; j < ObjectData.Length; j++) { output += ObjectData[j].ToString() + "\n"; } return output; } } /// AgentToNewRegion packet public class AgentToNewRegionPacket : Packet { /// RegionData block public class RegionDataBlock { /// IP field public uint IP; /// SessionID field public LLUUID SessionID; /// Port field public ushort Port; /// Handle field public ulong Handle; /// Length of this block serialized in bytes public int Length { get { return 30; } } /// Default constructor public RegionDataBlock() { } /// Constructor for building the block from a byte array public RegionDataBlock(byte[] bytes, ref int i) { try { IP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SessionID = new LLUUID(bytes, i); i += 16; Port = (ushort)((bytes[i++] << 8) + bytes[i++]); Handle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(IP % 256); bytes[i++] = (byte)((IP >> 8) % 256); bytes[i++] = (byte)((IP >> 16) % 256); bytes[i++] = (byte)((IP >> 24) % 256); if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((Port >> 8) % 256); bytes[i++] = (byte)(Port % 256); bytes[i++] = (byte)(Handle % 256); bytes[i++] = (byte)((Handle >> 8) % 256); bytes[i++] = (byte)((Handle >> 16) % 256); bytes[i++] = (byte)((Handle >> 24) % 256); bytes[i++] = (byte)((Handle >> 32) % 256); bytes[i++] = (byte)((Handle >> 40) % 256); bytes[i++] = (byte)((Handle >> 48) % 256); bytes[i++] = (byte)((Handle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- RegionData --\n"; output += "IP: " + IP.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "Port: " + Port.ToString() + "\n"; output += "Handle: " + Handle.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AgentToNewRegion public override PacketType Type { get { return PacketType.AgentToNewRegion; } } /// RegionData block public RegionDataBlock RegionData; /// Default constructor public AgentToNewRegionPacket() { Header = new HighHeader(); Header.ID = 18; Header.Reliable = true; RegionData = new RegionDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AgentToNewRegionPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); RegionData = new RegionDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AgentToNewRegionPacket(Header head, byte[] bytes, ref int i) { Header = head; RegionData = new RegionDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += RegionData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); RegionData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AgentToNewRegion ---\n"; output += RegionData.ToString() + "\n"; return output; } } /// TransferPacket packet public class TransferPacketPacket : Packet { /// TransferData block public class TransferDataBlock { /// TransferID field public LLUUID TransferID; private byte[] _data; /// Data field public byte[] Data { get { return _data; } set { if (value == null) { _data = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _data = new byte[value.Length]; Array.Copy(value, _data, value.Length); } } } /// Packet field public int Packet; /// ChannelType field public int ChannelType; /// Status field public int Status; /// Length of this block serialized in bytes public int Length { get { int length = 28; if (Data != null) { length += 2 + Data.Length; } return length; } } /// Default constructor public TransferDataBlock() { } /// Constructor for building the block from a byte array public TransferDataBlock(byte[] bytes, ref int i) { int length; try { TransferID = new LLUUID(bytes, i); i += 16; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _data = new byte[length]; Array.Copy(bytes, i, _data, 0, length); i += length; Packet = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ChannelType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Status = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(TransferID == null) { Console.WriteLine("Warning: TransferID is null, in " + this.GetType()); } Array.Copy(TransferID.GetBytes(), 0, bytes, i, 16); i += 16; if(Data == null) { Console.WriteLine("Warning: Data is null, in " + this.GetType()); } bytes[i++] = (byte)(Data.Length % 256); bytes[i++] = (byte)((Data.Length >> 8) % 256); Array.Copy(Data, 0, bytes, i, Data.Length); i += Data.Length; bytes[i++] = (byte)(Packet % 256); bytes[i++] = (byte)((Packet >> 8) % 256); bytes[i++] = (byte)((Packet >> 16) % 256); bytes[i++] = (byte)((Packet >> 24) % 256); bytes[i++] = (byte)(ChannelType % 256); bytes[i++] = (byte)((ChannelType >> 8) % 256); bytes[i++] = (byte)((ChannelType >> 16) % 256); bytes[i++] = (byte)((ChannelType >> 24) % 256); bytes[i++] = (byte)(Status % 256); bytes[i++] = (byte)((Status >> 8) % 256); bytes[i++] = (byte)((Status >> 16) % 256); bytes[i++] = (byte)((Status >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TransferData --\n"; output += "TransferID: " + TransferID.ToString() + "\n"; output += Helpers.FieldToString(Data, "Data") + "\n"; output += "Packet: " + Packet.ToString() + "\n"; output += "ChannelType: " + ChannelType.ToString() + "\n"; output += "Status: " + Status.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.TransferPacket public override PacketType Type { get { return PacketType.TransferPacket; } } /// TransferData block public TransferDataBlock TransferData; /// Default constructor public TransferPacketPacket() { Header = new HighHeader(); Header.ID = 19; Header.Reliable = true; TransferData = new TransferDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public TransferPacketPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); TransferData = new TransferDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public TransferPacketPacket(Header head, byte[] bytes, ref int i) { Header = head; TransferData = new TransferDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += TransferData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TransferData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- TransferPacket ---\n"; output += TransferData.ToString() + "\n"; return output; } } /// SendXferPacket packet public class SendXferPacketPacket : Packet { /// DataPacket block public class DataPacketBlock { private byte[] _data; /// Data field public byte[] Data { get { return _data; } set { if (value == null) { _data = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _data = new byte[value.Length]; Array.Copy(value, _data, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (Data != null) { length += 2 + Data.Length; } return length; } } /// Default constructor public DataPacketBlock() { } /// Constructor for building the block from a byte array public DataPacketBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _data = new byte[length]; Array.Copy(bytes, i, _data, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Data == null) { Console.WriteLine("Warning: Data is null, in " + this.GetType()); } bytes[i++] = (byte)(Data.Length % 256); bytes[i++] = (byte)((Data.Length >> 8) % 256); Array.Copy(Data, 0, bytes, i, Data.Length); i += Data.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- DataPacket --\n"; output += Helpers.FieldToString(Data, "Data") + "\n"; output = output.Trim(); return output; } } /// XferID block public class XferIDBlock { /// ID field public ulong ID; /// Packet field public uint Packet; /// Length of this block serialized in bytes public int Length { get { return 12; } } /// Default constructor public XferIDBlock() { } /// Constructor for building the block from a byte array public XferIDBlock(byte[] bytes, ref int i) { try { ID = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); Packet = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ID % 256); bytes[i++] = (byte)((ID >> 8) % 256); bytes[i++] = (byte)((ID >> 16) % 256); bytes[i++] = (byte)((ID >> 24) % 256); bytes[i++] = (byte)((ID >> 32) % 256); bytes[i++] = (byte)((ID >> 40) % 256); bytes[i++] = (byte)((ID >> 48) % 256); bytes[i++] = (byte)((ID >> 56) % 256); bytes[i++] = (byte)(Packet % 256); bytes[i++] = (byte)((Packet >> 8) % 256); bytes[i++] = (byte)((Packet >> 16) % 256); bytes[i++] = (byte)((Packet >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- XferID --\n"; output += "ID: " + ID.ToString() + "\n"; output += "Packet: " + Packet.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SendXferPacket public override PacketType Type { get { return PacketType.SendXferPacket; } } /// DataPacket block public DataPacketBlock DataPacket; /// XferID block public XferIDBlock XferID; /// Default constructor public SendXferPacketPacket() { Header = new HighHeader(); Header.ID = 20; Header.Reliable = true; DataPacket = new DataPacketBlock(); XferID = new XferIDBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SendXferPacketPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); DataPacket = new DataPacketBlock(bytes, ref i); XferID = new XferIDBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SendXferPacketPacket(Header head, byte[] bytes, ref int i) { Header = head; DataPacket = new DataPacketBlock(bytes, ref i); XferID = new XferIDBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += DataPacket.Length; length += XferID.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); DataPacket.ToBytes(bytes, ref i); XferID.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SendXferPacket ---\n"; output += DataPacket.ToString() + "\n"; output += XferID.ToString() + "\n"; return output; } } /// ConfirmXferPacket packet public class ConfirmXferPacketPacket : Packet { /// XferID block public class XferIDBlock { /// ID field public ulong ID; /// Packet field public uint Packet; /// Length of this block serialized in bytes public int Length { get { return 12; } } /// Default constructor public XferIDBlock() { } /// Constructor for building the block from a byte array public XferIDBlock(byte[] bytes, ref int i) { try { ID = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); Packet = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ID % 256); bytes[i++] = (byte)((ID >> 8) % 256); bytes[i++] = (byte)((ID >> 16) % 256); bytes[i++] = (byte)((ID >> 24) % 256); bytes[i++] = (byte)((ID >> 32) % 256); bytes[i++] = (byte)((ID >> 40) % 256); bytes[i++] = (byte)((ID >> 48) % 256); bytes[i++] = (byte)((ID >> 56) % 256); bytes[i++] = (byte)(Packet % 256); bytes[i++] = (byte)((Packet >> 8) % 256); bytes[i++] = (byte)((Packet >> 16) % 256); bytes[i++] = (byte)((Packet >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- XferID --\n"; output += "ID: " + ID.ToString() + "\n"; output += "Packet: " + Packet.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ConfirmXferPacket public override PacketType Type { get { return PacketType.ConfirmXferPacket; } } /// XferID block public XferIDBlock XferID; /// Default constructor public ConfirmXferPacketPacket() { Header = new HighHeader(); Header.ID = 21; Header.Reliable = true; XferID = new XferIDBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ConfirmXferPacketPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); XferID = new XferIDBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ConfirmXferPacketPacket(Header head, byte[] bytes, ref int i) { Header = head; XferID = new XferIDBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += XferID.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); XferID.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ConfirmXferPacket ---\n"; output += XferID.ToString() + "\n"; return output; } } /// AvatarAnimation packet public class AvatarAnimationPacket : Packet { /// AnimationSourceList block public class AnimationSourceListBlock { /// ObjectID field public LLUUID ObjectID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public AnimationSourceListBlock() { } /// Constructor for building the block from a byte array public AnimationSourceListBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AnimationSourceList --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output = output.Trim(); return output; } } /// Sender block public class SenderBlock { /// ID field public LLUUID ID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public SenderBlock() { } /// Constructor for building the block from a byte array public SenderBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- Sender --\n"; output += "ID: " + ID.ToString() + "\n"; output = output.Trim(); return output; } } /// AnimationList block public class AnimationListBlock { /// AnimID field public LLUUID AnimID; /// AnimSequenceID field public int AnimSequenceID; /// Length of this block serialized in bytes public int Length { get { return 20; } } /// Default constructor public AnimationListBlock() { } /// Constructor for building the block from a byte array public AnimationListBlock(byte[] bytes, ref int i) { try { AnimID = new LLUUID(bytes, i); i += 16; AnimSequenceID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(AnimID == null) { Console.WriteLine("Warning: AnimID is null, in " + this.GetType()); } Array.Copy(AnimID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(AnimSequenceID % 256); bytes[i++] = (byte)((AnimSequenceID >> 8) % 256); bytes[i++] = (byte)((AnimSequenceID >> 16) % 256); bytes[i++] = (byte)((AnimSequenceID >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AnimationList --\n"; output += "AnimID: " + AnimID.ToString() + "\n"; output += "AnimSequenceID: " + AnimSequenceID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AvatarAnimation public override PacketType Type { get { return PacketType.AvatarAnimation; } } /// AnimationSourceList block public AnimationSourceListBlock[] AnimationSourceList; /// Sender block public SenderBlock Sender; /// AnimationList block public AnimationListBlock[] AnimationList; /// Default constructor public AvatarAnimationPacket() { Header = new HighHeader(); Header.ID = 22; Header.Reliable = true; AnimationSourceList = new AnimationSourceListBlock[0]; Sender = new SenderBlock(); AnimationList = new AnimationListBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AvatarAnimationPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; AnimationSourceList = new AnimationSourceListBlock[count]; for (int j = 0; j < count; j++) { AnimationSourceList[j] = new AnimationSourceListBlock(bytes, ref i); } Sender = new SenderBlock(bytes, ref i); count = (int)bytes[i++]; AnimationList = new AnimationListBlock[count]; for (int j = 0; j < count; j++) { AnimationList[j] = new AnimationListBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public AvatarAnimationPacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; AnimationSourceList = new AnimationSourceListBlock[count]; for (int j = 0; j < count; j++) { AnimationSourceList[j] = new AnimationSourceListBlock(bytes, ref i); } Sender = new SenderBlock(bytes, ref i); count = (int)bytes[i++]; AnimationList = new AnimationListBlock[count]; for (int j = 0; j < count; j++) { AnimationList[j] = new AnimationListBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += Sender.Length;; length++; for (int j = 0; j < AnimationSourceList.Length; j++) { length += AnimationSourceList[j].Length; } length++; for (int j = 0; j < AnimationList.Length; j++) { length += AnimationList[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)AnimationSourceList.Length; for (int j = 0; j < AnimationSourceList.Length; j++) { AnimationSourceList[j].ToBytes(bytes, ref i); } Sender.ToBytes(bytes, ref i); bytes[i++] = (byte)AnimationList.Length; for (int j = 0; j < AnimationList.Length; j++) { AnimationList[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AvatarAnimation ---\n"; for (int j = 0; j < AnimationSourceList.Length; j++) { output += AnimationSourceList[j].ToString() + "\n"; } output += Sender.ToString() + "\n"; for (int j = 0; j < AnimationList.Length; j++) { output += AnimationList[j].ToString() + "\n"; } return output; } } /// AvatarSitResponse packet public class AvatarSitResponsePacket : Packet { /// SitTransform block public class SitTransformBlock { /// AutoPilot field public bool AutoPilot; /// ForceMouselook field public bool ForceMouselook; /// CameraEyeOffset field public LLVector3 CameraEyeOffset; /// CameraAtOffset field public LLVector3 CameraAtOffset; /// SitPosition field public LLVector3 SitPosition; /// SitRotation field public LLQuaternion SitRotation; /// Length of this block serialized in bytes public int Length { get { return 50; } } /// Default constructor public SitTransformBlock() { } /// Constructor for building the block from a byte array public SitTransformBlock(byte[] bytes, ref int i) { try { AutoPilot = (bytes[i++] != 0) ? (bool)true : (bool)false; ForceMouselook = (bytes[i++] != 0) ? (bool)true : (bool)false; CameraEyeOffset = new LLVector3(bytes, i); i += 12; CameraAtOffset = new LLVector3(bytes, i); i += 12; SitPosition = new LLVector3(bytes, i); i += 12; SitRotation = new LLQuaternion(bytes, i, true); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((AutoPilot) ? 1 : 0); bytes[i++] = (byte)((ForceMouselook) ? 1 : 0); if(CameraEyeOffset == null) { Console.WriteLine("Warning: CameraEyeOffset is null, in " + this.GetType()); } Array.Copy(CameraEyeOffset.GetBytes(), 0, bytes, i, 12); i += 12; if(CameraAtOffset == null) { Console.WriteLine("Warning: CameraAtOffset is null, in " + this.GetType()); } Array.Copy(CameraAtOffset.GetBytes(), 0, bytes, i, 12); i += 12; if(SitPosition == null) { Console.WriteLine("Warning: SitPosition is null, in " + this.GetType()); } Array.Copy(SitPosition.GetBytes(), 0, bytes, i, 12); i += 12; if(SitRotation == null) { Console.WriteLine("Warning: SitRotation is null, in " + this.GetType()); } Array.Copy(SitRotation.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- SitTransform --\n"; output += "AutoPilot: " + AutoPilot.ToString() + "\n"; output += "ForceMouselook: " + ForceMouselook.ToString() + "\n"; output += "CameraEyeOffset: " + CameraEyeOffset.ToString() + "\n"; output += "CameraAtOffset: " + CameraAtOffset.ToString() + "\n"; output += "SitPosition: " + SitPosition.ToString() + "\n"; output += "SitRotation: " + SitRotation.ToString() + "\n"; output = output.Trim(); return output; } } /// SitObject block public class SitObjectBlock { /// ID field public LLUUID ID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public SitObjectBlock() { } /// Constructor for building the block from a byte array public SitObjectBlock(byte[] bytes, ref int i) { try { ID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- SitObject --\n"; output += "ID: " + ID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AvatarSitResponse public override PacketType Type { get { return PacketType.AvatarSitResponse; } } /// SitTransform block public SitTransformBlock SitTransform; /// SitObject block public SitObjectBlock SitObject; /// Default constructor public AvatarSitResponsePacket() { Header = new HighHeader(); Header.ID = 23; Header.Reliable = true; Header.Zerocoded = true; SitTransform = new SitTransformBlock(); SitObject = new SitObjectBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AvatarSitResponsePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); SitTransform = new SitTransformBlock(bytes, ref i); SitObject = new SitObjectBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AvatarSitResponsePacket(Header head, byte[] bytes, ref int i) { Header = head; SitTransform = new SitTransformBlock(bytes, ref i); SitObject = new SitObjectBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += SitTransform.Length; length += SitObject.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); SitTransform.ToBytes(bytes, ref i); SitObject.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AvatarSitResponse ---\n"; output += SitTransform.ToString() + "\n"; output += SitObject.ToString() + "\n"; return output; } } /// CameraConstraint packet public class CameraConstraintPacket : Packet { /// CameraCollidePlane block public class CameraCollidePlaneBlock { /// Plane field public LLVector4 Plane; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public CameraCollidePlaneBlock() { } /// Constructor for building the block from a byte array public CameraCollidePlaneBlock(byte[] bytes, ref int i) { try { Plane = new LLVector4(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(Plane == null) { Console.WriteLine("Warning: Plane is null, in " + this.GetType()); } Array.Copy(Plane.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- CameraCollidePlane --\n"; output += "Plane: " + Plane.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.CameraConstraint public override PacketType Type { get { return PacketType.CameraConstraint; } } /// CameraCollidePlane block public CameraCollidePlaneBlock CameraCollidePlane; /// Default constructor public CameraConstraintPacket() { Header = new HighHeader(); Header.ID = 24; Header.Reliable = true; Header.Zerocoded = true; CameraCollidePlane = new CameraCollidePlaneBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public CameraConstraintPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); CameraCollidePlane = new CameraCollidePlaneBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public CameraConstraintPacket(Header head, byte[] bytes, ref int i) { Header = head; CameraCollidePlane = new CameraCollidePlaneBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += CameraCollidePlane.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); CameraCollidePlane.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- CameraConstraint ---\n"; output += CameraCollidePlane.ToString() + "\n"; return output; } } /// ParcelProperties packet public class ParcelPropertiesPacket : Packet { /// ParcelData block public class ParcelDataBlock { /// ReservedNewbie field public bool ReservedNewbie; /// GroupPrims field public int GroupPrims; /// SelectedPrims field public int SelectedPrims; /// MediaID field public LLUUID MediaID; /// UserLookAt field public LLVector3 UserLookAt; /// AABBMax field public LLVector3 AABBMax; /// AABBMin field public LLVector3 AABBMin; /// RequestResult field public int RequestResult; /// OwnerPrims field public int OwnerPrims; /// RegionPushOverride field public bool RegionPushOverride; /// RegionDenyAnonymous field public bool RegionDenyAnonymous; private byte[] _mediaurl; /// MediaURL field public byte[] MediaURL { get { return _mediaurl; } set { if (value == null) { _mediaurl = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _mediaurl = new byte[value.Length]; Array.Copy(value, _mediaurl, value.Length); } } } /// LocalID field public int LocalID; /// SimWideMaxPrims field public int SimWideMaxPrims; /// TotalPrims field public int TotalPrims; /// OtherCount field public int OtherCount; /// IsGroupOwned field public bool IsGroupOwned; /// UserLocation field public LLVector3 UserLocation; /// MaxPrims field public int MaxPrims; private byte[] _name; /// Name field public byte[] Name { get { return _name; } set { if (value == null) { _name = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _name = new byte[value.Length]; Array.Copy(value, _name, value.Length); } } } /// OtherCleanTime field public int OtherCleanTime; private byte[] _desc; /// Desc field public byte[] Desc { get { return _desc; } set { if (value == null) { _desc = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _desc = new byte[value.Length]; Array.Copy(value, _desc, value.Length); } } } /// Area field public int Area; /// OtherPrims field public int OtherPrims; /// RegionDenyIdentified field public bool RegionDenyIdentified; /// Category field public byte Category; /// PublicCount field public int PublicCount; /// GroupID field public LLUUID GroupID; /// SalePrice field public int SalePrice; /// OwnerID field public LLUUID OwnerID; /// SequenceID field public int SequenceID; /// RegionDenyTransacted field public bool RegionDenyTransacted; /// SelfCount field public int SelfCount; private byte[] _bitmap; /// Bitmap field public byte[] Bitmap { get { return _bitmap; } set { if (value == null) { _bitmap = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _bitmap = new byte[value.Length]; Array.Copy(value, _bitmap, value.Length); } } } /// Status field public byte Status; /// SnapshotID field public LLUUID SnapshotID; /// SnapSelection field public bool SnapSelection; /// LandingType field public byte LandingType; /// SimWideTotalPrims field public int SimWideTotalPrims; /// AuctionID field public uint AuctionID; /// AuthBuyerID field public LLUUID AuthBuyerID; /// PassHours field public float PassHours; /// ParcelFlags field public uint ParcelFlags; /// PassPrice field public int PassPrice; /// ClaimDate field public int ClaimDate; /// MediaAutoScale field public byte MediaAutoScale; private byte[] _musicurl; /// MusicURL field public byte[] MusicURL { get { return _musicurl; } set { if (value == null) { _musicurl = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _musicurl = new byte[value.Length]; Array.Copy(value, _musicurl, value.Length); } } } /// ParcelPrimBonus field public float ParcelPrimBonus; /// ClaimPrice field public int ClaimPrice; /// RentPrice field public int RentPrice; /// Length of this block serialized in bytes public int Length { get { int length = 239; if (MediaURL != null) { length += 1 + MediaURL.Length; } if (Name != null) { length += 1 + Name.Length; } if (Desc != null) { length += 1 + Desc.Length; } if (Bitmap != null) { length += 2 + Bitmap.Length; } if (MusicURL != null) { length += 1 + MusicURL.Length; } return length; } } /// Default constructor public ParcelDataBlock() { } /// Constructor for building the block from a byte array public ParcelDataBlock(byte[] bytes, ref int i) { int length; try { ReservedNewbie = (bytes[i++] != 0) ? (bool)true : (bool)false; GroupPrims = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SelectedPrims = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); MediaID = new LLUUID(bytes, i); i += 16; UserLookAt = new LLVector3(bytes, i); i += 12; AABBMax = new LLVector3(bytes, i); i += 12; AABBMin = new LLVector3(bytes, i); i += 12; RequestResult = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerPrims = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RegionPushOverride = (bytes[i++] != 0) ? (bool)true : (bool)false; RegionDenyAnonymous = (bytes[i++] != 0) ? (bool)true : (bool)false; length = (ushort)bytes[i++]; _mediaurl = new byte[length]; Array.Copy(bytes, i, _mediaurl, 0, length); i += length; LocalID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); SimWideMaxPrims = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); TotalPrims = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OtherCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); IsGroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; UserLocation = new LLVector3(bytes, i); i += 12; MaxPrims = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _name = new byte[length]; Array.Copy(bytes, i, _name, 0, length); i += length; OtherCleanTime = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)bytes[i++]; _desc = new byte[length]; Array.Copy(bytes, i, _desc, 0, length); i += length; Area = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OtherPrims = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RegionDenyIdentified = (bytes[i++] != 0) ? (bool)true : (bool)false; Category = (byte)bytes[i++]; PublicCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupID = new LLUUID(bytes, i); i += 16; SalePrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerID = new LLUUID(bytes, i); i += 16; SequenceID = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RegionDenyTransacted = (bytes[i++] != 0) ? (bool)true : (bool)false; SelfCount = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _bitmap = new byte[length]; Array.Copy(bytes, i, _bitmap, 0, length); i += length; Status = (byte)bytes[i++]; SnapshotID = new LLUUID(bytes, i); i += 16; SnapSelection = (bytes[i++] != 0) ? (bool)true : (bool)false; LandingType = (byte)bytes[i++]; SimWideTotalPrims = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); AuctionID = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); AuthBuyerID = new LLUUID(bytes, i); i += 16; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); PassHours = BitConverter.ToSingle(bytes, i); i += 4; ParcelFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); PassPrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ClaimDate = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); MediaAutoScale = (byte)bytes[i++]; length = (ushort)bytes[i++]; _musicurl = new byte[length]; Array.Copy(bytes, i, _musicurl, 0, length); i += length; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); ParcelPrimBonus = BitConverter.ToSingle(bytes, i); i += 4; ClaimPrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); RentPrice = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = (byte)((ReservedNewbie) ? 1 : 0); bytes[i++] = (byte)(GroupPrims % 256); bytes[i++] = (byte)((GroupPrims >> 8) % 256); bytes[i++] = (byte)((GroupPrims >> 16) % 256); bytes[i++] = (byte)((GroupPrims >> 24) % 256); bytes[i++] = (byte)(SelectedPrims % 256); bytes[i++] = (byte)((SelectedPrims >> 8) % 256); bytes[i++] = (byte)((SelectedPrims >> 16) % 256); bytes[i++] = (byte)((SelectedPrims >> 24) % 256); if(MediaID == null) { Console.WriteLine("Warning: MediaID is null, in " + this.GetType()); } Array.Copy(MediaID.GetBytes(), 0, bytes, i, 16); i += 16; if(UserLookAt == null) { Console.WriteLine("Warning: UserLookAt is null, in " + this.GetType()); } Array.Copy(UserLookAt.GetBytes(), 0, bytes, i, 12); i += 12; if(AABBMax == null) { Console.WriteLine("Warning: AABBMax is null, in " + this.GetType()); } Array.Copy(AABBMax.GetBytes(), 0, bytes, i, 12); i += 12; if(AABBMin == null) { Console.WriteLine("Warning: AABBMin is null, in " + this.GetType()); } Array.Copy(AABBMin.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = (byte)(RequestResult % 256); bytes[i++] = (byte)((RequestResult >> 8) % 256); bytes[i++] = (byte)((RequestResult >> 16) % 256); bytes[i++] = (byte)((RequestResult >> 24) % 256); bytes[i++] = (byte)(OwnerPrims % 256); bytes[i++] = (byte)((OwnerPrims >> 8) % 256); bytes[i++] = (byte)((OwnerPrims >> 16) % 256); bytes[i++] = (byte)((OwnerPrims >> 24) % 256); bytes[i++] = (byte)((RegionPushOverride) ? 1 : 0); bytes[i++] = (byte)((RegionDenyAnonymous) ? 1 : 0); if(MediaURL == null) { Console.WriteLine("Warning: MediaURL is null, in " + this.GetType()); } bytes[i++] = (byte)MediaURL.Length; Array.Copy(MediaURL, 0, bytes, i, MediaURL.Length); i += MediaURL.Length; bytes[i++] = (byte)(LocalID % 256); bytes[i++] = (byte)((LocalID >> 8) % 256); bytes[i++] = (byte)((LocalID >> 16) % 256); bytes[i++] = (byte)((LocalID >> 24) % 256); bytes[i++] = (byte)(SimWideMaxPrims % 256); bytes[i++] = (byte)((SimWideMaxPrims >> 8) % 256); bytes[i++] = (byte)((SimWideMaxPrims >> 16) % 256); bytes[i++] = (byte)((SimWideMaxPrims >> 24) % 256); bytes[i++] = (byte)(TotalPrims % 256); bytes[i++] = (byte)((TotalPrims >> 8) % 256); bytes[i++] = (byte)((TotalPrims >> 16) % 256); bytes[i++] = (byte)((TotalPrims >> 24) % 256); bytes[i++] = (byte)(OtherCount % 256); bytes[i++] = (byte)((OtherCount >> 8) % 256); bytes[i++] = (byte)((OtherCount >> 16) % 256); bytes[i++] = (byte)((OtherCount >> 24) % 256); bytes[i++] = (byte)((IsGroupOwned) ? 1 : 0); if(UserLocation == null) { Console.WriteLine("Warning: UserLocation is null, in " + this.GetType()); } Array.Copy(UserLocation.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = (byte)(MaxPrims % 256); bytes[i++] = (byte)((MaxPrims >> 8) % 256); bytes[i++] = (byte)((MaxPrims >> 16) % 256); bytes[i++] = (byte)((MaxPrims >> 24) % 256); if(Name == null) { Console.WriteLine("Warning: Name is null, in " + this.GetType()); } bytes[i++] = (byte)Name.Length; Array.Copy(Name, 0, bytes, i, Name.Length); i += Name.Length; bytes[i++] = (byte)(OtherCleanTime % 256); bytes[i++] = (byte)((OtherCleanTime >> 8) % 256); bytes[i++] = (byte)((OtherCleanTime >> 16) % 256); bytes[i++] = (byte)((OtherCleanTime >> 24) % 256); if(Desc == null) { Console.WriteLine("Warning: Desc is null, in " + this.GetType()); } bytes[i++] = (byte)Desc.Length; Array.Copy(Desc, 0, bytes, i, Desc.Length); i += Desc.Length; bytes[i++] = (byte)(Area % 256); bytes[i++] = (byte)((Area >> 8) % 256); bytes[i++] = (byte)((Area >> 16) % 256); bytes[i++] = (byte)((Area >> 24) % 256); bytes[i++] = (byte)(OtherPrims % 256); bytes[i++] = (byte)((OtherPrims >> 8) % 256); bytes[i++] = (byte)((OtherPrims >> 16) % 256); bytes[i++] = (byte)((OtherPrims >> 24) % 256); bytes[i++] = (byte)((RegionDenyIdentified) ? 1 : 0); bytes[i++] = Category; bytes[i++] = (byte)(PublicCount % 256); bytes[i++] = (byte)((PublicCount >> 8) % 256); bytes[i++] = (byte)((PublicCount >> 16) % 256); bytes[i++] = (byte)((PublicCount >> 24) % 256); if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(SalePrice % 256); bytes[i++] = (byte)((SalePrice >> 8) % 256); bytes[i++] = (byte)((SalePrice >> 16) % 256); bytes[i++] = (byte)((SalePrice >> 24) % 256); if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(SequenceID % 256); bytes[i++] = (byte)((SequenceID >> 8) % 256); bytes[i++] = (byte)((SequenceID >> 16) % 256); bytes[i++] = (byte)((SequenceID >> 24) % 256); bytes[i++] = (byte)((RegionDenyTransacted) ? 1 : 0); bytes[i++] = (byte)(SelfCount % 256); bytes[i++] = (byte)((SelfCount >> 8) % 256); bytes[i++] = (byte)((SelfCount >> 16) % 256); bytes[i++] = (byte)((SelfCount >> 24) % 256); if(Bitmap == null) { Console.WriteLine("Warning: Bitmap is null, in " + this.GetType()); } bytes[i++] = (byte)(Bitmap.Length % 256); bytes[i++] = (byte)((Bitmap.Length >> 8) % 256); Array.Copy(Bitmap, 0, bytes, i, Bitmap.Length); i += Bitmap.Length; bytes[i++] = Status; if(SnapshotID == null) { Console.WriteLine("Warning: SnapshotID is null, in " + this.GetType()); } Array.Copy(SnapshotID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((SnapSelection) ? 1 : 0); bytes[i++] = LandingType; bytes[i++] = (byte)(SimWideTotalPrims % 256); bytes[i++] = (byte)((SimWideTotalPrims >> 8) % 256); bytes[i++] = (byte)((SimWideTotalPrims >> 16) % 256); bytes[i++] = (byte)((SimWideTotalPrims >> 24) % 256); bytes[i++] = (byte)(AuctionID % 256); bytes[i++] = (byte)((AuctionID >> 8) % 256); bytes[i++] = (byte)((AuctionID >> 16) % 256); bytes[i++] = (byte)((AuctionID >> 24) % 256); if(AuthBuyerID == null) { Console.WriteLine("Warning: AuthBuyerID is null, in " + this.GetType()); } Array.Copy(AuthBuyerID.GetBytes(), 0, bytes, i, 16); i += 16; ba = BitConverter.GetBytes(PassHours); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(ParcelFlags % 256); bytes[i++] = (byte)((ParcelFlags >> 8) % 256); bytes[i++] = (byte)((ParcelFlags >> 16) % 256); bytes[i++] = (byte)((ParcelFlags >> 24) % 256); bytes[i++] = (byte)(PassPrice % 256); bytes[i++] = (byte)((PassPrice >> 8) % 256); bytes[i++] = (byte)((PassPrice >> 16) % 256); bytes[i++] = (byte)((PassPrice >> 24) % 256); bytes[i++] = (byte)(ClaimDate % 256); bytes[i++] = (byte)((ClaimDate >> 8) % 256); bytes[i++] = (byte)((ClaimDate >> 16) % 256); bytes[i++] = (byte)((ClaimDate >> 24) % 256); bytes[i++] = MediaAutoScale; if(MusicURL == null) { Console.WriteLine("Warning: MusicURL is null, in " + this.GetType()); } bytes[i++] = (byte)MusicURL.Length; Array.Copy(MusicURL, 0, bytes, i, MusicURL.Length); i += MusicURL.Length; ba = BitConverter.GetBytes(ParcelPrimBonus); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(ClaimPrice % 256); bytes[i++] = (byte)((ClaimPrice >> 8) % 256); bytes[i++] = (byte)((ClaimPrice >> 16) % 256); bytes[i++] = (byte)((ClaimPrice >> 24) % 256); bytes[i++] = (byte)(RentPrice % 256); bytes[i++] = (byte)((RentPrice >> 8) % 256); bytes[i++] = (byte)((RentPrice >> 16) % 256); bytes[i++] = (byte)((RentPrice >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ParcelData --\n"; output += "ReservedNewbie: " + ReservedNewbie.ToString() + "\n"; output += "GroupPrims: " + GroupPrims.ToString() + "\n"; output += "SelectedPrims: " + SelectedPrims.ToString() + "\n"; output += "MediaID: " + MediaID.ToString() + "\n"; output += "UserLookAt: " + UserLookAt.ToString() + "\n"; output += "AABBMax: " + AABBMax.ToString() + "\n"; output += "AABBMin: " + AABBMin.ToString() + "\n"; output += "RequestResult: " + RequestResult.ToString() + "\n"; output += "OwnerPrims: " + OwnerPrims.ToString() + "\n"; output += "RegionPushOverride: " + RegionPushOverride.ToString() + "\n"; output += "RegionDenyAnonymous: " + RegionDenyAnonymous.ToString() + "\n"; output += Helpers.FieldToString(MediaURL, "MediaURL") + "\n"; output += "LocalID: " + LocalID.ToString() + "\n"; output += "SimWideMaxPrims: " + SimWideMaxPrims.ToString() + "\n"; output += "TotalPrims: " + TotalPrims.ToString() + "\n"; output += "OtherCount: " + OtherCount.ToString() + "\n"; output += "IsGroupOwned: " + IsGroupOwned.ToString() + "\n"; output += "UserLocation: " + UserLocation.ToString() + "\n"; output += "MaxPrims: " + MaxPrims.ToString() + "\n"; output += Helpers.FieldToString(Name, "Name") + "\n"; output += "OtherCleanTime: " + OtherCleanTime.ToString() + "\n"; output += Helpers.FieldToString(Desc, "Desc") + "\n"; output += "Area: " + Area.ToString() + "\n"; output += "OtherPrims: " + OtherPrims.ToString() + "\n"; output += "RegionDenyIdentified: " + RegionDenyIdentified.ToString() + "\n"; output += "Category: " + Category.ToString() + "\n"; output += "PublicCount: " + PublicCount.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "SalePrice: " + SalePrice.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "SequenceID: " + SequenceID.ToString() + "\n"; output += "RegionDenyTransacted: " + RegionDenyTransacted.ToString() + "\n"; output += "SelfCount: " + SelfCount.ToString() + "\n"; output += Helpers.FieldToString(Bitmap, "Bitmap") + "\n"; output += "Status: " + Status.ToString() + "\n"; output += "SnapshotID: " + SnapshotID.ToString() + "\n"; output += "SnapSelection: " + SnapSelection.ToString() + "\n"; output += "LandingType: " + LandingType.ToString() + "\n"; output += "SimWideTotalPrims: " + SimWideTotalPrims.ToString() + "\n"; output += "AuctionID: " + AuctionID.ToString() + "\n"; output += "AuthBuyerID: " + AuthBuyerID.ToString() + "\n"; output += "PassHours: " + PassHours.ToString() + "\n"; output += "ParcelFlags: " + ParcelFlags.ToString() + "\n"; output += "PassPrice: " + PassPrice.ToString() + "\n"; output += "ClaimDate: " + ClaimDate.ToString() + "\n"; output += "MediaAutoScale: " + MediaAutoScale.ToString() + "\n"; output += Helpers.FieldToString(MusicURL, "MusicURL") + "\n"; output += "ParcelPrimBonus: " + ParcelPrimBonus.ToString() + "\n"; output += "ClaimPrice: " + ClaimPrice.ToString() + "\n"; output += "RentPrice: " + RentPrice.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ParcelProperties public override PacketType Type { get { return PacketType.ParcelProperties; } } /// ParcelData block public ParcelDataBlock ParcelData; /// Default constructor public ParcelPropertiesPacket() { Header = new HighHeader(); Header.ID = 25; Header.Reliable = true; Header.Zerocoded = true; ParcelData = new ParcelDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ParcelPropertiesPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); ParcelData = new ParcelDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ParcelPropertiesPacket(Header head, byte[] bytes, ref int i) { Header = head; ParcelData = new ParcelDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += ParcelData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ParcelData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ParcelProperties ---\n"; output += ParcelData.ToString() + "\n"; return output; } } /// EdgeDataPacket packet public class EdgeDataPacketPacket : Packet { /// EdgeData block public class EdgeDataBlock { /// LayerType field public byte LayerType; /// Direction field public byte Direction; private byte[] _layerdata; /// LayerData field public byte[] LayerData { get { return _layerdata; } set { if (value == null) { _layerdata = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _layerdata = new byte[value.Length]; Array.Copy(value, _layerdata, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 2; if (LayerData != null) { length += 2 + LayerData.Length; } return length; } } /// Default constructor public EdgeDataBlock() { } /// Constructor for building the block from a byte array public EdgeDataBlock(byte[] bytes, ref int i) { int length; try { LayerType = (byte)bytes[i++]; Direction = (byte)bytes[i++]; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _layerdata = new byte[length]; Array.Copy(bytes, i, _layerdata, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = LayerType; bytes[i++] = Direction; if(LayerData == null) { Console.WriteLine("Warning: LayerData is null, in " + this.GetType()); } bytes[i++] = (byte)(LayerData.Length % 256); bytes[i++] = (byte)((LayerData.Length >> 8) % 256); Array.Copy(LayerData, 0, bytes, i, LayerData.Length); i += LayerData.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- EdgeData --\n"; output += "LayerType: " + LayerType.ToString() + "\n"; output += "Direction: " + Direction.ToString() + "\n"; output += Helpers.FieldToString(LayerData, "LayerData") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.EdgeDataPacket public override PacketType Type { get { return PacketType.EdgeDataPacket; } } /// EdgeData block public EdgeDataBlock EdgeData; /// Default constructor public EdgeDataPacketPacket() { Header = new HighHeader(); Header.ID = 26; Header.Reliable = true; Header.Zerocoded = true; EdgeData = new EdgeDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public EdgeDataPacketPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); EdgeData = new EdgeDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public EdgeDataPacketPacket(Header head, byte[] bytes, ref int i) { Header = head; EdgeData = new EdgeDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += EdgeData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); EdgeData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- EdgeDataPacket ---\n"; output += EdgeData.ToString() + "\n"; return output; } } /// ChildAgentUpdate packet public class ChildAgentUpdatePacket : Packet { /// VisualParam block public class VisualParamBlock { /// ParamValue field public byte ParamValue; /// Length of this block serialized in bytes public int Length { get { return 1; } } /// Default constructor public VisualParamBlock() { } /// Constructor for building the block from a byte array public VisualParamBlock(byte[] bytes, ref int i) { try { ParamValue = (byte)bytes[i++]; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = ParamValue; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- VisualParam --\n"; output += "ParamValue: " + ParamValue.ToString() + "\n"; output = output.Trim(); return output; } } /// GranterBlock block public class GranterBlockBlock { /// GranterID field public LLUUID GranterID; /// Length of this block serialized in bytes public int Length { get { return 16; } } /// Default constructor public GranterBlockBlock() { } /// Constructor for building the block from a byte array public GranterBlockBlock(byte[] bytes, ref int i) { try { GranterID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(GranterID == null) { Console.WriteLine("Warning: GranterID is null, in " + this.GetType()); } Array.Copy(GranterID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GranterBlock --\n"; output += "GranterID: " + GranterID.ToString() + "\n"; output = output.Trim(); return output; } } /// AnimationData block public class AnimationDataBlock { /// ObjectID field public LLUUID ObjectID; /// Animation field public LLUUID Animation; /// Length of this block serialized in bytes public int Length { get { return 32; } } /// Default constructor public AnimationDataBlock() { } /// Constructor for building the block from a byte array public AnimationDataBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; Animation = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; if(Animation == null) { Console.WriteLine("Warning: Animation is null, in " + this.GetType()); } Array.Copy(Animation.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AnimationData --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "Animation: " + Animation.ToString() + "\n"; output = output.Trim(); return output; } } /// AgentData block public class AgentDataBlock { /// ViewerCircuitCode field public uint ViewerCircuitCode; /// ControlFlags field public uint ControlFlags; /// Far field public float Far; /// AgentID field public LLUUID AgentID; /// ChangedGrid field public bool ChangedGrid; /// HeadRotation field public LLQuaternion HeadRotation; /// SessionID field public LLUUID SessionID; /// LeftAxis field public LLVector3 LeftAxis; /// Size field public LLVector3 Size; /// GodLevel field public byte GodLevel; /// RegionHandle field public ulong RegionHandle; /// AgentAccess field public byte AgentAccess; /// AgentVel field public LLVector3 AgentVel; /// AgentPos field public LLVector3 AgentPos; /// PreyAgent field public LLUUID PreyAgent; private byte[] _throttles; /// Throttles field public byte[] Throttles { get { return _throttles; } set { if (value == null) { _throttles = null; return; } if (value.Length > 255) { throw new OverflowException("Value exceeds 255 characters"); } else { _throttles = new byte[value.Length]; Array.Copy(value, _throttles, value.Length); } } } /// UpAxis field public LLVector3 UpAxis; private byte[] _agenttextures; /// AgentTextures field public byte[] AgentTextures { get { return _agenttextures; } set { if (value == null) { _agenttextures = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _agenttextures = new byte[value.Length]; Array.Copy(value, _agenttextures, value.Length); } } } /// AtAxis field public LLVector3 AtAxis; /// Center field public LLVector3 Center; /// BodyRotation field public LLQuaternion BodyRotation; /// Aspect field public float Aspect; /// AlwaysRun field public bool AlwaysRun; /// EnergyLevel field public float EnergyLevel; /// LocomotionState field public uint LocomotionState; /// ActiveGroupID field public LLUUID ActiveGroupID; /// Length of this block serialized in bytes public int Length { get { int length = 208; if (Throttles != null) { length += 1 + Throttles.Length; } if (AgentTextures != null) { length += 2 + AgentTextures.Length; } return length; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { int length; try { ViewerCircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ControlFlags = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Far = BitConverter.ToSingle(bytes, i); i += 4; AgentID = new LLUUID(bytes, i); i += 16; ChangedGrid = (bytes[i++] != 0) ? (bool)true : (bool)false; HeadRotation = new LLQuaternion(bytes, i, true); i += 12; SessionID = new LLUUID(bytes, i); i += 16; LeftAxis = new LLVector3(bytes, i); i += 12; Size = new LLVector3(bytes, i); i += 12; GodLevel = (byte)bytes[i++]; RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); AgentAccess = (byte)bytes[i++]; AgentVel = new LLVector3(bytes, i); i += 12; AgentPos = new LLVector3(bytes, i); i += 12; PreyAgent = new LLUUID(bytes, i); i += 16; length = (ushort)bytes[i++]; _throttles = new byte[length]; Array.Copy(bytes, i, _throttles, 0, length); i += length; UpAxis = new LLVector3(bytes, i); i += 12; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _agenttextures = new byte[length]; Array.Copy(bytes, i, _agenttextures, 0, length); i += length; AtAxis = new LLVector3(bytes, i); i += 12; Center = new LLVector3(bytes, i); i += 12; BodyRotation = new LLQuaternion(bytes, i, true); i += 12; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Aspect = BitConverter.ToSingle(bytes, i); i += 4; AlwaysRun = (bytes[i++] != 0) ? (bool)true : (bool)false; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); EnergyLevel = BitConverter.ToSingle(bytes, i); i += 4; LocomotionState = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ActiveGroupID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; bytes[i++] = (byte)(ViewerCircuitCode % 256); bytes[i++] = (byte)((ViewerCircuitCode >> 8) % 256); bytes[i++] = (byte)((ViewerCircuitCode >> 16) % 256); bytes[i++] = (byte)((ViewerCircuitCode >> 24) % 256); bytes[i++] = (byte)(ControlFlags % 256); bytes[i++] = (byte)((ControlFlags >> 8) % 256); bytes[i++] = (byte)((ControlFlags >> 16) % 256); bytes[i++] = (byte)((ControlFlags >> 24) % 256); ba = BitConverter.GetBytes(Far); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((ChangedGrid) ? 1 : 0); if(HeadRotation == null) { Console.WriteLine("Warning: HeadRotation is null, in " + this.GetType()); } Array.Copy(HeadRotation.GetBytes(), 0, bytes, i, 12); i += 12; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(LeftAxis == null) { Console.WriteLine("Warning: LeftAxis is null, in " + this.GetType()); } Array.Copy(LeftAxis.GetBytes(), 0, bytes, i, 12); i += 12; if(Size == null) { Console.WriteLine("Warning: Size is null, in " + this.GetType()); } Array.Copy(Size.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = GodLevel; bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); bytes[i++] = AgentAccess; if(AgentVel == null) { Console.WriteLine("Warning: AgentVel is null, in " + this.GetType()); } Array.Copy(AgentVel.GetBytes(), 0, bytes, i, 12); i += 12; if(AgentPos == null) { Console.WriteLine("Warning: AgentPos is null, in " + this.GetType()); } Array.Copy(AgentPos.GetBytes(), 0, bytes, i, 12); i += 12; if(PreyAgent == null) { Console.WriteLine("Warning: PreyAgent is null, in " + this.GetType()); } Array.Copy(PreyAgent.GetBytes(), 0, bytes, i, 16); i += 16; if(Throttles == null) { Console.WriteLine("Warning: Throttles is null, in " + this.GetType()); } bytes[i++] = (byte)Throttles.Length; Array.Copy(Throttles, 0, bytes, i, Throttles.Length); i += Throttles.Length; if(UpAxis == null) { Console.WriteLine("Warning: UpAxis is null, in " + this.GetType()); } Array.Copy(UpAxis.GetBytes(), 0, bytes, i, 12); i += 12; if(AgentTextures == null) { Console.WriteLine("Warning: AgentTextures is null, in " + this.GetType()); } bytes[i++] = (byte)(AgentTextures.Length % 256); bytes[i++] = (byte)((AgentTextures.Length >> 8) % 256); Array.Copy(AgentTextures, 0, bytes, i, AgentTextures.Length); i += AgentTextures.Length; if(AtAxis == null) { Console.WriteLine("Warning: AtAxis is null, in " + this.GetType()); } Array.Copy(AtAxis.GetBytes(), 0, bytes, i, 12); i += 12; if(Center == null) { Console.WriteLine("Warning: Center is null, in " + this.GetType()); } Array.Copy(Center.GetBytes(), 0, bytes, i, 12); i += 12; if(BodyRotation == null) { Console.WriteLine("Warning: BodyRotation is null, in " + this.GetType()); } Array.Copy(BodyRotation.GetBytes(), 0, bytes, i, 12); i += 12; ba = BitConverter.GetBytes(Aspect); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)((AlwaysRun) ? 1 : 0); ba = BitConverter.GetBytes(EnergyLevel); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; bytes[i++] = (byte)(LocomotionState % 256); bytes[i++] = (byte)((LocomotionState >> 8) % 256); bytes[i++] = (byte)((LocomotionState >> 16) % 256); bytes[i++] = (byte)((LocomotionState >> 24) % 256); if(ActiveGroupID == null) { Console.WriteLine("Warning: ActiveGroupID is null, in " + this.GetType()); } Array.Copy(ActiveGroupID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "ViewerCircuitCode: " + ViewerCircuitCode.ToString() + "\n"; output += "ControlFlags: " + ControlFlags.ToString() + "\n"; output += "Far: " + Far.ToString() + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "ChangedGrid: " + ChangedGrid.ToString() + "\n"; output += "HeadRotation: " + HeadRotation.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "LeftAxis: " + LeftAxis.ToString() + "\n"; output += "Size: " + Size.ToString() + "\n"; output += "GodLevel: " + GodLevel.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output += "AgentAccess: " + AgentAccess.ToString() + "\n"; output += "AgentVel: " + AgentVel.ToString() + "\n"; output += "AgentPos: " + AgentPos.ToString() + "\n"; output += "PreyAgent: " + PreyAgent.ToString() + "\n"; output += Helpers.FieldToString(Throttles, "Throttles") + "\n"; output += "UpAxis: " + UpAxis.ToString() + "\n"; output += Helpers.FieldToString(AgentTextures, "AgentTextures") + "\n"; output += "AtAxis: " + AtAxis.ToString() + "\n"; output += "Center: " + Center.ToString() + "\n"; output += "BodyRotation: " + BodyRotation.ToString() + "\n"; output += "Aspect: " + Aspect.ToString() + "\n"; output += "AlwaysRun: " + AlwaysRun.ToString() + "\n"; output += "EnergyLevel: " + EnergyLevel.ToString() + "\n"; output += "LocomotionState: " + LocomotionState.ToString() + "\n"; output += "ActiveGroupID: " + ActiveGroupID.ToString() + "\n"; output = output.Trim(); return output; } } /// GroupData block public class GroupDataBlock { /// GroupPowers field public ulong GroupPowers; /// GroupID field public LLUUID GroupID; /// AcceptNotices field public bool AcceptNotices; /// Length of this block serialized in bytes public int Length { get { return 25; } } /// Default constructor public GroupDataBlock() { } /// Constructor for building the block from a byte array public GroupDataBlock(byte[] bytes, ref int i) { try { GroupPowers = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); GroupID = new LLUUID(bytes, i); i += 16; AcceptNotices = (bytes[i++] != 0) ? (bool)true : (bool)false; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(GroupPowers % 256); bytes[i++] = (byte)((GroupPowers >> 8) % 256); bytes[i++] = (byte)((GroupPowers >> 16) % 256); bytes[i++] = (byte)((GroupPowers >> 24) % 256); bytes[i++] = (byte)((GroupPowers >> 32) % 256); bytes[i++] = (byte)((GroupPowers >> 40) % 256); bytes[i++] = (byte)((GroupPowers >> 48) % 256); bytes[i++] = (byte)((GroupPowers >> 56) % 256); if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((AcceptNotices) ? 1 : 0); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- GroupData --\n"; output += "GroupPowers: " + GroupPowers.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "AcceptNotices: " + AcceptNotices.ToString() + "\n"; output = output.Trim(); return output; } } /// NVPairData block public class NVPairDataBlock { private byte[] _nvpairs; /// NVPairs field public byte[] NVPairs { get { return _nvpairs; } set { if (value == null) { _nvpairs = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _nvpairs = new byte[value.Length]; Array.Copy(value, _nvpairs, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (NVPairs != null) { length += 2 + NVPairs.Length; } return length; } } /// Default constructor public NVPairDataBlock() { } /// Constructor for building the block from a byte array public NVPairDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _nvpairs = new byte[length]; Array.Copy(bytes, i, _nvpairs, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(NVPairs == null) { Console.WriteLine("Warning: NVPairs is null, in " + this.GetType()); } bytes[i++] = (byte)(NVPairs.Length % 256); bytes[i++] = (byte)((NVPairs.Length >> 8) % 256); Array.Copy(NVPairs, 0, bytes, i, NVPairs.Length); i += NVPairs.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- NVPairData --\n"; output += Helpers.FieldToString(NVPairs, "NVPairs") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ChildAgentUpdate public override PacketType Type { get { return PacketType.ChildAgentUpdate; } } /// VisualParam block public VisualParamBlock[] VisualParam; /// GranterBlock block public GranterBlockBlock[] GranterBlock; /// AnimationData block public AnimationDataBlock[] AnimationData; /// AgentData block public AgentDataBlock AgentData; /// GroupData block public GroupDataBlock[] GroupData; /// NVPairData block public NVPairDataBlock[] NVPairData; /// Default constructor public ChildAgentUpdatePacket() { Header = new HighHeader(); Header.ID = 27; Header.Reliable = true; Header.Zerocoded = true; VisualParam = new VisualParamBlock[0]; GranterBlock = new GranterBlockBlock[0]; AnimationData = new AnimationDataBlock[0]; AgentData = new AgentDataBlock(); GroupData = new GroupDataBlock[0]; NVPairData = new NVPairDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ChildAgentUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); int count = (int)bytes[i++]; VisualParam = new VisualParamBlock[count]; for (int j = 0; j < count; j++) { VisualParam[j] = new VisualParamBlock(bytes, ref i); } count = (int)bytes[i++]; GranterBlock = new GranterBlockBlock[count]; for (int j = 0; j < count; j++) { GranterBlock[j] = new GranterBlockBlock(bytes, ref i); } count = (int)bytes[i++]; AnimationData = new AnimationDataBlock[count]; for (int j = 0; j < count; j++) { AnimationData[j] = new AnimationDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); count = (int)bytes[i++]; GroupData = new GroupDataBlock[count]; for (int j = 0; j < count; j++) { GroupData[j] = new GroupDataBlock(bytes, ref i); } count = (int)bytes[i++]; NVPairData = new NVPairDataBlock[count]; for (int j = 0; j < count; j++) { NVPairData[j] = new NVPairDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public ChildAgentUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; int count = (int)bytes[i++]; VisualParam = new VisualParamBlock[count]; for (int j = 0; j < count; j++) { VisualParam[j] = new VisualParamBlock(bytes, ref i); } count = (int)bytes[i++]; GranterBlock = new GranterBlockBlock[count]; for (int j = 0; j < count; j++) { GranterBlock[j] = new GranterBlockBlock(bytes, ref i); } count = (int)bytes[i++]; AnimationData = new AnimationDataBlock[count]; for (int j = 0; j < count; j++) { AnimationData[j] = new AnimationDataBlock(bytes, ref i); } AgentData = new AgentDataBlock(bytes, ref i); count = (int)bytes[i++]; GroupData = new GroupDataBlock[count]; for (int j = 0; j < count; j++) { GroupData[j] = new GroupDataBlock(bytes, ref i); } count = (int)bytes[i++]; NVPairData = new NVPairDataBlock[count]; for (int j = 0; j < count; j++) { NVPairData[j] = new NVPairDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += AgentData.Length;; length++; for (int j = 0; j < VisualParam.Length; j++) { length += VisualParam[j].Length; } length++; for (int j = 0; j < GranterBlock.Length; j++) { length += GranterBlock[j].Length; } length++; for (int j = 0; j < AnimationData.Length; j++) { length += AnimationData[j].Length; } length++; for (int j = 0; j < GroupData.Length; j++) { length += GroupData[j].Length; } length++; for (int j = 0; j < NVPairData.Length; j++) { length += NVPairData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); bytes[i++] = (byte)VisualParam.Length; for (int j = 0; j < VisualParam.Length; j++) { VisualParam[j].ToBytes(bytes, ref i); } bytes[i++] = (byte)GranterBlock.Length; for (int j = 0; j < GranterBlock.Length; j++) { GranterBlock[j].ToBytes(bytes, ref i); } bytes[i++] = (byte)AnimationData.Length; for (int j = 0; j < AnimationData.Length; j++) { AnimationData[j].ToBytes(bytes, ref i); } AgentData.ToBytes(bytes, ref i); bytes[i++] = (byte)GroupData.Length; for (int j = 0; j < GroupData.Length; j++) { GroupData[j].ToBytes(bytes, ref i); } bytes[i++] = (byte)NVPairData.Length; for (int j = 0; j < NVPairData.Length; j++) { NVPairData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ChildAgentUpdate ---\n"; for (int j = 0; j < VisualParam.Length; j++) { output += VisualParam[j].ToString() + "\n"; } for (int j = 0; j < GranterBlock.Length; j++) { output += GranterBlock[j].ToString() + "\n"; } for (int j = 0; j < AnimationData.Length; j++) { output += AnimationData[j].ToString() + "\n"; } output += AgentData.ToString() + "\n"; for (int j = 0; j < GroupData.Length; j++) { output += GroupData[j].ToString() + "\n"; } for (int j = 0; j < NVPairData.Length; j++) { output += NVPairData[j].ToString() + "\n"; } return output; } } /// ChildAgentAlive packet public class ChildAgentAlivePacket : Packet { /// AgentData block public class AgentDataBlock { /// ViewerCircuitCode field public uint ViewerCircuitCode; /// AgentID field public LLUUID AgentID; /// SessionID field public LLUUID SessionID; /// RegionHandle field public ulong RegionHandle; /// Length of this block serialized in bytes public int Length { get { return 44; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { ViewerCircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); AgentID = new LLUUID(bytes, i); i += 16; SessionID = new LLUUID(bytes, i); i += 16; RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ViewerCircuitCode % 256); bytes[i++] = (byte)((ViewerCircuitCode >> 8) % 256); bytes[i++] = (byte)((ViewerCircuitCode >> 16) % 256); bytes[i++] = (byte)((ViewerCircuitCode >> 24) % 256); if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "ViewerCircuitCode: " + ViewerCircuitCode.ToString() + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ChildAgentAlive public override PacketType Type { get { return PacketType.ChildAgentAlive; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ChildAgentAlivePacket() { Header = new HighHeader(); Header.ID = 28; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ChildAgentAlivePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ChildAgentAlivePacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ChildAgentAlive ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// ChildAgentPositionUpdate packet public class ChildAgentPositionUpdatePacket : Packet { /// AgentData block public class AgentDataBlock { /// ViewerCircuitCode field public uint ViewerCircuitCode; /// AgentID field public LLUUID AgentID; /// ChangedGrid field public bool ChangedGrid; /// SessionID field public LLUUID SessionID; /// LeftAxis field public LLVector3 LeftAxis; /// Size field public LLVector3 Size; /// RegionHandle field public ulong RegionHandle; /// AgentVel field public LLVector3 AgentVel; /// AgentPos field public LLVector3 AgentPos; /// UpAxis field public LLVector3 UpAxis; /// AtAxis field public LLVector3 AtAxis; /// Center field public LLVector3 Center; /// Length of this block serialized in bytes public int Length { get { return 129; } } /// Default constructor public AgentDataBlock() { } /// Constructor for building the block from a byte array public AgentDataBlock(byte[] bytes, ref int i) { try { ViewerCircuitCode = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); AgentID = new LLUUID(bytes, i); i += 16; ChangedGrid = (bytes[i++] != 0) ? (bool)true : (bool)false; SessionID = new LLUUID(bytes, i); i += 16; LeftAxis = new LLVector3(bytes, i); i += 12; Size = new LLVector3(bytes, i); i += 12; RegionHandle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); AgentVel = new LLVector3(bytes, i); i += 12; AgentPos = new LLVector3(bytes, i); i += 12; UpAxis = new LLVector3(bytes, i); i += 12; AtAxis = new LLVector3(bytes, i); i += 12; Center = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)(ViewerCircuitCode % 256); bytes[i++] = (byte)((ViewerCircuitCode >> 8) % 256); bytes[i++] = (byte)((ViewerCircuitCode >> 16) % 256); bytes[i++] = (byte)((ViewerCircuitCode >> 24) % 256); if(AgentID == null) { Console.WriteLine("Warning: AgentID is null, in " + this.GetType()); } Array.Copy(AgentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((ChangedGrid) ? 1 : 0); if(SessionID == null) { Console.WriteLine("Warning: SessionID is null, in " + this.GetType()); } Array.Copy(SessionID.GetBytes(), 0, bytes, i, 16); i += 16; if(LeftAxis == null) { Console.WriteLine("Warning: LeftAxis is null, in " + this.GetType()); } Array.Copy(LeftAxis.GetBytes(), 0, bytes, i, 12); i += 12; if(Size == null) { Console.WriteLine("Warning: Size is null, in " + this.GetType()); } Array.Copy(Size.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = (byte)(RegionHandle % 256); bytes[i++] = (byte)((RegionHandle >> 8) % 256); bytes[i++] = (byte)((RegionHandle >> 16) % 256); bytes[i++] = (byte)((RegionHandle >> 24) % 256); bytes[i++] = (byte)((RegionHandle >> 32) % 256); bytes[i++] = (byte)((RegionHandle >> 40) % 256); bytes[i++] = (byte)((RegionHandle >> 48) % 256); bytes[i++] = (byte)((RegionHandle >> 56) % 256); if(AgentVel == null) { Console.WriteLine("Warning: AgentVel is null, in " + this.GetType()); } Array.Copy(AgentVel.GetBytes(), 0, bytes, i, 12); i += 12; if(AgentPos == null) { Console.WriteLine("Warning: AgentPos is null, in " + this.GetType()); } Array.Copy(AgentPos.GetBytes(), 0, bytes, i, 12); i += 12; if(UpAxis == null) { Console.WriteLine("Warning: UpAxis is null, in " + this.GetType()); } Array.Copy(UpAxis.GetBytes(), 0, bytes, i, 12); i += 12; if(AtAxis == null) { Console.WriteLine("Warning: AtAxis is null, in " + this.GetType()); } Array.Copy(AtAxis.GetBytes(), 0, bytes, i, 12); i += 12; if(Center == null) { Console.WriteLine("Warning: Center is null, in " + this.GetType()); } Array.Copy(Center.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- AgentData --\n"; output += "ViewerCircuitCode: " + ViewerCircuitCode.ToString() + "\n"; output += "AgentID: " + AgentID.ToString() + "\n"; output += "ChangedGrid: " + ChangedGrid.ToString() + "\n"; output += "SessionID: " + SessionID.ToString() + "\n"; output += "LeftAxis: " + LeftAxis.ToString() + "\n"; output += "Size: " + Size.ToString() + "\n"; output += "RegionHandle: " + RegionHandle.ToString() + "\n"; output += "AgentVel: " + AgentVel.ToString() + "\n"; output += "AgentPos: " + AgentPos.ToString() + "\n"; output += "UpAxis: " + UpAxis.ToString() + "\n"; output += "AtAxis: " + AtAxis.ToString() + "\n"; output += "Center: " + Center.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.ChildAgentPositionUpdate public override PacketType Type { get { return PacketType.ChildAgentPositionUpdate; } } /// AgentData block public AgentDataBlock AgentData; /// Default constructor public ChildAgentPositionUpdatePacket() { Header = new HighHeader(); Header.ID = 29; Header.Reliable = true; AgentData = new AgentDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public ChildAgentPositionUpdatePacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); AgentData = new AgentDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public ChildAgentPositionUpdatePacket(Header head, byte[] bytes, ref int i) { Header = head; AgentData = new AgentDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += AgentData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); AgentData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- ChildAgentPositionUpdate ---\n"; output += AgentData.ToString() + "\n"; return output; } } /// PassObject packet public class PassObjectPacket : Packet { /// ObjectData block public class ObjectDataBlock { /// ID field public LLUUID ID; /// GroupOwned field public bool GroupOwned; /// PathTwistBegin field public sbyte PathTwistBegin; /// PathEnd field public byte PathEnd; /// AngVelX field public short AngVelX; /// AngVelY field public short AngVelY; /// AngVelZ field public short AngVelZ; /// BaseMask field public uint BaseMask; /// ProfileBegin field public byte ProfileBegin; /// SubType field public short SubType; /// PathRadiusOffset field public sbyte PathRadiusOffset; /// VelX field public short VelX; /// PathSkew field public sbyte PathSkew; /// VelY field public short VelY; /// VelZ field public short VelZ; private byte[] _data; /// Data field public byte[] Data { get { return _data; } set { if (value == null) { _data = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _data = new byte[value.Length]; Array.Copy(value, _data, value.Length); } } } /// ParentID field public LLUUID ParentID; /// PosX field public short PosX; /// PosY field public short PosY; /// PosZ field public short PosZ; /// ProfileCurve field public byte ProfileCurve; /// PathScaleX field public byte PathScaleX; /// PathScaleY field public byte PathScaleY; /// GroupID field public LLUUID GroupID; /// Material field public byte Material; /// OwnerID field public LLUUID OwnerID; /// CreatorID field public LLUUID CreatorID; /// PathShearX field public byte PathShearX; /// PathShearY field public byte PathShearY; /// PathTaperX field public sbyte PathTaperX; /// PathTaperY field public sbyte PathTaperY; /// ProfileEnd field public byte ProfileEnd; /// UsePhysics field public byte UsePhysics; /// PathBegin field public byte PathBegin; /// Active field public byte Active; /// PCode field public byte PCode; /// PathCurve field public byte PathCurve; /// EveryoneMask field public uint EveryoneMask; /// Scale field public LLVector3 Scale; /// State field public byte State; /// PathTwist field public sbyte PathTwist; private byte[] _textureentry; /// TextureEntry field public byte[] TextureEntry { get { return _textureentry; } set { if (value == null) { _textureentry = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _textureentry = new byte[value.Length]; Array.Copy(value, _textureentry, value.Length); } } } /// ProfileHollow field public byte ProfileHollow; /// PathRevolutions field public byte PathRevolutions; /// Rotation field public LLQuaternion Rotation; /// NextOwnerMask field public uint NextOwnerMask; /// GroupMask field public uint GroupMask; /// OwnerMask field public uint OwnerMask; /// Length of this block serialized in bytes public int Length { get { int length = 168; if (Data != null) { length += 2 + Data.Length; } if (TextureEntry != null) { length += 2 + TextureEntry.Length; } return length; } } /// Default constructor public ObjectDataBlock() { } /// Constructor for building the block from a byte array public ObjectDataBlock(byte[] bytes, ref int i) { int length; try { ID = new LLUUID(bytes, i); i += 16; GroupOwned = (bytes[i++] != 0) ? (bool)true : (bool)false; PathTwistBegin = (sbyte)bytes[i++]; PathEnd = (byte)bytes[i++]; AngVelX = (short)(bytes[i++] + (bytes[i++] << 8)); AngVelY = (short)(bytes[i++] + (bytes[i++] << 8)); AngVelZ = (short)(bytes[i++] + (bytes[i++] << 8)); BaseMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); ProfileBegin = (byte)bytes[i++]; SubType = (short)(bytes[i++] + (bytes[i++] << 8)); PathRadiusOffset = (sbyte)bytes[i++]; VelX = (short)(bytes[i++] + (bytes[i++] << 8)); PathSkew = (sbyte)bytes[i++]; VelY = (short)(bytes[i++] + (bytes[i++] << 8)); VelZ = (short)(bytes[i++] + (bytes[i++] << 8)); length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _data = new byte[length]; Array.Copy(bytes, i, _data, 0, length); i += length; ParentID = new LLUUID(bytes, i); i += 16; PosX = (short)(bytes[i++] + (bytes[i++] << 8)); PosY = (short)(bytes[i++] + (bytes[i++] << 8)); PosZ = (short)(bytes[i++] + (bytes[i++] << 8)); ProfileCurve = (byte)bytes[i++]; PathScaleX = (byte)bytes[i++]; PathScaleY = (byte)bytes[i++]; GroupID = new LLUUID(bytes, i); i += 16; Material = (byte)bytes[i++]; OwnerID = new LLUUID(bytes, i); i += 16; CreatorID = new LLUUID(bytes, i); i += 16; PathShearX = (byte)bytes[i++]; PathShearY = (byte)bytes[i++]; PathTaperX = (sbyte)bytes[i++]; PathTaperY = (sbyte)bytes[i++]; ProfileEnd = (byte)bytes[i++]; UsePhysics = (byte)bytes[i++]; PathBegin = (byte)bytes[i++]; Active = (byte)bytes[i++]; PCode = (byte)bytes[i++]; PathCurve = (byte)bytes[i++]; EveryoneMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); Scale = new LLVector3(bytes, i); i += 12; State = (byte)bytes[i++]; PathTwist = (sbyte)bytes[i++]; length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _textureentry = new byte[length]; Array.Copy(bytes, i, _textureentry, 0, length); i += length; ProfileHollow = (byte)bytes[i++]; PathRevolutions = (byte)bytes[i++]; Rotation = new LLQuaternion(bytes, i, true); i += 12; NextOwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); GroupMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); OwnerMask = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24)); } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(ID == null) { Console.WriteLine("Warning: ID is null, in " + this.GetType()); } Array.Copy(ID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)((GroupOwned) ? 1 : 0); bytes[i++] = (byte)PathTwistBegin; bytes[i++] = PathEnd; bytes[i++] = (byte)(AngVelX % 256); bytes[i++] = (byte)((AngVelX >> 8) % 256); bytes[i++] = (byte)(AngVelY % 256); bytes[i++] = (byte)((AngVelY >> 8) % 256); bytes[i++] = (byte)(AngVelZ % 256); bytes[i++] = (byte)((AngVelZ >> 8) % 256); bytes[i++] = (byte)(BaseMask % 256); bytes[i++] = (byte)((BaseMask >> 8) % 256); bytes[i++] = (byte)((BaseMask >> 16) % 256); bytes[i++] = (byte)((BaseMask >> 24) % 256); bytes[i++] = ProfileBegin; bytes[i++] = (byte)(SubType % 256); bytes[i++] = (byte)((SubType >> 8) % 256); bytes[i++] = (byte)PathRadiusOffset; bytes[i++] = (byte)(VelX % 256); bytes[i++] = (byte)((VelX >> 8) % 256); bytes[i++] = (byte)PathSkew; bytes[i++] = (byte)(VelY % 256); bytes[i++] = (byte)((VelY >> 8) % 256); bytes[i++] = (byte)(VelZ % 256); bytes[i++] = (byte)((VelZ >> 8) % 256); if(Data == null) { Console.WriteLine("Warning: Data is null, in " + this.GetType()); } bytes[i++] = (byte)(Data.Length % 256); bytes[i++] = (byte)((Data.Length >> 8) % 256); Array.Copy(Data, 0, bytes, i, Data.Length); i += Data.Length; if(ParentID == null) { Console.WriteLine("Warning: ParentID is null, in " + this.GetType()); } Array.Copy(ParentID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(PosX % 256); bytes[i++] = (byte)((PosX >> 8) % 256); bytes[i++] = (byte)(PosY % 256); bytes[i++] = (byte)((PosY >> 8) % 256); bytes[i++] = (byte)(PosZ % 256); bytes[i++] = (byte)((PosZ >> 8) % 256); bytes[i++] = ProfileCurve; bytes[i++] = PathScaleX; bytes[i++] = PathScaleY; if(GroupID == null) { Console.WriteLine("Warning: GroupID is null, in " + this.GetType()); } Array.Copy(GroupID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = Material; if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; if(CreatorID == null) { Console.WriteLine("Warning: CreatorID is null, in " + this.GetType()); } Array.Copy(CreatorID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = PathShearX; bytes[i++] = PathShearY; bytes[i++] = (byte)PathTaperX; bytes[i++] = (byte)PathTaperY; bytes[i++] = ProfileEnd; bytes[i++] = UsePhysics; bytes[i++] = PathBegin; bytes[i++] = Active; bytes[i++] = PCode; bytes[i++] = PathCurve; bytes[i++] = (byte)(EveryoneMask % 256); bytes[i++] = (byte)((EveryoneMask >> 8) % 256); bytes[i++] = (byte)((EveryoneMask >> 16) % 256); bytes[i++] = (byte)((EveryoneMask >> 24) % 256); if(Scale == null) { Console.WriteLine("Warning: Scale is null, in " + this.GetType()); } Array.Copy(Scale.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = State; bytes[i++] = (byte)PathTwist; if(TextureEntry == null) { Console.WriteLine("Warning: TextureEntry is null, in " + this.GetType()); } bytes[i++] = (byte)(TextureEntry.Length % 256); bytes[i++] = (byte)((TextureEntry.Length >> 8) % 256); Array.Copy(TextureEntry, 0, bytes, i, TextureEntry.Length); i += TextureEntry.Length; bytes[i++] = ProfileHollow; bytes[i++] = PathRevolutions; if(Rotation == null) { Console.WriteLine("Warning: Rotation is null, in " + this.GetType()); } Array.Copy(Rotation.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = (byte)(NextOwnerMask % 256); bytes[i++] = (byte)((NextOwnerMask >> 8) % 256); bytes[i++] = (byte)((NextOwnerMask >> 16) % 256); bytes[i++] = (byte)((NextOwnerMask >> 24) % 256); bytes[i++] = (byte)(GroupMask % 256); bytes[i++] = (byte)((GroupMask >> 8) % 256); bytes[i++] = (byte)((GroupMask >> 16) % 256); bytes[i++] = (byte)((GroupMask >> 24) % 256); bytes[i++] = (byte)(OwnerMask % 256); bytes[i++] = (byte)((OwnerMask >> 8) % 256); bytes[i++] = (byte)((OwnerMask >> 16) % 256); bytes[i++] = (byte)((OwnerMask >> 24) % 256); } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- ObjectData --\n"; output += "ID: " + ID.ToString() + "\n"; output += "GroupOwned: " + GroupOwned.ToString() + "\n"; output += "PathTwistBegin: " + PathTwistBegin.ToString() + "\n"; output += "PathEnd: " + PathEnd.ToString() + "\n"; output += "AngVelX: " + AngVelX.ToString() + "\n"; output += "AngVelY: " + AngVelY.ToString() + "\n"; output += "AngVelZ: " + AngVelZ.ToString() + "\n"; output += "BaseMask: " + BaseMask.ToString() + "\n"; output += "ProfileBegin: " + ProfileBegin.ToString() + "\n"; output += "SubType: " + SubType.ToString() + "\n"; output += "PathRadiusOffset: " + PathRadiusOffset.ToString() + "\n"; output += "VelX: " + VelX.ToString() + "\n"; output += "PathSkew: " + PathSkew.ToString() + "\n"; output += "VelY: " + VelY.ToString() + "\n"; output += "VelZ: " + VelZ.ToString() + "\n"; output += Helpers.FieldToString(Data, "Data") + "\n"; output += "ParentID: " + ParentID.ToString() + "\n"; output += "PosX: " + PosX.ToString() + "\n"; output += "PosY: " + PosY.ToString() + "\n"; output += "PosZ: " + PosZ.ToString() + "\n"; output += "ProfileCurve: " + ProfileCurve.ToString() + "\n"; output += "PathScaleX: " + PathScaleX.ToString() + "\n"; output += "PathScaleY: " + PathScaleY.ToString() + "\n"; output += "GroupID: " + GroupID.ToString() + "\n"; output += "Material: " + Material.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "CreatorID: " + CreatorID.ToString() + "\n"; output += "PathShearX: " + PathShearX.ToString() + "\n"; output += "PathShearY: " + PathShearY.ToString() + "\n"; output += "PathTaperX: " + PathTaperX.ToString() + "\n"; output += "PathTaperY: " + PathTaperY.ToString() + "\n"; output += "ProfileEnd: " + ProfileEnd.ToString() + "\n"; output += "UsePhysics: " + UsePhysics.ToString() + "\n"; output += "PathBegin: " + PathBegin.ToString() + "\n"; output += "Active: " + Active.ToString() + "\n"; output += "PCode: " + PCode.ToString() + "\n"; output += "PathCurve: " + PathCurve.ToString() + "\n"; output += "EveryoneMask: " + EveryoneMask.ToString() + "\n"; output += "Scale: " + Scale.ToString() + "\n"; output += "State: " + State.ToString() + "\n"; output += "PathTwist: " + PathTwist.ToString() + "\n"; output += Helpers.FieldToString(TextureEntry, "TextureEntry") + "\n"; output += "ProfileHollow: " + ProfileHollow.ToString() + "\n"; output += "PathRevolutions: " + PathRevolutions.ToString() + "\n"; output += "Rotation: " + Rotation.ToString() + "\n"; output += "NextOwnerMask: " + NextOwnerMask.ToString() + "\n"; output += "GroupMask: " + GroupMask.ToString() + "\n"; output += "OwnerMask: " + OwnerMask.ToString() + "\n"; output = output.Trim(); return output; } } /// NVPairData block public class NVPairDataBlock { private byte[] _nvpairs; /// NVPairs field public byte[] NVPairs { get { return _nvpairs; } set { if (value == null) { _nvpairs = null; return; } if (value.Length > 1024) { throw new OverflowException("Value exceeds 1024 characters"); } else { _nvpairs = new byte[value.Length]; Array.Copy(value, _nvpairs, value.Length); } } } /// Length of this block serialized in bytes public int Length { get { int length = 0; if (NVPairs != null) { length += 2 + NVPairs.Length; } return length; } } /// Default constructor public NVPairDataBlock() { } /// Constructor for building the block from a byte array public NVPairDataBlock(byte[] bytes, ref int i) { int length; try { length = (ushort)(bytes[i++] + (bytes[i++] << 8)); _nvpairs = new byte[length]; Array.Copy(bytes, i, _nvpairs, 0, length); i += length; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { if(NVPairs == null) { Console.WriteLine("Warning: NVPairs is null, in " + this.GetType()); } bytes[i++] = (byte)(NVPairs.Length % 256); bytes[i++] = (byte)((NVPairs.Length >> 8) % 256); Array.Copy(NVPairs, 0, bytes, i, NVPairs.Length); i += NVPairs.Length; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- NVPairData --\n"; output += Helpers.FieldToString(NVPairs, "NVPairs") + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.PassObject public override PacketType Type { get { return PacketType.PassObject; } } /// ObjectData block public ObjectDataBlock ObjectData; /// NVPairData block public NVPairDataBlock[] NVPairData; /// Default constructor public PassObjectPacket() { Header = new HighHeader(); Header.ID = 30; Header.Reliable = true; Header.Zerocoded = true; ObjectData = new ObjectDataBlock(); NVPairData = new NVPairDataBlock[0]; } /// Constructor that takes a byte array and beginning position (no prebuilt header) public PassObjectPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); ObjectData = new ObjectDataBlock(bytes, ref i); int count = (int)bytes[i++]; NVPairData = new NVPairDataBlock[count]; for (int j = 0; j < count; j++) { NVPairData[j] = new NVPairDataBlock(bytes, ref i); } } /// Constructor that takes a byte array and a prebuilt header public PassObjectPacket(Header head, byte[] bytes, ref int i) { Header = head; ObjectData = new ObjectDataBlock(bytes, ref i); int count = (int)bytes[i++]; NVPairData = new NVPairDataBlock[count]; for (int j = 0; j < count; j++) { NVPairData[j] = new NVPairDataBlock(bytes, ref i); } } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += ObjectData.Length;; length++; for (int j = 0; j < NVPairData.Length; j++) { length += NVPairData[j].Length; } if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); ObjectData.ToBytes(bytes, ref i); bytes[i++] = (byte)NVPairData.Length; for (int j = 0; j < NVPairData.Length; j++) { NVPairData[j].ToBytes(bytes, ref i); } if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- PassObject ---\n"; output += ObjectData.ToString() + "\n"; for (int j = 0; j < NVPairData.Length; j++) { output += NVPairData[j].ToString() + "\n"; } return output; } } /// AtomicPassObject packet public class AtomicPassObjectPacket : Packet { /// TaskData block public class TaskDataBlock { /// AttachmentNeedsSave field public bool AttachmentNeedsSave; /// TaskID field public LLUUID TaskID; /// Length of this block serialized in bytes public int Length { get { return 17; } } /// Default constructor public TaskDataBlock() { } /// Constructor for building the block from a byte array public TaskDataBlock(byte[] bytes, ref int i) { try { AttachmentNeedsSave = (bytes[i++] != 0) ? (bool)true : (bool)false; TaskID = new LLUUID(bytes, i); i += 16; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { bytes[i++] = (byte)((AttachmentNeedsSave) ? 1 : 0); if(TaskID == null) { Console.WriteLine("Warning: TaskID is null, in " + this.GetType()); } Array.Copy(TaskID.GetBytes(), 0, bytes, i, 16); i += 16; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- TaskData --\n"; output += "AttachmentNeedsSave: " + AttachmentNeedsSave.ToString() + "\n"; output += "TaskID: " + TaskID.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.AtomicPassObject public override PacketType Type { get { return PacketType.AtomicPassObject; } } /// TaskData block public TaskDataBlock TaskData; /// Default constructor public AtomicPassObjectPacket() { Header = new HighHeader(); Header.ID = 31; Header.Reliable = true; TaskData = new TaskDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public AtomicPassObjectPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); TaskData = new TaskDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public AtomicPassObjectPacket(Header head, byte[] bytes, ref int i) { Header = head; TaskData = new TaskDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += TaskData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); TaskData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- AtomicPassObject ---\n"; output += TaskData.ToString() + "\n"; return output; } } /// SoundTrigger packet public class SoundTriggerPacket : Packet { /// SoundData block public class SoundDataBlock { /// ObjectID field public LLUUID ObjectID; /// Gain field public float Gain; /// ParentID field public LLUUID ParentID; /// SoundID field public LLUUID SoundID; /// OwnerID field public LLUUID OwnerID; /// Handle field public ulong Handle; /// Position field public LLVector3 Position; /// Length of this block serialized in bytes public int Length { get { return 88; } } /// Default constructor public SoundDataBlock() { } /// Constructor for building the block from a byte array public SoundDataBlock(byte[] bytes, ref int i) { try { ObjectID = new LLUUID(bytes, i); i += 16; if (!BitConverter.IsLittleEndian) Array.Reverse(bytes, i, 4); Gain = BitConverter.ToSingle(bytes, i); i += 4; ParentID = new LLUUID(bytes, i); i += 16; SoundID = new LLUUID(bytes, i); i += 16; OwnerID = new LLUUID(bytes, i); i += 16; Handle = (ulong)((ulong)bytes[i++] + ((ulong)bytes[i++] << 8) + ((ulong)bytes[i++] << 16) + ((ulong)bytes[i++] << 24) + ((ulong)bytes[i++] << 32) + ((ulong)bytes[i++] << 40) + ((ulong)bytes[i++] << 48) + ((ulong)bytes[i++] << 56)); Position = new LLVector3(bytes, i); i += 12; } catch (Exception) { throw new MalformedDataException(); } } /// Serialize this block to a byte array public void ToBytes(byte[] bytes, ref int i) { byte[] ba; if(ObjectID == null) { Console.WriteLine("Warning: ObjectID is null, in " + this.GetType()); } Array.Copy(ObjectID.GetBytes(), 0, bytes, i, 16); i += 16; ba = BitConverter.GetBytes(Gain); if(!BitConverter.IsLittleEndian) { Array.Reverse(ba, 0, 4); } Array.Copy(ba, 0, bytes, i, 4); i += 4; if(ParentID == null) { Console.WriteLine("Warning: ParentID is null, in " + this.GetType()); } Array.Copy(ParentID.GetBytes(), 0, bytes, i, 16); i += 16; if(SoundID == null) { Console.WriteLine("Warning: SoundID is null, in " + this.GetType()); } Array.Copy(SoundID.GetBytes(), 0, bytes, i, 16); i += 16; if(OwnerID == null) { Console.WriteLine("Warning: OwnerID is null, in " + this.GetType()); } Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = (byte)(Handle % 256); bytes[i++] = (byte)((Handle >> 8) % 256); bytes[i++] = (byte)((Handle >> 16) % 256); bytes[i++] = (byte)((Handle >> 24) % 256); bytes[i++] = (byte)((Handle >> 32) % 256); bytes[i++] = (byte)((Handle >> 40) % 256); bytes[i++] = (byte)((Handle >> 48) % 256); bytes[i++] = (byte)((Handle >> 56) % 256); if(Position == null) { Console.WriteLine("Warning: Position is null, in " + this.GetType()); } Array.Copy(Position.GetBytes(), 0, bytes, i, 12); i += 12; } /// Serialize this block to a stringA string containing the serialized block public override string ToString() { string output = "-- SoundData --\n"; output += "ObjectID: " + ObjectID.ToString() + "\n"; output += "Gain: " + Gain.ToString() + "\n"; output += "ParentID: " + ParentID.ToString() + "\n"; output += "SoundID: " + SoundID.ToString() + "\n"; output += "OwnerID: " + OwnerID.ToString() + "\n"; output += "Handle: " + Handle.ToString() + "\n"; output += "Position: " + Position.ToString() + "\n"; output = output.Trim(); return output; } } private Header header; /// The header for this packet public override Header Header { get { return header; } set { header = value; } } /// Will return PacketType.SoundTrigger public override PacketType Type { get { return PacketType.SoundTrigger; } } /// SoundData block public SoundDataBlock SoundData; /// Default constructor public SoundTriggerPacket() { Header = new HighHeader(); Header.ID = 32; Header.Reliable = true; SoundData = new SoundDataBlock(); } /// Constructor that takes a byte array and beginning position (no prebuilt header) public SoundTriggerPacket(byte[] bytes, ref int i) { int packetEnd = bytes.Length - 1; Header = new HighHeader(bytes, ref i, ref packetEnd); SoundData = new SoundDataBlock(bytes, ref i); } /// Constructor that takes a byte array and a prebuilt header public SoundTriggerPacket(Header head, byte[] bytes, ref int i) { Header = head; SoundData = new SoundDataBlock(bytes, ref i); } /// Serialize this packet to a byte arrayA byte array containing the serialized packet public override byte[] ToBytes() { int length = 5; length += SoundData.Length;; if (header.AckList.Length > 0) { length += header.AckList.Length * 4 + 1; } byte[] bytes = new byte[length]; int i = 0; header.ToBytes(bytes, ref i); SoundData.ToBytes(bytes, ref i); if (header.AckList.Length > 0) { header.AcksToBytes(bytes, ref i); } return bytes; } /// Serialize this packet to a stringA string containing the serialized packet public override string ToString() { string output = "--- SoundTrigger ---\n"; output += SoundData.ToString() + "\n"; return output; } } }